@ohos-ports/core 1.0.113-beta.0 → 1.16.33-beta.0

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 (346) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +3 -0
  3. package/lib/api/node.js +176 -0
  4. package/lib/api/team.js +1889 -0
  5. package/lib/blocklet/downloader/blocklet-downloader.js +246 -0
  6. package/lib/blocklet/downloader/bundle-downloader.js +316 -0
  7. package/lib/blocklet/downloader/constants.js +3 -0
  8. package/lib/blocklet/downloader/resolve-download.js +187 -0
  9. package/lib/blocklet/extras.js +177 -0
  10. package/lib/blocklet/hooks.js +89 -0
  11. package/lib/blocklet/manager/base.js +49 -0
  12. package/lib/blocklet/manager/config-synchronizer.js +128 -0
  13. package/lib/blocklet/manager/disk.js +5170 -0
  14. package/lib/blocklet/manager/engine.js +124 -0
  15. package/lib/blocklet/manager/helper/install-application-from-backup.js +285 -0
  16. package/lib/blocklet/manager/helper/install-application-from-dev.js +72 -0
  17. package/lib/blocklet/manager/helper/install-application-from-general.js +209 -0
  18. package/lib/blocklet/manager/helper/install-component-from-dev.js +128 -0
  19. package/lib/blocklet/manager/helper/install-component-from-upload.js +197 -0
  20. package/lib/blocklet/manager/helper/install-component-from-url.js +214 -0
  21. package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +557 -0
  22. package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
  23. package/lib/blocklet/manager/helper/upgrade-components.js +179 -0
  24. package/lib/blocklet/manager/pm2-events.js +50 -0
  25. package/lib/blocklet/migration-dist/migration.cjs +38605 -0
  26. package/lib/blocklet/migration-dist/run-script.cjs +29 -0
  27. package/lib/blocklet/migration.js +145 -0
  28. package/lib/blocklet/project/connect-by-studio.js +91 -0
  29. package/lib/blocklet/project/connect-to-store.js +64 -0
  30. package/lib/blocklet/project/create-pack-release.js +293 -0
  31. package/lib/blocklet/project/disconnect-from-store.js +13 -0
  32. package/lib/blocklet/project/get-is-multiple-tenant.js +8 -0
  33. package/lib/blocklet/project/index.js +545 -0
  34. package/lib/blocklet/project/logo.png +0 -0
  35. package/lib/blocklet/project/publish-to-store.js +108 -0
  36. package/lib/blocklet/project/util.js +194 -0
  37. package/lib/blocklet/security/access-policy.js +131 -0
  38. package/lib/blocklet/security/index.js +309 -0
  39. package/lib/blocklet/security/response-header-policy.js +178 -0
  40. package/lib/blocklet/security/security-rule.js +127 -0
  41. package/lib/blocklet/security/utils.js +35 -0
  42. package/lib/blocklet/security/validator.js +40 -0
  43. package/lib/blocklet/storage/backup/base.js +149 -0
  44. package/lib/blocklet/storage/backup/blocklet-extras.js +110 -0
  45. package/lib/blocklet/storage/backup/blocklet.js +159 -0
  46. package/lib/blocklet/storage/backup/blocklets.js +109 -0
  47. package/lib/blocklet/storage/backup/data.js +35 -0
  48. package/lib/blocklet/storage/backup/disk.js +131 -0
  49. package/lib/blocklet/storage/backup/logs.js +24 -0
  50. package/lib/blocklet/storage/backup/routing-rule.js +47 -0
  51. package/lib/blocklet/storage/backup/spaces.js +345 -0
  52. package/lib/blocklet/storage/restore/base.js +74 -0
  53. package/lib/blocklet/storage/restore/blocklet-extras.js +89 -0
  54. package/lib/blocklet/storage/restore/blocklet.js +56 -0
  55. package/lib/blocklet/storage/restore/blocklets.js +43 -0
  56. package/lib/blocklet/storage/restore/disk.js +104 -0
  57. package/lib/blocklet/storage/restore/logs.js +21 -0
  58. package/lib/blocklet/storage/restore/spaces.js +174 -0
  59. package/lib/blocklet/storage/utils/disk.js +178 -0
  60. package/lib/blocklet/storage/utils/hash.js +53 -0
  61. package/lib/blocklet/storage/utils/zip.js +43 -0
  62. package/lib/cert.js +221 -0
  63. package/lib/crons/check-new-version.js +68 -0
  64. package/lib/crons/monitor-disk-usage.js +46 -0
  65. package/lib/crons/rotate-pm2-logs/index.js +41 -0
  66. package/lib/crons/rotate-pm2-logs/script.js +56 -0
  67. package/lib/event/auto-backup-handler.js +48 -0
  68. package/lib/event/index.js +520 -0
  69. package/lib/index.js +768 -364
  70. package/lib/locales/ar.js +18 -0
  71. package/lib/locales/de.js +21 -0
  72. package/lib/locales/en.js +19 -0
  73. package/lib/locales/es.js +21 -0
  74. package/lib/locales/fr.js +21 -0
  75. package/lib/locales/hi.js +18 -0
  76. package/lib/locales/i18n.db +0 -0
  77. package/lib/locales/id.js +20 -0
  78. package/lib/locales/index.js +54 -0
  79. package/lib/locales/ja.js +19 -0
  80. package/lib/locales/ko.js +18 -0
  81. package/lib/locales/pt.js +20 -0
  82. package/lib/locales/ru.js +21 -0
  83. package/lib/locales/th.js +18 -0
  84. package/lib/locales/vi.js +18 -0
  85. package/lib/locales/zh-tw.js +17 -0
  86. package/lib/locales/zh.js +17 -0
  87. package/lib/migrations/1.0.21-update-config.js +34 -0
  88. package/lib/migrations/1.0.22-max-memory.js +40 -0
  89. package/lib/migrations/1.0.25.js +36 -0
  90. package/lib/migrations/1.0.32-update-config.js +30 -0
  91. package/lib/migrations/1.0.33-blocklets.js +33 -0
  92. package/lib/migrations/1.0.36-snapshot.js +10 -0
  93. package/lib/migrations/1.1.10-team.js +26 -0
  94. package/lib/migrations/1.1.9-snapshot.js +7 -0
  95. package/lib/migrations/1.16.11-component-status.js +22 -0
  96. package/lib/migrations/1.16.33-blocklet-security-rule.js +17 -0
  97. package/lib/migrations/1.16.6-chain-info.js +78 -0
  98. package/lib/migrations/1.16.8-component-title.js +66 -0
  99. package/lib/migrations/1.2.11-blocklet-registry.js +10 -0
  100. package/lib/migrations/1.2.2-blocklet-registry.js +10 -0
  101. package/lib/migrations/1.3.1-disk-alert-threshold.js +10 -0
  102. package/lib/migrations/1.4.5-access-key.js +18 -0
  103. package/lib/migrations/1.5.0-site.js +34 -0
  104. package/lib/migrations/1.5.15-site.js +184 -0
  105. package/lib/migrations/1.5.20-registry.js +15 -0
  106. package/lib/migrations/1.6.17-blocklet-children.js +48 -0
  107. package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
  108. package/lib/migrations/1.6.4-security.js +59 -0
  109. package/lib/migrations/1.6.5-security.js +60 -0
  110. package/lib/migrations/1.6.9-update-node-info-and-certificate.js +39 -0
  111. package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
  112. package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
  113. package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
  114. package/lib/migrations/1.7.20-blocklet-component.js +41 -0
  115. package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
  116. package/lib/migrations/README.md +71 -0
  117. package/lib/migrations/index.js +215 -0
  118. package/lib/monitor/blocklet-runtime-monitor.js +204 -0
  119. package/lib/monitor/get-history-list.js +37 -0
  120. package/lib/monitor/node-monit-sender.js +99 -0
  121. package/lib/monitor/node-runtime-monitor.js +205 -0
  122. package/lib/processes/updater.js +186 -0
  123. package/lib/router/helper.js +1653 -0
  124. package/lib/router/index.js +341 -0
  125. package/lib/router/manager.js +806 -0
  126. package/lib/states/README.md +38 -0
  127. package/lib/states/access-key.js +124 -0
  128. package/lib/states/access-policy.js +29 -0
  129. package/lib/states/audit-log.js +734 -0
  130. package/lib/states/backup.js +165 -0
  131. package/lib/states/base.js +25 -0
  132. package/lib/states/blocklet-extras.js +257 -0
  133. package/lib/states/blocklet.js +755 -0
  134. package/lib/states/cache.js +23 -0
  135. package/lib/states/connect-account.js +8 -0
  136. package/lib/states/index.js +76 -0
  137. package/lib/states/job.js +8 -0
  138. package/lib/states/migration.js +34 -0
  139. package/lib/states/node.js +324 -0
  140. package/lib/states/notification.js +81 -0
  141. package/lib/states/passport.js +8 -0
  142. package/lib/states/project.js +119 -0
  143. package/lib/states/release.js +50 -0
  144. package/lib/states/response-header-policy.js +30 -0
  145. package/lib/states/routing-snapshot.js +146 -0
  146. package/lib/states/runtime-insight.js +25 -0
  147. package/lib/states/security-rule.js +30 -0
  148. package/lib/states/session.js +53 -0
  149. package/lib/states/site.js +102 -0
  150. package/lib/states/tag.js +8 -0
  151. package/lib/states/traffic-insight.js +25 -0
  152. package/lib/states/user-session.js +8 -0
  153. package/lib/states/user.js +717 -0
  154. package/lib/states/verify-code.js +152 -0
  155. package/lib/states/webhook.js +66 -0
  156. package/lib/team/manager.js +508 -0
  157. package/lib/util/blocklet.js +2182 -0
  158. package/lib/util/cache.js +63 -0
  159. package/lib/util/chain.js +29 -0
  160. package/lib/util/default-node-config.js +46 -0
  161. package/lib/util/docker/blocklet-custom-dockerfile.js +92 -0
  162. package/lib/util/docker/check-docker-has-image.js +23 -0
  163. package/lib/util/docker/check-docker-installed.js +32 -0
  164. package/lib/util/docker/check-docker-run-history.js +18 -0
  165. package/lib/util/docker/check-need-run-docker.js +32 -0
  166. package/lib/util/docker/create-docker-image.js +65 -0
  167. package/lib/util/docker/debian-dockerfile.js +50 -0
  168. package/lib/util/docker/docker-container-prune.js +75 -0
  169. package/lib/util/docker/docker-exec-chown.js +39 -0
  170. package/lib/util/docker/docker-exec.js +68 -0
  171. package/lib/util/docker/docker-remove-by-name.js +20 -0
  172. package/lib/util/docker/get-docker-runtime-info.js +39 -0
  173. package/lib/util/docker/parse-docker-name.js +10 -0
  174. package/lib/util/docker/parse-docker-options-from-pm2.js +295 -0
  175. package/lib/util/docker/shard-network.js +10 -0
  176. package/lib/util/domain-status.js +118 -0
  177. package/lib/util/get-accessible-external-node-ip.js +92 -0
  178. package/lib/util/get-dynamic-components.js +47 -0
  179. package/lib/util/get-meta-from-url.js +30 -0
  180. package/lib/util/get-migration-scripts.js +36 -0
  181. package/lib/util/get-safe-env.js +12 -0
  182. package/lib/util/index.js +522 -0
  183. package/lib/util/install-external-dependencies.js +67 -0
  184. package/lib/util/ip.js +53 -0
  185. package/lib/util/launcher.js +475 -0
  186. package/lib/util/log.js +431 -0
  187. package/lib/util/maintain.js +178 -0
  188. package/lib/util/promise-debounce.js +29 -0
  189. package/lib/util/promise-once.js +14 -0
  190. package/lib/util/promise-spawn.js +93 -0
  191. package/lib/util/queue.js +44 -0
  192. package/lib/util/ready.js +89 -0
  193. package/lib/util/request.js +10 -0
  194. package/lib/util/requirement.js +61 -0
  195. package/lib/util/reset-node.js +166 -0
  196. package/lib/util/rotator.js +194 -0
  197. package/lib/util/router.js +122 -0
  198. package/lib/util/rpc.js +78 -0
  199. package/lib/util/spaces.js +102 -0
  200. package/lib/util/store.js +184 -0
  201. package/lib/util/sysinfo.js +46 -0
  202. package/lib/util/ua.js +54 -0
  203. package/lib/validators/backup.js +34 -0
  204. package/lib/validators/blocklet-extra.js +18 -0
  205. package/lib/validators/node.js +73 -0
  206. package/lib/validators/permission.js +38 -0
  207. package/lib/validators/project.js +39 -0
  208. package/lib/validators/role.js +64 -0
  209. package/lib/validators/router.js +192 -0
  210. package/lib/validators/space-gateway.js +33 -0
  211. package/lib/validators/trusted-factory.js +28 -0
  212. package/lib/validators/trusted-passport.js +32 -0
  213. package/lib/validators/user.js +62 -0
  214. package/lib/validators/util.js +92 -0
  215. package/lib/validators/webhook.js +42 -0
  216. package/lib/webhook/index.js +216 -0
  217. package/lib/webhook/reduce-queue.js +12 -0
  218. package/lib/webhook/sender/api/index.js +67 -0
  219. package/lib/webhook/sender/base.js +11 -0
  220. package/lib/webhook/sender/index.js +44 -0
  221. package/lib/webhook/sender/slack/index.js +167 -0
  222. package/lib/webhook/sender/wallet/index.js +62 -0
  223. package/package.json +107 -34
  224. package/examples/BatchClient.js +0 -61
  225. package/examples/compressor/example.js +0 -7
  226. package/examples/jsonrpcserver/rpcmethod.js +0 -21
  227. package/examples/jsonrpcserver/rpcrequest.js +0 -20
  228. package/examples/jsonrpcserver/rpctest.js +0 -6
  229. package/examples/loader-pipes/test-mc.js +0 -52
  230. package/examples/loader-pipes/test.js +0 -51
  231. package/examples/mc-test.js +0 -44
  232. package/examples/redisdebug.js +0 -80
  233. package/lib/cache/CFMemcache.js +0 -57
  234. package/lib/cache/CacheLoader.js +0 -217
  235. package/lib/cache/Memcache.js +0 -406
  236. package/lib/class/Class.js +0 -54
  237. package/lib/client/MemcacheAdapter.js +0 -139
  238. package/lib/client/Memcached.js +0 -142
  239. package/lib/client/MemcachedSocket.js +0 -570
  240. package/lib/client/MySQLPool.js +0 -153
  241. package/lib/client/PGPool.js +0 -296
  242. package/lib/client/Redis.js +0 -787
  243. package/lib/client/S3.js +0 -103
  244. package/lib/client/S3Client.js +0 -392
  245. package/lib/client/pg/CursorQueryWorker.js +0 -160
  246. package/lib/client/rabbitmq/RbmqChannel.js +0 -61
  247. package/lib/client/rabbitmq/RbmqConfig.js +0 -144
  248. package/lib/client/rabbitmq/RbmqConnection.js +0 -259
  249. package/lib/client/rabbitmq/RbmqExchange.js +0 -112
  250. package/lib/client/rabbitmq/RbmqIncomingMessage.js +0 -53
  251. package/lib/client/rabbitmq/RbmqMessage.js +0 -120
  252. package/lib/client/rabbitmq/RbmqOutcomingMessage.js +0 -47
  253. package/lib/client/rabbitmq/RbmqQueue.js +0 -87
  254. package/lib/client/rabbitmq/index.js +0 -8
  255. package/lib/common/Assertions.js +0 -184
  256. package/lib/common/Merge.js +0 -32
  257. package/lib/common/Net.js +0 -56
  258. package/lib/common/Process.js +0 -20
  259. package/lib/common/Random.js +0 -53
  260. package/lib/common/Sort.js +0 -19
  261. package/lib/common/Types.js +0 -163
  262. package/lib/credentials/CredentialsProvider.js +0 -45
  263. package/lib/credentials/Manager.js +0 -101
  264. package/lib/crypto/Crypto.js +0 -66
  265. package/lib/data/BinaryData.js +0 -363
  266. package/lib/data/Compressor.js +0 -83
  267. package/lib/data/FormData.js +0 -144
  268. package/lib/data/Mime.js +0 -45
  269. package/lib/event/ErrorEvent.js +0 -71
  270. package/lib/event/Event.js +0 -20
  271. package/lib/event/EventDispatcher.js +0 -157
  272. package/lib/http/ConnectionPool.js +0 -82
  273. package/lib/http/ExpressServer.js +0 -19
  274. package/lib/http/Headers.js +0 -165
  275. package/lib/http/Loader.js +0 -584
  276. package/lib/http/Message.js +0 -189
  277. package/lib/http/Request.js +0 -848
  278. package/lib/http/RequestProcessor.js +0 -150
  279. package/lib/http/Response.js +0 -850
  280. package/lib/http/Server.js +0 -267
  281. package/lib/http/Socket.js +0 -157
  282. package/lib/http/Url.js +0 -2
  283. package/lib/jsonrpc/JsonRpcAbstract.js +0 -109
  284. package/lib/jsonrpc/JsonRpcBatchRequest.js +0 -54
  285. package/lib/jsonrpc/JsonRpcBatchResponse.js +0 -73
  286. package/lib/jsonrpc/JsonRpcError.js +0 -191
  287. package/lib/jsonrpc/JsonRpcMethod.js +0 -67
  288. package/lib/jsonrpc/JsonRpcRequest.js +0 -224
  289. package/lib/jsonrpc/JsonRpcRequestProcessor.js +0 -366
  290. package/lib/jsonrpc/JsonRpcResponse.js +0 -175
  291. package/lib/jsonrpc/JsonRpcServer.js +0 -81
  292. package/lib/logger/EmptyLogger.js +0 -15
  293. package/lib/logger/LoggerFactory.js +0 -20
  294. package/lib/logger/WildFireLogger.js +0 -267
  295. package/lib/pattern/Pool.js +0 -187
  296. package/lib/pattern/decorator/AbstractDecorator.js +0 -49
  297. package/lib/pattern/decorator/DecoratorChain.js +0 -285
  298. package/lib/util/DeviceDetector.js +0 -153
  299. package/lib/yaml/YAML.js +0 -46
  300. package/patterns.conf +0 -6
  301. package/tests/cache/CacheLoaderSpec.js +0 -7
  302. package/tests/class/ClassSpec.js +0 -106
  303. package/tests/client/MemcachedSocketSpec.js +0 -1228
  304. package/tests/client/MemcachedSpec.js +0 -77
  305. package/tests/client/MySQLPoolSpec.js +0 -231
  306. package/tests/client/PGPoolSpec.js +0 -479
  307. package/tests/client/RedisSpec.js +0 -471
  308. package/tests/client/S3ClientSpec.js +0 -26
  309. package/tests/client/S3Spec.js +0 -129
  310. package/tests/client/rabbitmq/RbmqConnectionSpec.js +0 -71
  311. package/tests/common/AssertionsSpec.js +0 -278
  312. package/tests/common/NetSpec.js +0 -6
  313. package/tests/common/RandomSpec.js +0 -35
  314. package/tests/common/TypesSpec.js +0 -7
  315. package/tests/credentials/CredentialsProviderSpec.js +0 -46
  316. package/tests/crypto/CryptoSpec.js +0 -33
  317. package/tests/data/BinaryDataSpec.js +0 -50
  318. package/tests/data/CompressorSpec.js +0 -7
  319. package/tests/data/FormDataSpec.js +0 -7
  320. package/tests/data/MimeSpec.js +0 -7
  321. package/tests/event/ErrorEventSpec.js +0 -20
  322. package/tests/event/EventDispatcherSpec.js +0 -319
  323. package/tests/event/EventSpec.js +0 -17
  324. package/tests/http/ConnectionPoolSpec.js +0 -7
  325. package/tests/http/HeadersSpec.js +0 -79
  326. package/tests/http/LoaderSpec.js +0 -43
  327. package/tests/http/MessageSpec.js +0 -251
  328. package/tests/http/RequestProcessorSpec.js +0 -124
  329. package/tests/http/RequestSpec.js +0 -651
  330. package/tests/http/ResponseSpec.js +0 -491
  331. package/tests/http/ServerSpec.js +0 -7
  332. package/tests/http/SocketSpec.js +0 -7
  333. package/tests/http/UrlSpec.js +0 -14
  334. package/tests/jsonrpc/JsonRpcAbstractSpec.js +0 -20
  335. package/tests/jsonrpc/JsonRpcBatchRequestSpec.js +0 -31
  336. package/tests/jsonrpc/JsonRpcBatchResponseSpec.js +0 -38
  337. package/tests/jsonrpc/JsonRpcErrorSpec.js +0 -58
  338. package/tests/jsonrpc/JsonRpcMethodSpec.js +0 -7
  339. package/tests/jsonrpc/JsonRpcRequestProcessorSpec.js +0 -271
  340. package/tests/jsonrpc/JsonRpcRequestSpec.js +0 -70
  341. package/tests/jsonrpc/JsonRpcResponseSpec.js +0 -63
  342. package/tests/jsonrpc/JsonRpcServerSpec.js +0 -42
  343. package/tests/pattern/PoolSpec.js +0 -180
  344. package/tests/pattern/decorator/AbstractDecoratorSpec.js +0 -7
  345. package/tests/pattern/decorator/DecoratorChainSpec.js +0 -7
  346. package/tests/yaml/YAMLSpec.js +0 -132
