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.
Files changed (216) hide show
  1. package/.buildkite/pipeline.yml +0 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.json +93 -0
  4. package/.nvmrc +1 -0
  5. package/LICENSE +7 -0
  6. package/README.md +160 -0
  7. package/babel.config.js +12 -0
  8. package/dist/src/GraphProperties.d.ts +6 -0
  9. package/dist/src/GraphProperties.d.ts.map +1 -0
  10. package/dist/src/GraphProperties.js +16 -0
  11. package/dist/src/GraphProperties.js.map +1 -0
  12. package/dist/src/Obsidian.d.ts +9 -0
  13. package/dist/src/Obsidian.d.ts.map +1 -0
  14. package/dist/src/Obsidian.js +22 -0
  15. package/dist/src/Obsidian.js.map +1 -0
  16. package/dist/src/ProvidedPropertiesStore.d.ts +10 -0
  17. package/dist/src/ProvidedPropertiesStore.d.ts.map +1 -0
  18. package/dist/src/ProvidedPropertiesStore.js +27 -0
  19. package/dist/src/ProvidedPropertiesStore.js.map +1 -0
  20. package/dist/src/Provides.d.ts +9 -0
  21. package/dist/src/Provides.d.ts.map +1 -0
  22. package/dist/src/Provides.js +15 -0
  23. package/dist/src/Provides.js.map +1 -0
  24. package/dist/src/ReferenceCounter.d.ts +8 -0
  25. package/dist/src/ReferenceCounter.d.ts.map +1 -0
  26. package/dist/src/ReferenceCounter.js +25 -0
  27. package/dist/src/ReferenceCounter.js.map +1 -0
  28. package/dist/src/ScopedValuesRegistry.d.ts +11 -0
  29. package/dist/src/ScopedValuesRegistry.d.ts.map +1 -0
  30. package/dist/src/ScopedValuesRegistry.js +25 -0
  31. package/dist/src/ScopedValuesRegistry.js.map +1 -0
  32. package/dist/src/decorators/Graph.d.ts +10 -0
  33. package/dist/src/decorators/Graph.d.ts.map +1 -0
  34. package/dist/src/decorators/Graph.js +17 -0
  35. package/dist/src/decorators/Graph.js.map +1 -0
  36. package/dist/src/decorators/injectClass.d.ts +7 -0
  37. package/dist/src/decorators/injectClass.d.ts.map +1 -0
  38. package/dist/src/decorators/injectClass.js +34 -0
  39. package/dist/src/decorators/injectClass.js.map +1 -0
  40. package/dist/src/graph/Graph.d.ts +6 -0
  41. package/dist/src/graph/Graph.d.ts.map +1 -0
  42. package/dist/src/graph/Graph.js +3 -0
  43. package/dist/src/graph/Graph.js.map +1 -0
  44. package/dist/src/graph/ObjectGraph.d.ts +11 -0
  45. package/dist/src/graph/ObjectGraph.d.ts.map +1 -0
  46. package/dist/src/graph/ObjectGraph.js +26 -0
  47. package/dist/src/graph/ObjectGraph.js.map +1 -0
  48. package/dist/src/graph/PropertyRetriever.d.ts +8 -0
  49. package/dist/src/graph/PropertyRetriever.d.ts.map +1 -0
  50. package/dist/src/graph/PropertyRetriever.js +40 -0
  51. package/dist/src/graph/PropertyRetriever.js.map +1 -0
  52. package/dist/src/graph/PropertyRetrieverDelegate.d.ts +5 -0
  53. package/dist/src/graph/PropertyRetrieverDelegate.d.ts.map +1 -0
  54. package/dist/src/graph/PropertyRetrieverDelegate.js +3 -0
  55. package/dist/src/graph/PropertyRetrieverDelegate.js.map +1 -0
  56. package/dist/src/graph/registry/DefaultGraphResolver.d.ts +7 -0
  57. package/dist/src/graph/registry/DefaultGraphResolver.d.ts.map +1 -0
  58. package/dist/src/graph/registry/DefaultGraphResolver.js +30 -0
  59. package/dist/src/graph/registry/DefaultGraphResolver.js.map +1 -0
  60. package/dist/src/graph/registry/GraphMiddleware.d.ts +12 -0
  61. package/dist/src/graph/registry/GraphMiddleware.d.ts.map +1 -0
  62. package/dist/src/graph/registry/GraphMiddleware.js +25 -0
  63. package/dist/src/graph/registry/GraphMiddleware.js.map +1 -0
  64. package/dist/src/graph/registry/GraphMiddlewareChain.d.ts +12 -0
  65. package/dist/src/graph/registry/GraphMiddlewareChain.d.ts.map +1 -0
  66. package/dist/src/graph/registry/GraphMiddlewareChain.js +30 -0
  67. package/dist/src/graph/registry/GraphMiddlewareChain.js.map +1 -0
  68. package/dist/src/graph/registry/GraphRegistry.d.ts +22 -0
  69. package/dist/src/graph/registry/GraphRegistry.d.ts.map +1 -0
  70. package/dist/src/graph/registry/GraphRegistry.js +65 -0
  71. package/dist/src/graph/registry/GraphRegistry.js.map +1 -0
  72. package/dist/src/index.d.ts +17 -0
  73. package/dist/src/index.d.ts.map +1 -0
  74. package/dist/src/index.js +24 -0
  75. package/dist/src/index.js.map +1 -0
  76. package/dist/src/injectHook.d.ts +5 -0
  77. package/dist/src/injectHook.d.ts.map +1 -0
  78. package/dist/src/injectHook.js +30 -0
  79. package/dist/src/injectHook.js.map +1 -0
  80. package/dist/src/injectors/components/ComponentInjector.d.ts +9 -0
  81. package/dist/src/injectors/components/ComponentInjector.d.ts.map +1 -0
  82. package/dist/src/injectors/components/ComponentInjector.js +48 -0
  83. package/dist/src/injectors/components/ComponentInjector.js.map +1 -0
  84. package/dist/src/injectors/components/PropsInjector.d.ts +7 -0
  85. package/dist/src/injectors/components/PropsInjector.d.ts.map +1 -0
  86. package/dist/src/injectors/components/PropsInjector.js +19 -0
  87. package/dist/src/injectors/components/PropsInjector.js.map +1 -0
  88. package/dist/src/injectors/components/useGraph.d.ts +5 -0
  89. package/dist/src/injectors/components/useGraph.d.ts.map +1 -0
  90. package/dist/src/injectors/components/useGraph.js +17 -0
  91. package/dist/src/injectors/components/useGraph.js.map +1 -0
  92. package/dist/test/integration/fixtures/InjectedComponent.d.ts +8 -0
  93. package/dist/test/integration/fixtures/InjectedComponent.d.ts.map +1 -0
  94. package/dist/test/integration/fixtures/InjectedComponent.js +14 -0
  95. package/dist/test/integration/fixtures/InjectedComponent.js.map +1 -0
  96. package/dist/test/integration/fixtures/MainGraph.d.ts +6 -0
  97. package/dist/test/integration/fixtures/MainGraph.d.ts.map +1 -0
  98. package/dist/test/integration/fixtures/MainGraph.js +53 -0
  99. package/dist/test/integration/fixtures/MainGraph.js.map +1 -0
  100. package/dist/test/integration/fixtures/StringProvider.d.ts +5 -0
  101. package/dist/test/integration/fixtures/StringProvider.d.ts.map +1 -0
  102. package/dist/test/integration/fixtures/StringProvider.js +15 -0
  103. package/dist/test/integration/fixtures/StringProvider.js.map +1 -0
  104. package/dist/test/integration/fixtures/Subgraph.d.ts +8 -0
  105. package/dist/test/integration/fixtures/Subgraph.d.ts.map +1 -0
  106. package/dist/test/integration/fixtures/Subgraph.js +71 -0
  107. package/dist/test/integration/fixtures/Subgraph.js.map +1 -0
  108. package/dist/test/integration/fixtures/ThrowingMainGraph.d.ts +5 -0
  109. package/dist/test/integration/fixtures/ThrowingMainGraph.d.ts.map +1 -0
  110. package/dist/test/integration/fixtures/ThrowingMainGraph.js +52 -0
  111. package/dist/test/integration/fixtures/ThrowingMainGraph.js.map +1 -0
  112. package/dist/test/integration/fixtures/injectedValues.d.ts +6 -0
  113. package/dist/test/integration/fixtures/injectedValues.d.ts.map +1 -0
  114. package/dist/test/integration/fixtures/injectedValues.js +7 -0
  115. package/dist/test/integration/fixtures/injectedValues.js.map +1 -0
  116. package/dist/testkit/index.d.ts +8 -0
  117. package/dist/testkit/index.d.ts.map +1 -0
  118. package/dist/testkit/index.js +46 -0
  119. package/dist/testkit/index.js.map +1 -0
  120. package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.d.ts +9 -0
  121. package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.d.ts.map +1 -0
  122. package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.js +54 -0
  123. package/dist/transformers/babel-plugin-obsidian-provide/helpers/index.js.map +1 -0
  124. package/dist/transformers/babel-plugin-obsidian-provide/index.d.ts +3 -0
  125. package/dist/transformers/babel-plugin-obsidian-provide/index.d.ts.map +1 -0
  126. package/dist/transformers/babel-plugin-obsidian-provide/index.js +35 -0
  127. package/dist/transformers/babel-plugin-obsidian-provide/index.js.map +1 -0
  128. package/example/.buckconfig +6 -0
  129. package/example/.editorconfig +3 -0
  130. package/example/.eslintrc.js +4 -0
  131. package/example/.flowconfig +65 -0
  132. package/example/.gitattributes +3 -0
  133. package/example/.prettierrc.js +7 -0
  134. package/example/.watchmanconfig +1 -0
  135. package/example/App.tsx +31 -0
  136. package/example/MyInjectedComponent.tsx +28 -0
  137. package/example/__tests__/App-test.js +14 -0
  138. package/example/android/app/BUCK +55 -0
  139. package/example/android/app/build.gradle +227 -0
  140. package/example/android/app/build_defs.bzl +19 -0
  141. package/example/android/app/debug.keystore +0 -0
  142. package/example/android/app/proguard-rules.pro +10 -0
  143. package/example/android/app/src/debug/AndroidManifest.xml +13 -0
  144. package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +72 -0
  145. package/example/android/app/src/main/AndroidManifest.xml +25 -0
  146. package/example/android/app/src/main/java/com/example/MainActivity.java +15 -0
  147. package/example/android/app/src/main/java/com/example/MainApplication.java +80 -0
  148. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  149. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  150. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  151. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  152. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  153. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  154. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  155. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  156. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  157. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  158. package/example/android/app/src/main/res/values/strings.xml +3 -0
  159. package/example/android/app/src/main/res/values/styles.xml +8 -0
  160. package/example/android/build.gradle +38 -0
  161. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  162. package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  163. package/example/android/gradle.properties +28 -0
  164. package/example/android/gradlew +185 -0
  165. package/example/android/gradlew.bat +89 -0
  166. package/example/android/settings.gradle +3 -0
  167. package/example/app.json +4 -0
  168. package/example/babel.config.js +8 -0
  169. package/example/index.js +9 -0
  170. package/example/ios/Podfile +30 -0
  171. package/example/ios/Podfile.lock +526 -0
  172. package/example/ios/example/AppDelegate.h +8 -0
  173. package/example/ios/example/AppDelegate.m +62 -0
  174. package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +38 -0
  175. package/example/ios/example/Images.xcassets/Contents.json +6 -0
  176. package/example/ios/example/Info.plist +55 -0
  177. package/example/ios/example/LaunchScreen.storyboard +47 -0
  178. package/example/ios/example/main.m +9 -0
  179. package/example/ios/example.xcodeproj/project.pbxproj +689 -0
  180. package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -0
  181. package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -0
  182. package/example/ios/exampleTests/Info.plist +24 -0
  183. package/example/ios/exampleTests/exampleTests.m +65 -0
  184. package/example/metro.config.js +44 -0
  185. package/example/package.json +35 -0
  186. package/example/tsconfig.json +45 -0
  187. package/jest.config.js +12 -0
  188. package/package.json +79 -0
  189. package/src/@types/obsidian.d.ts +19 -0
  190. package/src/GraphProperties.ts +11 -0
  191. package/src/Obsidian.ts +18 -0
  192. package/src/ProvidedPropertiesStore.ts +22 -0
  193. package/src/Provides.ts +16 -0
  194. package/src/ReferenceCounter.ts +20 -0
  195. package/src/ScopedValuesRegistry.ts +26 -0
  196. package/src/decorators/Graph.ts +20 -0
  197. package/src/decorators/injectClass.ts +28 -0
  198. package/src/graph/Graph.ts +7 -0
  199. package/src/graph/ObjectGraph.ts +19 -0
  200. package/src/graph/PropertyRetriever.ts +36 -0
  201. package/src/graph/PropertyRetrieverDelegate.ts +5 -0
  202. package/src/graph/registry/DefaultGraphResolver.ts +9 -0
  203. package/src/graph/registry/GraphMiddleware.ts +24 -0
  204. package/src/graph/registry/GraphMiddlewareChain.ts +31 -0
  205. package/src/graph/registry/GraphRegistry.ts +70 -0
  206. package/src/index.ts +23 -0
  207. package/src/injectHook.ts +26 -0
  208. package/src/injectors/components/ComponentInjector.tsx +29 -0
  209. package/src/injectors/components/PropsInjector.ts +14 -0
  210. package/src/injectors/components/useGraph.ts +14 -0
  211. package/testkit/index.ts +25 -0
  212. package/transformers/babel-plugin-obsidian-provide/helpers/index.ts +59 -0
  213. package/transformers/babel-plugin-obsidian-provide/index.ts +44 -0
  214. package/tsconfig.base.json +43 -0
  215. package/tsconfig.json +3 -0
  216. package/tsconfig.prod.json +7 -0
@@ -0,0 +1,88 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Scheme
3
+ LastUpgradeVersion = "1210"
4
+ version = "1.3">
5
+ <BuildAction
6
+ parallelizeBuildables = "YES"
7
+ buildImplicitDependencies = "YES">
8
+ <BuildActionEntries>
9
+ <BuildActionEntry
10
+ buildForTesting = "YES"
11
+ buildForRunning = "YES"
12
+ buildForProfiling = "YES"
13
+ buildForArchiving = "YES"
14
+ buildForAnalyzing = "YES">
15
+ <BuildableReference
16
+ BuildableIdentifier = "primary"
17
+ BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
18
+ BuildableName = "example.app"
19
+ BlueprintName = "example"
20
+ ReferencedContainer = "container:example.xcodeproj">
21
+ </BuildableReference>
22
+ </BuildActionEntry>
23
+ </BuildActionEntries>
24
+ </BuildAction>
25
+ <TestAction
26
+ buildConfiguration = "Debug"
27
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29
+ shouldUseLaunchSchemeArgsEnv = "YES">
30
+ <Testables>
31
+ <TestableReference
32
+ skipped = "NO">
33
+ <BuildableReference
34
+ BuildableIdentifier = "primary"
35
+ BlueprintIdentifier = "00E356ED1AD99517003FC87E"
36
+ BuildableName = "exampleTests.xctest"
37
+ BlueprintName = "exampleTests"
38
+ ReferencedContainer = "container:example.xcodeproj">
39
+ </BuildableReference>
40
+ </TestableReference>
41
+ </Testables>
42
+ </TestAction>
43
+ <LaunchAction
44
+ buildConfiguration = "Debug"
45
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
46
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
47
+ launchStyle = "0"
48
+ useCustomWorkingDirectory = "NO"
49
+ ignoresPersistentStateOnLaunch = "NO"
50
+ debugDocumentVersioning = "YES"
51
+ debugServiceExtension = "internal"
52
+ allowLocationSimulation = "YES">
53
+ <BuildableProductRunnable
54
+ runnableDebuggingMode = "0">
55
+ <BuildableReference
56
+ BuildableIdentifier = "primary"
57
+ BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
58
+ BuildableName = "example.app"
59
+ BlueprintName = "example"
60
+ ReferencedContainer = "container:example.xcodeproj">
61
+ </BuildableReference>
62
+ </BuildableProductRunnable>
63
+ </LaunchAction>
64
+ <ProfileAction
65
+ buildConfiguration = "Release"
66
+ shouldUseLaunchSchemeArgsEnv = "YES"
67
+ savedToolIdentifier = ""
68
+ useCustomWorkingDirectory = "NO"
69
+ debugDocumentVersioning = "YES">
70
+ <BuildableProductRunnable
71
+ runnableDebuggingMode = "0">
72
+ <BuildableReference
73
+ BuildableIdentifier = "primary"
74
+ BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
75
+ BuildableName = "example.app"
76
+ BlueprintName = "example"
77
+ ReferencedContainer = "container:example.xcodeproj">
78
+ </BuildableReference>
79
+ </BuildableProductRunnable>
80
+ </ProfileAction>
81
+ <AnalyzeAction
82
+ buildConfiguration = "Debug">
83
+ </AnalyzeAction>
84
+ <ArchiveAction
85
+ buildConfiguration = "Release"
86
+ revealArchiveInOrganizer = "YES">
87
+ </ArchiveAction>
88
+ </Scheme>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "group:example.xcodeproj">
6
+ </FileRef>
7
+ <FileRef
8
+ location = "group:Pods/Pods.xcodeproj">
9
+ </FileRef>
10
+ </Workspace>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>en</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>BNDL</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleSignature</key>
20
+ <string>????</string>
21
+ <key>CFBundleVersion</key>
22
+ <string>1</string>
23
+ </dict>
24
+ </plist>
@@ -0,0 +1,65 @@
1
+ #import <UIKit/UIKit.h>
2
+ #import <XCTest/XCTest.h>
3
+
4
+ #import <React/RCTLog.h>
5
+ #import <React/RCTRootView.h>
6
+
7
+ #define TIMEOUT_SECONDS 600
8
+ #define TEXT_TO_LOOK_FOR @"Welcome to React"
9
+
10
+ @interface exampleTests : XCTestCase
11
+
12
+ @end
13
+
14
+ @implementation exampleTests
15
+
16
+ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
17
+ {
18
+ if (test(view)) {
19
+ return YES;
20
+ }
21
+ for (UIView *subview in [view subviews]) {
22
+ if ([self findSubviewInView:subview matching:test]) {
23
+ return YES;
24
+ }
25
+ }
26
+ return NO;
27
+ }
28
+
29
+ - (void)testRendersWelcomeScreen
30
+ {
31
+ UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
32
+ NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
33
+ BOOL foundElement = NO;
34
+
35
+ __block NSString *redboxError = nil;
36
+ #ifdef DEBUG
37
+ RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
38
+ if (level >= RCTLogLevelError) {
39
+ redboxError = message;
40
+ }
41
+ });
42
+ #endif
43
+
44
+ while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
45
+ [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
46
+ [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
47
+
48
+ foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
49
+ if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
50
+ return YES;
51
+ }
52
+ return NO;
53
+ }];
54
+ }
55
+
56
+ #ifdef DEBUG
57
+ RCTSetLogFunction(RCTDefaultLogFunction);
58
+ #endif
59
+
60
+ XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
61
+ XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
62
+ }
63
+
64
+
65
+ @end
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Metro configuration for React Native
3
+ * https://github.com/facebook/react-native
4
+ *
5
+ * @format
6
+ */
7
+
8
+ const path = require('path');
9
+ const exclusionList = require('metro-config/src/defaults/exclusionList');
10
+ const root = path.resolve(__dirname, '..');
11
+ const pj = require('../package.json');
12
+ const modules = Object.keys({
13
+ ...pj.peerDependencies,
14
+ });
15
+
16
+ module.exports = {
17
+ projectRoot: __dirname,
18
+ watchFolders: [root],
19
+
20
+ // We need to make sure that only one version is loaded for peerDependencies
21
+ // So we blacklist them at the root, and alias them to the versions in example's node_modules
22
+ resolver: {
23
+ blacklistRE: exclusionList(
24
+ modules.map(
25
+ m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`),
26
+ ),
27
+ ),
28
+
29
+ extraNodeModules: modules.reduce((acc, name) => {
30
+ acc[name] = path.join(__dirname, 'node_modules', name);
31
+ return acc;
32
+ }, {}),
33
+ },
34
+
35
+ transformer: {
36
+ // eslint-disable-next-line require-await
37
+ getTransformOptions: async () => ({
38
+ transform: {
39
+ experimentalImportSupport: true,
40
+ inlineRequires: true,
41
+ },
42
+ }),
43
+ },
44
+ };
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "ReactNativeExample",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "scripts": {
6
+ "android": "react-native run-android",
7
+ "ios": "react-native run-ios",
8
+ "start": "react-native start",
9
+ "test": "jest",
10
+ "lint": "eslint ."
11
+ },
12
+ "dependencies": {
13
+ "react": "17.0.2",
14
+ "react-native": "0.66.2"
15
+ },
16
+ "devDependencies": {
17
+ "@babel/core": "7.16.0",
18
+ "@babel/plugin-proposal-decorators": "7.16.0",
19
+ "@babel/plugin-proposal-class-properties": "7.16.0",
20
+ "@babel/preset-typescript": "7.16.0",
21
+ "@babel/runtime": "7.16.0",
22
+ "@types/react-native": "0.66.3",
23
+ "@react-native-community/eslint-config": "2.0.0",
24
+ "babel-jest": "26.6.3",
25
+ "eslint": "7.14.0",
26
+ "jest": "26.6.3",
27
+ "metro-react-native-babel-preset": "0.66.2",
28
+ "react-test-renderer": "17.0.2",
29
+ "typescript": "^4.4.4",
30
+ "react-obsidian": "../"
31
+ },
32
+ "jest": {
33
+ "preset": "react-native"
34
+ }
35
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "include": [
3
+ "**/*",
4
+ ],
5
+ "exclude": [
6
+ "node_modules",
7
+ "dist",
8
+ "babel.config.js",
9
+ "metro.config.js",
10
+ "jest.config.js"
11
+ ],
12
+ "compilerOptions": {
13
+ "target": "esnext",
14
+ "module": "esnext",
15
+ "lib": [
16
+ "es2017",
17
+ ],
18
+ "moduleResolution": "node",
19
+ "outDir": "./dist",
20
+ "declaration": true,
21
+ "declarationMap": true,
22
+ "sourceMap": true,
23
+ "strict": true,
24
+ "noImplicitReturns": true,
25
+ "noFallthroughCasesInSwitch": true,
26
+ "noUnusedLocals": true,
27
+ "noUnusedParameters": true,
28
+ "noImplicitOverride": true,
29
+ "noPropertyAccessFromIndexSignature": true,
30
+ "forceConsistentCasingInFileNames": true,
31
+ "jsx": "react-native",
32
+ "esModuleInterop": true,
33
+ "isolatedModules": true,
34
+ "resolveJsonModule": true,
35
+ "experimentalDecorators": true,
36
+ "allowJs": true,
37
+ "allowSyntheticDefaultImports": true,
38
+ "types": ["reflect-metadata", "jest"],
39
+ "emitDecoratorMetadata": true,
40
+ "baseUrl": "./",
41
+ "paths": {
42
+ "@Obsidian": ["../src/@types/obsidian.d.ts"]
43
+ }
44
+ }
45
+ }
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
1
+ const config = {
2
+ resetMocks: true,
3
+ resetModules: true,
4
+ roots: [
5
+ 'node_modules',
6
+ 'src',
7
+ 'transformers',
8
+ 'test',
9
+ ],
10
+ };
11
+
12
+ module.exports = config;
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "react-obsidian",
3
+ "version": "0.0.1",
4
+ "description": "Dependency injection framework for React and React Native applications",
5
+ "main": "src/index.ts",
6
+ "directories": {
7
+ "test": "test"
8
+ },
9
+ "dependencies": {
10
+ "hoist-non-react-statics": "3.x.x",
11
+ "reflect-metadata": "~0.1.13"
12
+ },
13
+ "peerDependencies": {
14
+ "react": "*"
15
+ },
16
+ "devDependencies": {
17
+ "@babel/core": "7.16.x",
18
+ "@babel/generator": "7.16.x",
19
+ "@babel/plugin-proposal-class-properties": "7.16.x",
20
+ "@babel/plugin-proposal-decorators": "7.16.x",
21
+ "@babel/preset-env": "7.16.x",
22
+ "@babel/preset-react": "7.16.x",
23
+ "@babel/preset-typescript": "7.16.x",
24
+ "@babel/types": "7.16.x",
25
+ "@johanblumenberg/ts-mockito": "1.x.x",
26
+ "@testing-library/react": "^12.1.2",
27
+ "@types/hoist-non-react-statics": "^3.3.1",
28
+ "@types/jest": "26.x.x",
29
+ "@types/lodash": "^4.14.176",
30
+ "@types/react": "^17.0.34",
31
+ "@types/react-dom": "^17.0.11",
32
+ "@types/react-test-renderer": "17.0.1",
33
+ "@typescript-eslint/eslint-plugin": "^5.3.0",
34
+ "@typescript-eslint/parser": "^5.3.0",
35
+ "eslint": "^7.32.0",
36
+ "eslint-config-airbnb-typescript": "^16.0.0",
37
+ "eslint-plugin-import": "^2.25.2",
38
+ "eslint-plugin-import-newlines": "^1.1.5",
39
+ "eslint-plugin-jsx-a11y": "^6.4.1",
40
+ "eslint-plugin-react": "^7.26.1",
41
+ "eslint-plugin-react-hooks": "^4.2.0",
42
+ "jest": "26.x.x",
43
+ "lodash": "^4.17.21",
44
+ "react": "17.0.2",
45
+ "react-dom": "17.0.2",
46
+ "typescript": "^4.4.4"
47
+ },
48
+ "scripts": {
49
+ "prepack": "npm run lint && tsc --project tsconfig.prod.json",
50
+ "lint": "npx eslint src transformers test --ignore-pattern '*.d.ts' --ext .ts,.tsx,.js",
51
+ "pretest": "tsc",
52
+ "test": "npx jest"
53
+ },
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/wix-incubator/react-obsidian.git"
57
+ },
58
+ "keywords": [
59
+ "react",
60
+ "react-native",
61
+ "dependency-injection",
62
+ "typescript",
63
+ "ioc"
64
+ ],
65
+ "contributors": [
66
+ {
67
+ "name": "Artal Druk"
68
+ },
69
+ {
70
+ "name": "Guy Carmeli"
71
+ }
72
+ ],
73
+ "author": "Guy Carmeli",
74
+ "license": "ISC",
75
+ "bugs": {
76
+ "url": "https://github.com/wix-incubator/react-obsidian/issues"
77
+ },
78
+ "homepage": "https://github.com/wix-incubator/react-obsidian#readme"
79
+ }
@@ -0,0 +1,19 @@
1
+ import ObjectGraph from '../graph/ObjectGraph';
2
+
3
+ type Constructable<T> = {
4
+ new(...args: any): T;
5
+ };
6
+
7
+ type GraphClass<T extends ObjectGraph<P>, P> = {
8
+ new(props?: P): T;
9
+ };
10
+
11
+ type Scope = string | number | symbol;
12
+
13
+ type Constructor = { new(...args: any[]): any };
14
+
15
+ type GraphType = { new(...args: any[]): ObjectGraph };
16
+
17
+ type ServiceLocator<Clazz> = {
18
+ [Key in keyof Clazz]: Function
19
+ };
@@ -0,0 +1,11 @@
1
+ export default class GraphProperties {
2
+ private unmangledToMangledPropKeys = new Map<string, string>();
3
+
4
+ add(mangledPropertyKey: string, unmangledPropertyKey: string) {
5
+ this.unmangledToMangledPropKeys.set(unmangledPropertyKey, mangledPropertyKey);
6
+ }
7
+
8
+ getMangledProperty(unmangledProperty: string): string | undefined {
9
+ return this.unmangledToMangledPropKeys.get(unmangledProperty);
10
+ }
11
+ }
@@ -0,0 +1,18 @@
1
+ import { Constructable, ServiceLocator } from '@Obsidian';
2
+ import graphRegistry from './graph/registry/GraphRegistry';
3
+ import ObjectGraph from './graph/ObjectGraph';
4
+ import { GraphMiddleware } from './graph/registry/GraphMiddleware';
5
+
6
+ export default class Obsidian {
7
+ obtain<T extends ObjectGraph<P>, P = any>(Graph: Constructable<T>, props?: P): ServiceLocator<T> {
8
+ return graphRegistry.resolve(Graph, props) as unknown as ServiceLocator<T>;
9
+ }
10
+
11
+ addGraphMiddleware(middleware: GraphMiddleware) {
12
+ graphRegistry.addGraphMiddleware(middleware);
13
+ }
14
+
15
+ clearGraphMiddlewares() {
16
+ graphRegistry.clearGraphMiddlewares();
17
+ }
18
+ }
@@ -0,0 +1,22 @@
1
+ import GraphProperties from './GraphProperties';
2
+ import Graph from './graph/Graph';
3
+
4
+ class ProvidedPropertiesStore {
5
+ private readonly providedPropertiesForGraph: Map<string, GraphProperties> = new Map();
6
+
7
+ getMangledProperty(graph: Graph, unmangledProp: string): string | undefined {
8
+ return this.providedPropertiesForGraph.get(graph.name)?.getMangledProperty(unmangledProp);
9
+ }
10
+
11
+ set(graph: Graph, mangledProperty: string, unmangledProperty: string) {
12
+ const graphProperties = this.providedPropertiesForGraph.get(graph.name) ?? new GraphProperties();
13
+ graphProperties.add(mangledProperty, unmangledProperty);
14
+ this.providedPropertiesForGraph.set(graph.name, graphProperties);
15
+ }
16
+
17
+ clear(graph: Graph) {
18
+ this.providedPropertiesForGraph.delete(graph.name);
19
+ }
20
+ }
21
+
22
+ export default new ProvidedPropertiesStore();
@@ -0,0 +1,16 @@
1
+ import { Scope } from '@Obsidian';
2
+ import Graph from './graph/Graph';
3
+ import providedPropertiesStore from './ProvidedPropertiesStore';
4
+
5
+ interface ProvidesParams {
6
+ scope?: Scope;
7
+ name: string;
8
+ }
9
+
10
+ function Provides({ name }: Partial<ProvidesParams> = {}) {
11
+ return function provide(graph: Graph, propertyKey: string, descriptor: PropertyDescriptor) {
12
+ providedPropertiesStore.set(graph, propertyKey, name!);
13
+ return descriptor;
14
+ };
15
+ }
16
+ export default Provides;
@@ -0,0 +1,20 @@
1
+ class ReferenceCounter {
2
+ private readonly references = new WeakMap<object, number>();
3
+
4
+ retain(object: any) {
5
+ const count = this.references.get(object) ?? 0;
6
+ this.references.set(object, count + 1);
7
+ }
8
+
9
+ release<T extends object>(object: T, onReleased: (_object: T) => void) {
10
+ const count = this.references.get(object)!;
11
+ if (count === 1) {
12
+ onReleased(object);
13
+ this.references.delete(object);
14
+ } else {
15
+ this.references.set(object, count - 1);
16
+ }
17
+ }
18
+ }
19
+
20
+ export default new ReferenceCounter();
@@ -0,0 +1,26 @@
1
+ import { Scope } from '@Obsidian';
2
+
3
+ class ScopedValuesRegistry {
4
+ private readonly values: Map<string, any> = new Map();
5
+
6
+ has(scope: Scope, property: string): boolean {
7
+ return this.values.has(scope.toString() + property);
8
+ }
9
+
10
+ get(scope: Scope, property: string): any {
11
+ if (this.values.has(scope.toString() + property)) {
12
+ return this.values.get(scope.toString() + property);
13
+ }
14
+ throw new Error(`Property ${property} does not exist`);
15
+ }
16
+
17
+ set(scope: Scope, property: string, value: any) {
18
+ this.values.set(scope.toString() + property, value);
19
+ }
20
+
21
+ clear(scope: Scope, property: string) {
22
+ this.values.delete(scope.toString() + property);
23
+ }
24
+ }
25
+
26
+ export default new ScopedValuesRegistry();
@@ -0,0 +1,20 @@
1
+ import { Constructable, Scope } from '@Obsidian';
2
+ import 'reflect-metadata';
3
+ import graphRegistry from '../graph/registry/GraphRegistry';
4
+ import ObjectGraph from '../graph/ObjectGraph';
5
+
6
+ interface GraphParams {
7
+ scope: Scope | undefined;
8
+ subgraphs: Constructable<ObjectGraph>[];
9
+ }
10
+
11
+ export default function Graph({
12
+ scope,
13
+ subgraphs = [],
14
+ }: Partial<GraphParams> = {}) {
15
+ return <T extends ObjectGraph>(constructor: Constructable<T>) => {
16
+ Reflect.defineMetadata('scope', scope, constructor);
17
+ graphRegistry.register(constructor, scope, subgraphs);
18
+ return constructor;
19
+ };
20
+ }
@@ -0,0 +1,28 @@
1
+ import { Constructable } from '@Obsidian';
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
+ }
@@ -0,0 +1,7 @@
1
+ import PropertyRetrieverDelegate from './PropertyRetrieverDelegate';
2
+
3
+ interface Graph extends PropertyRetrieverDelegate {
4
+ get name(): string;
5
+ }
6
+
7
+ export default Graph;
@@ -0,0 +1,19 @@
1
+ import { Scope } from '@Obsidian';
2
+ import Graph from './Graph';
3
+ import PropertyRetriever from './PropertyRetriever';
4
+
5
+ export default abstract class ObjectGraph<T = unknown> implements Graph {
6
+ // TODO? rename scope to singleInstance
7
+ public scope!: Scope;
8
+ private propertyRetriever = new PropertyRetriever(this);
9
+ get name(): string {
10
+ return this.constructor.name;
11
+ }
12
+
13
+ // eslint-disable-next-line no-useless-constructor, no-unused-vars, no-empty-function
14
+ constructor(protected props?: T) {}
15
+
16
+ retrieve<Dependency>(property: string, receiver?: unknown): Dependency | undefined {
17
+ return this.propertyRetriever.retrieve(property, receiver) as Dependency | undefined;
18
+ }
19
+ }
@@ -0,0 +1,36 @@
1
+ import graphRegistry from './registry/GraphRegistry';
2
+ import Graph from './Graph';
3
+ import providedPropertiesStore from '../ProvidedPropertiesStore';
4
+
5
+ export default class PropertyRetriever {
6
+ constructor(private graph: Graph) { }
7
+
8
+ retrieve(property: string, receiver?: unknown): unknown | undefined {
9
+ const mangledPropertyKey = providedPropertiesStore.getMangledProperty(this.graph, property);
10
+ if (mangledPropertyKey && mangledPropertyKey in this.graph) {
11
+ const proxiedGraph = new Proxy(this.graph, {
12
+ get(graph: Graph, dependencyName: string) {
13
+ return graph.retrieve(dependencyName);
14
+ },
15
+ });
16
+ return Reflect.get(this.graph, mangledPropertyKey, receiver)(proxiedGraph);
17
+ }
18
+
19
+ const results = this.getFromSubgraphs(property, receiver);
20
+ if (results.length === 1) return results[0];
21
+ if (results.length > 1) {
22
+ throw new Error(
23
+ `Multiple subgraphs provide the property ${property}.`
24
+ + 'You should probably provide a unique name to one of the providers: @Provide({name: \'uniqueName\')})',
25
+ );
26
+ }
27
+ return undefined;
28
+ }
29
+
30
+ private getFromSubgraphs(property: string, receiver: unknown): unknown[] {
31
+ const subgraphs = graphRegistry.getSubgraphs(this.graph);
32
+ return subgraphs
33
+ .map((subgraph: Graph) => subgraph.retrieve(property, receiver))
34
+ .filter((result) => result !== undefined);
35
+ }
36
+ }
@@ -0,0 +1,5 @@
1
+ interface PropertyRetrieverDelegate {
2
+ retrieve: (property: string, receiver?: unknown) => unknown | undefined;
3
+ }
4
+
5
+ export default PropertyRetrieverDelegate;