Skip to content

Conversation

@jaipaljadeja
Copy link
Member

@jaipaljadeja jaipaljadeja commented Apr 18, 2025

  • refactors runtimeConfig data flow in cli
  • fixes runtimeConfig values not being updated on changes to apibara.config during dev mode
  • improves hot-reload in cli, so on changes of runtimeConfig, preset & preset values in apibara.config, we only refresh these values and restart indexers without any re-build step (restarts before you could blink)
  • adds sourcemaps to all packages
  • re-exports @apibara/indexer modules from apibara cli package as submodules for better UX
  • updates examples and cli templates to use apibara submodules instead of @apibara/indexer package.
  • adds an option clientOptions in defineIndexer to override client options.

@coderabbitai
Copy link

coderabbitai bot commented Apr 18, 2025

📝 Walkthrough

Walkthrough

This update introduces source map support across all packages by enabling source map generation in build configurations and updating related prerelease metadata files. The CLI runtime data flow is refactored to centralize runtime and preset configuration handling via environment variables and helper utilities. Several new modules are added for modular imports, and import paths throughout example and generated files are updated to use unscoped package names. The configuration and hot reloading logic are revised to improve runtime config merging, preset handling, and process management. Deprecated or redundant files and plugins are removed, and the package exports and TypeScript configuration are updated to reflect the new module structure.

Changes

