@graphql-tools/executor-http
Advanced tools
Comparing version 1.0.3 to 1.0.4-alpha-20231127174528-cef35ff2
@@ -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, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54751
1156
2