@travetto/model-firestore 7.0.0-rc.2 → 7.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,7 +47,7 @@ export class FirestoreModelConfig {
47
47
  emulator?: string;
48
48
  projectId: string;
49
49
  namespace?: string;
50
- autoCreate?: boolean;
50
+ modifyStorage?: boolean;
51
51
  credentials?: FirestoreModelConfigCredentials;
52
52
 
53
53
  async postConstruct(): Promise<void> {
@@ -56,7 +56,7 @@ export class FirestoreModelConfig {
56
56
  }
57
57
  if (this.credentialsFile && !this.credentials) {
58
58
  this.credentials = FirestoreModelConfigCredentials.from(
59
- JSON.parse(await RuntimeResources.read(this.credentialsFile))
59
+ await RuntimeResources.readJSON(this.credentialsFile)
60
60
  );
61
61
  await SchemaValidator.validate(FirestoreModelConfigCredentials, this.credentials);
62
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-firestore",
3
- "version": "7.0.0-rc.2",
3
+ "version": "7.0.0-rc.3",
4
4
  "description": "Firestore backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,10 +26,10 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@google-cloud/firestore": "^7.11.6",
29
- "@travetto/cli": "^7.0.0-rc.2",
30
- "@travetto/config": "^7.0.0-rc.2",
31
- "@travetto/model": "^7.0.0-rc.2",
32
- "@travetto/runtime": "^7.0.0-rc.2"
29
+ "@travetto/cli": "^7.0.0-rc.3",
30
+ "@travetto/config": "^7.0.0-rc.3",
31
+ "@travetto/model": "^7.0.0-rc.3",
32
+ "@travetto/runtime": "^7.0.0-rc.3"
33
33
  },
34
34
  "travetto": {
35
35
  "displayName": "Firestore Model Support"
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RuntimeResources } from '@travetto/runtime';
1
+ import { Runtime, RuntimeResources } from '@travetto/runtime';
2
2
  import { Config } from '@travetto/config';
3
3
  import { Schema, SchemaValidator } from '@travetto/schema';
4
4
 
@@ -14,18 +14,22 @@ export class FirestoreModelConfig {
14
14
  databaseURL?: string;
15
15
  credentialsFile?: string;
16
16
  emulator?: string;
17
- projectId: string;
17
+ projectId?: string;
18
18
  namespace?: string;
19
- autoCreate?: boolean;
19
+ modifyStorage?: boolean;
20
20
  credentials?: FirestoreModelConfigCredentials;
21
21
 
22
22
  async postConstruct(): Promise<void> {
23
+ if (!this.databaseURL && !Runtime.production) {
24
+ this.projectId ??= 'trv-local-dev';
25
+ this.emulator ??= 'localhost:7000'; // From docker
26
+ }
23
27
  if (this.emulator) {
24
28
  process.env.FIRESTORE_EMULATOR_HOST = this.emulator;
25
29
  }
26
30
  if (this.credentialsFile && !this.credentials) {
27
31
  this.credentials = FirestoreModelConfigCredentials.from(
28
- JSON.parse(await RuntimeResources.read(this.credentialsFile))
32
+ await RuntimeResources.readJSON(this.credentialsFile)
29
33
  );
30
34
  await SchemaValidator.validate(FirestoreModelConfigCredentials, this.credentials);
31
35
  }
package/src/service.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DocumentData, FieldValue, Firestore, PartialWithFieldValue, Query } from '@google-cloud/firestore';
2
2
 
3
- import { ShutdownManager, type Class, type DeepPartial } from '@travetto/runtime';
3
+ import { JSONUtil, ShutdownManager, type Class, type DeepPartial } from '@travetto/runtime';
4
4
  import { Injectable } from '@travetto/di';
5
5
  import {
6
6
  ModelCrudSupport, ModelRegistryIndex, ModelStorageSupport,
@@ -13,7 +13,7 @@ import { FirestoreModelConfig } from './config.ts';
13
13
  const clone = structuredClone;
14
14
 
15
15
  const toSimpleObject = <T>(input: T, missingValue: unknown = null): PartialWithFieldValue<DocumentData> =>
16
- JSON.parse(JSON.stringify(input, (_, value) => value ?? null), (_, value) => value ?? missingValue);
16
+ JSONUtil.parseSafe(JSON.stringify(input, (_, value) => value ?? null), (_, value) => value ?? missingValue);
17
17
 
18
18
  /**
19
19
  * A model service backed by Firestore