Skip to content

Commit

Permalink
feat(openapi-client): inject logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Pablo Vargas Martinez authored and Juan Pablo Vargas Martinez committed Dec 12, 2024
1 parent c075db3 commit 6e28cd1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/openapi-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@ import {
type ClientOptions,
type RequestArgs,
type RequestOptions,
Verb,
fromAxiosError,
} from '@sebspark/openapi-core'
import { retry } from '@sebspark/retry'
import axios, { type AxiosError, type AxiosHeaders } from 'axios'
import type { Logger } from 'winston'
import { paramsSerializer } from './paramsSerializer'

export const TypedClient = <C extends Partial<BaseClient>>(
baseURL: string,
globalOptions?: ClientOptions
globalOptions?: ClientOptions,
logger?: Logger
): C => {
if (logger) {
axios.interceptors.request.use((request) => {
logger.debug(JSON.stringify(request, null, 2))
return request
})

axios.interceptors.response.use((response) => {
logger.debug(JSON.stringify(response, null, 2))
return response
})
}
const client: BaseClient = {
get: (url, args, opts) =>
callServer(mergeArgs(baseURL, url, 'get', args, opts, globalOptions)),
Expand Down
14 changes: 14 additions & 0 deletions packages/promise-cache/src/serializerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ function deserializePrimitives(serialized: Serialized): Serializable {
}
}

export default function isPlainObject(value: Serialized) {
if (typeof value !== 'object' || value === null) {
return false
}

const prototype = Object.getPrototypeOf(value)
return (
(prototype === null ||
prototype === Object.prototype ||
Object.getPrototypeOf(prototype) === null) &&
!(Symbol.toStringTag in value) &&
!(Symbol.iterator in value)
)
}
/**
* Deserialize a value from a string.
* @param serialized string to deserialize
Expand Down

0 comments on commit 6e28cd1

Please sign in to comment.