File(s) / Path(s) Change Summary
change/@apibara-*, change/apibara-*.json Added prerelease metadata files for multiple packages, documenting patch-level prerelease builds with comments about adding sourcemaps. No functional code changes.
packages/*/build.config.ts Enabled source map generation by adding sourcemap: true to build configs for all relevant packages.
examples/cli-drizzle/indexers/*.ts, examples/cli-drizzle/test/*.ts, packages/cli/src/create/templates.ts Updated import paths from scoped (@apibara/*) to unscoped (apibara/*) packages for indexer, plugins, and testing utilities. Removed @apibara/indexer from generated dependencies.
packages/cli/build.config.ts, packages/cli/package.json Added new module entries (common, indexer, plugins, testing, vcr) and their exports. Enabled source maps. Added build lifecycle hooks to log build duration. Updated Rollup output banner typing.
packages/cli/src/common/constants.ts, packages/cli/src/common/helper.ts, packages/cli/src/common/index.ts Introduced new common module with exported constants for environment variable keys and helper functions for runtime config merging and retrieval.
packages/cli/src/indexer/index.ts, plugins.ts, testing.ts, vcr.ts Added proxy modules that re-export all exports from their respective @apibara/indexer/* modules for simplified imports.
packages/cli/src/cli/commands/dev.ts, start.ts Refined hot reloading and child process logic: improved runtime config update, changed logging methods, and removed direct --preset CLI argument passing. Updated comments and regex for config updates.
packages/cli/src/core/apibara.ts, update.ts Updated parameter naming for clarity. Refactored config update flow to apply new runtime config to environment before triggering reload.
packages/cli/src/core/build/dev.ts Excluded apibara.config files from rolldown watch patterns, clarifying they are handled elsewhere.
packages/cli/src/core/config/loader.ts Added runtimeConfigResolver to the config resolvers sequence for assigning runtime values to the environment.
packages/cli/src/core/config/resolvers/runtime.resolver.ts Added runtimeConfigResolver function to serialize and set runtime/preset configs to environment variables, and compute processed runtime config via helper.
packages/cli/src/hooks/useRuntimeConfig.ts Changed environment variable key for runtime config from a hardcoded string to a constant from the new common module.
packages/cli/src/runtime/dev.ts, start.ts, project-info.ts, internal/app.ts Refactored to retrieve runtime and preset data from environment via new helpers, and to pass processed runtime config as an object. Updated function signatures and removed redundant config merging logic.
packages/cli/src/types/config.ts Broadened ApibaraDynamicConfig type to include preset and presets in addition to runtimeConfig.
packages/cli/tsconfig.json Changed rootDir to ".", added path mappings for new modules, and removed include/exclude fields.
Deleted: packages/cli/src/core/config/resolvers/preset.resolver.ts, plugins/config.ts, types/virtual/config.d.ts, runtime/internal/helper.ts Removed deprecated or redundant files related to config merging and virtual module plugins.
packages/cli/src/create/constants.ts Removed @apibara/indexer from the list of generated dependencies.
packages/cli/src/rolldown/config.ts Removed the use of replace and appConfig plugins for injecting config at build time. Cleaned up related code.
packages/indexer/src/indexer.ts Added optional clientOptions property to IndexerConfig type to allow passing client creation options.

Sequence Diagram(s)

sequenceDiagram
    participant CLI_User
    participant CLI_Process
    participant EnvHelper
    participant IndexerModule

    CLI_User->>CLI_Process: Run CLI command (dev/start)
    CLI_Process->>EnvHelper: getRuntimeDataFromEnv()
    EnvHelper-->>CLI_Process: {preset, processedRuntimeConfig}
    CLI_Process->>IndexerModule: createIndexer({indexerName, processedRuntimeConfig, preset})
    IndexerModule-->>CLI_Process: Indexer instance (uses processed config)
Loading

Possibly related PRs

  • apibara/typescript-sdk#174: Adds source map support in the CLI, modifying environment variables and updating runtime dependencies—closely related to this PR's focus on sourcemap support.
  • apibara/typescript-sdk#103: Adds prerelease metadata JSON files for the same packages, indicating similar release management and metadata changes.

Suggested reviewers

  • fracek

Poem

Hopping through configs, a bunny so bright,
Adds sourcemaps for code insight.
Refactored the runtime, merged presets with care,
Imports are simpler, modules now share.
With every build, debugging’s a breeze—
This rabbit brings clarity with effortless ease!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33d0ee5 and cebe7c1.

📒 Files selected for processing (4)
  • packages/cli/src/runtime/dev.ts (3 hunks)
  • packages/cli/src/runtime/internal/app.ts (3 hunks)
  • packages/cli/src/runtime/start.ts (3 hunks)
  • packages/indexer/src/indexer.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/cli/src/runtime/start.ts
  • packages/cli/src/runtime/internal/app.ts
  • packages/cli/src/runtime/dev.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/indexer/src/indexer.ts (1)
packages/protocol/src/client.ts (1)
  • CreateClientOptions (57-63)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
packages/indexer/src/indexer.ts (1)

4-4: Nice addition of client options configuration support

This change adds the ability to configure client options at the indexer level, which provides greater flexibility for customizing connection behavior. The implementation is clean and backward-compatible since the property is optional.

Also applies to: 86-86

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jaipaljadeja jaipaljadeja requested a review from fracek April 18, 2025 11:19
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (12)
packages/indexer/build.config.ts (1)

16-16: Consider including inline sources in your source maps
To provide even richer debugging information—including original TypeScript source content—you might extend this setting with an inlineSources flag (if supported by your build toolchain) or configure Rollup’s output.sourcemap options accordingly. This can eliminate the need to fetch .ts files separately when inspecting stack traces.

packages/starknet/build.config.ts (1)

8-8: Enable source maps for improved debugging
The addition of sourcemap: true ensures that your compiled output emits sourcemaps, which will greatly aid in tracing errors back to the original TypeScript.
Consider also adding inlineSources: true to embed the TS sources directly in the map files, further enhancing the debugging experience in IDEs and browser devtools.

change/@apibara-evm-1fd2380c-16c6-4640-acf7-64a2f40baf8c.json (1)

5-5: Check author email formatting.

The email field is "jadejajaipal5@gmail.com". Ensure this is the correct address for release notifications. If your organization uses a centralized alias (e.g., releases@apibara.com), consider using that instead.

change/@apibara-plugin-mongo-add18c13-4892-47e9-b4c3-5e666ce99996.json (3)

3-3: Align the comment with commit/message conventions
The "comment" field is free‑form metadata but should stay consistent with the monorepo’s commit message guidelines (e.g., build: add sourcemaps to all packages). Consider using imperative tense and a concise prefix if other prerelease files follow a different pattern.


5-5: Validate author email visibility
The "email" field contains PII that will be published in release metadata. Verify that this address is correct and that exposing it aligns with project policy.


7-8: Ensure JSON formatting and trailing newline
This file is valid JSON, but please confirm there’s a single newline at EOF and no trailing commas to maintain consistency with other metadata files.

packages/plugin-sqlite/build.config.ts (1)

8-8: Optional: Generate declaration maps
To further aid debugging of type definitions, consider enabling declarationMap: true so that .d.ts.map files are produced alongside your .d.ts declarations:

 export default defineBuildConfig({
   entries: ["./src/index.ts"],
   clean: true,
   outDir: "./dist",
   declaration: true,
   sourcemap: true,
+  declarationMap: true,
   rollup: {
     emitCJS: true,
   },
 });
packages/cli/src/core/config/resolvers/runtime.resolver.ts (1)

26-28: Consider adding more robust JSON parsing error handling.

While the overall error handling is good, this specific JSON parsing operation could benefit from explicit error handling since it relies on user-provided input.

-    const userEnvRuntimeConfig = JSON.parse(
-      process.env[USER_ENV_APIBARA_RUNTIME_CONFIG] ?? "{}",
-    );
+    let userEnvRuntimeConfig = {};
+    try {
+      if (process.env[USER_ENV_APIBARA_RUNTIME_CONFIG]) {
+        userEnvRuntimeConfig = JSON.parse(
+          process.env[USER_ENV_APIBARA_RUNTIME_CONFIG]
+        );
+      }
+    } catch (error) {
+      throw new Error(
+        "Failed to parse runtime config from environment variable",
+        { cause: error }
+      );
+    }
packages/cli/src/common/helper.ts (4)

52-52: Use deep cloning for runtime config

Using the spread operator ({ ...runtimeConfig }) creates a shallow copy which may lead to unexpected behavior if runtimeConfig contains nested objects that are later modified.

-  let _runtimeConfig: Record<string, unknown> = { ...runtimeConfig };
+  // Create a deep clone to avoid unintentional mutations of nested objects
+  let _runtimeConfig: Record<string, unknown> = JSON.parse(JSON.stringify(runtimeConfig || {}));

Alternatively, you could use a deep cloning utility if available in your codebase.


34-40: Document function return type in JSDoc

The function documentation explains priorities well but doesn't describe what the function returns. Adding the return type information would improve the documentation.

/**
 * Get the merged runtime config from the user env overrided runtime config, presets and defaults.
 * Priority (Highest to lowest):
 * 1. User env overrided runtime config
 * 2. Preset
 * 3. Defaults
+ *
+ * @returns {Record<string, unknown>} The merged runtime configuration object
 */

