New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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-20230627172525-6f08bfa to 1.6.0-alpha-20230628182657-a7b1727

2

cjs/constants.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RETRY_MAX_ATTEMPTS_PLACEHOLDER = exports.INTERNAL_VERSION = void 0;
exports.INTERNAL_VERSION = 4;
exports.INTERNAL_VERSION = 5;
exports.RETRY_MAX_ATTEMPTS_PLACEHOLDER = 13;

@@ -8,3 +8,3 @@ "use strict";

const fetch_1 = require("@whatwg-node/fetch");
const url_1 = require("url");
const node_url_1 = require("node:url");
const errors_js_1 = require("./errors.js");

@@ -20,3 +20,3 @@ const version_js_1 = __importDefault(require("./version.js"));

try {
endpoint = new url_1.URL(path, apiEndpoint);
endpoint = new node_url_1.URL(path, apiEndpoint);
}

@@ -23,0 +23,0 @@ catch (error) {

@@ -6,5 +6,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.awaitResult = exports.addMetadata = exports.delay = exports.defer = exports.deferEnabled = exports.configure = exports.__httpClient = exports.__database = exports.useDeferRoute = exports.asNextRoute = void 0;
exports.awaitResult = exports.addMetadata = exports.delay = exports.defer = exports.getExecution = exports.deferEnabled = exports.configure = void 0;
const parse_duration_1 = __importDefault(require("parse-duration"));
const uuid_1 = require("uuid");
const parse_duration_1 = __importDefault(require("parse-duration"));
const constants_js_1 = require("./constants.js");

@@ -14,13 +14,10 @@ const client_js_1 = require("./client.js");

const httpClient_js_1 = require("./httpClient.js");
var asNextRoute_1 = require("./next/asNextRoute");
Object.defineProperty(exports, "asNextRoute", { enumerable: true, get: function () { return asNextRoute_1.asNextRoute; } });
var useDeferRoute_1 = require("./next/useDeferRoute");
Object.defineProperty(exports, "useDeferRoute", { enumerable: true, get: function () { return useDeferRoute_1.useDeferRoute; } });
const withDelay = (dt, delay) => new Date(dt.getTime() + (0, parse_duration_1.default)(delay));
exports.__database = new Map();
const __database = new Map();
let __accessToken = process.env["DEFER_TOKEN"];
let __endpoint = process.env["DEFER_ENDPOINT"] || "https://api.defer.run";
let __verbose = false;
let __httpClient;
if (__accessToken)
exports.__httpClient = (0, httpClient_js_1.makeHTTPClient)(__endpoint, __accessToken);
__httpClient = (0, httpClient_js_1.makeHTTPClient)(__endpoint, __accessToken);
function configure(opts = {}) {

@@ -34,3 +31,3 @@ if (opts.accessToken)

if (__accessToken)
exports.__httpClient = (0, httpClient_js_1.makeHTTPClient)(__endpoint, __accessToken);
__httpClient = (0, httpClient_js_1.makeHTTPClient)(__endpoint, __accessToken);
return;

@@ -66,5 +63,14 @@ }

const response = { id, state, result };
exports.__database.set(id, response);
__database.set(id, response);
return response;
}
async function getExecution(id) {
if (__httpClient)
return (0, client_js_1.fetchExecution)(__httpClient, { id });
const response = __database.get(id);
if (response)
return Promise.resolve(response);
throw new errors_js_1.APIError("execution not found", "");
}
exports.getExecution = getExecution;
function defaultRetryPolicy() {

@@ -91,4 +97,4 @@ return {

}
if (exports.__httpClient) {
return (0, client_js_1.enqueueExecution)(exports.__httpClient, {
if (__httpClient) {
return (0, client_js_1.enqueueExecution)(__httpClient, {
name: fn.name,

@@ -103,3 +109,3 @@ arguments: functionArguments,

const id = (0, uuid_1.v4)();
exports.__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "running" });
execLocally(id, fn, functionArguments);

@@ -185,3 +191,3 @@ return { id };

console.log(`[defer.run][${fn.name}] invoked.`);
if (exports.__httpClient) {
if (__httpClient) {
let scheduleFor;

@@ -195,3 +201,3 @@ if (delay instanceof Date) {

}
return (0, client_js_1.enqueueExecution)(exports.__httpClient, {
return (0, client_js_1.enqueueExecution)(__httpClient, {
name: fn.name,

@@ -206,3 +212,3 @@ arguments: functionArguments,

const id = (0, uuid_1.v4)();
exports.__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "running" });
execLocally(id, fn, functionArguments);

@@ -241,3 +247,3 @@ return { id };

console.log(`[defer.run][${fn.name}] invoked.`);
if (exports.__httpClient) {
if (__httpClient) {
let scheduleFor;

@@ -255,3 +261,3 @@ const delay = deferFn.__execOptions?.delay;

}
return (0, client_js_1.enqueueExecution)(exports.__httpClient, {
return (0, client_js_1.enqueueExecution)(__httpClient, {
name: fn.name,

@@ -266,3 +272,3 @@ arguments: functionArguments,

const id = (0, uuid_1.v4)();
exports.__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "running" });
execLocally(id, fn, functionArguments);

@@ -298,4 +304,4 @@ return { id };

let response;
if (exports.__httpClient) {
const { id } = await (0, client_js_1.enqueueExecution)(exports.__httpClient, {
if (__httpClient) {
const { id } = await (0, client_js_1.enqueueExecution)(__httpClient, {
name: fnName,

@@ -306,7 +312,7 @@ arguments: functionArguments,

});
response = await (0, client_js_1.waitExecutionResult)(exports.__httpClient, { id: id });
response = await (0, client_js_1.waitExecutionResult)(__httpClient, { id: id });
}
else {
const id = (0, uuid_1.v4)();
exports.__database.set(id, { id: id, state: "running" });
__database.set(id, { id: id, state: "running" });
response = await execLocally(id, fn, functionArguments);

@@ -313,0 +319,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = "1.6.0-alpha-20230627172525-6f08bfa";
exports.default = "1.6.0-alpha-20230628182657-a7b1727";

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

export const INTERNAL_VERSION = 4;
export const INTERNAL_VERSION = 5;
export const RETRY_MAX_ATTEMPTS_PLACEHOLDER = 13;
import { fetch } from "@whatwg-node/fetch";
import { URL } from "url";
import { URL } from "node:url";
import { APIError, ClientError, HTTPRequestError, errorMessage, } from "./errors.js";

@@ -4,0 +4,0 @@ import VERSION from "./version.js";

@@ -0,15 +1,13 @@

import parseDuration from "parse-duration";
import { v4 as randomUUID } from "uuid";
import parseDuration from "parse-duration";
import { INTERNAL_VERSION, RETRY_MAX_ATTEMPTS_PLACEHOLDER, } from "./constants.js";
import { enqueueExecution, waitExecutionResult, } from "./client.js";
import { DeferError } from "./errors.js";
import { enqueueExecution, fetchExecution, waitExecutionResult, } from "./client.js";
import { APIError, DeferError } from "./errors.js";
import { makeHTTPClient } from "./httpClient.js";
export { asNextRoute } from "./next/asNextRoute";
export { useDeferRoute } from "./next/useDeferRoute";
const withDelay = (dt, delay) => new Date(dt.getTime() + parseDuration(delay));
export const __database = new Map();
const __database = new Map();
let __accessToken = process.env["DEFER_TOKEN"];
let __endpoint = process.env["DEFER_ENDPOINT"] || "https://api.defer.run";
let __verbose = false;
export let __httpClient;
let __httpClient;
if (__accessToken)

@@ -57,2 +55,10 @@ __httpClient = makeHTTPClient(__endpoint, __accessToken);

}
export async function getExecution(id) {
if (__httpClient)
return fetchExecution(__httpClient, { id });
const response = __database.get(id);
if (response)
return Promise.resolve(response);
throw new APIError("execution not found", "");
}
function defaultRetryPolicy() {

@@ -59,0 +65,0 @@ return {

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

export default "1.6.0-alpha-20230627172525-6f08bfa";
export default "1.6.0-alpha-20230628182657-a7b1727";
{
"name": "@defer/client",
"version": "1.6.0-alpha-20230627172525-6f08bfa",
"version": "1.6.0-alpha-20230628182657-a7b1727",
"description": "Zero infrastructure NodeJS background jobs",
"peerDependencies": {
"next": "^13.4.7",
"react": "^18.2.0"
},
"dependencies": {
"@whatwg-node/fetch": "^0.9.7",
"@whatwg-node/fetch": "^0.2.9",
"parse-duration": "^1.0.2",

@@ -17,5 +13,2 @@ "uuid": "^9.0.0"

"license": "ISC",
"engines": {
"node": ">16.0.0"
},
"main": "cjs/index.js",

@@ -22,0 +15,0 @@ "module": "esm/index.js",

@@ -15,12 +15,12 @@ import type { HTTPClient } from "./httpClient.js";

}
export type ExecutionState = "running" | "created" | "failed" | "succeed" | "started";
export interface FetchExecutionResponse<R = any> {
export declare type ExecutionState = "running" | "created" | "failed" | "succeed";
export interface FetchExecutionResponse {
id: string;
state: ExecutionState;
result?: R;
result?: any;
}
export type PoolExecutionRequest = FetchExecutionRequest;
export type PoolExecutionResponse = FetchExecutionResponse;
export declare type PoolExecutionRequest = FetchExecutionRequest;
export declare type PoolExecutionResponse = FetchExecutionResponse;
export declare function enqueueExecution(client: HTTPClient, request: EnqueueExecutionRequest): Promise<EnqueueExecutionResponse>;
export declare function fetchExecution(client: HTTPClient, request: FetchExecutionRequest): Promise<FetchExecutionResponse>;
export declare function waitExecutionResult(client: HTTPClient, request: PoolExecutionRequest): Promise<PoolExecutionResponse>;

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

export declare const INTERNAL_VERSION = 4;
export declare const INTERNAL_VERSION = 5;
export declare const RETRY_MAX_ATTEMPTS_PLACEHOLDER = 13;

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

export type HTTPClient = ReturnType<typeof makeHTTPClient>;
export declare type HTTPClient = ReturnType<typeof makeHTTPClient>;
export declare function makeHTTPClient(apiEndpoint: string, accessToken: string, clientOptions?: RequestInit): <T>(method: string, path: string, body?: string | null) => Promise<T>;
import { Units } from "parse-duration";
import { EnqueueExecutionResponse, ExecutionState } from "./client.js";
import { HTTPClient } from "./httpClient.js";
export { DeferNextRoute, asNextRoute } from "./next/asNextRoute";
export { UseDeferRoute, useDeferRoute } from "./next/useDeferRoute";
import { EnqueueExecutionResponse, FetchExecutionResponse } from "./client.js";
interface Options {

@@ -11,12 +8,7 @@ accessToken?: string;

}
export declare const __database: Map<string, {
id: string;
state: ExecutionState;
result?: any;
}>;
export declare let __httpClient: HTTPClient | undefined;
export declare function configure(opts?: Options): void;
export declare const deferEnabled: () => boolean;
export type UnPromise<F> = F extends Promise<infer R> ? R : F;
export type DelayString = `${string}${Units}`;
export declare function getExecution(id: string): Promise<FetchExecutionResponse>;
export declare type UnPromise<F> = F extends Promise<infer R> ? R : F;
export declare type DelayString = `${string}${Units}`;
export interface Metadata {

@@ -29,7 +21,6 @@ [key: string]: string;

}
export type DeferRetFnParameters<F extends (...args: any | undefined) => Promise<any>> = [...first: Parameters<F>, options: DeferExecutionOptions];
type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
type Range<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
export type Concurrency = Range<0, 51>;
export type NextRouteString = `/api/${string}`;
export declare type DeferRetFnParameters<F extends (...args: any | undefined) => Promise<any>> = [...first: Parameters<F>, options: DeferExecutionOptions];
declare type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
declare type Range<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
export declare type Concurrency = Range<0, 51>;
export interface HasDeferMetadata {

@@ -41,2 +32,3 @@ __metadata: {

concurrency?: Concurrency | undefined;
maxDuration?: number | undefined;
};

@@ -104,1 +96,2 @@ }

export declare const awaitResult: DeferAwaitResult;
export {};

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

declare const _default: "1.6.0-alpha-20230627172525-6f08bfa";
declare const _default: "1.6.0-alpha-20230628182657-a7b1727";
export default _default;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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