Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cua.run/babel

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cua.run/babel

`cua` is your favorite async tasks handler to offload your JavaScript API.

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by175%
Maintainers
1
Weekly downloads
 
Created
Source

@cua.run/babel

cua is your favorite async tasks handler to offload your JavaScript API.


@cua.run/babel enable you to seamlessly call cua functions as follows:

import type { NextApiRequest, NextApiResponse } from "next";
import importContacts from "../../cua-functions/importContacts";

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  const user = { /* ... */ }
  await importContacts([user]); // will be replaced by `cua.push('importContacts', [user])` by our babel plugin
  res.status(200).json({ name: "John Doe" });
}

Install

yarn add -D @cua.run/babel

# or

npm i --save-dev @cua.run/babel

Configuration

Next.js

Create a babelrc.js configuration as follows:

const babelPlugin = require("@cua.run/babel");
module.exports = {
  presets: ["next/babel"],
  plugins: [[babelPlugin]],
};

Write your first cua function

All cua functions must be in a root cua-functions/ folder:

example for a Next.js project:

- pages/
  - _app.ts
  - index.ts
  - api/
    - import.ts
- cua.functions/
  - importContacts.ts
- .babelrc.js
- next.config.js
- package.json

Then, your cua function should be a file having:

  • a function with CuaFunction signature
  • a default export

cua.functions/importContacts.ts

import { CuaFunction } from "@cua.run/client";

interface Contact {
  id: string
  name: string
}

const importContacts: CuaFunction = (contact: Contact[]) => {
  // ...
  // returns a Promise
}

export default importContacts

Then, your cua function can be invoked as follows:

pages/api/import.ts

import type { NextApiRequest, NextApiResponse } from "next";
import importContacts from "../../cua-functions/importContacts";

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  const user = { /* ... */ }
  // will delay the execution of the function in the background queue
  await importContacts([user]); 
  res.status(200).json({ ok: true });
}

FAQs

Package last updated on 14 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc