Skip to content

Add type declarations. - #69

Merged
ramhr merged 6 commits into
masterfrom
types
Mar 11, 2024
Merged

ramhr merged 6 commits into
masterfrom
types

Conversation

@ramhr

@ramhr ramhr commented Mar 6, 2024 •

Copy link
Copy Markdown
Contributor

Tested the type with several projects I have locally and everything compiles.

I had to fight the compiler very hard until I got to a definition that worked everywhere.

Comment thread tsconfig.json
Comment thread types/index.d.ts Outdated
Comment thread types/modules/arnavmq.d.ts Outdated
Comment thread types/modules/channels.d.ts Outdated
Comment thread types/modules/channels.d.ts Outdated
Comment thread types/modules/channels.d.ts Outdated
Comment on lines +23 to +26
constructor(name: any, config: any);
name: any;
config: any;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
constructor(name: any, config: any);
name: any;
config: any;
}
constructor(name: string, config: any);
public readonly name: string;
public readonly config: any;
}

and please type config

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ramhr what about this ?

Comment thread types/modules/consumer.d.ts Outdated
Comment thread types/modules/consumer.d.ts Outdated
Comment thread types/modules/hooks/base_hooks.d.ts Outdated
import type amqp = require('amqplib');
import pDefer = require('p-defer');

declare class Producer {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please private modifiers where appropriate.. checkRpcQueue / maybeAnswer / etc .. should be private.

@yosiat yosiat assigned ramhr and unassigned yosiat Mar 6, 2024
@ramhr ramhr assigned yosiat and unassigned ramhr Mar 7, 2024
Comment thread types/modules/arnavmq.d.ts Outdated
import { Connection } from './connection';
import { ConnectionHooks, ConsumerHooks, ProducerHooks } from './hooks';

declare function arnavmq(connection: any): arnavmq.Arnavmq;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why connection is any here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sorry, missed it

Comment thread types/modules/channels.d.ts Outdated
Comment on lines +23 to +26
constructor(name: any, config: any);
name: any;
config: any;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ramhr what about this ?

Comment thread types/modules/producer.d.ts Outdated
*
* [queue: string] -> [correlationId: string] -> {responsePromise, timeoutId}
*/
amqpRPCQueues: Record<

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
amqpRPCQueues: Record<
private amqpRPCQueues: Record<

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

also added readonly


declare class Producer {
constructor(connection: Connection);
hooks: ProducerHooks;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
hooks: ProducerHooks;
private hooks: ProducerHooks;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are actually public so you can add hooks to the producer, and it's exposed on the arnavmq object.

Comment thread types/modules/producer.d.ts Outdated
Record<string, { responsePromise: pDefer.DeferredPromise<unknown>; timeoutId: NodeJS.Timeout }>
>;
private _connection: Connection;
set connection(value: Connection);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't think we should allow setting connection ..

Suggested change
set connection(value: Connection);
private set connection(value: Connection);

@ramhr ramhr Mar 10, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is actually used internally to replace the connection so it's not really private.
This should be cleaned as part of #68 since the replaced collection is always the same instance anyways and it doesn't make sense to even have this option, but on it's singleton form now that's how it is.

instance.connection = connection;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't expect someone to do arnavmq.producer.connection = ..., and if so I would consider it as bad practice.

I think it should be ok to mark it as private, and if once we move to TypeScript, have the connection be accepted at the constructor and don't expose it.

@yosiat yosiat assigned ramhr and unassigned yosiat Mar 10, 2024
@ramhr ramhr assigned yosiat and unassigned yosiat Mar 10, 2024

@yosiat yosiat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR is important to defining our external API, so it's important that we mark public/private correctly.

I think connection should be made private (#69 (comment)) prior to merging, but I won't block the merge here.

@yosiat yosiat removed their assignment Mar 10, 2024
Comment thread package.json
"types": "types/index.d.ts",
"scripts": {
"lint": "eslint . && prettier -c .",
"lint": "eslint . && prettier -c . && tsc --project types/tsconfig.types.json",

@shamil shamil Mar 10, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how lint relates to types?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't really build the project, just makes sure the types are well formed. I think it's too much to add a "build" step to it.

@shamil shamil removed their assignment Mar 10, 2024
It is used internally, not privately, but it makes sense to make it private on the types.
@ramhr
ramhr merged commit 013e8c1 into master Mar 11, 2024
@ramhr
ramhr deleted the types branch March 11, 2024 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants