Skip to content
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(zoe): add type inference for issuerKeywordRecord in ZCF #9330

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

0xpatrickdev
Copy link
Member

@0xpatrickdev 0xpatrickdev commented May 7, 2024

closes: #XXXX
refs: #XXXX

Description

  • adds IKR (IssuerKeywordRecord) generic parameter to ZCF to enable type inference for issuers and brands from contract terms
    • low priority, but seems helpful for contracts that rely on predefined keyword records like Collateral or In.

Security Considerations

Scaling Considerations

Documentation Considerations

Testing Considerations

Upgrade Considerations

- update ZCF type to accept a generic parameter for issuerKeywordRecord (IKR)
- modify StandardTerms and related types to use the issuerKeywordRecord generic
- preserve existing default of `<Keyword, <Issuer<any>>` when IKR parameter is undefined
Copy link

cloudflare-pages bot commented May 7, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: b0e7088
Status: ✅  Deploy successful!
Preview URL: https://4a6f47cb.agoric-sdk.pages.dev
Branch Preview URL: https://pc-zcf-ikr-generic.agoric-sdk.pages.dev

View logs

type ZCF<CT extends unknown = Record<string, unknown>> = {
type ZCF<
CT extends unknown = Record<string, unknown>,
IKR extends Record<Keyword, AssetKind> = Record<Keyword, any>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope you'll add some docs.

(again, it sure would be nice to be able to re-use the examples from the tests as docs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get a type annotated example to play nicely (js doc comment inception), but included some documentation additions in fd4fb78 and b0e7088

@0xpatrickdev 0xpatrickdev marked this pull request as ready for review May 8, 2024 18:57
Comment on lines -16 to -18
* @typedef {Record<Keyword, Issuer<any>>} IssuerKeywordRecord
* @typedef {Record<Keyword, ERef<Issuer<any>>>} IssuerPKeywordRecord
* @typedef {Record<Keyword, Brand<any>>} BrandKeywordRecord
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these types should be maintained.

when there is a more specific type, it's a concrete type that extends this more general one, not a parameterization of this.

*/

/**
* @template {Record<Keyword, AssetKind>} [IKR=Record<Keyword, any>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @template {Record<Keyword, AssetKind>} [IKR=Record<Keyword, any>]
* @template {IssuerKeywordRecord} [IKR=IssuerKeywordRecord]

* @typedef {object} StandardTerms
* @property {IssuerKeywordRecord} issuers - record with
* @property {IssuerKeywordRecord<IKR>} issuers - record with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @property {IssuerKeywordRecord<IKR>} issuers - record with
* @property {IKR} issuers - record with

* keywords keys, issuer values
* @property {BrandKeywordRecord} brands - record with keywords
* @property {BrandKeywordRecord<IKR>} brands - record with keywords
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one will take a little type-fu to make a BrandKeywordRecord from an IssuerKeywordRecord. that can be a utility type.

the upside is that brands will be the actual brands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants