Skip to content

Commit

Permalink
Fix linting and building
Browse files Browse the repository at this point in the history
  • Loading branch information
duncangrubbs committed May 1, 2024
1 parent 639a7dd commit 6d729de
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/examples/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ to Express.js
api.use(toJson)
api.use(hydrateDates)

function sampleMiddleware(data: ApiResponse) {
async function sampleMiddleware(data: ApiResponse) {
return data
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OzzzyAuth implements AuthProvider {
this.header = header
}

getHeaders(): Array<Array<string>> {
getHeaders(): [string, string][] {
switch (this.type) {
case AuthTypes.Bearer:
return [[this.header!, `${this.type} ${this.token}`]]
Expand Down
13 changes: 5 additions & 8 deletions src/lib/http-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ export class HttpApi {
* @returns The response, after all middleware has been applied
* @example await api.get('/users/all')
*/
get<K = unknown>(
url: URL,
...middleware: Middleware<K, unknown>[]
): Promise<K> {
get<K = unknown>(url: URL, ...middleware: Middleware[]): Promise<K> {
const requestMiddleware = [...this.middleware, ...middleware]
const options = { method: RestMethods.GET }
return this._fetch<K>(url, options, requestMiddleware)
Expand All @@ -88,7 +85,7 @@ export class HttpApi {
put<K = unknown>(
url: URL,
payload: object,
...middleware: Middleware<K, unknown>[]
...middleware: Middleware[]
): Promise<K> {
const requestMiddleware = [...this.middleware, ...middleware]
const options = {
Expand All @@ -109,7 +106,7 @@ export class HttpApi {
post<K = unknown>(
url: URL,
payload: object,
...middleware: Middleware<K, unknown>[]
...middleware: Middleware[]
): Promise<K> {
const requestMiddleware = [...this.middleware, ...middleware]
const options = {
Expand All @@ -130,7 +127,7 @@ export class HttpApi {
delete<K = unknown>(
url: URL,
payload: object,
...middleware: Middleware<K, unknown>[]
...middleware: Middleware[]
): Promise<K> {
const requestMiddleware = [...this.middleware, ...middleware]
const options = {
Expand Down Expand Up @@ -171,7 +168,7 @@ export class HttpApi {
private async _fetch<K>(
url: URL,
options: object,
middleware: Middleware<K, unknown>[],
middleware: Middleware[],
): Promise<K> {
let combinedHeaders = [...this.headers]
if (this.auth !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/dates.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const dateFormat = /^-?\d+-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
* If there is a match, it returns the value as a date,
* if not, it returns the value as is
*/
function dateReviver(_key: string, value: any) {
function dateReviver(_key: string, value: unknown) {
if (typeof value === 'string' && dateFormat.test(value)) {
return new Date(value)
}
Expand All @@ -29,7 +29,7 @@ function dateReviver(_key: string, value: any) {
* Note that this data is expected to be a Javascript object
* @returns Hydrated data object
*/
export function hydrateDates(data: object): Promise<any> {
export function hydrateDates(data: object): Promise<object> {
const dataAsString = JSON.stringify(data)
const hydratedData = JSON.parse(dataAsString, dateReviver)

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/json.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @param next Next middleware handler function
* @returns Call to next middleware handler
*/
export function toJson(response: Response): Promise<any> {
export function toJson(response: Response): Promise<object> {
return response.json()
}
3 changes: 2 additions & 1 deletion src/shared-types/middleware.type.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type Middleware<K = unknown, V = unknown> = (data: K) => Promise<V>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Middleware<K = any, V = any> = (data: K) => Promise<V>

0 comments on commit 6d729de

Please sign in to comment.