Packaged is a repository that contains interfaces/types/contracts that helps developers to create their own strongly-typed environment-agnostic (AWS, Azure, Google Cloud, IBM Cloud, Apache OpenWhisk, etc.) Function-as-a-Service apps.
This project only contains the abstraction and there's no implementation involved. Given that, developers can implement application-specific business logic without having a unified API interface.
To install this package, run the command below.
# npm
npm install --save packaged
# yarn
yarn add packaged
This file contains a general event structure. The event is a generic type, means that not providing the payload type (TPayload) results in an event w/o payload.
import { Event } from 'packaged';
const dailyCronEvent: Event = {
// check the properties of the Event object
};
const userRegisteredEvent: Event<User> = {
// check the properties of the Event object
payload: {
// User object (based on the input type)
},
};
This file contains a request/response structure for an RPC system (e.g. HTTP API or internal lambda functions).
The request object is not unified (due to the complexity and coupling to the implementation). But there are several types you can use to unify your request objects.
- PaginatedRequest
- FilteredRequest
- RequestWithPayload
You can define your request object by combining these types.
import { PaginatedRequest, FilteredRequest } from 'packaged';
type UserFilters = {
group: Array<string>;
};
type ListUsersRequest = PaginatedRequest & FilteredRequest<UserFilters>;
const listUsers = (req: ListUserRequest) => {
const { filters, pagination } = req;
// apply filters (e.g. filters.group...)
// apply pagination (e.g. skip/take or cursor based)
};
There are two main response types:
- SuccessResponse
- ErrorResponse
There is one child response from SuccessResponse
- PaginatedResponse
import { Response, PaginatedResponse } from 'packaged';
const requestReceived: Response = {
// check the properties of the Event object
};
const userCreatedResponse: Response<User> = {
// check the properties of the Event object
payload: {
// User object (based on the input type)
},
};
TBD
TBD
And you're good to go!
MIT