Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ygkit/request

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ygkit/request - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

dist/__tests__/sleep.test.d.ts

2

dist/index.d.ts
export * from './utils/sleep';
export * from './utils/wait-status';
export * from './utils/wait-response';
//# sourceMappingURL=index.d.ts.map

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

import { getProp } from '@ygkit/object';
/*! *****************************************************************************

@@ -63,12 +65,12 @@ Copyright (c) Microsoft Corporation. All rights reserved.

function waitStatus(_a) {
var callback = _a.callback, _b = _a.statusProp, statusProp = _b === void 0 ? 'status' : _b,
function waitResponse(_a) {
var callback = _a.callback, targetProp = _a.targetProp,
// wait status
targetStatus = _a.targetStatus,
targetResponse = _a.targetResponse,
// timeout mini seconds
timeout = _a.timeout, _c = _a.loopGap, loopGap = _c === void 0 ? 1000 : _c,
timeout = _a.timeout, _b = _a.loopGap, loopGap = _b === void 0 ? 1000 : _b,
// start mini seconds
_d = _a.start,
_c = _a.start,
// start mini seconds
start = _d === void 0 ? Date.now() : _d,
start = _c === void 0 ? Date.now() : _c,
// promise resolve

@@ -81,10 +83,10 @@ resolve = _a.resolve,

var _this = this;
return __generator(this, function (_e) {
return __generator(this, function (_d) {
now = Date.now();
return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
var detail, e_1;
var response, prop, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 5, , 6]);
_a.trys.push([0, 7, , 8]);
resolve = resolve || res;

@@ -94,9 +96,14 @@ reject = reject || rej;

if (now - start > timeout) {
reject(new Error('Request Timeout.'));
reject(new Error('Request Timeout'));
}
return [4 /*yield*/, callback()];
case 1:
detail = _a.sent();
if (!(detail && detail[statusProp] === targetStatus)) return [3 /*break*/, 2];
resolve(detail);
response = _a.sent();
if (!targetResponse) return [3 /*break*/, 5];
if (!targetProp) {
reject(new Error('Unknow target response property'));
}
prop = getProp(response, targetProp);
if (!(response && prop === targetResponse)) return [3 /*break*/, 2];
resolve(response);
return [3 /*break*/, 4];

@@ -106,6 +113,6 @@ case 2: return [4 /*yield*/, sleep(loopGap)];

