@richardmcquiston01/error-log-adapter 0.6.0 → 0.7.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/README.md +12 -0
- package/dist/index.cjs +38 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -1
- package/dist/index.d.ts +38 -1
- package/dist/index.mjs +37 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1022,4 +1022,41 @@ declare class EventEmitterErrorAdapter<TCode extends string = string> implements
|
|
|
1022
1022
|
log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
|
-
|
|
1025
|
+
/**
|
|
1026
|
+
* The only things this adapter needs from a socket: `send` and `readyState`. The
|
|
1027
|
+
* browser `WebSocket`, Node's global `WebSocket`, Deno, Bun, and the `ws` package
|
|
1028
|
+
* all fit as they are.
|
|
1029
|
+
*/
|
|
1030
|
+
interface WebSocketLike {
|
|
1031
|
+
send(data: string): unknown;
|
|
1032
|
+
readonly readyState: number;
|
|
1033
|
+
}
|
|
1034
|
+
interface WebSocketErrorOptions {
|
|
1035
|
+
/** Text printed before failure messages. Defaults to `[error-log-adapter]`. */
|
|
1036
|
+
prefix?: string;
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Sends each entry as one JSON text message (the serialized entry plus its UUID
|
|
1040
|
+
* `id`) over a socket you own. You connect, and reconnect, the socket; this
|
|
1041
|
+
* adapter never opens one and keeps no buffer. If the socket is not open when
|
|
1042
|
+
* `log` is called, the entry is not sent and `log` returns `ok: false`, so
|
|
1043
|
+
* combine it with a durable adapter in a `CompositeErrorAdapter` when entries
|
|
1044
|
+
* must not be lost while the socket is down.
|
|
1045
|
+
*
|
|
1046
|
+
* `ok: true` means the socket accepted the message, not that the server
|
|
1047
|
+
* received it: a WebSocket gives no acknowledgement, and a connection that
|
|
1048
|
+
* drops after `send` loses the message.
|
|
1049
|
+
*
|
|
1050
|
+
* ```ts
|
|
1051
|
+
* const socket = new WebSocket('wss://logs.example.com/errors');
|
|
1052
|
+
* const adapter = new WebSocketErrorAdapter(socket);
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
declare class WebSocketErrorAdapter<TCode extends string = string> implements ErrorLogAdapter<TCode> {
|
|
1056
|
+
private readonly socket;
|
|
1057
|
+
private readonly prefix;
|
|
1058
|
+
constructor(socket: WebSocketLike, options?: WebSocketErrorOptions);
|
|
1059
|
+
log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
export { 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1022,4 +1022,41 @@ declare class EventEmitterErrorAdapter<TCode extends string = string> implements
|
|
|
1022
1022
|
log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
|
-
|
|
1025
|
+
/**
|
|
1026
|
+
* The only things this adapter needs from a socket: `send` and `readyState`. The
|
|
1027
|
+
* browser `WebSocket`, Node's global `WebSocket`, Deno, Bun, and the `ws` package
|
|
1028
|
+
* all fit as they are.
|
|
1029
|
+
*/
|
|
1030
|
+
interface WebSocketLike {
|
|
1031
|
+
send(data: string): unknown;
|
|
1032
|
+
readonly readyState: number;
|
|
1033
|
+
}
|
|
1034
|
+
interface WebSocketErrorOptions {
|
|
1035
|
+
/** Text printed before failure messages. Defaults to `[error-log-adapter]`. */
|
|
1036
|
+
prefix?: string;
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Sends each entry as one JSON text message (the serialized entry plus its UUID
|
|
1040
|
+
* `id`) over a socket you own. You connect, and reconnect, the socket; this
|
|
1041
|
+
* adapter never opens one and keeps no buffer. If the socket is not open when
|
|
1042
|
+
* `log` is called, the entry is not sent and `log` returns `ok: false`, so
|
|
1043
|
+
* combine it with a durable adapter in a `CompositeErrorAdapter` when entries
|
|
1044
|
+
* must not be lost while the socket is down.
|
|
1045
|
+
*
|
|
1046
|
+
* `ok: true` means the socket accepted the message, not that the server
|
|
1047
|
+
* received it: a WebSocket gives no acknowledgement, and a connection that
|
|
1048
|
+
* drops after `send` loses the message.
|
|
1049
|
+
*
|
|
1050
|
+
* ```ts
|
|
1051
|
+
* const socket = new WebSocket('wss://logs.example.com/errors');
|
|
1052
|
+
* const adapter = new WebSocketErrorAdapter(socket);
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
declare class WebSocketErrorAdapter<TCode extends string = string> implements ErrorLogAdapter<TCode> {
|
|
1056
|
+
private readonly socket;
|
|
1057
|
+
private readonly prefix;
|
|
1058
|
+
constructor(socket: WebSocketLike, options?: WebSocketErrorOptions);
|
|
1059
|
+
log(entry: ErrorLogEntry<TCode>): Promise<ErrorLogResult>;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
export { 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1770,6 +1770,42 @@ var EventEmitterErrorAdapter = class {
|
|
|
1770
1770
|
}
|
|
1771
1771
|
}
|
|
1772
1772
|
};
|
|
1773
|
+
|
|
1774
|
+
// src/adapters/websocket-error-adapter.ts
|
|
1775
|
+
var OPEN = 1;
|
|
1776
|
+
var STATE_NAMES = {
|
|
1777
|
+
0: "still connecting",
|
|
1778
|
+
1: "open",
|
|
1779
|
+
2: "closing",
|
|
1780
|
+
3: "closed"
|
|
1781
|
+
};
|
|
1782
|
+
var WebSocketErrorAdapter = class {
|
|
1783
|
+
constructor(socket, options = {}) {
|
|
1784
|
+
this.socket = socket;
|
|
1785
|
+
this.prefix = options.prefix ?? DEFAULT_PREFIX;
|
|
1786
|
+
}
|
|
1787
|
+
async log(entry) {
|
|
1788
|
+
try {
|
|
1789
|
+
const state = this.socket.readyState;
|
|
1790
|
+
if (state !== OPEN) {
|
|
1791
|
+
throw new Error(
|
|
1792
|
+
`the socket is ${STATE_NAMES[state] ?? `in unknown state ${String(state)}`} (readyState ${String(state)}), so the entry was not sent; connect or reconnect it first`
|
|
1793
|
+
);
|
|
1794
|
+
}
|
|
1795
|
+
this.socket.send(
|
|
1796
|
+
JSON.stringify({ id: resolveEntryId(entry), ...serializeEntry(entry) })
|
|
1797
|
+
);
|
|
1798
|
+
return { ok: true };
|
|
1799
|
+
} catch (error) {
|
|
1800
|
+
return reportFailure({
|
|
1801
|
+
adapterName: "WebSocketErrorAdapter",
|
|
1802
|
+
prefix: this.prefix,
|
|
1803
|
+
action: "to send over the socket",
|
|
1804
|
+
error
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1773
1809
|
export {
|
|
1774
1810
|
CompositeErrorAdapter,
|
|
1775
1811
|
ConsoleErrorAdapter,
|
|
@@ -1786,6 +1822,7 @@ export {
|
|
|
1786
1822
|
S3ErrorAdapter,
|
|
1787
1823
|
SqliteErrorAdapter,
|
|
1788
1824
|
SupabaseErrorAdapter,
|
|
1825
|
+
WebSocketErrorAdapter,
|
|
1789
1826
|
WebStorageErrorAdapter,
|
|
1790
1827
|
WebhookErrorAdapter,
|
|
1791
1828
|
buildCreateErrorLogTableSql,
|