Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add types definitions #76

Merged
merged 11 commits into from
Mar 5, 2021
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "8.1.2",
"description": "The spec for an Aedes persistence, with abstract tests and a fast in-memory implementation.",
"main": "persistence.js",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard --verbose | snazzy",
"lint-fix": "standard --fix",
Expand Down Expand Up @@ -58,6 +59,7 @@
"node": ">=10"
},
"devDependencies": {
"aedes": "^0.44.2",
robertsLando marked this conversation as resolved.
Show resolved Hide resolved
"concat-stream": "^2.0.0",
"faucet": "0.0.1",
"license-checker": "^25.0.1",
Expand Down
153 changes: 153 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import type { Client } from 'aedes';
import type { AedesPacket } from 'aedes-packet';
import type { Readable } from 'stream';

export type { AedesPacket as Packet } from 'aedes-packet';

export interface AedesPersistenceSubscription {
clientId?: string;
topic: string;
qos: number;
}
getlarge marked this conversation as resolved.
Show resolved Hide resolved
getlarge marked this conversation as resolved.
Show resolved Hide resolved

export interface Brokers {
[brokerId: string]: {
brokerId: string;
};
}
getlarge marked this conversation as resolved.
Show resolved Hide resolved
getlarge marked this conversation as resolved.
Show resolved Hide resolved

interface WillPacket extends AedesPacket {
[key: string]: any;
}

interface Incoming {
[clientId: string]: { [messageId: string]: AedesPacket };
}

declare class AedesMemoryPersistence {
private _retained: AedesPacket[];
private _subscriptions: Map<string, AedesPersistenceSubscription>;
private _clientsCount: number;
private _trie: any;
private _outgoing: Record<string, AedesPacket[]>;
private _incoming: Incoming;
private _wills: Record<string, WillPacket>;
getlarge marked this conversation as resolved.
Show resolved Hide resolved

constructor();

storeRetained: (
packet: AedesPacket,
cb: (error: Error | null) => void
) => void;

createRetainedStream: (pattern: string) => Readable;

createRetainedStreamCombi: (patterns: string[]) => Readable;

addSubscriptions: (
client: Client,
subs: AedesPersistenceSubscription[],
cb: (error: Error | null, client: Client) => void
) => void;

removeSubscriptions: (
client: Client,
subs: AedesPersistenceSubscription[],
cb: (error: Error | null, client: Client) => void
) => void;

subscriptionsByClient: (
client: Client,
cb: (
error: Error | null,
subs: AedesPersistenceSubscription[],
client: Client
) => void
) => void;

countOffline: (
cb: (
error: Error | null,
subscriptionsCount: number,
clientsCount: number
) => void
) => void;

subscriptionsByTopic: (
pattern: string,
cb: (error: Error | null, subs: AedesPersistenceSubscription[]) => void
) => void;

cleanSubscriptions: (
client: Client,
cb: (error: Error | null, client: Client) => void
) => void;

outgoingEnqueue: (
sub: AedesPersistenceSubscription,
packet: AedesPacket,
cb: (error: Error | null) => void
) => void;

outgoingEnqueueCombi: (
subs: AedesPersistenceSubscription[],
packet: AedesPacket,
cb: (error: Error | null) => void
) => void;

outgoingUpdate: (
client: Client,
packet: AedesPacket,
cb: (error: Error | null, client: Client, packet: AedesPacket) => void
) => void;

outgoingClearMessageId: (
client: Client,
packet: AedesPacket,
cb: (error?: Error | null, packet?: AedesPacket) => void
) => void;

outgoingStream: (client: Client) => Readable;

incomingStorePacket: (
client: Client,
packet: AedesPacket,
cb: (error: Error | null) => void
) => void;

incomingGetPacket: (
client: Client,
packet: AedesPacket,
cb: (error: Error | null, packet: AedesPacket) => void
) => void;

incomingDelPacket: (
client: Client,
packet: AedesPacket,
cb: (error: Error | null) => void
) => void;

putWill: (
client: Client,
packet: AedesPacket,
cb: (error: Error | null, client: Client) => void
) => void;

getWill: (
client: Client,
cb: (error: Error | null, will: any, client: Client) => void
) => void;

delWill: (
client: Client,
cb: (error: Error | null, will: any, client: Client) => void
) => void;

streamWill: (brokers: Brokers) => Readable;

getClientList: (topic: string) => Readable;

destroy: (cb?: () => void) => void;
getlarge marked this conversation as resolved.
Show resolved Hide resolved
}

export default function aedesMemoryPersistence(): AedesMemoryPersistence;