_a.sent();
return [2 /*return*/, waitStatus({
return [2 /*return*/, waitResponse({
callback: callback,
statusProp: statusProp,
targetStatus: targetStatus,
targetProp: targetProp,
targetResponse: targetResponse,
timeout: timeout,

@@ -118,6 +125,23 @@ start: start,

case 5:
if (response === targetResponse) {
resolve(response);
}
else {
return [2 /*return*/, waitResponse({
callback: callback,
targetProp: targetProp,
targetResponse: targetResponse,
timeout: timeout,
start: start,
resolve: resolve,
reject: reject,
})];
}
_a.label = 6;
case 6: return [3 /*break*/, 8];
case 7:
e_1 = _a.sent();
reject && reject(e_1);
return [3 /*break*/, 6];
case 6: return [2 /*return*/];
return [3 /*break*/, 8];
case 8: return [2 /*return*/];
}

@@ -130,3 +154,3 @@ });

export { sleep, waitStatus };
export { sleep, waitResponse };
//# sourceMappingURL=index.esm.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.ygkitRequest = {})));
}(this, (function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ygkit/object')) :
typeof define === 'function' && define.amd ? define(['exports', '@ygkit/object'], factory) :
(factory((global.ygkitRequest = {}),global['@ygkit/object']));
}(this, (function (exports,object) { 'use strict';

@@ -69,12 +69,12 @@ /*! *****************************************************************************

function waitStatus(_a) {
var callback = _a.callback, _b = _a.statusProp, statusProp = _b === void 0 ? 'status' : _b,
function waitResponse(_a) {
var callback = _a.callback, targetProp = _a.targetProp,
// wait status
targetStatus = _a.targetStatus,
targetResponse = _a.targetResponse,
// timeout mini seconds
timeout = _a.timeout, _c = _a.loopGap, loopGap = _c === void 0 ? 1000 : _c,
timeout = _a.timeout, _b = _a.loopGap, loopGap = _b === void 0 ? 1000 : _b,
// start mini seconds
_d = _a.start,
_c = _a.start,
// start mini seconds
start = _d === void 0 ? Date.now() : _d,
start = _c === void 0 ? Date.now() : _c,
// promise resolve

@@ -87,10 +87,10 @@ resolve = _a.resolve,

var _this = this;
return __generator(this, function (_e) {
return __generator(this, function (_d) {
now = Date.now();
return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
var detail, e_1;
var response, prop, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 5, , 6]);
_a.trys.push([0, 7, , 8]);
resolve = resolve || res;

@@ -100,9 +100,14 @@ reject = reject || rej;

if (now - start > timeout) {
reject(new Error('Request Timeout.'));
reject(new Error('Request Timeout'));
}
return [4 /*yield*/, callback()];
case 1:
detail = _a.sent();
if (!(detail && detail[statusProp] === targetStatus)) return [3 /*break*/, 2];
resolve(detail);
response = _a.sent();
if (!targetResponse) return [3 /*break*/, 5];
if (!targetProp) {
reject(new Error('Unknow target response property'));
}
prop = object.getProp(response, targetProp);
if (!(response && prop === targetResponse)) return [3 /*break*/, 2];
resolve(response);
return [3 /*break*/, 4];

@@ -112,6 +117,6 @@ case 2: return [4 /*yield*/, sleep(loopGap)];

_a.sent();
return [2 /*return*/, waitStatus({
return [2 /*return*/, waitResponse({
callback: callback,
statusProp: statusProp,
targetStatus: targetStatus,
targetProp: targetProp,
targetResponse: targetResponse,
timeout: timeout,

@@ -124,6 +129,23 @@ start: start,

case 5:
if (response === targetResponse) {
resolve(response);
}
else {
return [2 /*return*/, waitResponse({
callback: callback,
targetProp: targetProp,
targetResponse: targetResponse,
timeout: timeout,
start: start,
resolve: resolve,
reject: reject,
})];
}
_a.label = 6;
case 6: return [3 /*break*/, 8];
case 7:
e_1 = _a.sent();
reject && reject(e_1);
return [3 /*break*/, 6];
case 6: return [2 /*return*/];
return [3 /*break*/, 8];
case 8: return [2 /*return*/];
}

@@ -137,3 +159,3 @@ });

exports.sleep = sleep;
exports.waitStatus = waitStatus;
exports.waitResponse = waitResponse;

@@ -140,0 +162,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

{
"name": "@ygkit/request",
"version": "0.0.4",
"description": "Node utils",
"version": "0.0.5",
"description": "Node request utils",
"main": "dist/index.js",

@@ -33,3 +33,6 @@ "node": "dist/index.js",

"homepage": "https://github.com/yugasun/ygkit#readme",
"gitHead": "2a623b52fe452b5d2ee3d0187469bf1f4433f746"
"dependencies": {
"@ygkit/object": "0.0.1"
},
"gitHead": "d9cc423693a7723f58f0c69021bc7ba7dbc2b1a6"
}

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

# Request Utils
# @ygkit/request

@@ -6,2 +6,4 @@ [![npm](https://img.shields.io/npm/v/%40ygkit%2Frequest)](http://www.npmtrends.com/%40ygkit%2Frequest)

Node request utils.
## Functions

@@ -8,0 +10,0 @@

export * from './utils/sleep';
export * from './utils/wait-status';
export * from './utils/wait-response';

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