diff --git a/packages/rest/__test__/index.js b/packages/rest/__test__/index.js index 70b3c3a..434ddd9 100644 --- a/packages/rest/__test__/index.js +++ b/packages/rest/__test__/index.js @@ -6,11 +6,17 @@ const manager = new REST.default( { timings: true, logger: { - debug: console.log, + header: () => '[abcdef]', + debug: (message, ...args) => { + if (!message.startsWith('[abcdef]')) + throw new Error(`Unexpected message: ${message}`); + + console.log(message, ...args); + }, trace: console.log, - kleur: null - } - } + kleur: null, + }, + }, ); manager.client.setAuth(process.env.DISCORD_TOKEN); diff --git a/packages/rest/package.json b/packages/rest/package.json index a68a9dd..b10e593 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -1,6 +1,6 @@ { "name": "@fuwa/rest", - "version": "0.1.1", + "version": "0.2.2", "description": "A simple REST client for Discord's public API", "main": "dist/index.js", "types": "typings/index.d.ts", diff --git a/packages/rest/src/RequestManager.ts b/packages/rest/src/RequestManager.ts index 8f3a923..5c1d28c 100644 --- a/packages/rest/src/RequestManager.ts +++ b/packages/rest/src/RequestManager.ts @@ -16,6 +16,7 @@ export interface RequestManagerOptions { debug?: (...args: any[]) => void; trace?: (...args: any[]) => void; kleur?: any; + header?: (() => string) | string; }; } @@ -177,21 +178,27 @@ export class RequestManager { this.offset = local - discordDate; } - #__log_header() { - return `[${this.options?.logger?.kleur?.().green('REST') ?? 'REST'}]`; - } - /** @ignore */ __log_header() { - return this.#__log_header(); + if (this.options.logger?.header) { + const header = this.options.logger.header; + + if (typeof header === 'function') { + return header(); + } else { + return header; + } + } else { + return `[${this.options.logger?.kleur?.().green('REST') ?? 'REST'}]`; + } } debug(...args: any[]) { - this.options?.logger?.debug?.(this.#__log_header(), ...args); + this.options.logger?.debug?.(this.__log_header(), ...args); } private trace(...args: any[]) { - this.options?.logger?.trace?.('[REST]', ...args); + this.options.logger?.trace?.(this.__log_header(), ...args); } } diff --git a/packages/rest/typings/RequestManager.d.ts b/packages/rest/typings/RequestManager.d.ts index 2f49f61..e6409db 100644 --- a/packages/rest/typings/RequestManager.d.ts +++ b/packages/rest/typings/RequestManager.d.ts @@ -8,10 +8,10 @@ export interface RequestManagerOptions { debug?: (...args: any[]) => void; trace?: (...args: any[]) => void; kleur?: any; + header?: (() => string) | string; }; } export declare class RequestManager { - #private; client: RESTClient; options: RequestManagerOptions; limit: number; diff --git a/yarn.lock b/yarn.lock index 1cf6e4f..90ad0fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -286,13 +286,13 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/eslint-plugin@npm:5.21.0" +"@typescript-eslint/eslint-plugin@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/eslint-plugin@npm:5.22.0" dependencies: - "@typescript-eslint/scope-manager": 5.21.0 - "@typescript-eslint/type-utils": 5.21.0 - "@typescript-eslint/utils": 5.21.0 + "@typescript-eslint/scope-manager": 5.22.0 + "@typescript-eslint/type-utils": 5.22.0 + "@typescript-eslint/utils": 5.22.0 debug: ^4.3.2 functional-red-black-tree: ^1.0.1 ignore: ^5.1.8 @@ -305,42 +305,42 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 52068319798775f320564e98b1361bbe7f8a80ece3ded35145b2cefc5530047a12c6482727eb3c4d845dcd4e4a8d8bf5898125775f99c1d197d45c47a7732813 + checksum: 3b083f7003f091c3ef7b3970dca9cfd507ab8c52a9b8a52259c630010adf765e9766f0e6fd9c901fc0e807319a4e8c003e12287b1f12a4b9eb4d7222e8d6db83 languageName: node linkType: hard -"@typescript-eslint/parser@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/parser@npm:5.21.0" +"@typescript-eslint/parser@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/parser@npm:5.22.0" dependencies: - "@typescript-eslint/scope-manager": 5.21.0 - "@typescript-eslint/types": 5.21.0 - "@typescript-eslint/typescript-estree": 5.21.0 + "@typescript-eslint/scope-manager": 5.22.0 + "@typescript-eslint/types": 5.22.0 + "@typescript-eslint/typescript-estree": 5.22.0 debug: ^4.3.2 peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 peerDependenciesMeta: typescript: optional: true - checksum: c0a4f03dccfba699c95788bef35312ec2ab7fa0dd7164916bce7762293b00f12f454d44dea2f1553d516d87a5fcc262ea3c5b7efa958cbfda7e4b9b73d67b54f + checksum: 28a7d4b73154fc97336be9a4efd5ffdc659f748232c82479909e86ed87ed8a78d23280b3aaf532ca4e735caaffac43d9576e6af2dfd11865e30a9d70c8a3f275 languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/scope-manager@npm:5.21.0" +"@typescript-eslint/scope-manager@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/scope-manager@npm:5.22.0" dependencies: - "@typescript-eslint/types": 5.21.0 - "@typescript-eslint/visitor-keys": 5.21.0 - checksum: 2bcb5947d7882f08fb8f40eea154c15152957105a3dc80bf8481212a66d35a8d2239437e095a9a7526c6c0043e9bd6bececf4f87d40da85abb2d2b69f774d805 + "@typescript-eslint/types": 5.22.0 + "@typescript-eslint/visitor-keys": 5.22.0 + checksum: ebf2ad44f4e5a4dfd55225419804f81f68056086c20f1549adbcca4236634eac3aae461e30d6cab6539ce6f42346ed6e1fbbb2710d2cc058a3283ef91a0fe174 languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/type-utils@npm:5.21.0" +"@typescript-eslint/type-utils@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/type-utils@npm:5.22.0" dependencies: - "@typescript-eslint/utils": 5.21.0 + "@typescript-eslint/utils": 5.22.0 debug: ^4.3.2 tsutils: ^3.21.0 peerDependencies: @@ -348,23 +348,23 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 09a9dbaa26c0c56aa36e0d6e119007dcbe2cc326b844892ce9389409d5a1d43951f67e0ca03fb28d4d96a09ab498f125dd3bc09f82e655c2ca7023566ad2cf5f + checksum: 7128085bfbeca3a9646a795a34730cdfeca110bc00240569f6a7b3dc0854680afa56e015715675a78198b414de869339bd6036cc33cb14903919780a60321a95 languageName: node linkType: hard -"@typescript-eslint/types@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/types@npm:5.21.0" - checksum: 1581bf79f8c9236844ca8891e26c84503b654359fbfee80d76f9f57fb90c24210687cd30f61592e7d44cacf5417c83aaa5ae8559a4a8b6ce6b6c4a163b8b86c2 +"@typescript-eslint/types@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/types@npm:5.22.0" + checksum: 74f822c5a3b96bba05229eea4ed370c4bd48b17f475c37f08d6ba708adf65c3aa026bb544f1d0308c96e043b30015e396fd53b1e8e4e9fbb6dc9c92d2ccc0a15 languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/typescript-estree@npm:5.21.0" +"@typescript-eslint/typescript-estree@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/typescript-estree@npm:5.22.0" dependencies: - "@typescript-eslint/types": 5.21.0 - "@typescript-eslint/visitor-keys": 5.21.0 + "@typescript-eslint/types": 5.22.0 + "@typescript-eslint/visitor-keys": 5.22.0 debug: ^4.3.2 globby: ^11.0.4 is-glob: ^4.0.3 @@ -373,33 +373,33 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 4f78d61be2f35775d0f2d7fc4e3bb0bfc6b84e608e96a297c948f84a7254c1b9f0062f61a1dce67a8d4eb67476a9b4a9ebd8b6412e97db76f675c03363a5a0ad + checksum: 2797a79d7d32a9a547b7f1de77a353d8e8c8519791f865f5e061bfc4918d12cdaddec51afa015f5aac5d068ef525c92bd65afc83b84dc9e52e697303acf0873a languageName: node linkType: hard -"@typescript-eslint/utils@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/utils@npm:5.21.0" +"@typescript-eslint/utils@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/utils@npm:5.22.0" dependencies: "@types/json-schema": ^7.0.9 - "@typescript-eslint/scope-manager": 5.21.0 - "@typescript-eslint/types": 5.21.0 - "@typescript-eslint/typescript-estree": 5.21.0 + "@typescript-eslint/scope-manager": 5.22.0 + "@typescript-eslint/types": 5.22.0 + "@typescript-eslint/typescript-estree": 5.22.0 eslint-scope: ^5.1.1 eslint-utils: ^3.0.0 peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - checksum: ed339a4ccb9eeb2a1132c41999d6584c15c4b7e2f0132bce613f502faa1dbbad7e206b642360392a6e2b24e294df90910141c7da0959901efcd600aedc4c4253 + checksum: 5019485e76d754a7a60c042545fd884dc666fddf9d4223ff706bbf0c275f19ea25a6b210fb5cf7ed368b019fe538fd854a925e9c6f12007d51b1731a29d95cc1 languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:5.21.0": - version: 5.21.0 - resolution: "@typescript-eslint/visitor-keys@npm:5.21.0" +"@typescript-eslint/visitor-keys@npm:5.22.0": + version: 5.22.0 + resolution: "@typescript-eslint/visitor-keys@npm:5.22.0" dependencies: - "@typescript-eslint/types": 5.21.0 + "@typescript-eslint/types": 5.22.0 eslint-visitor-keys: ^3.0.0 - checksum: 328b18faa61872160f3e5faacb5b68022bdabd04b5414f115133245a4a1ecfb5762c67fd645ab3253005480bd25a38598f57fdc2ff2b01d830ac68b37d3d06a5 + checksum: d30dfa98dcce75da49a6a204a0132d42e63228c35681cb9b3643e47a0a24a633e259832d48d101265bd85b8eb5a9f2b4858f9447646c1d3df6a2ac54258dfe8f languageName: node linkType: hard @@ -1646,8 +1646,8 @@ __metadata: "@splatterxl/tsconfig": 1.1.1 "@types/node": 17.0.31 "@types/ws": 8.5.3 - "@typescript-eslint/eslint-plugin": 5.21.0 - "@typescript-eslint/parser": 5.21.0 + "@typescript-eslint/eslint-plugin": 5.22.0 + "@typescript-eslint/parser": 5.22.0 cz-conventional-changelog: 3.3.0 discord-api-types: 0.32.0 eslint: 8.14.0