react-obsidian 0.0.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.
- package/.buildkite/pipeline.yml +0 -0
- package/.eslintignore +1 -0
- package/.eslintrc.json +93 -0
- package/.nvmrc +1 -0
- package/LICENSE +7 -0
- package/README.md +160 -0
- package/babel.config.js +12 -0
- package/dist/src/GraphProperties.d.ts +6 -0
- package/dist/src/GraphProperties.d.ts.map +1 -0
- package/dist/src/GraphProperties.js +16 -0
- package/dist/src/GraphProperties.js.map +1 -0
- package/dist/src/Obsidian.d.ts +9 -0
- package/dist/src/Obsidian.d.ts.map +1 -0
- package/dist/src/Obsidian.js +22 -0
- package/dist/src/Obsidian.js.map +1 -0
- package/dist/src/ProvidedPropertiesStore.d.ts +10 -0
- package/dist/src/ProvidedPropertiesStore.d.ts.map +1 -0
- package/dist/src/ProvidedPropertiesStore.js +27 -0
- package/dist/src/ProvidedPropertiesStore.js.map +1 -0
- package/dist/src/Provides.d.ts +9 -0
- package/dist/src/Provides.d.ts.map +1 -0
- package/dist/src/Provides.js +15 -0
- package/dist/src/Provides.js.map +1 -0
- package/dist/src/ReferenceCounter.d.ts +8 -0
- package/dist/src/ReferenceCounter.d.ts.map +1 -0
- package/dist/src/ReferenceCounter.js +25 -0
- package/dist/src/ReferenceCounter.js.map +1 -0
- package/dist/src/ScopedValuesRegistry.d.ts +11 -0
- package/dist/src/ScopedValuesRegistry.d.ts.map +1 -0
- package/dist/src/ScopedValuesRegistry.js +25 -0
- package/dist/src/ScopedValuesRegistry.js.map +1 -0
- package/dist/src/decorators/Graph.d.ts +10 -0
- package/dist/src/decorators/Graph.d.ts.map +1 -0
- package/dist/src/decorators/Graph.js +17 -0
- package/dist/src/decorators/Graph.js.map +1 -0
- package/dist/src/decorators/injectClass.d.ts +7 -0
- package/dist/src/decorators/injectClass.d.ts.map +1 -0
- package/dist/src/decorators/injectClass.js +34 -0
- package/dist/src/decorators/injectClass.js.map +1 -0
- package/dist/src/graph/Graph.d.ts +6 -0
- package/dist/src/graph/Graph.d.ts.map +1 -0
- package/dist/src/graph/Graph.js +3 -0
- package/dist/src/graph/Graph.js.map +1 -0
- package/dist/src/graph/ObjectGraph.d.ts +11 -0
- package/dist/src/graph/ObjectGraph.d.ts.map +1 -0
- package/dist/src/graph/ObjectGraph.js +26 -0
- package/dist/src/graph/ObjectGraph.js.map +1 -0
- package/dist/src/graph/PropertyRetriever.d.ts +8 -0
- package/dist/src/graph/PropertyRetriever.d.ts.map +1 -0
- package/dist/src/graph/PropertyRetriever.js +40 -0
- package/dist/src/graph/PropertyRetriever.js.map +1 -0
- package/dist/src/graph/PropertyRetrieverDelegate.d.ts +5 -0
- package/dist/src/graph/PropertyRetrieverDelegate.d.ts.map +1 -0
- package/dist/src/graph/PropertyRetrieverDelegate.js +3 -0
- package/dist/src/graph/PropertyRetrieverDelegate.js.map +1 -0
- package/dist/src/graph/registry/DefaultGraphResolver.d.ts +7 -0
- package/dist/src/graph/registry/DefaultGraphResolver.d.ts.map +1 -0
- package/dist/src/graph/registry/DefaultGraphResolver.js +30 -0
- package/dist/src/graph/registry/DefaultGraphResolver.js.map +1 -0
- package/dist/src/graph/registry/GraphMiddleware.d.ts +12 -0
- package/dist/src/graph/registry/GraphMiddleware.d.ts.map +1 -0
- package/dist/src/graph/registry/GraphMiddleware.js +25 -0
- package/dist/src/graph/registry/GraphMiddleware.js.map +1 -0
- package/dist/src/graph/registry/GraphMiddlewareChain.d.ts +12 -0
- package/dist/src/graph/registry/GraphMiddlewareChain.d.ts.map +1 -0
- package/dist/src/graph/registry/GraphMiddlewareChain.js +30 -0
- package/dist/src/graph/registry/GraphMiddlewareChain.js.map +1 -0
- package/dist/src/graph/registry/GraphRegistry.d.ts +22 -0
- package/dist/src/graph/registry/GraphRegistry.d.ts.map +1 -0
- package/dist/src/graph/registry/GraphRegistry.js +65 -0
- package/dist/src/graph/registry/GraphRegistry.js.map +1 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +24 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/injectHook.d.ts +5 -0
- package/dist/src/injectHook.d.ts.map +1 -0
- package/dist/src/injectHook.js +30 -0
- package/dist/src/injectHook.js.map +1 -0
- package/dist/src/injectors/components/ComponentInjector.d.ts +9 -0
- package/dist/src/injectors/components/ComponentInjector.d.ts.map +1 -0
- package/dist/src/injectors/components/ComponentInjector.js +48 -0
- package/dist/src/injectors/components/ComponentInjector.js.map +1 -0
- package/dist/src/injectors/components/PropsInjector.d.ts +7 -0
- package/dist/src/injectors/components/PropsInjector.d.ts.map +1 -0
- package/dist/src/injectors/components/PropsInjector.js +19 -0
- package/dist/src/injectors/components/PropsInjector.js.map +1 -0
- package/dist/src/injectors/components/useGraph.d.ts +5 -0
- package/dist/src/injectors/components/useGraph.d.ts.map +1 -0
- package/dist/src/injectors/components/useGraph.js +17 -0
- package/dist/src/injectors/components/useGraph.js.map +1 -0
- package/dist/test/integration/fixtures/InjectedComponent.d.ts +8 -0
- package/dist/test/integration/fixtures/InjectedComponent.d.ts.map +1 -0
- package/dist/test/integration/fixtures/InjectedComponent.js +14 -0
- package/dist/test/integration/fixtures/InjectedComponent.js.map +1 -0
- package/dist/test/integration/fixtures/MainGraph.d.ts +6 -0
- package/dist/test/integration/fixtures/MainGraph.d.ts.map +1 -0
- package/dist/test/integration/fixtures/MainGraph.js +53 -0
- package/dist/test/integration/fixtures/MainGraph.js.map +1 -0
- package/dist/test/integration/fixtures/StringProvider.d.ts +5 -0
- package/dist/test/integration/fixtures/StringProvider.d.ts.map +1 -0
- package/dist/test/integration/fixtures/StringProvider.js +15 -0
- package/dist/test/integration/fixtures/StringProvider.js.map +1 -0
- package/dist/test/integration/fixtures/Subgraph.d.ts +8 -0
- package/dist/test/integration/fixtures/Subgraph.d.ts.map +1 -0
- package/dist/test/integration/fixtures/Subgraph.js +71 -0
- package/dist/test/integration/fixtures/Subgraph.js.map +1 -0
- package/dist/test/integration/fixtures/ThrowingMainGraph.d.ts +5 -0
- package/dist/test/integration/fixtures/ThrowingMainGraph.d.ts.map +1 -0
- package/dist/test/integration/fixtures/ThrowingMainGraph.js +52 -0
- package/dist/test/integration/fixtures/ThrowingMainGraph.js.map +1 -0
- package/dist/test/integration/fixtures/injectedValues.d.ts +6 -0
- package/dist/test/integration/fixtures/injectedValues.d.ts.map +1 -0
- package/dist/test/integration/fixtures/injectedValues.js +7 -0
- package/dist/test/integration/fixtures/injectedValues.js.map +1 -0
- package/dist/testkit/index.d.ts +8 -0
- package/dist/testkit/index.d.ts.map +1 -0
- package/dist/testkit/index.js +46 -0
- package/dist/testkit/index.js.map +1 -0
- package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.d.ts +9 -0
- package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.d.ts.map +1 -0
- package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.js +54 -0
- package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.js.map +1 -0
- package/dist/transformers/babel-plugin-obsidian-provide/index.d.ts +3 -0
- package/dist/transformers/babel-plugin-obsidian-provide/index.d.ts.map +1 -0
- package/dist/transformers/babel-plugin-obsidian-provide/index.js +35 -0
- package/dist/transformers/babel-plugin-obsidian-provide/index.js.map +1 -0
- package/example/.buckconfig +6 -0
- package/example/.editorconfig +3 -0
- package/example/.eslintrc.js +4 -0
- package/example/.flowconfig +65 -0
- package/example/.gitattributes +3 -0
- package/example/.prettierrc.js +7 -0
- package/example/.watchmanconfig +1 -0
- package/example/App.tsx +31 -0
- package/example/MyInjectedComponent.tsx +28 -0
- package/example/__tests__/App-test.js +14 -0
- package/example/android/app/BUCK +55 -0
- package/example/android/app/build.gradle +227 -0
- package/example/android/app/build_defs.bzl +19 -0
- package/example/android/app/debug.keystore +0 -0
- package/example/android/app/proguard-rules.pro +10 -0
- package/example/android/app/src/debug/AndroidManifest.xml +13 -0
- package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +72 -0
- package/example/android/app/src/main/AndroidManifest.xml +25 -0
- package/example/android/app/src/main/java/com/example/MainActivity.java +15 -0
- package/example/android/app/src/main/java/com/example/MainApplication.java +80 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +3 -0
- package/example/android/app/src/main/res/values/styles.xml +8 -0
- package/example/android/build.gradle +38 -0
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/example/android/gradle.properties +28 -0
- package/example/android/gradlew +185 -0
- package/example/android/gradlew.bat +89 -0
- package/example/android/settings.gradle +3 -0
- package/example/app.json +4 -0
- package/example/babel.config.js +8 -0
- package/example/index.js +9 -0
- package/example/ios/Podfile +30 -0
- package/example/ios/Podfile.lock +526 -0
- package/example/ios/example/AppDelegate.h +8 -0
- package/example/ios/example/AppDelegate.m +62 -0
- package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +38 -0
- package/example/ios/example/Images.xcassets/Contents.json +6 -0
- package/example/ios/example/Info.plist +55 -0
- package/example/ios/example/LaunchScreen.storyboard +47 -0
- package/example/ios/example/main.m +9 -0
- package/example/ios/example.xcodeproj/project.pbxproj +689 -0
- package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -0
- package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -0
- package/example/ios/exampleTests/Info.plist +24 -0
- package/example/ios/exampleTests/exampleTests.m +65 -0
- package/example/metro.config.js +44 -0
- package/example/package.json +35 -0
- package/example/tsconfig.json +45 -0
- package/jest.config.js +12 -0
- package/package.json +79 -0
- package/src/@types/obsidian.d.ts +19 -0
- package/src/GraphProperties.ts +11 -0
- package/src/Obsidian.ts +18 -0
- package/src/ProvidedPropertiesStore.ts +22 -0
- package/src/Provides.ts +16 -0
- package/src/ReferenceCounter.ts +20 -0
- package/src/ScopedValuesRegistry.ts +26 -0
- package/src/decorators/Graph.ts +20 -0
- package/src/decorators/injectClass.ts +28 -0
- package/src/graph/Graph.ts +7 -0
- package/src/graph/ObjectGraph.ts +19 -0
- package/src/graph/PropertyRetriever.ts +36 -0
- package/src/graph/PropertyRetrieverDelegate.ts +5 -0
- package/src/graph/registry/DefaultGraphResolver.ts +9 -0
- package/src/graph/registry/GraphMiddleware.ts +24 -0
- package/src/graph/registry/GraphMiddlewareChain.ts +31 -0
- package/src/graph/registry/GraphRegistry.ts +70 -0
- package/src/index.ts +23 -0
- package/src/injectHook.ts +26 -0
- package/src/injectors/components/ComponentInjector.tsx +29 -0
- package/src/injectors/components/PropsInjector.ts +14 -0
- package/src/injectors/components/useGraph.ts +14 -0
- package/testkit/index.ts +25 -0
- package/transformers/babel-plugin-obsidian-provide/helpers/index.ts +59 -0
- package/transformers/babel-plugin-obsidian-provide/index.ts +44 -0
- package/tsconfig.base.json +43 -0
- package/tsconfig.json +3 -0
- package/tsconfig.prod.json +7 -0
|
File without changes
|
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist/*
|
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"env": {
|
|
4
|
+
"es2021": true,
|
|
5
|
+
"jest": true
|
|
6
|
+
},
|
|
7
|
+
"extends": [
|
|
8
|
+
"airbnb-base",
|
|
9
|
+
"airbnb-typescript",
|
|
10
|
+
"plugin:react/recommended",
|
|
11
|
+
"plugin:@typescript-eslint/recommended",
|
|
12
|
+
"plugin:import/typescript"
|
|
13
|
+
],
|
|
14
|
+
"parser": "@typescript-eslint/parser",
|
|
15
|
+
"parserOptions": {
|
|
16
|
+
"project": "./tsconfig.json",
|
|
17
|
+
"ecmaVersion": 2021,
|
|
18
|
+
"sourceType": "module",
|
|
19
|
+
"ecmaFeatures": {
|
|
20
|
+
"jsx": true
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"plugins": [
|
|
24
|
+
"react",
|
|
25
|
+
"@typescript-eslint",
|
|
26
|
+
"import-newlines"
|
|
27
|
+
],
|
|
28
|
+
"rules": {
|
|
29
|
+
"max-len": ["error", {"code": 115}],
|
|
30
|
+
"lines-between-class-members": ["error", "always", {"exceptAfterSingleLine": true}],
|
|
31
|
+
"import/extensions": "off",
|
|
32
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
|
33
|
+
"no-useless-constructor": "off",
|
|
34
|
+
"@typescript-eslint/member-delimiter-style": "error",
|
|
35
|
+
"import/no-unresolved": "off",
|
|
36
|
+
"class-methods-use-this": "off",
|
|
37
|
+
"react/jsx-filename-extension": ["error", {"extensions": [".js", ".ts", ".jsx", ".tsx"]}],
|
|
38
|
+
"react/jsx-props-no-spreading": "off",
|
|
39
|
+
"no-use-before-define": "off",
|
|
40
|
+
"@typescript-eslint/no-use-before-define": ["off"],
|
|
41
|
+
"no-restricted-syntax": "off",
|
|
42
|
+
"import/no-named-as-default": "off",
|
|
43
|
+
"@typescript-eslint/ban-types": ["off"],
|
|
44
|
+
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
|
|
45
|
+
"max-classes-per-file": ["off"],
|
|
46
|
+
"curly": ["error", "multi-line"],
|
|
47
|
+
"semi": ["error", "always"],
|
|
48
|
+
"comma-dangle": ["error", "always-multiline"],
|
|
49
|
+
"function-call-argument-newline": ["error", "consistent"],
|
|
50
|
+
"function-paren-newline": ["error", "multiline-arguments"],
|
|
51
|
+
"object-curly-newline": [
|
|
52
|
+
"error",
|
|
53
|
+
{
|
|
54
|
+
"ObjectExpression": {
|
|
55
|
+
"multiline": true,
|
|
56
|
+
"consistent": true
|
|
57
|
+
},
|
|
58
|
+
"ObjectPattern": {
|
|
59
|
+
"multiline": true,
|
|
60
|
+
"consistent": true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"no-whitespace-before-property": "error",
|
|
65
|
+
"import-newlines/enforce": [
|
|
66
|
+
"error",
|
|
67
|
+
{
|
|
68
|
+
"items": 3,
|
|
69
|
+
"max-len": 115,
|
|
70
|
+
"semi": false
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"react/display-name": "off",
|
|
74
|
+
"no-plusplus": "off",
|
|
75
|
+
"no-trailing-spaces": "error",
|
|
76
|
+
"no-shadow": "off",
|
|
77
|
+
"@typescript-eslint/no-shadow": ["error", {"allow": ["Graph"]}],
|
|
78
|
+
"react/button-has-type": "off",
|
|
79
|
+
"react/jsx-one-expression-per-line": ["off"],
|
|
80
|
+
"arrow-body-style": ["off"],
|
|
81
|
+
"quotes": ["error", "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
|
|
82
|
+
"@typescript-eslint/lines-between-class-members": "off",
|
|
83
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
84
|
+
"@typescript-eslint/no-unused-vars": "error"
|
|
85
|
+
},
|
|
86
|
+
"settings": {
|
|
87
|
+
"import/resolver": {
|
|
88
|
+
"node": {
|
|
89
|
+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
12
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 by Guy Carmeli
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# react-obsidian
|
|
2
|
+
|
|
3
|
+
> Dependency injection framework for React and React Native applications
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
``` shell
|
|
8
|
+
npm install react-obsidian
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Declare an object graph
|
|
14
|
+
Before we can inject dependencies into hooks, components and classes, we first need to declare our dependencies. Dependencies are declared in classes called "Graphs" where the relationships between the dependencies are outlined.
|
|
15
|
+
|
|
16
|
+
In the `ApplicationGraph` example below, we declare two dependencies:
|
|
17
|
+
1. `httpClient`
|
|
18
|
+
2. `biLogger`
|
|
19
|
+
|
|
20
|
+
Both functions are annotated by the `@Provides()` annotation. This signals Obsidian that the results of these functions are provided by the graph and can be injected.
|
|
21
|
+
|
|
22
|
+
Notice how the biLogger function receives an `httpClient` as an argument. This means that `biLogger` has a dependency on `httpClient`. Obsidian will create an `httpClient` when `biLogger` is injected.
|
|
23
|
+
|
|
24
|
+
``` typescript
|
|
25
|
+
@Graph()
|
|
26
|
+
export default class ApplicationGraph extends ObjectGraph {
|
|
27
|
+
@Provides()
|
|
28
|
+
httpClient(): HttpClient {
|
|
29
|
+
return new HttpClient();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Provides()
|
|
33
|
+
biLogger(httpClient: HttpClient): BiLogger {
|
|
34
|
+
return new BiLogger(httpClient);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Component injection
|
|
40
|
+
```typescript
|
|
41
|
+
import {injectComponent} from 'react-obsidian';
|
|
42
|
+
|
|
43
|
+
interface InjectedComponentProps {
|
|
44
|
+
biLogger: BiLogger;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// When injecting components - we must use destructuring in order for Obsidian to know which dependencies to inject.
|
|
48
|
+
const InjectedComponent = ({ biLogger }: InjectedComponentProps) => (
|
|
49
|
+
<>
|
|
50
|
+
<button onclick={biLogger.logButtonClick}>Click Me</button>
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export default injectComponent(InjectedComponent, ApplicationGraph);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Hooks injection
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface UseButtonPressProps {
|
|
61
|
+
biLogger: BiLogger;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface UseButtonPress {
|
|
65
|
+
usePress: () => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Similarly to how dependencies are injected into hooks, we must use destructuring for Obsidian to be able to inject the dependencies.
|
|
69
|
+
const useButtonClick = ({ biLogger }: UseButtonPressProps): UseButtonPress => {
|
|
70
|
+
const onClick = useCallback(() => {
|
|
71
|
+
biLogger.logButtonClick();
|
|
72
|
+
}, [biLogger]);
|
|
73
|
+
|
|
74
|
+
return { onClick };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Dependencies are injected from ApplicationGraph
|
|
78
|
+
export default injectHook(usePress, ApplicationGraph);
|
|
79
|
+
|
|
80
|
+
// Now that exported the injected hook, we can use it in a component without needed so provide it's dependencies manually
|
|
81
|
+
const Component = () => (
|
|
82
|
+
// No need to specify dependencies as they are injected automatically
|
|
83
|
+
const { onClick } = useButtonClick();
|
|
84
|
+
<>
|
|
85
|
+
<button onclick={onClick}>Click Me</button>
|
|
86
|
+
</>
|
|
87
|
+
);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Class injection
|
|
91
|
+
Obsidian supports injected class properties. Constructor injection is not supported at this time.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
@Injectable(ApplicationGraph)
|
|
95
|
+
class ButtonController {
|
|
96
|
+
@Inject biLogger!: BiLogger;
|
|
97
|
+
|
|
98
|
+
onClick() {
|
|
99
|
+
this.biLogger.logButtonClick();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Obtaining dependencies from a graph
|
|
105
|
+
Dependencies can also be obtained by accessing the graph that provides them.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
Obsidian.obtain(ApplicationGraph).biLogger();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
> 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.
|
|
112
|
+
|
|
113
|
+
## Prerequisites
|
|
114
|
+
Obsidian is highly opinionated and is developed with a specific environment in mind. Therefore, it has a few prerequisites for projects that want to integrate it.
|
|
115
|
+
|
|
116
|
+
### TypeScript
|
|
117
|
+
Obsidian targets TypeScript projects. There are no plans to officially support pure JS environments.
|
|
118
|
+
|
|
119
|
+
### Reflect-metadata
|
|
120
|
+
Install and enable the reflect-metadata polyfill.
|
|
121
|
+
* `npm install reflect-metadata`
|
|
122
|
+
* `import 'reflect-metadata';` - this needs to be done once, typically in your application's entry point (index.ts).
|
|
123
|
+
|
|
124
|
+
### Enable experimental decorators
|
|
125
|
+
Obsidian uses the Decorators feature whose proposal is still stage 2.
|
|
126
|
+
|
|
127
|
+
Add the following options to your `tsconfig.json` file.
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"compilerOptions": {
|
|
131
|
+
"types": ["reflect-metadata", "jest"],
|
|
132
|
+
"experimentalDecorators": true,
|
|
133
|
+
"emitDecoratorMetadata": true
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Babel
|
|
139
|
+
Obsidian relies on reflection to resolve dependencies. Production code is typically mangled to reduce bundle size. This means that some names Obsidian expects are changed during the mangling process. To workaround this, Obsidian persists the names of methods annotated with the `@Provides` decorator with a Babel transformer.
|
|
140
|
+
|
|
141
|
+
### Add Obsidian's babel transformer
|
|
142
|
+
Add the transformer to the list of plugins in your `.babel` file.
|
|
143
|
+
```js
|
|
144
|
+
module.exports = {
|
|
145
|
+
presets: ['module:metro-react-native-babel-preset'],
|
|
146
|
+
plugins: [
|
|
147
|
+
['@babel/plugin-proposal-decorators', {legacy: true}],
|
|
148
|
+
['@babel/plugin-proposal-class-properties', {legacy: true}],
|
|
149
|
+
[`${__dirname}/../dist/transformers/babel-plugin-obsidian-provide`],
|
|
150
|
+
],
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## Related
|
|
157
|
+
|
|
158
|
+
* [InversifyJS](https://github.com/inversify/InversifyJS)
|
|
159
|
+
* [tsyringe](https://github.com/microsoft/tsyringe)
|
|
160
|
+
* [Dagger](https://github.com/google/dagger)
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
presets: [
|
|
3
|
+
['@babel/preset-env', { targets: { node: 'current' } }],
|
|
4
|
+
'@babel/preset-typescript',
|
|
5
|
+
'@babel/preset-react',
|
|
6
|
+
],
|
|
7
|
+
plugins: [
|
|
8
|
+
`${__dirname}/dist/transformers/babel-plugin-obsidian-provide`,
|
|
9
|
+
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
10
|
+
['@babel/plugin-proposal-class-properties', { legacy: true }],
|
|
11
|
+
],
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphProperties.d.ts","sourceRoot":"","sources":["../../src/GraphProperties.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,CAAC,0BAA0B,CAA6B;IAE/D,GAAG,CAAC,kBAAkB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM;IAI5D,kBAAkB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAGlE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var GraphProperties = /** @class */ (function () {
|
|
4
|
+
function GraphProperties() {
|
|
5
|
+
this.unmangledToMangledPropKeys = new Map();
|
|
6
|
+
}
|
|
7
|
+
GraphProperties.prototype.add = function (mangledPropertyKey, unmangledPropertyKey) {
|
|
8
|
+
this.unmangledToMangledPropKeys.set(unmangledPropertyKey, mangledPropertyKey);
|
|
9
|
+
};
|
|
10
|
+
GraphProperties.prototype.getMangledProperty = function (unmangledProperty) {
|
|
11
|
+
return this.unmangledToMangledPropKeys.get(unmangledProperty);
|
|
12
|
+
};
|
|
13
|
+
return GraphProperties;
|
|
14
|
+
}());
|
|
15
|
+
exports.default = GraphProperties;
|
|
16
|
+
//# sourceMappingURL=GraphProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphProperties.js","sourceRoot":"","sources":["../../src/GraphProperties.ts"],"names":[],"mappings":";;AAAA;IAAA;QACU,+BAA0B,GAAG,IAAI,GAAG,EAAkB,CAAC;IASjE,CAAC;IAPC,6BAAG,GAAH,UAAI,kBAA0B,EAAE,oBAA4B;QAC1D,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,CAAC;IAChF,CAAC;IAED,4CAAkB,GAAlB,UAAmB,iBAAyB;QAC1C,OAAO,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAChE,CAAC;IACH,sBAAC;AAAD,CAAC,AAVD,IAUC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Constructable, ServiceLocator } from '@Obsidian';
|
|
2
|
+
import ObjectGraph from './graph/ObjectGraph';
|
|
3
|
+
import { GraphMiddleware } from './graph/registry/GraphMiddleware';
|
|
4
|
+
export default class Obsidian {
|
|
5
|
+
obtain<T extends ObjectGraph<P>, P = any>(Graph: Constructable<T>, props?: P): ServiceLocator<T>;
|
|
6
|
+
addGraphMiddleware(middleware: GraphMiddleware): void;
|
|
7
|
+
clearGraphMiddlewares(): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=Obsidian.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Obsidian.d.ts","sourceRoot":"","sources":["../../src/Obsidian.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,WAAW,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,MAAM,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAIhG,kBAAkB,CAAC,UAAU,EAAE,eAAe;IAI9C,qBAAqB;CAGtB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
var GraphRegistry_1 = __importDefault(require("./graph/registry/GraphRegistry"));
|
|
7
|
+
var Obsidian = /** @class */ (function () {
|
|
8
|
+
function Obsidian() {
|
|
9
|
+
}
|
|
10
|
+
Obsidian.prototype.obtain = function (Graph, props) {
|
|
11
|
+
return GraphRegistry_1.default.resolve(Graph, props);
|
|
12
|
+
};
|
|
13
|
+
Obsidian.prototype.addGraphMiddleware = function (middleware) {
|
|
14
|
+
GraphRegistry_1.default.addGraphMiddleware(middleware);
|
|
15
|
+
};
|
|
16
|
+
Obsidian.prototype.clearGraphMiddlewares = function () {
|
|
17
|
+
GraphRegistry_1.default.clearGraphMiddlewares();
|
|
18
|
+
};
|
|
19
|
+
return Obsidian;
|
|
20
|
+
}());
|
|
21
|
+
exports.default = Obsidian;
|
|
22
|
+
//# sourceMappingURL=Obsidian.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Obsidian.js","sourceRoot":"","sources":["../../src/Obsidian.ts"],"names":[],"mappings":";;;;;AACA,iFAA2D;AAI3D;IAAA;IAYA,CAAC;IAXC,yBAAM,GAAN,UAA0C,KAAuB,EAAE,KAAS;QAC1E,OAAO,uBAAa,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAiC,CAAC;IAC7E,CAAC;IAED,qCAAkB,GAAlB,UAAmB,UAA2B;QAC5C,uBAAa,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,wCAAqB,GAArB;QACE,uBAAa,CAAC,qBAAqB,EAAE,CAAC;IACxC,CAAC;IACH,eAAC;AAAD,CAAC,AAZD,IAYC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Graph from './graph/Graph';
|
|
2
|
+
declare class ProvidedPropertiesStore {
|
|
3
|
+
private readonly providedPropertiesForGraph;
|
|
4
|
+
getMangledProperty(graph: Graph, unmangledProp: string): string | undefined;
|
|
5
|
+
set(graph: Graph, mangledProperty: string, unmangledProperty: string): void;
|
|
6
|
+
clear(graph: Graph): void;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: ProvidedPropertiesStore;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=ProvidedPropertiesStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProvidedPropertiesStore.d.ts","sourceRoot":"","sources":["../../src/ProvidedPropertiesStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,eAAe,CAAC;AAElC,cAAM,uBAAuB;IAC3B,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAA2C;IAEtF,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI3E,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;IAMpE,KAAK,CAAC,KAAK,EAAE,KAAK;CAGnB;;AAED,wBAA6C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
var GraphProperties_1 = __importDefault(require("./GraphProperties"));
|
|
7
|
+
var ProvidedPropertiesStore = /** @class */ (function () {
|
|
8
|
+
function ProvidedPropertiesStore() {
|
|
9
|
+
this.providedPropertiesForGraph = new Map();
|
|
10
|
+
}
|
|
11
|
+
ProvidedPropertiesStore.prototype.getMangledProperty = function (graph, unmangledProp) {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = this.providedPropertiesForGraph.get(graph.name)) === null || _a === void 0 ? void 0 : _a.getMangledProperty(unmangledProp);
|
|
14
|
+
};
|
|
15
|
+
ProvidedPropertiesStore.prototype.set = function (graph, mangledProperty, unmangledProperty) {
|
|
16
|
+
var _a;
|
|
17
|
+
var graphProperties = (_a = this.providedPropertiesForGraph.get(graph.name)) !== null && _a !== void 0 ? _a : new GraphProperties_1.default();
|
|
18
|
+
graphProperties.add(mangledProperty, unmangledProperty);
|
|
19
|
+
this.providedPropertiesForGraph.set(graph.name, graphProperties);
|
|
20
|
+
};
|
|
21
|
+
ProvidedPropertiesStore.prototype.clear = function (graph) {
|
|
22
|
+
this.providedPropertiesForGraph.delete(graph.name);
|
|
23
|
+
};
|
|
24
|
+
return ProvidedPropertiesStore;
|
|
25
|
+
}());
|
|
26
|
+
exports.default = new ProvidedPropertiesStore();
|
|
27
|
+
//# sourceMappingURL=ProvidedPropertiesStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProvidedPropertiesStore.js","sourceRoot":"","sources":["../../src/ProvidedPropertiesStore.ts"],"names":[],"mappings":";;;;;AAAA,sEAAgD;AAGhD;IAAA;QACmB,+BAA0B,GAAiC,IAAI,GAAG,EAAE,CAAC;IAexF,CAAC;IAbC,oDAAkB,GAAlB,UAAmB,KAAY,EAAE,aAAqB;;QACpD,OAAO,MAAA,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,0CAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;IAC5F,CAAC;IAED,qCAAG,GAAH,UAAI,KAAY,EAAE,eAAuB,EAAE,iBAAyB;;QAClE,IAAM,eAAe,GAAG,MAAA,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,mCAAI,IAAI,yBAAe,EAAE,CAAC;QACjG,eAAe,CAAC,GAAG,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;QACxD,IAAI,CAAC,0BAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACnE,CAAC;IAED,uCAAK,GAAL,UAAM,KAAY;QAChB,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IACH,8BAAC;AAAD,CAAC,AAhBD,IAgBC;AAED,kBAAe,IAAI,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Scope } from '@Obsidian';
|
|
2
|
+
import Graph from './graph/Graph';
|
|
3
|
+
interface ProvidesParams {
|
|
4
|
+
scope?: Scope;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
declare function Provides({ name }?: Partial<ProvidesParams>): (graph: Graph, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
8
|
+
export default Provides;
|
|
9
|
+
//# sourceMappingURL=Provides.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provides.d.ts","sourceRoot":"","sources":["../../src/Provides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,eAAe,CAAC;AAGlC,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,iBAAS,QAAQ,CAAC,EAAE,IAAI,EAAE,GAAE,OAAO,CAAC,cAAc,CAAM,WACvB,KAAK,eAAe,MAAM,cAAc,kBAAkB,wBAI1F;AACD,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
var ProvidedPropertiesStore_1 = __importDefault(require("./ProvidedPropertiesStore"));
|
|
7
|
+
function Provides(_a) {
|
|
8
|
+
var _b = _a === void 0 ? {} : _a, name = _b.name;
|
|
9
|
+
return function provide(graph, propertyKey, descriptor) {
|
|
10
|
+
ProvidedPropertiesStore_1.default.set(graph, propertyKey, name);
|
|
11
|
+
return descriptor;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.default = Provides;
|
|
15
|
+
//# sourceMappingURL=Provides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provides.js","sourceRoot":"","sources":["../../src/Provides.ts"],"names":[],"mappings":";;;;;AAEA,sFAAgE;AAOhE,SAAS,QAAQ,CAAC,EAAsC;QAAtC,qBAAoC,EAAE,KAAA,EAApC,IAAI,UAAA;IACtB,OAAO,SAAS,OAAO,CAAC,KAAY,EAAE,WAAmB,EAAE,UAA8B;QACvF,iCAAuB,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,IAAK,CAAC,CAAC;QACvD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AACD,kBAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare class ReferenceCounter {
|
|
2
|
+
private readonly references;
|
|
3
|
+
retain(object: any): void;
|
|
4
|
+
release<T extends object>(object: T, onReleased: (_object: T) => void): void;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: ReferenceCounter;
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=ReferenceCounter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReferenceCounter.d.ts","sourceRoot":"","sources":["../../src/ReferenceCounter.ts"],"names":[],"mappings":"AAAA,cAAM,gBAAgB;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;IAE5D,MAAM,CAAC,MAAM,EAAE,GAAG;IAKlB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI;CAStE;;AAED,wBAAsC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ReferenceCounter = /** @class */ (function () {
|
|
4
|
+
function ReferenceCounter() {
|
|
5
|
+
this.references = new WeakMap();
|
|
6
|
+
}
|
|
7
|
+
ReferenceCounter.prototype.retain = function (object) {
|
|
8
|
+
var _a;
|
|
9
|
+
var count = (_a = this.references.get(object)) !== null && _a !== void 0 ? _a : 0;
|
|
10
|
+
this.references.set(object, count + 1);
|
|
11
|
+
};
|
|
12
|
+
ReferenceCounter.prototype.release = function (object, onReleased) {
|
|
13
|
+
var count = this.references.get(object);
|
|
14
|
+
if (count === 1) {
|
|
15
|
+
onReleased(object);
|
|
16
|
+
this.references.delete(object);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.references.set(object, count - 1);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return ReferenceCounter;
|
|
23
|
+
}());
|
|
24
|
+
exports.default = new ReferenceCounter();
|
|
25
|
+
//# sourceMappingURL=ReferenceCounter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReferenceCounter.js","sourceRoot":"","sources":["../../src/ReferenceCounter.ts"],"names":[],"mappings":";;AAAA;IAAA;QACmB,eAAU,GAAG,IAAI,OAAO,EAAkB,CAAC;IAgB9D,CAAC;IAdC,iCAAM,GAAN,UAAO,MAAW;;QAChB,IAAM,KAAK,GAAG,MAAA,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,mCAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,kCAAO,GAAP,UAA0B,MAAS,EAAE,UAAgC;QACnE,IAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC;QAC3C,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,UAAU,CAAC,MAAM,CAAC,CAAC;YACnB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAChC;aAAM;YACL,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;SACxC;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AAjBD,IAiBC;AAED,kBAAe,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Scope } from '@Obsidian';
|
|
2
|
+
declare class ScopedValuesRegistry {
|
|
3
|
+
private readonly values;
|
|
4
|
+
has(scope: Scope, property: string): boolean;
|
|
5
|
+
get(scope: Scope, property: string): any;
|
|
6
|
+
set(scope: Scope, property: string, value: any): void;
|
|
7
|
+
clear(scope: Scope, property: string): void;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: ScopedValuesRegistry;
|
|
10
|
+
export default _default;
|
|
11
|
+
//# sourceMappingURL=ScopedValuesRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScopedValuesRegistry.d.ts","sourceRoot":"","sources":["../../src/ScopedValuesRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,cAAM,oBAAoB;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;IAEtD,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI5C,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG;IAOxC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAI9C,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM;CAGrC;;AAED,wBAA0C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ScopedValuesRegistry = /** @class */ (function () {
|
|
4
|
+
function ScopedValuesRegistry() {
|
|
5
|
+
this.values = new Map();
|
|
6
|
+
}
|
|
7
|
+
ScopedValuesRegistry.prototype.has = function (scope, property) {
|
|
8
|
+
return this.values.has(scope.toString() + property);
|
|
9
|
+
};
|
|
10
|
+
ScopedValuesRegistry.prototype.get = function (scope, property) {
|
|
11
|
+
if (this.values.has(scope.toString() + property)) {
|
|
12
|
+
return this.values.get(scope.toString() + property);
|
|
13
|
+
}
|
|
14
|
+
throw new Error("Property ".concat(property, " does not exist"));
|
|
15
|
+
};
|
|
16
|
+
ScopedValuesRegistry.prototype.set = function (scope, property, value) {
|
|
17
|
+
this.values.set(scope.toString() + property, value);
|
|
18
|
+
};
|
|
19
|
+
ScopedValuesRegistry.prototype.clear = function (scope, property) {
|
|
20
|
+
this.values.delete(scope.toString() + property);
|
|
21
|
+
};
|
|
22
|
+
return ScopedValuesRegistry;
|
|
23
|
+
}());
|
|
24
|
+
exports.default = new ScopedValuesRegistry();
|
|
25
|
+
//# sourceMappingURL=ScopedValuesRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScopedValuesRegistry.js","sourceRoot":"","sources":["../../src/ScopedValuesRegistry.ts"],"names":[],"mappings":";;AAEA;IAAA;QACmB,WAAM,GAAqB,IAAI,GAAG,EAAE,CAAC;IAoBxD,CAAC;IAlBC,kCAAG,GAAH,UAAI,KAAY,EAAE,QAAgB;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,kCAAG,GAAH,UAAI,KAAY,EAAE,QAAgB;QAChC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,EAAE;YAChD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;SACrD;QACD,MAAM,IAAI,KAAK,CAAC,mBAAY,QAAQ,oBAAiB,CAAC,CAAC;IACzD,CAAC;IAED,kCAAG,GAAH,UAAI,KAAY,EAAE,QAAgB,EAAE,KAAU;QAC5C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,oCAAK,GAAL,UAAM,KAAY,EAAE,QAAgB;QAClC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;IAClD,CAAC;IACH,2BAAC;AAAD,CAAC,AArBD,IAqBC;AAED,kBAAe,IAAI,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Constructable, Scope } from '@Obsidian';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import ObjectGraph from '../graph/ObjectGraph';
|
|
4
|
+
interface GraphParams {
|
|
5
|
+
scope: Scope | undefined;
|
|
6
|
+
subgraphs: Constructable<ObjectGraph>[];
|
|
7
|
+
}
|
|
8
|
+
export default function Graph({ scope, subgraphs, }?: Partial<GraphParams>): <T extends ObjectGraph<unknown>>(constructor: Constructable<T>) => Constructable<T>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=Graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../../src/decorators/Graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,kBAAkB,CAAC;AAE1B,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAE/C,UAAU,WAAW;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;CACzC;AAED,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,KAAK,EACL,SAAc,GACf,GAAE,OAAO,CAAC,WAAW,CAAM,uFAM3B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
require("reflect-metadata");
|
|
7
|
+
var GraphRegistry_1 = __importDefault(require("../graph/registry/GraphRegistry"));
|
|
8
|
+
function Graph(_a) {
|
|
9
|
+
var _b = _a === void 0 ? {} : _a, scope = _b.scope, _c = _b.subgraphs, subgraphs = _c === void 0 ? [] : _c;
|
|
10
|
+
return function (constructor) {
|
|
11
|
+
Reflect.defineMetadata('scope', scope, constructor);
|
|
12
|
+
GraphRegistry_1.default.register(constructor, scope, subgraphs);
|
|
13
|
+
return constructor;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.default = Graph;
|
|
17
|
+
//# sourceMappingURL=Graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../../src/decorators/Graph.ts"],"names":[],"mappings":";;;;;AACA,4BAA0B;AAC1B,kFAA4D;AAQ5D,SAAwB,KAAK,CAAC,EAGF;QAHE,qBAGJ,EAAE,KAAA,EAF1B,KAAK,WAAA,EACL,iBAAc,EAAd,SAAS,mBAAG,EAAE,KAAA;IAEd,OAAO,UAAwB,WAA6B;QAC1D,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QACpD,uBAAa,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QACtD,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AATD,wBASC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Constructable } from '@Obsidian';
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectClass.d.ts","sourceRoot":"","sources":["../../../src/decorators/injectClass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAI/C,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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectClass.js","sourceRoot":"","sources":["../../../src/decorators/injectClass.ts"],"names":[],"mappings":";;;;;;AACA,kFAA4D;AAG5D,IAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD,SAAgB,UAAU,CAAyC,KAAiC;IAClG,OAAO,UAAC,MAAS;QACf,IAAM,KAAK,GAAG;YACZ,SAAS,EAAT,UAAU,MAAW,EAAE,IAAW,EAAE,SAAc;;gBAChD,IAAM,YAAY,GAAa,MAAA,OAAO,CAAC,WAAW,CAAC,oBAAoB,EAAE,MAAM,CAAC,mCAAI,EAAE,CAAC;gBAEvF,IAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;gBACjE,IAAM,KAAK,GAAG,uBAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC3C,KAAkB,UAAY,EAAZ,6BAAY,EAAZ,0BAAY,EAAZ,IAAY,EAAE;oBAA3B,IAAM,GAAG,qBAAA;oBACZ,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;iBACtD;gBACD,OAAO,aAAa,CAAC;YACvB,CAAC;SACF,CAAC;QACF,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAhBD,gCAgBC;AAED,SAAgB,MAAM,CAAC,MAAc,EAAE,WAAmB;;IACxD,IAAM,YAAY,GAAG,MAAA,OAAO,CAAC,WAAW,CAAC,oBAAoB,EAAE,MAAM,CAAC,WAAW,CAAC,mCAAI,IAAI,GAAG,EAAE,CAAC;IAChG,OAAO,CAAC,cAAc,CAAC,oBAAoB,EAAE,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;AAClG,CAAC;AAHD,wBAGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../../src/graph/Graph.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AAEpE,UAAU,KAAM,SAAQ,yBAAyB;IAC/C,IAAI,IAAI,IAAI,MAAM,CAAC;CACpB;AAED,eAAe,KAAK,CAAC"}
|