Skip to content

Commit

Permalink
update validtor to cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
kirahsapong committed Mar 25, 2024
1 parent 77954d8 commit ef61bb3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/protocol/build/compile-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { mkdirp } from 'mkdirp'
import CloseSchema from '../../../tbdex/hosted/json-schemas/close.schema.json' assert { type: 'json' }
import DefinitionsSchema from '../../../tbdex/hosted/json-schemas/definitions.json' assert { type: 'json' }
import OfferingSchema from '../../../tbdex/hosted/json-schemas/offering.schema.json' assert { type: 'json' }
// TODO: uncomment once sdk up to latest spec offering schema
// TODO: uncomment once sdk up to latest spec
// import BalanceSchema from '../../../tbdex/hosted/json-schemas/balance.schema.json' assert { type: 'json' }
import MessageSchema from '../../../tbdex/hosted/json-schemas/message.schema.json' assert { type: 'json' }
import OrderSchema from '../../../tbdex/hosted/json-schemas/order.schema.json' assert { type: 'json' }
Expand All @@ -33,7 +33,7 @@ const schemas = {
close : CloseSchema,
definitions : DefinitionsSchema,
offering : OfferingSchema,
// TODO: uncomment once sdk up to latest spec offering schema
// TODO: uncomment once sdk up to latest spec
// balance : BalanceSchema,
message : MessageSchema,
order : OrderSchema,
Expand All @@ -53,4 +53,4 @@ const moduleCode = standaloneCode(validator)
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

await mkdirp(path.join(__dirname, '../generated'))
fs.writeFileSync(path.join(__dirname, '../generated/compiled-validators.js'), moduleCode)
fs.writeFileSync(path.join(__dirname, '../generated/compiled-validators.cjs'), moduleCode)
2 changes: 1 addition & 1 deletion packages/protocol/src/validator.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
* validates the payload against a json schema identified by name
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/tests/balance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO: uncomment once sdk up to latest spec offering schema
// TODO: uncomment once sdk up to latest spec
// import { Balance, Parser } from '../src/main.js'
// import { DevTools } from '../src/dev-tools.js'
// import { Convert } from '@web5/common'
Expand Down
23 changes: 11 additions & 12 deletions packages/protocol/tests/generate-test-vectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,18 @@ const generateParseOfferingVector = async () => {
}
}

// TODO: uncomment once sdk up to latest spec offering schema
// const generateParseBalanceVector = async () => {
// const balance = DevTools.createBalance({ from: pfiDid.uri })
const generateParseBalanceVector = async () => {
const balance = DevTools.createBalance({ from: pfiDid.uri })

// await balance.sign(pfiDid)
await balance.sign(pfiDid)

// return {
// description : 'Balance parses from string',
// input : JSON.stringify(balance.toJSON()),
// output : balance.toJSON(),
// error : false,
// }
// }
return {
description : 'Balance parses from string',
input : JSON.stringify(balance.toJSON()),
output : balance.toJSON(),
error : false,
}
}

const generateParseQuoteVector = async () => {

Expand Down Expand Up @@ -177,7 +176,7 @@ const overWriteTestVectors = async () => {
// Add more test vector generators as you need them. This is not a complete list.
const vectorFilePair: { filename: string, vector: TestVector }[] = [
{ filename: 'parse-offering.json', vector: await generateParseOfferingVector() },
// TODO: uncomment once sdk up to latest spec offering schema
// TODO: uncomment once sdk up to latest spec
// { filename: 'parse-balance.json', vector: await generateParseBalanceVector() },
{ filename: 'parse-quote.json', vector: await generateParseQuoteVector() },
{ filename: 'parse-close.json', vector: await generateParseCloseVector() },
Expand Down

0 comments on commit ef61bb3

Please sign in to comment.