@richardmcquiston01/error-log-adapter 0.8.0 → 0.10.0

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.
package/dist/index.d.cts CHANGED
@@ -127,6 +127,15 @@ declare class WebhookErrorAdapter<TCode extends string = string> implements Erro
127
127
  /** @throws {RangeError} if `url` is not a valid `https://` URL (see `allowInsecure`) or a timeout, retry or signing option is invalid. */
128
128
  constructor(url: string, options?: WebhookErrorOptions);
129
129
  log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
130
+ /**
131
+ * Sends several entries in one request, as a JSON array of the same records
132
+ * `log` sends one at a time (each with an `id`). `BatchingErrorAdapter` uses
133
+ * this when it wraps a webhook, so the receiver must accept an array. The
134
+ * whole request succeeds or fails together.
135
+ */
136
+ logBatch(entries: ErrorLogEntry<TCode>[]): Promise<ErrorLogResult>;
137
+ /** Sends one prepared body, trying again as `retries` allows. */
138
+ private deliver;
130
139
  /** Milliseconds to wait before retry number `retryNumber` (1 for the first). */
131
140
  private retryWaitMs;
132
141
  private send;
@@ -793,9 +802,16 @@ interface FirebaseErrorRecord {
793
802
  */
794
803
  interface FirestoreCollectionLike {
795
804
  doc(documentId: string): {
796
- set(data: FirebaseErrorRecord): Promise<unknown>;
805
+ set(data: FirestoreErrorRecord): Promise<unknown>;
797
806
  };
798
807
  }
808
+ /**
809
+ * What the Firestore adapter writes: the usual fields, plus the expiry field
810
+ * (a `Date`, which Firestore stores as a timestamp) when `expireAfterMs` is set.
811
+ */
812
+ type FirestoreErrorRecord = FirebaseErrorRecord & {
813
+ [field: string]: unknown;
814
+ };
799
815
  /**
800
816
  * The only thing the Realtime Database adapter needs from a reference:
801
817
  * `push(value)`, which resolves once the write is saved. A `firebase-admin`
@@ -834,6 +850,25 @@ interface FirebaseErrorOptions {
834
850
  /** Text printed before failure messages. Defaults to `[error-log-adapter]`. */
835
851
  prefix?: string;
836
852
  }
853
+ interface FirestoreErrorOptions extends FirebaseErrorOptions {
854
+ /**
855
+ * Add an expiry time to every document: the entry's `timestamp` plus this
856
+ * many milliseconds, stored as a Firestore timestamp in `expireField`. This
857
+ * only writes the field. Firestore deletes nothing until you turn on a TTL
858
+ * policy for that field, for example:
859
+ *
860
+ * ```sh
861
+ * gcloud firestore fields ttls update expire_at \
862
+ * --collection-group=error_log --enable-ttl
863
+ * ```
864
+ *
865
+ * Firestore then removes documents some time after they expire (typically
866
+ * within a day), and the deletes are billed like any other. Off by default.
867
+ */
868
+ expireAfterMs?: number;
869
+ /** Name of the expiry field. Defaults to `expire_at`. Only used with `expireAfterMs`. */
870
+ expireField?: string;
871
+ }
837
872
  /**
838
873
  * Writes each entry as a document in a Firestore collection. The document id is
839
874
  * the entry's UUID, so the SDK finishing one queued write twice cannot create two
@@ -846,8 +881,10 @@ declare class FirestoreErrorAdapter<TCode extends string = string> implements Er
846
881
  private readonly collection;
847
882
  private readonly prefix;
848
883
  private readonly timeoutMs;
849
- /** @throws {RangeError} if `options.timeoutMs` is not a positive number or `Infinity`. */
850
- constructor(collection: FirestoreCollectionLike, options?: FirebaseErrorOptions);
884
+ private readonly expireAfterMs;
885
+ private readonly expireField;
886
+ /** @throws {RangeError} if `options.timeoutMs` is not a positive number or `Infinity`, or the expiry options are invalid. */
887
+ constructor(collection: FirestoreCollectionLike, options?: FirestoreErrorOptions);
851
888
  log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
