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

react-streaming

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-streaming - npm Package Compare versions

Comparing version 0.3.33-commit-914f21d to 0.3.33-commit-993864b

2

dist/cjs/server/renderToStream.js

@@ -55,3 +55,3 @@ "use strict";

element = react_1.default.createElement(useSuspenseData_1.SuspenseData, null, element);
let injectToStream = (chunk) => {
let injectToStream = async (chunk) => {
buffer.push(chunk);

@@ -58,0 +58,0 @@ };

export { createBuffer };
export type { InjectToStream };
export type { StreamOperations };
export type { Chunk };
declare type InjectToStreamOptions = {
flush?: boolean;
};
declare type Chunk = string;
declare type InjectToStream = (chunk: Chunk, options?: InjectToStreamOptions) => void;
declare type Chunk = string | Promise<string>;
declare type InjectToStream = (chunk: Chunk, options?: InjectToStreamOptions) => Promise<void>;
declare type StreamOperations = {

@@ -17,6 +18,6 @@ operations: null | {

injectToStream: InjectToStream;
onReactWriteBefore: (chunk: unknown) => void;
onReactWriteAfter: () => void;
onBeforeEnd: () => void;
onReactWriteBefore: (chunk: unknown) => Promise<void>;
onReactWriteAfter: () => Promise<void>;
onBeforeEnd: () => Promise<void>;
hasStreamEnded: () => boolean;
};

@@ -15,3 +15,3 @@ "use strict";

return { injectToStream, onReactWriteBefore, onReactWriteAfter, onBeforeEnd, hasStreamEnded };
function injectToStream(chunk, options) {
async function injectToStream(chunk, options) {
if (debug.isEnabled) {

@@ -24,5 +24,5 @@ debug('injectToStream()', getChunkAsString(chunk));

buffer.push({ chunk, flush: options === null || options === void 0 ? void 0 : options.flush });
flushBuffer();
await flushBuffer();
}
function flushBuffer() {
async function flushBuffer() {
if (!writePermission) {

@@ -39,10 +39,11 @@ return;

let flushStream = false;
buffer.forEach((bufferEntry) => {
for (let { chunk, flush } of buffer) {
(0, utils_1.assert)(streamOperations.operations);
const { writeChunk } = streamOperations.operations;
writeChunk(bufferEntry.chunk);
if (bufferEntry.flush) {
if ((0, utils_1.isPromise)(chunk))
chunk = await chunk;
writeChunk(chunk);
if (flush)
flushStream = true;
}
});
}
buffer.length = 0;

@@ -55,9 +56,6 @@ (0, utils_1.assert)(streamOperations.operations);

}
function onReactWriteAfter() {
const writeWasBlocked = !writePermission;
writePermission = true;
if (writeWasBlocked)
flushBuffer();
async function onReactWriteAfter() {
// TODO: clean
}
function onReactWriteBefore(chunk) {
async function onReactWriteBefore(chunk) {
state === 'UNSTARTED' && debug('>>> START');

@@ -68,7 +66,15 @@ if (debug.isEnabled) {

state = 'STREAMING';
flushBuffer();
const bufferEntry = { chunk: chunk, flush: true };
if (!writePermission) {
buffer.unshift(bufferEntry);
}
else {
buffer.push(bufferEntry);
}
writePermission = true;
await flushBuffer();
}
function onBeforeEnd() {
async function onBeforeEnd() {
writePermission = true; // in case React didn't write anything
flushBuffer();
await flushBuffer();
(0, utils_1.assert)(buffer.length === 0);

@@ -75,0 +81,0 @@ state = 'ENDED';

@@ -23,8 +23,8 @@ "use strict";

const writableForReact = new stream_1.Writable({
write(chunk, encoding, callback) {
async write(chunk, encoding, callback) {
debug('write');
onReactWriteBefore(chunk);
await onReactWriteBefore(chunk);
if (!writableFromUser.destroyed) {
writableFromUser.write(chunk, encoding, callback);
onReactWriteAfter();
//writableFromUser.write(chunk, encoding, callback)
//onReactWriteAfter()
}

@@ -36,6 +36,6 @@ else {

},
final(callback) {
async final(callback) {
debug('final');
stopTimeout === null || stopTimeout === void 0 ? void 0 : stopTimeout();
onBeforeEnd();
await onBeforeEnd();
writableFromUser.end();

@@ -42,0 +42,0 @@ onEnded();

@@ -46,5 +46,5 @@ "use strict";

}
onReactWriteBefore(value);
streamOperations.operations.writeChunk(value);
onReactWriteAfter();
await onReactWriteBefore(value);
//streamOperations.operations.writeChunk(value)
//await onReactWriteAfter()
}

@@ -55,4 +55,4 @@ stopTimeout === null || stopTimeout === void 0 ? void 0 : stopTimeout();

// We should probably remove this workaround once we have a proper solution.
setTimeout(() => {
onBeforeEnd();
setTimeout(async () => {
await onBeforeEnd();
controllerOfUserStream.close();

@@ -59,0 +59,0 @@ onEnded();

@@ -30,2 +30,3 @@ "use strict";

var _a;
return true;
let DEBUG;

@@ -66,10 +67,10 @@ // - `process` can be undefined in edge workers

const PADDING = ' ';
const WIDTH = process.stdout.columns;
const terminalWidth = getTerminalWidth();
const lines = [];
str.split('\n').forEach((line) => {
if (!WIDTH) {
if (!terminalWidth) {
lines.push(line);
}
else {
chunk(line, WIDTH - PADDING.length).forEach((chunk) => {
chunk(line, terminalWidth - PADDING.length).forEach((chunk) => {
lines.push(chunk);

@@ -101,1 +102,5 @@ });

}
function getTerminalWidth() {
// https://stackoverflow.com/questions/30335637/get-width-of-terminal-in-node-js/30335724#30335724
return ((typeof process !== 'undefined' && typeof process.stdout !== 'undefined' && process.stdout.columns) || undefined);
}

@@ -5,3 +5,3 @@ "use strict";

const getGlobalObject_1 = require("./getGlobalObject");
const PROJECT_VERSION = '0.3.33-commit-914f21d';
const PROJECT_VERSION = '0.3.33-commit-993864b';
const projectInfo = {

@@ -8,0 +8,0 @@ projectName: 'react-streaming',

@@ -29,3 +29,3 @@ export { renderToStream };

element = React.createElement(SuspenseData, null, element);
let injectToStream = (chunk) => {
let injectToStream = async (chunk) => {
buffer.push(chunk);

@@ -32,0 +32,0 @@ };

export { createBuffer };
export type { InjectToStream };
export type { StreamOperations };
export type { Chunk };
declare type InjectToStreamOptions = {
flush?: boolean;
};
declare type Chunk = string;
declare type InjectToStream = (chunk: Chunk, options?: InjectToStreamOptions) => void;
declare type Chunk = string | Promise<string>;
declare type InjectToStream = (chunk: Chunk, options?: InjectToStreamOptions) => Promise<void>;
declare type StreamOperations = {

@@ -17,6 +18,6 @@ operations: null | {

injectToStream: InjectToStream;
onReactWriteBefore: (chunk: unknown) => void;
onReactWriteAfter: () => void;
onBeforeEnd: () => void;
onReactWriteBefore: (chunk: unknown) => Promise<void>;
onReactWriteAfter: () => Promise<void>;
onBeforeEnd: () => Promise<void>;
hasStreamEnded: () => boolean;
};
export { createBuffer };
import { assert, assertUsage, createDebugger } from '../utils';
import { assert, assertUsage, createDebugger, isPromise } from '../utils';
const debug = createDebugger('react-streaming:buffer');

@@ -13,3 +13,3 @@ function createBuffer(streamOperations) {

return { injectToStream, onReactWriteBefore, onReactWriteAfter, onBeforeEnd, hasStreamEnded };
function injectToStream(chunk, options) {
async function injectToStream(chunk, options) {
if (debug.isEnabled) {

@@ -22,5 +22,5 @@ debug('injectToStream()', getChunkAsString(chunk));

buffer.push({ chunk, flush: options === null || options === void 0 ? void 0 : options.flush });
flushBuffer();
await flushBuffer();
}
function flushBuffer() {
async function flushBuffer() {
if (!writePermission) {

@@ -37,10 +37,11 @@ return;

let flushStream = false;
buffer.forEach((bufferEntry) => {
for (let { chunk, flush } of buffer) {
assert(streamOperations.operations);
const { writeChunk } = streamOperations.operations;
writeChunk(bufferEntry.chunk);
if (bufferEntry.flush) {
if (isPromise(chunk))
chunk = await chunk;
writeChunk(chunk);
if (flush)
flushStream = true;
}
});
}
buffer.length = 0;

@@ -53,9 +54,6 @@ assert(streamOperations.operations);

}
function onReactWriteAfter() {
const writeWasBlocked = !writePermission;
writePermission = true;
if (writeWasBlocked)
flushBuffer();
async function onReactWriteAfter() {
// TODO: clean
}
function onReactWriteBefore(chunk) {
async function onReactWriteBefore(chunk) {
state === 'UNSTARTED' && debug('>>> START');

@@ -66,7 +64,15 @@ if (debug.isEnabled) {

state = 'STREAMING';
flushBuffer();
const bufferEntry = { chunk: chunk, flush: true };
if (!writePermission) {
buffer.unshift(bufferEntry);
}
else {
buffer.push(bufferEntry);
}
writePermission = true;
await flushBuffer();
}
function onBeforeEnd() {
async function onBeforeEnd() {
writePermission = true; // in case React didn't write anything
flushBuffer();
await flushBuffer();
assert(buffer.length === 0);

@@ -73,0 +79,0 @@ state = 'ENDED';

@@ -21,8 +21,8 @@ export { createPipeWrapper };

const writableForReact = new Writable({
write(chunk, encoding, callback) {
async write(chunk, encoding, callback) {
debug('write');
onReactWriteBefore(chunk);
await onReactWriteBefore(chunk);
if (!writableFromUser.destroyed) {
writableFromUser.write(chunk, encoding, callback);
onReactWriteAfter();
//writableFromUser.write(chunk, encoding, callback)
//onReactWriteAfter()
}

@@ -34,6 +34,6 @@ else {

},
final(callback) {
async final(callback) {
debug('final');
stopTimeout === null || stopTimeout === void 0 ? void 0 : stopTimeout();
onBeforeEnd();
await onBeforeEnd();
writableFromUser.end();

@@ -40,0 +40,0 @@ onEnded();

@@ -44,5 +44,5 @@ export { createReadableWrapper };

}
onReactWriteBefore(value);
streamOperations.operations.writeChunk(value);
onReactWriteAfter();
await onReactWriteBefore(value);
//streamOperations.operations.writeChunk(value)
//await onReactWriteAfter()
}

@@ -53,4 +53,4 @@ stopTimeout === null || stopTimeout === void 0 ? void 0 : stopTimeout();

// We should probably remove this workaround once we have a proper solution.
setTimeout(() => {
onBeforeEnd();
setTimeout(async () => {
await onBeforeEnd();
controllerOfUserStream.close();

@@ -57,0 +57,0 @@ onEnded();

@@ -28,2 +28,3 @@ export { createDebugger };

var _a;
return true;
let DEBUG;

@@ -63,10 +64,10 @@ // - `process` can be undefined in edge workers

const PADDING = ' ';
const WIDTH = process.stdout.columns;
const terminalWidth = getTerminalWidth();
const lines = [];
str.split('\n').forEach((line) => {
if (!WIDTH) {
if (!terminalWidth) {
lines.push(line);
}
else {
chunk(line, WIDTH - PADDING.length).forEach((chunk) => {
chunk(line, terminalWidth - PADDING.length).forEach((chunk) => {
lines.push(chunk);

@@ -98,1 +99,5 @@ });

}
function getTerminalWidth() {
// https://stackoverflow.com/questions/30335637/get-width-of-terminal-in-node-js/30335724#30335724
return ((typeof process !== 'undefined' && typeof process.stdout !== 'undefined' && process.stdout.columns) || undefined);
}
export { projectInfo };
import { getGlobalObject } from './getGlobalObject';
const PROJECT_VERSION = '0.3.33-commit-914f21d';
const PROJECT_VERSION = '0.3.33-commit-993864b';
const projectInfo = {

@@ -5,0 +5,0 @@ projectName: 'react-streaming',

{
"name": "react-streaming",
"description": "React 18 Streaming. Full-fledged & Easy.",
"version": "0.3.33-commit-914f21d",
"version": "0.3.33-commit-993864b",
"peerDependencies": {

@@ -6,0 +6,0 @@ "react": ">=18",

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