@@ -2,15 +2,14 @@ import {printTree} from 'tree-dump/lib/printTree';
22import * as schema from '../../schema' ;
33import { AbsType } from './AbsType' ;
44import type { SchemaOf , Type } from '../types' ;
5- import type * as ts from '../../typescript/types' ;
65import type { ResolveType } from '../../system' ;
76import type { Observable } from 'rxjs' ;
87
98const fnNotImplemented : schema . FunctionValue < any , any > = async ( ) => {
109 throw new Error ( 'NOT_IMPLEMENTED' ) ;
1110} ;
1211
13- const toStringTree = ( tab : string = '' , type : FnType < Type , Type > | FunctionStreamingType < Type , Type > ) => {
12+ const toStringTree = ( tab : string = '' , type : FnType < Type , Type , any > | FnRxType < Type , Type , any > ) => {
1413 return printTree ( tab , [
1514 ( tab ) => 'req: ' + type . req . toString ( tab + ' ' ) ,
1615 ( tab ) => 'res: ' + type . res . toString ( tab + ' ' ) ,
@@ -20,12 +19,12 @@ const toStringTree = (tab: string = '', type: FnType<Type, Type> | FunctionStrea
2019type FunctionImpl < Req extends Type , Res extends Type , Ctx = unknown > = (
2120 req : ResolveType < Req > ,
2221 ctx : Ctx ,
23- ) => Promise < ResolveType < Res > > ;
22+ ) => ResolveType < Res > | Promise < ResolveType < Res > > ;
2423
25- export class FnType < Req extends Type , Res extends Type > extends AbsType <
26- schema . FunctionSchema < SchemaOf < Req > , SchemaOf < Res > >
24+ export class FnType < Req extends Type , Res extends Type , Ctx = unknown > extends AbsType <
25+ schema . FunctionSchema < SchemaOf < Req > , SchemaOf < Res > , Ctx >
2726> {
28- protected schema : schema . FunctionSchema < SchemaOf < Req > , SchemaOf < Res > > ;
27+ protected schema : schema . FunctionSchema < SchemaOf < Req > , SchemaOf < Res > , Ctx > ;
2928
3029 public fn : schema . FunctionValue < schema . TypeOf < SchemaOf < Req > > , schema . TypeOf < SchemaOf < Res > > > = fnNotImplemented ;
3130
@@ -59,17 +58,21 @@ export class FnType<Req extends Type, Res extends Type> extends AbsType<
5958 return this . response ( res ) ;
6059 }
6160
62- public getSchema ( ) : schema . FunctionSchema < SchemaOf < Req > , SchemaOf < Res > > {
61+ public ctx < T > ( ) : FnType < Req , Res , T > {
62+ return this as any ;
63+ }
64+
65+ public getSchema ( ) : schema . FunctionSchema < SchemaOf < Req > , SchemaOf < Res > , Ctx > {
6366 return {
6467 ...this . schema ,
6568 req : this . req . getSchema ( ) as SchemaOf < Req > ,
6669 res : this . res . getSchema ( ) as SchemaOf < Res > ,
6770 } ;
6871 }
6972
70- public singleton ?: FunctionImpl < Req , Res , any > = undefined ;
73+ public singleton ?: FunctionImpl < Req , Res , Ctx > = undefined ;
7174
72- public implement < Ctx = unknown > ( singleton : FunctionImpl < Req , Res , Ctx > ) : this {
75+ public implement ( singleton : FunctionImpl < Req , Res , Ctx > ) : this {
7376 this . singleton = singleton ;
7477 return this ;
7578 }
@@ -84,11 +87,11 @@ type FunctionStreamingImpl<Req extends Type, Res extends Type, Ctx = unknown> =
8487 ctx : Ctx ,
8588) => Observable < ResolveType < Res > > ;
8689
87- export class FunctionStreamingType < Req extends Type , Res extends Type > extends AbsType <
88- schema . FunctionStreamingSchema < SchemaOf < Req > , SchemaOf < Res > >
90+ export class FnRxType < Req extends Type , Res extends Type , Ctx = unknown > extends AbsType <
91+ schema . FunctionStreamingSchema < SchemaOf < Req > , SchemaOf < Res > , Ctx >
8992> {
9093 public readonly isStreaming = true ;
91- protected schema : schema . FunctionStreamingSchema < SchemaOf < Req > , SchemaOf < Res > > ;
94+ protected schema : schema . FunctionStreamingSchema < SchemaOf < Req > , SchemaOf < Res > , Ctx > ;
9295
9396 constructor (
9497 public readonly req : Req ,
@@ -120,17 +123,17 @@ export class FunctionStreamingType<Req extends Type, Res extends Type> extends A
120123 return this . response ( res ) ;
121124 }
122125
123- public getSchema ( ) : schema . FunctionStreamingSchema < SchemaOf < Req > , SchemaOf < Res > > {
126+ public getSchema ( ) : schema . FunctionStreamingSchema < SchemaOf < Req > , SchemaOf < Res > , Ctx > {
124127 return {
125128 ...this . schema ,
126129 req : this . req . getSchema ( ) as SchemaOf < Req > ,
127130 res : this . res . getSchema ( ) as SchemaOf < Res > ,
128131 } ;
129132 }
130133
131- public singleton ?: FunctionStreamingImpl < Req , Res , any > = undefined ;
134+ public singleton ?: FunctionStreamingImpl < Req , Res , Ctx > = undefined ;
132135
133- public implement < Ctx = unknown > ( singleton : FunctionStreamingImpl < Req , Res , Ctx > ) : this {
136+ public implement ( singleton : FunctionStreamingImpl < Req , Res , Ctx > ) : this {
134137 this . singleton = singleton ;
135138 return this ;
136139 }
0 commit comments