Skip to content

Emulator edition#10280

Open
harshyyy21 wants to merge 8 commits intomainfrom
emulatorEdition
Open

Emulator edition#10280
harshyyy21 wants to merge 8 commits intomainfrom
emulatorEdition

Conversation

@harshyyy21
Copy link
Copy Markdown
Contributor

@harshyyy21 harshyyy21 commented Apr 7, 2026

Description

Add a new --edition flag to the Firestore Emulator. Valid values are "standard" or "enterprise". The default value is "standard" if one is not provided. This changes also allows user to specify edition via firebase.json. If command line flag is also present, it takes precedence over firebase.json.

Scenarios Tested

Manually tested starting and querying various combinations of this flag.

Example:

firebase.json:
{
  ...
  "emulators": {
    "firestore": {
      "port": 8080,
      "edition": "enterprise"
    },
    ...
  }
}

node lib/bin/firebase.js emulators:start --only firestore --project verify-1168a                   
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
✔  firestore: Firestore Emulator was started in enterprise edition.
✔  firestore: Firestore Emulator UI websocket is running on 9150.

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://127.0.0.1:4000/               │
└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub host: 127.0.0.1 port: 4400
  Other reserved ports: 4500, 9150

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
firebase.json:
{
  ...
  "emulators": {
    "firestore": {
      "port": 8080,
    },
    ...
  }
}

node lib/bin/firebase.js emulators:start --only firestore --project verify-1168a --edition enterprise
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
✔  firestore: Firestore Emulator was started in enterprise edition.
✔  firestore: Firestore Emulator UI websocket is running on 9150.

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://127.0.0.1:4000/               │
└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub host: 127.0.0.1 port: 4400
  Other reserved ports: 4500, 9150

Invalid Edition:

(base) harshprajapati@mac firebase-tools % node lib/bin/firebase.js emulators:start --only firestore --project verify-1168a --edition invalid  
i  emulators: Starting emulators: firestore
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub

Error: The Firestore emulator edition must be either 'standard' or 'enterprise'.

Sample Commands

firebase emulators:start --only firestore --edition enterprise

@harshyyy21 harshyyy21 requested a review from joehan April 7, 2026 21:56
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for selecting the Firestore emulator edition (standard or enterprise) through a new --edition CLI flag and firebase.json configuration. Key improvements suggested include hardening the edition selection logic to prevent crashes when the flag is used without a value, implementing stricter validation using enums in the JSON schema, and enhancing type safety by replacing generic strings with union types for the edition property.

I am having trouble creating individual review comments. Click here to see my feedback.

src/emulator/controller.ts (645-653)

high

The current logic for determining the emulator edition has a few issues:

  1. Potential Crash: If the --edition flag is provided without a value (e.g., firebase emulators:start --edition), options.edition will be true at runtime, causing cliEdition.toLowerCase() to throw an error.
  2. Lack of Validation: Any string provided via CLI or config is accepted and logged as the edition, even if it's invalid.
  3. Complexity: The logic can be simplified to reduce nesting, as per the repository style guide.

Using utils.assertIsString and adding explicit validation against allowed values is recommended.

    if (options.edition !== undefined) {
      utils.assertIsString(options.edition, "edition");
    }
    const edition = (
      (options.edition as string) ||
      options.config.src.emulators?.firestore?.edition ||
      "standard"
    ).toLowerCase();
    if (edition !== "standard" && edition !== "enterprise") {
      throw new FirebaseError(
        "The Firestore emulator edition must be either 'standard' or 'enterprise'.",
        { exit: 1 },
      );
    }
References
  1. Reduce nesting as much as possible. Handle edge cases early and exit or fold them into the general case. (link)

schema/firebase-config.json (1424-1426)

medium

It is recommended to define an enum for the edition property in the JSON schema. This provides better validation and autocompletion for users editing their firebase.json file.

                        "edition": {
                            "type": "string",
                            "enum": ["standard", "enterprise"]
                        }

src/firebaseConfig.ts (243)

medium

Using a union type instead of a generic string for the edition property improves type safety and adheres to the repository's best practice of avoiding loose types when possible.

    edition?: "standard" | "enterprise";
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

src/options.ts (29)

medium

For better type safety, consider using a union type for the edition option, matching the allowed values for the Firestore emulator.

  edition?: "standard" | "enterprise";
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

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