@defer/client
Advanced tools
Comparing version 2.0.0 to 2.1.0-alpha-20240207114445-7b0f26b2cc2cedc3426f5201e82d690a2ee06e5f
@@ -242,6 +242,6 @@ "use strict"; | ||
async function enqueue(func, args, scheduleFor, discardAfter, metadata) { | ||
let functionId = functionIdMapping.get(func.name); | ||
let functionId = functionIdMapping.get(func.__metadata.name); | ||
if (functionId === undefined) { | ||
functionId = (0, utils_js_1.randomUUID)(); | ||
functionIdMapping.set(func.name, functionId); | ||
functionIdMapping.set(func.__metadata.name, functionId); | ||
} | ||
@@ -253,3 +253,3 @@ const now = new Date(); | ||
functionId: functionId, | ||
functionName: func.__fn.name, | ||
functionName: func.__metadata.name, | ||
func, | ||
@@ -256,0 +256,0 @@ args: (0, utils_js_1.stringify)(args), |
@@ -54,2 +54,6 @@ "use strict"; | ||
} | ||
/** | ||
* Check if defer is enqueuing on the Defer cloud | ||
* @returns {boolean} | ||
*/ | ||
const deferEnabled = () => !!(0, utils_js_1.getEnv)("DEFER_TOKEN"); | ||
@@ -141,3 +145,3 @@ exports.deferEnabled = deferEnabled; | ||
* @template F | ||
* @param {DeferableFunction} fn | ||
* @param {F} fn | ||
* @param {DeferredFunctionConfiguration=} config | ||
@@ -163,3 +167,3 @@ * @returns {DeferredFunction<F>} | ||
* @template F | ||
* @param {DeferableFunction} fn | ||
* @param {F} fn | ||
* @param {string} cronExpr | ||
@@ -238,5 +242,5 @@ * @param {DeferredFunctionConfiguration=} config | ||
* @param {string} id | ||
* @returns {Promise<GetExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<GetExecutionResult>} | ||
*/ | ||
@@ -252,3 +256,2 @@ async function getExecution(id) { | ||
* @param {string} id | ||
* @returns {Promise<T>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -258,2 +261,3 @@ * @throws {ExecutionResultNotAvailableYet} when result is not yet available | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<T>} | ||
*/ | ||
@@ -269,3 +273,2 @@ async function getExecutionResult(id) { | ||
* @param {boolean} force | ||
* @returns {Promise<CancelExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -275,2 +278,3 @@ * @throws {ExecutionAbortingAlreadyInProgress} when execution is started | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<CancelExecutionResult>} | ||
*/ | ||
@@ -286,6 +290,6 @@ async function cancelExecution(id, force = false) { | ||
* @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 | ||
* @returns {Promise<RescheduleExecutionResult>} | ||
*/ | ||
@@ -311,5 +315,5 @@ async function rescheduleExecution(id, value) { | ||
* @param {string} id | ||
* @returns {Promise<ReRunExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ReRunExecutionResult>} | ||
*/ | ||
@@ -325,5 +329,5 @@ async function reRunExecution(id) { | ||
* @param {string} id | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
*/ | ||
@@ -337,3 +341,2 @@ async function getExecutionTries(id) { | ||
* List an execution attempts | ||
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts) | ||
* @async | ||
@@ -343,5 +346,5 @@ * @param {string} id | ||
* @param {ExecutionFilters=} filters | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
*/ | ||
@@ -357,4 +360,4 @@ async function listExecutionAttempts(id, page, filters) { | ||
* @param {ExecutionFilters=} filters | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionsResult>} | ||
* @throws {DeferError} when error is unknown | ||
*/ | ||
@@ -370,3 +373,2 @@ async function listExecutions(page, filters) { | ||
* @param {DeferredFunction<F>} fn | ||
* @returns {Promise<Awaited<F>>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -376,2 +378,3 @@ * @throws {ExecutionResultNotAvailableYet} when result is not yet available | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<Awaited<F>>} | ||
*/ | ||
@@ -378,0 +381,0 @@ function awaitResult(fn) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = "2.0.0"; | ||
exports.default = "2.1.0-alpha-20240207114445-7b0f26b2cc2cedc3426f5201e82d690a2ee06e5f"; |
@@ -235,6 +235,6 @@ // Copyright (c) 2023 Defer SAS <hello@defer.run>. | ||
export async function enqueue(func, args, scheduleFor, discardAfter, metadata) { | ||
let functionId = functionIdMapping.get(func.name); | ||
let functionId = functionIdMapping.get(func.__metadata.name); | ||
if (functionId === undefined) { | ||
functionId = randomUUID(); | ||
functionIdMapping.set(func.name, functionId); | ||
functionIdMapping.set(func.__metadata.name, functionId); | ||
} | ||
@@ -246,3 +246,3 @@ const now = new Date(); | ||
functionId: functionId, | ||
functionName: func.__fn.name, | ||
functionName: func.__metadata.name, | ||
func, | ||
@@ -249,0 +249,0 @@ args: stringify(args), |
@@ -28,2 +28,6 @@ // Copyright (c) 2021-2023 Defer SAS <hello@defer.run>. | ||
} | ||
/** | ||
* Check if defer is enqueuing on the Defer cloud | ||
* @returns {boolean} | ||
*/ | ||
export const deferEnabled = () => !!getEnv("DEFER_TOKEN"); | ||
@@ -114,3 +118,3 @@ function defaultRetryPolicy() { | ||
* @template F | ||
* @param {DeferableFunction} fn | ||
* @param {F} fn | ||
* @param {DeferredFunctionConfiguration=} config | ||
@@ -135,3 +139,3 @@ * @returns {DeferredFunction<F>} | ||
* @template F | ||
* @param {DeferableFunction} fn | ||
* @param {F} fn | ||
* @param {string} cronExpr | ||
@@ -206,5 +210,5 @@ * @param {DeferredFunctionConfiguration=} config | ||
* @param {string} id | ||
* @returns {Promise<GetExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<GetExecutionResult>} | ||
*/ | ||
@@ -219,3 +223,2 @@ export async function getExecution(id) { | ||
* @param {string} id | ||
* @returns {Promise<T>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -225,2 +228,3 @@ * @throws {ExecutionResultNotAvailableYet} when result is not yet available | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<T>} | ||
*/ | ||
@@ -235,3 +239,2 @@ export async function getExecutionResult(id) { | ||
* @param {boolean} force | ||
* @returns {Promise<CancelExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -241,2 +244,3 @@ * @throws {ExecutionAbortingAlreadyInProgress} when execution is started | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<CancelExecutionResult>} | ||
*/ | ||
@@ -251,6 +255,6 @@ export async function cancelExecution(id, force = false) { | ||
* @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 | ||
* @returns {Promise<RescheduleExecutionResult>} | ||
*/ | ||
@@ -275,5 +279,5 @@ export async function rescheduleExecution(id, value) { | ||
* @param {string} id | ||
* @returns {Promise<ReRunExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ReRunExecutionResult>} | ||
*/ | ||
@@ -288,5 +292,5 @@ export async function reRunExecution(id) { | ||
* @param {string} id | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
*/ | ||
@@ -299,3 +303,2 @@ export async function getExecutionTries(id) { | ||
* List an execution attempts | ||
* @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts) | ||
* @async | ||
@@ -305,5 +308,5 @@ * @param {string} id | ||
* @param {ExecutionFilters=} filters | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
*/ | ||
@@ -318,4 +321,4 @@ export async function listExecutionAttempts(id, page, filters) { | ||
* @param {ExecutionFilters=} filters | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionsResult>} | ||
* @throws {DeferError} when error is unknown | ||
*/ | ||
@@ -330,3 +333,2 @@ export async function listExecutions(page, filters) { | ||
* @param {DeferredFunction<F>} fn | ||
* @returns {Promise<Awaited<F>>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -336,2 +338,3 @@ * @throws {ExecutionResultNotAvailableYet} when result is not yet available | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<Awaited<F>>} | ||
*/ | ||
@@ -338,0 +341,0 @@ export function awaitResult(fn) { |
@@ -1,1 +0,1 @@ | ||
export default "2.0.0"; | ||
export default "2.1.0-alpha-20240207114445-7b0f26b2cc2cedc3426f5201e82d690a2ee06e5f"; |
{ | ||
"name": "@defer/client", | ||
"version": "2.0.0", | ||
"version": "2.1.0-alpha-20240207114445-7b0f26b2cc2cedc3426f5201e82d690a2ee06e5f", | ||
"description": "Zero infrastructure NodeJS background jobs", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
import { Backend, CancelExecutionResult, EnqueueResult, ExecutionFilters, GetExecutionResult, ListExecutionAttemptsResult, ListExecutionsResult, PageRequest, ReRunExecutionResult, RescheduleExecutionResult } from "./backend.js"; | ||
import { Duration } from "./utils.js"; | ||
export declare let backend: Backend; | ||
/** | ||
* Check if defer is enqueuing on the Defer cloud | ||
* @returns {boolean} | ||
*/ | ||
export declare const deferEnabled: () => boolean; | ||
@@ -46,3 +50,3 @@ export interface ExecutionMetadata { | ||
* @template F | ||
* @param {DeferableFunction} fn | ||
* @param {F} fn | ||
* @param {DeferredFunctionConfiguration=} config | ||
@@ -94,5 +98,5 @@ * @returns {DeferredFunction<F>} | ||
* @param {string} id | ||
* @returns {Promise<GetExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<GetExecutionResult>} | ||
*/ | ||
@@ -105,3 +109,2 @@ export declare function getExecution(id: string): Promise<GetExecutionResult>; | ||
* @param {string} id | ||
* @returns {Promise<T>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -111,2 +114,3 @@ * @throws {ExecutionResultNotAvailableYet} when result is not yet available | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<T>} | ||
*/ | ||
@@ -119,3 +123,2 @@ export declare function getExecutionResult<T = any>(id: string): Promise<T>; | ||
* @param {boolean} force | ||
* @returns {Promise<CancelExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -125,2 +128,3 @@ * @throws {ExecutionAbortingAlreadyInProgress} when execution is started | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<CancelExecutionResult>} | ||
*/ | ||
@@ -133,6 +137,6 @@ export declare function cancelExecution(id: string, force?: boolean): Promise<CancelExecutionResult>; | ||
* @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 | ||
* @returns {Promise<RescheduleExecutionResult>} | ||
*/ | ||
@@ -144,5 +148,5 @@ export declare function rescheduleExecution(id: string, value?: Duration | Date | undefined): Promise<RescheduleExecutionResult>; | ||
* @param {string} id | ||
* @returns {Promise<ReRunExecutionResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ReRunExecutionResult>} | ||
*/ | ||
@@ -155,5 +159,5 @@ export declare function reRunExecution(id: string): Promise<ReRunExecutionResult>; | ||
* @param {string} id | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
*/ | ||
@@ -163,3 +167,2 @@ 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 | ||
@@ -169,5 +172,5 @@ * @param {string} id | ||
* @param {ExecutionFilters=} filters | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionAttemptsResult>} | ||
*/ | ||
@@ -180,4 +183,4 @@ export declare function listExecutionAttempts(id: string, page?: PageRequest, filters?: ExecutionFilters): Promise<ListExecutionAttemptsResult>; | ||
* @param {ExecutionFilters=} filters | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<ListExecutionsResult>} | ||
* @throws {DeferError} when error is unknown | ||
*/ | ||
@@ -190,3 +193,2 @@ export declare function listExecutions(page?: PageRequest, filters?: ExecutionFilters): Promise<ListExecutionsResult>; | ||
* @param {DeferredFunction<F>} fn | ||
* @returns {Promise<Awaited<F>>} | ||
* @throws {ExecutionNotFound} when execution does not exists | ||
@@ -196,3 +198,4 @@ * @throws {ExecutionResultNotAvailableYet} when result is not yet available | ||
* @throws {DeferError} when error is unknown | ||
* @returns {Promise<Awaited<F>>} | ||
*/ | ||
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"; | ||
declare const _default: "2.1.0-alpha-20240207114445-7b0f26b2cc2cedc3426f5201e82d690a2ee06e5f"; | ||
export default _default; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
151664
3254
2