Skip to content

Commit

Permalink
Merge pull request #1 from pinax-network/fix/read-local-spkg
Browse files Browse the repository at this point in the history
fix file remote path
  • Loading branch information
DenisCarriere authored Mar 1, 2024
2 parents eb11e0f + a6e27f8 commit 0b28507
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lerna-debug.log*
*.csv
*.cursor
*.clock
*.spkg

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ SUBSTREAMS_API_KEY=<your-api-key>
MANIFEST=https://github.com/streamingfast/substreams-eth-block-meta/releases/download/v0.5.1/substreams-eth-block-meta-v0.5.1.spkg
MODULE_NAME=graph_out
SUBSTREAMS_ENDPOINT=eth.substreams.pinax.network:443
SCHEMA=schema.example.sql
```
**CLI**
**CLI** with `.env` file
```bash
$ substreams-sink-csv --schema schema.sql
$ substreams-sink-csv
```
**CLI** with `params`
```bash
$ substreams-sink-csv --schema schema.example.sql -e eth.substreams.pinax.network:443 --module-name graph_out --manifest https://github.com/streamingfast/substreams-eth-block-meta/releases/download/v0.5.1/substreams-eth-block-meta-v0.5.1.spkg --substreams-api-key <your-api-key>
```

### Substreams Support
Expand Down
11 changes: 10 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import fs from "fs";
import path from "path";
import { setup, fileCursor } from "substreams-sink";
import { CSVRunOptions } from "./bin/cli.js"
import { EntityChanges, getValuesInEntityChange } from "@substreams/sink-entity-changes/zod"
import logUpdate from "log-update";
import { getModuleHash } from "./src/getModuleHash.js";
import { getModuleHash, isRemotePath } from "./src/getModuleHash.js";
import { parseFilename } from "./src/parseFilename.js";
import { parseClock } from "./src/parseClock.js";
import { parseSchema } from "./src/parseSchema.js";

export async function action(options: CSVRunOptions ) {
// @substreams/manifest issue
// if manifest is local, add current directory
if (!isRemotePath(options.manifest) && !path.isAbsolute(options.manifest)) {
const currentDir = process.cwd();
options.manifest = path.join(currentDir, options.manifest);
}
if ( !fs.existsSync(options.manifest) ) throw new Error(`Manifest file not found: ${options.manifest}`);

// SQL schema
if ( !fs.existsSync(options.schema) ) throw new Error(`Schema file not found: ${options.schema}`);
const schema = fs.readFileSync(options.schema, "utf8");
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.3",
"version": "0.2.4",
"name": "substreams-sink-csv",
"description": "Substreams Sink CSV",
"type": "module",
Expand All @@ -26,7 +26,7 @@
}
},
"scripts": {
"start": "tsc && node ./dist/bin/cli.js --help",
"start": "tsc && node ./dist/bin/cli.js",
"pretest": "tsc --noEmit",
"test": "bun test",
"prepublishOnly": "tsc"
Expand Down
4 changes: 4 additions & 0 deletions src/getModuleHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { readPackage } from "@substreams/manifest";
import { CSVRunOptions } from "../bin/cli.js";
import { createModuleHashHex } from "@substreams/core";

export function isRemotePath(path: string): boolean {
return path.startsWith("http://") || path.startsWith("https://");
}

export async function getModuleHash(options: CSVRunOptions) {
// Read Substream
const substreamPackage = await readPackage(options.manifest);
Expand Down

0 comments on commit 0b28507

Please sign in to comment.