-
Notifications
You must be signed in to change notification settings - Fork 18
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!: full type checks, generation and publishing #18
Conversation
resolved ipld/js-ipld-garbage#1 as v3.0.0, all ✅ now |
@Gozala I'm trying to reconcile some of your comments in #16 with the interface we defined in https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts in this PR, but the naming complicates nice /**
* @template T
* @param {T} node
* @returns {Uint8Array}
*/
export function encode<T>(node: T): Uint8Array;
/**
* @template T
* @param {Uint8Array} data
* @returns {T}
*/
export function decode<T>(data: Uint8Array): T;
/** @type {0x71} */
export const code: 0x71;
/** @type {'dag-cbor'} */
export const name: 'dag-cbor';
export const decoder: import("multiformats/codecs/interface").BlockDecoder<113, any>;
export const encoder: import("multiformats/codecs/interface").BlockEncoder<113, any>;
//# sourceMappingURL=index.d.ts.map Is that going to be good enough for anything that says it wants a |
I would expect so, but might be worth double checking, just in case.
I’m not entirely sure anymore to be honest. Mainly const foo<C, T>(codec: Codec<C, T>, ... as opposed to const foo<C, T>(codec: BlockEncoder<C, T> & BlockDecoder<C, T>... But now that BlockCodec also has encoder and decoder properties two are no longer equivalent and less verbose one is inconvenient because you can no longer do foo({ encode, decode }, ....) as signature also requires |
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've tried that as par of my unixfs effort and it passed the type checking as expected.
This is what we probably should have done to solve the conflict in cea9063 because we ended up with a `BlockCodec` that has too many properties and is therefore not very useful. This makes `BlockCodec` just an implementer of both `BlockEncoder` and `BlockDecoder` but `codec()` returns you that, plus `encoder` and `decoder` properties so you have all the things and can consume them however you like. Ref: ipld/js-dag-cbor#18 (comment)
This is what we probably should have done to solve the conflict in cea9063 because we ended up with a `BlockCodec` that has too many properties and is therefore not very useful. This makes `BlockCodec` just an implementer of both `BlockEncoder` and `BlockDecoder` but `codec()` returns you that, plus `encoder` and `decoder` properties so you have all the things and can consume them however you like. Ref: ipld/js-dag-cbor#18 (comment)
This is what we probably should have done to solve the conflict in cea9063 because we ended up with a `BlockCodec` that has too many properties and is therefore not very useful. This makes `BlockCodec` just an implementer of both `BlockEncoder` and `BlockDecoder` but `codec()` returns you that, plus `encoder` and `decoder` properties so you have all the things and can consume them however you like. Ref: ipld/js-dag-cbor#18 (comment)
42b163e
to
cc73645
Compare
@Gozala here's a rewind of what we did for the latest js-multiformats changes (removed I've also added to this PR a test/ts-use case that actually consumes the codec in 4 different ways to test the composability. I'd be grateful if you'd have a look (at |
The tests will pass with the multiformats/js-multiformats#75 branch's
so it should be catching that composaibility point of |
These are actually pretty useful in terms of object capabilities stuff, I might have a codec but I might want to call the function which just requires decoder. This allows you to avoid reconstructing pieces and just pass them around. Argument could be made that maybe |
a50975d
to
f1eea96
Compare
updated to match latest, simplified form of the matches ipld/js-dag-pb#6 |
94aafed
to
e10cd26
Compare
BREAKING CHANGE: * remove `default` export, see below * check, generate and publish full TypeScript types * use multiformats@7 and its non-default exports and updated types * export types based on latest multiformats structure * publish with "main" Prior to this change this module was imported as ```js import dagcbor from '@ipld/dag-cbor' ``` Now it is imported as ```js import * as dagcbor from `@ipld/dag-cbor' ```
e10cd26
to
b5fd787
Compare
Builds in #16
depends on ipld/js-ipld-garbage#1 but I can't pull it in as a git dependency because it's compiled into a dist/ before publishing (you can symlink the dist/ as node_modules/ipld-garbage for it to work here).