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

Type fixes needed to make matrix-appservice-irc build #196

Merged
merged 7 commits into from
Aug 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
expose StateLookupEvent, make some parameters optional
  • Loading branch information
Half-Shot committed Aug 10, 2020
commit 06d59ef123b0e6dc660bc6431b61a70a8b342c8e
7 changes: 4 additions & 3 deletions src/components/state-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import PQueue from "p-queue";
interface StateLookupOpts {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
client: any; //TODO: Needs to be MatrixClient (once that becomes TypeScript)
stateLookupConcurrency: number;
stateLookupConcurrency?: number;
eventTypes?: string[];
retryStateInMs?: number;
}
Expand All @@ -33,14 +33,15 @@ interface StateLookupRoom {
};
}

interface StateLookupEvent {
export interface StateLookupEvent {
// eslint-disable-next-line camelcase
room_id: string;
// eslint-disable-next-line camelcase
state_key: string;
type: string;
// eslint-disable-next-line camelcase
event_id: string;
content: unknown;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is content guaranteed to be an Object or claimed as here unknown? That would require some more type checks in my PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably call it a Record<string,unknown>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if that's not guaranteed by the client lib, we'll get errors like the one #155 fixes, where a presumed object may be a string or a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content should really never be anything other than a object, if it is, we should reject it before insertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

const RETRY_STATE_IN_MS = 300;
Expand Down Expand Up @@ -96,7 +97,7 @@ export class StateLookup {
* array of events, which may be empty.
* @return {?Object|Object[]}
*/
public getState(roomId: string, eventType: string, stateKey?: string): unknown|unknown[] {
public getState(roomId: string, eventType: string, stateKey?: string): null|StateLookupEvent|StateLookupEvent[] {
const r = this.dict[roomId];
if (!r) {
return stateKey === undefined ? [] : null;
Expand Down