ts-procedures 8.5.0 → 8.6.0

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.
@@ -387,6 +387,35 @@ function injectRouteErrors(
387
387
  // Route emitters
388
388
  // ---------------------------------------------------------------------------
389
389
 
390
+ /**
391
+ * Builds the multi-line JSDoc comment for a route callable. Surfaces the
392
+ * second `options` argument (the per-call AbortSignal/timeout seam — DX #8) and,
393
+ * for routes that declare typed errors, points at the route's `Errors` type and
394
+ * how to narrow it on the throwing path (DX #10). Indented for placement inside
395
+ * the bind-object (4 spaces).
396
+ */
397
+ function buildCallableJsDoc(opts: {
398
+ methodLabel: string
399
+ path: string
400
+ errorsRef: string | null
401
+ }): string {
402
+ const lines = [
403
+ ` /**`,
404
+ ` * ${opts.methodLabel} ${opts.path}`,
405
+ ` *`,
406
+ ` * @param options Optional per-call {@link ProcedureCallOptions} —`,
407
+ ` * \`signal\` (cancel on dispose), \`timeout\`, \`headers\`, \`basePath\`.`,
408
+ ]
409
+ if (opts.errorsRef) {
410
+ lines.push(
411
+ ` * @throws Declared typed errors: {@link ${opts.errorsRef}}. Narrow with`,
412
+ ` * \`instanceof\` on the throwing path, or call \`.safe()\` for a \`Result\`.`,
413
+ )
414
+ }
415
+ lines.push(` */`)
416
+ return lines.join('\n')
417
+ }
418
+
390
419
  async function emitRpcRoute(route: RPCHttpRouteDoc, ctx: EmitRouteContext): Promise<RouteChunks> {
391
420
  const pascal = versionedPascal(route.name, route.version)
392
421
 
@@ -395,7 +424,7 @@ async function emitRpcRoute(route: RPCHttpRouteDoc, ctx: EmitRouteContext): Prom
395
424
  { shortName: 'Response', schema: route.jsonSchema.response },
396
425
  ], ctx)
397
426
 
398
- const paramsTypeName = refs['Params'] ?? 'unknown'
427
+ const paramsTypeName = refs['Params'] ?? 'void'
399
428
  const responseTypeName = refs['Response'] ?? 'unknown'
400
429
  const scopeStr = Array.isArray(route.scope) ? route.scope.join('-') : route.scope
401
430
 
@@ -409,7 +438,11 @@ async function emitRpcRoute(route: RPCHttpRouteDoc, ctx: EmitRouteContext): Prom
409
438
  : `client.bindCallable<${paramsTypeName}, ${responseTypeName}>`
410
439
 
411
440
  const callable = [
412
- ` /** ${route.method.toUpperCase()} ${route.path} */`,
441
+ buildCallableJsDoc({
442
+ methodLabel: route.method.toUpperCase(),
443
+ path: route.path,
444
+ errorsRef: hasErrors ? errorsRef : null,
445
+ }),
413
446
  ` ${pascal}: ${helperCall}({`,
414
447
  ` name: '${pascal}',`,
415
448
  ` scope: '${scopeStr}',`,
@@ -533,7 +566,7 @@ async function emitApiRoute(route: APIHttpRouteDoc, ctx: EmitRouteContext): Prom
533
566
  : `${pascal}Errors`
534
567
 
535
568
  const declarations: string[] = []
536
- let paramsTypeName = 'unknown'
569
+ let paramsTypeName = 'void'
537
570
  let returnTypeName = 'void'
538
571
 
539
572
  // Track reserved names across all sub-namespaces. Model names are reserved
@@ -638,7 +671,11 @@ async function emitApiRoute(route: APIHttpRouteDoc, ctx: EmitRouteContext): Prom
638
671
  ]
639
672
 
640
673
  const callable = [
641
- ` /** ${route.method.toUpperCase()} ${route.fullPath} */`,
674
+ buildCallableJsDoc({
675
+ methodLabel: route.method.toUpperCase(),
676
+ path: route.fullPath,
677
+ errorsRef: hasErrors ? errorsRef : null,
678
+ }),
642
679
  ` ${route.name}: ${helperCall}({`,
643
680
  ...descriptorLines,
644
681
  ` }),`,
@@ -676,7 +713,7 @@ async function emitHttpStreamRoute(route: HttpStreamRouteDoc, ctx: EmitRouteCont
676
713
 
677
714
  const scopeStr = route.scope ?? 'default'
678
715
  const declarations: string[] = []
679
- let paramsTypeName = 'unknown'
716
+ let paramsTypeName = 'void'
680
717
  let yieldTypeName = 'unknown'
681
718
  let returnTypeName = 'void'
682
719
 
@@ -774,7 +811,11 @@ async function emitHttpStreamRoute(route: HttpStreamRouteDoc, ctx: EmitRouteCont
774
811
  }
775
812
 
776
813
  const callable = [
777
- ` /** ${route.method.toUpperCase()} ${route.fullPath} */`,
814
+ buildCallableJsDoc({
815
+ methodLabel: route.method.toUpperCase(),
816
+ path: route.fullPath,
817
+ errorsRef: null,
818
+ }),
778
819
  ` ${route.name}(req: ${paramsTypeName}, options?: ProcedureCallOptions): TypedStream<${yieldTypeName}, ${returnTypeName}> {`,
779
820
  ` return client.stream<${yieldTypeName}, ${returnTypeName}>({`,
780
821
  ` name: '${route.name}',`,
@@ -813,13 +854,17 @@ async function emitStreamRoute(route: StreamHttpRouteDoc, ctx: EmitRouteContext)
813
854
  { shortName: 'Return', schema: route.jsonSchema.returnType },
814
855
  ], ctx)
815
856
 
816
- const paramsTypeName = refs['Params'] ?? 'unknown'
857
+ const paramsTypeName = refs['Params'] ?? 'void'
817
858
  const yieldTypeName = refs['Yield'] ?? 'unknown'
818
859
  const returnTypeName = refs['Return'] ?? 'void'
819
860
  const scopeStr = Array.isArray(route.scope) ? route.scope.join('-') : route.scope
820
861
 
821
862
  const callable = [
822
- ` /** ${route.methods.map((m) => m.toUpperCase()).join('|')} ${route.path} */`,
863
+ buildCallableJsDoc({
864
+ methodLabel: route.methods.map((m) => m.toUpperCase()).join('|'),
865
+ path: route.path,
866
+ errorsRef: null,
867
+ }),
823
868
  ` ${pascal}(params: ${paramsTypeName}, options?: ProcedureCallOptions): TypedStream<${yieldTypeName}, ${returnTypeName}> {`,
824
869
  ` return client.stream<${yieldTypeName}, ${returnTypeName}>({`,
825
870
  ` name: '${pascal}',`,
@@ -192,4 +192,10 @@ object Users {
192
192
  val count: Long,
193
193
  )
194
194
  }
195
+
196
+ object Heartbeat {
197
+ const val method = "GET"
198
+ const val pathTemplate = "/users/heartbeat"
199
+ const val path = "/users/heartbeat"
200
+ }
195
201
  }
@@ -199,4 +199,10 @@ public enum Users {
199
199
  public let count: Int64
200
200
  }
201
201
  }
202
+
203
+ public enum Heartbeat {
204
+ public static let method = "GET"
205
+ public static let pathTemplate = "/users/heartbeat"
206
+ public static let path = "/users/heartbeat"
207
+ }
202
208
  }