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

fetch-multipart-graphql

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-multipart-graphql - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

113

dist/PatchResolver.js

@@ -6,10 +6,6 @@ 'use strict';

});
exports.PatchResolver = undefined;
exports.PatchResolver = PatchResolver;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _parseMultipartHTTP = require('./parseMultipartHTTP');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -42,67 +38,58 @@

var PatchResolver = exports.PatchResolver = function () {
function PatchResolver(_ref) {
var onResponse = _ref.onResponse;
function PatchResolver(_ref) {
var onResponse = _ref.onResponse;
_classCallCheck(this, PatchResolver);
this.onResponse = onResponse;
this.previousResponse = null;
this.chunkBuffer = '';
this.processedChunks = 0;
}
this.onResponse = onResponse;
this.previousResponse = null;
this.chunkBuffer = '';
this.processedChunks = 0;
}
PatchResolver.prototype.handleChunk = function (data) {
var results = (0, _parseMultipartHTTP.parseMultipartHTTP)(this.chunkBuffer + data);
if (results === null) {
// The part is not complete yet, add it to the buffer
// and wait for the next chunk to arrive
this.chunkBuffer += data;
} else {
this.chunkBuffer = ''; // Reset
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
_createClass(PatchResolver, [{
key: 'handleChunk',
value: function handleChunk(data) {
var results = (0, _parseMultipartHTTP.parseMultipartHTTP)(this.chunkBuffer + data);
if (results === null) {
// The part is not complete yet, add it to the buffer
// and wait for the next chunk to arrive
this.chunkBuffer += data;
} else {
this.chunkBuffer = ''; // Reset
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = results[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var part = _step.value;
try {
for (var _iterator = results[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var part = _step.value;
if (this.processedChunks === 0) {
this.previousResponse = part;
this.onResponse(this.previousResponse);
} else {
if (!(part.path && part.data)) {
throw new Error('invalid patch format ' + JSON.stringify(part, null, 2));
}
this.previousResponse = Object.assign({}, this.previousResponse, {
data: applyPatch(this.previousResponse.data, part.path, part.data),
errors: mergeErrors(this.previousResponse.errors, part.errors)
});
if (this.processedChunks === 0) {
this.previousResponse = part;
this.onResponse(this.previousResponse);
} else {
if (!(part.path && part.data)) {
throw new Error('invalid patch format ' + JSON.stringify(part, null, 2));
}
this.previousResponse = Object.assign({}, this.previousResponse, {
data: applyPatch(this.previousResponse.data, part.path, part.data),
errors: mergeErrors(this.previousResponse.errors, part.errors)
});
this.onResponse(this.previousResponse);
}
this.processedChunks += 1;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
this.onResponse(this.previousResponse);
}
this.processedChunks += 1;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}]);
return PatchResolver;
}();
}
};
{
"name": "fetch-multipart-graphql",
"version": "1.0.3",
"version": "1.0.4",
"description": "Cross browser function to fetch and parse streaming multipart graphql responses.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -135,3 +135,3 @@ import { PatchResolver } from '../PatchResolver';

it.only('should merge errors', function() {
it('should merge errors', function() {
const onResponse = jest.fn();

@@ -138,0 +138,0 @@ const resolver = new PatchResolver({

@@ -29,37 +29,36 @@ import { parseMultipartHTTP } from './parseMultipartHTTP';

export class PatchResolver {
constructor({ onResponse }) {
this.onResponse = onResponse;
this.previousResponse = null;
this.chunkBuffer = '';
this.processedChunks = 0;
}
handleChunk(data) {
const results = parseMultipartHTTP(this.chunkBuffer + data);
if (results === null) {
// The part is not complete yet, add it to the buffer
// and wait for the next chunk to arrive
this.chunkBuffer += data;
} else {
this.chunkBuffer = ''; // Reset
for (const part of results) {
if (this.processedChunks === 0) {
this.previousResponse = part;
this.onResponse(this.previousResponse);
} else {
if (!(part.path && part.data)) {
throw new Error('invalid patch format ' + JSON.stringify(part, null, 2));
}
this.previousResponse = {
...this.previousResponse,
data: applyPatch(this.previousResponse.data, part.path, part.data),
errors: mergeErrors(this.previousResponse.errors, part.errors),
};
export function PatchResolver({ onResponse }) {
this.onResponse = onResponse;
this.previousResponse = null;
this.chunkBuffer = '';
this.processedChunks = 0;
}
this.onResponse(this.previousResponse);
PatchResolver.prototype.handleChunk = function(data) {
const results = parseMultipartHTTP(this.chunkBuffer + data);
if (results === null) {
// The part is not complete yet, add it to the buffer
// and wait for the next chunk to arrive
this.chunkBuffer += data;
} else {
this.chunkBuffer = ''; // Reset
for (const part of results) {
if (this.processedChunks === 0) {
this.previousResponse = part;
this.onResponse(this.previousResponse);
} else {
if (!(part.path && part.data)) {
throw new Error('invalid patch format ' + JSON.stringify(part, null, 2));
}
this.processedChunks += 1;
this.previousResponse = {
...this.previousResponse,
data: applyPatch(this.previousResponse.data, part.path, part.data),
errors: mergeErrors(this.previousResponse.errors, part.errors),
};
this.onResponse(this.previousResponse);
}
this.processedChunks += 1;
}
}
}
};
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