@defer/client
Advanced tools
Comparing version 1.0.0-alpha-20230226000522-b9231b3 to 1.0.0
@@ -66,47 +66,2 @@ "use strict"; | ||
ret.__metadata = { version: constants_js_1.INTERNAL_VERSION, retry: retryPolicy }; | ||
ret.await = async (...args) => { | ||
let functionArguments; | ||
try { | ||
functionArguments = JSON.parse(JSON.stringify(args)); | ||
} | ||
catch (error) { | ||
const e = error; | ||
throw new errors_js_1.DeferError(`cannot serialize argument: ${e.message}`); | ||
} | ||
if (__httpClient) { | ||
const { id } = await (0, client_js_1.enqueueExecution)(__httpClient, { | ||
name: fn.name, | ||
arguments: functionArguments, | ||
scheduleFor: new Date(), | ||
}); | ||
const response = await (0, client_js_1.waitExecutionResult)(__httpClient, { id: id }); | ||
if (response.state === "failed") { | ||
let error = new Error("Defer execution failed"); | ||
if (response.result?.message) { | ||
error = new Error(response.result.message); | ||
error.stack = response.result.stack; | ||
} | ||
else if (response.result) { | ||
error = response.result; | ||
} | ||
throw error; | ||
} | ||
return response.result; | ||
} | ||
try { | ||
return Promise.resolve(await fn(...functionArguments)); | ||
} | ||
catch (error) { | ||
// const e = error as Error; | ||
let deferError = new Error("Defer execution failed"); | ||
if (error instanceof Error) { | ||
deferError = new Error(error.message); | ||
deferError.stack = error.stack || ""; | ||
} | ||
else { | ||
deferError = error; | ||
} | ||
throw error; | ||
} | ||
}; | ||
return ret; | ||
@@ -191,5 +146,5 @@ }; | ||
if (response.state === "failed") { | ||
let error = new Error("Defer execution failed"); | ||
let error = new errors_js_1.DeferError("Defer execution failed"); | ||
if (response.result?.message) { | ||
error = new Error(response.result.message); | ||
error = new errors_js_1.DeferError(response.result.message); | ||
error.stack = response.result.stack; | ||
@@ -196,0 +151,0 @@ } |
@@ -59,47 +59,2 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
ret.__metadata = { version: INTERNAL_VERSION, retry: retryPolicy }; | ||
ret.await = async (...args) => { | ||
let functionArguments; | ||
try { | ||
functionArguments = JSON.parse(JSON.stringify(args)); | ||
} | ||
catch (error) { | ||
const e = error; | ||
throw new DeferError(`cannot serialize argument: ${e.message}`); | ||
} | ||
if (__httpClient) { | ||
const { id } = await enqueueExecution(__httpClient, { | ||
name: fn.name, | ||
arguments: functionArguments, | ||
scheduleFor: new Date(), | ||
}); | ||
const response = await waitExecutionResult(__httpClient, { id: id }); | ||
if (response.state === "failed") { | ||
let error = new Error("Defer execution failed"); | ||
if (response.result?.message) { | ||
error = new Error(response.result.message); | ||
error.stack = response.result.stack; | ||
} | ||
else if (response.result) { | ||
error = response.result; | ||
} | ||
throw error; | ||
} | ||
return response.result; | ||
} | ||
try { | ||
return Promise.resolve(await fn(...functionArguments)); | ||
} | ||
catch (error) { | ||
// const e = error as Error; | ||
let deferError = new Error("Defer execution failed"); | ||
if (error instanceof Error) { | ||
deferError = new Error(error.message); | ||
deferError.stack = error.stack || ""; | ||
} | ||
else { | ||
deferError = error; | ||
} | ||
throw error; | ||
} | ||
}; | ||
return ret; | ||
@@ -182,5 +137,5 @@ }; | ||
if (response.state === "failed") { | ||
let error = new Error("Defer execution failed"); | ||
let error = new DeferError("Defer execution failed"); | ||
if (response.result?.message) { | ||
error = new Error(response.result.message); | ||
error = new DeferError(response.result.message); | ||
error.stack = response.result.stack; | ||
@@ -187,0 +142,0 @@ } |
{ | ||
"name": "@defer/client", | ||
"version": "1.0.0-alpha-20230226000522-b9231b3", | ||
"version": "1.0.0", | ||
"description": "Zero infrastructure NodeJS background jobs", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -30,4 +30,2 @@ import { Units } from "parse-duration"; | ||
__fn: F; | ||
/** @deprecated use `waitResult(deferFn)` instead */ | ||
await: DeferAwaitRetFn<F>; | ||
} | ||
@@ -34,0 +32,0 @@ export interface DeferScheduledFn<F extends (...args: never) => Promise<any>> extends HasDeferMetadata { |
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
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
1
37476
850