Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fac164

Browse files
committed
Export generated HttpClient class.
This allows the class to be extended.
1 parent 83f074a commit 0fac164

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

conformance/src/conformanceApi.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { IConformanceApi, IGetApiInfoRequest, IGetApiInfoResponse, IGetWidgetsRe
66
export * from './conformanceApiTypes';
77

88
/** Provides access to ConformanceApi over HTTP via fetch. */
9-
export function createHttpClient({ fetch, baseUri }: IHttpClientOptions): IConformanceApi {
10-
return new ConformanceApiHttpClient(fetch, baseUri);
9+
export function createHttpClient(options: IHttpClientOptions): IConformanceApi {
10+
return new ConformanceApiHttpClient(options);
1111
}
1212

1313
const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;
@@ -27,8 +27,9 @@ function parseBoolean(value: string | undefined) {
2727
return undefined;
2828
}
2929

30-
class ConformanceApiHttpClient implements IConformanceApi {
31-
constructor(fetch: IFetch, baseUri?: string) {
30+
/** Provides access to ConformanceApi over HTTP via fetch. */
31+
export class ConformanceApiHttpClient implements IConformanceApi {
32+
constructor({ fetch, baseUri }: IHttpClientOptions) {
3233
if (typeof fetch !== 'function') {
3334
throw new TypeError('fetch must be a function.');
3435
}

conformance/src/jsConformanceApi.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import { HttpClientUtility } from 'facility-core';
66

77
/** Provides access to JsConformanceApi over HTTP via fetch. */
8-
export function createHttpClient({ fetch, baseUri }) {
9-
return new JsConformanceApiHttpClient(fetch, baseUri);
8+
export function createHttpClient(options) {
9+
return new JsConformanceApiHttpClient(options);
1010
}
1111

1212
const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;
@@ -24,8 +24,9 @@ function parseBoolean(value) {
2424
return undefined;
2525
}
2626

27-
class JsConformanceApiHttpClient {
28-
constructor(fetch, baseUri) {
27+
/** Provides access to JsConformanceApi over HTTP via fetch. */
28+
export class JsConformanceApiHttpClient {
29+
constructor({ fetch, baseUri }) {
2930
if (typeof fetch !== 'function') {
3031
throw new TypeError('fetch must be a function.');
3132
}

example/js/exampleApi.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
import { HttpClientUtility } from 'facility-core';
66

77
/** Provides access to ExampleApi over HTTP via fetch. */
8-
export function createHttpClient({ fetch, baseUri }) {
9-
return new ExampleApiHttpClient(fetch, baseUri);
8+
export function createHttpClient(options) {
9+
return new ExampleApiHttpClient(options);
1010
}
1111

1212
const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;
1313

14-
class ExampleApiHttpClient {
15-
constructor(fetch, baseUri) {
14+
/** Provides access to ExampleApi over HTTP via fetch. */
15+
export class ExampleApiHttpClient {
16+
constructor({ fetch, baseUri }) {
1617
if (typeof fetch !== 'function') {
1718
throw new TypeError('fetch must be a function.');
1819
}

example/ts/src/exampleApi.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { IExampleApi, IGetWidgetsRequest, IGetWidgetsResponse, ICreateWidgetRequ
66
export * from './exampleApiTypes';
77

88
/** Provides access to ExampleApi over HTTP via fetch. */
9-
export function createHttpClient({ fetch, baseUri }: IHttpClientOptions): IExampleApi {
10-
return new ExampleApiHttpClient(fetch, baseUri);
9+
export function createHttpClient(options: IHttpClientOptions): IExampleApi {
10+
return new ExampleApiHttpClient(options);
1111
}
1212

1313
const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;
1414
type IFetch = HttpClientUtility.IFetch;
1515
type IFetchRequest = HttpClientUtility.IFetchRequest;
1616

17-
class ExampleApiHttpClient implements IExampleApi {
18-
constructor(fetch: IFetch, baseUri?: string) {
17+
/** Provides access to ExampleApi over HTTP via fetch. */
18+
export class ExampleApiHttpClient implements IExampleApi {
19+
constructor({ fetch, baseUri }: IHttpClientOptions) {
1920
if (typeof fetch !== 'function') {
2021
throw new TypeError('fetch must be a function.');
2122
}

src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public override CodeGenOutput GenerateOutput(ServiceInfo service)
162162

163163
code.WriteLine();
164164
WriteJsDoc(code, $"Provides access to {capModuleName} over HTTP via fetch.");
165-
using (code.Block("export function createHttpClient({ fetch, baseUri }" + IfTypeScript(": IHttpClientOptions") + ")" + IfTypeScript($": I{capModuleName}") + " {", "}"))
166-
code.WriteLine($"return new {capModuleName}HttpClient(fetch, baseUri);");
165+
using (code.Block("export function createHttpClient(options" + IfTypeScript(": IHttpClientOptions") + ")" + IfTypeScript($": I{capModuleName}") + " {", "}"))
166+
code.WriteLine($"return new {capModuleName}HttpClient(options);");
167167

168168
code.WriteLine();
169169
code.WriteLine("const { fetchResponse, createResponseError, createRequiredRequestFieldError } = HttpClientUtility;");
@@ -192,9 +192,10 @@ public override CodeGenOutput GenerateOutput(ServiceInfo service)
192192
}
193193

194194
code.WriteLine();
195-
using (code.Block($"class {capModuleName}HttpClient" + IfTypeScript($" implements I{capModuleName}") + " {", "}"))
195+
WriteJsDoc(code, $"Provides access to {capModuleName} over HTTP via fetch.");
196+
using (code.Block($"export class {capModuleName}HttpClient" + IfTypeScript($" implements I{capModuleName}") + " {", "}"))
196197
{
197-
using (code.Block("constructor(fetch" + IfTypeScript(": IFetch") + ", baseUri" + IfTypeScript("?: string") + ") {", "}"))
198+
using (code.Block("constructor({ fetch, baseUri }" + IfTypeScript(": IHttpClientOptions") + ") {", "}"))
198199
{
199200
using (code.Block("if (typeof fetch !== 'function') {", "}"))
200201
code.WriteLine("throw new TypeError('fetch must be a function.');");

0 commit comments

Comments
 (0)