traceur-rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +8 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +87 -0
  10. data/Rakefile +2 -0
  11. data/lib/js/compile.js +31 -0
  12. data/lib/traceur-rb.rb +1 -0
  13. data/lib/traceur.rb +43 -0
  14. data/lib/traceur/compilation_options.rb +65 -0
  15. data/lib/traceur/compiler.rb +33 -0
  16. data/lib/traceur/configuration.rb +47 -0
  17. data/lib/traceur/node.rb +26 -0
  18. data/lib/traceur/node/command_result.rb +28 -0
  19. data/lib/traceur/node/runner.rb +40 -0
  20. data/lib/traceur/version.rb +3 -0
  21. data/spec/examples/classes.js +12 -0
  22. data/spec/integration/examples_spec.rb +28 -0
  23. data/spec/spec_helper.rb +1 -0
  24. data/spec/traceur/compilation_options_spec.rb +31 -0
  25. data/spec/traceur/configuration_spec.rb +54 -0
  26. data/spec/traceur/node_spec.rb +15 -0
  27. data/traceur-rb.gemspec +25 -0
  28. data/vendor/node_modules/.bin/traceur +3 -0
  29. data/vendor/node_modules/traceur/README.md +40 -0
  30. data/vendor/node_modules/traceur/bin/traceur-runtime.js +2101 -0
  31. data/vendor/node_modules/traceur/bin/traceur.js +23034 -0
  32. data/vendor/node_modules/traceur/node_modules/.bin/semver +125 -0
  33. data/vendor/node_modules/traceur/node_modules/commander/Readme.md +208 -0
  34. data/vendor/node_modules/traceur/node_modules/commander/index.js +852 -0
  35. data/vendor/node_modules/traceur/node_modules/commander/package.json +40 -0
  36. data/vendor/node_modules/traceur/node_modules/q-io/.npmignore +1 -0
  37. data/vendor/node_modules/traceur/node_modules/q-io/.travis.yml +3 -0
  38. data/vendor/node_modules/traceur/node_modules/q-io/CHANGES.md +122 -0
  39. data/vendor/node_modules/traceur/node_modules/q-io/LICENSE +19 -0
  40. data/vendor/node_modules/traceur/node_modules/q-io/README.md +928 -0
  41. data/vendor/node_modules/traceur/node_modules/q-io/buffer-stream.js +59 -0
  42. data/vendor/node_modules/traceur/node_modules/q-io/coverage-report.js +44 -0
  43. data/vendor/node_modules/traceur/node_modules/q-io/deprecate.js +51 -0
  44. data/vendor/node_modules/traceur/node_modules/q-io/fs-boot.js +307 -0
  45. data/vendor/node_modules/traceur/node_modules/q-io/fs-common.js +499 -0
  46. data/vendor/node_modules/traceur/node_modules/q-io/fs-mock.js +547 -0
  47. data/vendor/node_modules/traceur/node_modules/q-io/fs-root.js +105 -0
  48. data/vendor/node_modules/traceur/node_modules/q-io/fs.js +355 -0
  49. data/vendor/node_modules/traceur/node_modules/q-io/fs2http.js +65 -0
  50. data/vendor/node_modules/traceur/node_modules/q-io/http-apps.js +152 -0
  51. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/chain.js +24 -0
  52. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/content.js +93 -0
  53. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/cookie.js +154 -0
  54. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/decorators.js +178 -0
  55. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/fs.js +417 -0
  56. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/html.js +58 -0
  57. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/json.js +78 -0
  58. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/negotiate.js +120 -0
  59. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/proxy.js +27 -0
  60. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/redirect.js +209 -0
  61. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/route.js +125 -0
  62. data/vendor/node_modules/traceur/node_modules/q-io/http-apps/status.js +175 -0
  63. data/vendor/node_modules/traceur/node_modules/q-io/http-cookie.js +75 -0
  64. data/vendor/node_modules/traceur/node_modules/q-io/http.js +378 -0
  65. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/.npmignore +11 -0
  66. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/.travis.yml +4 -0
  67. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/CHANGES.md +78 -0
  68. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/LICENSE.md +21 -0
  69. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/README.md +1285 -0
  70. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/collections.js +22 -0
  71. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/dict.js +142 -0
  72. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/fast-map.js +57 -0
  73. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/fast-set.js +183 -0
  74. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-collection.js +261 -0
  75. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-map.js +186 -0
  76. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-order.js +55 -0
  77. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-set.js +59 -0
  78. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/heap.js +236 -0
  79. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/iterator.js +371 -0
  80. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/list.js +435 -0
  81. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/array-changes.js +247 -0
  82. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/map-changes.js +147 -0
  83. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/property-changes.js +448 -0
  84. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/range-changes.js +139 -0
  85. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/lru-map.js +79 -0
  86. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/lru-set.js +142 -0
  87. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/map.js +60 -0
  88. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/multi-map.js +41 -0
  89. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/package.json +12 -0
  90. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/sync +7 -0
  91. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/sync.patch +48 -0
  92. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/weak-map.js +590 -0
  93. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/package.json +49 -0
  94. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/set.js +173 -0
  95. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-array.js +274 -0
  96. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-function.js +59 -0
  97. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-object.js +538 -0
  98. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-regexp.js +14 -0
  99. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim.js +6 -0
  100. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array-map.js +49 -0
  101. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array-set.js +51 -0
  102. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array.js +269 -0
  103. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-map.js +61 -0
  104. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-set.js +736 -0
  105. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/tree-log.js +40 -0
  106. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/weak-map.js +1 -0
  107. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/LICENSE +19 -0
  108. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/README.md +66 -0
  109. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/mime.js +114 -0
  110. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/package.json +35 -0
  111. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/test.js +84 -0
  112. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/types/mime.types +1588 -0
  113. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/types/node.types +77 -0
  114. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/CHANGES +15 -0
  115. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/LICENSE +19 -0
  116. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/README +96 -0
  117. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/lib/mimeparse.js +166 -0
  118. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/package.json +43 -0
  119. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/CONTRIBUTING.md +40 -0
  120. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/LICENSE +19 -0
  121. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/README.md +813 -0
  122. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/benchmark/compare-with-callbacks.js +71 -0
  123. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/benchmark/scenarios.js +36 -0
  124. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/package.json +93 -0
  125. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/q.js +1937 -0
  126. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/queue.js +35 -0
  127. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/.gitmodules +6 -0
  128. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/History.md +36 -0
  129. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/Makefile +7 -0
  130. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/Readme.md +38 -0
  131. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/benchmark.js +32 -0
  132. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/examples.js +39 -0
  133. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/index.js +2 -0
  134. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/lib/querystring.js +123 -0
  135. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/package.json +19 -0
  136. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/.gitmodules +3 -0
  137. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/.npmignore +3 -0
  138. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/History.md +128 -0
  139. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/Makefile +53 -0
  140. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/Readme.md +61 -0
  141. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/bin/expresso +856 -0
  142. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/api.html +1080 -0
  143. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/index.html +377 -0
  144. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/index.md +290 -0
  145. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/layout/foot.html +3 -0
  146. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/layout/head.html +42 -0
  147. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/lib/bar.js +4 -0
  148. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/lib/foo.js +16 -0
  149. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/package.json +12 -0
  150. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/assert.test.js +91 -0
  151. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/async.test.js +12 -0
  152. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/bar.test.js +13 -0
  153. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/foo.test.js +14 -0
  154. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/http.test.js +146 -0
  155. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/serial/async.test.js +39 -0
  156. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/serial/http.test.js +48 -0
  157. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/.gitmodules +3 -0
  158. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/History.md +22 -0
  159. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/Makefile +6 -0
  160. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/Readme.md +248 -0
  161. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/examples/runner.js +53 -0
  162. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/index.js +2 -0
  163. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/lib/eql.js +91 -0
  164. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/lib/should.js +548 -0
  165. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/package.json +8 -0
  166. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/test/should.test.js +358 -0
  167. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/test/querystring.test.js +133 -0
  168. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/.npmignore +3 -0
  169. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/.travis.yml +4 -0
  170. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/LICENSE.md +20 -0
  171. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/README.md +33 -0
  172. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/package.json +37 -0
  173. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/test/url2-spec.js +125 -0
  174. data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/url2.js +151 -0
  175. data/vendor/node_modules/traceur/node_modules/q-io/package.json +51 -0
  176. data/vendor/node_modules/traceur/node_modules/q-io/reader.js +133 -0
  177. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/boot-directory-spec.js +47 -0
  178. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/contains-spec.js +11 -0
  179. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/fixtures/hello.txt +1 -0
  180. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/issues/1-spec.js +33 -0
  181. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/make-tree-spec.js +92 -0
  182. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/append-spec.js +41 -0
  183. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/copy-tree-spec.js +57 -0
  184. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/fixture/hello.txt +1 -0
  185. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/link-spec.js +70 -0
  186. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/make-tree-spec.js +109 -0
  187. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/merge-spec.js +67 -0
  188. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/move-spec.js +219 -0
  189. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/object-spec.js +20 -0
  190. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/range-spec.js +26 -0
  191. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/read-spec.js +40 -0
  192. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/remove-directory-spec.js +37 -0
  193. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/remove-tree-spec.js +39 -0
  194. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/root-spec.js +32 -0
  195. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/stat-spec.js +26 -0
  196. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/symbolic-link-spec.js +86 -0
  197. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/working-directory-spec.js +31 -0
  198. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/write-spec.js +73 -0
  199. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/range-spec.js +23 -0
  200. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/range-spec.txt +1 -0
  201. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/read-spec.js +22 -0
  202. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/relative-spec.js +25 -0
  203. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/reroot-spec.js +45 -0
  204. data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/write-spec.js +38 -0
  205. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/cookie-spec.js +52 -0
  206. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/directory-list-spec.js +86 -0
  207. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/01234.txt +1 -0
  208. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/1234.txt +1 -0
  209. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/5678.txt +0 -0
  210. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/9012/3456.txt +0 -0
  211. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/hosts-spec.js +49 -0
  212. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/interpret-range-spec.js +47 -0
  213. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/partial-range-spec.js +186 -0
  214. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/proxy-spec.js +82 -0
  215. data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/symbolic-link-spec.js +110 -0
  216. data/vendor/node_modules/traceur/node_modules/q-io/spec/http/agent-spec.js +96 -0
  217. data/vendor/node_modules/traceur/node_modules/q-io/spec/http/basic-spec.js +96 -0
  218. data/vendor/node_modules/traceur/node_modules/q-io/spec/lib/jasmine-promise.js +42 -0
  219. data/vendor/node_modules/traceur/node_modules/q-io/writer.js +111 -0
  220. data/vendor/node_modules/traceur/node_modules/semver/.npmignore +1 -0
  221. data/vendor/node_modules/traceur/node_modules/semver/LICENSE +27 -0
  222. data/vendor/node_modules/traceur/node_modules/semver/Makefile +24 -0
  223. data/vendor/node_modules/traceur/node_modules/semver/README.md +158 -0
  224. data/vendor/node_modules/traceur/node_modules/semver/bin/semver +125 -0
  225. data/vendor/node_modules/traceur/node_modules/semver/foot.js +6 -0
  226. data/vendor/node_modules/traceur/node_modules/semver/head.js +2 -0
  227. data/vendor/node_modules/traceur/node_modules/semver/package.json +31 -0
  228. data/vendor/node_modules/traceur/node_modules/semver/semver.browser.js +1039 -0
  229. data/vendor/node_modules/traceur/node_modules/semver/semver.browser.js.gz +0 -0
  230. data/vendor/node_modules/traceur/node_modules/semver/semver.js +1043 -0
  231. data/vendor/node_modules/traceur/node_modules/semver/semver.min.js +1 -0
  232. data/vendor/node_modules/traceur/node_modules/semver/semver.min.js.gz +0 -0
  233. data/vendor/node_modules/traceur/node_modules/semver/test/amd.js +15 -0
  234. data/vendor/node_modules/traceur/node_modules/semver/test/gtr.js +173 -0
  235. data/vendor/node_modules/traceur/node_modules/semver/test/index.js +584 -0
  236. data/vendor/node_modules/traceur/node_modules/semver/test/ltr.js +174 -0
  237. data/vendor/node_modules/traceur/node_modules/semver/test/no-module.js +19 -0
  238. data/vendor/node_modules/traceur/package.json +64 -0
  239. data/vendor/node_modules/traceur/src/node/System.js +31 -0
  240. data/vendor/node_modules/traceur/src/node/api.js +124 -0
  241. data/vendor/node_modules/traceur/src/node/command.js +141 -0
  242. data/vendor/node_modules/traceur/src/node/compile-single-file.js +69 -0
  243. data/vendor/node_modules/traceur/src/node/compiler.js +116 -0
  244. data/vendor/node_modules/traceur/src/node/deferred.js +110 -0
  245. data/vendor/node_modules/traceur/src/node/file-util.js +73 -0
  246. data/vendor/node_modules/traceur/src/node/getopt.js +147 -0
  247. data/vendor/node_modules/traceur/src/node/inline-module.js +149 -0
  248. data/vendor/node_modules/traceur/src/node/interpreter.js +33 -0
  249. data/vendor/node_modules/traceur/src/node/nodeLoader.js +41 -0
  250. data/vendor/node_modules/traceur/src/node/require.js +85 -0
  251. data/vendor/node_modules/traceur/src/node/to-amd-compiler.js +33 -0
  252. data/vendor/node_modules/traceur/src/node/to-commonjs-compiler.js +33 -0
  253. data/vendor/node_modules/traceur/src/node/traceur.js +32 -0
  254. data/vendor/node_modules/traceur/traceur +3 -0
  255. metadata +359 -0
