@causa/workspace-google 1.3.1 → 1.4.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.
Files changed (98) hide show
  1. package/README.md +23 -0
  2. package/dist/functions/event-topic/create-backfill-source-bigquery.call.js +2 -2
  3. package/dist/functions/event-topic/query-events-bigquery.call.js +2 -2
  4. package/dist/functions/google-app-check/generate-token.js +3 -1
  5. package/dist/functions/google-firebase-storage/merge-rules.js +3 -1
  6. package/dist/functions/google-firestore/generate-typescript-decorators.js +2 -1
  7. package/dist/functions/google-firestore/merge-rules.js +3 -1
  8. package/dist/functions/google-identity-platform/generate-custom-token.js +7 -2
  9. package/dist/functions/google-pubsub/index.d.ts +1 -1
  10. package/dist/functions/google-pubsub/index.js +1 -1
  11. package/dist/functions/google-pubsub/write-topics.d.ts +7 -0
  12. package/dist/functions/google-pubsub/write-topics.js +17 -3
  13. package/dist/functions/google-services/enable.js +3 -1
  14. package/dist/functions/google-spanner/generate-typescript-decorators.js +2 -1
  15. package/dist/functions/google-spanner/list-databases.d.ts +1 -1
  16. package/dist/functions/google-spanner/write-databases.js +7 -2
  17. package/dist/functions/graph/fetch-environment-metric-series.call.d.ts +3 -0
  18. package/dist/functions/graph/fetch-environment-metric-series.call.js +107 -0
  19. package/dist/functions/graph/fetch-environment-metric-series.d.ts +23 -0
  20. package/dist/functions/graph/fetch-environment-metric-series.js +40 -0
  21. package/dist/functions/graph/get-environment-provider.d.ts +11 -0
  22. package/dist/functions/graph/get-environment-provider.js +20 -0
  23. package/dist/functions/graph/index.d.ts +3 -0
  24. package/dist/functions/graph/index.js +3 -0
  25. package/dist/functions/graph/list-rules.d.ts +11 -0
  26. package/dist/functions/graph/list-rules.js +16 -0
  27. package/dist/functions/index.js +2 -1
  28. package/dist/graph/cloud-run.d.ts +98 -0
  29. package/dist/graph/cloud-run.js +102 -0
  30. package/dist/graph/environment/fetchers/cloud-monitoring-alerts.d.ts +6 -0
  31. package/dist/graph/environment/fetchers/cloud-monitoring-alerts.js +106 -0
  32. package/dist/graph/environment/fetchers/cloud-monitoring.d.ts +5 -0
  33. package/dist/graph/environment/fetchers/cloud-monitoring.js +13 -0
  34. package/dist/graph/environment/fetchers/cloud-run.d.ts +5 -0
  35. package/dist/graph/environment/fetchers/cloud-run.js +88 -0
  36. package/dist/graph/environment/fetchers/cloud-scheduler.d.ts +5 -0
  37. package/dist/graph/environment/fetchers/cloud-scheduler.js +95 -0
  38. package/dist/graph/environment/fetchers/console-links.d.ts +14 -0
  39. package/dist/graph/environment/fetchers/console-links.js +132 -0
  40. package/dist/graph/environment/fetchers/error-reporting.d.ts +5 -0
  41. package/dist/graph/environment/fetchers/error-reporting.js +98 -0
  42. package/dist/graph/environment/fetchers/index.d.ts +5 -0
  43. package/dist/graph/environment/fetchers/index.js +17 -0
  44. package/dist/graph/environment/index.d.ts +9 -0
  45. package/dist/graph/environment/index.js +9 -0
  46. package/dist/graph/environment/load-balancer-backends.d.ts +82 -0
  47. package/dist/graph/environment/load-balancer-backends.js +126 -0
  48. package/dist/graph/environment/monitoring-alerts.d.ts +60 -0
  49. package/dist/graph/environment/monitoring-alerts.js +67 -0
  50. package/dist/graph/environment/monitoring-catalog.d.ts +95 -0
  51. package/dist/graph/environment/monitoring-catalog.js +356 -0
  52. package/dist/graph/environment/monitoring-mappings.d.ts +133 -0
  53. package/dist/graph/environment/monitoring-mappings.js +97 -0
  54. package/dist/graph/environment/monitoring-query.d.ts +116 -0
  55. package/dist/graph/environment/monitoring-query.js +314 -0
  56. package/dist/graph/environment/monitoring-values.d.ts +41 -0
  57. package/dist/graph/environment/monitoring-values.js +119 -0
  58. package/dist/graph/environment/resource-resolvers.d.ts +7 -0
  59. package/dist/graph/environment/resource-resolvers.js +57 -0
  60. package/dist/graph/environment/resources.d.ts +45 -0
  61. package/dist/graph/environment/resources.js +49 -0
  62. package/dist/graph/ids.d.ts +35 -0
  63. package/dist/graph/ids.js +44 -0
  64. package/dist/graph/index.d.ts +7 -0
  65. package/dist/graph/index.js +7 -0
  66. package/dist/graph/rules/configuration/enqueues-assumed-from-google-task-trigger.d.ts +6 -0
  67. package/dist/graph/rules/configuration/enqueues-assumed-from-google-task-trigger.js +39 -0
  68. package/dist/graph/rules/configuration/firestore.d.ts +11 -0
  69. package/dist/graph/rules/configuration/firestore.js +93 -0
  70. package/dist/graph/rules/configuration/index.d.ts +5 -0
  71. package/dist/graph/rules/configuration/index.js +11 -0
  72. package/dist/graph/rules/configuration/service-container.d.ts +13 -0
  73. package/dist/graph/rules/configuration/service-container.js +123 -0
  74. package/dist/graph/rules/terraform/api-router.d.ts +15 -0
  75. package/dist/graph/rules/terraform/api-router.js +117 -0
  76. package/dist/graph/rules/terraform/cloud-run-cron-triggers.d.ts +11 -0
  77. package/dist/graph/rules/terraform/cloud-run-cron-triggers.js +67 -0
  78. package/dist/graph/rules/terraform/cloud-run-grants.d.ts +16 -0
  79. package/dist/graph/rules/terraform/cloud-run-grants.js +118 -0
  80. package/dist/graph/rules/terraform/cloud-run-module.d.ts +6 -0
  81. package/dist/graph/rules/terraform/cloud-run-module.js +29 -0
  82. package/dist/graph/rules/terraform/cloud-run-pubsub-triggers.d.ts +14 -0
  83. package/dist/graph/rules/terraform/cloud-run-pubsub-triggers.js +103 -0
  84. package/dist/graph/rules/terraform/cloud-run-services.d.ts +12 -0
  85. package/dist/graph/rules/terraform/cloud-run-services.js +61 -0
  86. package/dist/graph/rules/terraform/cloud-run-tasks-triggers.d.ts +14 -0
  87. package/dist/graph/rules/terraform/cloud-run-tasks-triggers.js +97 -0
  88. package/dist/graph/rules/terraform/event-topics.d.ts +18 -0
  89. package/dist/graph/rules/terraform/event-topics.js +193 -0
  90. package/dist/graph/rules/terraform/index.d.ts +5 -0
  91. package/dist/graph/rules/terraform/index.js +13 -0
  92. package/dist/graph/rules/terraform/spanner-databases.d.ts +17 -0
  93. package/dist/graph/rules/terraform/spanner-databases.js +180 -0
  94. package/dist/graph/spanner.d.ts +106 -0
  95. package/dist/graph/spanner.js +118 -0
  96. package/dist/graph/terraform-modules.d.ts +87 -0
  97. package/dist/graph/terraform-modules.js +107 -0
  98. package/package.json +30 -29
