@deepraxis/sdk 0.1.1-dev.5914d25 → 0.1.1-dev.59c5eab

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ /** Deprecated SDK methods warn once per process per method (ticket-4078). The table is generated from the
2
+ * OpenAPI `deprecated: true` operations; this is the single call path every deprecated binding goes through. */
3
+ export interface DeprecationNotice {
4
+ readonly replacement: string;
5
+ readonly sunset: string;
6
+ }
7
+ export declare function deprecationMessage(method: string, notice: DeprecationNotice): string;
8
+ /** Test seam: forget which methods already warned. */
9
+ export declare function resetDeprecationWarnings(): void;
10
+ export declare function envSilencesDeprecations(): boolean;
11
+ export declare function deprecate<F extends (...args: any[]) => any>(silenced: () => boolean, method: string, notice: DeprecationNotice, fn: F): F;
@@ -0,0 +1,20 @@
1
+ const warned = new Set();
2
+ export function deprecationMessage(method, notice) {
3
+ return `${method} is deprecated and stops working on ${notice.sunset}; use ${notice.replacement} instead.`;
4
+ }
5
+ /** Test seam: forget which methods already warned. */
6
+ export function resetDeprecationWarnings() { warned.clear(); }
7
+ export function envSilencesDeprecations() {
8
+ const env = globalThis.process?.env;
9
+ const value = env?.PRAXIS_SDK_SILENCE_DEPRECATIONS;
10
+ return value !== undefined && value !== '' && value !== '0' && value !== 'false';
11
+ }
12
+ export function deprecate(silenced, method, notice, fn) {
13
+ return ((...args) => {
14
+ if (!warned.has(method) && !silenced()) {
15
+ warned.add(method);
16
+ console.warn(deprecationMessage(method, notice));
17
+ }
18
+ return fn(...args);
19
+ });
20
+ }
@@ -6,6 +6,8 @@ export interface PraxisOptions {
6
6
  timeoutMs?: number;
7
7
  maxRetries?: number;
8
8
  fetch?: typeof globalThis.fetch;
9
+ /** Silence the once-per-method warning a deprecated method prints. PRAXIS_SDK_SILENCE_DEPRECATIONS=1 does the same. */
10
+ silenceDeprecations?: boolean;
9
11
  }
10
12
  export interface RequestOptions {
11
13
  headers?: Record<string, string>;
@@ -37,6 +39,8 @@ export declare function serverDeadlineMs(options: {
37
39
  export declare class Transport {
38
40
  private readonly config;
39
41
  constructor(options: PraxisOptions);
42
+ /** Whether deprecated-method warnings are off (client option or PRAXIS_SDK_SILENCE_DEPRECATIONS). */
43
+ readonly silenced: () => boolean;
40
44
  private validate;
41
45
  private scope;
42
46
  request<R>(operation: Operation, options?: InternalOptions): Promise<R>;
@@ -4,6 +4,7 @@ import { abortable, fetchWithRetry } from "./retry.js";
4
4
  import { parseSSE } from "./sse.js";
5
5
  import { resolveDefaultCredentials } from "./credentials.js";
6
6
  import { isBinaryOperation } from "./binary-operations.js";
7
+ import { envSilencesDeprecations } from "./deprecation.js";
7
8
  /** Our own per-call keys, beyond what the generated hey-api client accepts. */
8
9
  const SDK_OPTION_KEYS = ['timeoutMs', 'maxRetries', 'stream', 'lastEventId'];
9
10
  /** Every key of the generated client's per-call RequestOptions (request parts, fetch/RequestInit, serializers,
@@ -50,6 +51,8 @@ export class Transport {
50
51
  this.config = { timeoutMs: 600_000, maxRetries: 2, fetch: globalThis.fetch, ...options };
51
52
  this.validate(this.config.timeoutMs, this.config.maxRetries);
52
53
  }
54
+ /** Whether deprecated-method warnings are off (client option or PRAXIS_SDK_SILENCE_DEPRECATIONS). */
55
+ silenced = () => this.config.silenceDeprecations === true || envSilencesDeprecations();
53
56
  validate(timeout, retries) {
54
57
  if (!Number.isFinite(timeout) || timeout <= 0)
55
58
  throw new RangeError('timeoutMs must be positive and finite');