Skip to content

Commit 5785006

Browse files
authored
feat: making schema's possible from request types (#180)
* feat: any typing of request options renamed to schema for schema type generation * feat: rename request options types to schema * feat: remove json from this repo
1 parent e4e7056 commit 5785006

23 files changed

+176
-76
lines changed

package-lock.json

Lines changed: 96 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import type { DeepgramClientOptions } from "./lib/types";
44
/**
55
* Creates a new Deepgram Client.
66
*/
7-
export const createClient = (apiKey: string, options?: DeepgramClientOptions): DeepgramClient => {
7+
const createClient = (apiKey: string, options?: DeepgramClientOptions): DeepgramClient => {
88
return new DeepgramClient(apiKey, options);
99
};
1010

11+
export { createClient, DeepgramClient };
12+
13+
/**
14+
* Helpful exports.
15+
*/
1116
export * from "./lib/types";
1217
export * from "./lib/enums";
18+
export * from "./lib/constants";
19+
export * from "./lib/errors";

src/lib/types/CreateOnPremCredentialsOptions.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface CreateOnPremCredentialsSchema extends Record<string, unknown> {
2+
comment?: string;
3+
scopes?: string[];
4+
provider?: string;
5+
}

src/lib/types/CreateProjectKeyOptions.ts renamed to src/lib/types/CreateProjectKeySchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type CreateProjectKeyOptions = ExpirationOptions | TtlOptions;
1+
export type CreateProjectKeySchema = ExpirationOptions | TtlOptions;
22

33
interface ExpirationOptions extends CommonOptions {
44
expiration_date?: string;

src/lib/types/GetProjectUsageFieldsOptions.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface GetProjectUsageFieldsSchema extends Record<string, unknown> {
2+
start?: string;
3+
end: string;
4+
}

src/lib/types/GetProjectUsageRequestsOptions.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface GetProjectUsageRequestsSchema extends Record<string, unknown> {
2+
start?: string;
3+
end?: string;
4+
limit?: number;
5+
status?: string;
6+
}

src/lib/types/GetProjectUsageSummaryOptions.ts renamed to src/lib/types/GetProjectUsageSummarySchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface GetProjectUsageSummaryOptions extends Record<string, unknown> {
1+
export interface GetProjectUsageSummarySchema extends Record<string, unknown> {
22
start?: string;
33
end: string;
44
accessor?: string;

src/lib/types/SendProjectInviteOptions.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface SendProjectInviteSchema extends Record<string, unknown> {
2+
email: string;
3+
scope: string;
4+
}

src/lib/types/TranscriptionOptions.ts renamed to src/lib/types/TranscriptionSchema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Options for transcription
33
*/
4-
interface TranscriptionOptions extends Record<string, unknown> {
4+
interface TranscriptionSchema extends Record<string, unknown> {
55
/**
66
* @see https://developers.deepgram.com/docs/model
77
*/
@@ -86,7 +86,7 @@ interface TranscriptionOptions extends Record<string, unknown> {
8686
[key: string]: unknown;
8787
}
8888

89-
interface PrerecordedOptions extends TranscriptionOptions {
89+
interface PrerecordedSchema extends TranscriptionSchema {
9090
/**
9191
* @see https://developers.deepgram.com/docs/detect-entities
9292
*/
@@ -128,7 +128,7 @@ interface PrerecordedOptions extends TranscriptionOptions {
128128
utt_split?: number;
129129
}
130130

131-
interface LiveOptions extends TranscriptionOptions {
131+
interface LiveSchema extends TranscriptionSchema {
132132
/**
133133
* @see https://developers.deepgram.com/docs/channels
134134
*/
@@ -155,4 +155,4 @@ interface LiveOptions extends TranscriptionOptions {
155155
interim_results?: boolean;
156156
}
157157

158-
export type { TranscriptionOptions, PrerecordedOptions, LiveOptions };
158+
export type { TranscriptionSchema, PrerecordedSchema, LiveSchema };

src/lib/types/UpdateProjectMemberScopeOptions.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface UpdateProjectMemberScopeSchema {
2+
scope: string;
3+
}

src/lib/types/UpdateProjectOptions.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/lib/types/UpdateProjectSchema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface UpdateProjectSchema extends Record<string, unknown> {
2+
name?: string;
3+
company?: string;
4+
[key: string]: unknown;
5+
}

src/lib/types/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type { AsyncPrerecordedResponse } from "./AsyncPrerecordedResponse";
2-
export type { CreateOnPremCredentialsOptions } from "./CreateOnPremCredentialsOptions";
3-
export type { CreateProjectKeyOptions } from "./CreateProjectKeyOptions";
2+
export type { CreateOnPremCredentialsSchema } from "./CreateOnPremCredentialsSchema";
3+
export type { CreateProjectKeySchema } from "./CreateProjectKeySchema";
44
export type { CreateProjectKeyResponse } from "./CreateProjectKeyResponse";
55
export type { DeepgramClientOptions } from "./DeepgramClientOptions";
66
export type { DeepgramResponse } from "./DeepgramResponse";
@@ -15,14 +15,14 @@ export type { GetProjectMemberScopesResponse } from "./GetProjectMemberScopesRes
1515
export type { GetProjectMembersResponse } from "./GetProjectMembersResponse";
1616
export type { GetProjectResponse } from "./GetProjectResponse";
1717
export type { GetProjectsResponse } from "./GetProjectsResponse";
18-
export type { GetProjectUsageFieldsOptions } from "./GetProjectUsageFieldsOptions";
18+
export type { GetProjectUsageFieldsSchema } from "./GetProjectUsageFieldsSchema";
1919
export type { GetProjectUsageFieldsResponse } from "./GetProjectUsageFieldsResponse";
2020
export type {
2121
GetProjectUsageRequestResponse,
2222
GetProjectUsageRequestsResponse,
2323
} from "./GetProjectUsageRequestsResponse";
24-
export type { GetProjectUsageRequestsOptions } from "./GetProjectUsageRequestsOptions";
25-
export type { GetProjectUsageSummaryOptions } from "./GetProjectUsageSummaryOptions";
24+
export type { GetProjectUsageRequestsSchema } from "./GetProjectUsageRequestsSchema";
25+
export type { GetProjectUsageSummarySchema } from "./GetProjectUsageSummarySchema";
2626
export type { GetProjectUsageSummaryResponse } from "./GetProjectUsageSummaryResponse";
2727
export type {
2828
ListOnPremCredentialsResponse,
@@ -33,9 +33,9 @@ export type { LiveMetadataEvent } from "./LiveMetadataEvent";
3333
export type { LiveTranscriptionEvent } from "./LiveTranscriptionEvent";
3434
export type { MessageResponse } from "./MessageResponse";
3535
export type { FileSource, PrerecordedSource, UrlSource } from "./PrerecordedSource";
36-
export type { SendProjectInviteOptions } from "./SendProjectInviteOptions";
36+
export type { SendProjectInviteSchema } from "./SendProjectInviteSchema";
3737
export type { SyncPrerecordedResponse } from "./SyncPrerecordedResponse";
38-
export type { TranscriptionOptions, PrerecordedOptions, LiveOptions } from "./TranscriptionOptions";
39-
export type { UpdateProjectMemberScopeOptions } from "./UpdateProjectMemberScopeOptions";
40-
export type { UpdateProjectOptions } from "./UpdateProjectOptions";
38+
export type { TranscriptionSchema, PrerecordedSchema, LiveSchema } from "./TranscriptionSchema";
39+
export type { UpdateProjectMemberScopeSchema } from "./UpdateProjectMemberScopeSchema";
40+
export type { UpdateProjectSchema } from "./UpdateProjectSchema";
4141
export type { VoidResponse } from "./VoidResponse";

src/packages/ListenClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PrerecordedClient } from "./PrerecordedClient";
22
import { LiveClient } from "./LiveClient";
3-
import { LiveOptions } from "../lib/types";
3+
import { LiveSchema } from "../lib/types";
44

55
export class ListenClient {
66
protected baseUrl: URL;
@@ -17,7 +17,7 @@ export class ListenClient {
1717
return new PrerecordedClient(this.baseUrl, this.headers, this.key);
1818
}
1919

20-
public live(options: LiveOptions, endpoint = "v1/listen") {
20+
public live(options: LiveSchema, endpoint = "v1/listen") {
2121
return new LiveClient(this.baseUrl, this.key, options, endpoint);
2222
}
2323
}

src/packages/LiveClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { appendSearchParams, isBrowser } from "../lib/helpers";
33
import WebSocket from "modern-isomorphic-ws";
44
import { LiveConnectionState, LiveTranscriptionEvents } from "../lib/enums";
55
import type {
6-
LiveOptions,
6+
LiveSchema,
77
LiveConfigOptions,
88
LiveMetadataEvent,
99
LiveTranscriptionEvent,
@@ -13,10 +13,10 @@ import { DEFAULT_HEADERS } from "../lib/constants";
1313
export class LiveClient extends EventEmitter {
1414
private _socket: WebSocket;
1515

16-
constructor(baseUrl: URL, apiKey: string, options: LiveOptions, endpoint = "v1/listen") {
16+
constructor(baseUrl: URL, apiKey: string, options: LiveSchema, endpoint = "v1/listen") {
1717
super();
1818

19-
const transcriptionOptions: LiveOptions = { ...{}, ...options };
19+
const transcriptionOptions: LiveSchema = { ...{}, ...options };
2020
const url = new URL(endpoint, baseUrl);
2121
url.protocol = url.protocol.toLowerCase().replace(/(http)(s)?/gi, "ws$2");
2222
appendSearchParams(url.searchParams, transcriptionOptions);

0 commit comments

Comments
 (0)