852
889
  }
853
890
  /**
@@ -1175,4 +1212,123 @@ declare class CloudWatchLogsErrorAdapter<TCode extends string = string> implemen
1175
1212
  private fail;
1176
1213
  }
1177
1214
 
1178
- export { type CloudWatchBatchOptions, type CloudWatchLogEvent, type CloudWatchLogsClientLike, CloudWatchLogsErrorAdapter, type CloudWatchLogsErrorOptions, type CloudWatchPutLogEventsInput, type CollectionLike, CompositeErrorAdapter, type CompositeErrorOptions, ConsoleErrorAdapter, type ConsoleErrorOptions, type EmitterLike, type ErrorLogAdapter, type ErrorLogEntry, type ErrorLogResult, EventEmitterErrorAdapter, type EventEmitterErrorOptions, type EventEmitterErrorRecord, type FileSystemLike, type FirebaseErrorOptions, type FirebaseErrorRecord, type FirestoreCollectionLike, FirestoreErrorAdapter, FlatFileErrorAdapter, type FlatFileErrorOptions, type IdbDatabaseLike, type IdbObjectStoreLike, type IdbRequestLike, type IdbTransactionLike, type IdbUpgradeDatabaseLike, IndexedDbErrorAdapter, type IndexedDbErrorOptions, type IndexedDbErrorRecord, JsonFileErrorAdapter, type JsonFileErrorOptions, type JsonFileErrorRecord, type LockManagerLike, MongoDbErrorAdapter, type MongoDbErrorOptions, MySqlErrorAdapter, PostgresErrorAdapter, type ReadWriteFileSystemLike, RealtimeDatabaseErrorAdapter, type RealtimeDatabaseRefLike, type RedisClientLike, RedisErrorAdapter, type RedisErrorOptions, type S3BatchOptions, type S3ClientLike, S3ErrorAdapter, type S3ErrorOptions, type S3PutObjectInput, type SerializedErrorLogEntry, type SqlClientLike, type SqlDialect, type SqlErrorOptions, type SqliteClientLike, SqliteErrorAdapter, type SqliteErrorOptions, type StorageLike, type SupabaseClientLike, SupabaseErrorAdapter, type SupabaseErrorLike, type SupabaseErrorOptions, type SupabaseErrorRow, type SupabaseInsertResult, type SupabaseSetupOptions, WebSocketErrorAdapter, type WebSocketErrorOptions, type WebSocketLike, WebStorageErrorAdapter, type WebStorageErrorOptions, type WebStorageErrorRecord, WebhookErrorAdapter, type WebhookErrorOptions, buildCreateErrorLogTableSql, buildErrorLogTableDdl, buildMySqlWidenColumnsSql, buildSupabaseSetupSql, createErrorLogStore, formatErrorLogLine, serializeCause, serializeEntry };
1215
+ /**
1216
+ * An adapter that can send several entries in one go, such as
1217
+ * `WebhookErrorAdapter` (one request carrying a JSON array).
1218
+ * `BatchingErrorAdapter` uses it when it is there. The whole batch succeeds or
1219
+ * fails together.
1220
+ */
1221
+ interface BatchCapableAdapter<TCode extends string = string> extends ErrorLogAdapter<TCode> {
1222
+ logBatch(entries: ErrorLogEntry<TCode>[]): Promise<ErrorLogResult>;
1223
+ }
1224
+ interface BatchingErrorOptions<TCode extends string = string> {
1225
+ /** Deliver once this many entries are waiting. Defaults to 20. */
1226
+ batchSize?: number;
1227
+ /**
1228
+ * Also deliver once the oldest waiting entry has waited this long (ms).
1229
+ * Defaults to 5000. Pass `Infinity` to deliver only when `batchSize` is
1230
+ * reached or `flush()` is called. The timer does not keep the process alive,
1231
+ * so call `flush()` before exiting.
1232
+ */
1233
+ maxWaitMs?: number;
1234
+ /**
1235
+ * How many times to try an entry again after a failed delivery before giving
1236
+ * up on it. Defaults to 3 (four attempts in all).
1237
+ */
1238
+ retries?: number;
1239
+ /** Wait before the first retry, in milliseconds; it doubles after that. Defaults to 500. */
1240
+ retryDelayMs?: number;
1241
+ /** Longest wait between attempts, in milliseconds. Defaults to 30000. */
1242
+ maxRetryDelayMs?: number;
1243
+ /**
1244
+ * Most entries kept while the sink is slow or down. Past this, the oldest
1245
+ * are dropped. Defaults to 1000. Must be at least `batchSize`.
1246
+ */
1247
+ maxBuffered?: number;
1248
+ /**
1249
+ * Use the wrapped adapter's `logBatch` when it has one. Defaults to `true`.
1250
+ * Pass `false` to deliver one entry at a time even then (a wrapped
1251
+ * `WebhookErrorAdapter` then sends one request per entry, not an array).
1252
+ */
1253
+ useBatchMethod?: boolean;
1254
+ /**
1255
+ * Called when entries are given up on, either because they failed every
1256
+ * attempt or because the buffer was full. Errors it throws are ignored.
1257
+ */
1258
+ onDrop?: (entries: ErrorLogEntry<TCode>[], reason: string) => void;
1259
+ /** Text printed before failure messages. Defaults to `[error-log-adapter]`. */
1260
+ prefix?: string;
1261
+ }
1262
+ /**
1263
+ * Puts a queue in front of any other adapter. `log()` returns `ok: true` as
1264
+ * soon as the entry is queued, so a slow or failing sink never holds up the
1265
+ * application; entries are then delivered in order, in batches, and a failed
1266
+ * delivery is tried again with exponential backoff before the entry is given up
1267
+ * on (see `onDrop`).
1268
+ *
1269
+ * Delivery uses the wrapped adapter's `logBatch` when it has one (the webhook
1270
+ * sends one request for the whole batch); otherwise the entries go one at a
1271
+ * time through `log`, stopping at the first failure so a sink that is down is
1272
+ * not hammered. Because of that, `ok: true` from `log()` means "queued", not
1273
+ * "stored": call `flush()` before the process exits, and watch `onDrop` or the
1274
+ * console for entries that could not be delivered. The queue is in memory, so
1275
+ * entries still waiting when the process dies are lost; put a durable adapter
1276
+ * beside it in a `CompositeErrorAdapter` when that matters.
1277
+ *
1278
+ * ```ts
1279
+ * const errorLog = new BatchingErrorAdapter(
1280
+ * new WebhookErrorAdapter('https://example.com/errors'),
1281
+ * { batchSize: 50, maxWaitMs: 2000 }
1282
+ * );
1283
+ * process.on('beforeExit', () => void errorLog.flush());
1284
+ * ```
1285
+ *
1286
+ * Do not also turn on the wrapped adapter's own retries (for example the
1287
+ * webhook's `retries`): the two multiply.
1288
+ */
1289
+ declare class BatchingErrorAdapter<TCode extends string = string> implements ErrorLogAdapter<TCode> {
1290
+ private readonly inner;
1291
+ private readonly batchSize;
1292
+ private readonly maxWaitMs;
1293
+ private readonly retries;
1294
+ private readonly retryDelayMs;
1295
+ private readonly maxRetryDelayMs;
1296
+ private readonly maxBuffered;
1297
+ private readonly useBatchMethod;
1298
+ private readonly onDrop;
1299
+ private readonly logPrefix;
1300
+ private queue;
1301
+ private waitTimer;
1302
+ private backoffTimer;
1303
+ private draining;
1304
+ private flushers;
1305
+ private droppedSinceFlush;
1306
+ private lastDropReason;
1307
+ /** @throws {RangeError} if an option is out of range. */
1308
+ constructor(inner: ErrorLogAdapter<TCode>, options?: BatchingErrorOptions<TCode>);
1309
+ /** Queues the entry. Resolves ok straight away; delivery happens in the background. */
1310
+ log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
1311
+ /**
1312
+ * Delivers everything queued, retrying as configured, and resolves once the
1313
+ * queue is empty. Resolves `ok: false` if any entries were given up on since
1314
+ * the last flush. With retries on and the sink down this can take a while
1315
+ * (the waits add up to well over a minute with the defaults).
1316
+ */
1317
+ flush(): Promise<ErrorLogResult>;
1318
+ private scheduleDrain;
1319
+ private startDraining;
1320
+ /** Delivers batches until the queue is empty, waiting out a backoff after each failure. */
1321
+ private drain;
1322
+ /**
1323
+ * Tries to deliver `batch` (the front of the queue). Delivered entries leave
1324
+ * the queue; an entry that failed has its failure count raised and stays.
1325
+ * Resolves to the failure message, or undefined when everything went through.
1326
+ */
1327
+ private deliver;
1328
+ /** The wrapped adapter should not throw, but a bug in one must not stop the queue. */
1329
+ private safely;
1330
+ private backoff;
1331
+ private drop;
1332
+ }
1333
+
1334
+ export { type BatchCapableAdapter, BatchingErrorAdapter, type BatchingErrorOptions, type CloudWatchBatchOptions, type CloudWatchLogEvent, type CloudWatchLogsClientLike, CloudWatchLogsErrorAdapter, type CloudWatchLogsErrorOptions, type CloudWatchPutLogEventsInput, type CollectionLike, CompositeErrorAdapter, type CompositeErrorOptions, ConsoleErrorAdapter, type ConsoleErrorOptions, type EmitterLike, type ErrorLogAdapter, type ErrorLogEntry, type ErrorLogResult, EventEmitterErrorAdapter, type EventEmitterErrorOptions, type EventEmitterErrorRecord, type FileSystemLike, type FirebaseErrorOptions, type FirebaseErrorRecord, type FirestoreCollectionLike, FirestoreErrorAdapter, type FirestoreErrorOptions, type FirestoreErrorRecord, FlatFileErrorAdapter, type FlatFileErrorOptions, type IdbDatabaseLike, type IdbObjectStoreLike, type IdbRequestLike, type IdbTransactionLike, type IdbUpgradeDatabaseLike, IndexedDbErrorAdapter, type IndexedDbErrorOptions, type IndexedDbErrorRecord, JsonFileErrorAdapter, type JsonFileErrorOptions, type JsonFileErrorRecord, type LockManagerLike, MongoDbErrorAdapter, type MongoDbErrorOptions, MySqlErrorAdapter, PostgresErrorAdapter, type ReadWriteFileSystemLike, RealtimeDatabaseErrorAdapter, type RealtimeDatabaseRefLike, type RedisClientLike, RedisErrorAdapter, type RedisErrorOptions, type S3BatchOptions, type S3ClientLike, S3ErrorAdapter, type S3ErrorOptions, type S3PutObjectInput, type SerializedErrorLogEntry, type SqlClientLike, type SqlDialect, type SqlErrorOptions, type SqliteClientLike, SqliteErrorAdapter, type SqliteErrorOptions, type StorageLike, type SupabaseClientLike, SupabaseErrorAdapter, type SupabaseErrorLike, type SupabaseErrorOptions, type SupabaseErrorRow, type SupabaseInsertResult, type SupabaseSetupOptions, WebSocketErrorAdapter, type WebSocketErrorOptions, type WebSocketLike, WebStorageErrorAdapter, type WebStorageErrorOptions, type WebStorageErrorRecord, WebhookErrorAdapter, type WebhookErrorOptions, buildCreateErrorLogTableSql, buildErrorLogTableDdl, buildMySqlWidenColumnsSql, buildSupabaseSetupSql, createErrorLogStore, formatErrorLogLine, serializeCause, serializeEntry };
package/dist/index.d.ts CHANGED
@@ -127,6 +127,15 @@ declare class WebhookErrorAdapter<TCode extends string = string> implements Erro
127
127
  /** @throws {RangeError} if `url` is not a valid `https://` URL (see `allowInsecure`) or a timeout, retry or signing option is invalid. */
