@causa/workspace-google 1.0.1 → 1.2.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 +4 -1
- package/dist/functions/google-firestore/generate-typescript-decorators.js +15 -5
- package/dist/functions/index.js +2 -1
- package/dist/functions/typescript/generate-typescript-trigger-decorators.d.ts +12 -0
- package/dist/functions/typescript/generate-typescript-trigger-decorators.js +71 -0
- package/dist/functions/typescript/index.d.ts +1 -0
- package/dist/functions/typescript/index.js +1 -0
- package/package.json +4 -4
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
|
-
#
|
|
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
|
|
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
|
|
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 =
|
|
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}({
|
|
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/dist/functions/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { DatabaseQueryRecordsForSpanner, GoogleSpannerListDatabases, GoogleSpann
|
|
|
11
11
|
import { ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, } from './project/index.js';
|
|
12
12
|
import { SecretFetchForGoogleAccessToken, SecretFetchForGoogleSecretManager, } from './secret/index.js';
|
|
13
13
|
import { ServiceContainerQueryLogsForCloudRun } from './service-container/index.js';
|
|
14
|
+
import { ModelGenerateTypeScriptTriggerDecoratorsForGoogle } from './typescript/index.js';
|
|
14
15
|
export function registerFunctions(context) {
|
|
15
|
-
context.registerFunctionImplementations(CausaListConfigurationSchemasForGoogle, DatabaseQueryRecordsForFirestore, DatabaseQueryRecordsForSpanner, EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, EventTopicBrokerCreateTopicForPubSub, EventTopicBrokerCreateTriggerForCloudRun, EventTopicBrokerDeleteTopicForPubSub, EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole, EventTopicBrokerDeleteTriggerResourceForCloudRunService, EventTopicBrokerDeleteTriggerResourceForPubSubSubscription, EventTopicBrokerDeleteTriggerResourceForServiceAccount, EventTopicBrokerGetTopicIdForPubSub, EventTopicBrokerPublishEventsForGoogle, EventTopicBrokerWaitForProcessingForPubSub, EventTopicCreateBackfillSourceForBigQuery, EventTopicQueryEventsForBigQuery, GoogleAppCheckGenerateToken, GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, GooglePubSubWriteTopics, GoogleServicesEnable, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, ModelGenerateTypeScriptDecoratorsForGoogleFirestore, ModelGenerateTypeScriptDecoratorsForGoogleSpanner, ModelSchemaExtractDatabaseForGoogleFirestore, ModelSchemaExtractDatabaseForGoogleSpanner, ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, SecretFetchForGoogleAccessToken, SecretFetchForGoogleSecretManager, ServiceContainerQueryLogsForCloudRun);
|
|
16
|
+
context.registerFunctionImplementations(CausaListConfigurationSchemasForGoogle, DatabaseQueryRecordsForFirestore, DatabaseQueryRecordsForSpanner, EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, EventTopicBrokerCreateTopicForPubSub, EventTopicBrokerCreateTriggerForCloudRun, EventTopicBrokerDeleteTopicForPubSub, EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole, EventTopicBrokerDeleteTriggerResourceForCloudRunService, EventTopicBrokerDeleteTriggerResourceForPubSubSubscription, EventTopicBrokerDeleteTriggerResourceForServiceAccount, EventTopicBrokerGetTopicIdForPubSub, EventTopicBrokerPublishEventsForGoogle, EventTopicBrokerWaitForProcessingForPubSub, EventTopicCreateBackfillSourceForBigQuery, EventTopicQueryEventsForBigQuery, GoogleAppCheckGenerateToken, GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, GooglePubSubWriteTopics, GoogleServicesEnable, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, ModelGenerateTypeScriptDecoratorsForGoogleFirestore, ModelGenerateTypeScriptDecoratorsForGoogleSpanner, ModelGenerateTypeScriptTriggerDecoratorsForGoogle, ModelSchemaExtractDatabaseForGoogleFirestore, ModelSchemaExtractDatabaseForGoogleSpanner, ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, SecretFetchForGoogleAccessToken, SecretFetchForGoogleSecretManager, ServiceContainerQueryLogsForCloudRun);
|
|
16
17
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModelGenerateTypeScriptTriggerDecorators } from '@causa/workspace-typescript';
|
|
2
|
+
import { type TypeScriptDecorator } from '@causa/workspace-typescript/code-generation';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link ModelGenerateTypeScriptTriggerDecorators} for services running on the Google platform.
|
|
5
|
+
*
|
|
6
|
+
* Each supported trigger type is mapped to a `@UseEventHandler(...)` decorator with the handler ID of the Google
|
|
7
|
+
* service backing the trigger (Pub/Sub, Cloud Tasks, Cloud Scheduler, or Eventarc).
|
|
8
|
+
*/
|
|
9
|
+
export declare class ModelGenerateTypeScriptTriggerDecoratorsForGoogle extends ModelGenerateTypeScriptTriggerDecorators {
|
|
10
|
+
_call(): TypeScriptDecorator[];
|
|
11
|
+
_supports(): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ModelGenerateTypeScriptTriggerDecorators } from '@causa/workspace-typescript';
|
|
2
|
+
import { externalImportSpec, externalSymbolAlias, } from '@causa/workspace-typescript/code-generation';
|
|
3
|
+
/**
|
|
4
|
+
* The name of the Causa module for the TypeScript runtime, from which `UseEventHandler` is imported.
|
|
5
|
+
*/
|
|
6
|
+
const CAUSA_RUNTIME_NESTJS_MODULE = '@causa/runtime/nestjs';
|
|
7
|
+
/**
|
|
8
|
+
* The name of the Causa module for the TypeScript Google runtime.
|
|
9
|
+
*/
|
|
10
|
+
const CAUSA_GOOGLE_MODULE = '@causa/runtime-google';
|
|
11
|
+
/**
|
|
12
|
+
* The handler ID symbol to pass to `UseEventHandler` for each supported trigger type, along with the module from
|
|
13
|
+
* which it should be imported.
|
|
14
|
+
*/
|
|
15
|
+
const HANDLER_IDS_FOR_TRIGGER_TYPES = {
|
|
16
|
+
event: { module: CAUSA_GOOGLE_MODULE, symbol: 'PUBSUB_EVENT_HANDLER_ID' },
|
|
17
|
+
'google.pubSub': {
|
|
18
|
+
module: CAUSA_GOOGLE_MODULE,
|
|
19
|
+
symbol: 'PUBSUB_EVENT_HANDLER_ID',
|
|
20
|
+
},
|
|
21
|
+
task: {
|
|
22
|
+
module: CAUSA_GOOGLE_MODULE,
|
|
23
|
+
symbol: 'CLOUD_TASKS_EVENT_HANDLER_ID',
|
|
24
|
+
},
|
|
25
|
+
'google.tasks': {
|
|
26
|
+
module: CAUSA_GOOGLE_MODULE,
|
|
27
|
+
symbol: 'CLOUD_TASKS_EVENT_HANDLER_ID',
|
|
28
|
+
},
|
|
29
|
+
cron: {
|
|
30
|
+
module: CAUSA_GOOGLE_MODULE,
|
|
31
|
+
symbol: 'CLOUD_SCHEDULER_EVENT_HANDLER_ID',
|
|
32
|
+
},
|
|
33
|
+
'google.scheduler': {
|
|
34
|
+
module: CAUSA_GOOGLE_MODULE,
|
|
35
|
+
symbol: 'CLOUD_SCHEDULER_EVENT_HANDLER_ID',
|
|
36
|
+
},
|
|
37
|
+
'google.eventarc': {
|
|
38
|
+
module: CAUSA_RUNTIME_NESTJS_MODULE,
|
|
39
|
+
symbol: 'CLOUDEVENTS_EVENT_HANDLER_ID',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Implements {@link ModelGenerateTypeScriptTriggerDecorators} for services running on the Google platform.
|
|
44
|
+
*
|
|
45
|
+
* Each supported trigger type is mapped to a `@UseEventHandler(...)` decorator with the handler ID of the Google
|
|
46
|
+
* service backing the trigger (Pub/Sub, Cloud Tasks, Cloud Scheduler, or Eventarc).
|
|
47
|
+
*/
|
|
48
|
+
export class ModelGenerateTypeScriptTriggerDecoratorsForGoogle extends ModelGenerateTypeScriptTriggerDecorators {
|
|
49
|
+
_call() {
|
|
50
|
+
const handlerId = HANDLER_IDS_FOR_TRIGGER_TYPES[this.trigger.type];
|
|
51
|
+
if (!handlerId) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
const useEventHandlerAlias = externalSymbolAlias(CAUSA_RUNTIME_NESTJS_MODULE, 'UseEventHandler');
|
|
55
|
+
const handlerIdAlias = externalSymbolAlias(handlerId.module, handlerId.symbol);
|
|
56
|
+
const imports = {
|
|
57
|
+
[CAUSA_RUNTIME_NESTJS_MODULE]: [
|
|
58
|
+
externalImportSpec(CAUSA_RUNTIME_NESTJS_MODULE, 'UseEventHandler'),
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
(imports[handlerId.module] ??= []).push(externalImportSpec(handlerId.module, handlerId.symbol));
|
|
62
|
+
return [{ source: `@${useEventHandlerAlias}(${handlerIdAlias})`, imports }];
|
|
63
|
+
}
|
|
64
|
+
_supports() {
|
|
65
|
+
return (this.generator === 'typescriptNestjsController' &&
|
|
66
|
+
this._context.get('project.language') === 'typescript' &&
|
|
67
|
+
this._context
|
|
68
|
+
.asConfiguration()
|
|
69
|
+
.get('serviceContainer.platform') === 'google.cloudRun');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ModelGenerateTypeScriptTriggerDecoratorsForGoogle } from './generate-typescript-trigger-decorators.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ModelGenerateTypeScriptTriggerDecoratorsForGoogle } from './generate-typescript-trigger-decorators.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@causa/workspace-google",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "The Causa workspace module providing many functionalities related to GCP and its services.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@causa/cli": "^1.0.0",
|
|
39
39
|
"@causa/workspace": "^1.0.1",
|
|
40
|
-
"@causa/workspace-core": "^1.0
|
|
41
|
-
"@causa/workspace-typescript": "^1.0
|
|
40
|
+
"@causa/workspace-core": "^1.1.0",
|
|
41
|
+
"@causa/workspace-typescript": "^1.1.0",
|
|
42
42
|
"@google-cloud/apikeys": "^2.2.2",
|
|
43
43
|
"@google-cloud/bigquery": "^8.3.1",
|
|
44
44
|
"@google-cloud/iam-credentials": "^4.2.2",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@tsconfig/node22": "^22.0.5",
|
|
67
67
|
"@types/jest": "^30.0.0",
|
|
68
68
|
"@types/micromatch": "^4.0.10",
|
|
69
|
-
"@types/node": "^20.19.
|
|
69
|
+
"@types/node": "^20.19.43",
|
|
70
70
|
"copyfiles": "^2.4.1",
|
|
71
71
|
"eslint": "^10.4.1",
|
|
72
72
|
"eslint-config-prettier": "^10.1.8",
|