73-83: Redundant error handling for userEnvRuntimeConfig

The userEnvRuntimeConfig has already been parsed from JSON in the getRuntimeDataFromEnv() function, so the try/catch block here is unnecessary. The error would have been caught earlier.

  if (userEnvRuntimeConfig) {
-    try {
-      // Environment runtime config applied
-      _runtimeConfig = defu(userEnvRuntimeConfig, _runtimeConfig);
-    } catch (error) {
-      throw new Error(
-        "Failed to parse runtime config from process.env.APIBARA_RUNTIME_CONFIG. Please ensure it is a valid JSON string.",
-        { cause: error },
-      );
-    }
+    // Environment runtime config applied
+    _runtimeConfig = defu(userEnvRuntimeConfig, _runtimeConfig);
  }

1-8: Import "defu" type for better type safety

The defu function is imported without its type information, which might lead to issues with TypeScript type checking.

-import defu from "defu";
+import defu, { type Defu } from "defu";

This depends on whether the defu package exports its types. If it does, importing them would improve type safety in your code.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7c9e92 and 33d0ee5.

📒 Files selected for processing (52)
  • change/@apibara-beaconchain-6446ef46-637b-4b6b-96df-72f561286812.json (1 hunks)
  • change/@apibara-evm-1fd2380c-16c6-4640-acf7-64a2f40baf8c.json (1 hunks)
  • change/@apibara-indexer-3b0c9ba4-39a3-4c10-80c2-3efc2defc167.json (1 hunks)
  • change/@apibara-plugin-drizzle-e06d17ff-fbbe-492e-a3b6-28842772e7db.json (1 hunks)
  • change/@apibara-plugin-mongo-add18c13-4892-47e9-b4c3-5e666ce99996.json (1 hunks)
  • change/@apibara-plugin-sqlite-05d6412f-e9b4-436c-b03b-a19f6e801197.json (1 hunks)
  • change/@apibara-protocol-c2f956f6-1714-4f67-99f3-dc5af63bcee1.json (1 hunks)
  • change/@apibara-starknet-6e5b2085-16df-4ba6-9802-c83b2f744259.json (1 hunks)
  • change/apibara-59d66024-b9f5-4907-8b4e-f668cc87c247.json (1 hunks)
  • examples/cli-drizzle/indexers/1-evm.indexer.ts (1 hunks)
  • examples/cli-drizzle/indexers/2-starknet.indexer.ts (1 hunks)
  • examples/cli-drizzle/indexers/3-starknet-factory.indexer.ts (1 hunks)
  • examples/cli-drizzle/test/ethereum.test.ts (1 hunks)
  • examples/cli-drizzle/test/starknet.test.ts (1 hunks)
  • packages/beaconchain/build.config.ts (1 hunks)
  • packages/cli/build.config.ts (3 hunks)
  • packages/cli/package.json (2 hunks)
  • packages/cli/src/cli/commands/dev.ts (4 hunks)
  • packages/cli/src/cli/commands/start.ts (1 hunks)
  • packages/cli/src/common/constants.ts (1 hunks)
  • packages/cli/src/common/helper.ts (1 hunks)
  • packages/cli/src/common/index.ts (1 hunks)
  • packages/cli/src/core/apibara.ts (1 hunks)
  • packages/cli/src/core/build/dev.ts (1 hunks)
  • packages/cli/src/core/config/loader.ts (1 hunks)
  • packages/cli/src/core/config/resolvers/preset.resolver.ts (0 hunks)
  • packages/cli/src/core/config/resolvers/runtime.resolver.ts (1 hunks)
  • packages/cli/src/core/config/update.ts (1 hunks)
  • packages/cli/src/create/constants.ts (0 hunks)
  • packages/cli/src/create/templates.ts (1 hunks)
  • packages/cli/src/hooks/useRuntimeConfig.ts (1 hunks)
  • packages/cli/src/indexer/index.ts (1 hunks)
  • packages/cli/src/indexer/plugins.ts (1 hunks)
  • packages/cli/src/indexer/testing.ts (1 hunks)
  • packages/cli/src/indexer/vcr.ts (1 hunks)
  • packages/cli/src/rolldown/config.ts (0 hunks)
  • packages/cli/src/rolldown/plugins/config.ts (0 hunks)
  • packages/cli/src/runtime/dev.ts (3 hunks)
  • packages/cli/src/runtime/internal/app.ts (2 hunks)
  • packages/cli/src/runtime/internal/helper.ts (0 hunks)
  • packages/cli/src/runtime/project-info.ts (2 hunks)
  • packages/cli/src/runtime/start.ts (2 hunks)
  • packages/cli/src/types/config.ts (1 hunks)
  • packages/cli/src/types/virtual/config.d.ts (0 hunks)
  • packages/cli/tsconfig.json (2 hunks)
  • packages/evm/build.config.ts (1 hunks)
  • packages/indexer/build.config.ts (1 hunks)
  • packages/plugin-drizzle/build.config.ts (1 hunks)
  • packages/plugin-mongo/build.config.ts (1 hunks)
  • packages/plugin-sqlite/build.config.ts (1 hunks)
  • packages/protocol/build.config.ts (1 hunks)
  • packages/starknet/build.config.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • packages/cli/src/create/constants.ts
  • packages/cli/src/runtime/internal/helper.ts
  • packages/cli/src/rolldown/plugins/config.ts
  • packages/cli/src/types/virtual/config.d.ts
  • packages/cli/src/rolldown/config.ts
  • packages/cli/src/core/config/resolvers/preset.resolver.ts
