Skip to content

Commit

Permalink
Import assert from jslib-media and remove 3rd party assert
Browse files Browse the repository at this point in the history
  • Loading branch information
nandito committed Nov 6, 2023
1 parent b9804d6 commit 197b4de
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 16 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"dependencies": {
"@swc/helpers": "^0.3.13",
"@whereby/jslib-media": "whereby/jslib-media.git#1.4.1",
"assert": "^2.0.0",
"axios": "^1.2.3",
"btoa": "^1.2.1",
"events": "^3.3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/api/ApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import nodeBtoa from "btoa";
import assert from "@whereby/jslib-media/src/utils/assert";
import HttpClient, { HttpClientRequestConfig } from "./HttpClient";
import MultipartHttpClient from "./MultipartHttpClient";
import { assertString } from "./parameterAssertUtils";
Expand Down Expand Up @@ -92,7 +92,7 @@ export default class ApiClient {
*/
request(url: string, options: HttpClientRequestConfig): Promise<Response> {
assertString(url, "url");
assert.equal(url[0], "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(options, "options are required");

return this.authenticatedHttpClient.request(url, options);
Expand All @@ -103,7 +103,7 @@ export default class ApiClient {
*/
requestMultipart(url: string, options: HttpClientRequestConfig): Promise<Response> {
assertString(url, "url");
assert.equal(url[0], "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(options, "options are required");

return this.authenticatedFormDataHttpClient.request(url, options);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/HttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
import Response, { ErrorResponseObject } from "./Response";
import { assertString } from "./parameterAssertUtils";
Expand Down Expand Up @@ -50,7 +50,7 @@ export default class HttpClient implements IHttpClient {
*/
request(url: string, options: HttpClientRequestConfig): Promise<Response> {
assertString(url, "url");
assert.equal(url[0], "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(options, "options are required");

return this._requestAxios(url, options)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/MultipartHttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";
import { HttpClientRequestConfig, IHttpClient } from "./HttpClient";
import Response from "./Response";

Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/OrganizationApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "@whereby/jslib-media/src/utils/assert";
import ApiClient from "./ApiClient";
import assert from "assert";
import { assertString } from "./parameterAssertUtils";
import { HttpClientRequestConfig } from "./HttpClient";
import Response from "./Response";
Expand Down Expand Up @@ -41,7 +41,7 @@ export default class OrganizationApiClient {
options: HttpClientRequestConfig
): Promise<Response> {
assertString(url, "url");
assert.equal(url[0], "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(url[0] === "/", 'url<String> only accepts relative URLs beginning with "/".');
assert.ok(options, "options are required");
return this._fetchOrganization().then((organization) => {
if (!organization) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/models/Room.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";

export default class Room {
public readonly isLocked: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/organizationService/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";
import Organization, { OrganizationPreferences } from "../models/Organization";
import {
assertInstanceOf,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/parameterAssertUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";

/**
* Asserts that value is truthy.
Expand Down Expand Up @@ -65,7 +65,7 @@ export function assertInstanceOf<T>(value: unknown, type: new (any: unknown) =>
*/
export function assertRoomName(roomName: unknown, parameterName = "roomName"): string {
assertString(roomName, parameterName);
assert.equal(typeof roomName === "string" && roomName[0], "/", `${parameterName} must begin with a '/'`);
assert.ok(typeof roomName === "string" && roomName[0] === "/", `${parameterName} must begin with a '/'`);
return roomName as string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/test/extractUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
nullOrTransform,
Transformer,
} from "../extractUtils";
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";
import { Json } from "../Response";
import { assertString } from "../parameterAssertUtils";
type User = { name: string; eyeColor: string | null; age: number; dob: Date };
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/test/parameterAssertUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";
import {
assertBoolean,
assertRoomName,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "@whereby/jslib-media/src/utils/assert";

interface Options {
delay?: number;
Expand Down
10 changes: 10 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ declare module "@whereby/jslib-media/src/webrtc/RtcManager" {
}
}

declare const assert: {
(value: unknown, message?: string | Error): asserts value;
ok(value: unknown, message?: string | Error): asserts value;
notEqual<T>(actual: T, expected: T, message: string): void;
};

declare module "@whereby/jslib-media/src/utils/assert" {
export = assert;
}

declare module "@whereby/jslib-media/src/utils/urls" {
export function fromLocation({ host }: { host: string }): { subdomain: string };
}
Expand Down

0 comments on commit 197b4de

Please sign in to comment.