Skip to content

Commit

Permalink
feat: making schema's possible from request types (#180)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lukeocodes authored Oct 19, 2023
1 parent e4e7056 commit 5785006
Show file tree
Hide file tree
Showing 23 changed files with 176 additions and 76 deletions.
99 changes: 96 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import type { DeepgramClientOptions } from "./lib/types";
/**
* Creates a new Deepgram Client.
*/
export const createClient = (apiKey: string, options?: DeepgramClientOptions): DeepgramClient => {
const createClient = (apiKey: string, options?: DeepgramClientOptions): DeepgramClient => {
return new DeepgramClient(apiKey, options);
};

export { createClient, DeepgramClient };

/**
* Helpful exports.
*/
export * from "./lib/types";
export * from "./lib/enums";
export * from "./lib/constants";
export * from "./lib/errors";
5 changes: 0 additions & 5 deletions src/lib/types/CreateOnPremCredentialsOptions.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/lib/types/CreateOnPremCredentialsSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CreateOnPremCredentialsSchema extends Record<string, unknown> {
comment?: string;
scopes?: string[];
provider?: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type CreateProjectKeyOptions = ExpirationOptions | TtlOptions;
export type CreateProjectKeySchema = ExpirationOptions | TtlOptions;

interface ExpirationOptions extends CommonOptions {
expiration_date?: string;
Expand Down
4 changes: 0 additions & 4 deletions src/lib/types/GetProjectUsageFieldsOptions.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/lib/types/GetProjectUsageFieldsSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface GetProjectUsageFieldsSchema extends Record<string, unknown> {
start?: string;
end: string;
}
6 changes: 0 additions & 6 deletions src/lib/types/GetProjectUsageRequestsOptions.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/lib/types/GetProjectUsageRequestsSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface GetProjectUsageRequestsSchema extends Record<string, unknown> {
start?: string;
end?: string;
limit?: number;
status?: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface GetProjectUsageSummaryOptions extends Record<string, unknown> {
export interface GetProjectUsageSummarySchema extends Record<string, unknown> {
start?: string;
end: string;
accessor?: string;
Expand Down
4 changes: 0 additions & 4 deletions src/lib/types/SendProjectInviteOptions.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/lib/types/SendProjectInviteSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface SendProjectInviteSchema extends Record<string, unknown> {
email: string;
scope: string;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Options for transcription
*/
interface TranscriptionOptions extends Record<string, unknown> {
interface TranscriptionSchema extends Record<string, unknown> {
/**
* @see https://developers.deepgram.com/docs/model
*/
Expand Down Expand Up @@ -86,7 +86,7 @@ interface TranscriptionOptions extends Record<string, unknown> {
[key: string]: unknown;
}

interface PrerecordedOptions extends TranscriptionOptions {
interface PrerecordedSchema extends TranscriptionSchema {
/**
* @see https://developers.deepgram.com/docs/detect-entities
*/
Expand Down Expand Up @@ -128,7 +128,7 @@ interface PrerecordedOptions extends TranscriptionOptions {
utt_split?: number;
}

interface LiveOptions extends TranscriptionOptions {
interface LiveSchema extends TranscriptionSchema {
/**
* @see https://developers.deepgram.com/docs/channels
*/
Expand All @@ -155,4 +155,4 @@ interface LiveOptions extends TranscriptionOptions {
interim_results?: boolean;
}

export type { TranscriptionOptions, PrerecordedOptions, LiveOptions };
export type { TranscriptionSchema, PrerecordedSchema, LiveSchema };
3 changes: 0 additions & 3 deletions src/lib/types/UpdateProjectMemberScopeOptions.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/lib/types/UpdateProjectMemberScopeSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface UpdateProjectMemberScopeSchema {
scope: string;
}
5 changes: 0 additions & 5 deletions src/lib/types/UpdateProjectOptions.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/lib/types/UpdateProjectSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface UpdateProjectSchema extends Record<string, unknown> {
name?: string;
company?: string;
[key: string]: unknown;
}
18 changes: 9 additions & 9 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type { AsyncPrerecordedResponse } from "./AsyncPrerecordedResponse";
export type { CreateOnPremCredentialsOptions } from "./CreateOnPremCredentialsOptions";
export type { CreateProjectKeyOptions } from "./CreateProjectKeyOptions";
export type { CreateOnPremCredentialsSchema } from "./CreateOnPremCredentialsSchema";
export type { CreateProjectKeySchema } from "./CreateProjectKeySchema";
export type { CreateProjectKeyResponse } from "./CreateProjectKeyResponse";
export type { DeepgramClientOptions } from "./DeepgramClientOptions";
export type { DeepgramResponse } from "./DeepgramResponse";
Expand All @@ -15,14 +15,14 @@ export type { GetProjectMemberScopesResponse } from "./GetProjectMemberScopesRes
export type { GetProjectMembersResponse } from "./GetProjectMembersResponse";
export type { GetProjectResponse } from "./GetProjectResponse";
export type { GetProjectsResponse } from "./GetProjectsResponse";
export type { GetProjectUsageFieldsOptions } from "./GetProjectUsageFieldsOptions";
export type { GetProjectUsageFieldsSchema } from "./GetProjectUsageFieldsSchema";
export type { GetProjectUsageFieldsResponse } from "./GetProjectUsageFieldsResponse";
export type {
GetProjectUsageRequestResponse,
GetProjectUsageRequestsResponse,
} from "./GetProjectUsageRequestsResponse";
export type { GetProjectUsageRequestsOptions } from "./GetProjectUsageRequestsOptions";
export type { GetProjectUsageSummaryOptions } from "./GetProjectUsageSummaryOptions";
export type { GetProjectUsageRequestsSchema } from "./GetProjectUsageRequestsSchema";
export type { GetProjectUsageSummarySchema } from "./GetProjectUsageSummarySchema";
export type { GetProjectUsageSummaryResponse } from "./GetProjectUsageSummaryResponse";
export type {
ListOnPremCredentialsResponse,
Expand All @@ -33,9 +33,9 @@ export type { LiveMetadataEvent } from "./LiveMetadataEvent";
export type { LiveTranscriptionEvent } from "./LiveTranscriptionEvent";
export type { MessageResponse } from "./MessageResponse";
export type { FileSource, PrerecordedSource, UrlSource } from "./PrerecordedSource";
export type { SendProjectInviteOptions } from "./SendProjectInviteOptions";
export type { SendProjectInviteSchema } from "./SendProjectInviteSchema";
export type { SyncPrerecordedResponse } from "./SyncPrerecordedResponse";
export type { TranscriptionOptions, PrerecordedOptions, LiveOptions } from "./TranscriptionOptions";
export type { UpdateProjectMemberScopeOptions } from "./UpdateProjectMemberScopeOptions";
export type { UpdateProjectOptions } from "./UpdateProjectOptions";
export type { TranscriptionSchema, PrerecordedSchema, LiveSchema } from "./TranscriptionSchema";
export type { UpdateProjectMemberScopeSchema } from "./UpdateProjectMemberScopeSchema";
export type { UpdateProjectSchema } from "./UpdateProjectSchema";
export type { VoidResponse } from "./VoidResponse";
4 changes: 2 additions & 2 deletions src/packages/ListenClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrerecordedClient } from "./PrerecordedClient";
import { LiveClient } from "./LiveClient";
import { LiveOptions } from "../lib/types";
import { LiveSchema } from "../lib/types";

export class ListenClient {
protected baseUrl: URL;
Expand All @@ -17,7 +17,7 @@ export class ListenClient {
return new PrerecordedClient(this.baseUrl, this.headers, this.key);
}

public live(options: LiveOptions, endpoint = "v1/listen") {
public live(options: LiveSchema, endpoint = "v1/listen") {
return new LiveClient(this.baseUrl, this.key, options, endpoint);
}
}
6 changes: 3 additions & 3 deletions src/packages/LiveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { appendSearchParams, isBrowser } from "../lib/helpers";
import WebSocket from "modern-isomorphic-ws";
import { LiveConnectionState, LiveTranscriptionEvents } from "../lib/enums";
import type {
LiveOptions,
LiveSchema,
LiveConfigOptions,
LiveMetadataEvent,
LiveTranscriptionEvent,
Expand All @@ -13,10 +13,10 @@ import { DEFAULT_HEADERS } from "../lib/constants";
export class LiveClient extends EventEmitter {
private _socket: WebSocket;

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

const transcriptionOptions: LiveOptions = { ...{}, ...options };
const transcriptionOptions: LiveSchema = { ...{}, ...options };
const url = new URL(endpoint, baseUrl);
url.protocol = url.protocol.toLowerCase().replace(/(http)(s)?/gi, "ws$2");
appendSearchParams(url.searchParams, transcriptionOptions);
Expand Down
Loading

0 comments on commit 5785006

Please sign in to comment.