🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

deasyncify

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deasyncify - npm Package Compare versions

Comparing version
0.0.3
to
0.0.4
+3
lib/errors/DeasyncifyError.d.ts
export default class DeasyncifyError extends Error {
constructor(message: string);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DeasyncifyError extends Error {
constructor(message) {
super(`DeasyncifyError: ${message}`);
Object.setPrototypeOf(this, DeasyncifyError.prototype);
}
}
exports.default = DeasyncifyError;
//# sourceMappingURL=DeasyncifyError.js.map
{"version":3,"file":"DeasyncifyError.js","sourceRoot":"","sources":["../../src/errors/DeasyncifyError.ts"],"names":[],"mappings":";;AAAA,MAAqB,eAAgB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;QACrC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AALD,kCAKC"}
export default class DeasyncifyErrorMsgs {
static watch: {
EMPTY_ARGUMENT: string;
INVALID_TYPE: (type: string) => string;
};
static watchMany: {
EMPTY_ARGUMENT: string;
INVALID_TYPE: (type: string) => string;
INVALID_ASYNC_ELEMENT: (type: string, index: number) => string;
};
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DeasyncifyErrorMsgs {
}
exports.default = DeasyncifyErrorMsgs;
DeasyncifyErrorMsgs.watch = {
EMPTY_ARGUMENT: "Expected 1 argument of type Promise<T> | (() => Promise<T>) but received none",
INVALID_TYPE: (type) => `Expect argument of type Promise<T> | () => Promise<T> but instead received type ${type}`,
};
DeasyncifyErrorMsgs.watchMany = {
EMPTY_ARGUMENT: "Expected 1 argument of type (Promise<T> | (() => Promise<T>))[] but received none",
INVALID_TYPE: (type) => `Expect argument of type (Promise<T> | (() => Promise<T>))[] but instead received type ${type}`,
INVALID_ASYNC_ELEMENT: (type, index) => `INVALID ELEMENT of index ${index} in asyncArr param is of type ${type} which does not satisfy type Promise<T> | (() => Promise<T>)`,
};
//# sourceMappingURL=DeasyncifyErrorMessages.js.map
{"version":3,"file":"DeasyncifyErrorMessages.js","sourceRoot":"","sources":["../../src/errors/DeasyncifyErrorMessages.ts"],"names":[],"mappings":";;AAAA,MAAqB,mBAAmB;;AAAxC,sCAgBC;AAfe,yBAAK,GAAG;IACpB,cAAc,EACZ,+EAA+E;IACjF,YAAY,EAAE,CAAC,IAAY,EAAE,EAAE,CAC7B,mFAAmF,IAAI,EAAE;CAC5F,CAAC;AAEY,6BAAS,GAAG;IACxB,cAAc,EACZ,mFAAmF;IACrF,YAAY,EAAE,CAAC,IAAY,EAAE,EAAE,CAC7B,yFAAyF,IAAI,EAAE;IACjG,qBAAqB,EAAE,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE,CACrD,4BAA4B,KAAK,iCAAiC,IAAI,8DAA8D;CACvI,CAAC"}
declare type AsyncFn = <T>() => Promise<T>;
"use strict";
//# sourceMappingURL=types.js.map
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
+1
-1
export default class Deasyncify {
static watch: <T>(asyncObj: Promise<T> | (() => Promise<T>)) => Promise<[T | null, any]>;
static watch: <T>(asyncParam: Promise<T> | (() => Promise<T>)) => Promise<[T | null, any]>;
static watchAll: <J, T extends Awaited<J>, G = T extends () => any ? Awaited<ReturnType<T>> : T>(asyncArr: J[]) => Promise<[G[] | null, any]>;
static watchSettled: <J, T extends Awaited<J>, G = T extends () => any ? Awaited<ReturnType<T>> : T>(asyncArr: J[]) => Promise<[G[], any[]]>;
}

@@ -1,23 +0,24 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
export default class Deasyncify {
Object.defineProperty(exports, "__esModule", { value: true });
const DeasyncifyError_1 = __importDefault(require("./errors/DeasyncifyError"));
const DeasyncifyErrorMessages_1 = __importDefault(require("./errors/DeasyncifyErrorMessages"));
class Deasyncify {
}
exports.default = Deasyncify;
_a = Deasyncify;
Deasyncify.watch = (asyncObj) => __awaiter(void 0, void 0, void 0, function* () {
Deasyncify.watch = async (asyncParam) => {
try {
if (asyncParam == null)
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watch.EMPTY_ARGUMENT);
let result;
if (asyncObj instanceof Function)
result = yield asyncObj();
else if (asyncObj instanceof Promise)
result = yield asyncObj;
if (asyncParam instanceof Function)
result = await asyncParam();
else if (asyncParam instanceof Promise)
result = await asyncParam;
else
throw new Error("AsyncHook error: params is neither a promise or an async function");
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watch.INVALID_TYPE(typeof asyncParam));
return [result, null];

@@ -29,15 +30,24 @@ }

}
});
Deasyncify.watchAll = (asyncArr) => __awaiter(void 0, void 0, void 0, function* () {
};
Deasyncify.watchAll = async (asyncArr) => {
try {
const toBeResolvedPromises = asyncArr.map((asyncObj, idx) => {
if (asyncObj instanceof Function)
return asyncObj();
else if (asyncObj instanceof Promise)
return asyncObj;
else
throw new Error(`AsyncHook Error: asyncArr contains an element which is neither a promise or an async function at index ${idx} `);
});
const result = yield Promise.all(toBeResolvedPromises);
return [result, null];
switch (true) {
case asyncArr == null:
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watchMany.EMPTY_ARGUMENT);
case Array.isArray(asyncArr) === false:
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watchMany.INVALID_TYPE(typeof asyncArr));
default:
const toBeResolvedPromises = asyncArr.map((asyncParam, idx) => {
switch (true) {
case asyncParam instanceof Function:
return asyncParam();
case asyncParam instanceof Promise:
return asyncParam;
default:
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watchMany.INVALID_ASYNC_ELEMENT(typeof asyncParam, idx));
}
});
const result = await Promise.all(toBeResolvedPromises);
return [result, null];
}
}