@@ -0,0 +1,87 @@
1
+ import type { WorkspaceContext } from '@causa/workspace';
2
+ import { type GraphContext, type GraphResource, type GraphTemplatePart, type GraphWarning, type WorkspaceProject } from '@causa/workspace-core/graph';
3
+ import { type TerraformArgument, type TerraformBlock, type TerraformModuleBlock } from '@causa/workspace-terraform';
4
+ /**
5
+ * Finds the project whose configuration file a block reads. The argument is a path ending with `<project name>.json`,
6
+ * the file written by `ProjectWriteConfigurations`.
7
+ *
8
+ * @param argument The argument of the module block referencing the configuration file.
9
+ * @param projects The projects of the workspace.
10
+ * @returns The project, or `undefined` if the argument does not name a project of the workspace.
11
+ */
12
+ export declare function projectOfConfigurationFile(argument: TerraformArgument | undefined, projects: readonly WorkspaceProject[]): WorkspaceProject | undefined;
13
+ /**
14
+ * A block of a workspace-level module, which reads the configuration of an infrastructure project
15
+ * (`infrastructure_configuration_file`).
16
+ */
17
+ export type InfrastructureModule = {
18
+ /**
19
+ * The module block.
20
+ */
21
+ readonly block: TerraformModuleBlock;
22
+ /**
23
+ * The infrastructure project whose configuration the module reads.
24
+ */
25
+ readonly project: WorkspaceProject | undefined;
26
+ /**
27
+ * The context whose configuration the module reads: the project's if it is found, otherwise the workspace's.
28
+ */
29
+ readonly context: WorkspaceContext;
30
+ };
31
+ /**
32
+ * Returns the blocks of a workspace-level module, along with the context whose configuration each reads. The workspace
33
+ * context is used when the infrastructure project cannot be found.
34
+ *
35
+ * @param graph The context of the extraction.
36
+ * @param source The source of the module, e.g. `causa-io/event-topics-pubsub/google`.
37
+ * @returns The blocks of the module.
38
+ */
39
+ export declare function infrastructureModules(graph: GraphContext, source: string): Promise<InfrastructureModule[]>;
40
+ /**
41
+ * Returns a string argument of a module block, or a reference to the configuration the module falls back to, mirroring
42
+ * the `coalesce(var.<argument>, <configuration>)` logic of the Causa Terraform modules. When the block passes the
43
+ * argument but it cannot be evaluated as a string, the configuration is assumed, and a warning is raised.
44
+ *
45
+ * @param block The module block.
46
+ * @param argument The name of the module variable.
47
+ * @param configuration The path to the configuration value the module falls back to.
48
+ * @param warnings The warnings to which the one about a computed argument is added.
49
+ * @returns The literal value of the argument, or a reference to the configuration.
50
+ */
51
+ export declare function argumentOrConfiguration(block: TerraformModuleBlock, argument: string, configuration: string, warnings: GraphWarning[]): GraphTemplatePart;
52
+ /**
53
+ * The infrastructure resource created by a Terraform block, before its identifier is built.
54
+ */
55
+ export type BlockResource = {
56
+ /**
57
+ * The type of the resource, e.g. `pubsub.googleapis.com/Topic`.
58
+ */
59
+ readonly type: string;
60
+ /**
61
+ * The project whose configuration the block reads, if any. Otherwise, the workspace configuration is used.
62
+ */
63
+ readonly scope?: WorkspaceProject;
64
+ /**
65
+ * The parts of the identifier of the resource.
66
+ */
67
+ readonly id: GraphTemplatePart[];
68
+ /**
69
+ * Whether {@link BlockResource.id} is only a prefix of the identifier, when the full identifier cannot be known from
70
+ * the workspace.
71
+ */
72
+ readonly prefix?: boolean;
73
+ };
74
+ /**
75
+ * Returns the infrastructure resource a Terraform block creates.
76
+ * A block applied by the environment project creates the resource once per environment: its identifier references
77
+ * the configuration, to be rendered for a given environment, using the configuration of the scope. Other
78
+ * infrastructure projects do not depend on the environment: the identifier is rendered, and the resource has no
79
+ * scope. If it cannot be rendered, a warning is raised and the identifier references the configuration.
80
+ *
81
+ * @param graph The context of the extraction.
82
+ * @param block The block creating the resource.
83
+ * @param resource The resource.
84
+ * @param warnings The warnings to which the one about an identifier that cannot be rendered is added.
85
+ * @returns The {@link GraphResource}.
86
+ */
87
+ export declare function blockResource(graph: GraphContext, block: TerraformBlock, resource: BlockResource, warnings: GraphWarning[]): Promise<GraphResource>;
@@ -0,0 +1,107 @@
1
+ import { graphTemplate, projectId, ProjectsFact, renderGraphTemplate, } from '@causa/workspace-core/graph';
2
+ import { modulesWithSource, TerraformProjectsFact, } from '@causa/workspace-terraform';
3
+ import { basename } from 'path';
4
+ /**
5
+ * Finds the project whose configuration file a block reads. The argument is a path ending with `<project name>.json`,
6
+ * the file written by `ProjectWriteConfigurations`.
7
+ *
8
+ * @param argument The argument of the module block referencing the configuration file.
9
+ * @param projects The projects of the workspace.
10
+ * @returns The project, or `undefined` if the argument does not name a project of the workspace.
11
+ */
12
+ export function projectOfConfigurationFile(argument, projects) {
13
+ if (argument === undefined) {
14
+ return undefined;
15
+ }
16
+ const path = 'value' in argument ? argument.value : argument.expression;
17
+ if (typeof path !== 'string') {
18
+ return undefined;
19
+ }
20
+ const file = basename(path);
21
+ if (!/^[^${}]+\.json$/.test(file)) {
22
+ return undefined;
23
+ }
24
+ const name = file.slice(0, -'.json'.length);
25
+ return projects.find((p) => p.name === name);
26
+ }
27
+ /**
28
+ * Returns the blocks of a workspace-level module, along with the context whose configuration each reads. The workspace
29
+ * context is used when the infrastructure project cannot be found.
30
+ *
31
+ * @param graph The context of the extraction.
32
+ * @param source The source of the module, e.g. `causa-io/event-topics-pubsub/google`.
33
+ * @returns The blocks of the module.
34
+ */
35
+ export async function infrastructureModules(graph, source) {
36
+ const [terraformProjects, projects] = await Promise.all([
37
+ graph.get(TerraformProjectsFact),
38
+ graph.get(ProjectsFact),
39
+ ]);
40
+ return modulesWithSource(terraformProjects, source).map((block) => {
41
+ const project = projectOfConfigurationFile(block.arguments['infrastructure_configuration_file'], projects);
42
+ return { block, project, context: project?.context ?? graph.context };
43
+ });
44
+ }
45
+ /**
46
+ * Returns a string argument of a module block, or a reference to the configuration the module falls back to, mirroring
47
+ * the `coalesce(var.<argument>, <configuration>)` logic of the Causa Terraform modules. When the block passes the
48
+ * argument but it cannot be evaluated as a string, the configuration is assumed, and a warning is raised.
49
+ *
50
+ * @param block The module block.
51
+ * @param argument The name of the module variable.
52
+ * @param configuration The path to the configuration value the module falls back to.
53
+ * @param warnings The warnings to which the one about a computed argument is added.
54
+ * @returns The literal value of the argument, or a reference to the configuration.
55
+ */
56
+ export function argumentOrConfiguration(block, argument, configuration, warnings) {
57
+ const value = block.arguments[argument];
58
+ if (value === undefined ||
59
+ ('value' in value && (value.value === null || value.value === ''))) {
60
+ return { configuration };
61
+ }
62
+ if ('value' in value && typeof value.value === 'string') {
63
+ return value.value;
64
+ }
65
+ const expression = 'expression' in value ? value.expression : JSON.stringify(value.value);
66
+ warnings.push({
67
+ message: `The argument '${argument}' is computed (${expression}). Assuming the '${configuration}' configuration.`,
68
+ sources: [block.declaration],
69
+ });
70
+ return { configuration };
71
+ }
72
+ /**
73
+ * Returns the infrastructure resource a Terraform block creates.
74
+ * A block applied by the environment project creates the resource once per environment: its identifier references
75
+ * the configuration, to be rendered for a given environment, using the configuration of the scope. Other
76
+ * infrastructure projects do not depend on the environment: the identifier is rendered, and the resource has no
77
+ * scope. If it cannot be rendered, a warning is raised and the identifier references the configuration.
78
+ *
79
+ * @param graph The context of the extraction.
80
+ * @param block The block creating the resource.
81
+ * @param resource The resource.
82
+ * @param warnings The warnings to which the one about an identifier that cannot be rendered is added.
83
+ * @returns The {@link GraphResource}.
84
+ */
85
+ export async function blockResource(graph, block, resource, warnings) {
86
+ const { type, scope, id, prefix } = resource;
87
+ const build = (id, scope) => ({
88
+ type,
89
+ ...(prefix ? { idPrefix: id } : { id }),
90
+ ...(scope ? { scope } : {}),
91
+ });
92
+ const templated = build(graphTemplate(...id), scope && projectId(scope.directory));
93
+ if (block.module.project.environment) {
94
+ return templated;
95
+ }
96
+ try {
97
+ const context = scope?.context ?? graph.context;
98
+ return build(await renderGraphTemplate(context, ...id));
99
+ }
100
+ catch (error) {
101
+ warnings.push({
102
+ message: `The identifier of the '${type}' resource cannot be rendered, although the block is not applied by the environment project: ${error.message}`,
103
+ sources: [block.declaration],
104
+ });
105
+ return templated;
106
+ }
107
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causa/workspace-google",
3
- "version": "1.3.1",
3
+ "version": "1.4.0-beta.2",
4
4
  "description": "The Causa workspace module providing many functionalities related to GCP and its services.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,48 +35,49 @@
35
35
  "generateConfigurationSchemas": "cs model genCode && perl -pi -e 's|\\@causa/runtime|\\@causa/workspace/validation|g' src/configurations/generated.ts"
36
36
  },
