@bobtail.software/b-ssr 1.0.8 → 1.0.10

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,26 +593,31 @@ 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
606
  ${l.map(f=>{let v=[];f.requiresArgs&&v.push("args"),v.push("ssrContext");let D=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);
608
- return await options.handler.call(ssrContext.req.server, augmentedReq, ssrContext.reply);
610
+ if (!options?.handler) throw new Error('Handler no encontrado para RPC: ${f.name}');
611
+ const augmentedReq = Object.assign(Object.create(ssrContext.req), args);
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}');
617
+ const augmentedReq = Object.assign(Object.create(ssrContext.req), args || {});
613
618
  let customData = {};
614
- if (options.handler) customData = (await options.handler.call(ssrContext.req.server, ssrContext.req, ssrContext.reply)) || {};
615
- if (ssrContext.reply.sent) return;
619
+ if (options.handler) customData = (await options.handler.call(ssrContext.req.server, augmentedReq, ssrContext.reply)) || {};
620
+ if (ssrContext.reply.sent) return;
616
621
  return { ...customData };
617
622
  `;return`exports.${f.name} = async (${v.join(", ")}) => {
618
623
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobtail.software/b-ssr",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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",