@@ -47,23 +57,32 @@ catch (err) {

}
});
Deasyncify.watchSettled = (asyncArr) => __awaiter(void 0, void 0, void 0, function* () {
const promisesToBeSettled = asyncArr.map((asyncObj, idx) => {
if (asyncObj instanceof Function)
return asyncObj();
else if (asyncObj instanceof Promise)
return asyncObj;
else
throw new Error(`AsyncHook Error: asyncArr contains an element which is neither a promise or an async function at index ${idx} `);
});
let result = yield Promise.allSettled(promisesToBeSettled);
const allResolved = [];
const allRejected = [];
result.forEach((promise) => {
if (promise.status === "fulfilled")
allResolved.push(promise.value);
else if (promise.status === "rejected")
allRejected.push(promise.reason);
});
return [allResolved, allRejected];
});
};
Deasyncify.watchSettled = async (asyncArr) => {
switch (true) {
case asyncArr == null:
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watchMany.EMPTY_ARGUMENT);
case Array.isArray(asyncArr) === false:
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watchMany.INVALID_TYPE(typeof asyncArr));
default:
const promisesToBeSettled = asyncArr.map((asyncParam, idx) => {
switch (true) {
case asyncParam instanceof Function:
return asyncParam();
case asyncParam instanceof Promise:
return asyncParam;
default:
throw new DeasyncifyError_1.default(DeasyncifyErrorMessages_1.default.watchMany.INVALID_ASYNC_ELEMENT(typeof asyncParam, idx));
}
});
let result = await Promise.allSettled(promisesToBeSettled);
const allResolved = [];
const allRejected = [];
result.forEach((promise) => {
if (promise.status === "fulfilled")
allResolved.push(promise.value);
else if (promise.status === "rejected")
allRejected.push(promise.reason);
});
return [allResolved, allRejected];
}
};
//# sourceMappingURL=index.js.map

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

