File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed
src/schema-to-typescript/common Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
objectExpression ,
19
19
objectProperty ,
20
20
program ,
21
+ returnStatement ,
21
22
spreadElement ,
22
23
Statement ,
23
24
stringLiteral ,
@@ -166,9 +167,17 @@ export function generateClient({
166
167
} ) ;
167
168
clientClassBody . body . push (
168
169
attachJsDocComment (
169
- classProperty (
170
+ classMethod (
171
+ 'get' ,
170
172
identifier ( applyEntityNameCase ( tag , 'camelCase' ) ) ,
171
- newExpression ( identifier ( name ) , [ memberExpression ( thisExpression ( ) , identifier ( 'getClient' ) ) ] )
173
+ [ ] ,
174
+ blockStatement ( [
175
+ returnStatement (
176
+ callExpression ( memberExpression ( thisExpression ( ) , identifier ( 'getServiceInstance' ) ) , [
177
+ identifier ( name )
178
+ ] )
179
+ )
180
+ ] )
172
181
) ,
173
182
renderJsDoc ( jsdoc , jsDocRenderConfig )
174
183
)
@@ -246,14 +255,6 @@ export function generateClient({
246
255
)
247
256
)
248
257
] )
249
- ) ,
250
- classProperty (
251
- identifier ( 'createClientWithServices' ) ,
252
- memberExpression ( identifier ( commonHttpClientImportName ) , identifier ( 'createClientWithServices' ) ) ,
253
- null ,
254
- null ,
255
- false ,
256
- true
257
258
)
258
259
) ;
259
260
Original file line number Diff line number Diff line change 1
1
import * as commonHttpClient from './common-http-client' ;
2
2
3
3
export class CommonHttpService {
4
+ protected serviceInstancesMap : Map <
5
+ new ( getClientInstance : ( ) => commonHttpClient . CommonHttpClient ) => CommonHttpService ,
6
+ CommonHttpService
7
+ > = new Map ( ) ;
8
+
9
+ protected getServiceInstance < T extends CommonHttpService > (
10
+ serviceClass : new ( getClientInstance : ( ) => commonHttpClient . CommonHttpClient ) => T
11
+ ) : T {
12
+ let serviceInstance = this . serviceInstancesMap . get ( serviceClass ) ;
13
+ if ( ! serviceInstance ) {
14
+ serviceInstance = new serviceClass ( this . getClientInstance ) ;
15
+ this . serviceInstancesMap . set ( serviceClass , serviceInstance ) ;
16
+ }
17
+ return serviceInstance as T ;
18
+ }
19
+
4
20
protected getClientInstance : ( ) => commonHttpClient . CommonHttpClient ;
5
21
constructor ( getClientInstance : ( ) => commonHttpClient . CommonHttpClient ) {
6
22
this . getClientInstance = ( ) => {
You can’t perform that action at this time.
0 commit comments