• This repository has been archived on 13/Apr/2024
  • Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ballerina compiler extension to validate and generate wrapper services for transformer-typed packages

Ballerina-Transformer tools

A data transformation function is a general-purpose API to apply a function to a set of data points. The output may contain data points generated by adding, removing, or altering some. The Ballerina transformer is also a set of such tools that provide the following capabilities.

  1. Validate if a given Ballerina package is a transformer package
  2. Generate Ballerina service(s) to expose Ballerina transformer functions as REST APIs

Create a data-transformation service

To create a data transformation service, a Ballerina package has to be created and transformer tools have to be imported. Once after writing the transformer functions, the build command would generate the required transformer services for the transformer functions written. The below is an example.

Example:

import ballerinax/transformer as _;

public type Person record {
    string firstName;
    string lastName;
};

public type Student record {
    string fullName;
    string school;
};

public isolated function transform(Person person, string school) returns Student => {
    fullName: person.firstName + " " + person.lastName,
    school: school
};

Once the above code is validated, a service would get generated for the transformer function, which transforms a Person into a Student.

Request

POST /transform/

curl -X POST http://localhost:7000/transform
    -H 'Content-Type: application/json'
    -d '{"person": {"firstName": "Joe", "lastName": "Root"}, "school": "Kingswood"}'

Response

HTTP/1.1 201 Created
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 201 Created
Connection: close
Content-Type: application/json
Location: /thing/1
Content-Length: 36

{"fullName": "Joe Root", "school": "Kingswood"}

For the transformer function above, it would create a Ballerina record to capture all parameters and that record would be passed as the payload of the service's resource function.

type transformPayload record {
    Person person;
    string school;
};

Validator and Generator

Transformer Package Validator

Ballerina transformer tools can validate a Ballerina package if that complies with the constraints of a Ballerina transformer package. For a Ballerina package to be treated as a transformer package, it should comply with the constraints below.

  1. The package should not contain any entry points (i. e., main function or services)
  2. The package should have one or more expression-bodied functions (transformer-function) with public and isolated qualifiers
  3. The package can contain other functions, which can be used at util functions (cannot be public)
  4. The package can contain records
  5. The package is not allowed to have class definitions or listener definitions
  6. Expression-bodied functions in the package are only allowed to have a public qualifier
  7. The package is not allowed to have annotations
  8. The public isolated expression-bodied functions (transformer-functions) are allowed to have serializable types as a parameter type and return type

As of now, to activate the transformer tools on a Ballerina package, the tool is required to be imported to the relevant package as specified below. After that, when the Ballerina transformer package is built, it will be validated against the aforementioned constraints.

import ballerinax/transformer as _;

Ballerina Service Generator

Once a Ballerina package is validated, the transformer tools will generate a service, which would allow the transformer functions to be consumed through REST APIs. The parameters of the transformer function have to be passed as a JSON payload.

Note: The service for the Ballerina package would only get generated if there are no validation errors, and the parameter types and return types of the transformer function should be serializable and should be supported by the Ballerina HTTP module. The list of such Ballerina types can be found in the Ballerina HTTP module specification.

Build from the source

Set up the prerequisites

  1. OpenJDK 11 (Adopt OpenJDK or any other OpenJDK distribution)

    Info: You can also use Oracle JDK. Set the JAVA_HOME environment variable to the pathname of the directory into which you installed JDK.

  2. Export the GitHub Personal access token with the read package permissions as follows.

    export packageUser=<Username>
    export packagePAT=<Personal access token>
    

Build the source

Execute the commands below to build from the source.

  1. To build the library:

    ./gradlew clean build
  2. To run the integration tests:

    ./gradlew clean test
  3. To build the module without the tests:

    ./gradlew clean build -x test
  4. To publish to local Maven:

    ./gradlew clean build publishToMavenLocal

Contribute to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All the contributors are encouraged to read the Ballerina Code of Conduct.

Useful links

More Repositories

1

ballerina-extended-library

Library for Ballerina Extensions and Connectors
Java
110
star
2

playground

Ballerina playground is a web based tool which allows trying out language features.
Ballerina
110
star
3

