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 1.6.0-alpha-20230629072654-4646cd0 to 1.6.0-alpha-20230629092805-c92bb44

67

cjs/index.js

@@ -81,30 +81,3 @@ "use strict";

}
const defer = (fn, options) => {
const ret = async (...args) => {
if (__verbose)
console.log(`[defer.run][${fn.name}] invoked.`);
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) {
return (0, client_js_1.enqueueExecution)(__httpClient, {
name: fn.name,
arguments: functionArguments,
scheduleFor: new Date(),
metadata: {},
});
}
if (__verbose)
console.log(`[defer.run][${fn.name}] defer ignore, no token found.`);
const id = (0, uuid_1.v4)();
__database.set(id, { id: id, state: "running" });
execLocally(id, fn, functionArguments);
return { id };
};
ret.__fn = fn;
function parseRetryPolicy(options) {
const retryPolicy = defaultRetryPolicy();

@@ -147,6 +120,37 @@ switch (typeof options?.retry) {

}
return retryPolicy;
}
const defer = (fn, options) => {
const ret = async (...args) => {
if (__verbose)
console.log(`[defer.run][${fn.name}] invoked.`);
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) {
return (0, client_js_1.enqueueExecution)(__httpClient, {
name: fn.name,
arguments: functionArguments,
scheduleFor: new Date(),
metadata: {},
});
}
if (__verbose)
console.log(`[defer.run][${fn.name}] defer ignore, no token found.`);
const id = (0, uuid_1.v4)();
__database.set(id, { id: id, state: "running" });
execLocally(id, fn, functionArguments);
return { id };
};
ret.__fn = fn;
ret.__metadata = {
version: constants_js_1.INTERNAL_VERSION,
retry: retryPolicy,
retry: parseRetryPolicy(options),
concurrency: options?.concurrency,
maxDuration: options?.maxDuration,
};

@@ -156,3 +160,3 @@ return ret;

exports.defer = defer;
exports.defer.cron = (fn, schedule) => {
exports.defer.cron = (fn, schedule, options) => {
const ret = () => {

@@ -165,2 +169,5 @@ throw new Error("`defer.cron()` functions should not be invoked.");

cron: schedule,
retry: parseRetryPolicy(options),
concurrency: options?.concurrency,
maxDuration: options?.maxDuration,
};

@@ -167,0 +174,0 @@ return ret;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = "1.6.0-alpha-20230629072654-4646cd0";
exports.default = "1.6.0-alpha-20230629092805-c92bb44";

@@ -72,30 +72,3 @@ import parseDuration from "parse-duration";

}
export const defer = (fn, options) => {
const ret = async (...args) => {
if (__verbose)
console.log(`[defer.run][${fn.name}] invoked.`);
let functionArguments;
try {
functionArguments = JSON.parse(JSON.stringify(args));
}
catch (error) {
const e = error;
throw new DeferError(`cannot serialize argument: ${e.message}`);
}
if (__httpClient) {
return enqueueExecution(__httpClient, {
name: fn.name,
arguments: functionArguments,
scheduleFor: new Date(),
metadata: {},
});
}
if (__verbose)
console.log(`[defer.run][${fn.name}] defer ignore, no token found.`);
const id = randomUUID();
__database.set(id, { id: id, state: "running" });
execLocally(id, fn, functionArguments);
return { id };
};
ret.__fn = fn;
function parseRetryPolicy(options) {
const retryPolicy = defaultRetryPolicy();

@@ -138,10 +111,41 @@ switch (typeof options?.retry) {

}
return retryPolicy;
}
export const defer = (fn, options) => {
const ret = async (...args) => {
if (__verbose)
console.log(`[defer.run][${fn.name}] invoked.`);
let functionArguments;
try {
functionArguments = JSON.parse(JSON.stringify(args));
}
catch (error) {
const e = error;
throw new DeferError(`cannot serialize argument: ${e.message}`);
}
if (__httpClient) {
return enqueueExecution(__httpClient, {
name: fn.name,
arguments: functionArguments,
scheduleFor: new Date(),
metadata: {},
});
}
if (__verbose)
console.log(`[defer.run][${fn.name}] defer ignore, no token found.`);
const id = randomUUID();
__database.set(id, { id: id, state: "running" });
execLocally(id, fn, functionArguments);
return { id };
};
ret.__fn = fn;
ret.__metadata = {
version: INTERNAL_VERSION,
retry: retryPolicy,
retry: parseRetryPolicy(options),
concurrency: options?.concurrency,
maxDuration: options?.maxDuration,
};
return ret;
};
defer.cron = (fn, schedule) => {
defer.cron = (fn, schedule, options) => {
const ret = () => {

@@ -154,2 +158,5 @@ throw new Error("`defer.cron()` functions should not be invoked.");

cron: schedule,
retry: parseRetryPolicy(options),
concurrency: options?.concurrency,
maxDuration: options?.maxDuration,
};

@@ -156,0 +163,0 @@ return ret;

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

export default "1.6.0-alpha-20230629072654-4646cd0";
export default "1.6.0-alpha-20230629092805-c92bb44";
{
"name": "@defer/client",
"version": "1.6.0-alpha-20230629072654-4646cd0",
"version": "1.6.0-alpha-20230629092805-c92bb44",
"description": "Zero infrastructure NodeJS background jobs",

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

@@ -47,3 +47,3 @@ import { Units } from "parse-duration";

<F extends (...args: any | undefined) => Promise<any>>(fn: F, options?: DeferOptions): DeferRetFn<F>;
cron: <F extends (args: never[]) => Promise<any>>(fn: F, schedule: string) => DeferScheduledFn<F>;
cron: <F extends (args: never[]) => Promise<any>>(fn: F, schedule: string, options?: DeferOptions) => DeferScheduledFn<F>;
}

@@ -60,2 +60,3 @@ export interface RetryPolicy {

concurrency?: Concurrency;
maxDuration?: number;
}

@@ -62,0 +63,0 @@ export declare const defer: Defer;

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

declare const _default: "1.6.0-alpha-20230629072654-4646cd0";
declare const _default: "1.6.0-alpha-20230629092805-c92bb44";
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