{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,MAAM,CAAC,OAAO,OAAO,UAAU;;;AACf,gBAAK,GAAG,CACpB,QAAyC,EACf,EAAE;IAC5B,IAAI;QACF,IAAI,MAAS,CAAC;QACd,IAAI,QAAQ,YAAY,QAAQ;YAAE,MAAM,GAAG,MAAM,QAAQ,EAAE,CAAC;aACvD,IAAI,QAAQ,YAAY,OAAO;YAAE,MAAM,GAAG,MAAM,QAAQ,CAAC;;YAE5D,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;QACJ,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;KACvB;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,KAAK,GAAG,GAAG,CAAC;QAChB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KACtB;AACH,CAAC,CAAC,CAAA;AAEY,mBAAQ,GAAG,CAKvB,QAAa,EACe,EAAE;IAC9B,IAAI;QACF,MAAM,oBAAoB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE;YAC1D,IAAI,QAAQ,YAAY,QAAQ;gBAAE,OAAO,QAAQ,EAAE,CAAC;iBAC/C,IAAI,QAAQ,YAAY,OAAO;gBAAE,OAAO,QAAQ,CAAC;;gBAEpD,MAAM,IAAI,KAAK,CACb,0GAA0G,GAAG,GAAG,CACjH,CAAC;QACN,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAM,oBAAoB,CAAC,CAAC;QAC5D,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;KACvB;IAAC,OAAO,GAAQ,EAAE;QACjB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACpB;AACH,CAA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,UAAU;oBACpC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;KACrC;AACH,CAAE,CAAA"}
{
"name": "deasyncify",
"version": "0.0.3",
"version": "0.0.4",
"description": "A powerful library to handle asynchronous programming in javascript",

@@ -5,0 +5,0 @@ "main": "lib/index",

+169
-6
# Deasyncify
A declarative way to a execute asynchronous programing with javascript with first class typescript support.
A declarative way of doing asynchronous programing with Typescript.
# Overview
- [Getting started](#getting-started)
- [Issues](#issues)
- [Installation](#installation)
- [Usage](#usage)
- [Methods](#methods)
- [watch](#watch)
- [watchAll](#watchall)
- [watchSettled](#watchsettled)
# Getting started
Deasyncify is a utility library which builds on top of Typescript's Promise api and simplifies handling promises and async functions. The goal of this library is to help make handling asychronous Typescript code more declarative withoud having to wrap code in a try-catch blockcode (which
makes your code more cleaner) and without losing type definition on the return types of the values of resolved promises or async function trying to write a custom wrapper for yourself (yes we implemented that too). Imagine writing your own custom async wrapper for every single new project (that's pretty much a drag).
```
// (ES6 imports)
import axios from 'axios';
import Deasyncify from 'deasyncify';
const doSomething = async () => {
const [expectedValue, error] = await Deasyncify.watch(axios.get(url))
if(error) throw error
return expectedValue
}
```
# Issues
This library is meant to work on all nodejs enviroments. If any issue or bug is found in whatever enviroment you are on, feel free to report it to [issues](https://github.com/Xavier577/deasyncify/issues) and we'll address it as fast as we can.
# Installation
### Using yarn
```
$ yarn add deasyncify
```
### Using npm
```
$ npm install deasyncify
```
# Usage
Deasyncify is a utility class which currenctly comprises of watch, watchAll and watchSettled methods which we'll look into [below](#methods)
# Methods
## watch
Deasyncify.`watch` is used to handle a single asynchorous function or promise.
> Definitions
- `watch = <T> (asynParam: Promise<T> | (() => Promise<T>)) => Promise<[T | null, any]>`
- Args
- `asyncParam: Promise<T> | (() => Promise<T>)`
- Expected output:
- `expectValue: T | null`
- `error: any`
> usage
`watch` takes in on argument (which could be either a promise or an async function or a function that returns a promise) executes it and returns an array of two values; expectedValue and error. expectedValue being the value return from your asynchronous code (you can name this anything) and error being any errors which running your asynchronous code (you can name this anything as well). error would be undefined if the asyncParam runs successfully but if asyncParam fails, error would be defined an expectedValue would be undefined.
> Example
```
import { Request, Response, Next } from "express";
import prisma from "prisma";
import Deasyncify from "deasyncify";
export const getUser = async (req: Request, res: Response, next: Next) => {
const [user, userFindError] = await Deasyncify.watch(this.prisma.users.findOne({
where: { userId: req.user.id }
}));
if(userFindError) return next(userFindError);
res.json(user);
};
```
## watchAll
Deasyncify.`watchAll` is used to handle a bunch of asynchorous function or promise "concurrently".
> Definitions
- ```
watchAll = <
J,
T extends Awaited<J>,
G = T extends () => any ? Awaited<ReturnType<T>> : T> (asyncArr: J[]) => Promise<[G[] | null, any]>
```
- Args
- `asyncParam: (Promise<T> | (() => Promise<T>))[]`
- Expected output:
- `expectValues: T[] | null`
- `error: any`
> usage
`watchAll` takes in on argument (which could be an array of an asyncParam (a promise or an async function or a function that returns a promise)) executes it and returns an array of two values; expectedValue and error. expectedValues being the value return from your asynchronous code (you can name this anything) and error being any error that occur while running your asynchronous code (you can name this anything as well). if any of the asyncParam in the arr fails, expectedValues would be null and error would be defined. An alternative to this is [watchSettled](#watchsettled) method which doesn't have this behaviour.
> Example
```
import { Request, Response, Next } from "express";
import prisma from "prisma";
import Deasyncify from "deasyncify";
export const getUser = async (userId: string) = (_req: Request, _res: Response, next: Next) => {
const [user, error] = Deasyncify.watch(this.prisma.user.findOne({ where: {userId } }));
if(error) return next(error);
return user;
export const getUserItems = async (req: Request, res: Response, next: Next) => {
const [userItems, userItemsFindError] = await Deasyncify.watchAll([
this.prisma.cars.findOne({where: { ownersId: req.user.id } }),
this.prisma.phones.findOne({ where: { ownersId: req.user.id }}),
this.prisma.pets.findOne({ where: { ownersId: req.user.id }})
]);
if(userFindError) return next(userItemsFindError);
res.json(userItems);
};
```
## watchSettled
Deasyncify.`watchSettled` is used to also handle a bunch of asynchorous function or promise "concurrently".
> Definitions
- ```
watchSettled = <
J,
T extends Awaited<J>,
G = T extends () => any ? Awaited<ReturnType<T>> : T> (asyncArr: J[]) => Promise<[G[], any[]]>
```
- Args
- `asyncParam: (Promise<T> | (() => Promise<T>))[]`
- Expected output:
- `expectValues: T[] | null`
- `errors: any[]`
> usage
`watchAll` takes in on argument (which could be an array of an asyncParam (a promise or an async function or a function that returns a promise)) executes it and returns an array of two values; expectedValue and error. expectedValues being the value return from your asynchronous code (you can name this anything) and error being an arr of errors which running your asynchronous code (you can name this anything as well). unlike `watchAll` which fails if one of the asyncArr elems fail during execution, since watchSettled using Promise.`allSettled` under the hood, expectedValues would contain all the values of the settled asyncParams and errors would contain all errors if any.
> Example
```
import { Request, Response, Next } from "express";
import prisma from "prisma";
import Deasyncify from "deasyncify";
export const getUserItems = async (req: Request, res: Response, next: Next) => {
const [userItems, userItemsFindError] = await Deasyncify.watchSettled([
this.prisma.cars.findOne({where: { ownersId: req.user.id } }),
this.prisma.phones.findOne({ where: { ownersId: req.user.id }}),
this.prisma.pets.findOne({ where: { ownersId: req.user.id }})
]);
if(userItemsFindError.length > 0) return next(userItemsFindError);
res.json(userItems);
};
```