128
128
  constructor(url: string, options?: WebhookErrorOptions);
129
129
  log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
130
+ /**
131
+ * Sends several entries in one request, as a JSON array of the same records
132
+ * `log` sends one at a time (each with an `id`). `BatchingErrorAdapter` uses
133
+ * this when it wraps a webhook, so the receiver must accept an array. The
134
+ * whole request succeeds or fails together.
135
+ */
136
+ logBatch(entries: ErrorLogEntry<TCode>[]): Promise<ErrorLogResult>;
137
+ /** Sends one prepared body, trying again as `retries` allows. */
138
+ private deliver;
130
139
  /** Milliseconds to wait before retry number `retryNumber` (1 for the first). */
131
140
  private retryWaitMs;
132
141
  private send;
@@ -793,9 +802,16 @@ interface FirebaseErrorRecord {
793
802
  */
794
803
  interface FirestoreCollectionLike {
795
804
  doc(documentId: string): {
796
- set(data: FirebaseErrorRecord): Promise<unknown>;
805
+ set(data: FirestoreErrorRecord): Promise<unknown>;
797
806
  };
798
807
  }
808
+ /**
809
+ * What the Firestore adapter writes: the usual fields, plus the expiry field
810
+ * (a `Date`, which Firestore stores as a timestamp) when `expireAfterMs` is set.
811
+ */
812
+ type FirestoreErrorRecord = FirebaseErrorRecord & {
813
+ [field: string]: unknown;
814
+ };
799
815
  /**
800
816
  * The only thing the Realtime Database adapter needs from a reference:
801
817
  * `push(value)`, which resolves once the write is saved. A `firebase-admin`
@@ -834,6 +850,25 @@ interface FirebaseErrorOptions {
834
850
  /** Text printed before failure messages. Defaults to `[error-log-adapter]`. */
835
851
  prefix?: string;
836
852
  }
