@joystick.js/node-canary 0.0.0-canary.367 → 0.0.0-canary.369

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.
@@ -1 +1 @@
1
- var i=null,c=0,a=(e={},t=null)=>{let n=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(e.query).toString()}`);i&&(clearInterval(i),i=null);let _={client:n,send:(o={})=>(e.queryParams&&(o={...o,...e.queryParams}),n.send(JSON.stringify(o)))};return n.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,t&&t(_)}),n.addEventListener("message",o=>{o?.data&&e.onMessage&&e.onMessage(JSON.parse(o.data),_)}),n.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),n=null,e.autoReconnect&&!i&&(i=setInterval(()=>{n=null,c<12?(a(e,t),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(i))},5e3))}),_},d=async()=>{let e=await l();window.joystick.mount(e,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},l=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(t=>{location.reload()}))?.default,u=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(t=>{location.reload()}))?.default,p=async()=>{let e=await u(),t=await l();window.joystick.mount(e,Object.assign({page:t},window.__joystick_ssr_props__),document.getElementById("app"))},w=e=>{let t=document.createElement("link");t.setAttribute("rel","stylesheet"),t.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(t,e)},y=(e={})=>{let t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src","/_joystick/index.client.js"),e.parentNode.replaceChild(t,e)},g=a({autoReconnect:!0,query:{user_language:window?.__joystick_user__?.language||"",browser_language:navigator?.language||"",page_component_path:window.__joystick_page_url__?.replace("/_joystick/","")},onMessage:async(e={},t={})=>{window.__joystick_hmr_update__=!0,window.__joystick_hmr_previous_tree__=[...window.joystick._internal.tree||[]],window.__joystick_hmr_previous_websockets__=[...window.joystick._internal.websockets||[]];let n=Object.assign({},{scrollTop:window.scrollY}),_=e&&e.type&&e.type==="FILE_CHANGE",o=!!window.__joystick_layout_url__&&!!window.__joystick_page_url__,s=document.head.querySelector('link[href="/_joystick/index.css"]'),r=document.body.querySelector('script[src="/_joystick/index.client.js"]');e?.index_html_changed&&location.reload(),e?.i18n&&(window.__joystick_i18n__=e?.i18n),e?.settings&&(window.__joystick_settings__=e?.settings,window.joystick.settings=e?.settings),r&&e?.index_client_changed&&y(r),s&&e?.index_css_changed&&w(s),_&&o&&p(t),_&&!o&&d(t),window.scrollTo(0,n.scrollTop),t.send&&t.send({type:"HMR_UPDATE_COMPLETE"})}}),m=g;export{m as default};
1
+ var i=null,c=0,l=(t={},e=null)=>{let o=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(t.query).toString()}`);i&&(clearInterval(i),i=null);let _={client:o,send:(n={})=>(t.queryParams&&(n={...n,...t.queryParams}),o.send(JSON.stringify(n)))};return o.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,e&&e(_)}),o.addEventListener("message",n=>{n?.data&&t.onMessage&&t.onMessage(JSON.parse(n.data),_)}),o.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),o=null,t.autoReconnect&&!i&&(i=setInterval(()=>{o=null,c<12?(l(t,e),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(i))},5e3))}),_},u=async()=>{let t=await d();window.joystick.mount(t,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},d=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,p=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,y=async()=>{let t=await p(),e=await d();window.joystick.mount(t,Object.assign({page:e},window.__joystick_ssr_props__),document.getElementById("app"))},w=t=>{let e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(e,t)},g=(t={})=>{let e=document.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("src","/_joystick/index.client.js"),t.parentNode.replaceChild(e,t)},m=l({autoReconnect:!0,query:{user_language:window?.__joystick_user__?.language||"",browser_language:navigator?.language||"",page_component_path:window.__joystick_page_url__?.replace("/_joystick/","")},onMessage:async(t={},e={})=>{if(t&&t.type&&t.type==="BUILD_ERROR")return location.reload();window.__joystick_hmr_update__=!0,window.__joystick_hmr_previous_tree__=[...window.joystick._internal.tree||[]],window.__joystick_hmr_previous_websockets__=[...window.joystick._internal.websockets||[]];let _=Object.assign({},{scrollTop:window.scrollY}),n=t&&t.type&&t.type==="FILE_CHANGE",r=!!window.__joystick_layout_url__&&!!window.__joystick_page_url__,s=document.head.querySelector('link[href="/_joystick/index.css"]'),a=document.body.querySelector('script[src="/_joystick/index.client.js"]');t?.index_html_changed&&location.reload(),t?.i18n&&(window.__joystick_i18n__=t?.i18n),t?.settings&&(window.__joystick_settings__=t?.settings,window.joystick.settings=t?.settings),a&&t?.index_client_changed&&g(a),s&&t?.index_css_changed&&w(s),n&&r&&y(e),n&&!r&&u(e),window.scrollTo(0,_.scrollTop),e.send&&e.send({type:"HMR_UPDATE_COMPLETE"})}}),j=m;export{j as default};
@@ -1 +1 @@
1
- import i from"../databases/queries/sessions.js";import n from"../../lib/set_cookie.js";const c=async(s,e,t)=>{let o=s?.cookies?.joystick_session;(o?await i("get_session",{session_id:o}):null)||(o=await i("create_session"),n(e,"joystick_session",o)),s.cookies={...s?.cookies||{},joystick_session:o},s.context={...s?.context||{},session:await i("get_session",{session_id:o})},console.log("MIDDIE",s.context),t()};var l=c;export{l as default};
1
+ import i from"../databases/queries/sessions.js";import n from"../../lib/set_cookie.js";const c=async(o,e,t)=>{let s=o?.cookies?.joystick_session;(s?await i("get_session",{session_id:s}):null)||(s=await i("create_session"),n(e,"joystick_session",s)),o.cookies={...o?.cookies||{},joystick_session:s},o.context={...o?.context||{},session:await i("get_session",{session_id:s})},t()};var l=c;export{l as default};
@@ -1 +1 @@
1
- import c from"node-html-parser";import _ from"../../lib/types.js";const f=(u="",t=null,g={})=>{const p=c.parse(u),i=p.querySelector("head");if(console.log(g?.context),g?.context?.session){const s=c.parse("<meta />").querySelector("meta");s.setAttribute("name","csrf"),s.setAttribute("content",g?.context?.session?.csrf),i.appendChild(s)}if(!t)return p.toString();if(t.title){const e=i.querySelector("title");if(e){const s=c.parse(`<title>${t.title}</title>`);i.exchangeChild(e,s)}e||i.insertAdjacentHTML("afterbegin",`<title>${t.title}</title>`)}if(t.tags&&t.tags.meta&&_.is_array(t.tags.meta)&&t.tags.meta.length>0)for(let e=0;e<t?.tags?.meta?.length;e+=1){const s=t.tags.meta[e],r=i.querySelector(`meta[name="${s.name}"]`),a=c.parse("<meta />"),n=Object.entries(s||{});for(let l=0;l<n?.length;l+=1){const[o,m]=n[l];a.querySelector("meta").setAttribute(o,m)}r&&i.exchangeChild(r,a),r||i.appendChild(a)}if(t.tags&&t.tags.link&&_.is_array(t.tags.link)&&t.tags.link.length>0)for(let e=0;e<t?.tags?.link?.length;e+=1){const s=t?.tags?.link[e],r=c.parse("<link />"),a=Object.entries(s||{});for(let n=0;n<a?.length;n+=1){const[l,o]=a[n];r.querySelector("link").setAttribute(l,o)}i.appendChild(r)}if(t.tags&&t.tags.script&&Array.isArray(t.tags.script)&&t.tags.script.length>0)for(let e=0;e<t?.tags?.script?.length;e+=1){const s=t.tags.script[e],r=c.parse("<script></script>"),a=Object.entries(s||{});for(let n=0;n<a?.length;n+=1){const[l,o]=a[n];r.querySelector("script").setAttribute(l,o)}i.appendChild(r)}if(t.jsonld){const e=c.parse("<script></script>"),s=e.querySelector("script");s.setAttribute("type","application/ld+json"),s.set_content(JSON.stringify(t.jsonld,null,2)),i.appendChild(e)}return p.toString()};var S=f;export{S as default};
1
+ import c from"node-html-parser";import _ from"../../lib/types.js";const f=(u="",t=null,p={})=>{const g=c.parse(u),i=g.querySelector("head");if(p?.context?.session){const s=c.parse("<meta />").querySelector("meta");s.setAttribute("name","csrf"),s.setAttribute("content",p?.context?.session?.csrf),i.appendChild(s)}if(!t)return g.toString();if(t.title){const e=i.querySelector("title");if(e){const s=c.parse(`<title>${t.title}</title>`);i.exchangeChild(e,s)}e||i.insertAdjacentHTML("afterbegin",`<title>${t.title}</title>`)}if(t.tags&&t.tags.meta&&_.is_array(t.tags.meta)&&t.tags.meta.length>0)for(let e=0;e<t?.tags?.meta?.length;e+=1){const s=t.tags.meta[e],r=i.querySelector(`meta[name="${s.name}"]`),a=c.parse("<meta />"),n=Object.entries(s||{});for(let l=0;l<n?.length;l+=1){const[o,m]=n[l];a.querySelector("meta").setAttribute(o,m)}r&&i.exchangeChild(r,a),r||i.appendChild(a)}if(t.tags&&t.tags.link&&_.is_array(t.tags.link)&&t.tags.link.length>0)for(let e=0;e<t?.tags?.link?.length;e+=1){const s=t?.tags?.link[e],r=c.parse("<link />"),a=Object.entries(s||{});for(let n=0;n<a?.length;n+=1){const[l,o]=a[n];r.querySelector("link").setAttribute(l,o)}i.appendChild(r)}if(t.tags&&t.tags.script&&Array.isArray(t.tags.script)&&t.tags.script.length>0)for(let e=0;e<t?.tags?.script?.length;e+=1){const s=t.tags.script[e],r=c.parse("<script></script>"),a=Object.entries(s||{});for(let n=0;n<a?.length;n+=1){const[l,o]=a[n];r.querySelector("script").setAttribute(l,o)}i.appendChild(r)}if(t.jsonld){const e=c.parse("<script></script>"),s=e.querySelector("script");s.setAttribute("type","application/ld+json"),s.set_content(JSON.stringify(t.jsonld,null,2)),i.appendChild(e)}return g.toString()};var S=f;export{S as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.367",
4
+ "version": "0.0.0-canary.369",
5
5
  "description": "The Node.js framework for Joystick.",
6
6
  "main": "./dist/index.js",
7
7
  "scripts": {
@@ -136,6 +136,12 @@ const hmr_client = (() =>
136
136
  page_component_path: window.__joystick_page_url__?.replace('/_joystick/', ''),
137
137
  },
138
138
  onMessage: async (message = {}, websocket_client_connection = {}) => {
139
+ const is_build_error = message && message.type && message.type === "BUILD_ERROR";
140
+
141
+ if (is_build_error) {
142
+ return location.reload();
143
+ }
144
+
139
145
  // NOTE: Set this to disable the auto mount code in layouts/pages when
140
146
  // working in an HMR/development context.
141
147
  window.__joystick_hmr_update__ = true;
@@ -24,8 +24,6 @@ const session_middleware = async (req, res, next) => {
24
24
  ...(req?.context || {}),
25
25
  session: await sessions_query('get_session', { session_id }),
26
26
  };
27
-
28
- console.log('MIDDIE', req.context);
29
27
 
30
28
  next();
31
29
  };
@@ -5,8 +5,6 @@ const set_head_tags_in_html = (html_string = '', head = null, req = {}) => {
5
5
  const html = html_parser.parse(html_string);
6
6
  const head_tag = html.querySelector('head');
7
7
 
8
- console.log(req?.context);
9
-
10
8
  if (req?.context?.session) {
11
9
  const meta_tag_wrapper = html_parser.parse(`<meta />`);
12
10
  const tag = meta_tag_wrapper.querySelector('meta');