turbo-stream 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/flatten.js +24 -2
- package/dist/turbo-stream.js +4 -0
- package/dist/turbo-stream.mjs +26 -2
- package/package.json +1 -1
package/dist/flatten.js
CHANGED
|
@@ -135,8 +135,30 @@ function stringify(input, index) {
|
|
|
135
135
|
}
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
|
-
default:
|
|
139
|
-
|
|
138
|
+
default: {
|
|
139
|
+
const isArray = Array.isArray(input);
|
|
140
|
+
let pluginHandled = false;
|
|
141
|
+
if (!isArray && plugins) {
|
|
142
|
+
for (const plugin of plugins) {
|
|
143
|
+
const pluginResult = plugin(input);
|
|
144
|
+
if (Array.isArray(pluginResult)) {
|
|
145
|
+
pluginHandled = true;
|
|
146
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
|
147
|
+
str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
|
148
|
+
if (rest.length > 0) {
|
|
149
|
+
str[index] += `,${rest
|
|
150
|
+
.map((v) => flatten.call(this, v))
|
|
151
|
+
.join(",")}`;
|
|
152
|
+
}
|
|
153
|
+
str[index] += "]";
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!pluginHandled) {
|
|
159
|
+
throw new Error("Cannot encode function or unexpected type");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
140
162
|
}
|
|
141
163
|
}
|
|
142
164
|
const objectProtoNames = Object.getOwnPropertyNames(Object.prototype)
|
package/dist/turbo-stream.js
CHANGED
|
@@ -141,6 +141,8 @@ function encode(input, options) {
|
|
|
141
141
|
const id = flatten_js_1.flatten.call(encoder, resolved);
|
|
142
142
|
if (Array.isArray(id)) {
|
|
143
143
|
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`));
|
|
144
|
+
encoder.index++;
|
|
145
|
+
lastSentIndex++;
|
|
144
146
|
}
|
|
145
147
|
else if (id < 0) {
|
|
146
148
|
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_PROMISE}${deferredId}:${id}\n`));
|
|
@@ -161,6 +163,8 @@ function encode(input, options) {
|
|
|
161
163
|
const id = flatten_js_1.flatten.call(encoder, reason);
|
|
162
164
|
if (Array.isArray(id)) {
|
|
163
165
|
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:[["${utils_js_1.TYPE_PREVIOUS_RESOLVED}",${id[0]}]]\n`));
|
|
166
|
+
encoder.index++;
|
|
167
|
+
lastSentIndex++;
|
|
164
168
|
}
|
|
165
169
|
else if (id < 0) {
|
|
166
170
|
controller.enqueue(textEncoder.encode(`${utils_js_1.TYPE_ERROR}${deferredId}:${id}\n`));
|
package/dist/turbo-stream.mjs
CHANGED
|
@@ -163,8 +163,28 @@ function stringify(input, index) {
|
|
|
163
163
|
}
|
|
164
164
|
break;
|
|
165
165
|
}
|
|
166
|
-
default:
|
|
167
|
-
|
|
166
|
+
default: {
|
|
167
|
+
const isArray = Array.isArray(input);
|
|
168
|
+
let pluginHandled = false;
|
|
169
|
+
if (!isArray && plugins) {
|
|
170
|
+
for (const plugin of plugins) {
|
|
171
|
+
const pluginResult = plugin(input);
|
|
172
|
+
if (Array.isArray(pluginResult)) {
|
|
173
|
+
pluginHandled = true;
|
|
174
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
|
175
|
+
str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
|
176
|
+
if (rest.length > 0) {
|
|
177
|
+
str[index] += `,${rest.map((v) => flatten.call(this, v)).join(",")}`;
|
|
178
|
+
}
|
|
179
|
+
str[index] += "]";
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!pluginHandled) {
|
|
185
|
+
throw new Error("Cannot encode function or unexpected type");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
168
188
|
}
|
|
169
189
|
}
|
|
170
190
|
var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
@@ -432,6 +452,8 @@ function encode(input, options) {
|
|
|
432
452
|
`
|
|
433
453
|
)
|
|
434
454
|
);
|
|
455
|
+
encoder.index++;
|
|
456
|
+
lastSentIndex++;
|
|
435
457
|
} else if (id2 < 0) {
|
|
436
458
|
controller.enqueue(
|
|
437
459
|
textEncoder.encode(`${TYPE_PROMISE}${deferredId}:${id2}
|
|
@@ -460,6 +482,8 @@ function encode(input, options) {
|
|
|
460
482
|
`
|
|
461
483
|
)
|
|
462
484
|
);
|
|
485
|
+
encoder.index++;
|
|
486
|
+
lastSentIndex++;
|
|
463
487
|
} else if (id2 < 0) {
|
|
464
488
|
controller.enqueue(
|
|
465
489
|
textEncoder.encode(`${TYPE_ERROR}${deferredId}:${id2}
|
package/package.json
CHANGED