853
+ interface FirestoreErrorOptions extends FirebaseErrorOptions {
854
+ /**
855
+ * Add an expiry time to every document: the entry's `timestamp` plus this
856
+ * many milliseconds, stored as a Firestore timestamp in `expireField`. This
857
+ * only writes the field. Firestore deletes nothing until you turn on a TTL
858
+ * policy for that field, for example:
859
+ *
860
+ * ```sh
861
+ * gcloud firestore fields ttls update expire_at \
862
+ * --collection-group=error_log --enable-ttl
863
+ * ```
864
+ *
865
+ * Firestore then removes documents some time after they expire (typically
866
+ * within a day), and the deletes are billed like any other. Off by default.
867
+ */
868
+ expireAfterMs?: number;
869
+ /** Name of the expiry field. Defaults to `expire_at`. Only used with `expireAfterMs`. */
870
+ expireField?: string;
871
+ }
837
872
  /**
838
873
  * Writes each entry as a document in a Firestore collection. The document id is
839
874
  * the entry's UUID, so the SDK finishing one queued write twice cannot create two
@@ -846,8 +881,10 @@ declare class FirestoreErrorAdapter<TCode extends string = string> implements Er
846
881
  private readonly collection;
847
882
  private readonly prefix;
848
883
  private readonly timeoutMs;
849
- /** @throws {RangeError} if `options.timeoutMs` is not a positive number or `Infinity`. */
850
- constructor(collection: FirestoreCollectionLike, options?: FirebaseErrorOptions);
884
+ private readonly expireAfterMs;
885
+ private readonly expireField;
886
+ /** @throws {RangeError} if `options.timeoutMs` is not a positive number or `Infinity`, or the expiry options are invalid. */
887
+ constructor(collection: FirestoreCollectionLike, options?: FirestoreErrorOptions);
851
888
  log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
