-
Notifications
You must be signed in to change notification settings - Fork 11
cli: refactor build, dev, start commands #111
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
Changes from all commits
175aa32
2c7a519
b46b3ce
7c38629
fb19cfe
8d11ff4
933a8e6
b80ea2a
19c8973
ee9d3ea
c4c53a8
44326f4
7039ff0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "Remove unused scripts", | ||
| "packageName": "@apibara/indexer", | ||
| "email": "francesco@ceccon.me", | ||
| "dependentChangeType": "none" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "Refactor dev, build, and start commands", | ||
| "packageName": "apibara", | ||
| "email": "francesco@ceccon.me", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { defineConfig } from "apibara/config"; | ||
|
|
||
| export default defineConfig({ | ||
| runtimeConfig: { | ||
| test: 123, | ||
| check: "something", | ||
| }, | ||
| presets: { | ||
| dev: { | ||
| runtimeConfig: { | ||
| test: 999, | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { defineIndexer } from "@apibara/indexer"; | ||
| import { StarknetStream } from "@apibara/starknet"; | ||
| import { hash } from "starknet"; | ||
|
|
||
| export default defineIndexer(StarknetStream)({ | ||
| streamUrl: "https://starknet.preview.apibara.org", | ||
| finality: "accepted", | ||
| startingCursor: { | ||
| orderKey: 800_000n, | ||
| }, | ||
| filter: { | ||
| events: [ | ||
| { | ||
| address: | ||
| "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", | ||
| keys: [hash.getSelectorFromName("Transfer")], | ||
| includeReceipt: true, | ||
| }, | ||
| ], | ||
| }, | ||
| async transform({ block: { header } }) { | ||
| console.log("Transforming block ", header?.blockNumber); | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "name": "example-cli-js", | ||
| "private": true, | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "scripts": { | ||
| "build": "apibara build", | ||
| "dev": "apibara dev", | ||
| "start": "apibara start", | ||
| "lint": "biome check .", | ||
| "lint:fix": "pnpm lint --write" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "@types/node": "^20.5.2", | ||
| "typescript": "^5.6.2" | ||
| }, | ||
| "dependencies": { | ||
| "@apibara/indexer": "workspace:*", | ||
| "@apibara/protocol": "workspace:*", | ||
| "@apibara/starknet": "workspace:*", | ||
| "apibara": "workspace:*", | ||
| "starknet": "^6.11.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,18 @@ | |
| "private": true, | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "scripts": {}, | ||
| "scripts": { | ||
| "build": "apibara build", | ||
| "dev": "apibara dev", | ||
| "start": "apibara start", | ||
| "lint": "biome check .", | ||
| "lint:fix": "pnpm lint --write" | ||
| }, | ||
|
Comment on lines
+6
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Based on the search results, I can now generate the final response since I have enough information to verify the documentation of the commands. Commands need documentation The new scripts (
🔗 Analysis chainLGTM! Verify command documentation. The new scripts align well with the PR objectives for refactoring the build, dev, and start commands. The addition of linting scripts with Biome is also a good practice for code quality. Let's verify if these commands are documented: Let me try another search strategy to verify the documentation of these commands. Let me try one more search to find CLI command documentation in the source code. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check if these commands are documented in README or CLI help
fd -t f "README.md" -X cat {} | rg -A 5 "(?:build|dev|start) command"
Length of output: 449 Script: #!/bin/bash
# Search for documentation in different locations
echo "=== Searching in README files ==="
fd -t f "README" -X cat {}
echo -e "\n=== Searching in docs directory ==="
fd -t f . -e md -p docs/ -X cat {}
echo -e "\n=== Searching for CLI help text ==="
ast-grep --pattern 'program
.command($_)
.description($_)'
Length of output: 5760 Script: #!/bin/bash
# Search for CLI command definitions
echo "=== Searching for command definitions ==="
rg -A 3 "\.command\(['\"](?:build|dev|start)['\"].*\)" --type ts
echo -e "\n=== Checking CLI package for documentation ==="
fd -t f . -p "packages/cli" -X cat {}
Length of output: 44122 |
||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "@types/better-sqlite3": "^7.6.11", | ||
| "@types/node": "^20.5.2", | ||
| "typescript": "^5.6.2" | ||
| }, | ||
|
|
@@ -16,6 +23,7 @@ | |
| "@apibara/protocol": "workspace:*", | ||
| "@apibara/starknet": "workspace:*", | ||
| "apibara": "workspace:*", | ||
| "better-sqlite3": "^11.5.0", | ||
| "starknet": "^6.11.0" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,13 +32,21 @@ | |
| "types": "./dist/hooks/index.d.ts", | ||
| "import": "./dist/hooks/index.mjs" | ||
| }, | ||
| "./internal/consola": { | ||
| "import": "./dist/internal/consola/index.mjs", | ||
| "types": "./dist/internal/consola/index.d.ts" | ||
| "./runtime": { | ||
| "types": "./dist/runtime/index.d.ts", | ||
| "import": "./dist/runtime/index.mjs" | ||
| }, | ||
| "./internal/citty": { | ||
| "import": "./dist/internal/citty/index.mjs", | ||
| "types": "./dist/internal/citty/index.d.ts" | ||
| "./runtime/meta": { | ||
| "types": "./runtime-meta.d.ts", | ||
| "import": "./runtime-meta.mjs" | ||
| }, | ||
| "./runtime/*": { | ||
| "types": "./dist/runtime/*.d.ts", | ||
| "import": "./dist/runtime/*.mjs" | ||
| }, | ||
| "./dist/runtime/*": { | ||
| "types": "./dist/runtime/*.d.ts", | ||
| "import": "./dist/runtime/*.mjs" | ||
|
Comment on lines
+35
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Runtime exports configuration needs adjustment The exports configuration in package.json references files in the
Either:
🔗 Analysis chainLGTM! Verify runtime directory structure. The new runtime-related exports are well-structured and consistent with the existing pattern. The wildcard exports will enable flexible runtime module loading as needed for the command refactoring. Let's verify the runtime directory structure matches the exports configuration: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify runtime directory structure exists as expected
# Check if runtime directory and type definitions exist
fd -t d "runtime$" "packages/cli/(src|dist)"
fd -t f ".*\.d\.ts$" -p "packages/cli/dist/runtime"
Length of output: 322 Script: #!/bin/bash
# Let's try a different approach to verify the runtime-related files and structure
# Check src directory structure
fd -t d "runtime" "packages/cli/src"
# Check for runtime-related source files
fd -t f ".*\.(ts|js|mjs)$" "packages/cli/src/runtime"
# Check for runtime meta files
fd "runtime-meta" "packages/cli"
# List all files in packages/cli to understand the structure
ls -la packages/cli/
Length of output: 1103 |
||
| } | ||
| }, | ||
| "bin": { | ||
|
|
@@ -55,13 +63,14 @@ | |
| "typecheck": "tsc --noEmit", | ||
| "lint:fix": "pnpm lint --write", | ||
| "format": "biome format . --write", | ||
| "playground": "JITI_ESM_RESOLVE=1 NODE_OPTIONS=\"--enable-source-maps\" jiti ./src/cli/index.ts", | ||
| "playground": "JITI_ESM_RESOLVE=1 CONSOLA_LEVEL=debug NODE_OPTIONS=\"--enable-source-maps\" jiti ./src/cli/index.ts", | ||
| "playground:prepare": "pnpm playground prepare --dir playground", | ||
| "playground:dev": "pnpm playground dev --dir playground", | ||
| "playground:build": "pnpm playground build --dir playground", | ||
| "playground:start": "JITI_ESM_RESOLVE=1 NODE_OPTIONS=\"--enable-source-maps\" jiti ./playground/.apibara/build/main.mjs" | ||
| "playground:start": "pnpm playground start --dir playground --indexer starknet" | ||
| }, | ||
| "devDependencies": { | ||
| "@apibara/starknet": "workspace:*", | ||
| "@types/fs-extra": "^11.0.4", | ||
| "@types/node": "^20.14.0", | ||
| "jiti": "^1.21.0", | ||
|
|
@@ -71,14 +80,13 @@ | |
| "vitest": "^1.6.0" | ||
| }, | ||
| "dependencies": { | ||
| "@apibara/evm": "workspace:*", | ||
| "@apibara/indexer": "workspace:*", | ||
| "@apibara/protocol": "workspace:*", | ||
| "@apibara/starknet": "workspace:*", | ||
| "@rollup/plugin-commonjs": "^26.0.1", | ||
| "@rollup/plugin-json": "^6.1.0", | ||
| "@rollup/plugin-node-resolve": "^15.2.3", | ||
| "@rollup/plugin-typescript": "^11.1.6", | ||
| "@rollup/plugin-virtual": "^3.0.2", | ||
| "c12": "^1.11.1", | ||
| "chokidar": "^3.6.0", | ||
| "citty": "^0.1.6", | ||
|
|
@@ -88,10 +96,12 @@ | |
| "fs-extra": "^11.2.0", | ||
| "hookable": "^5.5.3", | ||
| "klona": "^2.0.6", | ||
| "magic-string": "^0.30.12", | ||
| "pathe": "^1.1.2", | ||
| "perfect-debounce": "^1.0.0", | ||
| "pkg-types": "^1.1.3", | ||
| "rollup": "^4.18.1", | ||
| "rollup-plugin-esbuild": "^6.1.1", | ||
| "tslib": "^2.6.3", | ||
| "untyped": "^1.4.2" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| import { defaultSink } from "@apibara/indexer"; | ||
| import { defineConfig } from "apibara/config"; | ||
|
|
||
| export default defineConfig({ | ||
| runtimeConfig: { | ||
| test: 123, | ||
| check: "something", | ||
| nested: { | ||
| test: 456, | ||
| }, | ||
| fromEnv: { | ||
| nodeEnv: process.env.NODE_ENV, | ||
| }, | ||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding type safety and validation for environment variables. The direct use of
fromEnv: {
- nodeEnv: process.env.NODE_ENV,
+ nodeEnv: process.env.NODE_ENV ?? 'development',
},You might also want to add a type guard: const validateNodeEnv = (env: string | undefined): env is 'development' | 'production' | 'test' => {
return env === 'development' || env === 'production' || env === 'test';
};
// Usage
nodeEnv: validateNodeEnv(process.env.NODE_ENV)
? process.env.NODE_ENV
: 'development', |
||
| }, | ||
| presets: { | ||
| dev: { | ||
|
|
@@ -13,7 +18,4 @@ export default defineConfig({ | |
| }, | ||
| }, | ||
| }, | ||
| sink: { | ||
| default: () => defaultSink(), | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,10 @@ import { hash } from "starknet"; | |
| export default function indexer(runtimeConfig: ApibaraRuntimeConfig) { | ||
| consola.log("--> Starknet Indexer Runtime Config: ", runtimeConfig); | ||
| return defineIndexer(StarknetStream)({ | ||
| streamUrl: "http://mainnet-v2.starknet.a5a.ch:7007", | ||
| streamUrl: "https://starknet.preview.apibara.org", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Update required: Old Starknet URL found in examples The new Starknet stream URL
This file needs to be updated to maintain consistency across the codebase and avoid confusion. 🔗 Analysis chainVerify the new Starknet stream URL configuration. The migration to Run the following script to check for any other instances of the old URL that might need updating: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any remaining instances of the old URL
rg "mainnet-v2\.starknet\.a5a\.ch:7007"
Length of output: 136 Script: #!/bin/bash
# Let's check if there are any other Starknet stream URL configurations
rg -A 2 "streamUrl.*starknet"
# Also check for any documentation or configuration files mentioning Starknet URLs
rg -t md -t yaml -t json "starknet.*\.org|starknet.*\.ch"
Length of output: 585 |
||
| finality: "accepted", | ||
| startingCursor: { | ||
| orderKey: 80_000n, | ||
| orderKey: 800_000n, | ||
| }, | ||
| filter: { | ||
| events: [ | ||
|
|
@@ -23,12 +23,9 @@ export default function indexer(runtimeConfig: ApibaraRuntimeConfig) { | |
| ], | ||
| }, | ||
| async transform({ block: { header, events } }) { | ||
| consola.info("Transforming block ", header?.blockNumber); | ||
| }, | ||
| hooks: { | ||
| "handler:after": ({ endCursor }) => { | ||
| consola.info("Handler After ", endCursor?.orderKey); | ||
| }, | ||
| consola.info( | ||
| `Got block ${header?.blockNumber} with ${events.length} events`, | ||
| ); | ||
|
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Migrate to apibara.logger for consistent logging. According to the broader changes in this PR, logging is being centralized through Consider updating the logging implementation: -import consola from "consola";
+import { logger } from "apibara";
export default function indexer(runtimeConfig: ApibaraRuntimeConfig) {
- consola.log("--> Starknet Indexer Runtime Config: ", runtimeConfig);
+ logger.debug("Starknet Indexer Runtime Config: ", runtimeConfig);
// ...
- consola.info(
+ logger.info(
`Got block ${header?.blockNumber} with ${events.length} events`,
);
|
||
| }, | ||
| }); | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export declare const pkgDir: string; | ||
| export declare const runtimeDir: string; |
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.
🛠️ Refactor suggestion
Enhance transform function with structured logging and error handling.
The current transform function uses basic console.log and lacks error handling. Consider using a structured logger and adding proper error handling.
Here's a suggested improvement:
📝 Committable suggestion