37
37
  "dependencies": {
38
- "@causa/cli": "^1.0.0",
39
- "@causa/workspace": "^1.0.2",
40
- "@causa/workspace-core": "^1.3.0",
41
- "@causa/workspace-typescript": "^1.3.0",
42
- "@google-cloud/apikeys": "^2.2.2",
43
- "@google-cloud/bigquery": "^8.3.1",
44
- "@google-cloud/iam-credentials": "^4.2.2",
45
- "@google-cloud/logging": "^11.3.0",
46
- "@google-cloud/monitoring": "^5.4.0",
47
- "@google-cloud/pubsub": "^5.3.1",
48
- "@google-cloud/resource-manager": "^6.3.0",
49
- "@google-cloud/run": "^3.3.0",
50
- "@google-cloud/secret-manager": "^6.3.0",
51
- "@google-cloud/service-usage": "^4.2.2",
52
- "@google-cloud/spanner": "^8.10.0",
53
- "@google-cloud/storage": "^7.21.0",
38
+ "@causa/cli": "^1.0.1-beta.1",
39
+ "@causa/workspace": "^1.3.0-beta.1",
40
+ "@causa/workspace-core": "^1.5.0-beta.2",
41
+ "@causa/workspace-terraform": "^1.1.0-beta.2",
42
+ "@causa/workspace-typescript": "^1.4.0-beta.1",
43
+ "@google-cloud/apikeys": "^3.1.1",
44
+ "@google-cloud/bigquery": "^9.1.0",
45
+ "@google-cloud/iam-credentials": "^5.0.1",
46
+ "@google-cloud/logging": "^12.1.0",
47
+ "@google-cloud/monitoring": "^6.1.1",
48
+ "@google-cloud/pubsub": "^6.1.0",
49
+ "@google-cloud/resource-manager": "^7.1.1",
50
+ "@google-cloud/run": "^4.1.1",
51
+ "@google-cloud/secret-manager": "^7.1.1",
52
+ "@google-cloud/service-usage": "^5.1.1",
53
+ "@google-cloud/spanner": "^9.0.0",
54
+ "@google-cloud/storage": "^8.2.0",
54
55
  "class-transformer": "^0.5.1",
55
56
  "class-validator": "^0.15.1",
56
- "firebase": "^12.17.0",
57
- "firebase-admin": "^14.2.0",
58
- "globby": "^16.2.2",
57
+ "firebase": "^12.19.0",
58
+ "firebase-admin": "^14.5.0",
59
+ "globby": "^16.2.4",
59
60
  "google-gax": "5.0.6",
60
- "googleapis": "^173.0.0",
61
+ "googleapis": "^183.0.0",
61
62
  "micromatch": "^4.0.8",
62
- "pino": "^10.3.1"
63
+ "pino": "^10.4.0"
63
64
  },
64
65
  "devDependencies": {
65
- "@swc/core": "^1.15.47",
66
+ "@swc/core": "^1.16.13",
66
67
  "@swc/jest": "^0.2.39",
67
- "@tsconfig/node22": "^22.0.5",
68
+ "@tsconfig/node22": "^22.0.6",
68
69
  "@types/jest": "^30.0.0",
69
70
  "@types/micromatch": "^4.0.10",
70
- "@types/node": "^22.20.1",
71
+ "@types/node": "^22.20.5",
71
72
  "copyfiles": "^2.4.1",
72
- "eslint": "^10.8.0",
73
+ "eslint": "^10.12.0",
73
74
  "eslint-config-prettier": "^10.1.8",
74
75
  "eslint-plugin-prettier": "^5.5.6",
75
- "jest": "^30.4.2",
76
+ "jest": "^30.5.2",
76
77
  "jest-extended": "^7.0.0",
77
78
  "rimraf": "^6.1.3",
78
79
  "typescript": "^6.0.3",
79
- "typescript-eslint": "^8.65.0",
80
- "yaml": "^2.9.0"
80
+ "typescript-eslint": "^8.71.1",
81
+ "yaml": "^2.9.1"
81
82
  }
82
83
  }