Socket
Socket
Sign inDemoInstall

@graphql-tools/executor-http

Package Overview
Dependencies
Maintainers
3
Versions
247
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/executor-http - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4-alpha-20231127174528-cef35ff2

37

cjs/handleAsyncIterable.js

@@ -6,18 +6,31 @@ "use strict";

const fetch_1 = require("@whatwg-node/fetch");
const DELIM = '\n\n';
async function* handleAsyncIterable(asyncIterable) {
const textDecoder = new fetch_1.TextDecoder();
let currChunk = '';
outer: for await (const chunk of asyncIterable) {
const chunkStr = typeof chunk === 'string' ? chunk : textDecoder.decode(chunk, { stream: true });
for (const part of chunkStr.split('\n\n')) {
if (part) {
const eventStr = part.split('event: ')[1];
const dataStr = part.split('data: ')[1];
if (eventStr === 'complete') {
break outer;
}
if (dataStr) {
const data = JSON.parse(dataStr);
yield data.payload || data;
}
currChunk += typeof chunk === 'string' ? chunk : textDecoder.decode(chunk);
for (;;) {
const delimIndex = currChunk.indexOf(DELIM);
if (delimIndex === -1) {
// incomplete message, wait for more chunks
continue outer;
}
const msg = currChunk.slice(0, delimIndex); // whole message
currChunk = currChunk.slice(delimIndex + DELIM.length); // remainder
if (msg === ':') {
// ping
continue;
}
// data
const dataStr = msg.split('data:')[1]?.trim();
if (dataStr) {
const data = JSON.parse(dataStr);
yield data.payload || data;
}
// event
const event = msg.split('event:')[1]?.trim();
if (event === 'complete') {
break outer;
}
}

@@ -24,0 +37,0 @@ }

/* eslint-disable no-labels */
import { TextDecoder } from '@whatwg-node/fetch';
const DELIM = '\n\n';
export async function* handleAsyncIterable(asyncIterable) {
const textDecoder = new TextDecoder();
let currChunk = '';
outer: for await (const chunk of asyncIterable) {
const chunkStr = typeof chunk === 'string' ? chunk : textDecoder.decode(chunk, { stream: true });
for (const part of chunkStr.split('\n\n')) {
if (part) {
const eventStr = part.split('event: ')[1];
const dataStr = part.split('data: ')[1];
if (eventStr === 'complete') {
break outer;
}
if (dataStr) {
const data = JSON.parse(dataStr);
yield data.payload || data;
}
currChunk += typeof chunk === 'string' ? chunk : textDecoder.decode(chunk);
for (;;) {
const delimIndex = currChunk.indexOf(DELIM);
if (delimIndex === -1) {
// incomplete message, wait for more chunks
continue outer;
}
const msg = currChunk.slice(0, delimIndex); // whole message
currChunk = currChunk.slice(delimIndex + DELIM.length); // remainder
if (msg === ':') {
// ping
continue;
}
// data
const dataStr = msg.split('data:')[1]?.trim();
if (dataStr) {
const data = JSON.parse(dataStr);
yield data.payload || data;
}
// event
const event = msg.split('event:')[1]?.trim();
if (event === 'complete') {
break outer;
}
}
}
}
{
"name": "@graphql-tools/executor-http",
"version": "1.0.3",
"version": "1.0.4-alpha-20231127174528-cef35ff2",
"description": "A set of utils for faster development of GraphQL tools",

@@ -5,0 +5,0 @@ "sideEffects": false,

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