Skip to content

Commit 1c3da35

Browse files
committed
refactor: generated code format slightly changed
1 parent 3123e5c commit 1c3da35

File tree

14 files changed

+2523
-1253
lines changed

14 files changed

+2523
-1253
lines changed

src/BaseApi.ts renamed to src/ApiClient.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import { ApiConfig, RequestMetadata, StreamError } from './types';
33
import { APIError } from './gen/models';
44
import { getRateLimitFromResponseHeader } from './utils/rate-limit';
55

6-
export class BaseApi {
6+
export class ApiClient {
77
private readonly dispatcher?: RequestInit['dispatcher'];
88

9-
constructor(protected readonly apiConfig: ApiConfig) {
9+
constructor(public readonly apiConfig: ApiConfig) {
1010
this.dispatcher = this.apiConfig.agent;
1111
}
1212

13-
protected sendRequest = async <T>(
13+
/**
14+
*
15+
* @internal
16+
*/
17+
sendRequest = async <T>(
1418
method: string,
1519
url: string,
1620
pathParams?: Record<string, string>,

src/StreamCall.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryCallMembersRequest } from './gen/models';
1+
import { GetOrCreateCallRequest, QueryCallMembersRequest } from './gen/models';
22
import { CallApi } from './gen/video/CallApi';
33
import { OmitTypeId } from './types';
44

@@ -7,7 +7,7 @@ export class StreamCall extends CallApi {
77
return `${this.type}:${this.id}`;
88
}
99

10-
create = this.getOrCreate;
10+
create = (request?: GetOrCreateCallRequest) => this.getOrCreate(request);
1111

1212
queryMembers = (request?: OmitTypeId<QueryCallMembersRequest>) => {
1313
return this.videoApi.queryCallMembers({

src/StreamClient.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { StreamChatClient } from './StreamChatClient';
66
import { CallTokenPayload, UserTokenPayload } from './types';
77
import { QueryBannedUsersPayload, UserRequest } from './gen/models';
88
import { StreamModerationClient } from './StreamModerationClient';
9+
import { ApiClient } from './ApiClient';
910

1011
export interface StreamClientOptions {
1112
timeout?: number;
@@ -38,36 +39,30 @@ export class StreamClient extends CommonApi {
3839
const timeout = config?.timeout ?? StreamClient.DEFAULT_TIMEOUT;
3940
const chatBaseUrl = config?.basePath ?? 'https://chat.stream-io-api.com';
4041
const videoBaseUrl = config?.basePath ?? 'https://video.stream-io-api.com';
41-
super({
42+
const chatApiClient = new ApiClient({
4243
apiKey,
4344
token,
44-
timeout,
4545
baseUrl: chatBaseUrl,
46+
timeout,
4647
agent: config?.agent as RequestInit['dispatcher'],
4748
});
4849

49-
this.video = new StreamVideoClient({
50-
streamClient: this,
50+
const videoApiClient = new ApiClient({
5151
apiKey,
5252
token,
53-
timeout,
5453
baseUrl: videoBaseUrl,
55-
agent: config?.agent as RequestInit['dispatcher'],
56-
});
57-
this.chat = new StreamChatClient({
58-
apiKey,
59-
token,
6054
timeout,
61-
baseUrl: chatBaseUrl,
6255
agent: config?.agent as RequestInit['dispatcher'],
6356
});
64-
this.moderation = new StreamModerationClient({
65-
apiKey,
66-
token,
67-
timeout,
68-
baseUrl: chatBaseUrl,
69-
agent: config?.agent as RequestInit['dispatcher'],
57+
58+
super(chatApiClient);
59+
60+
this.video = new StreamVideoClient({
61+
streamClient: this,
62+
apiClient: videoApiClient,
7063
});
64+
this.chat = new StreamChatClient(this.apiClient);
65+
this.moderation = new StreamModerationClient(chatApiClient);
7166
}
7267

7368
upsertUsers = (users: UserRequest[]) => {

src/StreamVideoClient.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { ApiClient } from './ApiClient';
12
import { VideoApi } from './gen/video/VideoApi';
23
import { StreamCall } from './StreamCall';
34
import type { StreamClient } from './StreamClient';
4-
import type { ApiConfig } from './types';
55
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
66
/** @ts-ignore Optional dependency */
77
import type {
@@ -15,9 +15,12 @@ export class StreamVideoClient extends VideoApi {
1515

1616
constructor({
1717
streamClient,
18-
...apiConfig
19-
}: ApiConfig & { streamClient: StreamClient }) {
20-
super(apiConfig);
18+
apiClient,
19+
}: {
20+
streamClient: StreamClient;
21+
apiClient: ApiClient;
22+
}) {
23+
super(apiClient);
2124
this.streamClient = streamClient;
2225
}
2326

@@ -54,9 +57,9 @@ export class StreamVideoClient extends VideoApi {
5457
});
5558

5659
const realtimeClient = doCreateRealtimeClient({
57-
baseUrl: this.apiConfig.baseUrl,
60+
baseUrl: this.streamClient.apiClient.apiConfig.baseUrl,
5861
call: options.call,
59-
streamApiKey: this.apiConfig.apiKey,
62+
streamApiKey: this.streamClient.apiClient.apiConfig.apiKey,
6063
streamUserToken: token,
6164
openAiApiKey: options.openAiApiKey,
6265
model: options.model,

src/gen-imports.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './ApiClient';
2+
export * from './gen/chat/ChatApi';
3+
export * from './gen/video/VideoApi';
4+
export * from './types';

0 commit comments

Comments
 (0)