@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
1 lines • 4.09 kB
Source Map (JSON)
{"version":3,"file":"assert-logger-shape.cjs","sources":["../../../src/logger/assert-logger-shape.ts"],"sourcesContent":["import type { LoggerInterface } from '../types/logger'\n\n/**\n * Every logging method declared by {@link LoggerInterface}. Kept explicit rather\n * than derived, so adding a level to the interface surfaces here as a compile\n * error instead of silently going unchecked.\n */\nconst LOG_METHODS = [\n 'log',\n 'debug',\n 'info',\n 'notice',\n 'warning',\n 'error',\n 'critical',\n 'alert',\n 'emergency'\n] as const satisfies readonly (keyof LoggerInterface)[]\n\n/**\n * Warn if a logger handed to `setLogger(...)` does not look like it returns\n * promises.\n *\n * {@link LoggerInterface} declares every method as `Promise<void>`, and the SDK\n * relies on that: it calls the logger as fire-and-forget and appends\n * `.catch(() => {})` to say it does not care about the outcome. Against a logger\n * whose methods return `undefined` — easy to write in plain JavaScript, or in\n * TypeScript behind an `as any` — that `.catch` is a `TypeError`, at every\n * logging callsite in the SDK. A logging mistake would then break the operation\n * being logged, which is the failure this whole area exists to prevent (#346).\n *\n * TypeScript already rejects a non-conforming implementation at compile time, so\n * this only catches what the compiler cannot see. It warns rather than throws:\n * refusing to install the logger would itself be a logging concern breaking the\n * caller, and the shape is only *probably* wrong — a method could legitimately\n * be absent from a partial stub the caller never triggers.\n *\n * The check is shallow on purpose: it verifies each method exists and is\n * callable, and does not invoke anything. Calling the methods to inspect their\n * return value would emit spurious log records as a side effect of installation.\n *\n * A warning is as far as the SDK goes here, by decision rather than by omission\n * (#346). It does **not** wrap the installed logger to isolate it the way\n * `Logger.log()` isolates its handlers, so an implementation that throws\n * synchronously — before the promise the callsite's `.catch(() => {})` expects —\n * still reaches the caller. Wrapping would put the SDK in charge of code it\n * does not own, at all ~94 callsites, to guard a case the compiler already\n * rejects; the contract is that your methods return promises, and this check is\n * the reminder, not the enforcement.\n *\n * @param logger The logger about to be installed.\n * @param source Where it is being installed, used in the warning text.\n */\nexport function warnOnNonPromiseLogger(logger: LoggerInterface, source: string): void {\n if (logger === null || typeof logger !== 'object') {\n console.warn(\n `[b24jssdk] ${source}: the value passed to setLogger() is not an object. `\n + `Expected an implementation of LoggerInterface.`\n )\n return\n }\n\n const missing = LOG_METHODS.filter(name => typeof logger[name] !== 'function')\n if (missing.length > 0) {\n console.warn(\n `[b24jssdk] ${source}: the logger passed to setLogger() is missing `\n + `${missing.join(', ')}. LoggerInterface declares every level as `\n + `Promise<void>; the SDK calls them fire-and-forget, so a missing or `\n + `non-promise method raises a TypeError at the callsite.`\n )\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAOA,MAAM,WAAA,GAAc;AAAA,EAClB,KAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAA;AAoCO,SAAS,sBAAA,CAAuB,QAAyB,MAAA,EAAsB;AACpF,EAAA,IAAI,MAAA,KAAW,IAAA,IAAQ,OAAO,MAAA,KAAW,QAAA,EAAU;AACjD,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN,cAAc,MAAM,CAAA,kGAAA;AAAA,KAEtB;AACA,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,OAAA,GAAU,YAAY,MAAA,CAAO,CAAA,IAAA,KAAQ,OAAO,MAAA,CAAO,IAAI,MAAM,UAAU,CAAA;AAC7E,EAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACtB,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN,cAAc,MAAM,CAAA,8CAAA,EACf,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,mKAAA;AAAA,KAGzB;AAAA,EACF;AACF;AAlBgB,MAAA,CAAA,sBAAA,EAAA,wBAAA,CAAA;;;;"}