@defer/client
Advanced tools
Comparing version 1.0.0 to 1.1.0-alpha-20230305031509-ccc39dd
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.awaitResult = exports.delay = exports.defer = exports.configure = void 0; | ||
exports.awaitResult = exports.delay = exports.defer = exports.getExecution = exports.configure = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -34,2 +34,7 @@ const parse_duration_1 = __importDefault(require("parse-duration")); | ||
exports.configure = configure; | ||
const getExecution = (id, client) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return (0, client_js_1.fetchExecution)(client || __httpClient, { id }); | ||
}; | ||
exports.getExecution = getExecution; | ||
const defer = (fn, options) => { | ||
@@ -36,0 +41,0 @@ const ret = async (...args) => { |
@@ -5,3 +5,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const FakeID = "00000000000000000000000000000000"; | ||
import { enqueueExecution, waitExecutionResult, } from "./client.js"; | ||
import { enqueueExecution, fetchExecution, waitExecutionResult, } from "./client.js"; | ||
import { DeferError } from "./errors.js"; | ||
@@ -27,2 +27,6 @@ import { makeHTTPClient } from "./httpClient.js"; | ||
} | ||
export const getExecution = (id, client) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return fetchExecution(client || __httpClient, { id }); | ||
}; | ||
export const defer = (fn, options) => { | ||
@@ -29,0 +33,0 @@ const ret = async (...args) => { |
{ | ||
"name": "@defer/client", | ||
"version": "1.0.0", | ||
"version": "1.1.0-alpha-20230305031509-ccc39dd", | ||
"description": "Zero infrastructure NodeJS background jobs", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
# `@defer/client` | ||
`defer` is your favorite background tasks handler to offload your JavaScript API. | ||
Zero infrastructure Node.js background jobs. | ||
---- | ||
## Install | ||
## Get started | ||
- [Next.js Quickstart](https://docs.defer.run/quickstart/next/) | ||
- [Express/Koa/hapi Quickstart](https://docs.defer.run/quickstart/express-koa-hapi/) | ||
```sh | ||
yarn add @defer/client | ||
# or | ||
## API documentation | ||
npm i @defer/client | ||
``` | ||
## Configuration | ||
Make sure to define the `DEFER_TOKEN` environment variable in production/staging environments. | ||
## Usage | ||
### 1. Define your background function | ||
A background function should be a unique default export of a file placed in `background-functions/` folder. | ||
```ts | ||
import { defer } from "@defer/client"; | ||
function importContacts(intercomId: string) { | ||
// import contacts from Hubspot and insert them in the database | ||
} | ||
export default defer(importContacts) | ||
``` | ||
### 2. Call your background function | ||
For a seamless integration with your project, we recommend to install our `@defer.run/babel` babel plugin. | ||
Our babel plugin will replace all usage of defer functions to client pushes: | ||
```ts | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import sentToIntercom from "../../background-functions/importContacts"; | ||
export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
// will be executed in the background | ||
await importContacts(currentUser.intercomId); | ||
res.status(200).json({ name: "John Doe" }); | ||
} | ||
``` | ||
- [Configuration options: retries, concurrency](https://docs.defer.run/features/retries-concurrency/) | ||
- [Delayed Function](https://docs.defer.run/features/delay/) | ||
- [CRON](https://docs.defer.run/features/cron/) | ||
- [Workflows](https://docs.defer.run/features/workflows/) |
import { Units } from "parse-duration"; | ||
import { EnqueueExecutionResponse } from "./client.js"; | ||
import { HTTPClient } from "./httpClient.js"; | ||
interface Options { | ||
@@ -9,2 +10,3 @@ accessToken?: string; | ||
export declare function configure(opts?: Options): void; | ||
export declare const getExecution: (id: string, client?: HTTPClient) => Promise<import("./client.js").FetchExecutionResponse>; | ||
export declare type UnPromise<F> = F extends Promise<infer R> ? R : F; | ||
@@ -11,0 +13,0 @@ export declare type DelayString = `${string}${Units}`; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37594
861
2
19