@trpc-panel/core 1.0.0 → 1.0.1

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/lib/index.js CHANGED
@@ -64,7 +64,15 @@ const RouterSchema = zod.z.object({
64
64
  _def: RouterDefSchema,
65
65
  });
66
66
  function isRouter(obj) {
67
- return RouterSchema.safeParse(obj).success;
67
+ if (RouterSchema.safeParse(obj).success)
68
+ return true;
69
+ if (typeof obj === "object" &&
70
+ obj !== null &&
71
+ !isProcedure(obj) &&
72
+ !Array.isArray(obj)) {
73
+ return true;
74
+ }
75
+ return false;
68
76
  }
69
77
  zod.z.object({
70
78
  _def: ProcedureDefSchema,
@@ -272,22 +280,28 @@ function nodeAndInputSchemaFromInputs(inputs, _routerPath, options, addDataFunct
272
280
  };
273
281
  }
274
282
  if (inputs.length !== 1) {
275
- return { parseInputResult: "failure" };
283
+ return { parseInputResult: "failure", error: `Inputs length is ${inputs.length}` };
276
284
  }
277
285
  const input = inputs[0];
278
- return {
279
- parseInputResult: "success",
280
- schema: zodToJsonSchema.zodToJsonSchema(input, {
281
- errorMessages: true,
282
- $refStrategy: "none",
283
- target: "jsonSchema7"
284
- }),
285
- node: zodSelectorFunction(input._def, {
286
- path: [],
287
- options,
288
- addDataFunctions,
289
- }),
290
- };
286
+ try {
287
+ return {
288
+ parseInputResult: "success",
289
+ schema: zodToJsonSchema.zodToJsonSchema(input, {
290
+ errorMessages: true,
291
+ $refStrategy: "none",
292
+ target: "jsonSchema7"
293
+ }),
294
+ node: zodSelectorFunction(input._def, {
295
+ path: [],
296
+ options,
297
+ addDataFunctions,
298
+ }),
299
+ };
300
+ }
301
+ catch (e) {
302
+ console.error("Error parsing input schema:", e);
303
+ return { parseInputResult: "failure", error: "Exception in zodToJsonSchema or zodSelectorFunction" };
304
+ }
291
305
  }
292
306
  function parseProcedure(procedure, path, options) {
293
307
  var _a, _b;
@@ -305,6 +319,7 @@ function parseProcedure(procedure, path, options) {
305
319
  },
306
320
  });
307
321
  if (nodeAndInput.parseInputResult === "failure") {
322
+ console.warn(`parseProcedure failed for ${path.join(".")}: nodeAndInput failed. Error: ${nodeAndInput.error}`);
308
323
  return null;
309
324
  }
310
325
  const t = (() => {
@@ -317,6 +332,7 @@ function parseProcedure(procedure, path, options) {
317
332
  return null;
318
333
  })();
319
334
  if (!t) {
335
+ console.warn(`parseProcedure failed for ${path.join(".")}: could not determine procedure type.`);
320
336
  return null;
321
337
  }
322
338
  return {
package/lib/index.mjs CHANGED
@@ -61,7 +61,15 @@ const RouterSchema = z.object({
61
61
  _def: RouterDefSchema,
62
62
  });
63
63
  function isRouter(obj) {
64
- return RouterSchema.safeParse(obj).success;
64
+ if (RouterSchema.safeParse(obj).success)
65
+ return true;
66
+ if (typeof obj === "object" &&
67
+ obj !== null &&
68
+ !isProcedure(obj) &&
69
+ !Array.isArray(obj)) {
70
+ return true;
71
+ }
72
+ return false;
65
73
  }
66
74
  z.object({
67
75
  _def: ProcedureDefSchema,
@@ -269,22 +277,28 @@ function nodeAndInputSchemaFromInputs(inputs, _routerPath, options, addDataFunct
269
277
  };
270
278
  }
271
279
  if (inputs.length !== 1) {
272
- return { parseInputResult: "failure" };
280
+ return { parseInputResult: "failure", error: `Inputs length is ${inputs.length}` };
273
281
  }
274
282
  const input = inputs[0];
275
- return {
276
- parseInputResult: "success",
277
- schema: zodToJsonSchema(input, {
278
- errorMessages: true,
279
- $refStrategy: "none",
280
- target: "jsonSchema7"
281
- }),
282
- node: zodSelectorFunction(input._def, {
283
- path: [],
284
- options,
285
- addDataFunctions,
286
- }),
287
- };
283
+ try {
284
+ return {
285
+ parseInputResult: "success",
286
+ schema: zodToJsonSchema(input, {
287
+ errorMessages: true,
288
+ $refStrategy: "none",
289
+ target: "jsonSchema7"
290
+ }),
291
+ node: zodSelectorFunction(input._def, {
292
+ path: [],
293
+ options,
294
+ addDataFunctions,
295
+ }),
296
+ };
297
+ }
298
+ catch (e) {
299
+ console.error("Error parsing input schema:", e);
300
+ return { parseInputResult: "failure", error: "Exception in zodToJsonSchema or zodSelectorFunction" };
301
+ }
288
302
  }
289
303
  function parseProcedure(procedure, path, options) {
290
304
  var _a, _b;
@@ -302,6 +316,7 @@ function parseProcedure(procedure, path, options) {
302
316
  },
303
317
  });
304
318
  if (nodeAndInput.parseInputResult === "failure") {
319
+ console.warn(`parseProcedure failed for ${path.join(".")}: nodeAndInput failed. Error: ${nodeAndInput.error}`);
305
320
  return null;
306
321
  }
307
322
  const t = (() => {
@@ -314,6 +329,7 @@ function parseProcedure(procedure, path, options) {
314
329
  return null;
315
330
  })();
316
331
  if (!t) {
332
+ console.warn(`parseProcedure failed for ${path.join(".")}: could not determine procedure type.`);
317
333
  return null;
318
334
  }
319
335
  return {
@@ -244,7 +244,7 @@ export type RouterDef = {
244
244
  procedures: Record<string, RouterOrProcedure>;
245
245
  };
246
246
  export type Router = {
247
- _def: RouterDef;
247
+ _def?: RouterDef;
248
248
  } & {
249
249
  [key: string]: Router | Procedure;
250
250
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc-panel/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "UI for testing tRPC backends",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",