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

Utility to query Snaps for conditions. #520

Merged
merged 7 commits into from
Mar 27, 2024
Merged

Conversation

mario-christopher
Copy link
Collaborator

This PR is for a Snap Query Utility.
Occasionally we have the need to query for Snaps that meet a condition or criteria - the main use-case being notifying a Snap Builder of an upcoming change or other reason.

The PR has 2 code files:

  • get-manifests.ts : The code in this file is used to download the manifest files of all Snaps. This will get called the first time or when a refresh of the manifests are needed. All the Snap manifests are then saved to a local JSON file (./data.json). Local storage is to avoid fetching Snap manifests every time we need to run a query.
  • query.ts : This file contains the query logic that we are interested in, and works on the ./data.json file.

Usage:

yarn run query-snaps

options:
--force-download : This forces a download of all Snap manifests (refresh).

@mario-christopher mario-christopher requested a review from a team as a code owner March 26, 2024 01:03
.eslintrc.js Outdated
@@ -32,5 +32,6 @@ module.exports = {
'dist/',
'docs/',
'.yarn/',
'scripts/query/',
Copy link
Member

Choose a reason for hiding this comment

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

Why is this ignored?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Query uses fs, path and process to manage local file writes, reads and env vars.
This violates the eslint rules. So we can either relax the eslint rules or we can ignore it for the Query files.
Please let me know if there is another option.

Copy link
Member

Choose a reason for hiding this comment

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

If you change

files: ['*.js', 'scripts/*.ts'],

to

files: ['*.js', 'scripts/**/*.ts'],

a little further up in the config, and remove this line, most of the lint errors will be fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.
Fixed as per your suggestion. 👍

.gitignore Outdated Show resolved Hide resolved
scripts/query/query.ts Show resolved Hide resolved
);

const location = detectSnapLocation(snap.id, {
versionRange: latestVersion as any,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this type cast necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@@ -0,0 +1,41 @@
import type { SnapManifest } from '@metamask/snaps-utils';
import fs from 'fs';
Copy link
Member

Choose a reason for hiding this comment

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

If you import from fs/promises, you can just use fs.readFile instead of fs.promises.readFile.

Suggested change
import fs from 'fs';
import fs from 'fs/promises';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@mario-christopher mario-christopher merged commit e5f6459 into main Mar 27, 2024
16 checks passed
@mario-christopher mario-christopher deleted the query-snaps-util branch March 27, 2024 19:34
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.

2 participants