Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Recent small spec changes #213

Merged
merged 9 commits into from
Mar 27, 2024
Merged

Recent small spec changes #213

merged 9 commits into from
Mar 27, 2024

Conversation

diehuxx
Copy link

@diehuxx diehuxx commented Mar 26, 2024

Implement spec changes from this PR: TBD54566975/tbdex#269

There are currently no up-to-date test vectors for RFQ and Offerings. We can't create functioning test vectors until 2 tbdex SDKs have implemented these changes. I would prefer to take the following approach:

  1. Merge these changes so this PR does not remain pending
  2. Implement or have another engineer implement these changes in JS and KT
  3. Regenerate and validate the test vectors in question
  4. Open a new PR against tbdex-js to add the vectors.

Commits

issue tbdex commits tbdex-js commits
260 f55c588, 752aa4f 87c4162
261 9dc5148 1d82302
262 ff03448 85636b3
263 0614cf5 80da7b
253 5c1e67a fceb7aca

Copy link

changeset-bot bot commented Mar 26, 2024

⚠️ No Changeset found

Latest commit: 7540d80

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

fs.writeFileSync(path.join(__dirname, '../generated/compiled-validators.cjs'), moduleCode)
Copy link
Author

Choose a reason for hiding this comment

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

When I updated the tbdex submodule to bring in the changes, I got a warning when running tbdex-js tests that compiled-validators.js was being read as ES and that was causing error. It fixed when I switched this to cjs. Seeking feedback if this is not the right thing to do here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@frankhinek would know for sure, but I think if the is the only place it could be a problem and not work in certain environments ?

@codecov-commenter
Copy link

codecov-commenter commented Mar 26, 2024

Codecov Report

Merging #213 (7540d80) into main (74b6ade) will decrease coverage by 0.58%.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #213      +/-   ##
==========================================
- Coverage   93.53%   92.96%   -0.58%     
==========================================
  Files          39       39              
  Lines        3141     3142       +1     
  Branches      356      355       -1     
==========================================
- Hits         2938     2921      -17     
- Misses        203      221      +18     
Components Coverage Δ
protocol 93.21% <100.00%> (-1.06%) ⬇️
http-client 94.83% <ø> (ø)
http-server 91.05% <100.00%> (ø)

Copy link
Contributor

github-actions bot commented Mar 26, 2024

TBDocs Report

✅ No errors or warnings

@tbdex/protocol

  • Project entry file: packages/protocol/src/main.ts

@tbdex/http-client

  • Project entry file: packages/http-client/src/main.ts

@tbdex/http-server

  • Project entry file: packages/http-server/src/main.ts

TBDocs Report Updated at 2024-03-27T01:40:09Z 7540d80

@diehuxx diehuxx changed the title Issue 211 Recent small spec changes Mar 26, 2024
@KendallWeihe
Copy link
Contributor

253 is implemented here in tbdex-js via the JSON Schema, yeah?

Copy link
Contributor

@KendallWeihe KendallWeihe left a comment

Choose a reason for hiding this comment

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

💯

