@travetto/model-firestore
v7.1.4
Published
Firestore backing for the travetto model module.
Maintainers
Readme
Firestore Model Support
Firestore backing for the travetto model module.
Install: @travetto/model-firestore
npm install @travetto/model-firestore
# or
yarn add @travetto/model-firestoreThis module provides an Firestore-based implementation of the Data Modeling Support. This source allows the Data Modeling Support module to read, write and query against Firestore.
Supported features:
Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source or config, you can override and register it with the Dependency Injection module.
Code: Wiring up a custom Model Source
import { InjectableFactory } from '@travetto/di';
import { type FirestoreModelConfig, FirestoreModelService } from '@travetto/model-firestore';
export class Init {
@InjectableFactory({
primary: true
})
static getModelSource(config: FirestoreModelConfig) {
return new FirestoreModelService(config);
}
}where the FirestoreModelConfig is defined by:
Code: Structure of FirestoreModelConfig
@Config('model.firestore')
export class FirestoreModelConfig {
databaseURL?: string;
credentialsFile?: string;
emulator?: string;
projectId?: string;
namespace?: string;
modifyStorage?: boolean;
credentials?: FirestoreModelConfigCredentials;
async postConstruct(): Promise<void> {
if (!this.databaseURL && !Runtime.production) {
this.projectId ??= 'trv-local-dev';
this.emulator ??= 'localhost:7000'; // From docker
}
if (this.emulator) {
process.env.FIRESTORE_EMULATOR_HOST = this.emulator;
}
if (this.credentialsFile && !this.credentials) {
this.credentials = FirestoreModelConfigCredentials.from(
await RuntimeResources.readJSON(this.credentialsFile)
);
await SchemaValidator.validate(FirestoreModelConfigCredentials, this.credentials);
}
}
}Additionally, you can see that the class is registered with the @Config annotation, and so these values can be overridden using the standard Configuration resolution paths.
