@bobtail.software/b-ssr 1.0.9 → 1.0.11

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.
@@ -593,24 +593,28 @@ node_modules`),!r)return;let i=(0,Isr.default)({allowRelativePaths:!0}).add(r);r
593
593
  renderOptionsMap = new Map();
594
594
  const serverModulePath = '${h.replace(/\\/g,"/")}';
595
595
  const routeModule = await import(/* @vite-ignore */ serverModulePath);
596
- const mockFastify = {
597
- addRpcRoute: (url, options) => rpcOptionsMap.set(url, options),
598
- addRenderRoute: (url, options) => renderOptionsMap.set(url, options),
599
- };
596
+ const mockFastify = new Proxy({}, {
597
+ get: (target, prop) => {
598
+ if (prop === 'addRpcRoute') return (url, options) => rpcOptionsMap.set(url, options);
599
+ if (prop === 'addRenderRoute') return (url, options) => renderOptionsMap.set(url, options);
600
+ // "Agujero negro": devuelve una funci\xF3n muda para cualquier otro m\xE9todo
601
+ return () => {};
602
+ }
603
+ });
600
604
  if (routeModule.default) await routeModule.default(mockFastify);
601
605
  }
602
- ${l.map(f=>{let v=[];f.requiresArgs&&v.push("args"),v.push("ssrContext");let D=f.type==="rpc"?`
606
+ ${l.map(f=>{let v=[];f.requiresArgs&&v.push("args"),v.push("ssrContext");let D=f.requiresArgs?"args":"{}",C=f.type==="rpc"?`
603
607
  if (fn.isMultipart) throw new Error('RPC multipart no soportado en SSR.');
604
608
  await getOptionsMaps();
605
609
  const options = rpcOptionsMap.get('${f.url}');
606
- if (!options?.handler) throw new Error('Handler no encontrado para RPC: ${f.name}');
607
- const augmentedReq = Object.assign(Object.create(ssrContext.req), args);
610
+ if (!options?.handler) throw new Error('Handler no encontrado para RPC: ${f.name}');
611
+ const augmentedReq = Object.assign(Object.create(ssrContext.req), ${D});
608
612
  return await options.handler.call(ssrContext.req.server, augmentedReq, ssrContext.reply);
609
613
  `:`
610
614
  await getOptionsMaps();
611
615
  const options = renderOptionsMap.get('${f.url}');
612
616
  if (!options) throw new Error('Opciones loader no encontradas para: ${f.name}');
613
- const augmentedReq = Object.assign(Object.create(ssrContext.req), args || {});
617
+ const augmentedReq = Object.assign(Object.create(ssrContext.req), ${D});
614
618
  let customData = {};
615
619
  if (options.handler) customData = (await options.handler.call(ssrContext.req.server, augmentedReq, ssrContext.reply)) || {};
616
620
  if (ssrContext.reply.sent) return;
@@ -618,7 +622,7 @@ node_modules`),!r)return;let i=(0,Isr.default)({allowRelativePaths:!0}).add(r);r
618
622
  `;return`exports.${f.name} = async (${v.join(", ")}) => {
619
623
  try {
620
624
  if (!ssrContext?.req || !ssrContext?.reply) throw new Error('ssrContext requerido en ${f.name}. Aseg\xFArate de pasarlo en el loader: ${f.name}({ context })');
621
- ${D}
625
+ ${C}
622
626
  } catch (error) {
623
627
  if (ssrContext?.req?.log) {
624
628
  ssrContext.req.log.error({ err: error }, '\u274C [B-SSR Error] ${f.name}');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobtail.software/b-ssr",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Fastify + Vite SSR Plugin wrapper with RPC",
5
5
  "author": "Victor Moreno <info@bobtail.software> (https://bobtail.software)",
6
6
  "license": "GPL-3.0",