-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add type declarations. #69
Conversation
types/modules/channels.d.ts
Outdated
constructor(name: any, config: any); | ||
name: any; | ||
config: any; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramhr what about this ?
import type amqp = require('amqplib'); | ||
import pDefer = require('p-defer'); | ||
|
||
declare class Producer { |
There was a problem hiding this comment.
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.
types/modules/arnavmq.d.ts
Outdated
import { Connection } from './connection'; | ||
import { ConnectionHooks, ConsumerHooks, ProducerHooks } from './hooks'; | ||
|
||
declare function arnavmq(connection: any): arnavmq.Arnavmq; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, missed it
types/modules/channels.d.ts
Outdated
constructor(name: any, config: any); | ||
name: any; | ||
config: any; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramhr what about this ?
types/modules/producer.d.ts
Outdated
* | ||
* [queue: string] -> [correlationId: string] -> {responsePromise, timeoutId} | ||
*/ | ||
amqpRPCQueues: Record< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amqpRPCQueues: Record< | |
private amqpRPCQueues: Record< |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hooks: ProducerHooks; | |
private hooks: ProducerHooks; |
There was a problem hiding this comment.
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.
types/modules/producer.d.ts
Outdated
Record<string, { responsePromise: pDefer.DeferredPromise<unknown>; timeoutId: NodeJS.Timeout }> | ||
>; | ||
private _connection: Connection; | ||
set connection(value: Connection); |
There was a problem hiding this comment.
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 ..
set connection(value: Connection); | |
private set connection(value: Connection); |
There was a problem hiding this comment.
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.
node-arnavmq/src/modules/arnavmq.js
Line 49 in 35a8461
instance.connection = connection; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
"scripts": { | ||
"lint": "eslint . && prettier -c .", | ||
"lint": "eslint . && prettier -c . && tsc --project types/tsconfig.types.json", |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
It is used internally, not privately, but it makes sense to make it private on the types.
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.