nitrogen 0.2.24 → 0.29.4

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 (333) hide show
  1. package/README.md +15 -109
  2. package/lib/Logger.d.ts +10 -0
  3. package/lib/Logger.js +56 -0
  4. package/lib/autolinking/Autolinking.d.ts +8 -0
  5. package/lib/autolinking/Autolinking.js +1 -0
  6. package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
  7. package/lib/autolinking/android/createCMakeExtension.js +106 -0
  8. package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
  9. package/lib/autolinking/android/createGradleExtension.js +36 -0
  10. package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
  11. package/lib/autolinking/android/createHybridObjectInitializer.js +159 -0
  12. package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
  13. package/lib/autolinking/createAndroidAutolinking.js +13 -0
  14. package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
  15. package/lib/autolinking/createIOSAutolinking.js +19 -0
  16. package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
  17. package/lib/autolinking/ios/createHybridObjectInitializer.js +97 -0
  18. package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
  19. package/lib/autolinking/ios/createPodspecRubyExtension.js +69 -0
  20. package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
  21. package/lib/autolinking/ios/createSwiftCxxBridge.js +117 -0
  22. package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
  23. package/lib/autolinking/ios/createSwiftUmbrellaHeader.js +74 -0
  24. package/lib/config/NitroConfig.d.ts +52 -0
  25. package/lib/config/NitroConfig.js +112 -0
  26. package/lib/config/NitroUserConfig.d.ts +22 -0
  27. package/lib/config/NitroUserConfig.js +88 -0
  28. package/lib/config/getConfig.d.ts +2 -0
  29. package/lib/config/getConfig.js +84 -0
  30. package/lib/createGitAttributes.d.ts +1 -0
  31. package/lib/createGitAttributes.js +11 -0
  32. package/lib/createPlatformSpec.d.ts +4 -0
  33. package/lib/createPlatformSpec.js +127 -0
  34. package/lib/getFiles.d.ts +1 -0
  35. package/lib/getFiles.js +28 -0
  36. package/lib/getPlatformSpecs.d.ts +17 -0
  37. package/lib/getPlatformSpecs.js +153 -0
  38. package/lib/index.d.ts +2 -0
  39. package/lib/index.js +113 -10
  40. package/lib/init.d.ts +1 -0
  41. package/lib/init.js +123 -0
  42. package/lib/nitrogen.d.ts +11 -0
  43. package/lib/nitrogen.js +165 -0
  44. package/lib/prettifyDirectory.d.ts +1 -0
  45. package/lib/prettifyDirectory.js +27 -0
  46. package/lib/syntax/BridgedType.d.ts +41 -0
  47. package/lib/syntax/BridgedType.js +1 -0
  48. package/lib/syntax/CodeNode.d.ts +23 -0
  49. package/lib/syntax/CodeNode.js +1 -0
  50. package/lib/syntax/HybridObjectSpec.d.ts +13 -0
  51. package/lib/syntax/HybridObjectSpec.js +1 -0
  52. package/lib/syntax/Method.d.ts +41 -0
  53. package/lib/syntax/Method.js +108 -0
  54. package/lib/syntax/Parameter.d.ts +15 -0
  55. package/lib/syntax/Parameter.js +65 -0
  56. package/lib/syntax/Property.d.ts +50 -0
  57. package/lib/syntax/Property.js +147 -0
  58. package/lib/syntax/SourceFile.d.ts +70 -0
  59. package/lib/syntax/SourceFile.js +7 -0
  60. package/lib/syntax/c++/CppEnum.d.ts +6 -0
  61. package/lib/syntax/c++/CppEnum.js +110 -0
  62. package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
  63. package/lib/syntax/c++/CppHybridObject.js +146 -0
  64. package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
  65. package/lib/syntax/c++/CppHybridObjectRegistration.js +18 -0
  66. package/lib/syntax/c++/CppStruct.d.ts +3 -0
  67. package/lib/syntax/c++/CppStruct.js +108 -0
  68. package/lib/syntax/c++/CppUnion.d.ts +6 -0
  69. package/lib/syntax/c++/CppUnion.js +88 -0
  70. package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
  71. package/lib/syntax/c++/getForwardDeclaration.js +14 -0
  72. package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
  73. package/lib/syntax/c++/includeNitroHeader.js +34 -0
  74. package/lib/syntax/createType.d.ts +15 -0
  75. package/lib/syntax/createType.js +303 -0
  76. package/lib/syntax/getAllTypes.d.ts +3 -0
  77. package/lib/syntax/getAllTypes.js +11 -0
  78. package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
  79. package/lib/syntax/getCustomTypeConfig.js +53 -0
  80. package/lib/syntax/getHybridObjectName.d.ts +36 -0
  81. package/lib/syntax/getHybridObjectName.js +10 -0
  82. package/lib/syntax/getInterfaceProperties.d.ts +4 -0
  83. package/lib/syntax/getInterfaceProperties.js +9 -0
  84. package/lib/syntax/getReferencedTypes.d.ts +2 -0
  85. package/lib/syntax/getReferencedTypes.js +47 -0
  86. package/lib/syntax/helpers.d.ts +13 -0
  87. package/lib/syntax/helpers.js +53 -0
  88. package/lib/syntax/isCoreType.d.ts +9 -0
  89. package/lib/syntax/isCoreType.js +47 -0
  90. package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
  91. package/lib/syntax/kotlin/FbjniHybridObject.js +261 -0
  92. package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
  93. package/lib/syntax/kotlin/JNINativeRegistrations.js +7 -0
  94. package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
  95. package/lib/syntax/kotlin/KotlinBoxedPrimitive.js +17 -0
  96. package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
  97. package/lib/syntax/kotlin/KotlinCxxBridgedType.js +893 -0
  98. package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
  99. package/lib/syntax/kotlin/KotlinEnum.js +113 -0
  100. package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
  101. package/lib/syntax/kotlin/KotlinFunction.js +256 -0
  102. package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
  103. package/lib/syntax/kotlin/KotlinHybridObject.js +177 -0
  104. package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
  105. package/lib/syntax/kotlin/KotlinHybridObjectRegistration.js +26 -0
  106. package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
  107. package/lib/syntax/kotlin/KotlinStruct.js +172 -0
  108. package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
  109. package/lib/syntax/kotlin/KotlinVariant.js +191 -0
  110. package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
  111. package/lib/syntax/swift/SwiftCxxBridgedType.js +819 -0
  112. package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +17 -0
  113. package/lib/syntax/swift/SwiftCxxTypeHelper.js +613 -0
  114. package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
  115. package/lib/syntax/swift/SwiftEnum.js +52 -0
  116. package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
  117. package/lib/syntax/swift/SwiftFunction.js +83 -0
  118. package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
  119. package/lib/syntax/swift/SwiftHybridObject.js +103 -0
  120. package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
  121. package/lib/syntax/swift/SwiftHybridObjectBridge.js +451 -0
  122. package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
  123. package/lib/syntax/swift/SwiftHybridObjectRegistration.js +42 -0
  124. package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
  125. package/lib/syntax/swift/SwiftStruct.js +75 -0
  126. package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
  127. package/lib/syntax/swift/SwiftVariant.js +58 -0
  128. package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
  129. package/lib/syntax/types/ArrayBufferType.js +37 -0
  130. package/lib/syntax/types/ArrayType.d.ts +12 -0
  131. package/lib/syntax/types/ArrayType.js +52 -0
  132. package/lib/syntax/types/BigIntType.d.ts +10 -0
  133. package/lib/syntax/types/BigIntType.js +27 -0
  134. package/lib/syntax/types/BooleanType.d.ts +10 -0
  135. package/lib/syntax/types/BooleanType.js +27 -0
  136. package/lib/syntax/types/CustomType.d.ts +14 -0
  137. package/lib/syntax/types/CustomType.js +36 -0
  138. package/lib/syntax/types/DateType.d.ts +10 -0
  139. package/lib/syntax/types/DateType.js +35 -0
  140. package/lib/syntax/types/EnumType.d.ts +23 -0
  141. package/lib/syntax/types/EnumType.js +101 -0
  142. package/lib/syntax/types/ErrorType.d.ts +11 -0
  143. package/lib/syntax/types/ErrorType.js +37 -0
  144. package/lib/syntax/types/FunctionType.d.ts +29 -0
  145. package/lib/syntax/types/FunctionType.js +147 -0
  146. package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
  147. package/lib/syntax/types/HybridObjectBaseType.js +38 -0
  148. package/lib/syntax/types/HybridObjectType.d.ts +23 -0
  149. package/lib/syntax/types/HybridObjectType.js +131 -0
  150. package/lib/syntax/types/MapType.d.ts +10 -0
  151. package/lib/syntax/types/MapType.js +37 -0
  152. package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
  153. package/lib/syntax/types/NamedWrappingType.js +27 -0
  154. package/lib/syntax/types/NullType.d.ts +10 -0
  155. package/lib/syntax/types/NullType.js +23 -0
  156. package/lib/syntax/types/NumberType.d.ts +10 -0
  157. package/lib/syntax/types/NumberType.js +27 -0
  158. package/lib/syntax/types/OptionalType.d.ts +13 -0
  159. package/lib/syntax/types/OptionalType.js +59 -0
  160. package/lib/syntax/types/PromiseType.d.ts +16 -0
  161. package/lib/syntax/types/PromiseType.js +62 -0
  162. package/lib/syntax/types/RecordType.d.ts +13 -0
  163. package/lib/syntax/types/RecordType.js +47 -0
  164. package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
  165. package/lib/syntax/types/ResultWrappingType.js +44 -0
  166. package/lib/syntax/types/StringType.d.ts +10 -0
  167. package/lib/syntax/types/StringType.js +35 -0
  168. package/lib/syntax/types/StructType.d.ts +14 -0
  169. package/lib/syntax/types/StructType.js +61 -0
  170. package/lib/syntax/types/TupleType.d.ts +12 -0
  171. package/lib/syntax/types/TupleType.js +39 -0
  172. package/lib/syntax/types/Type.d.ts +55 -0
  173. package/lib/syntax/types/Type.js +1 -0
  174. package/lib/syntax/types/VariantType.d.ts +19 -0
  175. package/lib/syntax/types/VariantType.js +75 -0
  176. package/lib/syntax/types/VoidType.d.ts +10 -0
  177. package/lib/syntax/types/VoidType.js +27 -0
  178. package/lib/syntax/types/getTypeAs.d.ts +2 -0
  179. package/lib/syntax/types/getTypeAs.js +12 -0
  180. package/lib/utils.d.ts +22 -0
  181. package/lib/utils.js +126 -0
  182. package/lib/views/CppHybridViewComponent.d.ts +14 -0
  183. package/lib/views/CppHybridViewComponent.js +254 -0
  184. package/lib/views/createHostComponentJs.d.ts +3 -0
  185. package/lib/views/createHostComponentJs.js +27 -0
  186. package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
  187. package/lib/views/kotlin/KotlinHybridViewManager.js +229 -0
  188. package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
  189. package/lib/views/swift/SwiftHybridViewManager.js +131 -0
  190. package/lib/writeFile.d.ts +5 -0
  191. package/lib/writeFile.js +19 -0
  192. package/package.json +58 -29
  193. package/src/Logger.ts +63 -0
  194. package/src/autolinking/Autolinking.ts +9 -0
  195. package/src/autolinking/android/createCMakeExtension.ts +123 -0
  196. package/src/autolinking/android/createGradleExtension.ts +43 -0
  197. package/src/autolinking/android/createHybridObjectInitializer.ts +174 -0
  198. package/src/autolinking/createAndroidAutolinking.ts +28 -0
  199. package/src/autolinking/createIOSAutolinking.ts +24 -0
  200. package/src/autolinking/ios/createHybridObjectInitializer.ts +112 -0
  201. package/src/autolinking/ios/createPodspecRubyExtension.ts +76 -0
  202. package/src/autolinking/ios/createSwiftCxxBridge.ts +137 -0
  203. package/src/autolinking/ios/createSwiftUmbrellaHeader.ts +90 -0
  204. package/src/config/NitroConfig.ts +139 -0
  205. package/src/config/NitroUserConfig.ts +105 -0
  206. package/src/config/getConfig.ts +91 -0
  207. package/src/createGitAttributes.ts +15 -0
  208. package/src/createPlatformSpec.ts +176 -0
  209. package/src/getFiles.ts +31 -0
  210. package/src/getPlatformSpecs.ts +202 -0
  211. package/src/index.ts +146 -0
  212. package/src/init.ts +186 -0
  213. package/src/nitrogen.ts +246 -0
  214. package/src/prettifyDirectory.ts +32 -0
  215. package/src/syntax/BridgedType.ts +59 -0
  216. package/src/syntax/CodeNode.ts +24 -0
  217. package/src/syntax/HybridObjectSpec.ts +14 -0
  218. package/src/syntax/Method.ts +154 -0
  219. package/src/syntax/Parameter.ts +81 -0
  220. package/src/syntax/Property.ts +203 -0
  221. package/src/syntax/SourceFile.ts +80 -0
  222. package/src/syntax/c++/CppEnum.ts +128 -0
  223. package/src/syntax/c++/CppHybridObject.ts +165 -0
  224. package/src/syntax/c++/CppHybridObjectRegistration.ts +39 -0
  225. package/src/syntax/c++/CppStruct.ts +129 -0
  226. package/src/syntax/c++/CppUnion.ts +105 -0
  227. package/src/syntax/c++/getForwardDeclaration.ts +19 -0
  228. package/src/syntax/c++/includeNitroHeader.ts +40 -0
  229. package/src/syntax/createType.ts +365 -0
  230. package/src/syntax/getAllTypes.ts +18 -0
  231. package/src/syntax/getCustomTypeConfig.ts +71 -0
  232. package/src/syntax/getHybridObjectName.ts +48 -0
  233. package/src/syntax/getInterfaceProperties.ts +21 -0
  234. package/src/syntax/getReferencedTypes.ts +57 -0
  235. package/src/syntax/helpers.ts +79 -0
  236. package/src/syntax/isCoreType.ts +60 -0
  237. package/src/syntax/kotlin/FbjniHybridObject.ts +313 -0
  238. package/src/syntax/kotlin/JNINativeRegistrations.ts +19 -0
  239. package/src/syntax/kotlin/KotlinBoxedPrimitive.ts +19 -0
  240. package/src/syntax/kotlin/KotlinCxxBridgedType.ts +942 -0
  241. package/src/syntax/kotlin/KotlinEnum.ts +130 -0
  242. package/src/syntax/kotlin/KotlinFunction.ts +277 -0
  243. package/src/syntax/kotlin/KotlinHybridObject.ts +205 -0
  244. package/src/syntax/kotlin/KotlinHybridObjectRegistration.ts +51 -0
  245. package/src/syntax/kotlin/KotlinStruct.ts +198 -0
  246. package/src/syntax/kotlin/KotlinVariant.ts +212 -0
  247. package/src/syntax/swift/SwiftCxxBridgedType.ts +874 -0
  248. package/src/syntax/swift/SwiftCxxTypeHelper.ts +674 -0
  249. package/src/syntax/swift/SwiftEnum.ts +65 -0
  250. package/src/syntax/swift/SwiftFunction.ts +91 -0
  251. package/src/syntax/swift/SwiftHybridObject.ts +121 -0
  252. package/src/syntax/swift/SwiftHybridObjectBridge.ts +522 -0
  253. package/src/syntax/swift/SwiftHybridObjectRegistration.ts +75 -0
  254. package/src/syntax/swift/SwiftStruct.ts +85 -0
  255. package/src/syntax/swift/SwiftVariant.ts +67 -0
  256. package/src/syntax/types/ArrayBufferType.ts +49 -0
  257. package/src/syntax/types/ArrayType.ts +62 -0
  258. package/src/syntax/types/BigIntType.ts +35 -0
  259. package/src/syntax/types/BooleanType.ts +35 -0
  260. package/src/syntax/types/CustomType.ts +47 -0
  261. package/src/syntax/types/DateType.ts +43 -0
  262. package/src/syntax/types/EnumType.ts +130 -0
  263. package/src/syntax/types/ErrorType.ts +44 -0
  264. package/src/syntax/types/FunctionType.ts +167 -0
  265. package/src/syntax/types/HybridObjectBaseType.ts +54 -0
  266. package/src/syntax/types/HybridObjectType.ts +198 -0
  267. package/src/syntax/types/MapType.ts +49 -0
  268. package/src/syntax/types/NamedWrappingType.ts +33 -0
  269. package/src/syntax/types/NullType.ts +30 -0
  270. package/src/syntax/types/NumberType.ts +34 -0
  271. package/src/syntax/types/OptionalType.ts +66 -0
  272. package/src/syntax/types/PromiseType.ts +72 -0
  273. package/src/syntax/types/RecordType.ts +56 -0
  274. package/src/syntax/types/ResultWrappingType.ts +53 -0
  275. package/src/syntax/types/StringType.ts +44 -0
  276. package/src/syntax/types/StructType.ts +83 -0
  277. package/src/syntax/types/TupleType.ts +53 -0
  278. package/src/syntax/types/Type.ts +82 -0
  279. package/src/syntax/types/VariantType.ts +92 -0
  280. package/src/syntax/types/VoidType.ts +34 -0
  281. package/src/syntax/types/getTypeAs.ts +15 -0
  282. package/src/utils.ts +162 -0
  283. package/src/views/CppHybridViewComponent.ts +301 -0
  284. package/src/views/createHostComponentJs.ts +34 -0
  285. package/src/views/kotlin/KotlinHybridViewManager.ts +258 -0
  286. package/src/views/swift/SwiftHybridViewManager.ts +153 -0
  287. package/src/writeFile.ts +27 -0
  288. package/.jshintignore +0 -6
  289. package/.jshintrc +0 -3
  290. package/.npmignore +0 -3
  291. package/.travis.yml +0 -13
  292. package/LICENSE +0 -13
  293. package/browser/nitrogen-min.js +0 -3
  294. package/browser/nitrogen.js +0 -6369
  295. package/lib/apiKey.js +0 -67
  296. package/lib/blob.js +0 -57
  297. package/lib/commandManager.js +0 -350
  298. package/lib/device.js +0 -19
  299. package/lib/memoryStore.js +0 -24
  300. package/lib/message.js +0 -298
  301. package/lib/permission.js +0 -121
  302. package/lib/principal.js +0 -330
  303. package/lib/service.js +0 -347
  304. package/lib/session.js +0 -494
  305. package/lib/user.js +0 -20
  306. package/publish +0 -2
  307. package/scripts/build-documentation +0 -4
  308. package/scripts/build-module +0 -27
  309. package/scripts/module.js +0 -12
  310. package/scripts/postamble.js +0 -1
  311. package/scripts/preamble.js +0 -2
  312. package/scripts/run-test-server +0 -9
  313. package/test/config.js +0 -12
  314. package/test/fixtures/images/image.jpg +0 -0
  315. package/test/fixtures/images/motion0.jpg +0 -0
  316. package/test/fixtures/images/motion1.jpg +0 -0
  317. package/test/fixtures/images/motion2.jpg +0 -0
  318. package/test/fixtures/index.js +0 -76
  319. package/test/main.js +0 -5
  320. package/test/memoryStore.js +0 -22
  321. package/test/mocha.opts +0 -3
  322. package/test/units/apiKey.js +0 -46
  323. package/test/units/blob.js +0 -35
  324. package/test/units/commandManager.js +0 -67
  325. package/test/units/device.js +0 -26
  326. package/test/units/heartbeat.js +0 -28
  327. package/test/units/message.js +0 -79
  328. package/test/units/permissions.js +0 -43
  329. package/test/units/principal.js +0 -116
  330. package/test/units/service.js +0 -92
  331. package/test/units/session.js +0 -97
  332. package/test/units/user.js +0 -48
  333. package/yuidoc.json +0 -8
