dfinity / agent-js

A collection of libraries and tools for building software around the Internet Computer, in JavaScript.
https://agent-js.icp.xyz
Apache License 2.0
151 stars 94 forks source link

feat: deprecate `HttpAgent` constructor in favor of new `create` #873

Closed krpeacock closed 2 months ago

krpeacock commented 4 months ago

Description

Following the pattern used by other interfaces in the library, this function switches to an async create method, that will be able to make the syncTime and fetchRootKey calls before completing. This will also support future async setup calls if needed in the future. createSync initializes the agent but skips any async steps, and is useful for testing or more sophisticated applications

The agent also has a from method, and will support either the v1 or v2 agent interfaces.

The HttpAgent also switches to true es6 private class fields, and will formally reveal its config and its host as fields. This supports the from method, but the _-prefixed methods from older HttpAgents will be supported.

Note: the constructor is marked deprecated in this PR. Existing code will not break yet, but will inform the developer that they should switch to create orcreateSync`.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Checklist:

github-actions[bot] commented 4 months ago

size-limit report 📦

Path Size
@dfinity/agent 86 KB (+0.08% 🔺)
@dfinity/candid 13.58 KB (0%)
@dfinity/principal 4.97 KB (0%)
@dfinity/auth-client 60.84 KB (+0.08% 🔺)
@dfinity/assets 80.65 KB (+0.07% 🔺)
@dfinity/identity 58.03 KB (+0.06% 🔺)
@dfinity/identity-secp256k1 266.58 KB (+0.05% 🔺)
krpeacock commented 3 months ago

@roelstorms