react-streaming
Advanced tools
Comparing version 0.3.31 to 0.3.32-commit-91eaf97
@@ -33,2 +33,3 @@ export { renderToStream }; | ||
streamEnd: Promise<boolean>; | ||
hasStreamEnded: () => boolean; | ||
disabled: boolean; | ||
@@ -35,0 +36,0 @@ injectToStream: InjectToStream; |
@@ -6,3 +6,3 @@ export { createBuffer }; | ||
flush?: boolean; | ||
expectStreamEnd?: boolean; | ||
tolerateStreamEnded?: boolean; | ||
}; | ||
@@ -20,2 +20,3 @@ declare type InjectToStream = (chunk: unknown, options?: InjectToStreamOptions) => boolean; | ||
onBeforeEnd: () => void; | ||
hasStreamEnded: () => boolean; | ||
}; |
@@ -10,3 +10,3 @@ "use strict"; | ||
let writePermission = null; // Set to `null` because React fails to hydrate if something is injected before the first react write | ||
return { injectToStream, onBeforeWrite, onBeforeEnd }; | ||
return { injectToStream, onBeforeWrite, onBeforeEnd, hasStreamEnded }; | ||
function injectToStream(chunk, options) { | ||
@@ -16,5 +16,5 @@ if (debug.isEnabled) { | ||
} | ||
if (state === 'ENDED') { | ||
if (!(options === null || options === void 0 ? void 0 : options.expectStreamEnd)) { | ||
(0, utils_1.assertUsage)(state, `Cannot inject following chunk after stream has ended:\n${getChunkAsString(chunk)}`); | ||
if (hasStreamEnded()) { | ||
if (!(options === null || options === void 0 ? void 0 : options.tolerateStreamEnded)) { | ||
(0, utils_1.assertUsage)(state, `Cannot inject the following chunk because the stream has already ended. Either 1) don't inject chunks after the stream ends, or 2) use the tolerateStreamEnded option, or 3) use the hasStreamEnded() function. The chunk:\n${getChunkAsString(chunk)}`); | ||
} | ||
@@ -71,3 +71,3 @@ return false; | ||
flushBuffer(); | ||
}); | ||
}, 0); | ||
} | ||
@@ -83,2 +83,5 @@ } | ||
} | ||
function hasStreamEnded() { | ||
return state === 'ENDED'; | ||
} | ||
} | ||
@@ -85,0 +88,0 @@ exports.createBuffer = createBuffer; |
@@ -13,2 +13,3 @@ /// <reference types="node" /> | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}>; |
@@ -13,4 +13,4 @@ "use strict"; | ||
}; | ||
const { injectToStream, onBeforeWrite, onBeforeEnd } = (0, createBuffer_1.createBuffer)(streamOperations); | ||
return { pipeForUser, streamEnd, injectToStream }; | ||
const { injectToStream, onBeforeWrite, onBeforeEnd, hasStreamEnded } = (0, createBuffer_1.createBuffer)(streamOperations); | ||
return { pipeForUser, streamEnd, injectToStream, hasStreamEnded }; | ||
function createPipeForUser() { | ||
@@ -17,0 +17,0 @@ debug('createPipeForUser()'); |
@@ -8,2 +8,3 @@ export { createReadableWrapper }; | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}; |
@@ -23,4 +23,4 @@ "use strict"; | ||
}); | ||
const { injectToStream, onBeforeWrite, onBeforeEnd } = (0, createBuffer_1.createBuffer)(streamOperations); | ||
return { readableForUser, streamEnd, injectToStream }; | ||
const { injectToStream, onBeforeWrite, onBeforeEnd, hasStreamEnded } = (0, createBuffer_1.createBuffer)(streamOperations); | ||
return { readableForUser, streamEnd, injectToStream, hasStreamEnded }; | ||
async function onReady(onEnded) { | ||
@@ -51,8 +51,5 @@ streamOperations.operations = { | ||
stopTimeout === null || stopTimeout === void 0 ? void 0 : stopTimeout(); | ||
// Collect `injectToStream()` calls stuck in an async call | ||
setTimeout(() => { | ||
onBeforeEnd(); | ||
controllerOfUserStream.close(); | ||
onEnded(); | ||
}, 0); | ||
onBeforeEnd(); | ||
controllerOfUserStream.close(); | ||
onEnded(); | ||
} | ||
@@ -59,0 +56,0 @@ } |
@@ -18,2 +18,3 @@ export { renderToNodeStream }; | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}>; |
@@ -50,3 +50,3 @@ "use strict"; | ||
let promiseResolved = false; | ||
const { pipeForUser, injectToStream, streamEnd } = await (0, createPipeWrapper_1.createPipeWrapper)(pipeOriginal, { | ||
const { pipeForUser, injectToStream, streamEnd, hasStreamEnded } = await (0, createPipeWrapper_1.createPipeWrapper)(pipeOriginal, { | ||
stopTimeout, | ||
@@ -78,4 +78,5 @@ onReactBug(err) { | ||
injectToStream, | ||
hasStreamEnded, | ||
}; | ||
} | ||
exports.renderToNodeStream = renderToNodeStream; |
@@ -21,2 +21,3 @@ export { renderToWebStream }; | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}>; |
@@ -52,3 +52,5 @@ "use strict"; | ||
throw firstErr; | ||
const { readableForUser, streamEnd, injectToStream } = (0, createReadableWrapper_1.createReadableWrapper)(readableOriginal, { stopTimeout }); | ||
const { readableForUser, streamEnd, injectToStream, hasStreamEnded } = (0, createReadableWrapper_1.createReadableWrapper)(readableOriginal, { | ||
stopTimeout, | ||
}); | ||
promiseResolved = true; | ||
@@ -61,4 +63,5 @@ return { | ||
injectToStream, | ||
hasStreamEnded, | ||
}; | ||
} | ||
exports.renderToWebStream = renderToWebStream; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const getGlobalObject_1 = require("./getGlobalObject"); | ||
const PROJECT_VERSION = '0.3.31'; | ||
const PROJECT_VERSION = '0.3.32-commit-91eaf97'; | ||
const projectInfo = { | ||
@@ -8,0 +8,0 @@ projectName: 'react-streaming', |
@@ -33,2 +33,3 @@ export { renderToStream }; | ||
streamEnd: Promise<boolean>; | ||
hasStreamEnded: () => boolean; | ||
disabled: boolean; | ||
@@ -35,0 +36,0 @@ injectToStream: InjectToStream; |
@@ -6,3 +6,3 @@ export { createBuffer }; | ||
flush?: boolean; | ||
expectStreamEnd?: boolean; | ||
tolerateStreamEnded?: boolean; | ||
}; | ||
@@ -20,2 +20,3 @@ declare type InjectToStream = (chunk: unknown, options?: InjectToStreamOptions) => boolean; | ||
onBeforeEnd: () => void; | ||
hasStreamEnded: () => boolean; | ||
}; |
@@ -8,3 +8,3 @@ export { createBuffer }; | ||
let writePermission = null; // Set to `null` because React fails to hydrate if something is injected before the first react write | ||
return { injectToStream, onBeforeWrite, onBeforeEnd }; | ||
return { injectToStream, onBeforeWrite, onBeforeEnd, hasStreamEnded }; | ||
function injectToStream(chunk, options) { | ||
@@ -14,5 +14,5 @@ if (debug.isEnabled) { | ||
} | ||
if (state === 'ENDED') { | ||
if (!(options === null || options === void 0 ? void 0 : options.expectStreamEnd)) { | ||
assertUsage(state, `Cannot inject following chunk after stream has ended:\n${getChunkAsString(chunk)}`); | ||
if (hasStreamEnded()) { | ||
if (!(options === null || options === void 0 ? void 0 : options.tolerateStreamEnded)) { | ||
assertUsage(state, `Cannot inject the following chunk because the stream has already ended. Either 1) don't inject chunks after the stream ends, or 2) use the tolerateStreamEnded option, or 3) use the hasStreamEnded() function. The chunk:\n${getChunkAsString(chunk)}`); | ||
} | ||
@@ -69,3 +69,3 @@ return false; | ||
flushBuffer(); | ||
}); | ||
}, 0); | ||
} | ||
@@ -81,2 +81,5 @@ } | ||
} | ||
function hasStreamEnded() { | ||
return state === 'ENDED'; | ||
} | ||
} | ||
@@ -83,0 +86,0 @@ function getChunkAsString(chunk) { |
@@ -13,2 +13,3 @@ /// <reference types="node" /> | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}>; |
@@ -11,4 +11,4 @@ export { createPipeWrapper }; | ||
}; | ||
const { injectToStream, onBeforeWrite, onBeforeEnd } = createBuffer(streamOperations); | ||
return { pipeForUser, streamEnd, injectToStream }; | ||
const { injectToStream, onBeforeWrite, onBeforeEnd, hasStreamEnded } = createBuffer(streamOperations); | ||
return { pipeForUser, streamEnd, injectToStream, hasStreamEnded }; | ||
function createPipeForUser() { | ||
@@ -15,0 +15,0 @@ debug('createPipeForUser()'); |
@@ -8,2 +8,3 @@ export { createReadableWrapper }; | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}; |
@@ -21,4 +21,4 @@ export { createReadableWrapper }; | ||
}); | ||
const { injectToStream, onBeforeWrite, onBeforeEnd } = createBuffer(streamOperations); | ||
return { readableForUser, streamEnd, injectToStream }; | ||
const { injectToStream, onBeforeWrite, onBeforeEnd, hasStreamEnded } = createBuffer(streamOperations); | ||
return { readableForUser, streamEnd, injectToStream, hasStreamEnded }; | ||
async function onReady(onEnded) { | ||
@@ -49,8 +49,5 @@ streamOperations.operations = { | ||
stopTimeout === null || stopTimeout === void 0 ? void 0 : stopTimeout(); | ||
// Collect `injectToStream()` calls stuck in an async call | ||
setTimeout(() => { | ||
onBeforeEnd(); | ||
controllerOfUserStream.close(); | ||
onEnded(); | ||
}, 0); | ||
onBeforeEnd(); | ||
controllerOfUserStream.close(); | ||
onEnded(); | ||
} | ||
@@ -57,0 +54,0 @@ } |
@@ -18,2 +18,3 @@ export { renderToNodeStream }; | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}>; |
@@ -53,3 +53,3 @@ export { renderToNodeStream }; | ||
let promiseResolved = false; | ||
const { pipeForUser, injectToStream, streamEnd } = await createPipeWrapper(pipeOriginal, { | ||
const { pipeForUser, injectToStream, streamEnd, hasStreamEnded } = await createPipeWrapper(pipeOriginal, { | ||
stopTimeout, | ||
@@ -81,3 +81,4 @@ onReactBug(err) { | ||
injectToStream, | ||
hasStreamEnded, | ||
}; | ||
} |
@@ -21,2 +21,3 @@ export { renderToWebStream }; | ||
injectToStream: import("./createBuffer").InjectToStream; | ||
hasStreamEnded: () => boolean; | ||
}>; |
@@ -54,3 +54,5 @@ export { renderToWebStream }; | ||
throw firstErr; | ||
const { readableForUser, streamEnd, injectToStream } = createReadableWrapper(readableOriginal, { stopTimeout }); | ||
const { readableForUser, streamEnd, injectToStream, hasStreamEnded } = createReadableWrapper(readableOriginal, { | ||
stopTimeout, | ||
}); | ||
promiseResolved = true; | ||
@@ -63,3 +65,4 @@ return { | ||
injectToStream, | ||
hasStreamEnded, | ||
}; | ||
} |
export { projectInfo }; | ||
import { getGlobalObject } from './getGlobalObject'; | ||
const PROJECT_VERSION = '0.3.31'; | ||
const PROJECT_VERSION = '0.3.32-commit-91eaf97'; | ||
const projectInfo = { | ||
@@ -5,0 +5,0 @@ projectName: 'react-streaming', |
{ | ||
"name": "react-streaming", | ||
"description": "React 18 Streaming. Full-fledged & Easy.", | ||
"version": "0.3.31", | ||
"version": "0.3.32-commit-91eaf97", | ||
"peerDependencies": { | ||
@@ -6,0 +6,0 @@ "react": ">=18", |
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
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
144133
3059