@causa/workspace-google 0.17.0 → 0.18.0-beta.2
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/dist/configurations/schemas/google.yaml +37 -70
- package/dist/configurations/schemas/infrastructure.yaml +3 -5
- package/dist/configurations/schemas/service-container.yaml +7 -17
- package/dist/functions/emulator/start-firebase-storage.d.ts +1 -4
- package/dist/functions/emulator/start-firebase-storage.js +8 -11
- package/dist/functions/emulator/start-firestore.d.ts +1 -3
- package/dist/functions/emulator/start-firestore.js +8 -10
- package/dist/functions/emulator/start-identity-platform.d.ts +1 -4
- package/dist/functions/emulator/start-identity-platform.js +7 -10
- package/dist/functions/emulator/start-pubsub.call.d.ts +1 -2
- package/dist/functions/emulator/start-pubsub.call.js +2 -2
- package/dist/functions/emulator/start-pubsub.d.ts +1 -2
- package/dist/functions/emulator/start-pubsub.js +3 -3
- package/dist/functions/emulator/start-spanner.call.d.ts +1 -2
- package/dist/functions/emulator/start-spanner.call.js +2 -2
- package/dist/functions/emulator/start-spanner.d.ts +1 -2
- package/dist/functions/emulator/start-spanner.js +3 -3
- package/dist/functions/emulator/stop-firebase-storage.d.ts +1 -2
- package/dist/functions/emulator/stop-firebase-storage.js +5 -6
- package/dist/functions/emulator/stop-firestore.d.ts +1 -2
- package/dist/functions/emulator/stop-firestore.js +5 -6
- package/dist/functions/emulator/stop-identity-platform.d.ts +1 -2
- package/dist/functions/emulator/stop-identity-platform.js +5 -6
- package/dist/functions/emulator/stop-pubsub.d.ts +1 -2
- package/dist/functions/emulator/stop-pubsub.js +5 -6
- package/dist/functions/emulator/stop-spanner.d.ts +1 -2
- package/dist/functions/emulator/stop-spanner.js +5 -6
- package/dist/functions/event-topic/broker-create-topic-pubsub.call.d.ts +1 -2
- package/dist/functions/event-topic/broker-create-topic-pubsub.call.js +4 -4
- package/dist/functions/event-topic/broker-create-topic-pubsub.d.ts +2 -3
- package/dist/functions/event-topic/broker-create-topic-pubsub.js +7 -6
- package/dist/functions/event-topic/broker-create-trigger-cloud-run.call.d.ts +1 -2
- package/dist/functions/event-topic/broker-create-trigger-cloud-run.call.js +4 -4
- package/dist/functions/event-topic/broker-create-trigger-cloud-run.d.ts +2 -3
- package/dist/functions/event-topic/broker-create-trigger-cloud-run.js +8 -7
- package/dist/functions/event-topic/broker-delete-topic-pubsub.call.d.ts +1 -2
- package/dist/functions/event-topic/broker-delete-topic-pubsub.call.js +4 -4
- package/dist/functions/event-topic/broker-delete-topic-pubsub.d.ts +2 -3
- package/dist/functions/event-topic/broker-delete-topic-pubsub.js +7 -6
- package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.call.d.ts +1 -2
- package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.call.js +3 -3
- package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.d.ts +2 -3
- package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.js +7 -6
- package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.call.d.ts +1 -2
- package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.call.js +7 -4
- package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.d.ts +2 -3
- package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.js +7 -6
- package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.call.d.ts +1 -2
- package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.call.js +4 -4
- package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.d.ts +2 -3
- package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.js +7 -6
- package/dist/functions/event-topic/broker-get-topic-id-pubsub.d.ts +2 -3
- package/dist/functions/event-topic/broker-get-topic-id-pubsub.js +6 -6
- package/dist/functions/event-topic/broker-publish-events-google.call.d.ts +1 -2
- package/dist/functions/event-topic/broker-publish-events-google.call.js +6 -7
- package/dist/functions/event-topic/broker-publish-events-google.d.ts +2 -3
- package/dist/functions/event-topic/broker-publish-events-google.js +7 -6
- package/dist/functions/event-topic/create-backfill-source-bigquery.call.d.ts +1 -2
- package/dist/functions/event-topic/create-backfill-source-bigquery.call.js +4 -4
- package/dist/functions/event-topic/create-backfill-source-bigquery.d.ts +2 -3
- package/dist/functions/event-topic/create-backfill-source-bigquery.js +5 -5
- package/dist/functions/event-topic/query-events-bigquery.call.d.ts +1 -2
- package/dist/functions/event-topic/query-events-bigquery.call.js +4 -4
- package/dist/functions/event-topic/query-events-bigquery.d.ts +2 -3
- package/dist/functions/event-topic/query-events-bigquery.js +5 -5
- package/dist/functions/google-app-check/generate-token.call.d.ts +1 -2
- package/dist/functions/google-app-check/generate-token.call.js +3 -3
- package/dist/functions/google-app-check/generate-token.d.ts +2 -2
- package/dist/functions/google-app-check/generate-token.js +3 -3
- package/dist/functions/google-firebase-storage/merge-rules.d.ts +2 -2
- package/dist/functions/google-firebase-storage/merge-rules.js +4 -4
- package/dist/functions/google-firestore/extract-database.d.ts +11 -0
- package/dist/functions/google-firestore/extract-database.js +44 -0
- package/dist/functions/google-firestore/generate-typescript-decorators.d.ts +13 -0
- package/dist/functions/google-firestore/generate-typescript-decorators.js +78 -0
- package/dist/functions/google-firestore/index.d.ts +2 -0
- package/dist/functions/google-firestore/index.js +2 -0
- package/dist/functions/google-firestore/merge-rules.d.ts +2 -2
- package/dist/functions/google-firestore/merge-rules.js +4 -4
- package/dist/functions/google-firestore/query-records.call.d.ts +1 -2
- package/dist/functions/google-firestore/query-records.call.js +3 -3
- package/dist/functions/google-firestore/query-records.d.ts +1 -2
- package/dist/functions/google-firestore/query-records.js +3 -3
- package/dist/functions/google-identity-platform/generate-custom-token.call.d.ts +1 -2
- package/dist/functions/google-identity-platform/generate-custom-token.call.js +2 -2
- package/dist/functions/google-identity-platform/generate-custom-token.d.ts +2 -2
- package/dist/functions/google-identity-platform/generate-custom-token.js +3 -3
- package/dist/functions/google-identity-platform/generate-token.call.d.ts +1 -2
- package/dist/functions/google-identity-platform/generate-token.call.js +4 -4
- package/dist/functions/google-identity-platform/generate-token.d.ts +2 -2
- package/dist/functions/google-identity-platform/generate-token.js +3 -3
- package/dist/functions/google-pubsub/write-topics.d.ts +2 -3
- package/dist/functions/google-pubsub/write-topics.js +11 -12
- package/dist/functions/google-services/enable.call.d.ts +1 -2
- package/dist/functions/google-services/enable.call.js +3 -3
- package/dist/functions/google-services/enable.d.ts +2 -2
- package/dist/functions/google-services/enable.js +3 -3
- package/dist/functions/google-spanner/extract-database.d.ts +11 -0
- package/dist/functions/google-spanner/extract-database.js +25 -0
- package/dist/functions/google-spanner/generate-typescript-decorators.d.ts +14 -0
- package/dist/functions/google-spanner/generate-typescript-decorators.js +120 -0
- package/dist/functions/google-spanner/index.d.ts +2 -0
- package/dist/functions/google-spanner/index.js +2 -0
- package/dist/functions/google-spanner/list-databases.d.ts +2 -2
- package/dist/functions/google-spanner/list-databases.js +7 -7
- package/dist/functions/google-spanner/query-records.call.d.ts +1 -2
- package/dist/functions/google-spanner/query-records.call.js +4 -4
- package/dist/functions/google-spanner/query-records.d.ts +1 -2
- package/dist/functions/google-spanner/query-records.js +3 -3
- package/dist/functions/google-spanner/write-databases.d.ts +2 -3
- package/dist/functions/google-spanner/write-databases.js +11 -12
- package/dist/functions/index.js +3 -4
- package/dist/functions/project/get-artefact-destination-cloud-functions.d.ts +2 -3
- package/dist/functions/project/get-artefact-destination-cloud-functions.js +5 -6
- package/dist/functions/project/get-artefact-destination-cloud-run.d.ts +2 -3
- package/dist/functions/project/get-artefact-destination-cloud-run.js +5 -6
- package/dist/functions/project/push-artefact-cloud-functions.call.d.ts +1 -2
- package/dist/functions/project/push-artefact-cloud-functions.call.js +5 -5
- package/dist/functions/project/push-artefact-cloud-functions.d.ts +2 -3
- package/dist/functions/project/push-artefact-cloud-functions.js +5 -5
- package/dist/functions/secret/fetch-access-token.call.d.ts +1 -2
- package/dist/functions/secret/fetch-access-token.call.js +4 -2
- package/dist/functions/secret/fetch-access-token.d.ts +2 -2
- package/dist/functions/secret/fetch-access-token.js +3 -3
- package/dist/functions/secret/fetch-secret-manager.call.d.ts +1 -2
- package/dist/functions/secret/fetch-secret-manager.call.js +3 -3
- package/dist/functions/secret/fetch-secret-manager.d.ts +2 -2
- package/dist/functions/secret/fetch-secret-manager.js +3 -3
- package/dist/functions/service-container/query-logs-cloud-run.call.d.ts +1 -2
- package/dist/functions/service-container/query-logs-cloud-run.call.js +3 -3
- package/dist/functions/service-container/query-logs-cloud-run.d.ts +2 -3
- package/dist/functions/service-container/query-logs-cloud-run.js +5 -5
- package/package.json +16 -16
- package/dist/code-generation/google-firestore-renderer.d.ts +0 -12
- package/dist/code-generation/google-firestore-renderer.js +0 -89
- package/dist/code-generation/google-spanner-renderer.d.ts +0 -11
- package/dist/code-generation/google-spanner-renderer.js +0 -100
- package/dist/code-generation/index.d.ts +0 -2
- package/dist/code-generation/index.js +0 -2
- package/dist/code-generation/utils.d.ts +0 -12
- package/dist/code-generation/utils.js +0 -21
- package/dist/functions/typescript/get-decorator-renderer-google-firestore.d.ts +0 -9
- package/dist/functions/typescript/get-decorator-renderer-google-firestore.js +0 -15
- package/dist/functions/typescript/get-decorator-renderer-google-spanner.d.ts +0 -9
- package/dist/functions/typescript/get-decorator-renderer-google-spanner.js +0 -15
- package/dist/functions/typescript/index.d.ts +0 -2
- package/dist/functions/typescript/index.js +0 -2
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { callDeferred,
|
|
10
|
+
import { callDeferred, WorkspaceFunction } from '@causa/workspace';
|
|
11
11
|
import { AllowMissing } from '@causa/workspace/validation';
|
|
12
12
|
import { IsObject, IsString } from 'class-validator';
|
|
13
13
|
/**
|
|
@@ -26,8 +26,8 @@ export class GoogleIdentityPlatformGenerateCustomToken extends WorkspaceFunction
|
|
|
26
26
|
* A dictionary of custom claims to add to the token.
|
|
27
27
|
*/
|
|
28
28
|
claims;
|
|
29
|
-
async _call(
|
|
30
|
-
return await callDeferred(this,
|
|
29
|
+
async _call() {
|
|
30
|
+
return await callDeferred(this, import.meta.url);
|
|
31
31
|
}
|
|
32
32
|
_supports() {
|
|
33
33
|
return true;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { WorkspaceContext } from '@causa/workspace';
|
|
2
1
|
import type { GoogleIdentityPlatformGenerateToken } from './generate-token.js';
|
|
3
|
-
export default function call(this: GoogleIdentityPlatformGenerateToken
|
|
2
|
+
export default function call(this: GoogleIdentityPlatformGenerateToken): Promise<string>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getAuth, signInWithCustomToken } from 'firebase/auth';
|
|
2
2
|
import { FirebaseAppService } from '../../services/firebase-app.js';
|
|
3
3
|
import { GoogleIdentityPlatformGenerateCustomToken } from './generate-custom-token.js';
|
|
4
|
-
export default async function call(
|
|
5
|
-
|
|
6
|
-
const customToken = await
|
|
7
|
-
const app = await
|
|
4
|
+
export default async function call() {
|
|
5
|
+
this._context.logger.info(`🛂 Signing in user '${this.user}' with a custom token.`);
|
|
6
|
+
const customToken = await this._context.call(GoogleIdentityPlatformGenerateCustomToken, { user: this.user, claims: this.claims });
|
|
7
|
+
const app = await this._context.service(FirebaseAppService).getApp();
|
|
8
8
|
const auth = getAuth(app);
|
|
9
9
|
const credentials = await signInWithCustomToken(auth, customToken);
|
|
10
10
|
return this.refreshToken
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WorkspaceFunction } from '@causa/workspace';
|
|
2
2
|
/**
|
|
3
3
|
* Generates an ID token for an Identity Platform end user.
|
|
4
4
|
* For this function to succeed, the `google.project` should be set, which usually means setting the environment in the
|
|
@@ -17,6 +17,6 @@ export declare class GoogleIdentityPlatformGenerateToken extends WorkspaceFuncti
|
|
|
17
17
|
* Whether to return the refresh token instead of the ID token.
|
|
18
18
|
*/
|
|
19
19
|
readonly refreshToken?: boolean;
|
|
20
|
-
_call(
|
|
20
|
+
_call(): Promise<string>;
|
|
21
21
|
_supports(): boolean;
|
|
22
22
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { CliArgument, CliCommand, CliOption } from '@causa/cli';
|
|
11
|
-
import { callDeferred,
|
|
11
|
+
import { callDeferred, WorkspaceFunction } from '@causa/workspace';
|
|
12
12
|
import { AllowMissing } from '@causa/workspace/validation';
|
|
13
13
|
import { Transform } from 'class-transformer';
|
|
14
14
|
import { IsBoolean, IsObject, IsString } from 'class-validator';
|
|
@@ -31,8 +31,8 @@ let GoogleIdentityPlatformGenerateToken = class GoogleIdentityPlatformGenerateTo
|
|
|
31
31
|
* Whether to return the refresh token instead of the ID token.
|
|
32
32
|
*/
|
|
33
33
|
refreshToken;
|
|
34
|
-
async _call(
|
|
35
|
-
return await callDeferred(this,
|
|
34
|
+
async _call() {
|
|
35
|
+
return await callDeferred(this, import.meta.url);
|
|
36
36
|
}
|
|
37
37
|
_supports() {
|
|
38
38
|
return true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ProcessorResult,
|
|
1
|
+
import { type ProcessorResult, WorkspaceFunction } from '@causa/workspace';
|
|
2
2
|
import { type InfrastructureProcessor } from '@causa/workspace-core';
|
|
3
3
|
/**
|
|
4
4
|
* A function that uses {@link EventTopicList} to find all the topics in the workspace, and writes their configurations
|
|
@@ -13,10 +13,9 @@ export declare class GooglePubSubWriteTopics extends WorkspaceFunction<Promise<P
|
|
|
13
13
|
* Returns the path to the directory where Pub/Sub topic configurations should be written.
|
|
14
14
|
* It is either fetched from the workspace configuration, or the default value is used.
|
|
15
15
|
*
|
|
16
|
-
* @param context The {@link WorkspaceContext}.
|
|
17
16
|
* @returns The path to the directory where topic configurations should be written.
|
|
18
17
|
*/
|
|
19
18
|
private getConfigurationsDirectory;
|
|
20
|
-
_call(
|
|
19
|
+
_call(): Promise<ProcessorResult>;
|
|
21
20
|
_supports(): boolean;
|
|
22
21
|
}
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { WorkspaceFunction } from '@causa/workspace';
|
|
11
11
|
import { EventTopicList, } from '@causa/workspace-core';
|
|
12
12
|
import { CAUSA_FOLDER } from '@causa/workspace/initialization';
|
|
13
13
|
import { AllowMissing } from '@causa/workspace/validation';
|
|
@@ -31,26 +31,25 @@ export class GooglePubSubWriteTopics extends WorkspaceFunction {
|
|
|
31
31
|
* Returns the path to the directory where Pub/Sub topic configurations should be written.
|
|
32
32
|
* It is either fetched from the workspace configuration, or the default value is used.
|
|
33
33
|
*
|
|
34
|
-
* @param context The {@link WorkspaceContext}.
|
|
35
34
|
* @returns The path to the directory where topic configurations should be written.
|
|
36
35
|
*/
|
|
37
|
-
getConfigurationsDirectory(
|
|
38
|
-
return (
|
|
36
|
+
getConfigurationsDirectory() {
|
|
37
|
+
return (this._context
|
|
39
38
|
.asConfiguration()
|
|
40
39
|
.get('google.pubSub.topicConfigurationsDirectory') ??
|
|
41
40
|
DEFAULT_TOPIC_CONFIGURATIONS_DIRECTORY);
|
|
42
41
|
}
|
|
43
|
-
async _call(
|
|
44
|
-
const topicConfigurationsDirectory = this.getConfigurationsDirectory(
|
|
45
|
-
const absoluteDir = join(
|
|
42
|
+
async _call() {
|
|
43
|
+
const topicConfigurationsDirectory = this.getConfigurationsDirectory();
|
|
44
|
+
const absoluteDir = join(this._context.rootPath, topicConfigurationsDirectory);
|
|
46
45
|
await rm(absoluteDir, { recursive: true, force: true });
|
|
47
46
|
if (this.tearDown) {
|
|
48
|
-
|
|
47
|
+
this._context.logger.debug(`📫 Tore down Pub/Sub topic configurations directory '${absoluteDir}'.`);
|
|
49
48
|
return { configuration: {} };
|
|
50
49
|
}
|
|
51
|
-
|
|
52
|
-
const topics = await
|
|
53
|
-
|
|
50
|
+
this._context.logger.info('️📫 Listing and writing Pub/Sub topic configurations.');
|
|
51
|
+
const topics = await this._context.call(EventTopicList, {});
|
|
52
|
+
this._context.logger.debug(`📫 Writing configurations for Pub/Sub topics: ${topics
|
|
54
53
|
.map((d) => `'${d.id}'`)
|
|
55
54
|
.join(', ')}.`);
|
|
56
55
|
await mkdir(absoluteDir, { recursive: true });
|
|
@@ -62,7 +61,7 @@ export class GooglePubSubWriteTopics extends WorkspaceFunction {
|
|
|
62
61
|
const topicFile = join(absoluteDir, `${topic.id}.json`);
|
|
63
62
|
await writeFile(topicFile, JSON.stringify(topicConfiguration));
|
|
64
63
|
}));
|
|
65
|
-
|
|
64
|
+
this._context.logger.debug(`️📫 Wrote Pub/Sub topic configurations in '${absoluteDir}'.`);
|
|
66
65
|
return {
|
|
67
66
|
configuration: {
|
|
68
67
|
google: { pubSub: { topicConfigurationsDirectory } },
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { WorkspaceContext } from '@causa/workspace';
|
|
2
1
|
import type { GoogleConfiguration } from '../../configurations/index.js';
|
|
3
2
|
import type { GoogleServicesEnable } from './enable.js';
|
|
4
|
-
export default function call(this: GoogleServicesEnable
|
|
3
|
+
export default function call(this: GoogleServicesEnable): Promise<{
|
|
5
4
|
configuration: GoogleConfiguration;
|
|
6
5
|
services: string[];
|
|
7
6
|
}>;
|
|
@@ -3,11 +3,11 @@ import { ServiceUsageClient } from '@google-cloud/service-usage';
|
|
|
3
3
|
* The maximum number of GCP services that can be enabled at the same time.
|
|
4
4
|
*/
|
|
5
5
|
const MAX_SERVICE_BATCH = 20;
|
|
6
|
-
export default async function call(
|
|
6
|
+
export default async function call() {
|
|
7
7
|
if (this.tearDown) {
|
|
8
8
|
return { configuration: {}, services: [] };
|
|
9
9
|
}
|
|
10
|
-
const googleConf =
|
|
10
|
+
const googleConf = this._context.asConfiguration();
|
|
11
11
|
const gcpProject = googleConf.getOrThrow('google.project');
|
|
12
12
|
const services = googleConf.get('google.services');
|
|
13
13
|
if (!services) {
|
|
@@ -20,7 +20,7 @@ export default async function call(context) {
|
|
|
20
20
|
const parent = `projects/${gcpProject}`;
|
|
21
21
|
while (servicesToEnable.length > 0) {
|
|
22
22
|
const serviceIds = servicesToEnable.splice(0, MAX_SERVICE_BATCH);
|
|
23
|
-
|
|
23
|
+
this._context.logger.info(`➕ Enabling GCP service(s) ${serviceIds
|
|
24
24
|
.map((s) => `'${s}'`)
|
|
25
25
|
.join(', ')} in project '${gcpProject}'.`);
|
|
26
26
|
const [operation] = await serviceUsageClient.batchEnableServices({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WorkspaceFunction } from '@causa/workspace';
|
|
2
2
|
import type { InfrastructureProcessor } from '@causa/workspace-core';
|
|
3
3
|
import type { GoogleConfiguration } from '../../configurations/index.js';
|
|
4
4
|
/**
|
|
@@ -22,7 +22,7 @@ type GoogleServicesEnableResult = {
|
|
|
22
22
|
*/
|
|
23
23
|
export declare class GoogleServicesEnable extends WorkspaceFunction<Promise<GoogleServicesEnableResult>> implements InfrastructureProcessor {
|
|
24
24
|
readonly tearDown?: boolean;
|
|
25
|
-
_call(
|
|
25
|
+
_call(): Promise<GoogleServicesEnableResult>;
|
|
26
26
|
_supports(): boolean;
|
|
27
27
|
}
|
|
28
28
|
export {};
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { CliCommand } from '@causa/cli';
|
|
11
|
-
import { callDeferred,
|
|
11
|
+
import { callDeferred, WorkspaceFunction } from '@causa/workspace';
|
|
12
12
|
import { AllowMissing } from '@causa/workspace/validation';
|
|
13
13
|
import { IsBoolean } from 'class-validator';
|
|
14
14
|
import { googleCommandDefinition } from '../../cli/index.js';
|
|
@@ -17,8 +17,8 @@ import { googleCommandDefinition } from '../../cli/index.js';
|
|
|
17
17
|
*/
|
|
18
18
|
let GoogleServicesEnable = class GoogleServicesEnable extends WorkspaceFunction {
|
|
19
19
|
tearDown;
|
|
20
|
-
async _call(
|
|
21
|
-
return await callDeferred(this,
|
|
20
|
+
async _call() {
|
|
21
|
+
return await callDeferred(this, import.meta.url);
|
|
22
22
|
}
|
|
23
23
|
_supports() {
|
|
24
24
|
return true;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModelSchemaExtractDatabase, type SchemaDatabase } from '@causa/workspace-core';
|
|
2
|
+
/**
|
|
3
|
+
* Implements {@link ModelSchemaExtractDatabase} for Google Spanner.
|
|
4
|
+
* The schema is selected when it carries a `googleSpannerTable` Causa extension with a `primaryKey` array. The table
|
|
5
|
+
* name defaults to the schema's name when not explicitly set, and the primary keys are read from the extension's
|
|
6
|
+
* `primaryKey` array.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ModelSchemaExtractDatabaseForGoogleSpanner extends ModelSchemaExtractDatabase {
|
|
9
|
+
_call(): SchemaDatabase;
|
|
10
|
+
_supports(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ModelSchemaExtractDatabase, } from '@causa/workspace-core';
|
|
2
|
+
/**
|
|
3
|
+
* The name of the Causa extension marking an object schema as a Google Spanner table.
|
|
4
|
+
*/
|
|
5
|
+
const GOOGLE_SPANNER_TABLE_EXTENSION = 'googleSpannerTable';
|
|
6
|
+
/**
|
|
7
|
+
* Implements {@link ModelSchemaExtractDatabase} for Google Spanner.
|
|
8
|
+
* The schema is selected when it carries a `googleSpannerTable` Causa extension with a `primaryKey` array. The table
|
|
9
|
+
* name defaults to the schema's name when not explicitly set, and the primary keys are read from the extension's
|
|
10
|
+
* `primaryKey` array.
|
|
11
|
+
*/
|
|
12
|
+
export class ModelSchemaExtractDatabaseForGoogleSpanner extends ModelSchemaExtractDatabase {
|
|
13
|
+
_call() {
|
|
14
|
+
const extension = this.schema.extensions[GOOGLE_SPANNER_TABLE_EXTENSION];
|
|
15
|
+
const primaryKeys = extension.primaryKey.filter((k) => typeof k === 'string');
|
|
16
|
+
const table = typeof extension.name === 'string' ? extension.name : this.schema.name;
|
|
17
|
+
return { engine: 'google.spanner', table, primaryKeys };
|
|
18
|
+
}
|
|
19
|
+
_supports() {
|
|
20
|
+
const extension = this.schema.extensions[GOOGLE_SPANNER_TABLE_EXTENSION];
|
|
21
|
+
return (typeof extension === 'object' &&
|
|
22
|
+
extension !== null &&
|
|
23
|
+
Array.isArray(extension.primaryKey));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModelGenerateTypeScriptDecorators } from '@causa/workspace-typescript';
|
|
2
|
+
import { type TypeScriptDecorator } from '@causa/workspace-typescript/code-generation';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link ModelGenerateTypeScriptDecorators} to add Google Spanner decorators from the Causa Google runtime.
|
|
5
|
+
*
|
|
6
|
+
* If an object schema is marked with the `googleSpannerTable` extension, the `@SpannerTable` decorator is added to the
|
|
7
|
+
* class, and `@SpannerColumn` decorators are added to all its properties.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ModelGenerateTypeScriptDecoratorsForGoogleSpanner extends ModelGenerateTypeScriptDecorators {
|
|
10
|
+
_call(): TypeScriptDecorator[];
|
|
11
|
+
_supports(): boolean;
|
|
12
|
+
private decoratorsForClass;
|
|
13
|
+
private decoratorsForProperty;
|
|
14
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ModelGenerateTypeScriptDecorators } from '@causa/workspace-typescript';
|
|
2
|
+
import { addDecoratorToList, } from '@causa/workspace-typescript/code-generation';
|
|
3
|
+
import micromatch from 'micromatch';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
/**
|
|
6
|
+
* The name of the Causa extension marking an object schema as a Google Spanner table.
|
|
7
|
+
*/
|
|
8
|
+
const GOOGLE_SPANNER_TABLE_EXTENSION = 'googleSpannerTable';
|
|
9
|
+
/**
|
|
10
|
+
* The name of the optional Causa extension that can be present on an object property schema to specify options for the
|
|
11
|
+
* `@SpannerColumn` decorator.
|
|
12
|
+
*/
|
|
13
|
+
const GOOGLE_SPANNER_COLUMN_EXTENSION = 'googleSpannerColumn';
|
|
14
|
+
/**
|
|
15
|
+
* The name of the Causa module for the TypeScript Google runtime.
|
|
16
|
+
*/
|
|
17
|
+
const CAUSA_GOOGLE_MODULE = '@causa/runtime-google';
|
|
18
|
+
/**
|
|
19
|
+
* The list of options that can be passed to the `@SpannerColumn` decorator and that indicates that the schema specifies
|
|
20
|
+
* the type of the column. In this case, the renderer should not infer any type information.
|
|
21
|
+
*/
|
|
22
|
+
const TYPE_INFO_COLUMN_ATTRIBUTE_NAMES = [
|
|
23
|
+
'isBigInt',
|
|
24
|
+
'isInt',
|
|
25
|
+
'isPreciseDate',
|
|
26
|
+
'isJson',
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Implements {@link ModelGenerateTypeScriptDecorators} to add Google Spanner decorators from the Causa Google runtime.
|
|
30
|
+
*
|
|
31
|
+
* If an object schema is marked with the `googleSpannerTable` extension, the `@SpannerTable` decorator is added to the
|
|
32
|
+
* class, and `@SpannerColumn` decorators are added to all its properties.
|
|
33
|
+
*/
|
|
34
|
+
export class ModelGenerateTypeScriptDecoratorsForGoogleSpanner extends ModelGenerateTypeScriptDecorators {
|
|
35
|
+
_call() {
|
|
36
|
+
const tableAttribute = this.schema.extensions[GOOGLE_SPANNER_TABLE_EXTENSION];
|
|
37
|
+
if (!tableAttribute) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const globs = this.configuration?.google?.spanner?.globs;
|
|
41
|
+
if (Array.isArray(globs)) {
|
|
42
|
+
const projectPath = this._context.getProjectPathOrThrow();
|
|
43
|
+
const absoluteGlobs = globs.map((g) => join(projectPath, g));
|
|
44
|
+
const schemaPath = this.schema.path.split('#')[0];
|
|
45
|
+
if (!micromatch.isMatch(schemaPath, absoluteGlobs)) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return this.property
|
|
50
|
+
? this.decoratorsForProperty()
|
|
51
|
+
: this.decoratorsForClass(tableAttribute);
|
|
52
|
+
}
|
|
53
|
+
_supports() {
|
|
54
|
+
return (this._context.get('project.language') === 'typescript' &&
|
|
55
|
+
this.generator === 'typescriptModelClass');
|
|
56
|
+
}
|
|
57
|
+
decoratorsForClass(tableAttribute) {
|
|
58
|
+
const debugName = this.schema.name;
|
|
59
|
+
if (typeof tableAttribute !== 'object' ||
|
|
60
|
+
tableAttribute === null ||
|
|
61
|
+
!('primaryKey' in tableAttribute) ||
|
|
62
|
+
!Array.isArray(tableAttribute.primaryKey) ||
|
|
63
|
+
tableAttribute.primaryKey.length === 0 ||
|
|
64
|
+
tableAttribute.primaryKey.some((k) => typeof k !== 'string')) {
|
|
65
|
+
throw new Error(`Invalid '${GOOGLE_SPANNER_TABLE_EXTENSION}' attribute on '${debugName}'. Expected an object with a 'primaryKey' array.`);
|
|
66
|
+
}
|
|
67
|
+
const { primaryKey, name } = tableAttribute;
|
|
68
|
+
if (name !== undefined && typeof name !== 'string') {
|
|
69
|
+
throw new Error(`Invalid 'name' in '${GOOGLE_SPANNER_TABLE_EXTENSION}' attribute on '${debugName}'. Expected a string.`);
|
|
70
|
+
}
|
|
71
|
+
const decorators = [];
|
|
72
|
+
addDecoratorToList(decorators, { schema: this.schema }, 'SpannerTable', CAUSA_GOOGLE_MODULE, `@SpannerTable(${JSON.stringify({ primaryKey, name })})`);
|
|
73
|
+
return decorators;
|
|
74
|
+
}
|
|
75
|
+
decoratorsForProperty() {
|
|
76
|
+
const property = this.property;
|
|
77
|
+
const rawAttributes = property.extensions[GOOGLE_SPANNER_COLUMN_EXTENSION] ?? {};
|
|
78
|
+
if (typeof rawAttributes !== 'object' || rawAttributes === null) {
|
|
79
|
+
throw new Error(`Invalid '${GOOGLE_SPANNER_COLUMN_EXTENSION}' attribute on '${this.schema.name}.${property.name}'. Expected an object.`);
|
|
80
|
+
}
|
|
81
|
+
const { name: overriddenName, tsOptions } = rawAttributes;
|
|
82
|
+
if (tsOptions !== undefined &&
|
|
83
|
+
(typeof tsOptions !== 'object' || tsOptions === null)) {
|
|
84
|
+
throw new Error(`Invalid 'tsOptions' in '${GOOGLE_SPANNER_COLUMN_EXTENSION}' attribute. Expected an object.`);
|
|
85
|
+
}
|
|
86
|
+
const columnAttributes = {
|
|
87
|
+
...(tsOptions ?? {}),
|
|
88
|
+
};
|
|
89
|
+
if (overriddenName !== undefined) {
|
|
90
|
+
if (typeof overriddenName !== 'string') {
|
|
91
|
+
throw new Error(`Invalid 'name' in '${GOOGLE_SPANNER_COLUMN_EXTENSION}' attribute. Expected a string.`);
|
|
92
|
+
}
|
|
93
|
+
columnAttributes.name = overriddenName;
|
|
94
|
+
}
|
|
95
|
+
const softDeletionColumn = this.configuration?.google?.spanner
|
|
96
|
+
?.softDeletionColumn;
|
|
97
|
+
const columnName = typeof overriddenName === 'string' ? overriddenName : property.name;
|
|
98
|
+
if (columnName === softDeletionColumn) {
|
|
99
|
+
columnAttributes.softDelete = true;
|
|
100
|
+
}
|
|
101
|
+
const schemaOverridesTypeInfo = TYPE_INFO_COLUMN_ATTRIBUTE_NAMES.some((n) => n in columnAttributes);
|
|
102
|
+
if (!schemaOverridesTypeInfo) {
|
|
103
|
+
const type = property.type.kind === 'array' ? property.type.items : property.type;
|
|
104
|
+
const resolved = type.kind === 'ref' ? this.schemas[type.ref] : undefined;
|
|
105
|
+
if (type.kind === 'primitive' && type.type === 'integer') {
|
|
106
|
+
columnAttributes.isInt = true;
|
|
107
|
+
}
|
|
108
|
+
else if (type.kind === 'map' || resolved?.kind === 'object') {
|
|
109
|
+
columnAttributes.isJson = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const hasOptions = Object.keys(columnAttributes).length > 0;
|
|
113
|
+
const source = hasOptions
|
|
114
|
+
? `@SpannerColumn(${JSON.stringify(columnAttributes)})`
|
|
115
|
+
: '@SpannerColumn()';
|
|
116
|
+
const decorators = [];
|
|
117
|
+
addDecoratorToList(decorators, { schema: this.schema, property }, 'SpannerColumn', CAUSA_GOOGLE_MODULE, source);
|
|
118
|
+
return decorators;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { ModelSchemaExtractDatabaseForGoogleSpanner } from './extract-database.js';
|
|
2
|
+
export { ModelGenerateTypeScriptDecoratorsForGoogleSpanner } from './generate-typescript-decorators.js';
|
|
1
3
|
export { GoogleSpannerListDatabases } from './list-databases.js';
|
|
2
4
|
export { DatabaseQueryRecordsForSpanner } from './query-records.js';
|
|
3
5
|
export { GoogleSpannerWriteDatabases } from './write-databases.js';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { ModelSchemaExtractDatabaseForGoogleSpanner } from './extract-database.js';
|
|
2
|
+
export { ModelGenerateTypeScriptDecoratorsForGoogleSpanner } from './generate-typescript-decorators.js';
|
|
1
3
|
export { GoogleSpannerListDatabases } from './list-databases.js';
|
|
2
4
|
export { DatabaseQueryRecordsForSpanner } from './query-records.js';
|
|
3
5
|
export { GoogleSpannerWriteDatabases } from './write-databases.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WorkspaceFunction } from '@causa/workspace';
|
|
2
2
|
/**
|
|
3
3
|
* The definition of a Spanner database with its DDL statements.
|
|
4
4
|
*/
|
|
@@ -20,7 +20,7 @@ export type SpannerDatabase = {
|
|
|
20
20
|
* A function that lists Spanner databases defined in the workspace, and returns their corresponding DDLs.
|
|
21
21
|
*/
|
|
22
22
|
export declare class GoogleSpannerListDatabases extends WorkspaceFunction<Promise<SpannerDatabase[]>> {
|
|
23
|
-
_call(
|
|
23
|
+
_call(): Promise<SpannerDatabase[]>;
|
|
24
24
|
/**
|
|
25
25
|
* Parses a SQL file containing Spanner DDL statements.
|
|
26
26
|
* End-of-the-line comments are removed, and statements are split using semicolons.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WorkspaceFunction, listFilesAndFormat } from '@causa/workspace';
|
|
2
2
|
import { readFile } from 'fs/promises';
|
|
3
3
|
/**
|
|
4
4
|
* The default format used to infer the ID / name of the database from the format parts.
|
|
@@ -16,16 +16,16 @@ const DEFAULT_DDL_REGULAR_EXPRESSION = 'domains/(?<database>[\\w-]+)\\/spanner\\
|
|
|
16
16
|
* A function that lists Spanner databases defined in the workspace, and returns their corresponding DDLs.
|
|
17
17
|
*/
|
|
18
18
|
export class GoogleSpannerListDatabases extends WorkspaceFunction {
|
|
19
|
-
async _call(
|
|
20
|
-
const googleConf =
|
|
19
|
+
async _call() {
|
|
20
|
+
const googleConf = this._context.asConfiguration();
|
|
21
21
|
const format = googleConf.get('google.spanner.ddls.format') ??
|
|
22
22
|
DEFAULT_DDL_DATABASE_ID_FORMAT;
|
|
23
23
|
const globs = googleConf.get('google.spanner.ddls.globs') ?? DEFAULT_DDL_GLOBS;
|
|
24
24
|
const regExp = googleConf.get('google.spanner.ddls.regularExpression') ??
|
|
25
25
|
DEFAULT_DDL_REGULAR_EXPRESSION;
|
|
26
|
-
|
|
27
|
-
const filesAndFormats = await listFilesAndFormat(globs, regExp, format,
|
|
28
|
-
nonMatchingPathHandler: (path) =>
|
|
26
|
+
this._context.logger.debug('🗃️ Listing Spanner databases and DDL files.');
|
|
27
|
+
const filesAndFormats = await listFilesAndFormat(globs, regExp, format, this._context.rootPath, {
|
|
28
|
+
nonMatchingPathHandler: (path) => this._context.logger.warn(`📂 Path '${path}' matches the Spanner DDL globs but did not match the regular expression. It will be ignored.`),
|
|
29
29
|
});
|
|
30
30
|
const databaseDdlFiles = filesAndFormats.reduce((files, { rendered, filePath }) => {
|
|
31
31
|
(files[rendered] ?? (files[rendered] = [])).push(filePath);
|
|
@@ -35,7 +35,7 @@ export class GoogleSpannerListDatabases extends WorkspaceFunction {
|
|
|
35
35
|
ddlFiles.sort();
|
|
36
36
|
const ddlsInFiles = await Promise.all(ddlFiles.map((ddlFile) => this.parseDdlFile(ddlFile)));
|
|
37
37
|
const ddls = ddlsInFiles.flatMap((ddls) => ddls);
|
|
38
|
-
|
|
38
|
+
this._context.logger.debug(`🗃️ Found Spanner database '${id}' with ${ddlFiles.length} DDL file(s) and ${ddls.length} statement(s).`);
|
|
39
39
|
return { id, ddlFiles, ddls };
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { WorkspaceContext } from '@causa/workspace';
|
|
2
1
|
import { type DatabaseQueryRecordsForSpanner } from './query-records.js';
|
|
3
|
-
export default function call(this: DatabaseQueryRecordsForSpanner
|
|
2
|
+
export default function call(this: DatabaseQueryRecordsForSpanner): Promise<any[]>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Numeric, PGNumeric, Spanner, SpannerDate, } from '@google-cloud/spanner';
|
|
2
2
|
import { SPANNER_QUERY_RECORDS_LIMIT, } from './query-records.js';
|
|
3
|
-
export default async function call(
|
|
3
|
+
export default async function call() {
|
|
4
4
|
if (!this.database) {
|
|
5
5
|
throw new Error(`The 'database' input is required for the 'google.spanner' engine.`);
|
|
6
6
|
}
|
|
7
7
|
if (!this.query) {
|
|
8
8
|
throw new Error(`The 'query' input is required for the 'google.spanner' engine.`);
|
|
9
9
|
}
|
|
10
|
-
const googleConf =
|
|
10
|
+
const googleConf = this._context.asConfiguration();
|
|
11
11
|
const projectId = googleConf.getOrThrow('google.project');
|
|
12
12
|
const instanceName = googleConf.getOrThrow('google.spanner.instance.name');
|
|
13
|
-
|
|
13
|
+
this._context.logger.debug(`🗃️ Querying Spanner database '${this.database}' in instance '${instanceName}' (project '${projectId}').`);
|
|
14
14
|
const spanner = new Spanner({ projectId });
|
|
15
15
|
let database;
|
|
16
16
|
try {
|
|
@@ -23,7 +23,7 @@ export default async function call(context) {
|
|
|
23
23
|
});
|
|
24
24
|
for await (const row of stream) {
|
|
25
25
|
if (rows.length >= SPANNER_QUERY_RECORDS_LIMIT) {
|
|
26
|
-
|
|
26
|
+
this._context.logger.warn(`⚠️ Spanner query exceeded the hard limit of ${SPANNER_QUERY_RECORDS_LIMIT} rows. Results were truncated.`);
|
|
27
27
|
break;
|
|
28
28
|
}
|
|
29
29
|
rows.push(toJson(row));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WorkspaceContext } from '@causa/workspace';
|
|
2
1
|
import { DatabaseQueryRecords } from '@causa/workspace-core';
|
|
3
2
|
/**
|
|
4
3
|
* The engine identifier handled by this implementation.
|
|
@@ -18,6 +17,6 @@ export declare const SPANNER_QUERY_RECORDS_LIMIT = 100000;
|
|
|
18
17
|
* Results are streamed and capped to {@link SPANNER_QUERY_RECORDS_LIMIT} rows.
|
|
19
18
|
*/
|
|
20
19
|
export declare class DatabaseQueryRecordsForSpanner extends DatabaseQueryRecords {
|
|
21
|
-
_call(
|
|
20
|
+
_call(): Promise<any[]>;
|
|
22
21
|
_supports(): boolean;
|
|
23
22
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { callDeferred
|
|
1
|
+
import { callDeferred } from '@causa/workspace';
|
|
2
2
|
import { DatabaseQueryRecords } from '@causa/workspace-core';
|
|
3
3
|
/**
|
|
4
4
|
* The engine identifier handled by this implementation.
|
|
@@ -18,8 +18,8 @@ export const SPANNER_QUERY_RECORDS_LIMIT = 100_000;
|
|
|
18
18
|
* Results are streamed and capped to {@link SPANNER_QUERY_RECORDS_LIMIT} rows.
|
|
19
19
|
*/
|
|
20
20
|
export class DatabaseQueryRecordsForSpanner extends DatabaseQueryRecords {
|
|
21
|
-
async _call(
|
|
22
|
-
return await callDeferred(this,
|
|
21
|
+
async _call() {
|
|
22
|
+
return await callDeferred(this, import.meta.url);
|
|
23
23
|
}
|
|
24
24
|
_supports() {
|
|
25
25
|
return this.engine === SPANNER_ENGINE;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ProcessorResult,
|
|
1
|
+
import { type ProcessorResult, WorkspaceFunction } from '@causa/workspace';
|
|
2
2
|
import type { InfrastructureProcessor } from '@causa/workspace-core';
|
|
3
3
|
/**
|
|
4
4
|
* A function that uses {@link GoogleSpannerListDatabases} to find all the Spanner databases in the workspace, and
|
|
@@ -13,10 +13,9 @@ export declare class GoogleSpannerWriteDatabases extends WorkspaceFunction<Promi
|
|
|
13
13
|
* Returns the path to the directory where Spanner databases configurations should be written.
|
|
14
14
|
* It is either fetched from the workspace configuration, or the default value is used.
|
|
15
15
|
*
|
|
16
|
-
* @param context The {@link WorkspaceContext}.
|
|
17
16
|
* @returns The path to the directory where database configurations should be written.
|
|
18
17
|
*/
|
|
19
18
|
private getConfigurationsDirectory;
|
|
20
|
-
_call(
|
|
19
|
+
_call(): Promise<ProcessorResult>;
|
|
21
20
|
_supports(): boolean;
|
|
22
21
|
}
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { WorkspaceFunction } from '@causa/workspace';
|
|
11
11
|
import { CAUSA_FOLDER } from '@causa/workspace/initialization';
|
|
12
12
|
import { AllowMissing } from '@causa/workspace/validation';
|
|
13
13
|
import { IsBoolean } from 'class-validator';
|
|
@@ -31,31 +31,30 @@ export class GoogleSpannerWriteDatabases extends WorkspaceFunction {
|
|
|
31
31
|
* Returns the path to the directory where Spanner databases configurations should be written.
|
|
32
32
|
* It is either fetched from the workspace configuration, or the default value is used.
|
|
33
33
|
*
|
|
34
|
-
* @param context The {@link WorkspaceContext}.
|
|
35
34
|
* @returns The path to the directory where database configurations should be written.
|
|
36
35
|
*/
|
|
37
|
-
getConfigurationsDirectory(
|
|
38
|
-
return (
|
|
36
|
+
getConfigurationsDirectory() {
|
|
37
|
+
return (this._context
|
|
39
38
|
.asConfiguration()
|
|
40
39
|
.get('google.spanner.databaseConfigurationsDirectory') ??
|
|
41
40
|
DEFAULT_DATABASE_CONFIGURATIONS_DIRECTORY);
|
|
42
41
|
}
|
|
43
|
-
async _call(
|
|
44
|
-
const databaseConfigurationsDirectory = this.getConfigurationsDirectory(
|
|
45
|
-
const absoluteDir = join(
|
|
42
|
+
async _call() {
|
|
43
|
+
const databaseConfigurationsDirectory = this.getConfigurationsDirectory();
|
|
44
|
+
const absoluteDir = join(this._context.rootPath, databaseConfigurationsDirectory);
|
|
46
45
|
await rm(absoluteDir, { recursive: true, force: true });
|
|
47
46
|
if (this.tearDown) {
|
|
48
|
-
|
|
47
|
+
this._context.logger.debug(`️🗃️ Tore down Spanner database configurations directory '${absoluteDir}'.`);
|
|
49
48
|
return { configuration: {} };
|
|
50
49
|
}
|
|
51
|
-
|
|
52
|
-
const databases = await
|
|
50
|
+
this._context.logger.info('🗃️ Listing and writing Spanner database configurations.');
|
|
51
|
+
const databases = await this._context.call(GoogleSpannerListDatabases, {});
|
|
53
52
|
await mkdir(absoluteDir, { recursive: true });
|
|
54
|
-
|
|
53
|
+
this._context.logger.debug(`🗃️ Writing configurations for Spanner databases: ${databases
|
|
55
54
|
.map((d) => `'${d.id}'`)
|
|
56
55
|
.join(', ')}.`);
|
|
57
56
|
await Promise.all(databases.map((database) => writeFile(join(absoluteDir, `${database.id}.json`), JSON.stringify(database))));
|
|
58
|
-
|
|
57
|
+
this._context.logger.debug(`🗃️ Wrote Spanner database configurations in '${absoluteDir}'.`);
|
|
59
58
|
return {
|
|
60
59
|
configuration: {
|
|
61
60
|
google: { spanner: { databaseConfigurationsDirectory } },
|
package/dist/functions/index.js
CHANGED
|
@@ -3,15 +3,14 @@ import { EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorSta
|
|
|
3
3
|
import { EventTopicBrokerCreateTopicForPubSub, EventTopicBrokerCreateTriggerForCloudRun, EventTopicBrokerDeleteTopicForPubSub, EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole, EventTopicBrokerDeleteTriggerResourceForPubSubSubscription, EventTopicBrokerDeleteTriggerResourceForServiceAccount, EventTopicBrokerGetTopicIdForPubSub, EventTopicBrokerPublishEventsForGoogle, EventTopicCreateBackfillSourceForBigQuery, EventTopicQueryEventsForBigQuery, } from './event-topic/index.js';
|
|
4
4
|
import { GoogleAppCheckGenerateToken } from './google-app-check/index.js';
|
|
5
5
|
import { GoogleFirebaseStorageMergeRules } from './google-firebase-storage/index.js';
|
|
6
|
-
import { DatabaseQueryRecordsForFirestore, GoogleFirestoreMergeRules, } from './google-firestore/index.js';
|
|
6
|
+
import { DatabaseQueryRecordsForFirestore, GoogleFirestoreMergeRules, ModelGenerateTypeScriptDecoratorsForGoogleFirestore, ModelSchemaExtractDatabaseForGoogleFirestore, } from './google-firestore/index.js';
|
|
7
7
|
import { GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, } from './google-identity-platform/index.js';
|
|
8
8
|
import { GooglePubSubWriteTopics } from './google-pubsub/index.js';
|
|
9
9
|
import { GoogleServicesEnable } from './google-services/index.js';
|
|
10
|
-
import { DatabaseQueryRecordsForSpanner, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, } from './google-spanner/index.js';
|
|
10
|
+
import { DatabaseQueryRecordsForSpanner, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, ModelGenerateTypeScriptDecoratorsForGoogleSpanner, ModelSchemaExtractDatabaseForGoogleSpanner, } from './google-spanner/index.js';
|
|
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 { TypeScriptGetDecoratorRendererForGoogleFirestore, TypeScriptGetDecoratorRendererForGoogleSpanner, } from './typescript/index.js';
|
|
15
14
|
export function registerFunctions(context) {
|
|
16
|
-
context.registerFunctionImplementations(CausaListConfigurationSchemasForGoogle, DatabaseQueryRecordsForFirestore, DatabaseQueryRecordsForSpanner, EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, EventTopicBrokerCreateTopicForPubSub, EventTopicBrokerCreateTriggerForCloudRun, EventTopicBrokerDeleteTopicForPubSub, EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole, EventTopicBrokerDeleteTriggerResourceForPubSubSubscription, EventTopicBrokerDeleteTriggerResourceForServiceAccount, EventTopicBrokerGetTopicIdForPubSub, EventTopicBrokerPublishEventsForGoogle, EventTopicCreateBackfillSourceForBigQuery, EventTopicQueryEventsForBigQuery, GoogleAppCheckGenerateToken, GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, GooglePubSubWriteTopics, GoogleServicesEnable, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, SecretFetchForGoogleAccessToken, SecretFetchForGoogleSecretManager, ServiceContainerQueryLogsForCloudRun
|
|
15
|
+
context.registerFunctionImplementations(CausaListConfigurationSchemasForGoogle, DatabaseQueryRecordsForFirestore, DatabaseQueryRecordsForSpanner, EmulatorStartForFirebaseStorage, EmulatorStartForFirestore, EmulatorStartForIdentityPlatform, EmulatorStartForPubSub, EmulatorStartForSpanner, EmulatorStopForFirebaseStorage, EmulatorStopForFirestore, EmulatorStopForIdentityPlatform, EmulatorStopForPubSub, EmulatorStopForSpanner, EventTopicBrokerCreateTopicForPubSub, EventTopicBrokerCreateTriggerForCloudRun, EventTopicBrokerDeleteTopicForPubSub, EventTopicBrokerDeleteTriggerResourceForCloudRunInvokerRole, EventTopicBrokerDeleteTriggerResourceForPubSubSubscription, EventTopicBrokerDeleteTriggerResourceForServiceAccount, EventTopicBrokerGetTopicIdForPubSub, EventTopicBrokerPublishEventsForGoogle, EventTopicCreateBackfillSourceForBigQuery, EventTopicQueryEventsForBigQuery, GoogleAppCheckGenerateToken, GoogleFirebaseStorageMergeRules, GoogleFirestoreMergeRules, GoogleIdentityPlatformGenerateCustomToken, GoogleIdentityPlatformGenerateToken, GooglePubSubWriteTopics, GoogleServicesEnable, GoogleSpannerListDatabases, GoogleSpannerWriteDatabases, ModelGenerateTypeScriptDecoratorsForGoogleFirestore, ModelGenerateTypeScriptDecoratorsForGoogleSpanner, ModelSchemaExtractDatabaseForGoogleFirestore, ModelSchemaExtractDatabaseForGoogleSpanner, ProjectGetArtefactDestinationForCloudFunctions, ProjectGetArtefactDestinationForCloudRun, ProjectPushArtefactForCloudFunctions, SecretFetchForGoogleAccessToken, SecretFetchForGoogleSecretManager, ServiceContainerQueryLogsForCloudRun);
|
|
17
16
|
}
|