🧰 Additional context used
🧬 Code Graph Analysis (6)
packages/cli/src/core/config/loader.ts (2)
packages/cli/src/core/config/resolvers/paths.resolver.ts (1)
  • resolvePathOptions (4-14)
packages/cli/src/core/config/resolvers/runtime.resolver.ts (1)
  • runtimeConfigResolver (11-44)
packages/cli/src/core/apibara.ts (2)
packages/cli/src/types/config.ts (1)
  • ApibaraDynamicConfig (44-47)
packages/cli/src/core/config/update.ts (1)
  • updateApibaraConfig (4-13)
packages/cli/src/hooks/useRuntimeConfig.ts (2)
packages/cli/src/types/runtime.ts (1)
  • ApibaraRuntimeConfig (1-1)
packages/cli/src/common/constants.ts (1)
  • ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME (4-5)
packages/cli/src/runtime/project-info.ts (2)
packages/cli/src/common/helper.ts (2)
  • getRuntimeDataFromEnv (10-32)
  • getProcessedRuntimeConfig (41-86)
packages/cli/src/runtime/internal/app.ts (2)
  • availableIndexers (22-22)
  • createIndexer (24-97)
packages/cli/src/common/helper.ts (1)
packages/cli/src/common/constants.ts (5)
  • ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME (4-5)
  • ENV_INTERNAL_APIBARA_PRESET (2-2)
  • ENV_INTERNAL_APIBARA_PRESETS (3-3)
  • ENV_INTERNAL_APIBARA_RUNTIME (1-1)
  • USER_ENV_APIBARA_RUNTIME_CONFIG (6-6)
packages/cli/src/core/config/resolvers/runtime.resolver.ts (3)
packages/cli/src/types/config.ts (1)
  • ApibaraOptions (57-108)
packages/cli/src/common/constants.ts (5)
  • ENV_INTERNAL_APIBARA_RUNTIME (1-1)
  • ENV_INTERNAL_APIBARA_PRESET (2-2)
  • ENV_INTERNAL_APIBARA_PRESETS (3-3)
  • USER_ENV_APIBARA_RUNTIME_CONFIG (6-6)
  • ENV_INTERNAL_APIBARA_PROCESSED_RUNTIME (4-5)
packages/cli/src/common/helper.ts (1)
  • getProcessedRuntimeConfig (41-86)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (83)
packages/evm/build.config.ts (1)

8-8: Enable source map generation
Adding sourcemap: true ensures that the build emits source maps for better debugging and stack traces. Please verify post-build that .map files appear in dist/ and that your runtime or IDE correctly picks them up.

packages/indexer/build.config.ts (1)

16-16: Enable source map generation for improved debugging
Adding sourcemap: true ensures that compiled output includes source maps, aligning with other packages in the monorepo and greatly aiding developers when troubleshooting or stepping through code in their editors or debuggers.

packages/plugin-mongo/build.config.ts (1)

