Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Migrate away from class-transfomer

Abierto
#100 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
javascript, nodejs, typescript

Línea de trabajo

Revisa primero el issue 68 y el ejemplo propuesto de handlers.ts; después, inspecciona el SDK y el código generado que, según el issue, requerirían cambios. Sigue la integración actual de class-transformer e identifica los puntos de entrada afectados antes de evaluar camelcase-keys, AJV y json-schema-to-typescript. La tarea estará completa cuando el plugin ya no dependa de class-transformer, admita el flujo de trabajo de JavaScript y TypeScript propuesto e incluya los cambios necesarios en el SDK y el código generado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

This is a rethought version of my previous ticket https://github.com/aws-cloudformation/cloudformation-cli-typescript-plugin/issues/68

To resummarize the issues with class-transformer:

  • The serialization breaks down in the face of unsupported CloudFormation JSON Schema Features, and increases complexity since JSON Schema features must be manually mapped to the Class Transformer equivalent.
  • It ties the implementation to TypeScript's decorators which are soon to be completely deprecated and redesigned entirely, and results in a data model that might be foreign to a lot of JavaScript developers today (outside angular and nestjs)
  • Because of the above, it prevents JavaScript from working (though I'd personally always encourage TS over JS) (https://github.com/aws-cloudformation/cloudformation-cli-typescript-plugin/issues/8)
  • The project isn't also super alive right now: https://github.com/typestack/class-transformer/issues/1272 Possibly no longer as valid, it looks like the projects might be getting new maintainers.

The updated proposal proposes swapping class-transformer with three components:

  • The package camelcase-keys to handle the CloudFormation-to-JS object key camelcasing.
  • The package AJV to handle validating the incoming event properties, provide friendly(er) error messages, as well as automatic type conversion
  • The package json-schema-to-typescript to handle consuming the resource definition and outputting type information for a richer experience.

While a very large change, it would uncouple this plugin from TypeScript and an unmaintained library while hopefully simplifying the Dev UX of developing a resource in typescript.

For example, a simple handler like the template default would become (example greatly appreviated):

// handlers.ts
import { Resource, TypeConfiguration } from "./.generated/models";
import { createResource, ProgressEvent, exceptions } from '@amazon-web-services-cloudformation/cloudformation-cli-typescript-lib';

const { entrypoint, testEntrypoint } = createResource<Resource, TypeConfiguration>({
    typeName: Resource.TypeName,
	schema: Resource.Schema,
    // Type information for all the below is automatically infered
	async create({ session, properties, request, logger, typeConfiguration }) {
        // Example:
        try {
			const { apiKey } = typeConfiguration;
            const response = await fetch(`https://api.someservice.com`, {
              method: 'POST',
              headers: { 'x-api-key': apiKey },
              body: { ...properties },
			});
            const { id } = await response.json();
            properties.id = id;
            // else handle error
        } catch(err) {
            logger.log(err);
            // exceptions module lets CloudFormation know the type of failure that occurred
            throw new exceptions.InternalFailure(err.message);
            // this can also be done by returning a failed progress event
            // return ProgressEvent.failed(HandlerErrorCode.InternalFailure, err.message);
        }
        return properties;
    },
    /* more handlers.... */
    async list({ properties, typeConfiguration }) {
	   /* ...some list code... */
       // Just return a plain array of models, validate via typescript & ajv
       return [/* list of plain old javascript models */];
    },
});

export { entrypoint, testEntrypoint };

This also externalizes a lot of concerns unnecessary to the user code, infers a lot more of type information automatically, and makes developing resource types much less mentally onerous allowing developers to focus on business logic.

It would require more work with the SDK and generated code however.

Lenguaje dominante
TypeScript
Estrellas
46
Forks
18
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws-cloudformation/cloudformation-cli-typescript-plugin

Todos los issues de aws-cloudformation/cloudformation-cli-typescript-plugin

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.