-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: add Agent Manager to utils package #731
base: main
Are you sure you want to change the base?
feat: add Agent Manager to utils package #731
Conversation
size-limit report 📦
|
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.
Cool idea!
}, | ||
})); | ||
|
||
jest.mock("./nullish.utils", () => ({ |
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.
You need to mock this?
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.
apparently yes... when i ran the test without, it said that it couldn't find it... I will re-try and let you know
@@ -42,3 +42,102 @@ export const createAgent = async ({ | |||
shouldFetchRootKey: fetchRootKey, | |||
}); | |||
}; | |||
|
|||
export interface AgentManagerConfig { |
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.
In another PR, we should extract an interface for all the paramters of @dfinity/utils.createAgent
and this interface become a subtype of this new interface.
export type AgentManagerConfig = Omit<NewInterface, 'identity'>
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.
ah! right! shall i do it before this one? i think it would be a fast one
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.
Sure, go for 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.
In addition:
|
|
Yes at the top, in
Nvm, my bad. Assumed it was a brand new separate module. All good. |
Motivation
It is a simple but useful class to manage multiple HTTP agents associated with identities.
Credits
The original scripts were created by @peterpeterparker in the OISY repo. This is just a transposition to a re-usable utility.
Changes
New
AgentManager
class with:create
method: static constructor.createAgent
method: as the name suggests, it creates a new HTTP but do not cache it.getAgent
method: it fetches the HTTP agent among the cached, and if does note exists, it creates it and cache it.clearAgents
method: clean slate.Tests
I created a few tests for the few usecases.
Todos