openvibers/openvibe.sdk Commits

SDK types: the PostgreSQL telemetry sink takes the collectors' samples (#49)

OP OpenVibers committed 29 days ago · ef60149238 · 1 file, +1 −1

Typings only. `createPgTelemetrySink()` was declared to take `TelemetrySample[]` (from `types/telemetry.d.ts`, where `service` is required). The collectors in `types/service.d.ts` hand their sink a sample type whose `service` is optional. So `telemetry.init({ sink: createPgTelemetrySink({ db }) })` and `createHttpTelemetry({ sink: createPgTelemetrySink({ db }) })` did not compile in TypeScript. OpenVibe.Games#85 had to cast.

The sink already accepts anything at runtime: `storable()` drops a sample without `service`, `operation` or a valid `at` (with one warning) and stores the rest. The declaration now says so: `(samples: ReadonlyArray<Partial<TelemetrySample>>) => Promise<void>`. Existing callers that pass `TelemetrySample[]` still compile.

Verified with TypeScript (strict, nodenext) against these declaration files: both calls above compile.

No behaviour change and no release needed; the next SDK release carries it.

Changes

ddiff --git a/types/telemetry.d.ts b/types/telemetry.d.ts
iindex 6a6ef8d..e43e0ab 100644
---- a/types/telemetry.d.ts
++++ b/types/telemetry.d.ts
@@@ -37,7 +37,7 @@ export declare function telemetrySchema(table?: string): string;
/** A sink for createTelemetry() / createHttpTelemetry(): one multi-row parameterized INSERT per flush. A malformed
* sample is dropped with one warning and the rest stored; missing fields are NULL, `extra` is JSON; a rejected
* db.query propagates (the collector keeps the batch). */
--export declare function createPgTelemetrySink(opts: { db: TelemetryDb; table?: string; log?: { warn(...a: unknown[]): void } }): (samples: TelemetrySample[]) => Promise<void>;
++export declare function createPgTelemetrySink(opts: { db: TelemetryDb; table?: string; log?: { warn(...a: unknown[]): void } }): (samples: ReadonlyArray<Partial<TelemetrySample>>) => Promise<void>;
/** Retention: deletes rows whose `at` is older than olderThanDays (default 30); resolves with the count. */
export declare function pruneTelemetry(opts: { db: TelemetryDb; table?: string; olderThanDays?: number }): Promise<number>;
/** Scheduled retention: pruneTelemetry() delayMs after the call (default 60000) and then every everyMs (default