852
889
  }
853
890
  /**
@@ -1175,4 +1212,123 @@ declare class CloudWatchLogsErrorAdapter<TCode extends string = string> implemen
1175
1212
  private fail;
1176
1213
  }
1177
1214
 
1178
- export { type CloudWatchBatchOptions, type CloudWatchLogEvent, type CloudWatchLogsClientLike, CloudWatchLogsErrorAdapter, type CloudWatchLogsErrorOptions, type CloudWatchPutLogEventsInput, type CollectionLike, CompositeErrorAdapter, type CompositeErrorOptions, ConsoleErrorAdapter, type ConsoleErrorOptions, type EmitterLike, type ErrorLogAdapter, type ErrorLogEntry, type ErrorLogResult, EventEmitterErrorAdapter, type EventEmitterErrorOptions, type EventEmitterErrorRecord, type FileSystemLike, type FirebaseErrorOptions, type FirebaseErrorRecord, type FirestoreCollectionLike, FirestoreErrorAdapter, FlatFileErrorAdapter, type FlatFileErrorOptions, type IdbDatabaseLike, type IdbObjectStoreLike, type IdbRequestLike, type IdbTransactionLike, type IdbUpgradeDatabaseLike, IndexedDbErrorAdapter, type IndexedDbErrorOptions, type IndexedDbErrorRecord, JsonFileErrorAdapter, type JsonFileErrorOptions, type JsonFileErrorRecord, type LockManagerLike, MongoDbErrorAdapter, type MongoDbErrorOptions, MySqlErrorAdapter, PostgresErrorAdapter, type ReadWriteFileSystemLike, RealtimeDatabaseErrorAdapter, type RealtimeDatabaseRefLike, type RedisClientLike, RedisErrorAdapter, type RedisErrorOptions, type S3BatchOptions, type S3ClientLike, S3ErrorAdapter, type S3ErrorOptions, type S3PutObjectInput, type SerializedErrorLogEntry, type SqlClientLike, type SqlDialect, type SqlErrorOptions, type SqliteClientLike, SqliteErrorAdapter, type SqliteErrorOptions, type StorageLike, type SupabaseClientLike, SupabaseErrorAdapter, type SupabaseErrorLike, type SupabaseErrorOptions, type SupabaseErrorRow, type SupabaseInsertResult, type SupabaseSetupOptions, WebSocketErrorAdapter, type WebSocketErrorOptions, type WebSocketLike, WebStorageErrorAdapter, type WebStorageErrorOptions, type WebStorageErrorRecord, WebhookErrorAdapter, type WebhookErrorOptions, buildCreateErrorLogTableSql, buildErrorLogTableDdl, buildMySqlWidenColumnsSql, buildSupabaseSetupSql, createErrorLogStore, formatErrorLogLine, serializeCause, serializeEntry };
1215
+ /**
1216
+ * An adapter that can send several entries in one go, such as
1217
+ * `WebhookErrorAdapter` (one request carrying a JSON array).
1218
+ * `BatchingErrorAdapter` uses it when it is there. The whole batch succeeds or
1219
+ * fails together.
1220
+ */
1221
+ interface BatchCapableAdapter<TCode extends string = string> extends ErrorLogAdapter<TCode> {
1222
+ logBatch(entries: ErrorLogEntry<TCode>[]): Promise<ErrorLogResult>;
1223
+ }
1224
+ interface BatchingErrorOptions<TCode extends string = string> {
1225
+ /** Deliver once this many entries are waiting. Defaults to 20. */
1226
+ batchSize?: number;
1227
+ /**
1228
+ * Also deliver once the oldest waiting entry has waited this long (ms).
1229
+ * Defaults to 5000. Pass `Infinity` to deliver only when `batchSize` is
1230
+ * reached or `flush()` is called. The timer does not keep the process alive,
1231
+ * so call `flush()` before exiting.
1232
+ */
1233
+ maxWaitMs?: number;
1234
+ /**
1235
+ * How many times to try an entry again after a failed delivery before giving
1236
+ * up on it. Defaults to 3 (four attempts in all).
1237
+ */
1238
+ retries?: number;
1239
+ /** Wait before the first retry, in milliseconds; it doubles after that. Defaults to 500. */
1240
+ retryDelayMs?: number;
1241
+ /** Longest wait between attempts, in milliseconds. Defaults to 30000. */
1242
+ maxRetryDelayMs?: number;
1243
+ /**
1244
+ * Most entries kept while the sink is slow or down. Past this, the oldest
1245
+ * are dropped. Defaults to 1000. Must be at least `batchSize`.
1246
+ */
1247
+ maxBuffered?: number;
1248
+ /**
1249
+ * Use the wrapped adapter's `logBatch` when it has one. Defaults to `true`.
1250
+ * Pass `false` to deliver one entry at a time even then (a wrapped
1251
+ * `WebhookErrorAdapter` then sends one request per entry, not an array).
1252
+ */
1253
+ useBatchMethod?: boolean;
1254
+ /**
1255
+ * Called when entries are given up on, either because they failed every
1256
+ * attempt or because the buffer was full. Errors it throws are ignored.
1257
+ */
1258
+ onDrop?: (entries: ErrorLogEntry<TCode>[], reason: string) => void;
1259
+ /** Text printed before failure messages. Defaults to `[error-log-adapter]`. */
1260
+ prefix?: string;
1261
+ }
1262
+ /**
1263
+ * Puts a queue in front of any other adapter. `log()` returns `ok: true` as
1264
+ * soon as the entry is queued, so a slow or failing sink never holds up the
1265
+ * application; entries are then delivered in order, in batches, and a failed
1266
+ * delivery is tried again with exponential backoff before the entry is given up
1267
+ * on (see `onDrop`).
1268
+ *
1269
+ * Delivery uses the wrapped adapter's `logBatch` when it has one (the webhook
1270
+ * sends one request for the whole batch); otherwise the entries go one at a
1271
+ * time through `log`, stopping at the first failure so a sink that is down is
1272
+ * not hammered. Because of that, `ok: true` from `log()` means "queued", not
1273
+ * "stored": call `flush()` before the process exits, and watch `onDrop` or the
1274
+ * console for entries that could not be delivered. The queue is in memory, so
1275
+ * entries still waiting when the process dies are lost; put a durable adapter
1276
+ * beside it in a `CompositeErrorAdapter` when that matters.
1277
+ *
1278
+ * ```ts
1279
+ * const errorLog = new BatchingErrorAdapter(
1280
+ * new WebhookErrorAdapter('https://example.com/errors'),
1281
+ * { batchSize: 50, maxWaitMs: 2000 }
1282
+ * );
1283
+ * process.on('beforeExit', () => void errorLog.flush());
1284
+ * ```
1285
+ *
1286
+ * Do not also turn on the wrapped adapter's own retries (for example the
1287
+ * webhook's `retries`): the two multiply.
1288
+ */
1289
+ declare class BatchingErrorAdapter<TCode extends string = string> implements ErrorLogAdapter<TCode> {
1290
+ private readonly inner;
1291
+ private readonly batchSize;
1292
+ private readonly maxWaitMs;
1293
+ private readonly retries;
1294
+ private readonly retryDelayMs;
1295
+ private readonly maxRetryDelayMs;
1296
+ private readonly maxBuffered;
1297
+ private readonly useBatchMethod;
1298
+ private readonly onDrop;
1299
+ private readonly logPrefix;
1300
+ private queue;
1301
+ private waitTimer;
1302
+ private backoffTimer;
1303
+ private draining;
1304
+ private flushers;
1305
+ private droppedSinceFlush;
1306
+ private lastDropReason;
1307
+ /** @throws {RangeError} if an option is out of range. */
1308
+ constructor(inner: ErrorLogAdapter<TCode>, options?: BatchingErrorOptions<TCode>);
1309
+ /** Queues the entry. Resolves ok straight away; delivery happens in the background. */
1310
+ log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
1311
+ /**
1312
+ * Delivers everything queued, retrying as configured, and resolves once the
1313
+ * queue is empty. Resolves `ok: false` if any entries were given up on since
1314
+ * the last flush. With retries on and the sink down this can take a while
1315
+ * (the waits add up to well over a minute with the defaults).
1316
+ */
1317
+ flush(): Promise<ErrorLogResult>;
1318
+ private scheduleDrain;
1319
+ private startDraining;
1320
+ /** Delivers batches until the queue is empty, waiting out a backoff after each failure. */
1321
+ private drain;
1322
+ /**
1323
+ * Tries to deliver `batch` (the front of the queue). Delivered entries leave
1324
+ * the queue; an entry that failed has its failure count raised and stays.
1325
+ * Resolves to the failure message, or undefined when everything went through.
1326
+ */
1327
+ private deliver;
1328
+ /** The wrapped adapter should not throw, but a bug in one must not stop the queue. */
1329
+ private safely;
1330
+ private backoff;
1331
+ private drop;
1332
+ }
1333
+
1334
+ export { type BatchCapableAdapter, BatchingErrorAdapter, type BatchingErrorOptions, type CloudWatchBatchOptions, type CloudWatchLogEvent, type CloudWatchLogsClientLike, CloudWatchLogsErrorAdapter, type CloudWatchLogsErrorOptions, type CloudWatchPutLogEventsInput, type CollectionLike, CompositeErrorAdapter, type CompositeErrorOptions, ConsoleErrorAdapter, type ConsoleErrorOptions, type EmitterLike, type ErrorLogAdapter, type ErrorLogEntry, type ErrorLogResult, EventEmitterErrorAdapter, type EventEmitterErrorOptions, type EventEmitterErrorRecord, type FileSystemLike, type FirebaseErrorOptions, type FirebaseErrorRecord, type FirestoreCollectionLike, FirestoreErrorAdapter, type FirestoreErrorOptions, type FirestoreErrorRecord, FlatFileErrorAdapter, type FlatFileErrorOptions, type IdbDatabaseLike, type IdbObjectStoreLike, type IdbRequestLike, type IdbTransactionLike, type IdbUpgradeDatabaseLike, IndexedDbErrorAdapter, type IndexedDbErrorOptions, type IndexedDbErrorRecord, JsonFileErrorAdapter, type JsonFileErrorOptions, type JsonFileErrorRecord, type LockManagerLike, MongoDbErrorAdapter, type MongoDbErrorOptions, MySqlErrorAdapter, PostgresErrorAdapter, type ReadWriteFileSystemLike, RealtimeDatabaseErrorAdapter, type RealtimeDatabaseRefLike, type RedisClientLike, RedisErrorAdapter, type RedisErrorOptions, type S3BatchOptions, type S3ClientLike, S3ErrorAdapter, type S3ErrorOptions, type S3PutObjectInput, type SerializedErrorLogEntry, type SqlClientLike, type SqlDialect, type SqlErrorOptions, type SqliteClientLike, SqliteErrorAdapter, type SqliteErrorOptions, type StorageLike, type SupabaseClientLike, SupabaseErrorAdapter, type SupabaseErrorLike, type SupabaseErrorOptions, type SupabaseErrorRow, type SupabaseInsertResult, type SupabaseSetupOptions, WebSocketErrorAdapter, type WebSocketErrorOptions, type WebSocketLike, WebStorageErrorAdapter, type WebStorageErrorOptions, type WebStorageErrorRecord, WebhookErrorAdapter, type WebhookErrorOptions, buildCreateErrorLogTableSql, buildErrorLogTableDdl, buildMySqlWidenColumnsSql, buildSupabaseSetupSql, createErrorLogStore, formatErrorLogLine, serializeCause, serializeEntry };