silgi 0.52.0 → 0.52.2

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.
@@ -170,7 +170,7 @@ function createFetchHandler(routerDef, contextFactory, hooks, prefix, bridge) {
170
170
  });
171
171
  if (prepareResult) await prepareResult;
172
172
  if (!route.passthrough) rawInput = await parseInput(request, url, qMark);
173
- if (match.params && Object.keys(match.params).length > 0) rawInput = rawInput != null && typeof rawInput === "object" ? {
173
+ if (match.params) rawInput = rawInput != null && typeof rawInput === "object" ? {
174
174
  ...match.params,
175
175
  ...rawInput
176
176
  } : match.params;
@@ -0,0 +1,43 @@
1
+ import { ProcedureDef, RouterDef } from "../types.mjs";
2
+ import { compileRouter } from "../compile.mjs";
3
+
4
+ //#region src/core/router-utils.d.ts
5
+ declare function isProcedureDef(value: unknown): value is ProcedureDef;
6
+ /**
7
+ * Walk a router tree and invoke `cb` for every procedure.
8
+ *
9
+ * @remarks
10
+ * Depth-first traversal. `path` is the segment list from the router
11
+ * root to the procedure (e.g. `['users', 'list']`). Use this when you
12
+ * need the live `ProcedureDef` reference (e.g. to read `.input`,
13
+ * `.output`, `.route`, `.meta`). For a flat list of paths only, use
14
+ * {@link getProcedurePaths}.
15
+ */
16
+ declare function collectProcedures(router: RouterDef, cb: (path: string[], proc: ProcedureDef) => void): void;
17
+ /**
18
+ * Flat list of every procedure in a router tree.
19
+ *
20
+ * @remarks
21
+ * Each entry carries the dot-joined path (e.g. `'users.list'`), the
22
+ * effective HTTP path (from `$route({ path })` or auto-derived), the
23
+ * method, the procedure kind and a direct reference to the
24
+ * `ProcedureDef`. Useful for generating client stubs, auditing the
25
+ * surface, or writing custom dashboards.
26
+ */
27
+ interface ProcedureSummary {
28
+ /** Dot-joined segment path, e.g. `'users.list'`. */
29
+ name: string;
30
+ /** Router tree segments, e.g. `['users', 'list']`. */
31
+ segments: string[];
32
+ /** HTTP path used by the handler (auto or `$route`-overridden). */
33
+ httpPath: string;
34
+ /** HTTP method (uppercase), or `'*'` when wildcarded. */
35
+ method: string;
36
+ /** Procedure kind — `'query'`, `'mutation'`, `'subscription'`. */
37
+ type: ProcedureDef['type'];
38
+ /** Live `ProcedureDef` reference. */
39
+ procedure: ProcedureDef;
40
+ }
41
+ declare function getProcedurePaths(router: RouterDef): ProcedureSummary[];
42
+ //#endregion
43
+ export { ProcedureSummary, collectProcedures, getProcedurePaths, isProcedureDef };
@@ -4,6 +4,43 @@ const routerCache = /* @__PURE__ */ new WeakMap();
4
4
  function isProcedureDef(value) {
5
5
  return typeof value === "object" && value !== null && "type" in value && "resolve" in value && typeof value.resolve === "function";
6
6
  }
7
+ /**
8
+ * Walk a router tree and invoke `cb` for every procedure.
9
+ *
10
+ * @remarks
11
+ * Depth-first traversal. `path` is the segment list from the router
12
+ * root to the procedure (e.g. `['users', 'list']`). Use this when you
13
+ * need the live `ProcedureDef` reference (e.g. to read `.input`,
14
+ * `.output`, `.route`, `.meta`). For a flat list of paths only, use
15
+ * {@link getProcedurePaths}.
16
+ */
17
+ function collectProcedures(router, cb) {
18
+ walk(router, [], cb);
19
+ }
20
+ function walk(node, path, cb) {
21
+ if (isProcedureDef(node)) {
22
+ cb(path, node);
23
+ return;
24
+ }
25
+ if (typeof node === "object" && node !== null) for (const [key, child] of Object.entries(node)) walk(child, [...path, key], cb);
26
+ }
27
+ function getProcedurePaths(router) {
28
+ const out = [];
29
+ walk(router, [], (segments, proc) => {
30
+ const route = proc.route;
31
+ const httpPath = route?.path ?? "/" + segments.join("/");
32
+ const method = route?.method?.toUpperCase() ?? "POST";
33
+ out.push({
34
+ name: segments.join("."),
35
+ segments,
36
+ httpPath,
37
+ method,
38
+ type: proc.type,
39
+ procedure: proc
40
+ });
41
+ });
42
+ return out;
43
+ }
7
44
  function assignPaths(def, prefix = []) {
8
45
  const result = {};
9
46
  for (const [key, value] of Object.entries(def)) {
@@ -19,4 +56,4 @@ function assignPaths(def, prefix = []) {
19
56
  return result;
20
57
  }
21
58
  //#endregion
22
- export { assignPaths, isProcedureDef, routerCache };
59
+ export { assignPaths, collectProcedures, getProcedurePaths, isProcedureDef, routerCache };
package/dist/index.d.mts CHANGED
@@ -16,5 +16,6 @@ import { CallableOptions, callable } from "./callable.mjs";
16
16
  import { LifecycleHooks, lifecycleWrap } from "./lifecycle.mjs";
17
17
  import { mapInput } from "./map-input.mjs";
18
18
  import { compileProcedure, compileRouter, createContext } from "./compile.mjs";
19
+ import { ProcedureSummary, collectProcedures, getProcedurePaths, isProcedureDef } from "./core/router-utils.mjs";
19
20
  import { LazyRouter, isLazy, lazy, resolveLazy } from "./lazy.mjs";
20
- export { type AnySchema, AsyncIteratorClass, type BaseContext, type CallableOptions, type ContextBridge, type ConvertOptions, type Driver, type ErrorDef, type ErrorDefItem, type EventMeta, type FailFn, type GuardDef, type GuardFn, type InferClient, type InferContextFromUse, type InferGuardOutput, type InferSchemaInput, type InferSchemaOutput, type JSONSchema, type LazyRouter, type LifecycleHooks, type Meta, type MiddlewareDef, type ProcedureBuilder, type ProcedureBuilderWithOutput, type ProcedureDef, type ProcedureType, type ResolveContext, type RouterDef, type ScalarOptions, type ScheduledTaskInfo, type Schema, type SchemaConverter, type SchemaRegistry, type ServeOptions, type SilgiConfig, SilgiError, type SilgiErrorCode, type SilgiErrorJSON, type SilgiErrorOptions, type SilgiInstance, type SilgiServer, type Storage, type StorageConfig, type StorageValue, type TaskDef, type TaskEvent, ValidationError, type WrapDef, type WrapFn, callable, collectCronTasks, compileProcedure, compileRouter, createContext, createContextBridge, createSchemaRegistry, generateOpenAPI, getEventMeta, getScheduledTasks, initStorage, isDefinedError, isLazy, isSilgiError, lazy, lifecycleWrap, mapAsyncIterator, mapInput, resetStorage, resolveLazy, runTask, scalarHTML, schemaToJsonSchema, setTaskAnalytics, silgi, startCronJobs, stopCronJobs, toSilgiError, type, useStorage, validateSchema, withEventMeta };
21
+ export { type AnySchema, AsyncIteratorClass, type BaseContext, type CallableOptions, type ContextBridge, type ConvertOptions, type Driver, type ErrorDef, type ErrorDefItem, type EventMeta, type FailFn, type GuardDef, type GuardFn, type InferClient, type InferContextFromUse, type InferGuardOutput, type InferSchemaInput, type InferSchemaOutput, type JSONSchema, type LazyRouter, type LifecycleHooks, type Meta, type MiddlewareDef, type ProcedureBuilder, type ProcedureBuilderWithOutput, type ProcedureDef, type ProcedureSummary, type ProcedureType, type ResolveContext, type RouterDef, type ScalarOptions, type ScheduledTaskInfo, type Schema, type SchemaConverter, type SchemaRegistry, type ServeOptions, type SilgiConfig, SilgiError, type SilgiErrorCode, type SilgiErrorJSON, type SilgiErrorOptions, type SilgiInstance, type SilgiServer, type Storage, type StorageConfig, type StorageValue, type TaskDef, type TaskEvent, ValidationError, type WrapDef, type WrapFn, callable, collectCronTasks, collectProcedures, compileProcedure, compileRouter, createContext, createContextBridge, createSchemaRegistry, generateOpenAPI, getEventMeta, getProcedurePaths, getScheduledTasks, initStorage, isDefinedError, isLazy, isProcedureDef, isSilgiError, lazy, lifecycleWrap, mapAsyncIterator, mapInput, resetStorage, resolveLazy, runTask, scalarHTML, schemaToJsonSchema, setTaskAnalytics, silgi, startCronJobs, stopCronJobs, toSilgiError, type, useStorage, validateSchema, withEventMeta };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ValidationError, type, validateSchema } from "./core/schema.mjs";
2
2
  import { collectCronTasks, getScheduledTasks, runTask, setTaskAnalytics, startCronJobs, stopCronJobs } from "./core/task.mjs";
3
3
  import { SilgiError, isDefinedError, isSilgiError, toSilgiError } from "./core/error.mjs";
4
+ import { collectProcedures, getProcedurePaths, isProcedureDef } from "./core/router-utils.mjs";
4
5
  import { compileProcedure, compileRouter, createContext } from "./compile.mjs";
5
6
  import { createContextBridge } from "./core/context-bridge.mjs";
6
7
  import { AsyncIteratorClass, mapAsyncIterator } from "./core/iterator.mjs";
@@ -13,4 +14,4 @@ import { mapInput } from "./map-input.mjs";
13
14
  import { isLazy, lazy, resolveLazy } from "./lazy.mjs";
14
15
  import { initStorage, resetStorage, useStorage } from "./core/storage.mjs";
15
16
  import { generateOpenAPI, scalarHTML } from "./scalar.mjs";
16
- export { AsyncIteratorClass, SilgiError, ValidationError, callable, collectCronTasks, compileProcedure, compileRouter, createContext, createContextBridge, createSchemaRegistry, generateOpenAPI, getEventMeta, getScheduledTasks, initStorage, isDefinedError, isLazy, isSilgiError, lazy, lifecycleWrap, mapAsyncIterator, mapInput, resetStorage, resolveLazy, runTask, scalarHTML, schemaToJsonSchema, setTaskAnalytics, silgi, startCronJobs, stopCronJobs, toSilgiError, type, useStorage, validateSchema, withEventMeta };
17
+ export { AsyncIteratorClass, SilgiError, ValidationError, callable, collectCronTasks, collectProcedures, compileProcedure, compileRouter, createContext, createContextBridge, createSchemaRegistry, generateOpenAPI, getEventMeta, getProcedurePaths, getScheduledTasks, initStorage, isDefinedError, isLazy, isProcedureDef, isSilgiError, lazy, lifecycleWrap, mapAsyncIterator, mapInput, resetStorage, resolveLazy, runTask, scalarHTML, schemaToJsonSchema, setTaskAnalytics, silgi, startCronJobs, stopCronJobs, toSilgiError, type, useStorage, validateSchema, withEventMeta };
@@ -1,3 +1,4 @@
1
+ import { collectProcedures } from "../../core/router-utils.mjs";
1
2
  import { compileProcedure } from "../../compile.mjs";
2
3
  import { jsonSchema, tool } from "ai";
3
4
  //#region src/integrations/ai/index.ts
@@ -53,23 +54,13 @@ function procedureToTool(name, procedure, options) {
53
54
  */
54
55
  function routerToTools(router, options) {
55
56
  const tools = {};
56
- collectProcedures(router, [], (path, proc) => {
57
+ collectProcedures(router, (path, proc) => {
57
58
  const flatName = path.join("_");
58
59
  if (options?.filter && !options.filter(flatName, proc)) return;
59
60
  tools[flatName] = procedureToTool(flatName, proc, { description: options?.descriptions?.[flatName] });
60
61
  });
61
62
  return tools;
62
63
  }
63
- function isProcedureDef(v) {
64
- return typeof v === "object" && v !== null && "type" in v && "resolve" in v;
65
- }
66
- function collectProcedures(node, path, cb) {
67
- if (isProcedureDef(node)) {
68
- cb(path, node);
69
- return;
70
- }
71
- if (typeof node === "object" && node !== null) for (const [key, child] of Object.entries(node)) collectProcedures(child, [...path, key], cb);
72
- }
73
64
  /** Simple Zod → JSON Schema for AI tool parameters */
74
65
  function zodToJsonSchemaSimple(schema) {
75
66
  const zod = schema?._zod ?? schema?._def;
package/dist/scalar.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { collectProcedures } from "./core/router-utils.mjs";
1
2
  import { schemaToJsonSchema } from "./core/schema-converter.mjs";
2
3
  //#region src/scalar.ts
3
4
  /**
@@ -35,7 +36,7 @@ function generateOpenAPI(router, options = {}, basePath = "", registry) {
35
36
  const schemaToJsonSchema$1 = (schema, strategy = "input") => schemaToJsonSchema(schema, strategy, registry);
36
37
  const paths = {};
37
38
  const tags = /* @__PURE__ */ new Map();
38
- collectProcedures(router, [], (path, proc) => {
39
+ collectProcedures(router, (path, proc) => {
39
40
  const route = proc.route;
40
41
  const { httpPath: routePath, pathParams } = toOpenAPIPath(route?.path ?? "/" + path.join("/"));
41
42
  const httpPath = basePath ? basePath.replace(/\/$/, "") + routePath : routePath;
@@ -260,16 +261,6 @@ function scalarHTML(specUrl, options = {}) {
260
261
  function escapeHtml(s) {
261
262
  return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
262
263
  }
263
- function isProcedureDef(value) {
264
- return typeof value === "object" && value !== null && "type" in value && "resolve" in value && typeof value.resolve === "function";
265
- }
266
- function collectProcedures(node, path, cb) {
267
- if (isProcedureDef(node)) {
268
- cb(path, node);
269
- return;
270
- }
271
- if (typeof node === "object" && node !== null) for (const [key, child] of Object.entries(node)) collectProcedures(child, [...path, key], cb);
272
- }
273
264
  function objectSchemaToParams(schema) {
274
265
  if (schema.type !== "object" || !schema.properties) return [];
275
266
  const required = new Set(schema.required ?? []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "silgi",
3
- "version": "0.52.0",
3
+ "version": "0.52.2",
4
4
  "private": false,
5
5
  "description": "The fastest end-to-end type-safe RPC framework for TypeScript — compiled pipelines, single package, every runtime",
6
6
  "keywords": [