Platformatic v0.29.0 is out now!

Platformatic v0.29.0 is out now!

Today we are releasing v0.29.0 of Platformatic, packing in many improvements.

Through this exciting release, we’ve improved TypeScript support. We now allow you to edit your APIs on the fly with Platformatic Composer, you’ll be able to make platformatic client runtime aware, and we’ve improved the generator.

Check out the full release notes at: github.com/platformatic/platformatic/releas..

Here is a summary of the major features.

TypeScript Compilation for Production

Platformatic Service provides automatic TypeScript compilation during the startup of your Node.js server. While this provides a great developer experience, it adds additional startup time and requires more resources – something that comes at a premium in production environments.

In Platformatic v0.29.0 we changed how the plugin configuration is generated by npx create-platformatic@latest, adding a {PLT_TYPESCRIPT} env variable:

{
  ...
  "plugins": {
    "paths": [{
      "path": "plugins",
      "encapsulate": false
    }, "routes"],
    "typescript": "{PLT_TYPESCRIPT}"
  }
}

Note that the {PLT_TYPESCRIPT} will be automatically replaced with the PLT_TYPESCRIPT environment variable, that is configured in your .env (and .env.sample) file:

PLT_TYPESCRIPT=true

Compiling for deployment

Compiling for deployment is as easy as running plt service compile in said folder. Remember to set PLT_TYPESCRIPT=false in your environment variables in the deployed environments.

Usage with Runtime

If you are building a Runtime-based application, you will need to compile every service independently or with the use of plt runtime compile.

Runtime-aware Client generator

Platformatic Runtime allows you to create a network of services that are not exposed. To create a client to invoke one of those services from another, run:

$ platformatic client --name <clientname> --runtime <serviceId>

Where <clientname> is the name of the client and <serviceId> is the id of the given service (which correspond in the basic case with the folder name of that service). The client generated is identical to the one in the previous section.

Note that this command looks for a platformatic.runtime.json in a parent directory.

Editing your composed APIs on the fly

Platformatic Composer allows you to compose multiple services exposing OpenAPI definitions:

 Composition of two remote services:

  ```json
  {
    "composer": {
      "services": [
        {
          "id": "auth-service",
          "origin": "https://auth-service.com",
          "openapi": {
            "url": "/documentation/json",
            "prefix": "auth",
            "config": "./auth-openapi-config.json"
          }
        },
        {
          "id": "payment-service",
          "origin": "https://payment-service.com",
          "openapi": {
            "file": "./schemas/payment-service.json",
            "config": "./payment-openapi-config.json"
          }
        }
      ],
      "refreshTimeout": 1000
    }
  }

Each service API can be modified on the fly by Platformatic Composer via the use of a service-specific config file (composer.services.openapi.config property). It supports the following options:

  • ignore (boolean) - If true, the route will be ignored by the composer. If you want to ignore a specific method, use the ignore option in the nested method object.

    Example

    {
      "paths": {
        "/users": {
          "ignore": true
        },
        "/users/{id}": {
          "get": { "ignore": true },
          "put": { "ignore": true }
        }
      }
    }
    
  • alias (string) - Use it create an alias for the route path. The original route path will be ignored.

    Example

    {
      "paths": {
        "/users": {
          "alias": "/customers"
        }
      }
    }
    
  • rename (string) - Use it to rename composed route response fields. Use JSON Schema format to describe the response structure. For now, this will only work for 200 responses.

    Example

    {
      "paths": {
        "/users": {
          "responses": {
              "200": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": { "rename": "user_id" },
                    "name": { "rename": "first_name" }
                  }
                }
              }
            }
        }
      }
    }
    

Create Platformatic DB applications for MySQL, MariaDB and PostgreSQL

We have updated our create-platformatic command to generate the correct environment variables and schema definitions for Platformatic DB, should you want to connect to MySQL, MariaDB and PostgreSQL

➜  create-platformatic
 Hello, Matteo Collina welcome to Platformatic 0.28.1!
 Let's start by creating a new project.
? Which kind of project do you want to create? DB
? Where would you like to create your project? .
? What database do you want to use? (Use arrow keys)
  SQLite
❯ PostgreSQL
  MySQL
  MariaDB
? Do you want to use the connection string "postgres://postgres:postgres@127.0.0.1:5432/postgres"? (yeH)

Remember to start the correct databases if you are developing locally.

MySQL

docker run --env MYSQL_ALLOW_EMPTY_PASSWORD=true --env MYSQL_DATABASE=test -p 3306:3306 mysql

MariaDB

docker run --env MYSQL_ALLOW_EMPTY_PASSWORD=true --env MYSQL_DATABASE=test -p 3306:3306 mysql:5.7

PostgreSQL

docker run -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=test -p 5432:5432 postgres