-
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 encoding and decoding methods to IdInternal
#11
Conversation
I can't quite get the encode/decode feature to work nicely so we're stuck with to/fromMultibase and wrapping them. But I have added this neat feature were we can create an Opaque type directly when converting by doing // where
type NodeId = Opaque<'nodeId', Id>;
// we can do
const nodeId = internalId.fromBuffer<NodeId>(buffer);
// or
const nodeid2: NodeId = InternalId.fromBuffer(buffer); Any method that returns an |
This is still a WIP. I'm still making changes. |
It may be possible to extend type NodeId = InternalNodeid & number;
class internalNodeId extends InternalId {
public readonly base: MultibaseFormats = 'base58btc';
} The encode and decode functions can be built into The alternative is to just have the utility functions for each domain to encode/decode. |
It's not necessary, it would just be a nice to have. We can proceed to merge this with just the relevant instance and static methods added in here. We keep using |
Id
IdInternal
@tegefaulkes Changed PR title to be more clearer. You should try to be more descriptive on those PR names. |
f79f3ac
to
27a1967
Compare
Examples of new features. All of the type coverters are in one place now in the IdInternal class. IdInternal.fromBuffer();
IdInternal.fromString();
IdInternal.fromUUID();
IdInternal.fromMultibase();
const id = IdInternal.create();
id.toBuffer();
id.toString();
id.toUUID();
id.toMultibase('someRandomBase'); Any constructors for a Id can create an opaque type directly now by using type OpaqueId<'opaqueId', Id>
const opaqueId = IdInternal.create<OpaqueId>();
const opaqueId: OpaqueId = idInternal.create();
// Same for conversions from other types
const opaqueId = IdInternal.fromBuffer<OpaqueId>();
const opaqueId: OpaqueId = IdInternal.fromString();
// The original way still works
const id = IdInternal.create() as OpaqueId; The id generators can do the same thing. type OpaqueId = Opaque<'opaque', Id>;
const idGen = new IdRandom<OpaqueId>();
// ids has type OpaqueId[]
const ids = [...utils.take(idGen, 10)]; |
27a1967
to
8641a5f
Compare
All review comments are resolved. should be good to merge. |
Description
This adds some QOL features to the
Id
andIdInternal
.Issues Fixed
NodeId
from encoded string to an opaque alias ofId
which is a typed array from js-id Polykey#318GenericIdTypes.ts
Polykey#299Tasks
InternalId
Id
Final checklist