-
Notifications
You must be signed in to change notification settings - Fork 9
Recent small spec changes #213
Conversation
|
fs.writeFileSync(path.join(__dirname, '../generated/compiled-validators.cjs'), moduleCode) |
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.
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.
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.
@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 Report
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
|
TBDocs Report ✅ No errors or warnings @tbdex/protocol
@tbdex/http-client
@tbdex/http-server
TBDocs Report Updated at 2024-03-27T01:40:09Z |
253 is implemented here in tbdex-js via the JSON Schema, yeah? |
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.
💯
requiredPaymentDetails : { | ||
$schema : 'http://json-schema.org/draft-07/schema', | ||
type : 'object', | ||
properties : { |
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.
do you normally need billing address for this?
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 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.
packages/protocol/src/validator.ts
Outdated
@@ -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' |
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.
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?
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.
@nitro-neal not all runtimes allow you to read files. this is especially the case in constrained CSP environments
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.
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.
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.
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() => { |
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.
Please don't skip tests.
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.
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:
- merge these changes so this PR does not remain pending
- implement or have another engineer implement these changes in JS and KT
- Regenerate and validate the test vectors in question
- Open a new PR against tbdex-js to add the vectors.
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.
You should include this information in the PR description.
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.
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 () => { |
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.
Ditto - Please don't skip tests.
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.
Ditto #213 (comment)
Re: using cjs - |
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. |
@diehuxx i would build |
@mistermoe Good call. There's an open issue in |
Just pushed a brute force solution to the ESM compiled validators issue. I added some lines to |
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:
Commits