@causa/workspace-google 1.0.1 → 1.1.0

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
@@ -130,7 +130,8 @@ additionalProperties: false
130
130
  causa:
131
131
  # This must be set for the decorators to be added to the class.
132
132
  googleFirestoreCollection:
133
- # Mandatory, the name of the Firestore collection.
133
+ # Optional, the name of the Firestore collection.
134
+ # If not set, the `name` is omitted from the decorator options.
134
135
  name: myCollection
135
136
  # Mandatory, determines how to create the path for a document.
136
137
  path: [property: id]
@@ -166,6 +167,8 @@ model:
166
167
  # Same as Spanner globs.
167
168
  globs:
168
169
  - ../firestore/*.yaml
170
+ # Optional, generates the document path as an array of segments instead of a slash-joined string.
171
+ pathAsArray: true
169
172
  ```
170
173
 
171
174
  ## 🔨 Custom `google` commands
@@ -26,7 +26,9 @@ export class ModelGenerateTypeScriptDecoratorsForGoogleFirestore extends ModelGe
26
26
  if (!attribute) {
27
27
  return [];
28
28
  }
29
- const globs = this.configuration?.google?.firestore?.globs;
29
+ const firestoreConfiguration = this.configuration?.google
30
+ ?.firestore;
31
+ const globs = firestoreConfiguration?.globs;
30
32
  if (Array.isArray(globs)) {
31
33
  const projectPath = this._context.getProjectPathOrThrow();
32
34
  const absoluteGlobs = globs.map((g) => join(projectPath, g));
@@ -40,8 +42,8 @@ export class ModelGenerateTypeScriptDecoratorsForGoogleFirestore extends ModelGe
40
42
  throw new Error(`Invalid '${GOOGLE_FIRESTORE_COLLECTION_EXTENSION}' attribute on '${debugName}'. Expected an object.`);
41
43
  }
42
44
  const { name, path, hasSoftDelete } = attribute;
43
- if (typeof name !== 'string') {
44
- throw new Error(`Invalid '${GOOGLE_FIRESTORE_COLLECTION_EXTENSION}' attribute on '${debugName}'. Expected an object with a 'name' string property.`);
45
+ if (name !== undefined && typeof name !== 'string') {
46
+ throw new Error(`Invalid '${GOOGLE_FIRESTORE_COLLECTION_EXTENSION}' attribute on '${debugName}'. Expected the 'name' property to be a string.`);
45
47
  }
46
48
  if (!Array.isArray(path)) {
47
49
  throw new Error(`Invalid '${GOOGLE_FIRESTORE_COLLECTION_EXTENSION}' attribute on '${debugName}'. Expected an object with a 'path' array property.`);
@@ -63,9 +65,17 @@ export class ModelGenerateTypeScriptDecoratorsForGoogleFirestore extends ModelGe
63
65
  }
64
66
  throw new Error(`Invalid path element in '${GOOGLE_FIRESTORE_COLLECTION_EXTENSION}' attribute on '${debugName}'.`);
65
67
  });
66
- const pathExpression = path.length === 1 ? elements[0] : `[${elements.join(', ')}].join("/")`;
68
+ const pathExpression = firestoreConfiguration?.pathAsArray === true
69
+ ? `[${elements.join(', ')}]`
70
+ : path.length === 1
71
+ ? elements[0]
72
+ : `[${elements.join(', ')}].join("/")`;
73
+ const decoratorOptions = [`path: (doc) => ${pathExpression}`];
74
+ if (name !== undefined) {
75
+ decoratorOptions.push(`name: ${JSON.stringify(name)}`);
76
+ }
67
77
  const decorators = [];
68
- addDecoratorToList(decorators, { schema: this.schema }, 'FirestoreCollection', CAUSA_GOOGLE_MODULE, (alias) => `@${alias}({ name: ${JSON.stringify(name)}, path: (doc) => ${pathExpression} })`);
78
+ addDecoratorToList(decorators, { schema: this.schema }, 'FirestoreCollection', CAUSA_GOOGLE_MODULE, (alias) => `@${alias}({ ${decoratorOptions.join(', ')} })`);
69
79
  if (hasSoftDelete === true) {
70
80
  addDecoratorToList(decorators, { schema: this.schema }, 'SoftDeletedFirestoreCollection', CAUSA_GOOGLE_MODULE, (alias) => `@${alias}()`);
71
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causa/workspace-google",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "The Causa workspace module providing many functionalities related to GCP and its services.",
5
5
  "repository": {
6
6
  "type": "git",