From 0caeb9c81db8b3c0b894d8005ac36ce00f841047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 5 Jun 2023 12:56:33 +0200 Subject: [PATCH] chore: add `debug` --- tools/upend_js/api.ts | 39 +++++++++++++++++++++++++++++-------- tools/upend_js/package.json | 2 ++ tools/upend_js/yarn.lock | 30 ++++++++++++++++++++++++++++ webui/package.json | 2 ++ webui/src/lib/entity.ts | 4 +++- webui/yarn.lock | 23 ++++++++++++++++++++-- 6 files changed, 89 insertions(+), 11 deletions(-) diff --git a/tools/upend_js/api.ts b/tools/upend_js/api.ts index caac736..2e62013 100644 --- a/tools/upend_js/api.ts +++ b/tools/upend_js/api.ts @@ -12,6 +12,8 @@ import type { StoreInfo, VaultInfo, } from "./types"; +import debug from "debug"; +const dbg = debug("upend:api"); export class UpEndApi { private instanceUrl = ""; @@ -32,6 +34,7 @@ export class UpEndApi { } public async fetchEntity(address: string): Promise { + dbg("Fetching Entity %s", address); const entityFetch = await fetch(`${this.apiUrl}/obj/${address}`); const entityResult = (await entityFetch.json()) as EntityListing; const entityListing = new UpListing(entityResult.entries); @@ -39,6 +42,7 @@ export class UpEndApi { } public async fetchEntry(address: string) { + dbg("Fetching entry %s", address); const response = await fetch(`${this.apiUrl}/raw/${address}`); const data = await response.json(); const listing = new UpListing({ address: data }); @@ -49,7 +53,7 @@ export class UpEndApi { const cacheResult = this.queryOnceLRU.get(query); if (!cacheResult) { if (!this.inFlightRequests[query]) { - console.debug(`Querying: ${query}`); + dbg(`Querying: ${query}`); this.inFlightRequests[query] = new Promise((resolve, reject) => { fetch(`${this.apiUrl}/query`, { method: "POST", @@ -63,16 +67,17 @@ export class UpEndApi { .catch((err) => reject(err)); }); } else { - console.debug(`Chaining request for ${query}...`); + dbg(`Chaining request for ${query}...`); } return await (this.inFlightRequests[query] as Promise); // TODO? } else { - console.debug(`Returning cached: ${query}`); + dbg(`Returning cached: ${query}`); return cacheResult; } } public async putEntry(input: PutInput): Promise { + dbg("Putting %O", input); const response = await fetch(`${this.apiUrl}/obj`, { method: "PUT", headers: { "Content-Type": "application/json" }, @@ -87,6 +92,7 @@ export class UpEndApi { attribute: string, value: IValue ): Promise
{ + dbg("Putting %s = %o for %s", attribute, value, entity); const response = await fetch(`${this.apiUrl}/obj/${entity}/${attribute}`, { method: "PUT", headers: { "Content-Type": "application/json" }, @@ -97,6 +103,7 @@ export class UpEndApi { } public async putBlob(fileOrUrl: File | URL): Promise { + dbg("Putting Blob: %O", fileOrUrl); const formData = new FormData(); if (fileOrUrl instanceof File) { formData.append(fileOrUrl.name, fileOrUrl); @@ -117,26 +124,33 @@ export class UpEndApi { } public async deleteEntry(address: Address): Promise { + dbg("Deleting entry %s", address); await fetch(`${this.apiUrl}/obj/${address}`, { method: "DELETE" }); } public async getRaw(address: Address, preview = false) { + dbg("Getting %s raw (preview = %s)", address, preview); return await fetch( `${this.apiUrl}/${preview ? "thumb" : "raw"}/${address}` ); } public async refreshVault() { + dbg("Triggering vault refresh"); return await fetch(`${this.apiUrl}/refresh`, { method: "POST" }); } public async nativeOpen(address: Address) { + dbg("Opening %s natively", address); return fetch(`${this.apiUrl}/raw/${address}?native=1`); } public async fetchRoots(): Promise { + dbg("Fetching hierarchical roots..."); const response = await fetch(`${this.apiUrl}/hier_roots`); - return await response.json(); + const roots = await response.json(); + dbg("Hierarchical roots: %O", roots); + return roots; } public async fetchJobs(): Promise { @@ -145,18 +159,25 @@ export class UpEndApi { } public async fetchAllAttributes(): Promise { + dbg("Fetching all attributes..."); const response = await fetch(`${this.apiUrl}/all/attributes`); - return await response.json(); + const result = await response.json(); + dbg("All attributes: %O", result); + return await result; } public async fetchInfo(): Promise { const response = await fetch(`${this.apiUrl}/info`); - return await response.json(); + const result = await response.json(); + dbg("Vault info: %O", result); + return result; } public async fetchStoreInfo(): Promise<{ [key: string]: StoreInfo }> { const response = await fetch(`${this.apiUrl}/store`); - return await response.json(); + const result = await response.json(); + dbg("Store info: %O"); + return await result; } public async getAddress( @@ -176,6 +197,8 @@ export class UpEndApi { } else { throw new Error("Input cannot be empty."); } - return await response.json(); + const result = await response.json(); + dbg("Address for %o = %s", input, result); + return result; } } diff --git a/tools/upend_js/package.json b/tools/upend_js/package.json index 9db08f8..21ccbcc 100644 --- a/tools/upend_js/package.json +++ b/tools/upend_js/package.json @@ -10,6 +10,7 @@ "author": "Tomáš Mládek ", "license": "MIT", "devDependencies": { + "@types/debug": "^4.1.8", "@typescript-eslint/eslint-plugin": "latest", "@typescript-eslint/parser": "latest", "ava": "^3.15.0", @@ -18,6 +19,7 @@ }, "packageManager": "yarn@3.1.1", "dependencies": { + "debug": "^4.3.4", "lru-cache": "^7.0.0" } } diff --git a/tools/upend_js/yarn.lock b/tools/upend_js/yarn.lock index aa6c12e..abdbaab 100644 --- a/tools/upend_js/yarn.lock +++ b/tools/upend_js/yarn.lock @@ -153,6 +153,15 @@ __metadata: languageName: node linkType: hard +"@types/debug@npm:^4.1.8": + version: 4.1.8 + resolution: "@types/debug@npm:4.1.8" + dependencies: + "@types/ms": "*" + checksum: a9a9bb40a199e9724aa944e139a7659173a9b274798ea7efbc277cb084bc37d32fc4c00877c3496fac4fed70a23243d284adb75c00b5fdabb38a22154d18e5df + languageName: node + linkType: hard + "@types/json-schema@npm:^7.0.9": version: 7.0.9 resolution: "@types/json-schema@npm:7.0.9" @@ -169,6 +178,13 @@ __metadata: languageName: node linkType: hard +"@types/ms@npm:*": + version: 0.7.31 + resolution: "@types/ms@npm:0.7.31" + checksum: daadd354aedde024cce6f5aa873fefe7b71b22cd0e28632a69e8b677aeb48ae8caa1c60e5919bb781df040d116b01cb4316335167a3fc0ef6a63fa3614c0f6da + languageName: node + linkType: hard + "@types/node@npm:*": version: 17.0.0 resolution: "@types/node@npm:17.0.0" @@ -1037,6 +1053,18 @@ __metadata: languageName: node linkType: hard +"debug@npm:^4.3.4": + version: 4.3.4 + resolution: "debug@npm:4.3.4" + dependencies: + ms: 2.1.2 + peerDependenciesMeta: + supports-color: + optional: true + checksum: 3dbad3f94ea64f34431a9cbf0bafb61853eda57bff2880036153438f50fb5a84f27683ba0d8e5426bf41a8c6ff03879488120cf5b3a761e77953169c0600a708 + languageName: node + linkType: hard + "decompress-response@npm:^3.3.0": version: 3.3.0 resolution: "decompress-response@npm:3.3.0" @@ -3596,9 +3624,11 @@ __metadata: version: 0.0.0-use.local resolution: "upend@workspace:." dependencies: + "@types/debug": ^4.1.8 "@typescript-eslint/eslint-plugin": latest "@typescript-eslint/parser": latest ava: ^3.15.0 + debug: ^4.3.4 eslint: ^8.7.0 lru-cache: ^7.0.0 typescript: ^4.4.4 diff --git a/webui/package.json b/webui/package.json index 496dba1..7cf4acb 100644 --- a/webui/package.json +++ b/webui/package.json @@ -26,6 +26,7 @@ "@sveltejs/vite-plugin-svelte": "^1.0.1", "@tsconfig/svelte": "^3.0.0", "@types/d3": "^7.4.0", + "@types/debug": "^4.1.8", "@types/dompurify": "^2.3.3", "@types/lodash": "^4.14.182", "@types/lru-cache": "^7.10.10", @@ -55,6 +56,7 @@ "boxicons": "^2.1.4", "d3": "^7.8.0", "date-fns": "^2.29.3", + "debug": "^4.3.4", "dompurify": "^2.4.1", "filesize": "^8.0.6", "history": "^5.3.0", diff --git a/webui/src/lib/entity.ts b/webui/src/lib/entity.ts index 3e8dfed..5c20b93 100644 --- a/webui/src/lib/entity.ts +++ b/webui/src/lib/entity.ts @@ -4,6 +4,8 @@ import { UpListing, UpObject } from "upend"; import type { ListingResult, EntityListing, EntityInfo } from "upend/types"; import { useSWR } from "../util/fetch"; import api from "./api"; +import debug from "debug"; +const dbg = debug("upend:lib"); export function useEntity(address: string) { const { data, error, revalidate } = useSWR( @@ -35,7 +37,7 @@ export function useEntity(address: string) { } export function query(query: string) { - console.debug(`Querying: ${query}`); + dbg(`Querying: ${query}`); const { data, error, revalidate } = useSWR( `${api.apiUrl}/query`, { method: "POST", body: query } diff --git a/webui/yarn.lock b/webui/yarn.lock index 19149dc..a847e23 100644 --- a/webui/yarn.lock +++ b/webui/yarn.lock @@ -3663,6 +3663,15 @@ __metadata: languageName: node linkType: hard +"@types/debug@npm:^4.1.8": + version: 4.1.8 + resolution: "@types/debug@npm:4.1.8" + dependencies: + "@types/ms": "*" + checksum: a9a9bb40a199e9724aa944e139a7659173a9b274798ea7efbc277cb084bc37d32fc4c00877c3496fac4fed70a23243d284adb75c00b5fdabb38a22154d18e5df + languageName: node + linkType: hard + "@types/detect-port@npm:^1.3.0": version: 1.3.2 resolution: "@types/detect-port@npm:1.3.2" @@ -3846,6 +3855,13 @@ __metadata: languageName: node linkType: hard +"@types/ms@npm:*": + version: 0.7.31 + resolution: "@types/ms@npm:0.7.31" + checksum: daadd354aedde024cce6f5aa873fefe7b71b22cd0e28632a69e8b677aeb48ae8caa1c60e5919bb781df040d116b01cb4316335167a3fc0ef6a63fa3614c0f6da + languageName: node + linkType: hard + "@types/node-fetch@npm:^2.5.7": version: 2.6.2 resolution: "@types/node-fetch@npm:2.6.2" @@ -12519,6 +12535,7 @@ __metadata: "@sveltejs/vite-plugin-svelte": ^1.0.1 "@tsconfig/svelte": ^3.0.0 "@types/d3": ^7.4.0 + "@types/debug": ^4.1.8 "@types/dompurify": ^2.3.3 "@types/lodash": ^4.14.182 "@types/lru-cache": ^7.10.10 @@ -12530,6 +12547,7 @@ __metadata: boxicons: ^2.1.4 d3: ^7.8.0 date-fns: ^2.29.3 + debug: ^4.3.4 dompurify: ^2.4.1 eslint: ^8.30.0 eslint-plugin-storybook: ^0.6.10 @@ -12567,10 +12585,11 @@ __metadata: "upend@file:../tools/upend_js::locator=upend-kestrel%40workspace%3A.": version: 0.0.1 - resolution: "upend@file:../tools/upend_js#../tools/upend_js::hash=ea2989&locator=upend-kestrel%40workspace%3A." + resolution: "upend@file:../tools/upend_js#../tools/upend_js::hash=67912a&locator=upend-kestrel%40workspace%3A." dependencies: + debug: ^4.3.4 lru-cache: ^7.0.0 - checksum: 8120076b2d6c66fa8c469e514c96cc168608c8244e1e529483aab05c6fc87ad886b10c023959070828c0d08753741c3757e694c7ccc1b8df3bbf2f24b709ee1a + checksum: e89edf5fc49b52de1f6bcc8574c5a5c9d6decfb0150f03355d54d2fa8f507962c0a5eaf71c49a23c60a3e088c218f39eb83d5a7ec06c891117cbc1dcdb1445b6 languageName: node linkType: hard