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

@defer/client

Package Overview
Dependencies
Maintainers
2
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@defer/client - npm Package Compare versions

Comparing version 2.0.0-alpha-20240131122545-2f0ef39 to 2.0.0-alpha-20240131131340-13491e1

133

cjs/index.js

@@ -137,2 +137,9 @@ "use strict";

}
/**
* Define a deferred function
* @template F
* @param {DeferableFunction} fn
* @param {DeferredFunctionConfiguration=} config
* @returns {DeferredFunction<F>}
*/
function defer(fn, config) {

@@ -152,2 +159,10 @@ const wrapped = async (...args) => enqueue(wrapped, ...args);

exports.defer = defer;
/**
* Define a defer cron
* @template F
* @param {DeferableFunction} fn
* @param {string} cronExpr
* @param {DeferredFunctionConfiguration=} config
* @returns {DeferredFunction<F>}
*/
defer.cron = function (fn, cronExpr, config) {

@@ -169,6 +184,7 @@ const wrapped = async (...args) => enqueue(wrapped, ...args);

* Delay an execution
* @param fn Duration
* @param delay Duration | Date
* @template F
* @param {DeferredFunction<F>} fn
* @param {Duration | Date} delay
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -181,6 +197,7 @@ function delay(fn, delay) {

* Add metadata to an execution
* @param fn Duration
* @param metadata Object
* @template F
* @param {DeferredFunction<F>} fn
* @param {ExecutionMetadata} metadata
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -193,6 +210,7 @@ function addMetadata(fn, metadata) {

* Discard an execution if not started after a given interval
* @param fn Duration
* @param value Duration | Date
* @template F
* @param {DeferredFunction<F>} fn
* @param {Duration | Date} value
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -203,2 +221,9 @@ function discardAfter(fn, value) {

exports.discardAfter = discardAfter;
/**
* Assign execution options to a deferred function
* @template F
* @param {DeferredFunction<F>} fn
* @param {ExecutionOptions} options
* @returns {DeferredFunction<F>}
*/
function assignOptions(fn, options) {

@@ -212,2 +237,10 @@ const wrapped = async (...args) => enqueue(wrapped, ...args);

exports.assignOptions = assignOptions;
/**
* Get an execution
* @async
* @param {string} id
* @returns {Promise<GetExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
async function getExecution(id) {

@@ -217,2 +250,13 @@ return exports.backend.getExecution(id);

exports.getExecution = getExecution;
/**
* Get an execution result
* @async
* @template T
* @param {string} id
* @returns {Promise<T>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionResultNotAvailableYet} when result is not yet available
* @throws {ExecutionResultNotAvailable} when there's no result
* @throws {DeferError} when error is unknown
*/
async function getExecutionResult(id) {

@@ -222,2 +266,13 @@ return exports.backend.getExecutionResult(id);

exports.getExecutionResult = getExecutionResult;
/**
* Cancel an execution
* @async
* @param {string} id
* @param {boolean} force
* @returns {Promise<CancelExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionAbortingAlreadyInProgress} when execution is started
* @throws {ExecutionNotCancellable} when execution cannot be cancelled
* @throws {DeferError} when error is unknown
*/
async function cancelExecution(id, force = false) {

@@ -227,2 +282,12 @@ return exports.backend.cancelExecution(id, force);

exports.cancelExecution = cancelExecution;
/**
* Reschedule an execution
* @async
* @param {string} id
* @param {Duration | Date | undefined} value
* @returns {Promise<RescheduleExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionNotReschedulable} when execution has started and/or completed.
* @throws {DeferError} when error is unknown
*/
async function rescheduleExecution(id, value) {

@@ -243,2 +308,10 @@ const now = new Date();

exports.rescheduleExecution = rescheduleExecution;
/**
* ReRun an execution
* @async
* @param {string} id
* @returns {Promise<ReRunExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
async function reRunExecution(id) {

@@ -249,9 +322,26 @@ return exports.backend.reRunExecution(id);

/**
* List an execution attempts
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts)
* @async
* @param {string} id
* @returns {Promise<ListExecutionAttemptsResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
async function getExecutionTries(id) {
(0, logger_js_1.warn)(`"getExecutionTries/1" is deprecated and will be removed in future versions. Please use "listExecutionAttempts/2" instead.`);
(0, logger_js_1.warn)(`"getExecutionTries" is deprecated and will be removed in future versions. Please use "listExecutionAttempts" instead.`);
return listExecutionAttempts(id);
}
exports.getExecutionTries = getExecutionTries;
/**
* List an execution attempts
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts)
* @async
* @param {string} id
* @param {PageRequest=} page
* @param {ExecutionFilters=} filters
* @returns {Promise<ListExecutionAttemptsResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
async function listExecutionAttempts(id, page, filters) {

@@ -261,2 +351,10 @@ return exports.backend.listExecutionAttempts(id, page, filters);

exports.listExecutionAttempts = listExecutionAttempts;
/**
* List executions
* @async
* @param {PageRequest=} page
* @param {ExecutionFilters=} filters
* @returns {Promise<ListExecutionsResult>}
* @throws {DeferError} when error is unknown
*/
async function listExecutions(page, filters) {

@@ -266,5 +364,16 @@ return exports.backend.listExecutions(page, filters);

exports.listExecutions = listExecutions;
function awaitResult(func) {
/**
* Enqueue and wait for an execution result
* @async
* @template F
* @param {DeferredFunction<F>} fn
* @returns {Promise<Awaited<F>>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionResultNotAvailableYet} when result is not yet available
* @throws {ExecutionResultNotAvailable} when there's no result
* @throws {DeferError} when error is unknown
*/
function awaitResult(fn) {
return async function (...args) {
const enqueueResponse = await enqueue(func, ...args);
const enqueueResponse = await enqueue(fn, ...args);
await (0, utils_js_1.sleep)(1000);

@@ -271,0 +380,0 @@ let i = 0;

2

cjs/version.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = "2.0.0-alpha-20240131122545-2f0ef39";
exports.default = "2.0.0-alpha-20240131131340-13491e1";

@@ -110,2 +110,9 @@ // Copyright (c) 2021-2023 Defer SAS <hello@defer.run>.

}
/**
* Define a deferred function
* @template F
* @param {DeferableFunction} fn
* @param {DeferredFunctionConfiguration=} config
* @returns {DeferredFunction<F>}
*/
export function defer(fn, config) {

@@ -124,2 +131,10 @@ const wrapped = async (...args) => enqueue(wrapped, ...args);

}
/**
* Define a defer cron
* @template F
* @param {DeferableFunction} fn
* @param {string} cronExpr
* @param {DeferredFunctionConfiguration=} config
* @returns {DeferredFunction<F>}
*/
defer.cron = function (fn, cronExpr, config) {

@@ -141,6 +156,7 @@ const wrapped = async (...args) => enqueue(wrapped, ...args);

* Delay an execution
* @param fn Duration
* @param delay Duration | Date
* @template F
* @param {DeferredFunction<F>} fn
* @param {Duration | Date} delay
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -152,6 +168,7 @@ export function delay(fn, delay) {

* Add metadata to an execution
* @param fn Duration
* @param metadata Object
* @template F
* @param {DeferredFunction<F>} fn
* @param {ExecutionMetadata} metadata
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -163,6 +180,7 @@ export function addMetadata(fn, metadata) {

* Discard an execution if not started after a given interval
* @param fn Duration
* @param value Duration | Date
* @template F
* @param {DeferredFunction<F>} fn
* @param {Duration | Date} value
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -172,2 +190,9 @@ export function discardAfter(fn, value) {

}
/**
* Assign execution options to a deferred function
* @template F
* @param {DeferredFunction<F>} fn
* @param {ExecutionOptions} options
* @returns {DeferredFunction<F>}
*/
export function assignOptions(fn, options) {

@@ -180,11 +205,51 @@ const wrapped = async (...args) => enqueue(wrapped, ...args);

}
/**
* Get an execution
* @async
* @param {string} id
* @returns {Promise<GetExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export async function getExecution(id) {
return backend.getExecution(id);
}
/**
* Get an execution result
* @async
* @template T
* @param {string} id
* @returns {Promise<T>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionResultNotAvailableYet} when result is not yet available
* @throws {ExecutionResultNotAvailable} when there's no result
* @throws {DeferError} when error is unknown
*/
export async function getExecutionResult(id) {
return backend.getExecutionResult(id);
}
/**
* Cancel an execution
* @async
* @param {string} id
* @param {boolean} force
* @returns {Promise<CancelExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionAbortingAlreadyInProgress} when execution is started
* @throws {ExecutionNotCancellable} when execution cannot be cancelled
* @throws {DeferError} when error is unknown
*/
export async function cancelExecution(id, force = false) {
return backend.cancelExecution(id, force);
}
/**
* Reschedule an execution
* @async
* @param {string} id
* @param {Duration | Date | undefined} value
* @returns {Promise<RescheduleExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionNotReschedulable} when execution has started and/or completed.
* @throws {DeferError} when error is unknown
*/
export async function rescheduleExecution(id, value) {

@@ -204,2 +269,10 @@ const now = new Date();

}
/**
* ReRun an execution
* @async
* @param {string} id
* @returns {Promise<ReRunExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export async function reRunExecution(id) {

@@ -209,17 +282,53 @@ return backend.reRunExecution(id);

/**
* List an execution attempts
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts)
* @async
* @param {string} id
* @returns {Promise<ListExecutionAttemptsResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export async function getExecutionTries(id) {
warn(`"getExecutionTries/1" is deprecated and will be removed in future versions. Please use "listExecutionAttempts/2" instead.`);
warn(`"getExecutionTries" is deprecated and will be removed in future versions. Please use "listExecutionAttempts" instead.`);
return listExecutionAttempts(id);
}
/**
* List an execution attempts
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts)
* @async
* @param {string} id
* @param {PageRequest=} page
* @param {ExecutionFilters=} filters
* @returns {Promise<ListExecutionAttemptsResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export async function listExecutionAttempts(id, page, filters) {
return backend.listExecutionAttempts(id, page, filters);
}
/**
* List executions
* @async
* @param {PageRequest=} page
* @param {ExecutionFilters=} filters
* @returns {Promise<ListExecutionsResult>}
* @throws {DeferError} when error is unknown
*/
export async function listExecutions(page, filters) {
return backend.listExecutions(page, filters);
}
export function awaitResult(func) {
/**
* Enqueue and wait for an execution result
* @async
* @template F
* @param {DeferredFunction<F>} fn
* @returns {Promise<Awaited<F>>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionResultNotAvailableYet} when result is not yet available
* @throws {ExecutionResultNotAvailable} when there's no result
* @throws {DeferError} when error is unknown
*/
export function awaitResult(fn) {
return async function (...args) {
const enqueueResponse = await enqueue(func, ...args);
const enqueueResponse = await enqueue(fn, ...args);
await sleep(1000);

@@ -226,0 +335,0 @@ let i = 0;

@@ -1,1 +0,1 @@

export default "2.0.0-alpha-20240131122545-2f0ef39";
export default "2.0.0-alpha-20240131131340-13491e1";
{
"name": "@defer/client",
"version": "2.0.0-alpha-20240131122545-2f0ef39",
"version": "2.0.0-alpha-20240131131340-13491e1",
"description": "Zero infrastructure NodeJS background jobs",

@@ -5,0 +5,0 @@ "dependencies": {

@@ -43,12 +43,20 @@ import { Backend, CancelExecutionResult, EnqueueResult, ExecutionFilters, GetExecutionResult, ListExecutionAttemptsResult, ListExecutionsResult, PageRequest, ReRunExecutionResult, RescheduleExecutionResult } from "./backend.js";

}
/**
* Define a deferred function
* @template F
* @param {DeferableFunction} fn
* @param {DeferredFunctionConfiguration=} config
* @returns {DeferredFunction<F>}
*/
export declare function defer<F extends DeferableFunction>(fn: F, config?: DeferredFunctionConfiguration): DeferredFunction<F>;
export declare namespace defer {
var cron: (fn: DeferableFunction, cronExpr: string, config?: DeferredFunctionConfiguration | undefined) => DeferredFunction<DeferableFunction>;
var cron: <F extends DeferableFunction>(fn: F, cronExpr: string, config?: DeferredFunctionConfiguration | undefined) => DeferredFunction<F>;
}
/**
* Delay an execution
* @param fn Duration
* @param delay Duration | Date
* @template F
* @param {DeferredFunction<F>} fn
* @param {Duration | Date} delay
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -58,6 +66,7 @@ export declare function delay<F extends DeferableFunction>(fn: DeferredFunction<F>, delay: Duration | Date): DeferredFunction<F>;

* Add metadata to an execution
* @param fn Duration
* @param metadata Object
* @template F
* @param {DeferredFunction<F>} fn
* @param {ExecutionMetadata} metadata
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/

@@ -67,20 +76,112 @@ export declare function addMetadata<F extends DeferableFunction>(fn: DeferredFunction<F>, metadata: ExecutionMetadata): DeferredFunction<F>;

* Discard an execution if not started after a given interval
* @param fn Duration
* @param value Duration | Date
* @template F
* @param {DeferredFunction<F>} fn
* @param {Duration | Date} value
* @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options)
* @returns
* @returns {DeferredFunction<F>}
*/
export declare function discardAfter<F extends DeferableFunction>(fn: DeferredFunction<F>, value: Duration | Date): DeferredFunction<F>;
/**
* Assign execution options to a deferred function
* @template F
* @param {DeferredFunction<F>} fn
* @param {ExecutionOptions} options
* @returns {DeferredFunction<F>}
*/
export declare function assignOptions<F extends DeferableFunction>(fn: DeferredFunction<F>, options: ExecutionOptions): DeferredFunction<F>;
/**
* Get an execution
* @async
* @param {string} id
* @returns {Promise<GetExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export declare function getExecution(id: string): Promise<GetExecutionResult>;
/**
* Get an execution result
* @async
* @template T
* @param {string} id
* @returns {Promise<T>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionResultNotAvailableYet} when result is not yet available
* @throws {ExecutionResultNotAvailable} when there's no result
* @throws {DeferError} when error is unknown
*/
export declare function getExecutionResult<T = any>(id: string): Promise<T>;
/**
* Cancel an execution
* @async
* @param {string} id
* @param {boolean} force
* @returns {Promise<CancelExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionAbortingAlreadyInProgress} when execution is started
* @throws {ExecutionNotCancellable} when execution cannot be cancelled
* @throws {DeferError} when error is unknown
*/
export declare function cancelExecution(id: string, force?: boolean): Promise<CancelExecutionResult>;
/**
* Reschedule an execution
* @async
* @param {string} id
* @param {Duration | Date | undefined} value
* @returns {Promise<RescheduleExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionNotReschedulable} when execution has started and/or completed.
* @throws {DeferError} when error is unknown
*/
export declare function rescheduleExecution(id: string, value?: Duration | Date | undefined): Promise<RescheduleExecutionResult>;
/**
* ReRun an execution
* @async
* @param {string} id
* @returns {Promise<ReRunExecutionResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export declare function reRunExecution(id: string): Promise<ReRunExecutionResult>;
/**
* List an execution attempts
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts)
* @async
* @param {string} id
* @returns {Promise<ListExecutionAttemptsResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export declare function getExecutionTries(id: string): Promise<ListExecutionAttemptsResult>;
/**
* List an execution attempts
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts)
* @async
* @param {string} id
* @param {PageRequest=} page
* @param {ExecutionFilters=} filters
* @returns {Promise<ListExecutionAttemptsResult>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {DeferError} when error is unknown
*/
export declare function listExecutionAttempts(id: string, page?: PageRequest, filters?: ExecutionFilters): Promise<ListExecutionAttemptsResult>;
/**
* List executions
* @async
* @param {PageRequest=} page
* @param {ExecutionFilters=} filters
* @returns {Promise<ListExecutionsResult>}
* @throws {DeferError} when error is unknown
*/
export declare function listExecutions(page?: PageRequest, filters?: ExecutionFilters): Promise<ListExecutionsResult>;
export declare function awaitResult<F extends DeferableFunction>(func: DeferredFunction<F>): (...args: Parameters<F>) => Promise<Awaited<F>>;
/**
* Enqueue and wait for an execution result
* @async
* @template F
* @param {DeferredFunction<F>} fn
* @returns {Promise<Awaited<F>>}
* @throws {ExecutionNotFound} when execution does not exists
* @throws {ExecutionResultNotAvailableYet} when result is not yet available
* @throws {ExecutionResultNotAvailable} when there's no result
* @throws {DeferError} when error is unknown
*/
export declare function awaitResult<F extends DeferableFunction>(fn: DeferredFunction<F>): (...args: Parameters<F>) => Promise<Awaited<F>>;

@@ -1,2 +0,2 @@

declare const _default: "2.0.0-alpha-20240131122545-2f0ef39";
declare const _default: "2.0.0-alpha-20240131131340-13491e1";
export default _default;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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