Skip to content

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.

License

Notifications You must be signed in to change notification settings

DManavi/packaged

Repository files navigation

Packaged

NPM version NPM downloads Build Status

About

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.

Installation

To install this package, run the command below.

# npm
npm install --save packaged

# yarn
yarn add packaged

Usage

Event

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)
  },
};

RPC

This file contains a request/response structure for an RPC system (e.g. HTTP API or internal lambda functions).

Request

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)
};

Response

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)
  },
};

Pagination

Offset-based

TBD

Cursor-based

TBD

And you're good to go!

License

MIT


About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published