Configuration (fireschema.config.json
)
The FireSchema generator is configured using a JSON file, typically named fireschema.config.json
. This file tells the CLI where to find your schema definition and specifies how and where to generate the code for different target platforms and SDKs.
Example Configuration
Here's an example demonstrating common configuration options:
json
{
"schema": "./firestore.schema.json", // Required: Path to schema file (relative to this config file)
"outputs": [ // Required: Array of output targets
{
"target": "typescript-client", // Target: TS + Firebase Client SDK (v9+)
"outputDir": "./src/generated/firestore-ts-client", // Output directory (relative to this config file)
"options": { // Optional target-specific options
"dateTimeType": "Timestamp" // 'Timestamp' or 'Date' (default: 'Timestamp')
},
"package": { // Optional: Generate package.json
"name": "my-project-firestore-ts-client",
"version": "1.0.0"
}
},
{
"target": "typescript-admin", // Target: TS + Firebase Admin SDK
"outputDir": "./src/generated/firestore-ts-admin",
"options": {
"dateTimeType": "Timestamp"
}
// "package": { ... } // Optional package generation
},
{
"target": "dart-client", // Target: Dart + cloud_firestore
"outputDir": "./lib/generated/firestore_dart",
"options": { // Optional Dart options
"nullSafety": true // Generate null-safe code (default: true)
},
"package": { // Optional: Generate pubspec.yaml
"name": "my_project_firestore_dart",
"version": "1.0.0",
"description": "Generated Dart ODM"
}
}
// Add more targets as needed
],
"generatorOptions": { // Optional global options
"logLevel": "info" // 'verbose', 'info', 'warn', 'error' (default: 'info')
}
}
Configuration Options
schema
- (Required, string)
- Specifies the path to your
firestore.schema.json
file. - Important: This path is resolved relative to the location of the
fireschema.config.json
file itself.
outputs
(Required, array)
An array where each object defines a specific code generation target. This allows generating code for multiple platforms (e.g., a TypeScript web frontend and a Dart mobile app) from the single schema definition.
Each output object contains:
target
(Required, string):- Identifies the desired language and SDK combination. This determines which internal code generator (adapter) is used and which runtime library the generated code will depend on.
- Supported Values:
"typescript-client"
: For TypeScript projects using the Firebase Client SDK (firebase
v9+)."typescript-admin"
: For TypeScript projects using the Firebase Admin SDK (firebase-admin
)."dart-client"
: For Dart/Flutter projects using thecloud_firestore
package.
- (More targets may be added in the future).
outputDir
(Required, string):- The directory where the generated code for this specific target will be placed.
- Important: This path is also resolved relative to the location of the
fireschema.config.json
file.
options
(Optional, object):- Provides language/target-specific generation settings.
- TypeScript Client/Admin Options:
dateTimeType
(Optional, string, default:"Timestamp"
): Controls the type generated fortimestamp
fields."Timestamp"
: Uses FirestoreTimestamp
(fromfirebase/firestore
orfirebase-admin/firestore
). Recommended for direct Firestore interaction."Date"
: Uses the standard JavaScriptDate
object. Requires manual conversion when reading/writing to Firestore.
- Dart Client Options:
nullSafety
(Optional, boolean, default:true
): Determines whether to generate null-safe Dart code (highly recommended).
package
(Optional, object):- If provided, FireSchema generates a basic package manifest file (
package.json
for TS,pubspec.yaml
for Dart) within theoutputDir
. - This is useful if you want to treat the generated code as a distinct, importable package within a monorepo or for separate publishing.
- Requires at least a
name
property:name
(Required, string): The name for the generated package.version
(Optional, string, default:"0.1.0"
): The package version.description
(Optional, string): A description for the package.
- If provided, FireSchema generates a basic package manifest file (
generatorOptions
- (Optional, object)
- Global options affecting the generator's overall behavior.
logLevel
(Optional, string, default:"info"
): Controls the amount of information logged to the console during generation.- Supported values:
"verbose"
,"info"
,"warn"
,"error"
.
- Supported values: