Skip to content

Commit

Permalink
refactor(types): mark always lowercased values and keys as Lowercase<…
Browse files Browse the repository at this point in the history
…string>
  • Loading branch information
panva committed Jan 3, 2024
1 parent c28efda commit 89e7a77
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/interfaces/ClientCredentialsGrantResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ___

### token\_type

`Readonly` **token\_type**: `string`
`Readonly` **token\_type**: ``"dpop"`` \| [`Lowercase`]( https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#lowercasestringtype )\<`string`\> \| ``"bearer"``

NOTE: because the value is case insensitive it is always returned lowercased

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/OAuth2TokenEndpointResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ___

### token\_type

`Readonly` **token\_type**: `string`
`Readonly` **token\_type**: ``"dpop"`` \| [`Lowercase`]( https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#lowercasestringtype )\<`string`\> \| ``"bearer"``

NOTE: because the value is case insensitive it is always returned lowercased

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/OpenIDTokenEndpointResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ___

### token\_type

`Readonly` **token\_type**: `string`
`Readonly` **token\_type**: ``"dpop"`` \| [`Lowercase`]( https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#lowercasestringtype )\<`string`\> \| ``"bearer"``

NOTE: because the value is case insensitive it is always returned lowercased

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/TokenEndpointResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ___

### token\_type

`Readonly` **token\_type**: `string`
`Readonly` **token\_type**: ``"dpop"`` \| [`Lowercase`]( https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#lowercasestringtype )\<`string`\> \| ``"bearer"``

NOTE: because the value is case insensitive it is always returned lowercased

Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/WWWAuthenticateChallenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ ___

### scheme

`Readonly` **scheme**: `string`
`Readonly` **scheme**: [`Lowercase`]( https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#lowercasestringtype )\<`string`\>

NOTE: because the value is case insensitive it is always returned lowercased
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,12 +1499,12 @@ export interface WWWAuthenticateChallengeParameters {
readonly scope?: string

/** NOTE: because the parameter names are case insensitive they are always returned lowercased */
readonly [parameter: string]: string | undefined
readonly [parameter: Lowercase<string>]: string | undefined
}

export interface WWWAuthenticateChallenge {
/** NOTE: because the value is case insensitive it is always returned lowercased */
readonly scheme: string
readonly scheme: Lowercase<string>
readonly parameters: WWWAuthenticateChallengeParameters
}

Expand All @@ -1522,7 +1522,7 @@ const SCHEMES_REGEXP = /(?:^|, ?)([0-9a-zA-Z!#$%&'*+\-.^_`|~]+)(?=$|[ ,])/g
function wwwAuth(scheme: string, params: string): WWWAuthenticateChallenge {
const arr = params.split(SPLIT_REGEXP).slice(1)
if (!arr.length) {
return { scheme: scheme.toLowerCase(), parameters: {} }
return { scheme: <Lowercase<string>>scheme.toLowerCase(), parameters: {} }
}
arr[arr.length - 1] = arr[arr.length - 1].replace(/,$/, '')
const parameters: WWWAuthenticateChallenge['parameters'] = {}
Expand All @@ -1533,13 +1533,13 @@ function wwwAuth(scheme: string, params: string): WWWAuthenticateChallenge {
arr[idx] += arr[i]
}
}
const key = arr[idx - 1].replace(/^(?:, ?)|=$/g, '').toLowerCase()
const key = <Lowercase<string>>arr[idx - 1].replace(/^(?:, ?)|=$/g, '').toLowerCase()
// @ts-expect-error
parameters[key] = unquote(arr[idx])
}

return {
scheme: scheme.toLowerCase(),
scheme: <Lowercase<string>>scheme.toLowerCase(),
parameters,
}
}
Expand Down Expand Up @@ -2444,7 +2444,7 @@ export interface TokenEndpointResponse {
readonly refresh_token?: string
readonly scope?: string
/** NOTE: because the value is case insensitive it is always returned lowercased */
readonly token_type: string
readonly token_type: 'bearer' | 'dpop' | Lowercase<string>

readonly [parameter: string]: JsonValue | undefined
}
Expand All @@ -2456,7 +2456,7 @@ export interface OpenIDTokenEndpointResponse {
readonly refresh_token?: string
readonly scope?: string
/** NOTE: because the value is case insensitive it is always returned lowercased */
readonly token_type: string
readonly token_type: 'bearer' | 'dpop' | Lowercase<string>

readonly [parameter: string]: JsonValue | undefined
}
Expand All @@ -2468,7 +2468,7 @@ export interface OAuth2TokenEndpointResponse {
readonly refresh_token?: string
readonly scope?: string
/** NOTE: because the value is case insensitive it is always returned lowercased */
readonly token_type: string
readonly token_type: 'bearer' | 'dpop' | Lowercase<string>

readonly [parameter: string]: JsonValue | undefined
}
Expand All @@ -2478,7 +2478,7 @@ export interface ClientCredentialsGrantResponse {
readonly expires_in?: number
readonly scope?: string
/** NOTE: because the value is case insensitive it is always returned lowercased */
readonly token_type: string
readonly token_type: 'bearer' | 'dpop' | Lowercase<string>

readonly [parameter: string]: JsonValue | undefined
}
Expand Down

0 comments on commit 89e7a77

Please sign in to comment.