rack-queries 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f55bcc1a15b5bb9a73b90c8e9e61ed8e9c3c2d014ec4d28edd19b3bb2e56489
4
- data.tar.gz: 5450b27bf6ef559a49d729c8a70c7a21288d81f46add15e661dad04051023e8c
3
+ metadata.gz: f21bb05b87f39a3ab3253f83e181403b13eeb7f4e94ffb8729dabfceb58a072f
4
+ data.tar.gz: b8ea60adddcc790b2e9755cd2ded9c870b8521d1df05d162df7b006f8e4815c1
5
5
  SHA512:
6
- metadata.gz: 18e45faa5d19a42f54c983153fc9222cae541d57f992c38f4d6b6e050d0663fedad53832562205d2743d51fc9290358f7c1fc490f614eb13da5581cd490fa079
7
- data.tar.gz: 2342e3aaf4ff7dc0763d50bcf721bd269c943ae660c6f09b6d3f2801a5b2ef3477a1fe8cdccc1b94a4e8bb732a00022f2c7cdc263a3c95ace2c1b6c0b21bb0a8
6
+ metadata.gz: 8b2f9632bf8ba7aa784d8cd3ba798be741f481a598620bbd691e4b79fba74d1b6ac1c2f999c0cb91b1e570fa3cdf258dd4f512f1d87c7432ec41c89380b49938
7
+ data.tar.gz: 81e453b2a544b17a1ed44623d422480ac4ec89050094463f34901fc48075f43d09ac87e58507cdad792a29f476c3f3750f452ea797ef30f37253ea9958203a66
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.3] - 2019-03-01
10
+ ### Changed
11
+ - Move the middlewares before the static handler so that auth middlewares can handle the request before files like the index are returned.
12
+ - More properly handle nesting the rack application under a script name such that you can visit `/queries` and not just `/queries/`.
13
+
9
14
  ## [0.1.2] - 2019-02-27
10
15
  ### Changed
11
16
  - Use relative paths for the static assets so that when the app is mounted it will be prefixed with the mounting path.
@@ -18,7 +23,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
18
23
  ### Added
19
24
  - Initial release 🎉
20
25
 
21
- [Unreleased]: https://github.com/CultureHQ/rack-queries/compare/v0.1.2...HEAD
26
+ [Unreleased]: https://github.com/CultureHQ/rack-queries/compare/v0.1.3...HEAD
27
+ [0.1.3]: https://github.com/CultureHQ/rack-queries/compare/v0.1.2...v0.1.3
22
28
  [0.1.2]: https://github.com/CultureHQ/rack-queries/compare/v0.1.1...v0.1.2
23
29
  [0.1.1]: https://github.com/CultureHQ/rack-queries/compare/v0.1.0...v0.1.1
24
30
  [0.1.0]: https://github.com/CultureHQ/rack-queries/compare/f4f0b2...v0.1.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-queries (0.1.2)
