@taujs/server 0.2.6 → 0.2.7

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.
package/dist/build.js CHANGED
@@ -330,16 +330,15 @@ function renderPreloadLink(file) {
330
330
  return "";
331
331
  }
332
332
  }
333
- var callServiceMethod = async (serviceRegistry, serviceName, serviceMethod, params) => {
334
- const service = serviceRegistry[serviceName];
335
- if (service && typeof service[serviceMethod] === "function") {
336
- const method = service[serviceMethod];
337
- const data = await method(params);
338
- if (typeof data !== "object" || data === null)
339
- throw new Error(`Expected object response from service method ${serviceMethod} on ${serviceName}, but got ${typeof data}`);
340
- return data;
341
- }
342
- throw new Error(`Service method ${serviceMethod} does not exist on ${serviceName}`);
333
+ var callServiceMethod = async (registry, serviceName, methodName, params) => {
334
+ const service = registry[serviceName];
335
+ if (!service) throw new Error(`Service ${String(serviceName)} does not exist in the registry`);
336
+ const method = service[methodName];
337
+ if (typeof method !== "function") throw new Error(`Service method ${String(methodName)} does not exist on ${String(serviceName)}`);
338
+ const data = await method(params);
339
+ if (typeof data !== "object" || data === null)
340
+ throw new Error(`Expected object response from ${String(serviceName)}.${String(methodName)}, but got ${typeof data}`);
341
+ return data;
343
342
  };
344
343
  var fetchData = async ({ url, options }) => {
345
344
  if (url) {
@@ -357,10 +356,10 @@ var fetchInitialData = async (attr, params, serviceRegistry) => {
357
356
  headers: { "Content-Type": "application/json" },
358
357
  params
359
358
  }).then(async (data) => {
360
- if (data.serviceName && data.serviceMethod) {
359
+ if (data.serviceName && data.serviceMethod && typeof data.serviceName === "string" && typeof data.serviceMethod === "string")
361
360
  return await callServiceMethod(serviceRegistry, data.serviceName, data.serviceMethod, data.options?.params ?? {});
362
- }
363
- return await fetchData(data);
361
+ if (data.url && typeof data.url === "string") return await fetchData(data);
362
+ throw new Error("Invalid fetch configuration: must have either serviceName+serviceMethod or url");
364
363
  }).catch((error) => {
365
364
  console.error("Error fetching initial data:", error);
366
365
  throw error;
package/dist/index.js CHANGED
@@ -325,16 +325,15 @@ function renderPreloadLink(file) {
325
325
  return "";
326
326
  }
327
327
  }
328
- var callServiceMethod = async (serviceRegistry, serviceName, serviceMethod, params) => {
329
- const service = serviceRegistry[serviceName];
330
- if (service && typeof service[serviceMethod] === "function") {
331
- const method = service[serviceMethod];
332
- const data = await method(params);
333
- if (typeof data !== "object" || data === null)
334
- throw new Error(`Expected object response from service method ${serviceMethod} on ${serviceName}, but got ${typeof data}`);
335
- return data;
336
- }
337
- throw new Error(`Service method ${serviceMethod} does not exist on ${serviceName}`);
328
+ var callServiceMethod = async (registry, serviceName, methodName, params) => {
329
+ const service = registry[serviceName];
330
+ if (!service) throw new Error(`Service ${String(serviceName)} does not exist in the registry`);
331
+ const method = service[methodName];
332
+ if (typeof method !== "function") throw new Error(`Service method ${String(methodName)} does not exist on ${String(serviceName)}`);
333
+ const data = await method(params);
334
+ if (typeof data !== "object" || data === null)
335
+ throw new Error(`Expected object response from ${String(serviceName)}.${String(methodName)}, but got ${typeof data}`);
336
+ return data;
338
337
  };
339
338
  var fetchData = async ({ url, options }) => {
340
339
  if (url) {
@@ -352,10 +351,10 @@ var fetchInitialData = async (attr, params, serviceRegistry) => {
352
351
  headers: { "Content-Type": "application/json" },
353
352
  params
354
353
  }).then(async (data) => {
355
- if (data.serviceName && data.serviceMethod) {
354
+ if (data.serviceName && data.serviceMethod && typeof data.serviceName === "string" && typeof data.serviceMethod === "string")
356
355
  return await callServiceMethod(serviceRegistry, data.serviceName, data.serviceMethod, data.options?.params ?? {});
357
- }
358
- return await fetchData(data);
356
+ if (data.url && typeof data.url === "string") return await fetchData(data);
357
+ throw new Error("Invalid fetch configuration: must have either serviceName+serviceMethod or url");
359
358
  }).catch((error) => {
360
359
  console.error("Error fetching initial data:", error);
361
360
  throw error;
@@ -98,7 +98,6 @@ type Manifest = {
98
98
  type RenderSSR = (initialDataResolved: Record<string, unknown>, location: string, meta?: Record<string, unknown>) => Promise<{
99
99
  headContent: string;
100
100
  appHtml: string;
101
- initialDataScript: string;
102
101
  }>;
103
102
  type RenderStream = (serverResponse: ServerResponse, callbacks: RenderCallbacks, initialDataPromise: Promise<Record<string, unknown>>, location: string, bootstrapModules?: string, meta?: Record<string, unknown>) => void;
104
103
  type RenderModule = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taujs/server",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "taujs | τjs",
5
5
  "author": "Aoede <taujs@aoede.uk.net> (https://www.aoede.uk.net)",
6
6
  "license": "MIT",