From 0ed1ae9ad99b905543436ea38cc0aa7c63017f31 Mon Sep 17 00:00:00 2001 From: andes-it Date: Tue, 22 Oct 2024 22:20:25 +0000 Subject: [PATCH] chore: nx format:write update dirty files --- infra/src/common/nx-command.ts | 2 +- .../output-generators/map-to-helm-values.ts | 5 +- .../pre-process-service.ts | 9 +- infra/src/dsl/types/input-types.ts | 8 +- .../dsl/value-files-generators/local-setup.ts | 12 +- infra/src/generated/nx-project-schema.ts | 272 ++++++++++++++---- infra/src/uber-charts/islandis.ts | 3 +- 7 files changed, 233 insertions(+), 78 deletions(-) diff --git a/infra/src/common/nx-command.ts b/infra/src/common/nx-command.ts index 1cf2b8d4b0c0..791ff6a9edfc 100644 --- a/infra/src/common/nx-command.ts +++ b/infra/src/common/nx-command.ts @@ -28,7 +28,7 @@ export const nxCommand = async (options: { } // If not parsing JSON, return raw stdout - return (stdout as unknown) as T + return stdout as unknown as T } catch (error) { handleNxCommandError(error) throw error diff --git a/infra/src/dsl/output-generators/map-to-helm-values.ts b/infra/src/dsl/output-generators/map-to-helm-values.ts index c5bfa329a7ff..8e75cd861692 100644 --- a/infra/src/dsl/output-generators/map-to-helm-values.ts +++ b/infra/src/dsl/output-generators/map-to-helm-values.ts @@ -341,9 +341,8 @@ function serializeIngress( ingressConf: IngressForEnv, env: EnvironmentConfig, ) { - const hosts = (typeof ingressConf.host === 'string' - ? [ingressConf.host] - : ingressConf.host + const hosts = ( + typeof ingressConf.host === 'string' ? [ingressConf.host] : ingressConf.host ).map((host) => ingressConf.public ?? true ? hostFullName(host, env) diff --git a/infra/src/dsl/service-to-environment/pre-process-service.ts b/infra/src/dsl/service-to-environment/pre-process-service.ts index 3cf91811a488..1476f8880b7d 100644 --- a/infra/src/dsl/service-to-environment/pre-process-service.ts +++ b/infra/src/dsl/service-to-environment/pre-process-service.ts @@ -306,12 +306,9 @@ function addFeaturesConfig( env: EnvironmentConfig, serviceName: string, ) { - const activeFeatures = Object.entries( - serviceDefFeatures, - ).filter(([feature]) => env.featuresOn.includes(feature as FeatureNames)) as [ - FeatureNames, - Feature, - ][] + const activeFeatures = Object.entries(serviceDefFeatures).filter( + ([feature]) => env.featuresOn.includes(feature as FeatureNames), + ) as [FeatureNames, Feature][] const featureEnvs = activeFeatures.map(([name, v]) => { const { envs, errors } = getEnvVariables(v.env, serviceName, env.type) return { diff --git a/infra/src/dsl/types/input-types.ts b/infra/src/dsl/types/input-types.ts index 26c35e98b590..5afc4616e0ae 100644 --- a/infra/src/dsl/types/input-types.ts +++ b/infra/src/dsl/types/input-types.ts @@ -155,11 +155,9 @@ export interface Ingress { } paths: string[] public?: boolean - extraAnnotations?: Partial< - { - [env in OpsEnv]: { [annotation: string]: string | null } - } - > + extraAnnotations?: Partial<{ + [env in OpsEnv]: { [annotation: string]: string | null } + }> } export interface IngressForEnv { diff --git a/infra/src/dsl/value-files-generators/local-setup.ts b/infra/src/dsl/value-files-generators/local-setup.ts index 89d03384593c..ecb09d8534be 100644 --- a/infra/src/dsl/value-files-generators/local-setup.ts +++ b/infra/src/dsl/value-files-generators/local-setup.ts @@ -33,21 +33,21 @@ export const mapServiceToNXname = async ( if (!validatedProjectMeta.name || !validatedProjectMeta.sourceRoot) { throw new Error( - `Project metadata is missing required fields: name or sourceRoot.` - ); + `Project metadata is missing required fields: name or sourceRoot.`, + ) } return { serviceName: validatedProjectMeta.name, projectPath: validatedProjectMeta.sourceRoot, - }; + } } catch (error) { - logger.error('Error in mapServiceToNXname:', error); + logger.error('Error in mapServiceToNXname:', error) if (error instanceof Error) { - throw new Error(`Unexpected error: ${error.message}`); + throw new Error(`Unexpected error: ${error.message}`) } - throw new Error('An unknown error occurred.'); + throw new Error('An unknown error occurred.') } } diff --git a/infra/src/generated/nx-project-schema.ts b/infra/src/generated/nx-project-schema.ts index eda9c6df9f6a..bbd06e64aa60 100644 --- a/infra/src/generated/nx-project-schema.ts +++ b/infra/src/generated/nx-project-schema.ts @@ -1,60 +1,220 @@ // This file is auto-generated. Do not edit directly. -import { z } from "zod" +import { z } from 'zod' -export const nxProjectSchema = z.object({ "name": z.string().describe("Project's name. Optional if specified in workspace.json").optional(), "root": z.string().describe("Project's location relative to the root of the workspace").optional(), "sourceRoot": z.string().describe("The location of project's sources relative to the root of the workspace").optional(), "projectType": z.enum(["library","application"]).describe("Type of project supported").optional(), "generators": z.record(z.any()).describe("List of default values used by generators").optional(), "namedInputs": z.record(z.any()).describe("Named inputs used by inputs defined in targets").optional(), "targets": z.record(z.object({ "executor": z.string().describe("The function that Nx will invoke when you run this target").optional(), "options": z.record(z.any()).optional(), "outputs": z.array(z.string()).optional(), "defaultConfiguration": z.string().describe("The name of a configuration to use as the default if a configuration is not provided").optional(), "configurations": z.record(z.record(z.any())).describe("provides extra sets of values that will be merged into the options map").optional(), "inputs": z.any().optional(), "dependsOn": z.array(z.any().superRefine((x, ctx) => { - const schemas = [z.string(), z.object({ "projects": z.any().superRefine((x, ctx) => { - const schemas = [z.string().describe("A project name"), z.array(z.string()).describe("An array of project names")]; - const errors = schemas.reduce( - (errors, schema) => - ((result) => - result.error ? [...errors, result.error] : errors)( - schema.safeParse(x), - ), - [], - ); - if (schemas.length - errors.length !== 1) { - ctx.addIssue({ - path: ctx.path, - code: "invalid_union", - unionErrors: errors, - message: "Invalid input: Should pass single schema", - }); - } - }).optional(), "dependencies": z.boolean().optional(), "target": z.string().describe("The name of the target.").optional(), "params": z.enum(["ignore","forward"]).describe("Configuration for params handling.").default("ignore") }).strict().and(z.any().superRefine((x, ctx) => { - const schemas = [z.any(), z.any(), z.any().refine((value) => !z.union([z.any(), z.any()]).safeParse(value).success, "Invalid input: Should NOT be valid against schema")]; - const errors = schemas.reduce( - (errors, schema) => - ((result) => - result.error ? [...errors, result.error] : errors)( - schema.safeParse(x), - ), - [], - ); - if (schemas.length - errors.length !== 1) { - ctx.addIssue({ - path: ctx.path, - code: "invalid_union", - unionErrors: errors, - message: "Invalid input: Should pass single schema", - }); - } - }))]; - const errors = schemas.reduce( - (errors, schema) => - ((result) => - result.error ? [...errors, result.error] : errors)( - schema.safeParse(x), - ), - [], - ); - if (schemas.length - errors.length !== 1) { - ctx.addIssue({ - path: ctx.path, - code: "invalid_union", - unionErrors: errors, - message: "Invalid input: Should pass single schema", - }); - } - })).optional(), "command": z.string().describe("A shorthand for using the nx:run-commands executor").optional(), "cache": z.boolean().describe("Specifies if the given target should be cacheable").optional(), "parallelism": z.boolean().describe("Whether this target can be run in parallel with other tasks").default(true), "metadata": z.object({ "description": z.string().describe("A description of the target").optional() }).catchall(z.any()).describe("Metadata about the target").optional(), "syncGenerators": z.array(z.string()).describe("List of generators to run before the target to ensure the workspace is up to date").optional() })).describe("Configures all the targets which define what tasks you can run against the project").optional(), "tags": z.array(z.string()).optional(), "implicitDependencies": z.array(z.string()).optional(), "metadata": z.object({ "description": z.string().describe("A description of the project.").optional() }).catchall(z.any()).describe("Metadata about the project.").optional(), "release": z.object({ "version": z.object({ "generator": z.string().describe("The version generator to use. Defaults to @nx/js:release-version.").optional(), "generatorOptions": z.record(z.any()).describe("Options for the version generator.").optional() }).describe("Configuration for the nx release version command.").optional() }).describe("Configuration for the nx release commands.").optional() }) +export const nxProjectSchema = z.object({ + name: z + .string() + .describe("Project's name. Optional if specified in workspace.json") + .optional(), + root: z + .string() + .describe("Project's location relative to the root of the workspace") + .optional(), + sourceRoot: z + .string() + .describe( + "The location of project's sources relative to the root of the workspace", + ) + .optional(), + projectType: z + .enum(['library', 'application']) + .describe('Type of project supported') + .optional(), + generators: z + .record(z.any()) + .describe('List of default values used by generators') + .optional(), + namedInputs: z + .record(z.any()) + .describe('Named inputs used by inputs defined in targets') + .optional(), + targets: z + .record( + z.object({ + executor: z + .string() + .describe('The function that Nx will invoke when you run this target') + .optional(), + options: z.record(z.any()).optional(), + outputs: z.array(z.string()).optional(), + defaultConfiguration: z + .string() + .describe( + 'The name of a configuration to use as the default if a configuration is not provided', + ) + .optional(), + configurations: z + .record(z.record(z.any())) + .describe( + 'provides extra sets of values that will be merged into the options map', + ) + .optional(), + inputs: z.any().optional(), + dependsOn: z + .array( + z.any().superRefine((x, ctx) => { + const schemas = [ + z.string(), + z + .object({ + projects: z + .any() + .superRefine((x, ctx) => { + const schemas = [ + z.string().describe('A project name'), + z + .array(z.string()) + .describe('An array of project names'), + ] + const errors = schemas.reduce( + (errors, schema) => + ((result) => + result.error + ? [...errors, result.error] + : errors)(schema.safeParse(x)), + [], + ) + if (schemas.length - errors.length !== 1) { + ctx.addIssue({ + path: ctx.path, + code: 'invalid_union', + unionErrors: errors, + message: 'Invalid input: Should pass single schema', + }) + } + }) + .optional(), + dependencies: z.boolean().optional(), + target: z + .string() + .describe('The name of the target.') + .optional(), + params: z + .enum(['ignore', 'forward']) + .describe('Configuration for params handling.') + .default('ignore'), + }) + .strict() + .and( + z.any().superRefine((x, ctx) => { + const schemas = [ + z.any(), + z.any(), + z + .any() + .refine( + (value) => + !z.union([z.any(), z.any()]).safeParse(value) + .success, + 'Invalid input: Should NOT be valid against schema', + ), + ] + const errors = schemas.reduce( + (errors, schema) => + ((result) => + result.error ? [...errors, result.error] : errors)( + schema.safeParse(x), + ), + [], + ) + if (schemas.length - errors.length !== 1) { + ctx.addIssue({ + path: ctx.path, + code: 'invalid_union', + unionErrors: errors, + message: 'Invalid input: Should pass single schema', + }) + } + }), + ), + ] + const errors = schemas.reduce( + (errors, schema) => + ((result) => + result.error ? [...errors, result.error] : errors)( + schema.safeParse(x), + ), + [], + ) + if (schemas.length - errors.length !== 1) { + ctx.addIssue({ + path: ctx.path, + code: 'invalid_union', + unionErrors: errors, + message: 'Invalid input: Should pass single schema', + }) + } + }), + ) + .optional(), + command: z + .string() + .describe('A shorthand for using the nx:run-commands executor') + .optional(), + cache: z + .boolean() + .describe('Specifies if the given target should be cacheable') + .optional(), + parallelism: z + .boolean() + .describe( + 'Whether this target can be run in parallel with other tasks', + ) + .default(true), + metadata: z + .object({ + description: z + .string() + .describe('A description of the target') + .optional(), + }) + .catchall(z.any()) + .describe('Metadata about the target') + .optional(), + syncGenerators: z + .array(z.string()) + .describe( + 'List of generators to run before the target to ensure the workspace is up to date', + ) + .optional(), + }), + ) + .describe( + 'Configures all the targets which define what tasks you can run against the project', + ) + .optional(), + tags: z.array(z.string()).optional(), + implicitDependencies: z.array(z.string()).optional(), + metadata: z + .object({ + description: z + .string() + .describe('A description of the project.') + .optional(), + }) + .catchall(z.any()) + .describe('Metadata about the project.') + .optional(), + release: z + .object({ + version: z + .object({ + generator: z + .string() + .describe( + 'The version generator to use. Defaults to @nx/js:release-version.', + ) + .optional(), + generatorOptions: z + .record(z.any()) + .describe('Options for the version generator.') + .optional(), + }) + .describe('Configuration for the nx release version command.') + .optional(), + }) + .describe('Configuration for the nx release commands.') + .optional(), +}) export type NxProjectSchema = z.infer diff --git a/infra/src/uber-charts/islandis.ts b/infra/src/uber-charts/islandis.ts index efd31d74396f..372e30eeaa3f 100644 --- a/infra/src/uber-charts/islandis.ts +++ b/infra/src/uber-charts/islandis.ts @@ -138,7 +138,8 @@ const downloadService = downloadServiceSetup({ const userNotificationWorkerService = userNotificationWorkerSetup({ userProfileApi: servicePortalApi, }) -const userNotificationCleanupWorkerService = userNotificationCleanUpWorkerSetup() +const userNotificationCleanupWorkerService = + userNotificationCleanUpWorkerSetup() const githubActionsCache = githubActionsCacheSetup()