wsdl-tools

Source code of WSDL to Ballerina Tool
109
star
4

hl7-tools

Tools that generate HL7-related ballerina artefacts
105
star
5

ballerina-examples

58
star
6

ballerina-www

HTML
53
star
7

docs-ballerina-vscode-extension

This is the official documentation of the Ballerina Visual Studio Code plugin.
HTML
33
star
8

composer

The Ballerina Composer provides a flexible and powerful browser-based tool for creating your Ballerina programs.
JavaScript
25
star
9

nballerina-cpp

Ballerina compiler backend that generates platform-specific executables.
C++
16
star
10

playground-hello-service

Ballerina
14
star
11

ballerina-demo

Ballerina
14
star
12

restful-service

Ballerina
10
star
13

tools-distribution

Ballerina Distribution
Java
9
star
14

ballerina-bridge

Java
8
star
15

messaging-with-kafka

Ballerina
8
star
16

module-twitter

Ballerina
7
star
17

plugin-vscode

Ballerina extension for VS Code.
TypeScript
7
star
18

ballerina-with-istio

Ballerina
6
star
19

connectors

Ballerina
6
star
20

plugin-intellij

Java
5
star
21

language-server

Java
5
star
22

grpc-service

Ballerina
4
star
23

service-composition

Ballerina
4
star
24

module-sonarqube

Ballerina
4
star
25

jdbc

Ballerina
4
star
26

ballerina-performance

Shell
4
star
27

api-gateway

Ballerina
4
star
28

module-ballerinax-cassandra

Java
3
star
29

module-ballerinax-jira

Ballerina
3
star
30

plugin-vim

Vim Script
3
star
31

module-kubernetes

Ballerina
3
star
32

container-support

Java
3
star
33

plugin-vscode_prev

JavaScript
3
star
34

website

HTML
3
star
35

community

Ballerina community call contents
Ballerina
3
star
36

ballerina-observability

Java
3
star
37

inter-microservice-communication

Ballerina
2
star
38

parallel-service-orchestration

Ballerina
2
star
39

salesforce-netsuite-slack-quote-to-cash

Automating a quote-to-cash process using Salesforce, Netsuite and Slack connectors.
Ballerina
2
star
40

module-scim2

Ballerina
2
star
41

backend-for-frontend

Ballerina
2
star
42

ballerina-api-gateway

2
star
43

module-amazonec2

Ballerina
2
star
44

websocket-integration

Ballerina
2
star
45

messaging-with-activemq

Ballerina
2
star
46

salesforce-samples

This repository contains Salesforce integration samples using Ballerina. These samples highlight the capabilities of the Ballerina programming language in ERP integrations.
2
star
47

module-ballerinax-stripe

The Ballerina connector to perform operations on Stripe online payment system.
Ballerina
1
star
48

salesforce-twilio-integration

Ballerina
1
star
49

eip-message-construction

Ballerina
1
star
50

loadbalancing-failover

Ballerina
1
star
51

ballerina-specs

1
star
52

module-smb

Java
1
star
53

plugin-eclipse

Java
1
star
54

pass-through-messaging

Ballerina
1
star
55

module-reliable-delivery

Ballerina
1
star
56

resiliency-timeouts

Ballerina
1
star
57

ballerina-awslambda-deployment

1
star
58

module-salesforcerest

Ballerina
1
star
59

content-based-routing

Ballerina
1
star
60

plugin-sublimetext3

1
star
61

playground-streaming

Ballerina
1
star
62

module-ballerinax-shopify

Ballerina Shopify module
Ballerina
1
star
63

message-filtering

Ballerina
1
star
64

scatter-gather-messaging

Ballerina
1
star
65

module-storeforward

The store forward connector provides a guaranteed delivery pattern.
Ballerina
1
star
66

resiliency-circuit-breaker

Ballerina
1
star
67

module-facebook

Ballerina
1
star
68

plugin-atom

JavaScript
1
star
69

ballerina-gke-deployment

Ballerina
1
star
70

asynchronous-invocation

Ballerina
1
star