4
+ rack-queries (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -55,8 +55,24 @@ module Rack
55
55
  end
56
56
 
57
57
  def call(env)
58
- env[PATH_INFO] = '/index.html' if env[PATH_INFO] == '/'
59
- (FILES.include?(env[PATH_INFO]) ? server : app).call(env)
58
+ if env[PATH_INFO] == '/'
59
+ render_index(env)
60
+ elsif FILES.include?(env[PATH_INFO])
61
+ server.call(env)
62
+ else
63
+ app.call(env)
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def render_index(env)
70
+ content = ::File.read(::File.join(STATIC, 'index.html.erb'))
71
+ script_name = env[SCRIPT_NAME]
72
+
73
+ result = ERB.new(content).result_with_hash(script_name: script_name)
74
+
75
+ [200, { 'Content-Type' => 'text/html' }, [result]]
60
76
  end
61
77
  end
62
78
 
@@ -81,10 +97,10 @@ module Rack
81
97
  configurations = middlewares
82
98
 
83
99
  Builder.new do
84
- use Static
85
100
  configurations.each do |middleware, block|
86
101
  use(*middleware, &block)
87
102
  end
103
+ use Static
88
104
  run Controller.new
89
105
  end
90
106
  end
@@ -28,4 +28,4 @@ object-assign
28
28
  * This source code is licensed under the MIT license found in the
29
29
  * LICENSE file in the root directory of this source tree.
30
30
  */
31
- Object.defineProperty(t,"__esModule",{value:!0});var n=null,r=!1,l=3,a=-1,i=-1,o=!1,u=!1;function c(){if(!o){var e=n.expirationTime;u?T():u=!0,w(d,e)}}function s(){var e=n,t=n.next;if(n===t)n=null;else{var r=n.previous;n=r.next=t,t.previous=r}e.next=e.previous=null,r=e.callback,t=e.expirationTime,e=e.priorityLevel;var a=l,o=i;l=e,i=t;try{var u=r()}finally{l=a,i=o}if("function"==typeof u)if(u={callback:u,priorityLevel:e,expirationTime:t,next:null,previous:null},null===n)n=u.next=u.previous=u;else{r=null,e=n;do{if(e.expirationTime>=t){r=e;break}e=e.next}while(e!==n);null===r?r=n:r===n&&(n=u,c()),(t=r.previous).next=r.previous=u,u.next=r,u.previous=t}}function f(){if(-1===a&&null!==n&&1===n.priorityLevel){o=!0;try{do{s()}while(null!==n&&1===n.priorityLevel)}finally{o=!1,null!==n?c():u=!1}}}function d(e){o=!0;var l=r;r=e;try{if(e)for(;null!==n;){var a=t.unstable_now();if(!(n.expirationTime<=a))break;do{s()}while(null!==n&&n.expirationTime<=a)}else if(null!==n)do{s()}while(null!==n&&!E())}finally{o=!1,r=l,null!==n?c():u=!1,f()}}var p,m,h=Date,y="function"==typeof setTimeout?setTimeout:void 0,v="function"==typeof clearTimeout?clearTimeout:void 0,g="function"==typeof requestAnimationFrame?requestAnimationFrame:void 0,b="function"==typeof cancelAnimationFrame?cancelAnimationFrame:void 0;function k(e){p=g(function(t){v(m),e(t)}),m=y(function(){b(p),e(t.unstable_now())},100)}if("object"==typeof performance&&"function"==typeof performance.now){var x=performance;t.unstable_now=function(){return x.now()}}else t.unstable_now=function(){return h.now()};var w,T,E,S=null;if("undefined"!=typeof window?S=window:void 0!==e&&(S=e),S&&S._schedMock){var _=S._schedMock;w=_[0],T=_[1],E=_[2],t.unstable_now=_[3]}else if("undefined"==typeof window||"function"!=typeof MessageChannel){var C=null,P=function(e){if(null!==C)try{C(e)}finally{C=null}};w=function(e){null!==C?setTimeout(w,0,e):(C=e,setTimeout(P,0,!1))},T=function(){C=null},E=function(){return!1}}else{"undefined"!=typeof console&&("function"!=typeof g&&console.error("This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"),"function"!=typeof b&&console.error("This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"));var N=null,O=!1,R=-1,M=!1,I=!1,z=0,U=33,D=33;E=function(){return z<=t.unstable_now()};var F=new MessageChannel,j=F.port2;F.port1.onmessage=function(){O=!1;var e=N,n=R;N=null,R=-1;var r=t.unstable_now(),l=!1;if(0>=z-r){if(!(-1!==n&&n<=r))return M||(M=!0,k(L)),N=e,void(R=n);l=!0}if(null!==e){I=!0;try{e(l)}finally{I=!1}}};var L=function(e){if(null!==N){k(L);var t=e-z+D;t<D&&U<D?(8>t&&(t=8),D=t<U?U:t):U=t,z=e+D,O||(O=!0,j.postMessage(void 0))}else M=!1};w=function(e,t){N=e,R=t,I||0>t?j.postMessage(void 0):M||(M=!0,k(L))},T=function(){N=null,O=!1,R=-1}}t.unstable_ImmediatePriority=1,t.unstable_UserBlockingPriority=2,t.unstable_NormalPriority=3,t.unstable_IdlePriority=5,t.unstable_LowPriority=4,t.unstable_runWithPriority=function(e,n){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var r=l,i=a;l=e,a=t.unstable_now();try{return n()}finally{l=r,a=i,f()}},t.unstable_next=function(e){switch(l){case 1:case 2:case 3:var n=3;break;default:n=l}var r=l,i=a;l=n,a=t.unstable_now();try{return e()}finally{l=r,a=i,f()}},t.unstable_scheduleCallback=function(e,r){var i=-1!==a?a:t.unstable_now();if("object"==typeof r&&null!==r&&"number"==typeof r.timeout)r=i+r.timeout;else switch(l){case 1:r=i+-1;break;case 2:r=i+250;break;case 5:r=i+1073741823;break;case 4:r=i+1e4;break;default:r=i+5e3}if(e={callback:e,priorityLevel:l,expirationTime:r,next:null,previous:null},null===n)n=e.next=e.previous=e,c();else{i=null;var o=n;do{if(o.expirationTime>r){i=o;break}o=o.next}while(o!==n);null===i?i=n:i===n&&(n=e,c()),(r=i.previous).next=i.previous=e,e.next=i,e.previous=r}return e},t.unstable_cancelCallback=function(e){var t=e.next;if(null!==t){if(t===e)n=null;else{e===n&&(n=t);var r=e.previous;r.next=t,t.previous=r}e.next=e.previous=null}},t.unstable_wrapCallback=function(e){var n=l;return function(){var r=l,i=a;l=n,a=t.unstable_now();try{return e.apply(this,arguments)}finally{l=r,a=i,f()}}},t.unstable_getCurrentPriorityLevel=function(){return l},t.unstable_shouldYield=function(){return!r&&(null!==n&&n.expirationTime<i||E())},t.unstable_continueExecution=function(){null!==n&&c()},t.unstable_pauseExecution=function(){},t.unstable_getFirstCallbackNode=function(){return n}}).call(this,n(7))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.r(t);var r=n(0),l=n.n(r),a=n(2),i=function(e){return new Promise(function(t,n){var r=new XMLHttpRequest;r.onreadystatechange=function(){4===r.readyState&&(r.status>=200&&r.status<300?t(JSON.parse(r.responseText)):n(new Error(r.responseText)))},r.open("GET",e),r.send()})};function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,l=!1,a=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){l=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(l)throw a}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var u=function(e){var t=!1,n=o(Object(r.useState)({error:null,fetching:!0,json:{}}),2),l=n[0],a=n[1];return Object(r.useEffect)(function(){return a({error:null,fetching:!0,json:{}}),i(e).then(function(e){t||a({fetching:!1,json:e})}).catch(function(e){t||a({fetching:!1,error:e})}),function(){t=!0}},[e]),l},c=function(e){var t=e.query,n=e.opt,a=e.value,i=e.onValueChange,o=u("queries/".concat(t.name,"/opts/").concat(n)),c=o.error,s=o.fetching,f=o.json,d=Object(r.useCallback)(function(e){return i(n,e.target.value)},[i,n]);if(c)return"error";if(s)return"fetching";a||i(n,f.values[0]);var p="".concat(t.name,"-").concat(n);return l.a.createElement("label",{className:"opt",htmlFor:p},"".concat(n,": "),l.a.createElement("select",{id:p,name:p,onChange:d},f.values.map(function(e){return l.a.createElement("option",{key:e,value:e},e)})))},s=function(e){var t=e.query,n=e.values,r=e.onValueChange;return l.a.createElement(l.a.Fragment,null,t.opts.map(function(e){return l.a.createElement(c,{key:e,query:t,opt:e,value:n[e],onValueChange:r})}))};function f(e){return function(e){if(Array.isArray(e))return e}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var d=function(e){var t=e.error,n=e.fetching,r=e.results;if(!t&&!n&&null===r)return null;if(t)return"error";if(n)return"fetching";if(!Array.isArray(r))return"Result: ".concat(r);var a=f(r),i=a[0],o=a.slice(1);return l.a.createElement(l.a.Fragment,null,"Results:",l.a.createElement("table",null,l.a.createElement("thead",null,l.a.createElement("tr",null,i.map(function(e,t){return l.a.createElement("th",{key:t},e)}))),l.a.createElement("tbody",null,o.map(function(e,t){return l.a.createElement("tr",{key:t},e.map(function(e,t){return l.a.createElement("td",{key:t},e)}))}))))};function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){m(e,t,n[t])})}return e}function m(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,l=!1,a=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){l=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(l)throw a}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var y=function(e){var t=e.query,n=Object(r.useRef)(null),a=h(Object(r.useState)(t.opts.reduce(function(e,t){return p({},e,m({},t,null))},{})),2),o=a[0],u=a[1],c=h(Object(r.useState)({error:null,fetching:!1,results:null}),2),f=c[0],y=c[1],v=Object(r.useCallback)(function(e,t){u(function(n){return p({},n,m({},e,t))}),y({error:null,fetching:!1,results:null})},[u,y]),g=Object(r.useCallback)(function(){y({error:null,fetching:!0,results:null}),i(function(e,t){var n="queries/".concat(e.name);if(0===Object.keys(t).length)return n;var r=Object.keys(t).map(function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(t[e]))});return"".concat(n,"?").concat(r.join("&"))}(t,o)).then(function(e){var t=e.results;n.current&&y({fetching:!1,results:t})}).catch(function(e){n.current&&y({fetching:!1,error:e})})},[n,t,o,y]);return l.a.createElement("div",{ref:n},l.a.createElement(s,{query:t,values:o,onValueChange:v}),l.a.createElement("button",{className:"run",type:"button",disabled:Object.keys(o).some(function(e){return!o[e]}),onClick:g},"Run"),l.a.createElement("div",{className:"results"},l.a.createElement(d,f)))};function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,l=!1,a=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){l=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(l)throw a}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var g=function(e){var t=e.active,n=e.query,a=e.onQueryClick,i=Object(r.useCallback)(function(){return a(n)},[n,a]),o=t?"query query-active":"query";return l.a.createElement("button",{className:o,type:"button",onClick:i},n.name)},b=function(){var e=u("queries"),t=e.error,n=e.fetching,a=e.json,i=v(Object(r.useState)(null),2),o=i[0],c=i[1];return t?"error":n?"fetching":l.a.createElement("main",null,l.a.createElement("div",{className:"active"},o&&l.a.createElement(y,{key:o.name,query:o})),l.a.createElement("nav",null,a.queries.map(function(e){return l.a.createElement(g,{key:e.name,active:e===o,query:e,onQueryClick:c})})))};n.n(a).a.render(l.a.createElement(function(){return l.a.createElement(r.StrictMode,null,l.a.createElement("h1",null,"Rack::Queries"),l.a.createElement(b,null))},null),document.getElementById("main"))}]);
31
+ Object.defineProperty(t,"__esModule",{value:!0});var n=null,r=!1,l=3,a=-1,i=-1,o=!1,u=!1;function c(){if(!o){var e=n.expirationTime;u?T():u=!0,w(d,e)}}function s(){var e=n,t=n.next;if(n===t)n=null;else{var r=n.previous;n=r.next=t,t.previous=r}e.next=e.previous=null,r=e.callback,t=e.expirationTime,e=e.priorityLevel;var a=l,o=i;l=e,i=t;try{var u=r()}finally{l=a,i=o}if("function"==typeof u)if(u={callback:u,priorityLevel:e,expirationTime:t,next:null,previous:null},null===n)n=u.next=u.previous=u;else{r=null,e=n;do{if(e.expirationTime>=t){r=e;break}e=e.next}while(e!==n);null===r?r=n:r===n&&(n=u,c()),(t=r.previous).next=r.previous=u,u.next=r,u.previous=t}}function f(){if(-1===a&&null!==n&&1===n.priorityLevel){o=!0;try{do{s()}while(null!==n&&1===n.priorityLevel)}finally{o=!1,null!==n?c():u=!1}}}function d(e){o=!0;var l=r;r=e;try{if(e)for(;null!==n;){var a=t.unstable_now();if(!(n.expirationTime<=a))break;do{s()}while(null!==n&&n.expirationTime<=a)}else if(null!==n)do{s()}while(null!==n&&!E())}finally{o=!1,r=l,null!==n?c():u=!1,f()}}var p,m,h=Date,y="function"==typeof setTimeout?setTimeout:void 0,v="function"==typeof clearTimeout?clearTimeout:void 0,g="function"==typeof requestAnimationFrame?requestAnimationFrame:void 0,b="function"==typeof cancelAnimationFrame?cancelAnimationFrame:void 0;function k(e){p=g(function(t){v(m),e(t)}),m=y(function(){b(p),e(t.unstable_now())},100)}if("object"==typeof performance&&"function"==typeof performance.now){var x=performance;t.unstable_now=function(){return x.now()}}else t.unstable_now=function(){return h.now()};var w,T,E,S=null;if("undefined"!=typeof window?S=window:void 0!==e&&(S=e),S&&S._schedMock){var _=S._schedMock;w=_[0],T=_[1],E=_[2],t.unstable_now=_[3]}else if("undefined"==typeof window||"function"!=typeof MessageChannel){var C=null,P=function(e){if(null!==C)try{C(e)}finally{C=null}};w=function(e){null!==C?setTimeout(w,0,e):(C=e,setTimeout(P,0,!1))},T=function(){C=null},E=function(){return!1}}else{"undefined"!=typeof console&&("function"!=typeof g&&console.error("This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"),"function"!=typeof b&&console.error("This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"));var N=null,O=!1,R=-1,M=!1,I=!1,z=0,U=33,D=33;E=function(){return z<=t.unstable_now()};var F=new MessageChannel,j=F.port2;F.port1.onmessage=function(){O=!1;var e=N,n=R;N=null,R=-1;var r=t.unstable_now(),l=!1;if(0>=z-r){if(!(-1!==n&&n<=r))return M||(M=!0,k(L)),N=e,void(R=n);l=!0}if(null!==e){I=!0;try{e(l)}finally{I=!1}}};var L=function(e){if(null!==N){k(L);var t=e-z+D;t<D&&U<D?(8>t&&(t=8),D=t<U?U:t):U=t,z=e+D,O||(O=!0,j.postMessage(void 0))}else M=!1};w=function(e,t){N=e,R=t,I||0>t?j.postMessage(void 0):M||(M=!0,k(L))},T=function(){N=null,O=!1,R=-1}}t.unstable_ImmediatePriority=1,t.unstable_UserBlockingPriority=2,t.unstable_NormalPriority=3,t.unstable_IdlePriority=5,t.unstable_LowPriority=4,t.unstable_runWithPriority=function(e,n){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var r=l,i=a;l=e,a=t.unstable_now();try{return n()}finally{l=r,a=i,f()}},t.unstable_next=function(e){switch(l){case 1:case 2:case 3:var n=3;break;default:n=l}var r=l,i=a;l=n,a=t.unstable_now();try{return e()}finally{l=r,a=i,f()}},t.unstable_scheduleCallback=function(e,r){var i=-1!==a?a:t.unstable_now();if("object"==typeof r&&null!==r&&"number"==typeof r.timeout)r=i+r.timeout;else switch(l){case 1:r=i+-1;break;case 2:r=i+250;break;case 5:r=i+1073741823;break;case 4:r=i+1e4;break;default:r=i+5e3}if(e={callback:e,priorityLevel:l,expirationTime:r,next:null,previous:null},null===n)n=e.next=e.previous=e,c();else{i=null;var o=n;do{if(o.expirationTime>r){i=o;break}o=o.next}while(o!==n);null===i?i=n:i===n&&(n=e,c()),(r=i.previous).next=i.previous=e,e.next=i,e.previous=r}return e},t.unstable_cancelCallback=function(e){var t=e.next;if(null!==t){if(t===e)n=null;else{e===n&&(n=t);var r=e.previous;r.next=t,t.previous=r}e.next=e.previous=null}},t.unstable_wrapCallback=function(e){var n=l;return function(){var r=l,i=a;l=n,a=t.unstable_now();try{return e.apply(this,arguments)}finally{l=r,a=i,f()}}},t.unstable_getCurrentPriorityLevel=function(){return l},t.unstable_shouldYield=function(){return!r&&(null!==n&&n.expirationTime<i||E())},t.unstable_continueExecution=function(){null!==n&&c()},t.unstable_pauseExecution=function(){},t.unstable_getFirstCallbackNode=function(){return n}}).call(this,n(7))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.r(t);var r=n(0),l=n.n(r),a=n(2),i=function(e){return new Promise(function(t,n){var r=new XMLHttpRequest;r.onreadystatechange=function(){4===r.readyState&&(r.status>=200&&r.status<300?t(JSON.parse(r.responseText)):n(new Error(r.responseText)))},r.open("GET","".concat(document.body.dataset.scriptName,"/").concat(e)),r.send()})};function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,l=!1,a=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){l=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(l)throw a}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var u=function(e){var t=!1,n=o(Object(r.useState)({error:null,fetching:!0,json:{}}),2),l=n[0],a=n[1];return Object(r.useEffect)(function(){return a({error:null,fetching:!0,json:{}}),i(e).then(function(e){t||a({fetching:!1,json:e})}).catch(function(e){t||a({fetching:!1,error:e})}),function(){t=!0}},[e]),l},c=function(e){var t=e.query,n=e.opt,a=e.value,i=e.onValueChange,o=u("queries/".concat(t.name,"/opts/").concat(n)),c=o.error,s=o.fetching,f=o.json,d=Object(r.useCallback)(function(e){return i(n,e.target.value)},[i,n]);if(c)return"error";if(s)return"fetching";a||i(n,f.values[0]);var p="".concat(t.name,"-").concat(n);return l.a.createElement("label",{className:"opt",htmlFor:p},"".concat(n,": "),l.a.createElement("select",{id:p,name:p,onChange:d},f.values.map(function(e){return l.a.createElement("option",{key:e,value:e},e)})))},s=function(e){var t=e.query,n=e.values,r=e.onValueChange;return l.a.createElement(l.a.Fragment,null,t.opts.map(function(e){return l.a.createElement(c,{key:e,query:t,opt:e,value:n[e],onValueChange:r})}))};function f(e){return function(e){if(Array.isArray(e))return e}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var d=function(e){var t=e.error,n=e.fetching,r=e.results;if(!t&&!n&&null===r)return null;if(t)return"error";if(n)return"fetching";if(!Array.isArray(r))return"Result: ".concat(r);var a=f(r),i=a[0],o=a.slice(1);return l.a.createElement(l.a.Fragment,null,"Results:",l.a.createElement("table",null,l.a.createElement("thead",null,l.a.createElement("tr",null,i.map(function(e,t){return l.a.createElement("th",{key:t},e)}))),l.a.createElement("tbody",null,o.map(function(e,t){return l.a.createElement("tr",{key:t},e.map(function(e,t){return l.a.createElement("td",{key:t},e)}))}))))};function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){m(e,t,n[t])})}return e}function m(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,l=!1,a=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){l=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(l)throw a}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var y=function(e){var t=e.query,n=Object(r.useRef)(null),a=h(Object(r.useState)(t.opts.reduce(function(e,t){return p({},e,m({},t,null))},{})),2),o=a[0],u=a[1],c=h(Object(r.useState)({error:null,fetching:!1,results:null}),2),f=c[0],y=c[1],v=Object(r.useCallback)(function(e,t){u(function(n){return p({},n,m({},e,t))}),y({error:null,fetching:!1,results:null})},[u,y]),g=Object(r.useCallback)(function(){y({error:null,fetching:!0,results:null}),i(function(e,t){var n="queries/".concat(e.name);if(0===Object.keys(t).length)return n;var r=Object.keys(t).map(function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(t[e]))});return"".concat(n,"?").concat(r.join("&"))}(t,o)).then(function(e){var t=e.results;n.current&&y({fetching:!1,results:t})}).catch(function(e){n.current&&y({fetching:!1,error:e})})},[n,t,o,y]);return l.a.createElement("div",{ref:n},l.a.createElement(s,{query:t,values:o,onValueChange:v}),l.a.createElement("button",{className:"run",type:"button",disabled:Object.keys(o).some(function(e){return!o[e]}),onClick:g},"Run"),l.a.createElement("div",{className:"results"},l.a.createElement(d,f)))};function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,l=!1,a=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){l=!0,a=e}finally{try{r||null==o.return||o.return()}finally{if(l)throw a}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var g=function(e){var t=e.active,n=e.query,a=e.onQueryClick,i=Object(r.useCallback)(function(){return a(n)},[n,a]),o=t?"query query-active":"query";return l.a.createElement("button",{className:o,type:"button",onClick:i},n.name)},b=function(){var e=u("queries"),t=e.error,n=e.fetching,a=e.json,i=v(Object(r.useState)(null),2),o=i[0],c=i[1];return t?"error":n?"fetching":l.a.createElement("main",null,l.a.createElement("div",{className:"active"},o&&l.a.createElement(y,{key:o.name,query:o})),l.a.createElement("nav",null,a.queries.map(function(e){return l.a.createElement(g,{key:e.name,active:e===o,query:e,onQueryClick:c})})))};n.n(a).a.render(l.a.createElement(function(){return l.a.createElement(r.StrictMode,null,l.a.createElement("h1",null,"Rack::Queries"),l.a.createElement(b,null))},null),document.getElementById("main"))}]);
@@ -5,11 +5,11 @@
5
5
  <meta name="viewport" content="initial-scale=1, maximum-scale=5">
6
6
  <title>Rack::Queries</title>
7
7
  <link rel="shortcut icon" href="favicon.ico">
8
- <link rel="stylesheet" type="text/css" href="./app.css" />
8
+ <link rel="stylesheet" type="text/css" href="<%= script_name %>/app.css" />
9
9
  </head>
10
- <body>
10
+ <body data-script-name="<%= script_name %>">
11
11
  <noscript>JavaScript must be enabled in order to run this application.</noscript>
12
12
  <div id="main"></div>
13
- <script src="./app.js"></script>
13
+ <script src="<%= script_name %>/app.js"></script>
14
14
  </body>
15
15
  </html>
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  module Queries
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.3'
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rack-queries",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "The frontend component of the rack queries page",
5
5
  "main": "src/app.js",
6
6
  "scripts": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-queries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Deisz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-27 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,7 +151,7 @@ files:
151
151
  - lib/rack/queries/static/app.css
152
152
  - lib/rack/queries/static/app.js
153
153
  - lib/rack/queries/static/favicon.ico
154
- - lib/rack/queries/static/index.html
154
+ - lib/rack/queries/static/index.html.erb
155
155
  - lib/rack/queries/version.rb
156
156
  - package.json
157
157
  - rack-queries.gemspec