requiredPaymentDetails : {
$schema : 'http://json-schema.org/draft-07/schema',
type : 'object',
properties : {
Copy link
Contributor

Choose a reason for hiding this comment

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

do you normally need billing address for this?

Copy link
Author

Choose a reason for hiding this comment

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

I think in a real-life card payment the PFI might need the billing address, but for the purposes of this dummy test data it doesn't matter either way.

@@ -1,6 +1,6 @@
import type { ErrorObject } from 'ajv'
// validator functions are compiled at build time. check ./build/compile-validators.js for more details
import * as compiledValidators from '../generated/compiled-validators.js'
import * as compiledValidators from '../generated/compiled-validators.cjs'
Copy link
Contributor

Choose a reason for hiding this comment

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

only place in the code where we import a cjs right?

Maybe as a workaround / fix we can just make a normal .ts validator file? Why do we have to build a dynamic validation file?

Copy link
Contributor

Choose a reason for hiding this comment

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

@nitro-neal not all runtimes allow you to read files. this is especially the case in constrained CSP environments

Copy link
Author

Choose a reason for hiding this comment

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

Yep it's the only cjs import that I know of.

Maybe as a workaround / fix we can just make a normal .ts validator file?

I don't think we can, though there may be a neckbeard magic way. We're generating compiled-validators.*s using ajv's standaloneCode function. We're setting the esm: true option when generating the validation code, but it's still spitting out CJS for whatever reason. If we change the file extension to .ts, then that would technically be valid .ts since typescript is a superset of javascript. But the typescript compiler only knows how to transpile compiled-validators.ts into CJS. It can't turn that CJS-ts into ESM AFAIU.

Why do we have to build a dynamic validation file?

There's a few benefits to doing it this way, laid out in the ajv documentation here. But the gist is it's better for browsers to do this work at build time.

Copy link
Contributor

@nitro-neal nitro-neal left a comment

Choose a reason for hiding this comment

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

Looks good! Just double check if that cjs is all good to go

Co-authored-by: nitro-neal <[email protected]>
@@ -22,7 +22,7 @@ describe('TbdexTestVectorsProtocol', function () {
expect(close.toJSON()).to.deep.eq(ParseClose.output)
})

it('parse_offering', async() => {
it.skip('parse_offering', async() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't skip tests.

Copy link
Author

@diehuxx diehuxx Mar 26, 2024

Choose a reason for hiding this comment

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

There are no up-to-date test vectors for this test. We can't create functioning test vectors until 2 tbdex SDKs have implemented these changes. I would prefer to take the following approach:

  1. merge these changes so this PR does not remain pending
  2. implement or have another engineer implement these changes in JS and KT
  3. Regenerate and validate the test vectors in question
  4. Open a new PR against tbdex-js to add the vectors.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should include this information in the PR description.

Copy link
Author

Choose a reason for hiding this comment

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

Fair enough. Added.

@@ -70,7 +70,7 @@ describe('TbdexTestVectorsProtocol', function () {
expect(quote.toJSON()).to.deep.eq(ParseQuote.output)
})

it('parse_rfq', async () => {
it.skip('parse_rfq', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto - Please don't skip tests.

Copy link
Author

Choose a reason for hiding this comment

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

@kirahsapong
Copy link
Contributor

Re: using cjs -
Ajv injects require syntax in the generated code after introducing an externally resolved json schema $ref that appears twice in the offering schema. You either need to transform mixed syntax or use cjs or other. There are avenues

@diehuxx
Copy link
Author

diehuxx commented Mar 26, 2024

You either need to transform mixed syntax or use cjs or other. There are avenues

Which approach/avenue do you recommend? Does the approach I took fall into the category of using cjs or are you referring another possible approach?

@kirahsapong
Copy link
Contributor

Which approach/avenue do you recommend? Does the approach I took fall into the category of using cjs or are you referring another possible approach?

Yes this approach falls in the category of using cjs.

@diehuxx
Copy link
Author

diehuxx commented Mar 26, 2024

Which approach/avenue do you recommend? Does the approach I took fall into the category of using cjs or are you referring another possible approach?

Yes this approach falls in the category of using cjs.

Which approach/avenue you recommend?

@kirahsapong
Copy link
Contributor

Ajv injects require syntax in the generated code after introducing an externally resolved json schema $ref that appears twice in the offering schema. You either need to transform mixed syntax or use cjs or other. There are avenues

Which approach/avenue do you recommend? Does the approach I took fall into the category of using cjs or are you referring another possible approach?

Yes this approach falls in the category of using cjs.

Which approach/avenue you recommend?

You need to weigh the tradeoffs. I would think about what provides the smallest immediate lift with minimal drawbacks if getting this PR in shortly is a priority. If it isn't ideal longterm, I would consider that too.

@mistermoe
Copy link
Contributor

@diehuxx we've configured ajv to output esm which y'all can see here. if ajv is returning some cjs that means there's a bug in their codegen. have we checked ajv github issues?

@mistermoe
Copy link
Contributor

@diehuxx i would build dist and then set up a test script that consumes what's built to make sure that there's no issues. if all good on that front, i'd merge this and create an issue to tackle the ajv thing later.

@diehuxx
Copy link
Author

diehuxx commented Mar 27, 2024

@diehuxx we've configured ajv to output esm which y'all can see here. if ajv is returning some cjs that means there's a bug in their codegen. have we checked ajv github issues?

@mistermoe Good call. There's an open issue in ajv about esm generation being broken. ajv-validator/ajv#2209, but looks like a couple people posted workarounds in the comments. I'm going to give those a try.

@diehuxx
Copy link
Author

diehuxx commented Mar 27, 2024

Just pushed a brute force solution to the ESM compiled validators issue. I added some lines to packages/protocol/build/compile-validators.js which convert all requires into imports.

@diehuxx diehuxx merged commit 02ce905 into main Mar 27, 2024
6 checks passed
@diehuxx diehuxx deleted the issue-211 branch March 27, 2024 02:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants