turbo-stream
Advanced tools
Comparing version 2.0.1 to 2.1.0
import { type ThisEncode } from "./utils.js"; | ||
export declare function flatten(this: ThisEncode, input: unknown): number; | ||
export declare function flatten(this: ThisEncode, input: unknown): number | [number]; |
@@ -9,3 +9,3 @@ "use strict"; | ||
if (existing) | ||
return existing; | ||
return [existing]; | ||
if (input === undefined) | ||
@@ -94,10 +94,23 @@ return utils_js_1.UNDEFINED; | ||
else if (input instanceof Set) { | ||
str[index] = `["${utils_js_1.TYPE_SET}",${[...input] | ||
.map((val) => flatten.call(this, val)) | ||
.join(",")}]`; | ||
if (input.size > 0) { | ||
str[index] = `["${utils_js_1.TYPE_SET}",${[...input] | ||
.map((val) => flatten.call(this, val)) | ||
.join(",")}]`; | ||
} | ||
else { | ||
str[index] = `["${utils_js_1.TYPE_SET}"]`; | ||
} | ||
} | ||
else if (input instanceof Map) { | ||
str[index] = `["${utils_js_1.TYPE_MAP}",${[...input] | ||
.flatMap(([k, v]) => [flatten.call(this, k), flatten.call(this, v)]) | ||
.join(",")}]`; | ||
if (input.size > 0) { | ||
str[index] = `["${utils_js_1.TYPE_MAP}",${[...input] | ||
.flatMap(([k, v]) => [ | ||
flatten.call(this, k), | ||
flatten.call(this, v), | ||
]) | ||
.join(",")}]`; | ||
} | ||
else { | ||
str[index] = `["${utils_js_1.TYPE_MAP}"]`; | ||
} | ||
} | ||
@@ -104,0 +117,0 @@ else if (input instanceof Promise) { |
@@ -124,2 +124,5 @@ "use strict"; | ||
const id = flatten_js_1.flatten.call(encoder, input); | ||
if (Array.isArray(id)) { | ||
throw new Error("This should never happen"); | ||
} | ||
if (id < 0) { | ||
@@ -140,3 +143,6 @@ controller.enqueue(textEncoder.encode(`${id}\n`)); | ||
const id = flatten_js_1.flatten.call(encoder, resolved); | ||
if (id < 0) { | ||
if (Array.isArray(id)) { | ||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`)); | ||
} | ||
else if (id < 0) { | ||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:${id}\n`)); | ||
@@ -158,3 +164,6 @@ } | ||
const id = flatten_js_1.flatten.call(encoder, reason); | ||
if (id < 0) { | ||
if (Array.isArray(id)) { | ||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`)); | ||
} | ||
else if (id < 0) { | ||
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:${id}\n`)); | ||
@@ -161,0 +170,0 @@ } |
@@ -92,2 +92,4 @@ "use strict"; | ||
return error; | ||
case utils_js_1.TYPE_PREVIOUS_RESOLVED: | ||
return hydrate.call(this, b); | ||
default: | ||
@@ -94,0 +96,0 @@ // Run plugins at the end so we have a chance to resolve primitives |
@@ -18,2 +18,3 @@ export declare const HOLE = -1; | ||
export declare const TYPE_URL = "U"; | ||
export declare const TYPE_PREVIOUS_RESOLVED = "Z"; | ||
export type DecodePlugin = (type: string, ...data: unknown[]) => { | ||
@@ -20,0 +21,0 @@ value: unknown; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLineSplittingTransform = exports.Deferred = exports.TYPE_URL = exports.TYPE_SYMBOL = exports.TYPE_SET = exports.TYPE_REGEXP = exports.TYPE_PROMISE = exports.TYPE_NULL_OBJECT = exports.TYPE_MAP = exports.TYPE_ERROR = exports.TYPE_DATE = exports.TYPE_BIGINT = exports.UNDEFINED = exports.POSITIVE_INFINITY = exports.NULL = exports.NEGATIVE_ZERO = exports.NEGATIVE_INFINITY = exports.NAN = exports.HOLE = void 0; | ||
exports.createLineSplittingTransform = exports.Deferred = exports.TYPE_PREVIOUS_RESOLVED = exports.TYPE_URL = exports.TYPE_SYMBOL = exports.TYPE_SET = exports.TYPE_REGEXP = exports.TYPE_PROMISE = exports.TYPE_NULL_OBJECT = exports.TYPE_MAP = exports.TYPE_ERROR = exports.TYPE_DATE = exports.TYPE_BIGINT = exports.UNDEFINED = exports.POSITIVE_INFINITY = exports.NULL = exports.NEGATIVE_ZERO = exports.NEGATIVE_INFINITY = exports.NAN = exports.HOLE = void 0; | ||
exports.HOLE = -1; | ||
@@ -21,2 +21,3 @@ exports.NAN = -2; | ||
exports.TYPE_URL = "U"; | ||
exports.TYPE_PREVIOUS_RESOLVED = "Z"; | ||
class Deferred { | ||
@@ -23,0 +24,0 @@ promise; |
{ | ||
"name": "turbo-stream", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "A streaming data transport format that aims to support built-in features such as Promises, Dates, RegExps, Maps, Sets and more.", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
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
43150
1101