New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@effection/fetch

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effection/fetch - npm Package Compare versions

Comparing version 2.0.0-side-effects.1628189696867 to 2.0.0-v2-writable-unification.1633595877341

64

CHANGELOG.md
# @effection/fetch
## \[2.0.0-beta.19]
- Fix a bug when using blockParent where the children are not getting halt on an explicit halt.
- Bumped due to a bump in @effection/core.
- [1cd9803](https://github.com/thefrontside/effection/commit/1cd98033d2641989114f9589c7d887954fa66781) Fix halting children for blockParent tasks on 2021-09-30
## \[2.0.0-beta.18]
- - [0248d79](https://github.com/thefrontside/effection/commit/0248d79a33dcfc4200b0832aba975c9cad08981e) Add package readmes on 2021-09-28
## \[2.0.0-beta.17]
- Adjust the propagation of errors for resources to make it possible to catch errors from `init`
- Bumped due to a bump in @effection/core.
- [75a7248](https://github.com/thefrontside/effection/commit/75a7248ae13d1126bbcaf9b6223f348168e987d0) Catch errors thrown during resource init on 2021-09-21
- Enable support for resources in higher order operations `all`, `race` and `withTimeout`.
- Bumped due to a bump in @effection/core.
- [bbe6cdc](https://github.com/thefrontside/effection/commit/bbe6cdc44184a7669278d0d01ad23a2a79a69e52) Enable resource support for higher order operations on 2021-09-09
## \[2.0.0-beta.16]
- Add shortcuts to create resolved/rejected/halted futures via Future.resolve(123), etc...
- Bumped due to a bump in @effection/core.
- [9599dde](https://github.com/thefrontside/effection/commit/9599dde14e9bc3ba4ac7ea473e8624164727be0c) Add shortcuts for resolves/rejected/halted future on 2021-09-08
## \[2.0.0-beta.15]
- Fix dependency versions
- [5054ac0](https://github.com/thefrontside/effection/commit/5054ac0f10970bb5654e05545375c5349f18d43a) Add changeset on 2021-09-07
## \[2.0.0-beta.14]
- Add labels for fetch operations
- [4e6f2b7](https://github.com/thefrontside/effection/commit/4e6f2b758ea131654c531860cf2583dfd558c5b8) Add labels to fetch package on 2021-09-06
## \[2.0.0-beta.13]
- Change named import from a package.json file to default
- Bumped due to a bump in @effection/core.
- [65a856a](https://github.com/thefrontside/effection/commit/65a856a8d498205c27de00432fd43bc11bbb0e37) Change named import from a package.json file to default. ([#490](https://github.com/thefrontside/effection/pull/490)) on 2021-08-25
## \[2.0.0-beta.12]
- Update core dependency
- Bumped due to a bump in @effection/mocha.
- [d92eee5](https://github.com/thefrontside/effection/commit/d92eee594fdb8dc6d8ab6a37b6aa362122e63f6e) Update core dependency on 2021-08-16
## \[2.0.0-beta.11]
- Use Object.create to wrap error objects rather than copying properties
- Bumped due to a bump in @effection/core.
- [a56ae2a](https://github.com/thefrontside/effection/commit/a56ae2af8a6247697b8b6253bd35b6d9e569613d) Use Object.create to create error object with trace on 2021-08-16
## \[2.0.0-beta.10]
- add `Task#spawn` operation to spawn new task with a specific scope
- Bumped due to a bump in @effection/core.
- [a71d65b](https://github.com/thefrontside/effection/commit/a71d65b77df5c337a78b7934edd181080eacf5bf) Add changefile on 2021-07-27
## \[2.0.0-beta.9]
- Add sideEffects field to package.json
- [383141d](https://github.com/thefrontside/effection/commit/383141dc556c6a781d98087f3b68085d5eb31173) Add sideEffects field to package.json ([#470](https://github.com/thefrontside/effection/pull/470)) on 2021-08-05
## \[2.0.0-beta.8]

@@ -4,0 +68,0 @@

import { Operation, Resource } from '@effection/core';
/**
* A resource that can be used to create an HTTP request. This is the return
* value of [[fetch]]. It also contains helper methods for performing common
* requests.
*/
export interface Fetch extends Resource<Response> {
/**
* An operation that executes the request and produces an
* [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
* representation of the response body.
*/
arrayBuffer(): Operation<ArrayBuffer>;
/**
* An operation that executes the request and produces a
* [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
* representation of the response body.
*/
blob(): Operation<Blob>;
/**
* An operation that executes the request and produces a
* [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
* representation of the response body.
*/
formData(): Operation<FormData>;
/**
* An operation that executes the request and produces the response body
* parsed as JSON.
*/
json(): Operation<unknown>;
/**
* An operation that executes the request and produces the raw text of the
* response body
*/
text(): Operation<string>;
}
/**
* Retrieve network content with a superset of the
* [W3C fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
* that can be used as a drop-in, effection-enabled replacement:
*
* ```ts
* let response = yield fetch('https://example.com/movies.json');
* if (!response.ok) {
* throw new Error(`unable to fetch movies: ${response.status}`);
* }
* let json = yield response.json();
* ```
*
* The [[Fetch]] resource also has shortcut methods that return data operations
* allowing you to handle the entire request cycle in a single line. For
* example, the following will execute a request, read it fully, and parse it
* as JSON. An exception is raised if the response is not in the 200 range.
*
* ```ts
* let json = yield fetch('https://example.com/movies.json').json();
*```
*
* Like most operations in Effection, [[fetch]] is stateless, and does not
* actually _do_ anything unless it is yielded to:
*
* ```ts
* // nothing happens here except describing the requests
* let movies = fetch('https://example.com/movies.json');
* let getJSON = movies.json();
* let getText = movies.text();
*
* // Actually run operations. This will create three separate HTTP requests
* let response = yield movies;
* let json = yield getJSON;
* let text = yield getText;
*```
*
* In all cases the underlying HTTP request will be canceled gracefully if
* the current task goes away.
*
* @param info same as the first argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @param requestInit same as the (optional) second argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @returns a resource binding to a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* object
*/
export declare function fetch(info: RequestInfo, requestInit?: RequestInit): Fetch;
//# sourceMappingURL=fetch.d.ts.map

78

dist-cjs/fetch.js

@@ -7,13 +7,51 @@ "use strict";

const abort_controller_1 = require("abort-controller");
/**
* Retrieve network content with a superset of the
* [W3C fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
* that can be used as a drop-in, effection-enabled replacement:
*
* ```ts
* let response = yield fetch('https://example.com/movies.json');
* if (!response.ok) {
* throw new Error(`unable to fetch movies: ${response.status}`);
* }
* let json = yield response.json();
* ```
*
* The [[Fetch]] resource also has shortcut methods that return data operations
* allowing you to handle the entire request cycle in a single line. For
* example, the following will execute a request, read it fully, and parse it
* as JSON. An exception is raised if the response is not in the 200 range.
*
* ```ts
* let json = yield fetch('https://example.com/movies.json').json();
*```
*
* Like most operations in Effection, [[fetch]] is stateless, and does not
* actually _do_ anything unless it is yielded to:
*
* ```ts
* // nothing happens here except describing the requests
* let movies = fetch('https://example.com/movies.json');
* let getJSON = movies.json();
* let getText = movies.text();
*
* // Actually run operations. This will create three separate HTTP requests
* let response = yield movies;
* let json = yield getJSON;
* let text = yield getText;
*```
*
* In all cases the underlying HTTP request will be canceled gracefully if
* the current task goes away.
*
* @param info same as the first argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @param requestInit same as the (optional) second argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @returns a resource binding to a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* object
*/
function fetch(info, requestInit = {}) {
function* init() {
let controller = new abort_controller_1.AbortController();
yield core_1.spawn(function* () {
try {
yield;
}
finally {
controller.abort();
}
});
yield core_1.ensure(() => { controller.abort(); });
requestInit.signal = controller.signal;

@@ -23,24 +61,28 @@ let response = yield cross_fetch_1.fetch(info, requestInit);

}
let name = `fetch('${info}')`;
let labels = { expand: false, method: requestInit.method || 'GET' };
return {
name,
labels,
init,
*arrayBuffer() {
arrayBuffer: () => core_1.withLabels(function* () {
let response = yield { init };
return yield response.arrayBuffer();
},
*blob() {
}, { name: `${name}.arrayBuffer()`, ...labels }),
blob: () => core_1.withLabels(function* () {
let response = yield { init };
return yield response.blob();
},
*formData() {
}, { name: `${name}.blob()`, ...labels }),
formData: () => core_1.withLabels(function* () {
let response = yield { init };
return yield response.formData();
},
*json() {
}, { name: `${name}.formData()`, ...labels }),
json: () => core_1.withLabels(function* () {
let response = yield { init };
return yield response.json();
},
*text() {
}, { name: `${name}.json()`, ...labels }),
text: () => core_1.withLabels(function* () {
let response = yield { init };
return yield response.text();
},
}, { name: `${name}.text()`, ...labels }),
};

@@ -47,0 +89,0 @@ }

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

export { AbortController } from 'abort-controller';
export { fetch } from './fetch';
export * from './fetch';
//# sourceMappingURL=index.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetch = exports.AbortController = void 0;
var abort_controller_1 = require("abort-controller");
Object.defineProperty(exports, "AbortController", { enumerable: true, get: function () { return abort_controller_1.AbortController; } });
var fetch_1 = require("./fetch");
Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
__exportStar(require("./fetch"), exports);
//# sourceMappingURL=index.js.map
import { Operation, Resource } from '@effection/core';
/**
* A resource that can be used to create an HTTP request. This is the return
* value of [[fetch]]. It also contains helper methods for performing common
* requests.
*/
export interface Fetch extends Resource<Response> {
/**
* An operation that executes the request and produces an
* [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
* representation of the response body.
*/
arrayBuffer(): Operation<ArrayBuffer>;
/**
* An operation that executes the request and produces a
* [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
* representation of the response body.
*/
blob(): Operation<Blob>;
/**
* An operation that executes the request and produces a
* [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
* representation of the response body.
*/
formData(): Operation<FormData>;
/**
* An operation that executes the request and produces the response body
* parsed as JSON.
*/
json(): Operation<unknown>;
/**
* An operation that executes the request and produces the raw text of the
* response body
*/
text(): Operation<string>;
}
/**
* Retrieve network content with a superset of the
* [W3C fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
* that can be used as a drop-in, effection-enabled replacement:
*
* ```ts
* let response = yield fetch('https://example.com/movies.json');
* if (!response.ok) {
* throw new Error(`unable to fetch movies: ${response.status}`);
* }
* let json = yield response.json();
* ```
*
* The [[Fetch]] resource also has shortcut methods that return data operations
* allowing you to handle the entire request cycle in a single line. For
* example, the following will execute a request, read it fully, and parse it
* as JSON. An exception is raised if the response is not in the 200 range.
*
* ```ts
* let json = yield fetch('https://example.com/movies.json').json();
*```
*
* Like most operations in Effection, [[fetch]] is stateless, and does not
* actually _do_ anything unless it is yielded to:
*
* ```ts
* // nothing happens here except describing the requests
* let movies = fetch('https://example.com/movies.json');
* let getJSON = movies.json();
* let getText = movies.text();
*
* // Actually run operations. This will create three separate HTTP requests
* let response = yield movies;
* let json = yield getJSON;
* let text = yield getText;
*```
*
* In all cases the underlying HTTP request will be canceled gracefully if
* the current task goes away.
*
* @param info same as the first argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @param requestInit same as the (optional) second argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @returns a resource binding to a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* object
*/
export declare function fetch(info: RequestInfo, requestInit?: RequestInit): Fetch;
//# sourceMappingURL=fetch.d.ts.map

@@ -1,15 +0,53 @@

import { spawn } from '@effection/core';
import { ensure, withLabels } from '@effection/core';
import { fetch as nativeFetch } from 'cross-fetch';
import { AbortController } from 'abort-controller';
/**
* Retrieve network content with a superset of the
* [W3C fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
* that can be used as a drop-in, effection-enabled replacement:
*
* ```ts
* let response = yield fetch('https://example.com/movies.json');
* if (!response.ok) {
* throw new Error(`unable to fetch movies: ${response.status}`);
* }
* let json = yield response.json();
* ```
*
* The [[Fetch]] resource also has shortcut methods that return data operations
* allowing you to handle the entire request cycle in a single line. For
* example, the following will execute a request, read it fully, and parse it
* as JSON. An exception is raised if the response is not in the 200 range.
*
* ```ts
* let json = yield fetch('https://example.com/movies.json').json();
*```
*
* Like most operations in Effection, [[fetch]] is stateless, and does not
* actually _do_ anything unless it is yielded to:
*
* ```ts
* // nothing happens here except describing the requests
* let movies = fetch('https://example.com/movies.json');
* let getJSON = movies.json();
* let getText = movies.text();
*
* // Actually run operations. This will create three separate HTTP requests
* let response = yield movies;
* let json = yield getJSON;
* let text = yield getText;
*```
*
* In all cases the underlying HTTP request will be canceled gracefully if
* the current task goes away.
*
* @param info same as the first argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @param requestInit same as the (optional) second argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @returns a resource binding to a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* object
*/
export function fetch(info, requestInit = {}) {
function* init() {
let controller = new AbortController();
yield spawn(function* () {
try {
yield;
}
finally {
controller.abort();
}
});
yield ensure(() => { controller.abort(); });
requestInit.signal = controller.signal;

@@ -19,26 +57,30 @@ let response = yield nativeFetch(info, requestInit);

}
let name = `fetch('${info}')`;
let labels = { expand: false, method: requestInit.method || 'GET' };
return {
name,
labels,
init,
*arrayBuffer() {
arrayBuffer: () => withLabels(function* () {
let response = yield { init };
return yield response.arrayBuffer();
},
*blob() {
}, { name: `${name}.arrayBuffer()`, ...labels }),
blob: () => withLabels(function* () {
let response = yield { init };
return yield response.blob();
},
*formData() {
}, { name: `${name}.blob()`, ...labels }),
formData: () => withLabels(function* () {
let response = yield { init };
return yield response.formData();
},
*json() {
}, { name: `${name}.formData()`, ...labels }),
json: () => withLabels(function* () {
let response = yield { init };
return yield response.json();
},
*text() {
}, { name: `${name}.json()`, ...labels }),
text: () => withLabels(function* () {
let response = yield { init };
return yield response.text();
},
}, { name: `${name}.text()`, ...labels }),
};
}
//# sourceMappingURL=fetch.js.map

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

export { AbortController } from 'abort-controller';
export { fetch } from './fetch';
export * from './fetch';
//# sourceMappingURL=index.d.ts.map

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

export { AbortController } from 'abort-controller';
export { fetch } from './fetch';
export * from './fetch';
//# sourceMappingURL=index.js.map
{
"name": "@effection/fetch",
"version": "2.0.0-side-effects.1628189696867",
"version": "2.0.0-v2-writable-unification.1633595877341",
"description": "Fetch operation for Effection",

@@ -9,3 +9,3 @@ "main": "dist-cjs/index.js",

"sideEffects": false,
"homepage": "https://github.com/thefrontside/effection",
"homepage": "https://frontside.com/effection",
"repository": {

@@ -32,3 +32,2 @@ "type": "git",

"devDependencies": {
"@effection/mocha": "2.0.0-side-effects.1628189696867",
"@frontside/tsconfig": "^1.2.0",

@@ -42,3 +41,3 @@ "@types/node": "^16.3.2",

"dependencies": {
"@effection/core": "2.0.0-side-effects.1628189696867",
"@effection/core": "2.0.0-v2-writable-unification.1633595877341",
"abort-controller": "^3.0.0",

@@ -45,0 +44,0 @@ "cross-fetch": "^3.0.4",

# @effection/fetch
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Created by Frontside](https://img.shields.io/badge/created%20by-frontside-26abe8.svg)](https://frontside.com)
[![Chat on Discord](https://img.shields.io/discord/700803887132704931?Label=Discord)](https://discord.gg/Ug5nWH8)
Use `fetch` as an effection operation.
[Effection][] is the structured concurrency toolkit for JavaScript. You can find
detailed information about using its `fetch` api at [https://frontside.com/effection/api/modules/fetch.html#fetch](https://frontside.com/effection/api/modules/fetch.html#fetch)
## Synopsis
This implements the `fetch` api exactly as it appears in the JavaScript spec. However, an abort signal is automatically connected to the underlying call so that whenever the `fetch` operation passes out of scope, it is automatically cancelled. That way, it is impossible to leave an http request dangling.
``` js
let response = yield fetch('https://bigtestjs.io');
```
[Effection]: https://frontside.com/effection

@@ -1,13 +0,90 @@

import { spawn, Operation, Resource } from '@effection/core';
import { ensure, withLabels, Operation, Resource } from '@effection/core';
import { fetch as nativeFetch } from 'cross-fetch';
import { AbortController } from 'abort-controller';
/**
* A resource that can be used to create an HTTP request. This is the return
* value of [[fetch]]. It also contains helper methods for performing common
* requests.
*/
export interface Fetch extends Resource<Response> {
/**
* An operation that executes the request and produces an
* [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
* representation of the response body.
*/
arrayBuffer(): Operation<ArrayBuffer>;
/**
* An operation that executes the request and produces a
* [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
* representation of the response body.
*/
blob(): Operation<Blob>;
/**
* An operation that executes the request and produces a
* [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
* representation of the response body.
*/
formData(): Operation<FormData>;
/**
* An operation that executes the request and produces the response body
* parsed as JSON.
*/
json(): Operation<unknown>;
/**
* An operation that executes the request and produces the raw text of the
* response body
*/
text(): Operation<string>;
}
/**
* Retrieve network content with a superset of the
* [W3C fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
* that can be used as a drop-in, effection-enabled replacement:
*
* ```ts
* let response = yield fetch('https://example.com/movies.json');
* if (!response.ok) {
* throw new Error(`unable to fetch movies: ${response.status}`);
* }
* let json = yield response.json();
* ```
*
* The [[Fetch]] resource also has shortcut methods that return data operations
* allowing you to handle the entire request cycle in a single line. For
* example, the following will execute a request, read it fully, and parse it
* as JSON. An exception is raised if the response is not in the 200 range.
*
* ```ts
* let json = yield fetch('https://example.com/movies.json').json();
*```
*
* Like most operations in Effection, [[fetch]] is stateless, and does not
* actually _do_ anything unless it is yielded to:
*
* ```ts
* // nothing happens here except describing the requests
* let movies = fetch('https://example.com/movies.json');
* let getJSON = movies.json();
* let getText = movies.text();
*
* // Actually run operations. This will create three separate HTTP requests
* let response = yield movies;
* let json = yield getJSON;
* let text = yield getText;
*```
*
* In all cases the underlying HTTP request will be canceled gracefully if
* the current task goes away.
*
* @param info same as the first argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @param requestInit same as the (optional) second argument to the [W3C API](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters)
* @returns a resource binding to a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
* object
*/
export function fetch(info: RequestInfo, requestInit: RequestInit = {}): Fetch {

@@ -17,9 +94,3 @@ function* init() {

yield spawn(function*() {
try {
yield;
} finally {
controller.abort();
}
});
yield ensure(() => { controller.abort() });

@@ -32,25 +103,30 @@ requestInit.signal = controller.signal;

let name = `fetch('${info}')`;
let labels = { expand: false, method: requestInit.method || 'GET' };
return {
name,
labels,
init,
*arrayBuffer() {
arrayBuffer: () => withLabels(function*() {
let response = yield { init };
return yield response.arrayBuffer();
},
*blob() {
}, { name: `${name}.arrayBuffer()`, ...labels }),
blob: () => withLabels(function*() {
let response = yield { init };
return yield response.blob();
},
*formData() {
}, { name: `${name}.blob()`, ...labels }),
formData: () => withLabels(function*() {
let response = yield { init };
return yield response.formData();
},
*json() {
}, { name: `${name}.formData()`, ...labels }),
json: () => withLabels(function*() {
let response = yield { init };
return yield response.json();
},
*text() {
}, { name: `${name}.json()`, ...labels }),
text: () => withLabels(function*() {
let response = yield { init };
return yield response.text();
},
}, { name: `${name}.text()`, ...labels }),
};
}

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

export { AbortController } from 'abort-controller';
export { fetch } from './fetch';
export * from './fetch';

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

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