8-8: Enable source map generation for improved debugging
Adding sourcemap: true to the build config is correct and consistent with the other packages, facilitating better traceability of original TypeScript sources during development and troubleshooting.

change/@apibara-indexer-3b0c9ba4-39a3-4c10-80c2-3efc2defc167.json (1)

1-7: Approve prerelease metadata JSON

The JSON correctly specifies the prerelease configuration for @apibara/indexer, including the release type, descriptive comment, package scope, author email, and patch-level change designation. No issues detected.

packages/protocol/build.config.ts (1)

8-8: Enable source maps in build configuration
The addition of sourcemap: true correctly activates source map generation for this package’s build, improving debugging and stack trace mapping. This change is consistent with the coordinated updates across other packages.

change/@apibara-protocol-c2f956f6-1714-4f67-99f3-dc5af63bcee1.json (1)

1-7: Add prerelease metadata for sourcemaps patch
The new JSON file accurately declares a prerelease for @apibara/protocol with the appropriate comment, email, and patch-level change type. It follows the established pattern for other packages’ metadata files.

change/@apibara-plugin-sqlite-05d6412f-e9b4-436c-b03b-a19f6e801197.json (5)

2-2: Validate prerelease type
The "type" field is correctly set to "prerelease", matching the intended workflow for adding sourcemaps without bumping public APIs.


3-3: Confirm commit description
The "comment" accurately summarizes the change ("build: add sourcemaps to all packages") and adheres to conventional commit style.


4-4: Verify package name
The "packageName" is correctly specified as "@apibara/plugin-sqlite", aligning with the package being updated.


5-5: Ensure contact email accuracy
The "email" field is well‑formed. Please confirm this address is intended for release notifications.


6-6: Dependent change type is correct
Setting "dependentChangeType" to "patch" is appropriate, as sourcemap support is a build‐only enhancement that doesn’t affect public APIs.

change/@apibara-evm-1fd2380c-16c6-4640-acf7-64a2f40baf8c.json (3)

2-3: Ensure consistency of prerelease metadata comment and type.

The type is set to "prerelease", and the comment field accurately reflects the build change. Verify that this schema and messaging convention align with other packages’ prerelease metadata to maintain a unified release process.


4-4: Verify packageName matches the published package.

The packageName is "@apibara/evm". Confirm this exactly matches the name declared in the corresponding package.json to avoid any publishing discrepancies.


6-6: Validate semantic version bump strategy.

Using "patch" for dependentChangeType is appropriate since adding sourcemaps is non-breaking. If any other user‐facing changes are introduced alongside this, consider updating to "minor".

change/@apibara-plugin-mongo-add18c13-4892-47e9-b4c3-5e666ce99996.json (3)

2-2: Verify prerelease intent
The "type": "prerelease" flag drives release tooling behavior. Please confirm this change should indeed be published as a prerelease rather than a regular patch or minor release.


4-4: Confirm the package name
Ensure that "@apibara/plugin-mongo" exactly matches the published package identifier (including scope and hyphens). A mismatch here could lead to mis‑versioning or broken installs.


6-6: Dependent change type looks correct
The "dependentChangeType": "patch" designation is consistent for adding sourcemaps (non-breaking change). No action required if patch is intended.

packages/plugin-sqlite/build.config.ts (1)