package/lib/apiKey.js DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * An ApiKey in Nitrogen is a key that enables non-user principals to be created in the system.
3
- *
4
- * A permission has the following properties:
5
- * owner: The principal id that owns this api key.
6
- * key: The opaque key that should be used by the client as the api_key on requests
7
- * @class ApiKey
8
- * @namespace nitrogen
9
- **/
10
-
11
- function ApiKey(json) {
12
- for(var key in json) {
13
- if(json.hasOwnProperty(key)) {
14
- this[key] = json[key];
15
- }
16
- }
17
- }
18
-
19
- /**
20
- * Find all the api_keys for the authenticated user.
21
- *
22
- * @method index
23
- * @async
24
- * @param {Object} session An open session with a Nitrogen service. Only user principals will return results.
25
- * @param {Object} query A query filter for the apiKeys defined using MongoDB's query format. (reserved: currently ignored)
26
- * @param {Object} options Options for the query (reserved, currently ignored): 'limit': maximum number of results to be returned. 'sort': The field that the results should be sorted on, 'dir': The direction that the results should be sorted. 'skip': The number of results that should be skipped before pulling results.
27
- * @param {Function} callback Callback function of the form f(err, permissions).
28
- **/
29
-
30
- ApiKey.find = function(session, query, options, callback) {
31
- if (!session) return callback(new Error("Session required for ApiKey.index."));
32
- if (!callback || typeof callback !== 'function') return callback(new Error('Callback required for ApiKey.index.'));
33
-
34
- session.get({
35
- url: session.service.config.endpoints.api_keys,
36
- json: true
37
- }, function(err, resp, body) {
38
- if (err) return callback(err);
39
-
40
- var apiKeys = body.api_keys.map(function(apiKey) {
41
- return new ApiKey(apiKey);
42
- });
43
-
44
- callback(null, apiKeys);
45
- });
46
- };
47
-
48
- /**
49
- * Create an API key.
50
- *
51
- * @method create
52
- * @param {Object} session An open session with a Nitrogen service.
53
- * @param {Function} callback Callback function of the form f(err, apiKey).
54
- **/
55
-
56
- ApiKey.prototype.create = function(session, callback) {
57
- var self = this;
58
-
59
- session.post({ url: session.service.config.endpoints.api_keys, json: this }, function(err, resp, body) {
60
- if (err) return callback(err);
61
- if (resp.statusCode != 200) return callback(body.error || resp.statusCode);
62
-
63
- return callback(null, new ApiKey(body.api_key));
64
- });
65
- };
66
-
67
- module.exports = ApiKey;
package/lib/blob.js DELETED
@@ -1,57 +0,0 @@
1
- /**
2
- * A Blob represents a binary data object that is stored with the Nitrogen service.
3
- *
4
- * @class Blob
5
- * @namespace nitrogen
6
- */
7
-
8
- function Blob(json) {
9
- for(var key in json) {
10
- this[key] = json[key];
11
- }
12
- }
13
-
14
- /**
15
- * Saves a blob via streaming to the Nitrogen service.
16
- *
17
- * @method save
18
- * @async
19
- * @param {Object} session An open session with a Nitrogen service.
20
- * @param {Object} stream A stream with the contents of the blob.
21
- * @param {Function} callback Callback function of the form f(err, blob).
22
- **/
23
-
24
- Blob.prototype.save = function(session, stream, callback) {
25
- if (!session.service.config.endpoints.blobs) return callback("blob endpoint not available on this service");
26
-
27
- var self = this;
28
-
29
- stream.pipe(
30
- session.post({ url: session.service.config.endpoints.blobs,
31
- headers: { 'Content-Type': self.content_type } }, function (err, resp, body) {
32
-
33
- if (err) return callback(err);
34
- if (resp.statusCode != 200) return callback(resp.statusCode);
35
-
36
- var bodyJson = JSON.parse(body);
37
-
38
- return callback(null, new Blob(bodyJson.blob));
39
- })
40
- );
41
- };
42
-
43
- /**
44
- * Fetches a blob from the Nitrogen service.
45
- *
46
- * @method get
47
- * @async
48
- * @param {Object} session An open session with a Nitrogen service.
49
- * @param {Object} url The url for the blob.
50
- * @param {Function} callback Callback function of the form f(err, httpResponse, blobData).
51
- **/
52
-
53
- Blob.get = function(session, url, callback) {
54
- session.get({ url: url, encoding: null }, callback);
55
- };
56
-
57
- module.exports = Blob;
@@ -1,350 +0,0 @@
1
- var Message = require('./message');
2
-
3
- /**
4
- * The CommandManager object provides infrastructure for command processing within Nitrogen. Commands are messages that are issued
5
- * with the intent of changing the state of a principal in the system. The CommandManager's role is to watch that principal's message
6
- * stream and effect state changes on the device it is managing based on these commands and their context in the stream. The CommandManager
7
- * is always subclassed into a class that handles a specific type of command. This subclass is responsible for providing a set of functions
8
- * that define how the message stream should be interpreted and acted on: executeActiveCommands, isRelevant, isCommand, obsoletes. See each
9
- * function in this class for more information on what an implementation of these functions should provide.
10
- *
11
- * An example of how a SwitchManager subclass is used to control a light in a device application looks like this:
12
- *
13
- * service.connect(light, function(err, session, light) {
14
- * if (err) return console.log('failed to connect light: ' + err);
15
- *
16
- * var switchManager = new nitrogen.SwitchManager(light);
17
- * switchManager.start(session, { $or: [ { to: light.id }, { from: light.id } ] }, function(err) {
18
- * if (err) return console.log('switchManager failed to start: ' + err);
19
- * });
20
- * });
21
- *
22
- * @class CommandManager
23
- * @namespace nitrogen
24
- */
25
-
26
- function CommandManager(device) {
27
- this.device = device;
28
- this.executing = false;
29
- this.messageQueue = [];
30
- }
31
-
32
- /**
33
- * Returns the array of commands that are currently active for this manager. This is typically used to execute them during executeQueue.
34
- *
35
- * @method activeCommands
36
- * @returns {Array of Messages} Array of active command messages.
37
- **/
38
-
39
- CommandManager.prototype.activeCommands = function() {
40
- var filtered = [];
41
- this.messageQueue.forEach(function(message) {
42
- if (message.millisToTimestamp() <= 0) {
43
- filtered.push(message);
44
- }
45
- });
46
-
47
- return filtered;
48
- };
49
-
50
- CommandManager.prototype.commandFilter = function() {
51
- return {
52
- tags: CommandManager.commandTag(this.device.id)
53
- };
54
- };
55
-
56
- CommandManager.commandTag = function(principalId) {
57
- return "command:" + principalId;
58
- };
59
-
60
- /**
61
- * Reduce the current message queue to the set of active commands by obsoleting completed and
62
- * expired commands.
63
- *
64
- * @method collapse
65
- **/
66
-
67
- CommandManager.prototype.collapse = function() {
68
- var collapsedMessages = [];
69
- var upstreamMessage;
70
- var self = this;
71
-
72
- this.sortQueue();
73
-
74
- // first, strip all non relevant messages.
75
- var relevantMessages = [];
76
- this.messageQueue.forEach(function(message) {
77
- if (self.isRelevant(message)) {
78
- relevantMessages.push(message);
79
- }
80
- });
81
-
82
- // dequeue the first message in the message queue leaving only the downstream messages...
83
- while ((upstreamMessage = relevantMessages.shift())) {
84
- if (self.isCommand(upstreamMessage)) {
85
- var idx;
86
- var obsoleted = false;
87
- for (idx=0; idx < relevantMessages.length && !obsoleted; idx++) {
88
- var downstreamMessage = relevantMessages[idx];
89
- obsoleted = this.obsoletes(downstreamMessage, upstreamMessage);
90
- }
91
-
92
- if (!obsoleted) {
93
- collapsedMessages.push(upstreamMessage);
94
- // console.log('collapse: message: ' + upstreamMessage.from + '->' + upstreamMessage.to + ' not obsolete, ');
95
- } else {
96
- // console.log('collapse: message: ' + upstreamMessage.from + '->' + upstreamMessage.to + ' has been obsoleted, removing.');
97
- }
98
- } else {
99
- // console.log('collapse: message: ' + upstreamMessage.from + '->' + upstreamMessage.to + ' is type: ' + upstreamMessage.type + ': removing.');
100
- }
101
- }
102
-
103
- this.messageQueue = collapsedMessages;
104
- };
105
-
106
- /**
107
- * Executes the currently active command queue. If the next command's timestamp occurs in the future,
108
- * setup a timeout to retry then.
109
- *
110
- * @method execute
111
- * @private
112
- **/
113
-
114
- CommandManager.prototype.execute = function() {
115
- var self = this;
116
-
117
- if (this.device.id !== this.session.principal.id) return self.session.log.debug('CommandManager::execute: not in session of device, skipping execution.');
118
- if (this.executing) return; // self.session.log.debug('CommandManager::execute: already executing command, skipping execute. current queue: ' + JSON.stringify(this.messageQueue));
119
- if (!this.messageQueue || this.messageQueue.length === 0) return self.session.log.debug('CommandManager::execute: empty command queue.');
120
-
121
- var msToExecute = this.messageQueue[0].millisToTimestamp();
122
- if (msToExecute > 0) {
123
- self.session.log.debug('CommandManager::execute: top message occurs in the future, setting timeout for ' + msToExecute + 'ms.');
124
- return setTimeout(function() { self.execute(); }, msToExecute);
125
- }
126
-
127
- this.executing = true;
128
- this.executeQueue(function(err) {
129
- self.executing = false;
130
- if (err) self.session.log.error('CommandManager::execute: execution error: ' + err);
131
-
132
- // set up a new execution pass on the command queue.
133
- setTimeout(function() { self.execute(); }, 0);
134
- });
135
- };
136
-
137
- /**
138
- * Executes the active commands in the message queue. Should be implemented by subclasses of CommandManager.
139
- *
140
- * Commands that have reached this point have been passed the start filter (see the CommandManager.start() method details),
141
- * had a "true" result out of the CommandManager.isRelevant and CommandManager.isCommand methods and finally has recieved a "false"
142
- * to the CommandManager.obsoletes method.
143
- *
144
- * An example use of this from the Simple Device guide:
145
- *
146
- * SimpleLEDManager.prototype.executeQueue = function(callback) {
147
- * var self = this;
148
- *
149
- * // If you don't have a device, throw an error.
150
- * if (!this.device) return callback(new Error('no device attached to control manager.'));
151
- *
152
- * var activeCommands = this.activeCommands();
153
- * if (activeCommands.length === 0) {
154
- * this.session.log.warn('SimpleLEDManager::executeQueue: no active commands to execute.');
155
- * return callback();
156
- * }
157
- *
158
- * // We will take all of the activeCommand's ids and use pass them to the "response_to".
159
- * // This is important for the "obsoletes" method.
160
- * var commandIds = [];
161
- * activeCommands.forEach(function(activeCommand) {
162
- * commandIds.push(activeCommand.id);
163
- * });
164
- *
165
- * // Create the status response
166
- * var message = new nitrogen.Message({
167
- * type: '_myStatusResponse',
168
- * tags: nitrogen.CommandManager.commandTag(self.device.id),
169
- * body: {
170
- * command: {
171
- * message: "My status is good"
172
- * }
173
- * },
174
- * response_to: commandIds
175
- * });
176
- *
177
- * message.send(_session, function(err, message) {
178
- * if (err) return callback(err);
179
- *
180
- * // Let the command manager know we processed this _lightOn message by passing it the _isOn message.
181
- * self.process(new nitrogen.Message(message));
182
- *
183
- * // Need to callback if there aren't any issues so commandManager can proceed.
184
- * return callback();
185
- * });
186
- * }
187
- *
188
- * @method executeQueue
189
- **/
190
-
191
- /**
192
- * Return true if this message is relevant to the CommandManager. Should be implemented by subclasses of CommandManager.
193
- *
194
- * This works in concert with the filter passed into the server in the start method. It enables more intricate processing and
195
- * filtering than the simple filter. It is also possible that you could just return true on the method if your filter is correct and you
196
- * don't want to filter out additional messages. For example:
197
- *
198
- * MyCommandManager.prototype.isRelevant = function(message) {
199
- * return (message.body.property === "value I'm looking for");
200
- * };
201
- *
202
- * @method isRelevant
203
- * @param {Object} message The message to test for relevance.
204
- **/
205
-
206
- /**
207
- * Return true if this message is a command that this CommandManager can process. Should be implemented by subclasses of CommandManager.
208
- *
209
- * For example:
210
- *
211
- * MyCommandManager.prototype.isCommand = function(message) {
212
- * return message.is('_myCommandName');
213
- * };
214
- *
215
- * @method isCommand
216
- * @param {Object} message The message to test to see if it is a relevant command.
217
- **/
218
-
219
- /**
220
- * Return the last active command in the message queue as ordered by timestamp.
221
- *
222
- * @method lastActiveCommand
223
- **/
224
-
225
- CommandManager.prototype.lastActiveCommand = function() {
226
- var activeCommands = this.activeCommands();
227
- return activeCommands.length > 0 ? activeCommands[activeCommands.length - 1] : null;
228
- };
229
-
230
- /**
231
- * Returns true if the given message upstream in time of the given downstream message is obsoleted by
232
- * the downstream message. Should be overridden by subclasses to provide command type specific
233
- * obsoletion logic. Overrides should start their implementation by calling this function for base
234
- * functionality.
235
- *
236
- * For example:
237
- *
238
- * MyCommandManager.prototype.obsoletes = function(downstreamMsg, upstreamMsg) {
239
- * if (nitrogen.CommandManager.obsoletes(downstreamMsg, upstreamMsg))
240
- * return true;
241
- *
242
- * var value = downstreamMsg.is("_myStatusResponse") &&
243
- * downstreamMsg.isResponseTo(upstreamMsg) &&
244
- * upstreamMsg.is("_myStatusRequest");
245
- *
246
- * return value;
247
- * };
248
- *
249
- * @method obsoletes
250
- * @param {Object} downstreamMsg The downstream message that potentially obsoletes the upstream message.
251
- * @param {Object} upstreamMsg The upstream message that is potentially obsoleted by the downstream message.
252
- **/
253
-
254
- CommandManager.obsoletes = function(downstreamMsg, upstreamMsg) {
255
- if (downstreamMsg.ts < upstreamMsg.ts) return false;
256
- if (downstreamMsg.expired()) return false;
257
- if (upstreamMsg.expired()) return true;
258
-
259
- return false;
260
- };
261
-
262
- /**
263
- * Process new message in this principal's message stream: adds it to the messageQueue, collapses the
264
- * current message stream, and sets up timeout to handle expiration of this message and the subsequent
265
- * collapse that should occur.
266
- *
267
- * @method process
268
- * @param {Object} message The new message to process.
269
- * @private
270
- **/
271
-
272
- CommandManager.prototype.process = function(message) {
273
- if (!this.isRelevant(message)) return;
274
-
275
- this.messageQueue.push(message);
276
- this.collapse();
277
-
278
- var self = this;
279
-
280
- if (message.expires) {
281
- var nextExpiration = Math.max(message.millisToExpiration(), 0);
282
-
283
- setTimeout(function() { self.collapse(); }, nextExpiration);
284
- }
285
- };
286
-
287
- CommandManager.prototype.sortQueue = function() {
288
- this.messageQueue.sort(function(a,b) {
289
- return a.ts - b.ts;
290
- });
291
- };
292
-
293
- /**
294
- * Starts command processing on the message stream using the principal's session. It fetches all the
295
- * current messages, processes them, and then starts execution. It also establishes a subscription to
296
- * handle new messages and automatically executes them as they are received.
297
- *
298
- * The filter specified is passed to the service as both a query and subscription and should specify a bound on the messages you'd like
299
- * to receive. By default, it uses a commandFilter (as defined in commandFilter) which is a tag applied to messages that are "command relevant"
300
- * for this device. and is an opt in model for messages that you want to recieve. You can further filter out messages if you like but this can handle
301
- * nearly all cases. In the case that you can't specify a perfect filter, you can further filter the message stream by subclassing the
302
- * "isRelevant" function.
303
- *
304
- * In the most common case, your implementation of start in your CommandManager subclass should look like this:
305
- *
306
- * MyCommandManager.prototype.start = function(session, callback) {
307
- * return nitrogen.CommandManager.prototype.start.call(this, session, null, callback);
308
- * };
309
- *
310
- * @method start
311
- * @param {Object} session Session this CommandManager should operate under.
312
- * @param {Object} filter Filter for relevant messages for this CommandManager. This is usually specified by the CommandManager subclass.
313
- * @param {Object} callback Callback of the form f(err, message). Called after each new message received.
314
- **/
315
-
316
- CommandManager.prototype.start = function(session, filter, callback) {
317
- this.session = session;
318
-
319
- // if no custom filter is passed, use a command query.
320
- if (!filter) {
321
- filter = this.commandFilter();
322
- }
323
-
324
- var self = this;
325
- Message.find(session, filter, { sort: { ts: -1 }, limit: 1000 }, function(err, reversedMessages) {
326
- if (err) return callback(err);
327
-
328
- var messages = reversedMessages.reverse();
329
-
330
- // collapse the message stream down to the just the active commands.
331
- messages.forEach(function(message) { self.process(message); });
332
-
333
- self.execute();
334
-
335
- session.onMessage(filter, function(message) {
336
- self.process(message);
337
- callback(null, message);
338
-
339
- // if we aren't currently executing anything, kickstart execution.
340
- if (!self.executing) {
341
- self.execute();
342
- }
343
- });
344
-
345
- session.log.info('commandManager: started.');
346
- callback();
347
- });
348
- };
349
-
350
- module.exports = CommandManager;
package/lib/device.js DELETED
@@ -1,19 +0,0 @@
1
- var Principal = require('./principal');
2
-
3
- /**
4
- * Device is a subclass of principal that houses all device specific principal functionality.
5
- *
6
- * @class Device
7
- * @namespace nitrogen
8
- */
9
-
10
- function Device() {
11
- Principal.apply(this, arguments);
12
-
13
- this.type = 'device';
14
- }
15
-
16
- Device.prototype = Object.create(Principal.prototype);
17
- Device.prototype.constructor = Device;
18
-
19
- module.exports = Device;
@@ -1,24 +0,0 @@
1
- function MemoryStore() {
2
- this.clear();
3
- }
4
-
5
- MemoryStore.prototype.clear = function(callback) {
6
- this.store = {};
7
- if (callback) return callback();
8
- };
9
-
10
- MemoryStore.prototype.get = function(key, callback) {
11
- return callback(null, this.store[key]);
12
- };
13
-
14
- MemoryStore.prototype.set = function(key, value, callback) {
15
- this.store[key] = value;
16
- if (callback) return callback();
17
- };
18
-
19
- MemoryStore.prototype.delete = function(key, callback) {
20
- delete this.store[key];
21
- if (callback) return callback();
22
- };
23
-
24
- module.exports = MemoryStore;