Declare the logger contract in the library instead of depending on @larvit/log
This commit is contained in:
+4
-4
@@ -1,6 +1,6 @@
|
||||
import type { ConnectionOptions } from 'node:tls';
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { Result, VoidResult } from './result.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import type { Socket } from 'node:net';
|
||||
import { Session } from './session.ts';
|
||||
import { checkSessionOptions, undeclaredInterfaceVersion } from './session-options.ts';
|
||||
@@ -20,7 +20,7 @@ export type ClientOptions = {
|
||||
host?: string;
|
||||
idleTimeout?: number;
|
||||
interfaceVersion?: number;
|
||||
log?: LogInt;
|
||||
log?: SmppLog;
|
||||
maxOutstanding?: number;
|
||||
password?: string;
|
||||
port?: number;
|
||||
@@ -134,7 +134,7 @@ async function bind(session: Session, options: ClientOptions): Promise<VoidResul
|
||||
return {};
|
||||
}
|
||||
|
||||
function createSession(options: ClientOptions, log: LogInt, sock: Socket): Session {
|
||||
function createSession(options: ClientOptions, log: SmppLog, sock: Socket): Session {
|
||||
const enquireLinkInterval = options.enquireLinkInterval ?? defaults.enquireLinkInterval;
|
||||
|
||||
return new Session({
|
||||
@@ -157,7 +157,7 @@ function createSession(options: ClientOptions, log: LogInt, sock: Socket): Sessi
|
||||
});
|
||||
}
|
||||
|
||||
async function connect(options: ClientOptions, log: LogInt): Promise<Result<{ sock: Socket }>> {
|
||||
async function connect(options: ClientOptions, log: SmppLog): Promise<Result<{ sock: Socket }>> {
|
||||
const checked = checkSessionOptions(options);
|
||||
|
||||
if (checked.err) {
|
||||
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
import type { Dlr } from './dlr.ts';
|
||||
import type { MessageState } from './defs/constants.ts';
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import { ExpiringGroups } from './expiring-groups.ts';
|
||||
|
||||
export type MessageDlr = Dlr & { segments: Dlr[] };
|
||||
|
||||
export type DlrMergerOptions = {
|
||||
log: LogInt;
|
||||
log: SmppLog;
|
||||
max: number;
|
||||
/** Injected so expiry can be exercised without a wall clock. */
|
||||
now?: (() => number) | undefined;
|
||||
@@ -50,7 +50,7 @@ function severityOf(dlr: Dlr): number {
|
||||
|
||||
export class DlrMerger {
|
||||
private readonly groups: ExpiringGroups<Group>;
|
||||
private readonly log: LogInt;
|
||||
private readonly log: SmppLog;
|
||||
private readonly max: number;
|
||||
|
||||
constructor(options: DlrMergerOptions) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { DlrMerger } from './dlr-merger.ts';
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { OnRequest } from './session-options.ts';
|
||||
import type { PduObject } from './pdu.ts';
|
||||
import type { Session } from './session.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import { Reassembler, decodeSegments } from './reassembly.ts';
|
||||
import { bindCommands, defaults } from './session-options.ts';
|
||||
import { concatInfo } from './udh.ts';
|
||||
@@ -13,7 +13,7 @@ import { paramText } from './defs/types.ts';
|
||||
|
||||
export type IncomingRequestsOptions = {
|
||||
dlrMerger: DlrMerger;
|
||||
log: LogInt;
|
||||
log: SmppLog;
|
||||
maxOctets?: number | undefined;
|
||||
maxReassembly?: number | undefined;
|
||||
onRequest?: OnRequest | undefined;
|
||||
@@ -25,7 +25,7 @@ export type IncomingRequestsOptions = {
|
||||
/** Everything the peer asks of a session: messages, receipts, links and the answers to them. */
|
||||
export class IncomingRequests {
|
||||
private readonly dlrMerger: DlrMerger;
|
||||
private readonly log: LogInt;
|
||||
private readonly log: SmppLog;
|
||||
private readonly onRequest: OnRequest | undefined;
|
||||
private readonly reassembler: Reassembler;
|
||||
private readonly session: Session;
|
||||
|
||||
@@ -38,6 +38,7 @@ export type { Dlr, Receipt } from './dlr.ts';
|
||||
export type { SendRespOptions, Sms, SmsInput } from './sms.ts';
|
||||
export type { ConcatInfo } from './udh.ts';
|
||||
export type { Result, VoidResult } from './result.ts';
|
||||
export type { SmppLog } from './log.ts';
|
||||
export type {
|
||||
AuthenticateInput,
|
||||
AuthenticateResult,
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { SmppLog } from './log.ts';
|
||||
|
||||
export type LinkTimersOptions = {
|
||||
/** How long between enquire_link probes. Undefined or 0 never probes. */
|
||||
enquireLinkInterval?: number | undefined;
|
||||
/** How long a silent peer is kept. Undefined or 0 keeps it forever. */
|
||||
idleTimeout?: number | undefined;
|
||||
log: LogInt;
|
||||
log: SmppLog;
|
||||
onEnquireLink: () => void;
|
||||
onIdle: () => void;
|
||||
};
|
||||
|
||||
+20
-3
@@ -1,5 +1,22 @@
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import { Log } from '@larvit/log';
|
||||
export type LogMetadata = Record<string, boolean | number | string>;
|
||||
export type LogMethod = (msg: string, metadata?: LogMetadata) => void;
|
||||
|
||||
/** What the library needs from a logger. A `@larvit/log` instance satisfies it as it stands. */
|
||||
export type SmppLog = {
|
||||
debug: LogMethod;
|
||||
error: LogMethod;
|
||||
info: LogMethod;
|
||||
verbose: LogMethod;
|
||||
warn: LogMethod;
|
||||
};
|
||||
|
||||
const noop: LogMethod = () => undefined;
|
||||
|
||||
/** The default: a library that says nothing unless the application asks it to. */
|
||||
export const silentLog: LogInt = new Log({ logLevel: 'none' });
|
||||
export const silentLog: SmppLog = {
|
||||
debug: noop,
|
||||
error: noop,
|
||||
info: noop,
|
||||
verbose: noop,
|
||||
warn: noop,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { PduObject } from './pdu.ts';
|
||||
import type { Result } from './result.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import { maxSeqNr } from './pdu.ts';
|
||||
|
||||
export type WaitOptions = {
|
||||
@@ -14,11 +14,11 @@ type Pending = {
|
||||
|
||||
/** Hands out sequence numbers and matches responses to the requests waiting for them. */
|
||||
export class PendingRequests {
|
||||
private readonly log: LogInt;
|
||||
private readonly log: SmppLog;
|
||||
private readonly pending = new Map<number, Pending>();
|
||||
private ourSeqNr = 1;
|
||||
|
||||
constructor(log: LogInt) {
|
||||
constructor(log: SmppLog) {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
import type { ConcatInfo } from './udh.ts';
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { ParamValue } from './defs/types.ts';
|
||||
import type { PduObject } from './pdu.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import type { Tlv } from './defs/tlvs.ts';
|
||||
import { ExpiringGroups } from './expiring-groups.ts';
|
||||
import { decodeMessage } from './message.ts';
|
||||
import { paramText } from './defs/types.ts';
|
||||
|
||||
export type ReassemblerOptions = {
|
||||
log: LogInt;
|
||||
log: SmppLog;
|
||||
max: number;
|
||||
maxOctets?: number | undefined;
|
||||
/** Injected so expiry can be exercised without a wall clock. */
|
||||
@@ -97,7 +97,7 @@ export function decodeSegments(pduObjs: PduObject[]): string {
|
||||
/** Holds the segments of incomplete multipart messages until they are whole, capped and expiring. */
|
||||
export class Reassembler {
|
||||
private readonly groups: ExpiringGroups<Group>;
|
||||
private readonly log: LogInt;
|
||||
private readonly log: SmppLog;
|
||||
private readonly max: number;
|
||||
private readonly maxOctets: number;
|
||||
private octets = 0;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { Result, VoidResult } from './result.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import type { Socket } from 'node:net';
|
||||
|
||||
export type ReconnectLoopOptions = {
|
||||
connect: () => Promise<Result<{ sock: Socket }>>;
|
||||
log: LogInt;
|
||||
log: SmppLog;
|
||||
maxDelay: number;
|
||||
minDelay: number;
|
||||
/** Brings the owner back up on a freshly opened socket. An err means try again. */
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import type { EncodingName } from './defs/encodings.ts';
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { ParamValue } from './defs/types.ts';
|
||||
import type { PduObject, PduObjectInput } from './pdu.ts';
|
||||
import type { Result } from './result.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import { consts } from './defs/constants.ts';
|
||||
import { detect } from './defs/encodings.ts';
|
||||
import { paramText } from './defs/types.ts';
|
||||
@@ -28,7 +28,7 @@ export type SendSmsResult = { err?: Error; pduObjs: PduObject[]; smsIds: string[
|
||||
|
||||
/** What sending needs from the session: a concat reference and a way onto the wire. */
|
||||
export type SendSmsDeps = {
|
||||
log: LogInt;
|
||||
log: SmppLog;
|
||||
reference: number;
|
||||
send: (input: PduObjectInput) => Promise<Result<{ pduObj: PduObject }>>;
|
||||
};
|
||||
|
||||
+7
-7
@@ -1,8 +1,8 @@
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { PduObject, TlvInput } from './pdu.ts';
|
||||
import type { Result, VoidResult } from './result.ts';
|
||||
import type { Server as NetServer, Socket } from 'node:net';
|
||||
import type { Server as TlsServer, TlsOptions } from 'node:tls';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { Session, bindCommands, defaultSystemId } from './session.ts';
|
||||
import { checkSessionOptions, undeclaredInterfaceVersion } from './session-options.ts';
|
||||
@@ -26,7 +26,7 @@ export type ServerOptions = {
|
||||
host?: string;
|
||||
idleTimeout?: number;
|
||||
interfaceVersion?: number;
|
||||
log?: LogInt;
|
||||
log?: SmppLog;
|
||||
maxOutstanding?: number;
|
||||
maxOctets?: number;
|
||||
maxReassembly?: number;
|
||||
@@ -54,10 +54,10 @@ const defaults = {
|
||||
export class SmppServer extends EventEmitter<ServerEvents> {
|
||||
readonly sessions = new Set<Session>();
|
||||
|
||||
private readonly log: LogInt;
|
||||
private readonly log: SmppLog;
|
||||
private readonly server: NetServer;
|
||||
|
||||
constructor(server: NetServer, log: LogInt) {
|
||||
constructor(server: NetServer, log: SmppLog) {
|
||||
super();
|
||||
this.log = log;
|
||||
this.server = server;
|
||||
@@ -223,7 +223,7 @@ function onConnection(sock: Socket, options: ServerOptions, server: SmppServer):
|
||||
}
|
||||
|
||||
/** Node reports a rejected handshake as `tlsClientError`, which is never an `error` event. */
|
||||
function createSecureListener(tlsOptions: TlsOptions, log: LogInt): TlsServer {
|
||||
function createSecureListener(tlsOptions: TlsOptions, log: SmppLog): TlsServer {
|
||||
const listener = createTlsServer(tlsOptions);
|
||||
|
||||
listener.on('tlsClientError', err => {
|
||||
@@ -233,7 +233,7 @@ function createSecureListener(tlsOptions: TlsOptions, log: LogInt): TlsServer {
|
||||
return listener;
|
||||
}
|
||||
|
||||
function checkOptions(options: ServerOptions, log: LogInt, port: number): VoidResult {
|
||||
function checkOptions(options: ServerOptions, log: SmppLog, port: number): VoidResult {
|
||||
const checked = checkSessionOptions(options);
|
||||
|
||||
if (checked.err) return { err: checked.err };
|
||||
@@ -258,7 +258,7 @@ function checkOptions(options: ServerOptions, log: LogInt, port: number): VoidRe
|
||||
|
||||
function createListener(
|
||||
options: ServerOptions,
|
||||
log: LogInt,
|
||||
log: SmppLog,
|
||||
port: number,
|
||||
): Result<{ listener: NetServer | TlsServer; useTls: boolean }> {
|
||||
const useTls = options.tls !== undefined && options.tls !== false;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Dlr } from './dlr.ts';
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { MessageDlr } from './dlr-merger.ts';
|
||||
import type { PduObject } from './pdu.ts';
|
||||
import type { Result, VoidResult } from './result.ts';
|
||||
import type { Session } from './session.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import type { Sms } from './sms.ts';
|
||||
import type { Socket } from 'node:net';
|
||||
|
||||
@@ -48,7 +48,7 @@ export type ReconnectOptions = {
|
||||
export type SessionOptions = {
|
||||
enquireLinkInterval?: number | undefined;
|
||||
idleTimeout?: number | undefined;
|
||||
log?: LogInt | undefined;
|
||||
log?: SmppLog | undefined;
|
||||
maxOctets?: number | undefined;
|
||||
maxOutstanding?: number | undefined;
|
||||
maxReassembly?: number | undefined;
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
import type { ErrorName } from './defs/errors.ts';
|
||||
import type { LogInt } from '@larvit/log';
|
||||
import type { MessageDlr } from './dlr-merger.ts';
|
||||
import type { ParamValue } from './defs/types.ts';
|
||||
import type { PduObject, PduObjectInput, TlvInput } from './pdu.ts';
|
||||
import type { ReconnectOptions, SendOptions, SessionEvents, SessionOptions } from './session-options.ts';
|
||||
import type { Result, VoidResult } from './result.ts';
|
||||
import type { SendSmsOptions, SendSmsResult } from './send-sms.ts';
|
||||
import type { SmppLog } from './log.ts';
|
||||
import type { Socket } from 'node:net';
|
||||
import { DlrMerger } from './dlr-merger.ts';
|
||||
import { EventEmitter } from 'node:events';
|
||||
@@ -35,7 +35,7 @@ export { bindCommands, defaultSystemId };
|
||||
export class Session extends EventEmitter<SessionEvents> {
|
||||
/** Replaced on reconnect, so hold the session rather than this. */
|
||||
sock: Socket;
|
||||
readonly log: LogInt;
|
||||
readonly log: SmppLog;
|
||||
|
||||
loggedIn = false;
|
||||
/** What the peer declared when binding: 0x00 if it declared none, undefined before any bind. */
|
||||
|
||||
Reference in New Issue
Block a user