8-8: Enable source map generation
Adding sourcemap: true ensures that this package’s build will emit source maps, improving traceability and debugging and aligning with the other @apibara/* packages.

packages/plugin-drizzle/build.config.ts (1)

8-8: Enable source map generation
Adding sourcemap: true aligns this package with the rest of the SDK to emit .map files for improved debugging experience.

change/@apibara-plugin-drizzle-e06d17ff-fbbe-492e-a3b6-28842772e7db.json (1)

1-7: Add prerelease metadata for sourcemaps
The new prerelease JSON correctly sets type, comment, packageName, and dependentChangeType for a patch-level prerelease. It matches the pattern used across other packages.

packages/beaconchain/build.config.ts (1)

8-8: Enable source map generation
Adding sourcemap: true will produce source maps for the beaconchain package, improving debugging capabilities. Please verify that defineBuildConfig in unbuild supports the sourcemap option (versus sourcemaps) and that all other packages use the identical key for consistency.

change/@apibara-beaconchain-6446ef46-637b-4b6b-96df-72f561286812.json (1)

1-7: Add prerelease metadata for patch-level release
The new JSON defines a patch‐level prerelease for @apibara/beaconchain, documenting the sourcemap addition, author email, and dependent change type. Ensure this file’s path and naming conform to the repository’s release metadata schema (e.g., .changeset/ or equivalent) so the release tooling picks it up correctly.

change/@apibara-starknet-6e5b2085-16df-4ba6-9802-c83b2f744259.json (2)

1-7: Prerelease metadata looks correct.

All required fields (type, comment, packageName, email, dependentChangeType) are present and properly set for a patch-level prerelease, matching the intent to add sourcemaps to the @apibara/starknet package.


1-7:

✅ Verification successful

Verify consistency across all prerelease metadata files.

To ensure the type and comment fields are uniform across every @apibara/* prerelease in the change/ directory, you can run:


🏁 Script executed:

#!/bin/bash
# Description: Validate that all prerelease JSONs share the same type and comment.

set -e
expected_type="prerelease"
expected_comment="build: add sourcemaps to all packages"

for file in change/@apibara-*.json; do
  type=$(jq -r '.type' "$file")
  comment=$(jq -r '.comment' "$file")
  pkg=$(jq -r '.packageName' "$file")
  if [[ "$type" != "$expected_type" || "$comment" != "$expected_comment" ]]; then
    echo "❌ Mismatch in $file (package=$pkg): type=$type, comment=$comment"
    exit 1
  fi
done

echo "✅ All prerelease metadata files are consistent."

Length of output: 4663


All prerelease metadata files are consistent

I ran the provided validation script against all change/@apibara-*.json files and confirmed that each entry uses

  • type: prerelease
  • comment: build: add sourcemaps to all packages

No discrepancies were found—no further changes are needed.

examples/cli-drizzle/test/starknet.test.ts (1)

1-1: Import path updated to use unscoped proxy module
The createVcr import was correctly switched from the scoped package to the new apibara/testing proxy. Ensure that apibara/testing is properly exported in the CLI package’s package.json under the exports field so this resolves at runtime.

examples/cli-drizzle/test/ethereum.test.ts (1)

1-1: Align createVcr import with new proxy module
The import for createVcr now correctly points to apibara/testing. Just double‑check that the CLI package exports this subpath so Vitest can locate it without issues.

examples/cli-drizzle/indexers/3-starknet-factory.indexer.ts (1)

2-3: Switched to unscoped indexer and plugin imports
The lines importing defineIndexer and useLogger from apibara/indexer and apibara/plugins are correct following the new proxy modules. Verify that these paths are declared under exports in the CLI package’s manifest.

examples/cli-drizzle/indexers/1-evm.indexer.ts (2)

3-3: Proxy import for defineIndexer applied
The import of defineIndexer from apibara/indexer replaces the old scoped path. Confirm that apibara/indexer is exposed by the CLI package.


10-10: Proxy import for useLogger applied
Updated useLogger to come from apibara/plugins. Make sure the CLI package’s exports include this subpath to avoid resolution errors.

change/apibara-59d66024-b9f5-4907-8b4e-f668cc87c247.json (1)

1-7: Prerelease metadata is in place
The new prerelease descriptor correctly captures the CLI refactor’s intent, package name, and change type. No issues spotted in the JSON structure.

packages/cli/src/indexer/testing.ts (1)

1-2: Clean and consistent module re-export pattern

This re-export follows the same pattern as the other new module exports in the /indexer directory, creating a consistent and unified import experience for consumers.

examples/cli-drizzle/indexers/2-starknet.indexer.ts (1)

4-4: Import paths correctly updated to use the new module structure

The import paths have been properly updated from scoped packages (@apibara/indexer and @apibara/indexer/plugins) to unscoped packages (apibara/indexer and apibara/plugins), aligning with the new re-export module structure.

Also applies to: 7-7

packages/cli/src/cli/commands/start.ts (2)

53-53: Simplified CLI argument handling

The conditional inclusion of the --preset argument is removed, aligning with the new approach of using environment variables for runtime configuration and preset handling instead of CLI arguments.


61-65: More appropriate log level

Changed from log to info, which is more semantically correct for process exit notifications.

packages/cli/src/common/index.ts (1)

1-2: Clean module structure for common utilities

This index file effectively centralizes access to the new runtime configuration helpers and constants, creating a clear entry point for these utilities.

packages/cli/src/indexer/plugins.ts (1)

1-1: Well-structured module re-export

This re-export pattern improves the developer experience by allowing users to import from apibara/plugins instead of @apibara/indexer/plugins, simplifying import paths while maintaining access to all indexer plugin functionality.

packages/cli/src/indexer/index.ts (1)

1-1: Clean module re-export pattern

This re-export is part of the broader refactoring to provide simpler import paths. By re-exporting from @apibara/indexer, you're creating a more developer-friendly API that maintains all functionality while simplifying imports.

packages/cli/src/hooks/useRuntimeConfig.ts (1)

1-1: Good refactoring using centralized constants

Replacing the hardcoded environment variable string with a constant from a centralized location improves maintainability and reduces the risk of typos or inconsistencies across the codebase.

Also applies to: 5-7

packages/cli/src/core/build/dev.ts (1)

105-106: Appropriate exclusion pattern with clear explanation

Adding this ignore pattern for apibara configuration files is a good optimization since these changes are already handled by c12. This prevents duplicate handling of configuration changes and potential race conditions. The comment clearly explains the rationale.

packages/cli/src/indexer/vcr.ts (1)

1-1: Clean re-export of VCR module

This is a well-structured re-export that follows the pattern established for other indexer modules. This approach simplifies imports for consumers by providing a more direct path via the CLI package.

packages/cli/src/core/config/loader.ts (1)

10-13: Good addition of runtime config resolver to the config pipeline

Adding the runtimeConfigResolver to the config resolvers array ensures that runtime values are properly assigned to environment variables during the configuration loading process. The comment clearly explains the responsibility of this resolver.

This change aligns well with the broader refactoring goal of centralizing runtime configuration management through environment variables rather than passing config objects directly.

packages/cli/src/core/apibara.ts (1)

31-32: Parameter rename improves clarity

Renaming the parameter from config to newConfig provides better clarity by distinguishing between the initial configuration and subsequent updates. This matches the parameter naming in the updateApibaraConfig function.

packages/cli/tsconfig.json (3)

7-7: Broader rootDir scope enables full package compilation

Changing the rootDir from "src" to "." expands TypeScript's compilation scope to include the entire package folder, which is necessary for the new module structure.


18-19: New path mappings support modular imports

Adding path mappings for apibara/runtime and apibara/common supports the new modular structure and simplifies imports across the codebase. This aligns with the export updates in package.json.


22-22: Removal of include/exclude fields

The removal of the include and exclude fields is appropriate given the broader rootDir scope. This allows TypeScript to use its default inclusion behavior based on the rootDir.

packages/cli/src/types/config.ts (1)

44-47: Expanded dynamic config to include preset-related properties

The ApibaraDynamicConfig type has been expanded to include not just runtimeConfig but also preset and presets properties. This change aligns with the PR's objective to improve hot-reloading by making preset configuration dynamically refreshable.

packages/cli/src/create/templates.ts (1)

72-73: Updated import paths to use simplified unscoped package names

The template now uses unscoped imports (apibara/indexer and apibara/plugins) instead of scoped package imports (@apibara/indexer and @apibara/indexer/plugins). This implements the PR goal of re-exporting indexer modules through the CLI package.

packages/cli/src/runtime/start.ts (3)

2-2: Added import for centralized runtime configuration handling

The getRuntimeDataFromEnv import from apibara/common supports the refactored runtime data flow for retrieving configuration from environment variables.


22-24: Refactored runtime configuration retrieval

Now retrieving both processedRuntimeConfig and preset from environment variables using getRuntimeDataFromEnv() instead of directly accessing the preset from command arguments. This centralizes configuration management and improves hot-reloading capability.


27-31: Updated createIndexer call signature to use object parameter

Changed from positional parameters to a named object parameter with indexerName, processedRuntimeConfig, and preset. This provides better clarity and flexibility for future parameter changes.

packages/cli/src/runtime/dev.ts (3)

2-2: Added import for centralized runtime configuration handling

Similar to start.ts, importing getRuntimeDataFromEnv from apibara/common to support the refactored runtime data flow.


23-25: Refactored runtime configuration retrieval

Now retrieving configuration data from environment variables, which aligns with the centralized runtime data flow approach implemented throughout the CLI.


43-47: Updated createIndexer call signature to use object parameter

Consistent with the changes in start.ts, using a named object parameter for better code clarity and maintainability.

packages/cli/build.config.ts (6)

14-14: Well-structured modular organization with addition of "common" module.

Adding the "common" module to the modules array helps organize shared code and utilities that will be used across different parts of the application, supporting the refactoring of runtime data flow.


29-29: Proper entry point configuration for the new common module.

This correctly defines the entry point for the new "common" module that was added to the modules list above.


31-31: Good modularization by adding indexer module export.

Adding the indexer module as a separate entry enables re-exporting from @apibara/indexer as described in the PR objectives, improving the package structure and user experience.


33-33: Improved debugging with sourcemap support.

Enabling sourcemaps across all packages will significantly improve the debugging experience, allowing developers to see the original TypeScript code in stack traces and debugging tools.


50-57: Good build performance monitoring with time logging.

Adding build hooks to measure and log the build duration is a helpful development improvement that will make it easier to track build performance over time.


60-60: Improved type safety in the banner function.

Explicitly typing the fileName parameter as a string improves type safety and code readability.

packages/cli/src/core/config/update.ts (4)

2-2: Key dependency for the new runtime config resolution strategy.

Importing the runtimeConfigResolver is essential for the new approach to handling runtime configuration through environment variables rather than at build time.


6-6: Improved parameter naming for better code clarity.

Changing the parameter name from _config to newConfig makes the code more readable and self-documenting.


8-9: Core implementation of hot reload for runtime config.

This change is central to addressing the PR's objective of fixing runtime config not updating correctly during development. By applying new config values to environment variables, it ensures they're available to restarted indexers.


11-12: Enhanced hot-reloading mechanism.

Replaced the previous "rolldown:reload" hook with "dev:reload" to restart indexers with the updated runtime values, supporting the PR objective of improving the hot-reloading mechanism.

packages/cli/src/core/config/resolvers/runtime.resolver.ts (5)

1-8: Well-organized imports from the new common module.

Importing constants and helper functions from the new common module maintains good separation of concerns and enables the centralized runtime config management intended by this PR.


11-14: Good function signature and initial variable extraction.

The function correctly accepts a partial options object and extracts only the required properties needed for runtime configuration processing.


15-24: Proper environment variable persistence for configuration values.

Setting the runtime config, preset, and presets as JSON-stringified environment variables creates a consistent way to pass these values to child processes and during hot reloads.


30-38: Well-structured final config processing and storage.

This block effectively processes and merges configuration from multiple sources (base config, presets, and environment variables) and stores the result in an environment variable for consistent access.


39-43: Comprehensive error handling.

The try-catch block with a descriptive error message and proper error cause handling will make debugging easier if issues arise with runtime configuration processing.

packages/cli/src/runtime/project-info.ts (4)

3-6: Good use of newly extracted common helper functions.

Importing these helper functions from the common module helps maintain consistency in how runtime configuration is accessed and processed throughout the application.


37-39: Improved configuration source with environment variables.

Using getRuntimeDataFromEnv() aligns with the PR's objective to refactor runtime data flow and ensures consistent access to configuration across the application.


41-48: Well-structured preset processing.

The code now properly processes runtime configuration for each preset by calling getProcessedRuntimeConfig with all relevant sources of configuration data, which is crucial for the improved hot-reloading mechanism.


51-55: Improved function call with named parameters.

Using an object with named parameters for the createIndexer call improves code readability and makes the API more resilient to future changes.

packages/cli/package.json (2)

35-38: Good addition of new ./common export path

Adding this export path for the common module is a good choice as it centralizes shared utilities and constants. This will make it easier to maintain consistent environment variable names and helpers across the codebase.


59-74: Well-structured re-exports from indexer package

These new export paths effectively implement the PR objective of re-exporting modules from @apibara/indexer through the CLI package. This modular approach allows users to import from cleaner paths like apibara/indexer instead of @apibara/indexer, improving developer experience while maintaining proper organization of the code.

packages/cli/src/runtime/internal/app.ts (2)

24-38: Improved function signature with better parameter structure

The refactored function signature with a single object parameter is a good improvement. It makes the API more explicit and extensible, with clear JSDoc comments that document the purpose of each parameter.


57-57: Direct use of processed runtime config

This change correctly implements the refactored runtime data flow by directly using the externally provided processedRuntimeConfig instead of calculating it internally. This addresses the issue where runtime config values weren't updating correctly during development.

packages/cli/src/common/constants.ts (1)

1-6: Good centralization of environment variable constants

Creating this constants file is a good practice for centralizing and standardizing environment variable names. The naming convention clearly distinguishes between internal variables (prefixed with underscore) and user-facing ones, which helps prevent naming conflicts and makes the code more maintainable.

packages/cli/src/cli/commands/dev.ts (6)

12-13: Enhanced hot module reloading key regex

The updated regex properly expands HMR to include preset and presets.* keys, which aligns with the PR objective to improve hot-reloading of configuration values. This will ensure that changes to these keys trigger appropriate updates without unnecessary rebuilds.


82-82: Improved log readability

Adding a newline character to the config update log message improves readability by formatting the diff entries as a list rather than a single line, making it easier for developers to identify what changed.


86-87: Clearer documentation of hot reload behavior

The updated comment provides better clarity about what hot reloading actually does - updating runtime values and restarting indexers without rebuilding. This helps other developers understand the system behavior.


95-97: Properly await reload in restart hook

Making the restart hook callback async and awaiting the reload function ensures that the reload process completes before continuing, preventing potential race conditions or incomplete reloads.


117-117: Better sequencing of restart log message

Moving the "Restarting indexers" log message to after killing the child process makes the log sequence more accurate and helps developers better understand the actual flow of operations.


144-148: Appropriate log level for process exit

Changing to apibara.logger.info from apibara.logger.log is more semantically appropriate for this type of operational message, maintaining consistent logging practices.

@jaipaljadeja jaipaljadeja changed the title feat: refactor runtime data flow, improve hot-reloading, re-export indexer modules, add sourcemaps feat: refactor runtime data flow, improve hot-reloading, re-export indexer modules, add sourcemaps, option to override clientOptions in indexer Apr 18, 2025
@fracek fracek merged commit c60ae9b into apibara:main Apr 18, 2025
2 checks passed
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