-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support Frequency schema names #46
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9649cf5
Support Frequency schema names
a6da933
Address PR comments
40db31e
Correct explanation of "default" mapping
2d5b321
Update all dependency versions, but especially `api-augment` to 1.10.0.
638602c
Fix reference to this package.
df28127
Get better at handling rejection
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { getFrequencyAPI } from "./services/connect.js"; | ||
import { schemas } from "../dsnp/index.js"; | ||
|
||
const find = async () => { | ||
const api = await getFrequencyAPI(); | ||
|
||
console.log("\n## DSNP Schema Information"); | ||
|
||
const allDsnp = (await api.rpc.schemas.getVersions("dsnp")).unwrap(); | ||
for (const schemaEntry of schemas.entries()) { | ||
const schemaString = JSON.stringify(schemaEntry[1].model); | ||
const schemaVersionResult = allDsnp.filter( | ||
(versioned) => versioned.schema_name.toString() === "dsnp." + schemaEntry[0], | ||
); | ||
for (const version of schemaVersionResult) { | ||
const schemaResult = (await api.rpc.schemas.getBySchemaId(version.schema_id.toString())).unwrap(); | ||
const jsonSchema = Buffer.from(schemaResult.model).toString("utf8"); | ||
const { schema_id, model_type, payload_location, settings } = schemaResult; | ||
|
||
// Ensure that full entry details match, otherwise it's a different version | ||
if ( | ||
schemaString === jsonSchema && | ||
model_type.toHuman() === schemaEntry[1].modelType && | ||
payload_location.toHuman() === schemaEntry[1].payloadLocation && | ||
JSON.stringify(settings.toHuman()) === JSON.stringify(schemaEntry[1].settings) | ||
) { | ||
console.log(`\n## Schema Id ${schema_id}`); | ||
console.table( | ||
Object.entries({ | ||
schemaName: schemaEntry[0], | ||
dsnpVersion: schemaEntry[1].dsnpVersion, | ||
schemaId: schema_id.toHuman(), | ||
}).map(([key, value]) => ({ key, value })), | ||
); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export const main = async () => { | ||
await find(); | ||
}; | ||
|
||
main().catch(console.error).finally(process.exit); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
maybe not a big deal for your purposes but do you need to close the subscription?
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 so, for correctness. Probably doesn't matter too much since it's a run-and-done CLI program, but I wouldn't be surprised if there are some error logs that come out when the program is done that would be cleaned up with an
unsub()
call. I'll pull this branch and see...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 see no errors when I run; like I said, probably not a critical issue since this is CLI run-and-done. Fix if you like; non-blocking.
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 don't think we're actually subscribed here -- if the event is not immediately in the block or finalized, it looks like we never resolve or reject the Promise. Obviously this seems to work fine in an ideal environment (especially one with instant sealing) but I don't think it handles edge cases or busy chains very well.
I'd prefer to make that a separate issue though as it's a pre-existing condition, and maybe someone slightly more familiar with how to subscribe and poll could add this or give me some pointers.
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.
Added as #49