@@ -0,0 +1,125 @@
1
+
2
+ var Q = require("q");
3
+ var StatusApps = require("./status");
4
+
5
+ /**
6
+ * Makes a Q-JSGI app that only responds when there is nothing left
7
+ * on the path to route. If the there is unprocessed data on the
8
+ * path, the returned app either forwards to the `notFound` app or
9
+ * returns a `404 Not Found` response.
10
+ *
11
+ * @param {App} app a Q-JSGI application to
12
+ * respond to this end of the routing chain.
13
+ * @param {App} notFound (optional) defaults
14
+ * to the `notFound` app.
15
+ * @returns {App}
16
+ */
17
+ exports.Cap = function (app, notFound) {
18
+ notFound = notFound || StatusApps.notFound;
19
+ return function (request, response) {
20
+ // TODO Distinguish these cases
21
+ if (request.pathInfo === "" || request.pathInfo === "/") {
22
+ return app(request, response);
23
+ } else {
24
+ return notFound(request, response);
25
+ }
26
+ };
27
+ };
28
+
29
+ /**
30
+ * Wraps an app with a function that will observe incoming requests
31
+ * before giving the app an opportunity to respond. If the "tap"
32
+ * function returns a response, it will be used in lieu of forwarding
33
+ * the request to the wrapped app.
34
+ */
35
+ exports.Tap = function (app, tap) {
36
+ return function (request, response) {
37
+ var self = this, args = arguments;
38
+ return Q.when(tap.apply(this, arguments), function (response) {
39
+ if (response) {
40
+ return response;
41
+ } else {
42
+ return app.apply(self, args);
43
+ }
44
+ });
45
+ };
46
+ };
47
+
48
+ /**
49
+ * Wraps an app with a "trap" function that intercepts and may
50
+ * alter or replace the response of the wrapped application.
51
+ */
52
+ exports.Trap = function (app, trap) {
53
+ return function (request, response) {
54
+ return Q.when(app.apply(this, arguments), function (response) {
55
+ if (response) {
56
+ response.headers = response.headers || {};
57
+ return trap(response, request) || response;
58
+ }
59
+ });
60
+ };
61
+ };
62
+
63
+ /**
64
+ * Makes a Q-JSGI app that branches requests based on the next
65
+ * unprocessed path component.
66
+ * @param {Object * App} paths a mapping from path components (single
67
+ * file or directory names) to Q-JSGI applications for subsequent
68
+ * routing. The mapping may be a plain JavaScript `Object` record,
69
+ * which must own the mapping properties, or an object that has
70
+ * `has(key)` and `get(key)` methods in its prototype chain.
71
+ * @param {App} notFound a Q-JSGI application
72
+ * that handles requests for which the next file name does not exist
73
+ * in paths.
74
+ * @returns {App}
75
+ */
76
+ exports.Branch = function (paths, notFound) {
77
+ if (!paths)
78
+ paths = {};
79
+ if (!notFound)
80
+ notFound = StatusApps.notFound;
81
+ return function (request, response) {
82
+ if (!/^\//.test(request.pathInfo)) {
83
+ return notFound(request, response);
84
+ }
85
+ var path = request.pathInfo.slice(1);
86
+ var parts = path.split("/");
87
+ var part = decodeURIComponent(parts.shift());
88
+ if (Object.has(paths, part)) {
89
+ request.scriptName = request.scriptName + part + "/";
90
+ request.pathInfo = path.slice(part.length);
91
+ return Object.get(paths, part)(request, response);
92
+ }
93
+ return notFound(request, response);
94
+ };
95
+ };
96
+
97
+ /**
98
+ * Returns the response of the first application that returns a
99
+ * non-404 response status.
100
+ *
101
+ * @param {Array * App} apps a cascade of applications to try
102
+ * successively until one of them returns a non-404 status.
103
+ * @returns {App}
104
+ */
105
+ exports.FirstFound = function (cascade) {
106
+ return function (request, response) {
107
+ var i = 0, ii = cascade.length;
108
+ function next() {
109
+ var response = cascade[i++](request, response);
110
+ if (i < ii) {
111
+ return Q.when(response, function (response) {
112
+ if (response.status === 404) {
113
+ return next();
114
+ } else {
115
+ return response;
116
+ }
117
+ });
118
+ } else {
119
+ return response;
120
+ }
121
+ }
122
+ return next();
123
+ };
124
+ };
125
+
@@ -0,0 +1,175 @@
1
+
2
+ var Negotiation = require("./negotiate");
3
+ var HtmlApps = require("./html");
4
+
5
+ /**
6
+ * {Object * String} a mapping of HTTP status codes to
7
+ * their standard descriptions.
8
+ */
9
+ // Every standard HTTP code mapped to the appropriate message.
10
+ // Stolen from Rack which stole from Mongrel
11
+ exports.statusCodes = {
12
+ 100: 'Continue',
13
+ 101: 'Switching Protocols',
14
+ 102: 'Processing',
15
+ 200: 'OK',
16
+ 201: 'Created',
17
+ 202: 'Accepted',
18
+ 203: 'Non-Authoritative Information',
19
+ 204: 'No Content',
20
+ 205: 'Reset Content',
21
+ 206: 'Partial Content',
22
+ 207: 'Multi-Status',
23
+ 300: 'Multiple Choices',
24
+ 301: 'Moved Permanently',
25
+ 302: 'Found',
26
+ 303: 'See Other',
27
+ 304: 'Not Modified',
28
+ 305: 'Use Proxy',
29
+ 307: 'Temporary Redirect',
30
+ 400: 'Bad Request',
31
+ 401: 'Unauthorized',
32
+ 402: 'Payment Required',
33
+ 403: 'Forbidden',
34
+ 404: 'Not Found',
35
+ 405: 'Method Not Allowed',
36
+ 406: 'Not Acceptable',
37
+ 407: 'Proxy Authentication Required',
38
+ 408: 'Request Timeout',
39
+ 409: 'Conflict',
40
+ 410: 'Gone',
41
+ 411: 'Length Required',
42
+ 412: 'Precondition Failed',
43
+ 413: 'Request Entity Too Large',
44
+ 414: 'Request-URI Too Large',
45
+ 415: 'Unsupported Media Type',
46
+ 416: 'Request Range Not Satisfiable',
47
+ 417: 'Expectation Failed',
48
+ 422: 'Unprocessable Entity',
49
+ 423: 'Locked',
50
+ 424: 'Failed Dependency',
51
+ 500: 'Internal Server Error',
52
+ 501: 'Not Implemented',
53
+ 502: 'Bad Gateway',
54
+ 503: 'Service Unavailable',
55
+ 504: 'Gateway Timeout',
56
+ 505: 'HTTP Version Not Supported',
57
+ 507: 'Insufficient Storage'
58
+ };
59
+
60
+ /**
61
+ * {Object * Number} a mapping from HTTP status descriptions
62
+ * to HTTP status codes.
63
+ */
64
+ exports.statusMessages = {};
65
+ for (var code in exports.statusCodes)
66
+ exports.statusMessages[exports.statusCodes[code]] = +code;
67
+
68
+ /**
69
+ * Determines whether an HTTP response should have a
70
+ * response body, based on its status code.
71
+ * @param {Number} status
72
+ * @returns whether the HTTP response for the given status
73
+ * code has content.
74
+ */
75
+ exports.statusWithNoEntityBody = function (status) {
76
+ return (status >= 100 && status <= 199) ||
77
+ status == 204 || status == 304;
78
+ };
79
+
80
+ /**
81
+ * @param {Number} status
82
+ * @returns {Function(Request) :Response} a JSGI app that returns
83
+ * a plain text response with the given status code.
84
+ */
85
+ exports.appForStatus = function (status) {
86
+ return function (request) {
87
+ return exports.responseForStatus(request, status, request.method + " " + request.path);
88
+ };
89
+ };
90
+
91
+ /**
92
+ * @param {Number} status an HTTP status code
93
+ * @param {String} message (optional) a message to include
94
+ * in the response body.
95
+ * @returns a JSGI HTTP response object with the given status
96
+ * code and message as its body, if the status supports
97
+ * a body.
98
+ */
99
+ exports.responseForStatus = function(request, status, addendum) {
100
+ if (exports.statusCodes[status] === undefined)
101
+ throw "Unknown status code";
102
+
103
+ var message = exports.statusCodes[status];
104
+
105
+ // RFC 2616, 10.2.5:
106
+ // The 204 response MUST NOT include a message-body, and thus is always
107
+ // terminated by the first empty line after the header fields.
108
+ // RFC 2616, 10.3.5:
109
+ // The 304 response MUST NOT contain a message-body, and thus is always
110
+ // terminated by the first empty line after the header fields.
111
+ if (exports.statusWithNoEntityBody(status)) {
112
+ return {status: status, headers: {}};
113
+ } else {
114
+ var handlers = {};
115
+ handlers["text/plain"] = exports.textResponseForStatus;
116
+ if (request.handleHtmlFragmentResponse) {
117
+ handlers["text/html"] = exports.htmlResponseForStatus;
118
+ }
119
+ var responseForStatus = Negotiation.negotiate(request, handlers) || exports.textResponseForStatus;
120
+ return responseForStatus(request, status, message, addendum);
121
+ }
122
+ };
123
+
124
+ exports.textResponseForStatus = function (request, status, message, addendum) {
125
+ var content = message + "\n";
126
+ if (addendum) {
127
+ content += addendum + "\n";
128
+ }
129
+ var contentLength = content.length;
130
+ return {
131
+ status: status,
132
+ statusMessage: message,
133
+ headers: {
134
+ "content-length": contentLength
135
+ },
136
+ body: [content]
137
+ };
138
+ };
139
+
140
+ exports.htmlResponseForStatus = function (request, status, message, addendum) {
141
+ return {
142
+ status: status,
143
+ statusMessage: message,
144
+ headers: {},
145
+ htmlTitle: message,
146
+ htmlFragment: {
147
+ forEach: function (write) {
148
+ write("<h1>" + HtmlApps.escapeHtml(message) + "</h1>\n");
149
+ write("<p>Status: " + status + "</p>\n");
150
+ if (addendum) {
151
+ write("<pre>" + HtmlApps.escapeHtml(addendum) + "</pre>\n");
152
+ }
153
+ }
154
+ }
155
+ }
156
+ };
157
+
158
+ /**
159
+ * {App} an application that returns a 400 response.
160
+ */
161
+ exports.badRequest = exports.appForStatus(400);
162
+ /**
163
+ * {App} an application that returns a 404 response.
164
+ */
165
+ exports.notFound = exports.appForStatus(404);
166
+ /**
167
+ * {App} an application that returns a 405 response.
168
+ */
169
+ exports.methodNotAllowed = exports.appForStatus(405);
170
+ /**
171
+ * {App} an application that returns a 405 response.
172
+ */
173
+ exports.noLanguage =
174
+ exports.notAcceptable = exports.appForStatus(406);
175
+
@@ -0,0 +1,75 @@
1
+
2
+ /**
3
+ * Provides utilities for reading and writing HTTP cookies.
4
+ * @module
5
+ */
6
+
7
+ /*whatsupdoc*/
8
+
9
+ var QS = require("qs");
10
+
11
+ /**
12
+ * @param {String} cookie
13
+ * @returns {Object}
14
+ */
15
+ exports.parse = function (cookie, date) {
16
+ date = date || new Date();
17
+ var parsed = {};
18
+ var terms = cookie.split(/[;,]/g);
19
+ var keyValue = terms.shift().split("=");
20
+ parsed.key = keyValue[0];
21
+ parsed.value = keyValue[1];
22
+ terms.forEach(function (term) {
23
+ var parts = term.split("=").map(function (part) {
24
+ return part.trim();
25
+ });
26
+ var key = parts[0], value = parts[1];
27
+ if (/^domain$/i.test(key)) {
28
+ parsed.domain = value;
29
+ } else if (/^path$/i.test(key)) {
30
+ parsed.path = value;
31
+ } else if (/^expires$/i.test(key)) {
32
+ parsed.expires = new Date(
33
+ +new Date() + // actual now
34
+ (new Date(value) - date) // server offset
35
+ );
36
+ } else if (/^max-age$/i.test(key)) {
37
+ parsed.expires = new Date(
38
+ new Date().getTime() +
39
+ (value * 1000)
40
+ );
41
+ } else if (/^secure$/i.test(key)) {
42
+ parsed.secure = true;
43
+ } else if (/^httponly$/i.test(key)) {
44
+ parsed.httpOnly = true;
45
+ }
46
+ });
47
+ return parsed;
48
+ };
49
+
50
+ /**
51
+ * @param {String} key
52
+ * @param {String} value
53
+ * @param {Object} options (optional)
54
+ * @returns {String} a cookie string
55
+ */
56
+ exports.stringify = function (key, value, options) {
57
+ var cookie = (
58
+ encodeURIComponent(key) + "=" +
59
+ encodeURIComponent(value)
60
+ );
61
+ if (options) {
62
+ if (options.domain)
63
+ cookie += "; Domain=" + encodeURIComponent(options.domain);
64
+ if (options.path)
65
+ cookie += "; Path=" + encodeURIComponent(options.path);
66
+ if (options.expires)
67
+ cookie += "; Expires=" + options.expires.toGMTString();
68
+ if (options.secure)
69
+ cookie += "; Secure";
70
+ if (options.httpOnly)
71
+ cookie += "; HttpOnly";
72
+ }
73
+ return cookie;
74
+ };
75
+
@@ -0,0 +1,378 @@
1
+ /**
2
+ * A promise-based Q-JSGI server and client API.
3
+ * @module
4
+ */
5
+
6
+ /*whatsupdoc*/
7
+
8
+ var HTTP = require("http"); // node
9
+ var HTTPS = require("https"); // node
10
+ var URL = require("url2"); // node
11
+ var Q = require("q");
12
+ var Reader = require("./reader");
13
+
14
+ /**
15
+ * @param {respond(request Request)} respond a JSGI responder function that
16
+ * receives a Request object as its argument. The JSGI responder promises to
17
+ * return an object of the form `{status, headers, body}`. The status and
18
+ * headers must be fully resolved, but the body may be a promise for an object
19
+ * with a `forEach(write(chunk String))` method, albeit an array of strings.
20
+ * The `forEach` method may promise to resolve when all chunks have been
21
+ * written.
22
+ * @returns a Node Server object.
23
+ */
24
+ exports.Server = function (respond) {
25
+ var self = Object.create(exports.Server.prototype);
26
+
27
+ var server = HTTP.createServer(function (_request, _response) {
28
+ var request = exports.ServerRequest(_request);
29
+ var response = exports.ServerResponse(_response);
30
+
31
+ var closed = Q.defer();
32
+ _request.on("end", function (error, value) {
33
+ if (error) {
34
+ closed.reject(error);
35
+ } else {
36
+ closed.resolve(value);
37
+ }
38
+ });
39
+
40
+ Q.when(request, function (request) {
41
+ return Q.when(respond(request, response), function (response) {
42
+ if (!response)
43
+ return;
44
+
45
+ _response.writeHead(response.status, response.headers);
46
+
47
+ if (response.onclose || response.onClose)
48
+ Q.when(closed, response.onclose || response.onClose);
49
+
50
+ return Q.when(response.body, function (body) {
51
+ var length;
52
+ if (
53
+ Array.isArray(body) &&
54
+ (length = body.length) &&
55
+ body.every(function (chunk) {
56
+ return typeof chunk === "string"
57
+ })
58
+ ) {
59
+ body.forEach(function (chunk, i) {
60
+ if (i < length - 1) {
61
+ _response.write(chunk, response.charset);
62
+ } else {
63
+ _response.end(chunk, response.charset);
64
+ }
65
+ });
66
+ } else if (body) {
67
+ var end;
68
+ var done = body.forEach(function (chunk) {
69
+ end = Q.when(end, function () {
70
+ return Q.when(chunk, function (chunk) {
71
+ _response.write(chunk, response.charset);
72
+ });
73
+ });
74
+ });
75
+ return Q.when(done, function () {
76
+ return Q.when(end, function () {
77
+ _response.end();
78
+ });
79
+ });
80
+ } else {
81
+ _response.end();
82
+ }
83
+ });
84
+
85
+ })
86
+ })
87
+ .done(); // should be .fail(self.emitter("error"))
88
+
89
+ });
90
+
91
+ var stopped = Q.defer();
92
+ server.on("close", function (err) {
93
+ if (err) {
94
+ stopped.reject(err);
95
+ } else {
96
+ stopped.resolve();
97
+ }
98
+ });
99
+
100
+ /***
101
+ * Stops the server.
102
+ * @returns {Promise * Undefined} a promise that will
103
+ * resolve when the server is stopped.
104
+ */
105
+ self.stop = function () {
106
+ server.close();
107
+ listening = undefined;
108
+ return stopped.promise;
109
+ };
110
+
111
+ var listening = Q.defer();
112
+ server.on("listening", function (err) {
113
+ if (err) {
114
+ listening.reject(err);
115
+ } else {
116
+ listening.resolve(self);
117
+ }
118
+ });
119
+
120
+ /***
121
+ * Starts the server, listening on the given port
122
+ * @param {Number} port
123
+ * @returns {Promise * Undefined} a promise that will
124
+ * resolve when the server is ready to receive
125
+ * connections
126
+ */
127
+ self.listen = function (/*...args*/) {
128
+ if (typeof server.port !== "undefined")
129
+ return Q.reject(new Error("A server cannot be restarted or " +
130
+ "started on a new port"));
131
+ server.listen.apply(server, arguments);
132
+ return listening.promise;
133
+ };
134
+
135
+ self.stopped = stopped.promise;
136
+
137
+ self.node = server;
138
+ self.nodeServer = server; // Deprecated
139
+ self.address = server.address.bind(server);
140
+
141
+ return self;
142
+ };
143
+
144
+ Object.defineProperties(exports.Server, {
145
+
146
+ port: {
147
+ get: function () {
148
+ return this.node.port;
149
+ }
150
+ },
151
+
152
+ host: {
153
+ get: function () {
154
+ return this.node.host;
155
+ }
156
+ }
157
+
158
+ });
159
+
160
+ /**
161
+ * A wrapper for a Node HTTP Request, as received by
162
+ * the Q HTTP Server, suitable for use by the Q HTTP Client.
163
+ */
164
+ exports.ServerRequest = function (_request, ssl) {
165
+ var request = Object.create(_request);
166
+ /*** {Array} HTTP version. (JSGI) */
167
+ request.version = _request.httpVersion.split(".").map(Math.floor);
168
+ /*** {String} HTTP method, e.g., `"GET"` (JSGI) */
169
+ request.method = _request.method;
170
+ /*** {String} path, starting with `"/"` */
171
+ request.path = _request.url;
172
+ /*** {String} pathInfo, starting with `"/"`, the
173
+ * portion of the path that has not yet
174
+ * been routed (JSGI) */
175
+ request.pathInfo = URL.parse(_request.url).pathname;
176
+ /*** {String} scriptName, the portion of the path that
177
+ * has already been routed (JSGI) */
178
+ request.scriptName = "";
179
+ /*** {String} (JSGI) */
180
+ request.scheme = "http";
181
+
182
+ var address = _request.connection.address();
183
+ /*** {String} hostname */
184
+ if (_request.headers.host) {
185
+ request.hostname = _request.headers.host.split(":")[0];
186
+ } else {
187
+ request.hostname = address.address;
188
+ }
189
+ /*** {String} host */
190
+ request.host = request.hostname + ":" + address.port;
191
+ request.port = address.port;
192
+
193
+ var socket = _request.socket;
194
+ /*** {String} */
195
+ request.remoteHost = socket.remoteAddress;
196
+ /*** {Number} */
197
+ request.remotePort = socket.remotePort;
198
+
199
+ /*** {String} url */
200
+ request.url = URL.format({
201
+ protocol: request.scheme,
202
+ host: _request.headers.host,
203
+ port: request.port === (ssl ? 443 : 80) ? null : request.port,
204
+ path: request.path
205
+ });
206
+ /*** A Q IO asynchronous text reader */
207
+ request.body = Reader(_request);
208
+ /*** {Object} HTTP headers (JSGI)*/
209
+ request.headers = _request.headers;
210
+ /*** The underlying Node request */
211
+ request.node = _request;
212
+ request.nodeRequest = _request; // Deprecated
213
+ /*** The underlying Node TCP connection */
214
+ request.nodeConnection = _request.connection;
215
+
216
+ return Q.when(request.body, function (body) {
217
+ request.body = body;
218
+ return request;
219
+ });
220
+ };
221
+
222
+ exports.ServerResponse = function (_response, ssl) {
223
+ var response = Object.create(_response);
224
+ response.ssl = ssl;
225
+ response.node = _response;
226
+ response.nodeResponse = _response; // Deprecated
227
+ return response;
228
+ };
229
+
230
+ exports.normalizeRequest = function (request) {
231
+ if (typeof request === "string") {
232
+ request = {
233
+ url: request
234
+ };
235
+ }
236
+ if (request.url) {
237
+ var url = URL.parse(request.url);
238
+ request.host = url.hostname;
239
+ request.port = url.port;
240
+ request.ssl = url.protocol === "https:";
241
+ request.method = request.method || "GET";
242
+ request.path = (url.pathname || "") + (url.search || "");
243
+ request.headers = request.headers || {};
244
+ request.headers.host = url.hostname; // FIXME name consistency
245
+ }
246
+ return request;
247
+ };
248
+
249
+ exports.normalizeResponse = function (response) {
250
+ if (response === void 0) {
251
+ return;
252
+ }
253
+ if (typeof response == "string") {
254
+ response = [response];
255
+ }
256
+ if (response.forEach) {
257
+ response = {
258
+ status: 200,
259
+ headers: {},
260
+ body: response
261
+ }
262
+ }
263
+ return response;
264
+ };
265
+
266
+ /**
267
+ * Issues an HTTP request.
268
+ *
269
+ * @param {Request {host, port, method, path, headers,
270
+ * body}} request (may be a promise)
271
+ * @returns {Promise * Response} promise for a response
272
+ */
273
+ exports.request = function (request) {
274
+ return Q.when(request, function (request) {
275
+
276
+ request = exports.normalizeRequest(request);
277
+
278
+ var deferred = Q.defer();
279
+ var ssl = request.ssl;
280
+ var http = ssl ? HTTPS : HTTP;
281
+
282
+ var headers = request.headers || {};
283
+
284
+ headers.host = headers.host || request.host;
285
+
286
+ var _request = http.request({
287
+ "host": request.host,
288
+ "port": request.port || (ssl ? 443 : 80),
289
+ "path": request.path || "/",
290
+ "method": request.method || "GET",
291
+ "headers": headers,
292
+ "agent": request.agent
293
+ }, function (_response) {
294
+ deferred.resolve(exports.ClientResponse(_response, request.charset));
295
+ _response.on("error", function (error) {
296
+ // TODO find a better way to channel
297
+ // this into the response
298
+ console.warn(error && error.stack || error);
299
+ deferred.reject(error);
300
+ });
301
+ });
302
+
303
+ _request.on("error", function (error) {
304
+ deferred.reject(error);
305
+ });
306
+
307
+ Q.when(request.body, function (body) {
308
+ var end, done;
309
+ if (body) {
310
+ done = body.forEach(function (chunk) {
311
+ end = Q.when(end, function () {
312
+ return Q.when(chunk, function (chunk) {
313
+ _request.write(chunk, request.charset);
314
+ });
315
+ });
316
+ });
317
+ }
318
+ return Q.when(end, function () {
319
+ return Q.when(done, function () {
320
+ _request.end();
321
+ });
322
+ });
323
+ }).done();
324
+
325
+ return deferred.promise;
326
+ });
327
+ };
328
+
329
+ /**
330
+ * Issues a GET request to the given URL and returns
331
+ * a promise for a `String` containing the entirety
332
+ * of the response.
333
+ *
334
+ * @param {String} url
335
+ * @returns {Promise * String} or a rejection if the
336
+ * status code is not exactly 200. The reason for the
337
+ * rejection is the full response object.
338
+ */
339
+ exports.read = function (request, qualifier) {
340
+ qualifier = qualifier || function (response) {
341
+ return response.status === 200;
342
+ };
343
+ return Q.when(exports.request(request), function (response) {
344
+ if (!qualifier(response)){
345
+ var error = new Error("HTTP request failed with code " + response.status);
346
+ error.response = response;
347
+ throw error;
348
+ }
349
+ return Q.post(response.body, 'read', []);
350
+ });
351
+ };
352
+
353
+
354
+ /**
355
+ * A wrapper for the Node HTTP Response as provided
356
+ * by the Q HTTP Client API, suitable for use by the
357
+ * Q HTTP Server API.
358
+ */
359
+ exports.ClientResponse = function (_response, charset) {
360
+ var response = Object.create(exports.ClientResponse.prototype);
361
+ /*** {Number} HTTP status code */
362
+ response.status = _response.statusCode;
363
+ /*** HTTP version */
364
+ response.version = _response.httpVersion;
365
+ /*** {Object} HTTP headers */
366
+ response.headers = _response.headers;
367
+ /***
368
+ * A Q IO asynchronous text reader.
369
+ */
370
+ response.node = _response;
371
+ response.nodeResponse = _response; // Deprecated
372
+ response.nodeConnection = _response.connection; // Deprecated
373
+ return Q.when(Reader(_response, charset), function (body) {
374
+ response.body = body;
375
+ return response;
376
+ });
377
+ };
378
+