Skip to content

Commit

Permalink
fix: stick with Record<string,unknown> types
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Apr 27, 2023
1 parent 024cc60 commit ca8bfab
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/// <reference types="node" />
// TypeScript Version: 3.6
import { KeyObject, PrivateKeyInput, PublicKeyInput, JsonWebKeyInput } from 'crypto'
type JsonObject = { [Key in string]?: JsonValue }
type JsonArray = JsonValue[]
type JsonPrimitive = string | number | boolean | null
type JsonValue = JsonPrimitive | JsonObject | JsonArray
export interface ProduceOptions {
assertion?: string | Buffer
audience?: string
Expand Down Expand Up @@ -32,7 +28,7 @@ export interface ConsumeOptions<TComplete extends boolean> {
now?: Date
subject?: string
}
export interface CompleteResult<T = Record<string, JsonValue | undefined>> {
export interface CompleteResult<T = Record<string, unknown>> {
footer?: Buffer
payload: T
purpose: 'local' | 'public'
Expand All @@ -49,7 +45,7 @@ export interface CompleteResultBuffer {
purpose: 'local' | 'public'
version: string
}
export interface DecodeResult<T = Record<string, JsonValue | undefined>> {
export interface DecodeResult<T = Record<string, unknown>> {
footer?: Buffer
payload?: T
purpose: 'local' | 'public'
Expand All @@ -61,7 +57,7 @@ export interface DecodeResultBuffer {
purpose: 'local' | 'public'
version: string
}
export function decode<T = Record<string, JsonValue | undefined>>(token: string): DecodeResult<T>
export function decode<T = Record<string, unknown>>(token: string): DecodeResult<T>
export namespace V1 {
function sign(
payload: Record<PropertyKey, unknown> | Buffer,
Expand All @@ -73,12 +69,12 @@ export namespace V1 {
key: KeyObject | Buffer | string,
options?: Omit<ProduceOptions, 'assertion'>,
): Promise<string>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: Omit<ConsumeOptions<false>, 'assertion'>,
): Promise<T>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: Omit<ConsumeOptions<true>, 'assertion'>,
Expand All @@ -93,12 +89,12 @@ export namespace V1 {
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: Omit<ConsumeOptionsBuffer<true>, 'assertion'>,
): Promise<CompleteResultBuffer>
function decrypt<T = Record<string, JsonValue | undefined>>(
function decrypt<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | string,
options?: Omit<ConsumeOptions<false>, 'assertion'>,
): Promise<T>
function decrypt<T = Record<string, JsonValue | undefined>>(
function decrypt<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | string,
options?: Omit<ConsumeOptions<true>, 'assertion'>,
Expand Down Expand Up @@ -130,12 +126,12 @@ export namespace V2 {
key: KeyObject | Buffer | PrivateKeyInput | JsonWebKeyInput | string,
options?: Omit<ProduceOptions, 'assertion'>,
): Promise<string>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: Omit<ConsumeOptions<false>, 'assertion'>,
): Promise<T>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: Omit<ConsumeOptions<true>, 'assertion'>,
Expand Down Expand Up @@ -170,12 +166,12 @@ export namespace V3 {
key: KeyObject | Buffer | string,
options?: ProduceOptions,
): Promise<string>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: ConsumeOptions<false>,
): Promise<T>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: ConsumeOptions<true>,
Expand All @@ -190,12 +186,12 @@ export namespace V3 {
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: ConsumeOptionsBuffer<true>,
): Promise<CompleteResultBuffer>
function decrypt<T = Record<string, JsonValue | undefined>>(
function decrypt<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | string,
options?: ConsumeOptions<false>,
): Promise<T>
function decrypt<T = Record<string, JsonValue | undefined>>(
function decrypt<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | string,
options?: ConsumeOptions<true>,
Expand Down Expand Up @@ -229,12 +225,12 @@ export namespace V4 {
key: KeyObject | Buffer | PrivateKeyInput | JsonWebKeyInput | string,
options?: ProduceOptions,
): Promise<string>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: ConsumeOptions<false>,
): Promise<T>
function verify<T = Record<string, JsonValue | undefined>>(
function verify<T = Record<string, unknown>>(
token: string,
key: KeyObject | Buffer | PublicKeyInput | JsonWebKeyInput | string,
options?: ConsumeOptions<true>,
Expand Down

0 comments on commit ca8bfab

Please sign in to comment.