@@ -1,366 +0,0 @@
1
- /**
2
- * @overview JsonRpcRequestProcessor
3
- * @copyright Dreamlab Onet.pl sp. z. o o 2012
4
- */
5
-
6
- var RequestProcessor = require('../http/RequestProcessor.js').RequestProcessor;
7
- var JsonRpcAbstract = require('../jsonrpc/JsonRpcAbstract.js').JsonRpcAbstract;
8
- var JsonRpcResponse = require('../jsonrpc/JsonRpcResponse.js').JsonRpcResponse;
9
- var JsonRpcRequest = require('../jsonrpc/JsonRpcRequest.js').JsonRpcRequest;
10
- var JsonRpcMethod = require('../jsonrpc/JsonRpcMethod.js').JsonRpcMethod;
11
- var Types = require('../common/Types.js').Types;
12
- var BinaryData = require('../data/BinaryData.js').BinaryData;
13
-
14
- /**
15
- * @class JsonRpcRequestProcessor
16
- * @classdesc JsonRpcRequestProcessor
17
- * @extends RequestProcessor
18
- *
19
- * @requires RequestProcessor
20
- * @requires JsonRpcAbstract
21
- * @requires JsonRpcResponse
22
- * @requires JsonRpcMethod
23
- * @requires Types
24
- * @requires BinaryData
25
- *
26
- * @param {Server} server
27
- * @returns {JsonRpcRequestProcessor}
28
- */
29
- var JsonRpcRequestProcessor = exports.JsonRpcRequestProcessor = function (server) {
30
- this._request = null;
31
- this._response = null;
32
- this._responseData = [];
33
- this._isBatchRequest = false;
34
- this._methodCount = 0;
35
- RequestProcessor.call(this, server);
36
- };
37
-
38
- JsonRpcRequestProcessor.prototype = Object.create(RequestProcessor.prototype);
39
-
40
- /**
41
- * Processes request and generates response
42
- * @param {Request} request
43
- * @param {Response} response
44
- * @returns {undefined}
45
- * @method
46
- */
47
- JsonRpcRequestProcessor.prototype.process = function (request, response) {
48
- RequestProcessor.prototype.process.call(this, request, response);
49
-
50
- this._request = request;
51
- this._response = response;
52
- var jsonRpcRequests = this._getRequest();
53
- var methods = [];
54
- this._methodCount = jsonRpcRequests.length;
55
-
56
- for (var i = 0, tmpMethodCount = jsonRpcRequests.length; i < tmpMethodCount; i++ ) {
57
- this._processSingle(jsonRpcRequests[i]);
58
- try {
59
- methods.push(jsonRpcRequests[i].getMethod());
60
- } catch (e) {
61
- console.error('JsonRpcRequestProcessor/process: error:', e);
62
- }
63
- }
64
- //XXX: dziala jesli jest process.nextTick
65
- this._requestLine = '"' + this._request.getMethod() + ' ' + this._request.getPath() +
66
- ' method:' + methods.join(':') + ' ' + this._request.getHttpVersion() + '"';
67
- };
68
-
69
-
70
- /**
71
- * Returns Method object for specified request
72
- *
73
- * @param {JsonRpcRequest} request
74
- * @returns {JsonRpcMethod}
75
- * @method
76
- * @private
77
- */
78
- JsonRpcRequestProcessor.prototype._getMethodClass = function (requestedMethod) {
79
- return this.server.getMethod(requestedMethod, this._request);
80
- };
81
- /**
82
- * Return reposne to caller
83
- * @private
84
- */
85
- JsonRpcRequestProcessor.prototype._prepareResponse = function () {
86
- var tmp_rep = null;
87
- var that = this;
88
- if (--this._methodCount <= 0) {
89
-
90
- // jezeli ktos ustawil explicite statusCode lub body do zwrocenia
91
- // to znaczy ze chce nadpisac cala odpowiedz jsonRpc
92
- // i bierze na siebie odpowiedzialnosc poskladania poprawnie calego response
93
- // jedyne co wtedy robimy to odsylamy odpowiedz w nastepnym ticku
94
- // jezeli nic nie zmieniono: wartosciami sa getStatusCode()==null i getBody()==null
95
- if (!this._response.getStatusCode() || !this._response.getBody()) {
96
-
97
- this._response.setStatusCode(200);
98
- this._response.setHeaders({
99
- 'Content-Type': 'application/json; charset=utf8',
100
- 'Access-Control-Allow-Origin': '*'
101
- }, true);
102
-
103
- var responseData;
104
-
105
- if (this._isBatchRequest === true) {
106
- responseData = this._responseData;
107
- } else {
108
- responseData = this._responseData.pop();
109
- }
110
-
111
- this._response.setBody(new BinaryData(
112
- this._getBody(JSON.stringify(responseData)),
113
- BinaryData.Encoding.TEXT,
114
- BinaryData.CharacterEncoding.UTF8));
115
- }
116
-
117
- process.nextTick(function() {
118
- that._response.send();
119
- });
120
- }
121
-
122
- };
123
- /**
124
- * Processes single request and generates response
125
- * @param {Request} request
126
- * @param {Response} response
127
- * @param {Number} index
128
- * @returns {undefined}
129
- * @method
130
- */
131
-
132
- JsonRpcRequestProcessor.prototype._processSingle = function(jsonRpcRequest) {
133
- var method;
134
- var methodClass;
135
- var requestedMethod;
136
- var requestId = jsonRpcRequest.getId();
137
- var that = this;
138
-
139
- try {
140
- requestedMethod = jsonRpcRequest.getMethod();
141
- methodClass = this._getMethodClass(requestedMethod);
142
- } catch (ex) {
143
- console.error('_processSingle error', ex);
144
- this._throwError(JsonRpcRequestProcessor.Errors.INVALID_METHOD, ex, requestId);
145
- }
146
-
147
- if (!methodClass) {
148
- console.warn('JsonRpcRequestProcessor/process/methodNotFound', requestedMethod);
149
- var e = new Error(JsonRpcRequestProcessor.Errors.METHOD_NOT_FOUND);
150
- this._throwError(JsonRpcRequestProcessor.Errors.METHOD_NOT_FOUND, e, requestId);
151
- return;
152
- }
153
-
154
- method = new methodClass(this._request, this._response, this.server);
155
-
156
- if (!Types.isInstanceOf(method, JsonRpcMethod)) {
157
- var error = new Error(JsonRpcRequestProcessor.Errors.METHOD_NOT_FOUND);
158
- console.error('JsonRpcRequestProcessor/process/methodClassError/' + requestedMethod);
159
- this._throwError(JsonRpcRequestProcessor.Errors.METHOD_NOT_FOUND, error, requestId);
160
- return;
161
- }
162
-
163
-
164
- //FIXME: tutaj trzebaby sie zastanowic jak to zrobic bo raz przekazujemy Exception a raz ErrorEvent
165
- method.addEventListener(JsonRpcMethod.Event.WRONG_PARAMS, function (e) {
166
- that._handleError(e, requestId);
167
- }, this);
168
- method.addEventListener(JsonRpcMethod.Event.ERROR, function(e) {
169
- that._handleError(e, requestId);
170
- }, this);
171
- method.addEventListener(JsonRpcMethod.Event.OK, function(e) {
172
- that._success(e, requestId);
173
- }, this);
174
- try {
175
- method.execute(jsonRpcRequest.getParams());
176
- } catch (e) {
177
- console.error('JsonRpcRequestProcessor/execute/uncaughtException/method/' +
178
- requestedMethod, e, e.stack);
179
- this._throwError(JsonRpcRequestProcessor.Errors.INTERNAL_ERROR, e, requestId);
180
- }
181
-
182
- };
183
- /**
184
- * Returns jsonRpc response to the caller
185
- * @param {Event} e
186
- * @returns {undefined}
187
- * @method
188
- * @private
189
- */
190
- JsonRpcRequestProcessor.prototype._success = function(e, requestId) {
191
- var data;
192
- if (e.data) {
193
- data = e.data;
194
- if (!Types.isInstanceOf(e.data, JsonRpcResponse)) {
195
- data = new JsonRpcResponse();
196
- data.setResult(e.data);
197
- }
198
- data.setId(requestId);
199
-
200
- this._responseData.push(data.toJson());
201
-
202
- }
203
- return this._prepareResponse();
204
- };
205
-
206
- /**
207
- * Handles errors from executed JsonRpc Method
208
- * @param {Event} e
209
- * @returns {undefined}
210
- * @method
211
- * @private
212
- */
213
- JsonRpcRequestProcessor.prototype._handleError = function (e, requestId) {
214
- if (e.type == JsonRpcMethod.Event.WRONG_PARAMS) {
215
- this._throwError(JsonRpcRequestProcessor.Errors.INVALID_PARAMS, e, requestId);
216
- } else if (e.type == JsonRpcMethod.Event.ERROR) {
217
- this._throwError(e.code || -1, e, requestId);
218
- } else {
219
- this._throwError(JsonRpcRequestProcessor.Errors.INTERNAL_ERROR, e, requestId);
220
- }
221
- };
222
- /**
223
- * Retrieves jsonrpc request from request body
224
- * @returns [JsonRpcRequest]
225
- * @method
226
- * @private
227
- */
228
- JsonRpcRequestProcessor.prototype._getRequest = function () {
229
- //tutaj mozna dodac pewnie jakas walidacje czy request jest POSTem
230
- var raw_requests;
231
- var requests = [];
232
- try {
233
- raw_requests = JSON.parse(this._request.getBody().toBuffer().toString());
234
- } catch (e) {
235
- var ex = new Error(JsonRpcAbstract.Exceptions.PARSE_ERROR);
236
- console.error('JsonRpcRequestProcessor/process/createJsonRpcRequest', e);
237
- this._throwError(JsonRpcRequestProcessor.Errors.PARSE_ERROR, ex, 0);
238
- return requests;
239
- }
240
-
241
- if (Types.isArray(raw_requests) === true) {
242
- this._isBatchRequest = true;
243
- }
244
- else {
245
- this._isBatchRequest = false;
246
- raw_requests = [raw_requests];
247
- }
248
- for (var i = 0, raw_lenght = raw_requests.length; i < raw_lenght; i++) {
249
- try{
250
- requests.push(new JsonRpcRequest(raw_requests[i]));
251
- } catch(e) {
252
- console.error('JsonRpcRequestProcessor/process/createBathJsonRpcRequest', e);
253
- if (e.message == JsonRpcAbstract.Exceptions.INPROPER_JSON) {
254
- this._throwError(JsonRpcRequestProcessor.Errors.PARSE_ERROR, e);
255
- } else if (e.message == JsonRpcAbstract.Exceptions.INVALID_JSON_RPC) {
256
- this._throwError(JsonRpcRequestProcessor.Errors.INVALID_REQUEST, e);
257
- } else {
258
- this._throwError(JsonRpcRequestProcessor.Errors.INTERNAL_ERROR, e);
259
- }
260
- }
261
- }
262
-
263
- return requests;
264
- };
265
-
266
- /**
267
- * Retrieves body from given JsonRpcResponse
268
- * @method
269
- * @private
270
- * @param {JsonRpcResponse} response
271
- * @return {String}
272
- */
273
- JsonRpcRequestProcessor.prototype._getBody = function (response) {
274
- return response.toString();
275
- };
276
-
277
- /**
278
- * Returns jsonRpc error to the caller
279
- * @param {Number|ErrorEvent} code
280
- * @param {Exception|ErrorEvent} exception
281
- * @param {Number} id
282
- * @returns {undefined}
283
- * @method
284
- * @private
285
- */
286
- JsonRpcRequestProcessor.prototype._throwError = function (code, exception, id) {
287
- var errorCode = null;
288
- var errorMsg = null;
289
- var loggingFunc = 'warn';
290
- var jsonRpcResponse = new JsonRpcResponse();
291
- jsonRpcResponse.setId(id ? id : "undefined");
292
-
293
- if (Types.isObject(code)) {
294
- errorCode = code.code;
295
- errorMsg = code.message;
296
- } else {
297
- errorCode = code;
298
- errorMsg = exception.message;
299
- }
300
- // Error codes range pre-defined for JSON-RPC
301
- if (errorCode >= -32768 && errorCode <= -32000) {
302
- loggingFunc = 'error';
303
- }
304
-
305
- console[loggingFunc]('JsonRpcRequestProcessor/_throwError/ code: ' + errorCode + " msg: " + errorMsg);
306
- jsonRpcResponse.setError(parseInt(errorCode, 10), errorMsg || "", exception.data ? exception.data : null);
307
-
308
- this._responseData.push(jsonRpcResponse.toJson());
309
-
310
- return this._prepareResponse();
311
- };
312
-
313
- /**
314
- * @static
315
- * @constant
316
- * @namespace
317
- */
318
- JsonRpcRequestProcessor.Errors = {};
319
-
320
- /**
321
- * @static
322
- * @constant
323
- * @type {String}
324
- * @default
325
- */
326
- JsonRpcRequestProcessor.Errors.PARSE_ERROR = { code: -32700, message: 'Parse error' };
327
-
328
- /**
329
- * @static
330
- * @constant
331
- * @type {Object}
332
- * @default
333
- */
334
- JsonRpcRequestProcessor.Errors.INVALID_REQUEST = { code: -32600, message: 'Invalid Request' };
335
-
336
- /**
337
- * @static
338
- * @constant
339
- * @type {Object}
340
- * @default
341
- */
342
- JsonRpcRequestProcessor.Errors.METHOD_NOT_FOUND = { code: -32601, message: 'Method not found' };
343
-
344
- /**
345
- * @static
346
- * @constant
347
- * @type {Object}
348
- * @default
349
- */
350
- JsonRpcRequestProcessor.Errors.INVALID_PARAMS = { code: -32602, message: 'Invalid params' };
351
-
352
- /**
353
- * @static
354
- * @constant
355
- * @type {Object}
356
- * @default
357
- */
358
- JsonRpcRequestProcessor.Errors.INTERNAL_ERROR = { code: -32603, message: 'Internal error' };
359
-
360
- /**
361
- * @static
362
- * @constant
363
- * @type {Object}
364
- * @default
365
- */
366
- JsonRpcRequestProcessor.Errors.INVALID_METHOD = { code: -32604, message: 'Invalid method' };
@@ -1,175 +0,0 @@
1
- /**
2
- * @overview JsonRpcResponse
3
- * @copyright Dreamlab Onet.pl sp. z. o o 2012
4
- */
5
-
6
- var JsonRpcAbstract = require("./JsonRpcAbstract.js").JsonRpcAbstract;
7
- var JsonRpcError = require('./JsonRpcError.js').JsonRpcError;
8
-
9
- /**
10
- * @class JsonRpcResponse
11
- * @classdesc JsonRpcResponse
12
- * @extends JsonRpcAbstract
13
- *
14
- * @requires JsonRpcAbstract
15
- * @requires JsonRpcError
16
- *
17
- * @param {Number} id
18
- * @param {Object} result
19
- * @param {Object} error
20
- * @returns {JsonRpcResponse}
21
- *
22
- * @example empty object: new JsonRpcResponse()
23
- * @example specifining parameters: new JsonRpcResponse(id, result, error);
24
- * @example from object literal: new JsonRpcResponse({'id': 1, 'result': Object, 'error': {'code': -1, 'message': 'msg', 'data': 'some data'}});
25
- * @example from json string: new JsonRpcResponse("{'id': 1, 'result': Object, 'error': {'code': -1, 'message': 'msg', 'data': 'some data'}}");
26
- */
27
- var JsonRpcResponse = function (id, result, error) {
28
- this._id = null;
29
- this._result = null;
30
- this._error = null;
31
- JsonRpcAbstract.apply(this, arguments);
32
- };
33
-
34
- JsonRpcResponse.prototype = Object.create(JsonRpcAbstract.prototype);
35
-
36
- /**
37
- * Initialize object from object literal
38
- * @param {Array} args object literal in format: [id:Number, result:Object, error:Object]
39
- * @return {undefined}
40
- * @throws JsonRpcAbstract.Exceptions.INVALID_JSON_RPC
41
- * @method
42
- * @private
43
- */
44
- JsonRpcResponse.prototype._init = function (args) {
45
- if (args[0]) {
46
- this.setId(args[0]);
47
- } else {
48
- throw new Error(JsonRpcAbstract.Exceptions.INVALID_JSON_RPC);
49
- }
50
-
51
- if (typeof args[1] !== 'undefined') {
52
- this.setResult(args[1]);
53
- }
54
-
55
- if (typeof args[2] !== 'undefined') {
56
- this.setError(new JsonRpcError(args[2]));
57
- }
58
- };
59
-
60
- /**
61
- * Parses response json into array of parameters
62
- * @param {Object} json object literal in format: {'id':Number, 'result':Object, 'error': Object}
63
- * @return {Array}
64
- * @method
65
- * @private
66
- */
67
- JsonRpcResponse.prototype._parse = function (json) {
68
- return [
69
- json.id,
70
- json.result,
71
- json.error
72
- ];
73
- };
74
-
75
- /**
76
- * Sets JsonRpc Id
77
- * @param {Number} id
78
- * @returns {JsonRpcResponse}
79
- * @throws Id should be a string
80
- * @method
81
- */
82
- JsonRpcResponse.prototype.setId = function (id) {
83
- if (typeof id !== 'string') {
84
- throw new Error("Id should be a String");
85
- }
86
- this._id = id;
87
- return this;
88
- };
89
-
90
- /**
91
- * Returns JsonRpc Id
92
- * @returns {Number}
93
- * @method
94
- */
95
- JsonRpcResponse.prototype.getId = function () {
96
- return this._id;
97
- };
98
-
99
- /**
100
- * Sets JsonRpc result object
101
- * @param {Object} result
102
- * @returns {JsonRpcResponse}
103
- * @method
104
- */
105
- JsonRpcResponse.prototype.setResult = function (result) {
106
- this._result = result;
107
- return this;
108
- };
109
-
110
- /**
111
- * Returns JsonRpc result object
112
- * @returns {Object}
113
- * @method
114
- */
115
- JsonRpcResponse.prototype.getResult = function () {
116
- return this._result;
117
- };
118
-
119
- /**
120
- * Sets JsonRpc error
121
- *
122
- * @param {Number|JsonRpcError} code
123
- * @param {String} message
124
- * @param {Object} data
125
- *
126
- * @returns {JsonRpcResponse}
127
- * @example jsonRpcResponse.setError(-1, 'msg', 'data');
128
- * @example jsonRpcResponse.setError(new JsonRpcError(-1, 'msg', 'data'));
129
- * @method
130
- */
131
- JsonRpcResponse.prototype.setError = function (code, message, data) {
132
- if (code instanceof JsonRpcError) {
133
- this._error = code;
134
- } else {
135
- this._error = new JsonRpcError(code, message, data);
136
- }
137
- return this;
138
- };
139
-
140
- /**
141
- * Returns JsonRpc error
142
- * @returns {JsonRpcError}
143
- * @method
144
- */
145
- JsonRpcResponse.prototype.getError = function () {
146
- return this._error;
147
- };
148
-
149
- /**
150
- * Determines if JsonRpc response has error in it
151
- * @method
152
- * @returns {Boolean}
153
- */
154
- JsonRpcResponse.prototype.isError = function () {
155
- return this._error !== null;
156
- };
157
-
158
- /**
159
- * Returns JSON representation of a jsonrpc response
160
- * @method
161
- * @returns {Object} in format: {jsonrpc: "1.1", id: 20, result:Object, error: {code: -1, message: 'msg', data: 'data'}}
162
- */
163
- JsonRpcResponse.prototype.toJson = function () {
164
- var jsonObj = {
165
- jsonrpc: this._jsonrpc,
166
- id: this._id,
167
- result: this._result
168
- };
169
- if (this._error) {
170
- jsonObj.error = this._error.toJson();
171
- }
172
- return jsonObj;
173
- };
174
-
175
- exports.JsonRpcResponse = JsonRpcResponse;
@@ -1,81 +0,0 @@
1
- /**
2
- * @overview JsonRpcServer
3
- * @copyright Dreamlab Onet.pl sp. z. o o 2012
4
- */
5
-
6
- var Server = require('../http/Server.js').Server;
7
- var JsonRpcRequestProcessor = require('./JsonRpcRequestProcessor.js').JsonRpcRequestProcessor;
8
-
9
- /**
10
- * @class JsonRpcServer
11
- * @classdesc JsonRpcServer
12
- * @extends Server
13
- *
14
- * @requires Server
15
- * @requires JsonRpcRequestProcessor
16
- *
17
- * @returns {JsonRpcServer}
18
- */
19
- var JsonRpcServer = exports.JsonRpcServer = function () {
20
- this._methods = {};
21
- Server.call(this, JsonRpcRequestProcessor);
22
- };
23
-
24
- JsonRpcServer.prototype = Object.create(Server.prototype);
25
-
26
- /**
27
- * Add method to JsonRpc Server
28
- * @param {String} methodName
29
- * @param {JsonRpcMethod} method
30
- * @returns {Boolean}
31
- * @method
32
- */
33
- JsonRpcServer.prototype.addMethod = function (methodName, method) {
34
- if (!this._methods.hasOwnProperty(methodName)) {
35
- this._methods[methodName] = method;
36
- return true;
37
- }
38
- return false;
39
- };
40
-
41
- /**
42
- * Returns JsonRpc method
43
- * @param {String} methodName
44
- * @returns {JsonRpcMethod|false}
45
- * @method
46
- */
47
- JsonRpcServer.prototype.getMethod = function (methodName) {
48
- if (this._methods.hasOwnProperty(methodName)) {
49
- return this._methods[methodName];
50
- }
51
- return false;
52
- };
53
-
54
- /**
55
- * Removes method from the JsonRpc server
56
- * @param {String} methodName
57
- * @returns {Boolean}
58
- * @method
59
- */
60
- JsonRpcServer.prototype.removeMethod = function (methodName) {
61
- if (this._methods.hasOwnProperty(methodName)) {
62
- delete this._methods[methodName];
63
- return true;
64
- }
65
- return false;
66
- };
67
-
68
- /**
69
- * @static
70
- * @constant
71
- * @namespace
72
- */
73
- JsonRpcServer.Exceptions = {};
74
-
75
- /**
76
- * @static
77
- * @constant
78
- * @type {String}
79
- * @default
80
- */
81
- JsonRpcServer.Exceptions.WRONG_CLASS = "Method has to be an instanceof JsonRpcMethod";
@@ -1,15 +0,0 @@
1
- var EmptyLogger = function () {};
2
-
3
- EmptyLogger.prototype.attach = function () {};
4
- EmptyLogger.prototype.append = function () {};
5
- EmptyLogger.prototype.parse = function (obj) {
6
- return obj;
7
- };
8
-
9
- EmptyLogger.prototype.log = function () {};
10
- EmptyLogger.prototype.info = function () {};
11
- EmptyLogger.prototype.warn = function () {};
12
- EmptyLogger.prototype.error = function () {};
13
- EmptyLogger.prototype.trace = function () {};
14
-
15
- exports.EmptyLogger = EmptyLogger;
@@ -1,20 +0,0 @@
1
- var EmptyLogger = require('./EmptyLogger.js').EmptyLogger;
2
- var WildFireLogger = require('./WildFireLogger.js').WildFireLogger;
3
-
4
- LoggerFactory = function () {};
5
- LoggerFactory.getInstance = function (request) {
6
- var i = 0,
7
- l = LoggerFactory.LOGGERS.length;
8
-
9
- for (; i < l; i++) {
10
- if (LoggerFactory.LOGGERS[i].match(request)) {
11
- return LoggerFactory.LOGGERS[i];
12
- }
13
- }
14
-
15
- return null;
16
- };
17
-
18
- LoggerFactory.LOGGERS = [ WildFireLogger ];
19
-
20
- exports.LoggerFactory = LoggerFactory;