- 
                Notifications
    
You must be signed in to change notification settings  - Fork 230
 
          Feature | graph init Add support to download spkg files from spkg.io
          #1642
        
          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
          
     Closed
      
      
            joshuanazareth97
  wants to merge
  21
  commits into
  graphprotocol:main
from
joshuanazareth97:feature/graph-init-spkg-io-support
  
      
      
   
      
    
  
     Closed
                    Changes from 15 commits
      Commits
    
    
            Show all changes
          
          
            21 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      1541c32
              
                src/command-helpers: Add priority sort function
              
              
                joshuanazareth97 286a778
              
                src/command-helpers: Add priority sort tests
              
              
                joshuanazareth97 dbc2f94
              
                src/commands/init: Sort imports
              
              
                joshuanazareth97 70b799a
              
                src/commands/init: sort network choices before showing them to user
              
              
                joshuanazareth97 dd909e9
              
                remove jsdoc
              
              
                joshuanazareth97 dba1fa3
              
                src/command-helpers: improve priority sort JSDoc
              
              
                joshuanazareth97 4d63078
              
                Add changeset file
              
              
                joshuanazareth97 2e6448a
              
                Fix formatting
              
              
                joshuanazareth97 eb840d7
              
                Add file donwload utility
              
              
                joshuanazareth97 d995b1b
              
                Add url processing logic
              
              
                joshuanazareth97 cddafba
              
                Add spkg validation and processing utils
              
              
                joshuanazareth97 e4fdb3c
              
                Modify spkg prompt
              
              
                joshuanazareth97 74e2721
              
                Add imports
              
              
                joshuanazareth97 1d62121
              
                Merge branch 'main' of github.com:graphprotocol/graph-tooling into fe…
              
              
                joshuanazareth97 908438c
              
                Fix formatting error
              
              
                joshuanazareth97 461a3cd
              
                Add changeset file
              
              
                joshuanazareth97 239e528
              
                Update .changeset
              
              
                joshuanazareth97 8e13155
              
                Update spkg url validity check
              
              
                joshuanazareth97 5c7ac2d
              
                Merge branch 'feature/graph-init-spkg-io-support' of github.com:joshu…
              
              
                joshuanazareth97 91e488c
              
                Merge branch 'main' of github.com:graphprotocol/graph-tooling into fe…
              
              
                joshuanazareth97 7d24759
              
                src/command-helpers/download: Update download to use custom fetchwrapper
              
              
                joshuanazareth97 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 hidden or 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,5 @@ | ||
| --- | ||
| '@graphprotocol/graph-cli': patch | ||
| --- | ||
| 
     | 
||
| Order list of evm chains in graph init command | ||
  
    
      This file contains hidden or 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,13 @@ | ||
| import { createWriteStream } from 'fs'; | ||
| import { http } from 'gluegun'; | ||
| 
     | 
||
| export async function downloadFile(fileUrl: string, outputLocationPath: string) { | ||
| const writer = createWriteStream(outputLocationPath); | ||
| const api = http.create({ | ||
| baseURL: fileUrl, | ||
| }); | ||
| return api.get('', {}, { responseType: 'stream' }).then((response: any) => { | ||
| response.data.pipe(writer); | ||
| return Promise.resolve(outputLocationPath); | ||
| }); | ||
| } | ||
                
      
                  0237h marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
  
    
      This file contains hidden or 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,41 @@ | ||
| import path from 'path'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { getSpkgFilePath, isSpkgUrl } from '../../src/command-helpers/spkg'; | ||
| 
     | 
||
| describe('getSpkgFilePath', () => { | ||
| it('should return the correct file path', () => { | ||
| const spkgUrl = 'https://example.com/package.spkg'; | ||
| const directory = '/home/testuser/development/testgraph'; | ||
| const expectedFilePath = path.join(directory, 'package.spkg'); | ||
| 
     | 
||
| const filePath = getSpkgFilePath(spkgUrl, directory); | ||
| 
     | 
||
| expect(filePath).to.equal(expectedFilePath); | ||
| }); | ||
| 
     | 
||
| it('should throw an error for invalid spkg url', () => { | ||
| const spkgUrl = ''; | ||
| const directory = '/home/joshua/development/graphprotocol/graph-tooling/packages/cli'; | ||
| 
     | 
||
| expect(() => getSpkgFilePath(spkgUrl, directory)).to.throw('Invalid spkg url'); | ||
| }); | ||
| }); | ||
| 
     | 
||
| describe('isSpkgUrl', () => { | ||
| it('should return true for valid spkg url', () => { | ||
| const spkgUrl = 'https://spkg.io/streamingfast/package.spkg'; | ||
| const result = isSpkgUrl(spkgUrl); | ||
| expect(result).toBe(true); | ||
| }); | ||
| 
     | 
||
| it('should return false for invalid spkg url', () => { | ||
| const spkgUrl = 'https://example.com/package.spkg'; | ||
| const result = isSpkgUrl(spkgUrl); | ||
| expect(result).toBe(false); | ||
| }); | ||
| it('should return false for non-url string', () => { | ||
| const spkgUrl = 'streamingfast/package.spkg'; | ||
| const result = isSpkgUrl(spkgUrl); | ||
| expect(result).toBe(false); | ||
| }); | ||
| }); | 
  
    
      This file contains hidden or 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,18 @@ | ||
| // validator that checks if spkg exists or is valid url | ||
| 
     | 
||
| import path from 'path'; | ||
| import { filesystem } from 'gluegun'; | ||
| 
     | 
||
| export const isSpkgUrl = (value: string) => { | ||
| return value.startsWith('https://spkg.io/streamingfast'); | ||
                
      
                  joshuanazareth97 marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| }; | ||
| 
     | 
||
| export const validateSpkg = (value: string) => { | ||
| return filesystem.exists(value) || isSpkgUrl(value); | ||
| }; | ||
| 
     | 
||
| export const getSpkgFilePath = (spkgUrl: string, directory: string) => { | ||
| const spkgFileName = spkgUrl.split('/').pop(); | ||
| if (!spkgFileName) throw new Error('Invalid spkg url'); | ||
| return path.join(directory, spkgFileName); | ||
| }; | ||
  
    
      This file contains hidden or 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
    
  
  
    
              
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.