Package Exports
- @travetto/model-firestore
- @travetto/model-firestore/__index__.ts
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@travetto/model-firestore) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Firestore Model Support
Firestore backing for the travetto model module.
Install: @travetto/model-firestore
npm install @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](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") module.Code: Wiring up a custom Model Source
import { InjectableFactory } from '@travetto/di';
import { FirestoreModelConfig, FirestoreModelService } from '@travetto/model-firestore';
export class Init {
@InjectableFactory({
primary: true
})
static getModelSource(conf: FirestoreModelConfig) {
return new FirestoreModelService(conf);
}
}where the FirestoreModelConfig is defined by:
Code: Structure of FirestoreModelConfig
import { FileResourceProvider } from '@travetto/base';
import { Config } from '@travetto/config';
@Config('model.firestore')
export class FirestoreModelConfig {
databaseURL?: string;
credentialsFile?: string;
emulator?: string;
projectId: string;
namespace?: string;
autoCreate?: boolean;
credentials?: {
client_email: string;
project_id: string;
private_key: string;
};
async postConstruct(): Promise<void> {
if (this.emulator) {
process.env.FIRESTORE_EMULATOR_HOST = this.emulator;
}
if (this.credentialsFile && !this.credentials) {
const resources = new FileResourceProvider({ includeCommon: true });
this.credentials = JSON.parse(await resources.read(this.credentialsFile));
}
}
}Additionally, you can see that the class is registered with the @Config annotation, and so these values can be overridden using the standard Configurationresolution paths.