UNPKG

@codex-storage/sdk-js

Version:

Codex SDK to interact with the Codex decentralized storage network.

1 lines 3.74 kB
{"version":3,"sources":["../src/debug/types.ts","../src/debug/debug.ts"],"names":["v2"],"mappings":";;;;;AASO,IAAM,qBAAuB,CAAS,CAAA,QAAA,CAAA;AAAA,EAC3C,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAC;ACGM,IAAM,aAAN,MAAiB;AAAA,EACb,GAAA;AAAA,EACA,OAAkB,EAAC;AAAA,EAE5B,WAAA,CAAY,KAAa,OAA6B,EAAA;AACpD,IAAA,IAAA,CAAK,GAAM,GAAA,GAAA;AAEX,IAAA,IAAI,mCAAS,IAAM,EAAA;AACjB,MAAA,IAAA,CAAK,OAAO,OAAQ,CAAA,IAAA;AAAA;AACtB;AACF;AAAA;AAAA;AAAA,EAKA,MAAM,YAAY,KAAkD,EAAA;AAClE,IAAM,MAAA,MAAA,GAAWA,CAAU,CAAA,SAAA,CAAA,kBAAA,EAAoB,KAAK,CAAA;AAEpD,IAAI,IAAA,CAAC,OAAO,OAAS,EAAA;AACnB,MAAA,OAAO,QAAQ,OAAQ,CAAA;AAAA,QACrB,KAAO,EAAA,IAAA;AAAA,QACP,IAAA,EAAM,IAAI,UAAA,CAAW,2BAA6B,EAAA;AAAA,UAChD,MAAA,EAAQ,qBAAsB,CAAA,MAAA,CAAO,MAAM;AAAA,SAC5C;AAAA,OACF,CAAA;AAAA;AAGH,IAAA,MAAM,MACJ,IAAK,CAAA,GAAA,GACL,GAAI,CAAA,MAAA,CAAO,SACX,mCACA,GAAA,KAAA;AAEF,IAAO,OAAA,KAAA,CAAM,SAAS,GAAK,EAAA;AAAA,MACzB,MAAQ,EAAA,MAAA;AAAA,MACR,OAAS,EAAA,gBAAA,CAAiB,KAAM,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,MACzC,IAAM,EAAA;AAAA,KACP,CAAA;AAAA;AACH;AAAA;AAAA;AAAA,EAKA,IAA2C,GAAA;AACzC,IAAA,MAAM,GAAM,GAAA,IAAA,CAAK,GAAM,GAAA,GAAA,CAAI,OAAO,MAAS,GAAA,CAAA,WAAA,CAAA;AAE3C,IAAO,OAAA,KAAA,CAAM,SAA4B,GAAK,EAAA;AAAA,MAC5C,MAAQ,EAAA,KAAA;AAAA,MACR,OAAS,EAAA,gBAAA,CAAiB,KAAM,CAAA,IAAA,CAAK,IAAI;AAAA,KAC1C,CAAA;AAAA;AAEL","file":"chunk-OUB34QMD.mjs","sourcesContent":["import * as v from \"valibot\";\nimport type { paths } from \"../openapi\";\n\nexport type CodexLogLevelResponse =\n paths[\"/debug/chronicles/loglevel\"][\"post\"][\"responses\"][200][\"content\"];\n\nexport type CodexLogLevel =\n paths[\"/debug/chronicles/loglevel\"][\"post\"][\"parameters\"][\"query\"][\"level\"];\n\nexport const CodexLogLevelInput = v.picklist([\n \"TRACE\",\n \"DEBUG\",\n \"INFO\",\n \"NOTICE\",\n \"WARN\",\n \"ERROR\",\n \"FATAL\",\n]);\n\nexport type CodexInfoResponse =\n paths[\"/debug/info\"][\"get\"][\"responses\"][200][\"content\"][\"application/json\"];\n\nexport type CodexDebugInfo = CodexInfoResponse;\n","import { Api } from \"../api/config\";\nimport { CodexError, CodexValibotIssuesMap } from \"../errors/errors\";\nimport {\n Fetch,\n FetchAuthBuilder,\n type FetchAuth,\n} from \"../fetch-safe/fetch-safe\";\nimport type { SafeValue } from \"../values/values\";\nimport {\n CodexLogLevelInput,\n type CodexDebugInfo,\n type CodexInfoResponse,\n type CodexLogLevel,\n} from \"./types\";\nimport * as v from \"valibot\";\n\ntype CodexDebugOptions = {\n auth?: FetchAuth;\n};\n\nexport class CodexDebug {\n readonly url: string;\n readonly auth: FetchAuth = {};\n\n constructor(url: string, options?: CodexDebugOptions) {\n this.url = url;\n\n if (options?.auth) {\n this.auth = options.auth;\n }\n }\n\n /**\n * Set log level at run time\n */\n async setLogLevel(level: CodexLogLevel): Promise<SafeValue<string>> {\n const result = v.safeParse(CodexLogLevelInput, level);\n\n if (!result.success) {\n return Promise.resolve({\n error: true,\n data: new CodexError(\"Cannot validate the input\", {\n errors: CodexValibotIssuesMap(result.issues),\n }),\n });\n }\n\n const url =\n this.url +\n Api.config.prefix +\n \"/debug/chronicles/loglevel?level=\" +\n level;\n\n return Fetch.safeText(url, {\n method: \"POST\",\n headers: FetchAuthBuilder.build(this.auth),\n body: \"\",\n });\n }\n\n /**\n * Gets node information\n */\n info(): Promise<SafeValue<CodexDebugInfo>> {\n const url = this.url + Api.config.prefix + `/debug/info`;\n\n return Fetch.safeJson<CodexInfoResponse>(url, {\n method: \"GET\",\n headers: FetchAuthBuilder.build(this.auth),\n });\n }\n}\n"]}