react-server-dom-webpack 19.0.0-canary-657428a9e-20240416 → 19.0.0-canary-36e62c603-20240418

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.
@@ -1,2398 +0,0 @@
1
- /**
2
- * @license React
3
- * react-server-dom-webpack-client.browser.development.js
4
- *
5
- * Copyright (c) Meta Platforms, Inc. and affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
-
11
- (function (global, factory) {
12
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react-dom'), require('react')) :
13
- typeof define === 'function' && define.amd ? define(['exports', 'react-dom', 'react'], factory) :
14
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactServerDOMClient = {}, global.ReactDOM, global.React));
15
- })(this, (function (exports, ReactDOM, React) { 'use strict';
16
-
17
- // -----------------------------------------------------------------------------
18
- var enableBinaryFlight = false;
19
-
20
- function createStringDecoder() {
21
- return new TextDecoder();
22
- }
23
- var decoderOptions = {
24
- stream: true
25
- };
26
- function readPartialStringChunk(decoder, buffer) {
27
- return decoder.decode(buffer, decoderOptions);
28
- }
29
- function readFinalStringChunk(decoder, buffer) {
30
- return decoder.decode(buffer);
31
- }
32
-
33
- var badgeFormat = '%c%s%c '; // Same badge styling as DevTools.
34
-
35
- var badgeStyle = // We use a fixed background if light-dark is not supported, otherwise
36
- // we use a transparent background.
37
- 'background: #e6e6e6;' + 'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' + 'color: #000000;' + 'color: light-dark(#000000, #ffffff);' + 'border-radius: 2px';
38
- var resetStyle = '';
39
- var pad = ' ';
40
- function printToConsole(methodName, args, badgeName) {
41
- var offset = 0;
42
-
43
- switch (methodName) {
44
- case 'dir':
45
- case 'dirxml':
46
- case 'groupEnd':
47
- case 'table':
48
- {
49
- // These methods cannot be colorized because they don't take a formatting string.
50
- // eslint-disable-next-line react-internal/no-production-logging
51
- console[methodName].apply(console, args);
52
- return;
53
- }
54
-
55
- case 'assert':
56
- {
57
- // assert takes formatting options as the second argument.
58
- offset = 1;
59
- }
60
- }
61
-
62
- var newArgs = args.slice(0);
63
-
64
- if (typeof newArgs[offset] === 'string') {
65
- newArgs.splice(offset, 1, badgeFormat + newArgs[offset], badgeStyle, pad + badgeName + pad, resetStyle);
66
- } else {
67
- newArgs.splice(offset, 0, badgeFormat, badgeStyle, pad + badgeName + pad, resetStyle);
68
- } // eslint-disable-next-line react-internal/no-production-logging
69
-
70
-
71
- console[methodName].apply(console, newArgs);
72
- return;
73
- }
74
-
75
- // This is the parsed shape of the wire format which is why it is
76
- // condensed to only the essentialy information
77
- var ID = 0;
78
- var CHUNKS = 1;
79
- var NAME = 2; // export const ASYNC = 3;
80
- // This logic is correct because currently only include the 4th tuple member
81
- // when the module is async. If that changes we will need to actually assert
82
- // the value is true. We don't index into the 4th slot because flow does not
83
- // like the potential out of bounds access
84
-
85
- function isAsyncImport(metadata) {
86
- return metadata.length === 4;
87
- }
88
-
89
- function resolveClientReference(bundlerConfig, metadata) {
90
- if (bundlerConfig) {
91
- var moduleExports = bundlerConfig[metadata[ID]];
92
- var resolvedModuleData = moduleExports[metadata[NAME]];
93
- var name;
94
-
95
- if (resolvedModuleData) {
96
- // The potentially aliased name.
97
- name = resolvedModuleData.name;
98
- } else {
99
- // If we don't have this specific name, we might have the full module.
100
- resolvedModuleData = moduleExports['*'];
101
-
102
- if (!resolvedModuleData) {
103
- throw new Error('Could not find the module "' + metadata[ID] + '" in the React SSR Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
104
- }
105
-
106
- name = metadata[NAME];
107
- }
108
-
109
- if (isAsyncImport(metadata)) {
110
- return [resolvedModuleData.id, resolvedModuleData.chunks, name, 1
111
- /* async */
112
- ];
113
- } else {
114
- return [resolvedModuleData.id, resolvedModuleData.chunks, name];
115
- }
116
- }
117
-
118
- return metadata;
119
- }
120
- // If they're still pending they're a thenable. This map also exists
121
- // in Webpack but unfortunately it's not exposed so we have to
122
- // replicate it in user space. null means that it has already loaded.
123
-
124
- var chunkCache = new Map();
125
-
126
- function requireAsyncModule(id) {
127
- // We've already loaded all the chunks. We can require the module.
128
- var promise = __webpack_require__(id);
129
-
130
- if (typeof promise.then !== 'function') {
131
- // This wasn't a promise after all.
132
- return null;
133
- } else if (promise.status === 'fulfilled') {
134
- // This module was already resolved earlier.
135
- return null;
136
- } else {
137
- // Instrument the Promise to stash the result.
138
- promise.then(function (value) {
139
- var fulfilledThenable = promise;
140
- fulfilledThenable.status = 'fulfilled';
141
- fulfilledThenable.value = value;
142
- }, function (reason) {
143
- var rejectedThenable = promise;
144
- rejectedThenable.status = 'rejected';
145
- rejectedThenable.reason = reason;
146
- });
147
- return promise;
148
- }
149
- }
150
-
151
- function ignoreReject() {// We rely on rejected promises to be handled by another listener.
152
- } // Start preloading the modules since we might need them soon.
153
- // This function doesn't suspend.
154
-
155
-
156
- function preloadModule(metadata) {
157
- var chunks = metadata[CHUNKS];
158
- var promises = [];
159
- var i = 0;
160
-
161
- while (i < chunks.length) {
162
- var chunkId = chunks[i++];
163
- var chunkFilename = chunks[i++];
164
- var entry = chunkCache.get(chunkId);
165
-
166
- if (entry === undefined) {
167
- var thenable = loadChunk(chunkId, chunkFilename);
168
- promises.push(thenable); // $FlowFixMe[method-unbinding]
169
-
170
- var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
171
- thenable.then(resolve, ignoreReject);
172
- chunkCache.set(chunkId, thenable);
173
- } else if (entry !== null) {
174
- promises.push(entry);
175
- }
176
- }
177
-
178
- if (isAsyncImport(metadata)) {
179
- if (promises.length === 0) {
180
- return requireAsyncModule(metadata[ID]);
181
- } else {
182
- return Promise.all(promises).then(function () {
183
- return requireAsyncModule(metadata[ID]);
184
- });
185
- }
186
- } else if (promises.length > 0) {
187
- return Promise.all(promises);
188
- } else {
189
- return null;
190
- }
191
- } // Actually require the module or suspend if it's not yet ready.
192
- // Increase priority if necessary.
193
-
194
- function requireModule(metadata) {
195
- var moduleExports = __webpack_require__(metadata[ID]);
196
-
197
- if (isAsyncImport(metadata)) {
198
- if (typeof moduleExports.then !== 'function') ; else if (moduleExports.status === 'fulfilled') {
199
- // This Promise should've been instrumented by preloadModule.
200
- moduleExports = moduleExports.value;
201
- } else {
202
- throw moduleExports.reason;
203
- }
204
- }
205
-
206
- if (metadata[NAME] === '*') {
207
- // This is a placeholder value that represents that the caller imported this
208
- // as a CommonJS module as is.
209
- return moduleExports;
210
- }
211
-
212
- if (metadata[NAME] === '') {
213
- // This is a placeholder value that represents that the caller accessed the
214
- // default property of this if it was an ESM interop module.
215
- return moduleExports.__esModule ? moduleExports.default : moduleExports;
216
- }
217
-
218
- return moduleExports[metadata[NAME]];
219
- }
220
-
221
- var chunkMap = new Map();
222
- /**
223
- * We patch the chunk filename function in webpack to insert our own resolution
224
- * of chunks that come from Flight and may not be known to the webpack runtime
225
- */
226
-
227
- var webpackGetChunkFilename = __webpack_require__.u;
228
-
229
- __webpack_require__.u = function (chunkId) {
230
- var flightChunk = chunkMap.get(chunkId);
231
-
232
- if (flightChunk !== undefined) {
233
- return flightChunk;
234
- }
235
-
236
- return webpackGetChunkFilename(chunkId);
237
- };
238
-
239
- function loadChunk(chunkId, filename) {
240
- chunkMap.set(chunkId, filename);
241
- return __webpack_chunk_load__(chunkId);
242
- }
243
-
244
- var ReactDOMSharedInternals = ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
245
-
246
- // This client file is in the shared folder because it applies to both SSR and browser contexts.
247
- function dispatchHint(code, model) {
248
- var dispatcher = ReactDOMSharedInternals.d;
249
- /* ReactDOMCurrentDispatcher */
250
-
251
- switch (code) {
252
- case 'D':
253
- {
254
- var refined = refineModel(code, model);
255
- var href = refined;
256
- dispatcher.D(
257
- /* prefetchDNS */
258
- href);
259
- return;
260
- }
261
-
262
- case 'C':
263
- {
264
- var _refined = refineModel(code, model);
265
-
266
- if (typeof _refined === 'string') {
267
- var _href = _refined;
268
- dispatcher.C(
269
- /* preconnect */
270
- _href);
271
- } else {
272
- var _href2 = _refined[0];
273
- var crossOrigin = _refined[1];
274
- dispatcher.C(
275
- /* preconnect */
276
- _href2, crossOrigin);
277
- }
278
-
279
- return;
280
- }
281
-
282
- case 'L':
283
- {
284
- var _refined2 = refineModel(code, model);
285
-
286
- var _href3 = _refined2[0];
287
- var as = _refined2[1];
288
-
289
- if (_refined2.length === 3) {
290
- var options = _refined2[2];
291
- dispatcher.L(
292
- /* preload */
293
- _href3, as, options);
294
- } else {
295
- dispatcher.L(
296
- /* preload */
297
- _href3, as);
298
- }
299
-
300
- return;
301
- }
302
-
303
- case 'm':
304
- {
305
- var _refined3 = refineModel(code, model);
306
-
307
- if (typeof _refined3 === 'string') {
308
- var _href4 = _refined3;
309
- dispatcher.m(
310
- /* preloadModule */
311
- _href4);
312
- } else {
313
- var _href5 = _refined3[0];
314
- var _options = _refined3[1];
315
- dispatcher.m(
316
- /* preloadModule */
317
- _href5, _options);
318
- }
319
-
320
- return;
321
- }
322
-
323
- case 'X':
324
- {
325
- var _refined4 = refineModel(code, model);
326
-
327
- if (typeof _refined4 === 'string') {
328
- var _href6 = _refined4;
329
- dispatcher.X(
330
- /* preinitScript */
331
- _href6);
332
- } else {
333
- var _href7 = _refined4[0];
334
- var _options2 = _refined4[1];
335
- dispatcher.X(
336
- /* preinitScript */
337
- _href7, _options2);
338
- }
339
-
340
- return;
341
- }
342
-
343
- case 'S':
344
- {
345
- var _refined5 = refineModel(code, model);
346
-
347
- if (typeof _refined5 === 'string') {
348
- var _href8 = _refined5;
349
- dispatcher.S(
350
- /* preinitStyle */
351
- _href8);
352
- } else {
353
- var _href9 = _refined5[0];
354
- var precedence = _refined5[1] === 0 ? undefined : _refined5[1];
355
-
356
- var _options3 = _refined5.length === 3 ? _refined5[2] : undefined;
357
-
358
- dispatcher.S(
359
- /* preinitStyle */
360
- _href9, precedence, _options3);
361
- }
362
-
363
- return;
364
- }
365
-
366
- case 'M':
367
- {
368
- var _refined6 = refineModel(code, model);
369
-
370
- if (typeof _refined6 === 'string') {
371
- var _href10 = _refined6;
372
- dispatcher.M(
373
- /* preinitModuleScript */
374
- _href10);
375
- } else {
376
- var _href11 = _refined6[0];
377
- var _options4 = _refined6[1];
378
- dispatcher.M(
379
- /* preinitModuleScript */
380
- _href11, _options4);
381
- }
382
-
383
- return;
384
- }
385
- }
386
- } // Flow is having trouble refining the HintModels so we help it a bit.
387
- // This should be compiled out in the production build.
388
-
389
- function refineModel(code, model) {
390
- return model;
391
- }
392
-
393
- var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
394
-
395
- function error(format) {
396
- {
397
- {
398
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
399
- args[_key2 - 1] = arguments[_key2];
400
- }
401
-
402
- printWarning('error', format, args);
403
- }
404
- }
405
- }
406
-
407
- function printWarning(level, format, args) {
408
- // When changing this logic, you might want to also
409
- // update consoleWithStackDev.www.js as well.
410
- {
411
- var stack = ReactSharedInternals.getStackAddendum();
412
-
413
- if (stack !== '') {
414
- format += '%s';
415
- args = args.concat([stack]);
416
- } // eslint-disable-next-line react-internal/safe-string-coercion
417
-
418
-
419
- var argsWithFormat = args.map(function (item) {
420
- return String(item);
421
- }); // Careful: RN currently depends on this prefix
422
-
423
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
424
- // breaks IE9: https://github.com/facebook/react/issues/13610
425
- // eslint-disable-next-line react-internal/no-production-logging
426
-
427
- Function.prototype.apply.call(console[level], console, argsWithFormat);
428
- }
429
- }
430
-
431
- // ATTENTION
432
- // When adding new symbols to this file,
433
- // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
434
- // The Symbol used to tag the ReactElement-like types.
435
- var REACT_ELEMENT_TYPE = Symbol.for('react.element');
436
- var REACT_CONTEXT_TYPE = Symbol.for('react.context');
437
- var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
438
- var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
439
- var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
440
- var REACT_MEMO_TYPE = Symbol.for('react.memo');
441
- var REACT_LAZY_TYPE = Symbol.for('react.lazy');
442
- var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
443
- var FAUX_ITERATOR_SYMBOL = '@@iterator';
444
- function getIteratorFn(maybeIterable) {
445
- if (maybeIterable === null || typeof maybeIterable !== 'object') {
446
- return null;
447
- }
448
-
449
- var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
450
-
451
- if (typeof maybeIterator === 'function') {
452
- return maybeIterator;
453
- }
454
-
455
- return null;
456
- }
457
-
458
- var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
459
-
460
- function isArray(a) {
461
- return isArrayImpl(a);
462
- }
463
-
464
- var getPrototypeOf = Object.getPrototypeOf;
465
-
466
- // in case they error.
467
-
468
- var jsxPropsParents = new WeakMap();
469
- var jsxChildrenParents = new WeakMap();
470
-
471
- function isObjectPrototype(object) {
472
- if (!object) {
473
- return false;
474
- }
475
-
476
- var ObjectPrototype = Object.prototype;
477
-
478
- if (object === ObjectPrototype) {
479
- return true;
480
- } // It might be an object from a different Realm which is
481
- // still just a plain simple object.
482
-
483
-
484
- if (getPrototypeOf(object)) {
485
- return false;
486
- }
487
-
488
- var names = Object.getOwnPropertyNames(object);
489
-
490
- for (var i = 0; i < names.length; i++) {
491
- if (!(names[i] in ObjectPrototype)) {
492
- return false;
493
- }
494
- }
495
-
496
- return true;
497
- }
498
-
499
- function isSimpleObject(object) {
500
- if (!isObjectPrototype(getPrototypeOf(object))) {
501
- return false;
502
- }
503
-
504
- var names = Object.getOwnPropertyNames(object);
505
-
506
- for (var i = 0; i < names.length; i++) {
507
- var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
508
-
509
- if (!descriptor) {
510
- return false;
511
- }
512
-
513
- if (!descriptor.enumerable) {
514
- if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
515
- // React adds key and ref getters to props objects to issue warnings.
516
- // Those getters will not be transferred to the client, but that's ok,
517
- // so we'll special case them.
518
- continue;
519
- }
520
-
521
- return false;
522
- }
523
- }
524
-
525
- return true;
526
- }
527
- function objectName(object) {
528
- // $FlowFixMe[method-unbinding]
529
- var name = Object.prototype.toString.call(object);
530
- return name.replace(/^\[object (.*)\]$/, function (m, p0) {
531
- return p0;
532
- });
533
- }
534
-
535
- function describeKeyForErrorMessage(key) {
536
- var encodedKey = JSON.stringify(key);
537
- return '"' + key + '"' === encodedKey ? key : encodedKey;
538
- }
539
-
540
- function describeValueForErrorMessage(value) {
541
- switch (typeof value) {
542
- case 'string':
543
- {
544
- return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
545
- }
546
-
547
- case 'object':
548
- {
549
- if (isArray(value)) {
550
- return '[...]';
551
- }
552
-
553
- if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
554
- return describeClientReference();
555
- }
556
-
557
- var name = objectName(value);
558
-
559
- if (name === 'Object') {
560
- return '{...}';
561
- }
562
-
563
- return name;
564
- }
565
-
566
- case 'function':
567
- {
568
- if (value.$$typeof === CLIENT_REFERENCE_TAG) {
569
- return describeClientReference();
570
- }
571
-
572
- var _name = value.displayName || value.name;
573
-
574
- return _name ? 'function ' + _name : 'function';
575
- }
576
-
577
- default:
578
- // eslint-disable-next-line react-internal/safe-string-coercion
579
- return String(value);
580
- }
581
- }
582
-
583
- function describeElementType(type) {
584
- if (typeof type === 'string') {
585
- return type;
586
- }
587
-
588
- switch (type) {
589
- case REACT_SUSPENSE_TYPE:
590
- return 'Suspense';
591
-
592
- case REACT_SUSPENSE_LIST_TYPE:
593
- return 'SuspenseList';
594
- }
595
-
596
- if (typeof type === 'object') {
597
- switch (type.$$typeof) {
598
- case REACT_FORWARD_REF_TYPE:
599
- return describeElementType(type.render);
600
-
601
- case REACT_MEMO_TYPE:
602
- return describeElementType(type.type);
603
-
604
- case REACT_LAZY_TYPE:
605
- {
606
- var lazyComponent = type;
607
- var payload = lazyComponent._payload;
608
- var init = lazyComponent._init;
609
-
610
- try {
611
- // Lazy may contain any component type so we recursively resolve it.
612
- return describeElementType(init(payload));
613
- } catch (x) {}
614
- }
615
- }
616
- }
617
-
618
- return '';
619
- }
620
-
621
- var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
622
-
623
- function describeClientReference(ref) {
624
- return 'client';
625
- }
626
-
627
- function describeObjectForErrorMessage(objectOrArray, expandedName) {
628
- var objKind = objectName(objectOrArray);
629
-
630
- if (objKind !== 'Object' && objKind !== 'Array') {
631
- return objKind;
632
- }
633
-
634
- var str = '';
635
- var start = -1;
636
- var length = 0;
637
-
638
- if (isArray(objectOrArray)) {
639
- if (jsxChildrenParents.has(objectOrArray)) {
640
- // Print JSX Children
641
- var type = jsxChildrenParents.get(objectOrArray);
642
- str = '<' + describeElementType(type) + '>';
643
- var array = objectOrArray;
644
-
645
- for (var i = 0; i < array.length; i++) {
646
- var value = array[i];
647
- var substr = void 0;
648
-
649
- if (typeof value === 'string') {
650
- substr = value;
651
- } else if (typeof value === 'object' && value !== null) {
652
- substr = '{' + describeObjectForErrorMessage(value) + '}';
653
- } else {
654
- substr = '{' + describeValueForErrorMessage(value) + '}';
655
- }
656
-
657
- if ('' + i === expandedName) {
658
- start = str.length;
659
- length = substr.length;
660
- str += substr;
661
- } else if (substr.length < 15 && str.length + substr.length < 40) {
662
- str += substr;
663
- } else {
664
- str += '{...}';
665
- }
666
- }
667
-
668
- str += '</' + describeElementType(type) + '>';
669
- } else {
670
- // Print Array
671
- str = '[';
672
- var _array = objectOrArray;
673
-
674
- for (var _i = 0; _i < _array.length; _i++) {
675
- if (_i > 0) {
676
- str += ', ';
677
- }
678
-
679
- var _value = _array[_i];
680
-
681
- var _substr = void 0;
682
-
683
- if (typeof _value === 'object' && _value !== null) {
684
- _substr = describeObjectForErrorMessage(_value);
685
- } else {
686
- _substr = describeValueForErrorMessage(_value);
687
- }
688
-
689
- if ('' + _i === expandedName) {
690
- start = str.length;
691
- length = _substr.length;
692
- str += _substr;
693
- } else if (_substr.length < 10 && str.length + _substr.length < 40) {
694
- str += _substr;
695
- } else {
696
- str += '...';
697
- }
698
- }
699
-
700
- str += ']';
701
- }
702
- } else {
703
- if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
704
- str = '<' + describeElementType(objectOrArray.type) + '/>';
705
- } else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
706
- return describeClientReference();
707
- } else if (jsxPropsParents.has(objectOrArray)) {
708
- // Print JSX
709
- var _type = jsxPropsParents.get(objectOrArray);
710
-
711
- str = '<' + (describeElementType(_type) || '...');
712
- var object = objectOrArray;
713
- var names = Object.keys(object);
714
-
715
- for (var _i2 = 0; _i2 < names.length; _i2++) {
716
- str += ' ';
717
- var name = names[_i2];
718
- str += describeKeyForErrorMessage(name) + '=';
719
- var _value2 = object[name];
720
-
721
- var _substr2 = void 0;
722
-
723
- if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
724
- _substr2 = describeObjectForErrorMessage(_value2);
725
- } else {
726
- _substr2 = describeValueForErrorMessage(_value2);
727
- }
728
-
729
- if (typeof _value2 !== 'string') {
730
- _substr2 = '{' + _substr2 + '}';
731
- }
732
-
733
- if (name === expandedName) {
734
- start = str.length;
735
- length = _substr2.length;
736
- str += _substr2;
737
- } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
738
- str += _substr2;
739
- } else {
740
- str += '...';
741
- }
742
- }
743
-
744
- str += '>';
745
- } else {
746
- // Print Object
747
- str = '{';
748
- var _object = objectOrArray;
749
-
750
- var _names = Object.keys(_object);
751
-
752
- for (var _i3 = 0; _i3 < _names.length; _i3++) {
753
- if (_i3 > 0) {
754
- str += ', ';
755
- }
756
-
757
- var _name2 = _names[_i3];
758
- str += describeKeyForErrorMessage(_name2) + ': ';
759
- var _value3 = _object[_name2];
760
-
761
- var _substr3 = void 0;
762
-
763
- if (typeof _value3 === 'object' && _value3 !== null) {
764
- _substr3 = describeObjectForErrorMessage(_value3);
765
- } else {
766
- _substr3 = describeValueForErrorMessage(_value3);
767
- }
768
-
769
- if (_name2 === expandedName) {
770
- start = str.length;
771
- length = _substr3.length;
772
- str += _substr3;
773
- } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
774
- str += _substr3;
775
- } else {
776
- str += '...';
777
- }
778
- }
779
-
780
- str += '}';
781
- }
782
- }
783
-
784
- if (expandedName === undefined) {
785
- return str;
786
- }
787
-
788
- if (start > -1 && length > 0) {
789
- var highlight = ' '.repeat(start) + '^'.repeat(length);
790
- return '\n ' + str + '\n ' + highlight;
791
- }
792
-
793
- return '\n ' + str;
794
- }
795
-
796
- function createTemporaryReferenceSet() {
797
- return [];
798
- }
799
- function writeTemporaryReference(set, object) {
800
- // We always create a new entry regardless if we've already written the same
801
- // object. This ensures that we always generate a deterministic encoding of
802
- // each slot in the reply for cacheability.
803
- var newId = set.length;
804
- set.push(object);
805
- return newId;
806
- }
807
- function readTemporaryReference(set, id) {
808
- if (id < 0 || id >= set.length) {
809
- throw new Error("The RSC response contained a reference that doesn't exist in the temporary reference set. " + 'Always pass the matching set that was used to create the reply when parsing its response.');
810
- }
811
-
812
- return set[id];
813
- }
814
-
815
- var ObjectPrototype = Object.prototype;
816
- var knownServerReferences = new WeakMap(); // Serializable values
817
- // Thenable<ReactServerValue>
818
-
819
- function serializeByValueID(id) {
820
- return '$' + id.toString(16);
821
- }
822
-
823
- function serializePromiseID(id) {
824
- return '$@' + id.toString(16);
825
- }
826
-
827
- function serializeServerReferenceID(id) {
828
- return '$F' + id.toString(16);
829
- }
830
-
831
- function serializeTemporaryReferenceID(id) {
832
- return '$T' + id.toString(16);
833
- }
834
-
835
- function serializeFormDataReference(id) {
836
- // Why K? F is "Function". D is "Date". What else?
837
- return '$K' + id.toString(16);
838
- }
839
-
840
- function serializeNumber(number) {
841
- if (Number.isFinite(number)) {
842
- if (number === 0 && 1 / number === -Infinity) {
843
- return '$-0';
844
- } else {
845
- return number;
846
- }
847
- } else {
848
- if (number === Infinity) {
849
- return '$Infinity';
850
- } else if (number === -Infinity) {
851
- return '$-Infinity';
852
- } else {
853
- return '$NaN';
854
- }
855
- }
856
- }
857
-
858
- function serializeUndefined() {
859
- return '$undefined';
860
- }
861
-
862
- function serializeDateFromDateJSON(dateJSON) {
863
- // JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
864
- // We need only tack on a $D prefix.
865
- return '$D' + dateJSON;
866
- }
867
-
868
- function serializeBigInt(n) {
869
- return '$n' + n.toString(10);
870
- }
871
-
872
- function serializeMapID(id) {
873
- return '$Q' + id.toString(16);
874
- }
875
-
876
- function serializeSetID(id) {
877
- return '$W' + id.toString(16);
878
- }
879
-
880
- function escapeStringValue(value) {
881
- if (value[0] === '$') {
882
- // We need to escape $ prefixed strings since we use those to encode
883
- // references to IDs and as special symbol values.
884
- return '$' + value;
885
- } else {
886
- return value;
887
- }
888
- }
889
-
890
- function processReply(root, formFieldPrefix, temporaryReferences, resolve, reject) {
891
- var nextPartId = 1;
892
- var pendingParts = 0;
893
- var formData = null;
894
-
895
- function resolveToJSON(key, value) {
896
- var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
897
-
898
- {
899
- // $FlowFixMe[incompatible-use]
900
- var originalValue = parent[key];
901
-
902
- if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
903
- if (objectName(originalValue) !== 'Object') {
904
- error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
905
- } else {
906
- error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, key));
907
- }
908
- }
909
- }
910
-
911
- if (value === null) {
912
- return null;
913
- }
914
-
915
- if (typeof value === 'object') {
916
- switch (value.$$typeof) {
917
- case REACT_ELEMENT_TYPE:
918
- {
919
- if (temporaryReferences === undefined) {
920
- throw new Error('React Element cannot be passed to Server Functions from the Client without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
921
- }
922
-
923
- return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
924
- }
925
-
926
- case REACT_LAZY_TYPE:
927
- {
928
- // Resolve lazy as if it wasn't here. In the future this will be encoded as a Promise.
929
- var lazy = value;
930
- var payload = lazy._payload;
931
- var init = lazy._init;
932
-
933
- if (formData === null) {
934
- // Upgrade to use FormData to allow us to stream this value.
935
- formData = new FormData();
936
- }
937
-
938
- pendingParts++;
939
-
940
- try {
941
- var resolvedModel = init(payload); // We always outline this as a separate part even though we could inline it
942
- // because it ensures a more deterministic encoding.
943
-
944
- var lazyId = nextPartId++;
945
- var partJSON = JSON.stringify(resolvedModel, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
946
-
947
- var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
948
-
949
- data.append(formFieldPrefix + lazyId, partJSON);
950
- return serializeByValueID(lazyId);
951
- } catch (x) {
952
- if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
953
- // Suspended
954
- pendingParts++;
955
-
956
- var _lazyId = nextPartId++;
957
-
958
- var thenable = x;
959
-
960
- var retry = function () {
961
- // While the first promise resolved, its value isn't necessarily what we'll
962
- // resolve into because we might suspend again.
963
- try {
964
- var _partJSON = JSON.stringify(value, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
965
-
966
-
967
- var _data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
968
-
969
- _data.append(formFieldPrefix + _lazyId, _partJSON);
970
-
971
- pendingParts--;
972
-
973
- if (pendingParts === 0) {
974
- resolve(_data);
975
- }
976
- } catch (reason) {
977
- reject(reason);
978
- }
979
- };
980
-
981
- thenable.then(retry, retry);
982
- return serializeByValueID(_lazyId);
983
- } else {
984
- // In the future we could consider serializing this as an error
985
- // that throws on the server instead.
986
- reject(x);
987
- return null;
988
- }
989
- } finally {
990
- pendingParts--;
991
- }
992
- }
993
- } // $FlowFixMe[method-unbinding]
994
-
995
-
996
- if (typeof value.then === 'function') {
997
- // We assume that any object with a .then property is a "Thenable" type,
998
- // or a Promise type. Either of which can be represented by a Promise.
999
- if (formData === null) {
1000
- // Upgrade to use FormData to allow us to stream this value.
1001
- formData = new FormData();
1002
- }
1003
-
1004
- pendingParts++;
1005
- var promiseId = nextPartId++;
1006
- var _thenable = value;
1007
-
1008
- _thenable.then(function (partValue) {
1009
- try {
1010
- var _partJSON2 = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
1011
-
1012
-
1013
- var _data2 = formData; // eslint-disable-next-line react-internal/safe-string-coercion
1014
-
1015
- _data2.append(formFieldPrefix + promiseId, _partJSON2);
1016
-
1017
- pendingParts--;
1018
-
1019
- if (pendingParts === 0) {
1020
- resolve(_data2);
1021
- }
1022
- } catch (reason) {
1023
- reject(reason);
1024
- }
1025
- }, function (reason) {
1026
- // In the future we could consider serializing this as an error
1027
- // that throws on the server instead.
1028
- reject(reason);
1029
- });
1030
-
1031
- return serializePromiseID(promiseId);
1032
- }
1033
-
1034
- if (isArray(value)) {
1035
- // $FlowFixMe[incompatible-return]
1036
- return value;
1037
- } // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
1038
-
1039
-
1040
- if (value instanceof FormData) {
1041
- if (formData === null) {
1042
- // Upgrade to use FormData to allow us to use rich objects as its values.
1043
- formData = new FormData();
1044
- }
1045
-
1046
- var _data3 = formData;
1047
- var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
1048
- // These must come first in the form order because we assume that all the
1049
- // fields are available before this is referenced.
1050
-
1051
- var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
1052
-
1053
- value.forEach(function (originalValue, originalKey) {
1054
- _data3.append(prefix + originalKey, originalValue);
1055
- });
1056
- return serializeFormDataReference(refId);
1057
- }
1058
-
1059
- if (value instanceof Map) {
1060
- var _partJSON3 = JSON.stringify(Array.from(value), resolveToJSON);
1061
-
1062
- if (formData === null) {
1063
- formData = new FormData();
1064
- }
1065
-
1066
- var mapId = nextPartId++;
1067
- formData.append(formFieldPrefix + mapId, _partJSON3);
1068
- return serializeMapID(mapId);
1069
- }
1070
-
1071
- if (value instanceof Set) {
1072
- var _partJSON4 = JSON.stringify(Array.from(value), resolveToJSON);
1073
-
1074
- if (formData === null) {
1075
- formData = new FormData();
1076
- }
1077
-
1078
- var setId = nextPartId++;
1079
- formData.append(formFieldPrefix + setId, _partJSON4);
1080
- return serializeSetID(setId);
1081
- }
1082
-
1083
- var iteratorFn = getIteratorFn(value);
1084
-
1085
- if (iteratorFn) {
1086
- return Array.from(value);
1087
- } // Verify that this is a simple plain object.
1088
-
1089
-
1090
- var proto = getPrototypeOf(value);
1091
-
1092
- if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
1093
- if (temporaryReferences === undefined) {
1094
- throw new Error('Only plain objects, and a few built-ins, can be passed to Server Actions. ' + 'Classes or null prototypes are not supported.');
1095
- } // We can serialize class instances as temporary references.
1096
-
1097
-
1098
- return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1099
- }
1100
-
1101
- {
1102
- if (value.$$typeof === (REACT_CONTEXT_TYPE )) {
1103
- error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
1104
- } else if (objectName(value) !== 'Object') {
1105
- error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
1106
- } else if (!isSimpleObject(value)) {
1107
- error('Only plain objects can be passed to Server Functions from the Client. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
1108
- } else if (Object.getOwnPropertySymbols) {
1109
- var symbols = Object.getOwnPropertySymbols(value);
1110
-
1111
- if (symbols.length > 0) {
1112
- error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
1113
- }
1114
- }
1115
- } // $FlowFixMe[incompatible-return]
1116
-
1117
-
1118
- return value;
1119
- }
1120
-
1121
- if (typeof value === 'string') {
1122
- // TODO: Maybe too clever. If we support URL there's no similar trick.
1123
- if (value[value.length - 1] === 'Z') {
1124
- // Possibly a Date, whose toJSON automatically calls toISOString
1125
- // $FlowFixMe[incompatible-use]
1126
- var _originalValue = parent[key];
1127
-
1128
- if (_originalValue instanceof Date) {
1129
- return serializeDateFromDateJSON(value);
1130
- }
1131
- }
1132
-
1133
- return escapeStringValue(value);
1134
- }
1135
-
1136
- if (typeof value === 'boolean') {
1137
- return value;
1138
- }
1139
-
1140
- if (typeof value === 'number') {
1141
- return serializeNumber(value);
1142
- }
1143
-
1144
- if (typeof value === 'undefined') {
1145
- return serializeUndefined();
1146
- }
1147
-
1148
- if (typeof value === 'function') {
1149
- var metaData = knownServerReferences.get(value);
1150
-
1151
- if (metaData !== undefined) {
1152
- var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
1153
-
1154
- if (formData === null) {
1155
- // Upgrade to use FormData to allow us to stream this value.
1156
- formData = new FormData();
1157
- } // The reference to this function came from the same client so we can pass it back.
1158
-
1159
-
1160
- var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
1161
-
1162
-
1163
- formData.set(formFieldPrefix + _refId, metaDataJSON);
1164
- return serializeServerReferenceID(_refId);
1165
- }
1166
-
1167
- if (temporaryReferences === undefined) {
1168
- throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
1169
- }
1170
-
1171
- return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1172
- }
1173
-
1174
- if (typeof value === 'symbol') {
1175
- if (temporaryReferences === undefined) {
1176
- throw new Error('Symbols cannot be passed to a Server Function without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
1177
- }
1178
-
1179
- return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
1180
- }
1181
-
1182
- if (typeof value === 'bigint') {
1183
- return serializeBigInt(value);
1184
- }
1185
-
1186
- throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
1187
- } // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
1188
-
1189
-
1190
- var json = JSON.stringify(root, resolveToJSON);
1191
-
1192
- if (formData === null) {
1193
- // If it's a simple data structure, we just use plain JSON.
1194
- resolve(json);
1195
- } else {
1196
- // Otherwise, we use FormData to let us stream in the result.
1197
- formData.set(formFieldPrefix + '0', json);
1198
-
1199
- if (pendingParts === 0) {
1200
- // $FlowFixMe[incompatible-call] this has already been refined.
1201
- resolve(formData);
1202
- }
1203
- }
1204
- }
1205
-
1206
- function registerServerReference(proxy, reference, encodeFormAction) {
1207
-
1208
- knownServerReferences.set(proxy, reference);
1209
- } // $FlowFixMe[method-unbinding]
1210
-
1211
- function createServerReference(id, callServer, encodeFormAction) {
1212
- var proxy = function () {
1213
- // $FlowFixMe[method-unbinding]
1214
- var args = Array.prototype.slice.call(arguments);
1215
- return callServer(id, args);
1216
- };
1217
-
1218
- registerServerReference(proxy, {
1219
- id: id,
1220
- bound: null
1221
- });
1222
- return proxy;
1223
- }
1224
-
1225
- var ROW_ID = 0;
1226
- var ROW_TAG = 1;
1227
- var ROW_LENGTH = 2;
1228
- var ROW_CHUNK_BY_NEWLINE = 3;
1229
- var ROW_CHUNK_BY_LENGTH = 4;
1230
- var PENDING = 'pending';
1231
- var BLOCKED = 'blocked';
1232
- var CYCLIC = 'cyclic';
1233
- var RESOLVED_MODEL = 'resolved_model';
1234
- var RESOLVED_MODULE = 'resolved_module';
1235
- var INITIALIZED = 'fulfilled';
1236
- var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
1237
-
1238
- function Chunk(status, value, reason, response) {
1239
- this.status = status;
1240
- this.value = value;
1241
- this.reason = reason;
1242
- this._response = response;
1243
-
1244
- {
1245
- this._debugInfo = null;
1246
- }
1247
- } // We subclass Promise.prototype so that we get other methods like .catch
1248
-
1249
-
1250
- Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
1251
-
1252
- Chunk.prototype.then = function (resolve, reject) {
1253
- var chunk = this; // If we have resolved content, we try to initialize it first which
1254
- // might put us back into one of the other states.
1255
-
1256
- switch (chunk.status) {
1257
- case RESOLVED_MODEL:
1258
- initializeModelChunk(chunk);
1259
- break;
1260
-
1261
- case RESOLVED_MODULE:
1262
- initializeModuleChunk(chunk);
1263
- break;
1264
- } // The status might have changed after initialization.
1265
-
1266
-
1267
- switch (chunk.status) {
1268
- case INITIALIZED:
1269
- resolve(chunk.value);
1270
- break;
1271
-
1272
- case PENDING:
1273
- case BLOCKED:
1274
- case CYCLIC:
1275
- if (resolve) {
1276
- if (chunk.value === null) {
1277
- chunk.value = [];
1278
- }
1279
-
1280
- chunk.value.push(resolve);
1281
- }
1282
-
1283
- if (reject) {
1284
- if (chunk.reason === null) {
1285
- chunk.reason = [];
1286
- }
1287
-
1288
- chunk.reason.push(reject);
1289
- }
1290
-
1291
- break;
1292
-
1293
- default:
1294
- if (reject) {
1295
- reject(chunk.reason);
1296
- }
1297
-
1298
- break;
1299
- }
1300
- };
1301
-
1302
- function readChunk(chunk) {
1303
- // If we have resolved content, we try to initialize it first which
1304
- // might put us back into one of the other states.
1305
- switch (chunk.status) {
1306
- case RESOLVED_MODEL:
1307
- initializeModelChunk(chunk);
1308
- break;
1309
-
1310
- case RESOLVED_MODULE:
1311
- initializeModuleChunk(chunk);
1312
- break;
1313
- } // The status might have changed after initialization.
1314
-
1315
-
1316
- switch (chunk.status) {
1317
- case INITIALIZED:
1318
- return chunk.value;
1319
-
1320
- case PENDING:
1321
- case BLOCKED:
1322
- case CYCLIC:
1323
- // eslint-disable-next-line no-throw-literal
1324
- throw chunk;
1325
-
1326
- default:
1327
- throw chunk.reason;
1328
- }
1329
- }
1330
-
1331
- function getRoot(response) {
1332
- var chunk = getChunk(response, 0);
1333
- return chunk;
1334
- }
1335
-
1336
- function createPendingChunk(response) {
1337
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1338
- return new Chunk(PENDING, null, null, response);
1339
- }
1340
-
1341
- function createBlockedChunk(response) {
1342
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1343
- return new Chunk(BLOCKED, null, null, response);
1344
- }
1345
-
1346
- function createErrorChunk(response, error) {
1347
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1348
- return new Chunk(ERRORED, null, error, response);
1349
- }
1350
-
1351
- function wakeChunk(listeners, value) {
1352
- for (var i = 0; i < listeners.length; i++) {
1353
- var listener = listeners[i];
1354
- listener(value);
1355
- }
1356
- }
1357
-
1358
- function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
1359
- switch (chunk.status) {
1360
- case INITIALIZED:
1361
- wakeChunk(resolveListeners, chunk.value);
1362
- break;
1363
-
1364
- case PENDING:
1365
- case BLOCKED:
1366
- case CYCLIC:
1367
- chunk.value = resolveListeners;
1368
- chunk.reason = rejectListeners;
1369
- break;
1370
-
1371
- case ERRORED:
1372
- if (rejectListeners) {
1373
- wakeChunk(rejectListeners, chunk.reason);
1374
- }
1375
-
1376
- break;
1377
- }
1378
- }
1379
-
1380
- function triggerErrorOnChunk(chunk, error) {
1381
- if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
1382
-
1383
- return;
1384
- }
1385
-
1386
- var listeners = chunk.reason;
1387
- var erroredChunk = chunk;
1388
- erroredChunk.status = ERRORED;
1389
- erroredChunk.reason = error;
1390
-
1391
- if (listeners !== null) {
1392
- wakeChunk(listeners, error);
1393
- }
1394
- }
1395
-
1396
- function createResolvedModelChunk(response, value) {
1397
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1398
- return new Chunk(RESOLVED_MODEL, value, null, response);
1399
- }
1400
-
1401
- function createResolvedModuleChunk(response, value) {
1402
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1403
- return new Chunk(RESOLVED_MODULE, value, null, response);
1404
- }
1405
-
1406
- function createInitializedTextChunk(response, value) {
1407
- // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1408
- return new Chunk(INITIALIZED, value, null, response);
1409
- }
1410
-
1411
- function resolveModelChunk(chunk, value) {
1412
- if (chunk.status !== PENDING) {
1413
-
1414
- return;
1415
- }
1416
-
1417
- var resolveListeners = chunk.value;
1418
- var rejectListeners = chunk.reason;
1419
- var resolvedChunk = chunk;
1420
- resolvedChunk.status = RESOLVED_MODEL;
1421
- resolvedChunk.value = value;
1422
-
1423
- if (resolveListeners !== null) {
1424
- // This is unfortunate that we're reading this eagerly if
1425
- // we already have listeners attached since they might no
1426
- // longer be rendered or might not be the highest pri.
1427
- initializeModelChunk(resolvedChunk); // The status might have changed after initialization.
1428
-
1429
- wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
1430
- }
1431
- }
1432
-
1433
- function resolveModuleChunk(chunk, value) {
1434
- if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
1435
- // We already resolved. We didn't expect to see this.
1436
- return;
1437
- }
1438
-
1439
- var resolveListeners = chunk.value;
1440
- var rejectListeners = chunk.reason;
1441
- var resolvedChunk = chunk;
1442
- resolvedChunk.status = RESOLVED_MODULE;
1443
- resolvedChunk.value = value;
1444
-
1445
- if (resolveListeners !== null) {
1446
- initializeModuleChunk(resolvedChunk);
1447
- wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
1448
- }
1449
- }
1450
-
1451
- var initializingChunk = null;
1452
- var initializingChunkBlockedModel = null;
1453
-
1454
- function initializeModelChunk(chunk) {
1455
- var prevChunk = initializingChunk;
1456
- var prevBlocked = initializingChunkBlockedModel;
1457
- initializingChunk = chunk;
1458
- initializingChunkBlockedModel = null;
1459
- var resolvedModel = chunk.value; // We go to the CYCLIC state until we've fully resolved this.
1460
- // We do this before parsing in case we try to initialize the same chunk
1461
- // while parsing the model. Such as in a cyclic reference.
1462
-
1463
- var cyclicChunk = chunk;
1464
- cyclicChunk.status = CYCLIC;
1465
- cyclicChunk.value = null;
1466
- cyclicChunk.reason = null;
1467
-
1468
- try {
1469
- var value = parseModel(chunk._response, resolvedModel);
1470
-
1471
- if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
1472
- initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
1473
- // We have to go the BLOCKED state until they're resolved.
1474
-
1475
- var blockedChunk = chunk;
1476
- blockedChunk.status = BLOCKED;
1477
- blockedChunk.value = null;
1478
- blockedChunk.reason = null;
1479
- } else {
1480
- var resolveListeners = cyclicChunk.value;
1481
- var initializedChunk = chunk;
1482
- initializedChunk.status = INITIALIZED;
1483
- initializedChunk.value = value;
1484
-
1485
- if (resolveListeners !== null) {
1486
- wakeChunk(resolveListeners, value);
1487
- }
1488
- }
1489
- } catch (error) {
1490
- var erroredChunk = chunk;
1491
- erroredChunk.status = ERRORED;
1492
- erroredChunk.reason = error;
1493
- } finally {
1494
- initializingChunk = prevChunk;
1495
- initializingChunkBlockedModel = prevBlocked;
1496
- }
1497
- }
1498
-
1499
- function initializeModuleChunk(chunk) {
1500
- try {
1501
- var value = requireModule(chunk.value);
1502
- var initializedChunk = chunk;
1503
- initializedChunk.status = INITIALIZED;
1504
- initializedChunk.value = value;
1505
- } catch (error) {
1506
- var erroredChunk = chunk;
1507
- erroredChunk.status = ERRORED;
1508
- erroredChunk.reason = error;
1509
- }
1510
- } // Report that any missing chunks in the model is now going to throw this
1511
- // error upon read. Also notify any pending promises.
1512
-
1513
-
1514
- function reportGlobalError(response, error) {
1515
- response._chunks.forEach(function (chunk) {
1516
- // If this chunk was already resolved or errored, it won't
1517
- // trigger an error but if it wasn't then we need to
1518
- // because we won't be getting any new data to resolve it.
1519
- if (chunk.status === PENDING) {
1520
- triggerErrorOnChunk(chunk, error);
1521
- }
1522
- });
1523
- }
1524
-
1525
- function nullRefGetter() {
1526
- {
1527
- return null;
1528
- }
1529
- }
1530
-
1531
- function createElement(type, key, props, owner) // DEV-only
1532
- {
1533
- var element;
1534
-
1535
- {
1536
- // `ref` is non-enumerable in dev
1537
- element = {
1538
- $$typeof: REACT_ELEMENT_TYPE,
1539
- type: type,
1540
- key: key,
1541
- props: props,
1542
- _owner: owner
1543
- };
1544
- Object.defineProperty(element, 'ref', {
1545
- enumerable: false,
1546
- get: nullRefGetter
1547
- });
1548
- }
1549
-
1550
- {
1551
- // We don't really need to add any of these but keeping them for good measure.
1552
- // Unfortunately, _store is enumerable in jest matchers so for equality to
1553
- // work, I need to keep it or make _store non-enumerable in the other file.
1554
- element._store = {};
1555
- Object.defineProperty(element._store, 'validated', {
1556
- configurable: false,
1557
- enumerable: false,
1558
- writable: true,
1559
- value: true // This element has already been validated on the server.
1560
-
1561
- }); // debugInfo contains Server Component debug information.
1562
-
1563
- Object.defineProperty(element, '_debugInfo', {
1564
- configurable: false,
1565
- enumerable: false,
1566
- writable: true,
1567
- value: null
1568
- });
1569
- }
1570
-
1571
- return element;
1572
- }
1573
-
1574
- function createLazyChunkWrapper(chunk) {
1575
- var lazyType = {
1576
- $$typeof: REACT_LAZY_TYPE,
1577
- _payload: chunk,
1578
- _init: readChunk
1579
- };
1580
-
1581
- {
1582
- // Ensure we have a live array to track future debug info.
1583
- var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
1584
- lazyType._debugInfo = chunkDebugInfo;
1585
- }
1586
-
1587
- return lazyType;
1588
- }
1589
-
1590
- function getChunk(response, id) {
1591
- var chunks = response._chunks;
1592
- var chunk = chunks.get(id);
1593
-
1594
- if (!chunk) {
1595
- chunk = createPendingChunk(response);
1596
- chunks.set(id, chunk);
1597
- }
1598
-
1599
- return chunk;
1600
- }
1601
-
1602
- function createModelResolver(chunk, parentObject, key, cyclic, response, map) {
1603
- var blocked;
1604
-
1605
- if (initializingChunkBlockedModel) {
1606
- blocked = initializingChunkBlockedModel;
1607
-
1608
- if (!cyclic) {
1609
- blocked.deps++;
1610
- }
1611
- } else {
1612
- blocked = initializingChunkBlockedModel = {
1613
- deps: cyclic ? 0 : 1,
1614
- value: null
1615
- };
1616
- }
1617
-
1618
- return function (value) {
1619
- parentObject[key] = map(response, value); // If this is the root object for a model reference, where `blocked.value`
1620
- // is a stale `null`, the resolved value can be used directly.
1621
-
1622
- if (key === '' && blocked.value === null) {
1623
- blocked.value = parentObject[key];
1624
- }
1625
-
1626
- blocked.deps--;
1627
-
1628
- if (blocked.deps === 0) {
1629
- if (chunk.status !== BLOCKED) {
1630
- return;
1631
- }
1632
-
1633
- var resolveListeners = chunk.value;
1634
- var initializedChunk = chunk;
1635
- initializedChunk.status = INITIALIZED;
1636
- initializedChunk.value = blocked.value;
1637
-
1638
- if (resolveListeners !== null) {
1639
- wakeChunk(resolveListeners, blocked.value);
1640
- }
1641
- }
1642
- };
1643
- }
1644
-
1645
- function createModelReject(chunk) {
1646
- return function (error) {
1647
- return triggerErrorOnChunk(chunk, error);
1648
- };
1649
- }
1650
-
1651
- function createServerReferenceProxy(response, metaData) {
1652
- var callServer = response._callServer;
1653
-
1654
- var proxy = function () {
1655
- // $FlowFixMe[method-unbinding]
1656
- var args = Array.prototype.slice.call(arguments);
1657
- var p = metaData.bound;
1658
-
1659
- if (!p) {
1660
- return callServer(metaData.id, args);
1661
- }
1662
-
1663
- if (p.status === INITIALIZED) {
1664
- var bound = p.value;
1665
- return callServer(metaData.id, bound.concat(args));
1666
- } // Since this is a fake Promise whose .then doesn't chain, we have to wrap it.
1667
- // TODO: Remove the wrapper once that's fixed.
1668
-
1669
-
1670
- return Promise.resolve(p).then(function (bound) {
1671
- return callServer(metaData.id, bound.concat(args));
1672
- });
1673
- };
1674
-
1675
- registerServerReference(proxy, metaData);
1676
- return proxy;
1677
- }
1678
-
1679
- function getOutlinedModel(response, id, parentObject, key, map) {
1680
- var chunk = getChunk(response, id);
1681
-
1682
- switch (chunk.status) {
1683
- case RESOLVED_MODEL:
1684
- initializeModelChunk(chunk);
1685
- break;
1686
-
1687
- case RESOLVED_MODULE:
1688
- initializeModuleChunk(chunk);
1689
- break;
1690
- } // The status might have changed after initialization.
1691
-
1692
-
1693
- switch (chunk.status) {
1694
- case INITIALIZED:
1695
- var chunkValue = map(response, chunk.value);
1696
-
1697
- if (chunk._debugInfo) {
1698
- // If we have a direct reference to an object that was rendered by a synchronous
1699
- // server component, it might have some debug info about how it was rendered.
1700
- // We forward this to the underlying object. This might be a React Element or
1701
- // an Array fragment.
1702
- // If this was a string / number return value we lose the debug info. We choose
1703
- // that tradeoff to allow sync server components to return plain values and not
1704
- // use them as React Nodes necessarily. We could otherwise wrap them in a Lazy.
1705
- if (typeof chunkValue === 'object' && chunkValue !== null && (Array.isArray(chunkValue) || typeof chunkValue[ASYNC_ITERATOR] === 'function' || chunkValue.$$typeof === REACT_ELEMENT_TYPE) && !chunkValue._debugInfo) {
1706
- // We should maybe use a unique symbol for arrays but this is a React owned array.
1707
- // $FlowFixMe[prop-missing]: This should be added to elements.
1708
- Object.defineProperty(chunkValue, '_debugInfo', {
1709
- configurable: false,
1710
- enumerable: false,
1711
- writable: true,
1712
- value: chunk._debugInfo
1713
- });
1714
- }
1715
- }
1716
-
1717
- return chunkValue;
1718
-
1719
- case PENDING:
1720
- case BLOCKED:
1721
- case CYCLIC:
1722
- var parentChunk = initializingChunk;
1723
- chunk.then(createModelResolver(parentChunk, parentObject, key, chunk.status === CYCLIC, response, map), createModelReject(parentChunk));
1724
- return null;
1725
-
1726
- default:
1727
- throw chunk.reason;
1728
- }
1729
- }
1730
-
1731
- function createMap(response, model) {
1732
- return new Map(model);
1733
- }
1734
-
1735
- function createSet(response, model) {
1736
- return new Set(model);
1737
- }
1738
-
1739
- function createFormData(response, model) {
1740
- var formData = new FormData();
1741
-
1742
- for (var i = 0; i < model.length; i++) {
1743
- formData.append(model[i][0], model[i][1]);
1744
- }
1745
-
1746
- return formData;
1747
- }
1748
-
1749
- function createModel(response, model) {
1750
- return model;
1751
- }
1752
-
1753
- function parseModelString(response, parentObject, key, value) {
1754
- if (value[0] === '$') {
1755
- if (value === '$') {
1756
- // A very common symbol.
1757
- return REACT_ELEMENT_TYPE;
1758
- }
1759
-
1760
- switch (value[1]) {
1761
- case '$':
1762
- {
1763
- // This was an escaped string value.
1764
- return value.slice(1);
1765
- }
1766
-
1767
- case 'L':
1768
- {
1769
- // Lazy node
1770
- var id = parseInt(value.slice(2), 16);
1771
- var chunk = getChunk(response, id); // We create a React.lazy wrapper around any lazy values.
1772
- // When passed into React, we'll know how to suspend on this.
1773
-
1774
- return createLazyChunkWrapper(chunk);
1775
- }
1776
-
1777
- case '@':
1778
- {
1779
- // Promise
1780
- if (value.length === 2) {
1781
- // Infinite promise that never resolves.
1782
- return new Promise(function () {});
1783
- }
1784
-
1785
- var _id = parseInt(value.slice(2), 16);
1786
-
1787
- var _chunk = getChunk(response, _id);
1788
-
1789
- return _chunk;
1790
- }
1791
-
1792
- case 'S':
1793
- {
1794
- // Symbol
1795
- return Symbol.for(value.slice(2));
1796
- }
1797
-
1798
- case 'F':
1799
- {
1800
- // Server Reference
1801
- var _id2 = parseInt(value.slice(2), 16);
1802
-
1803
- return getOutlinedModel(response, _id2, parentObject, key, createServerReferenceProxy);
1804
- }
1805
-
1806
- case 'T':
1807
- {
1808
- // Temporary Reference
1809
- var _id3 = parseInt(value.slice(2), 16);
1810
-
1811
- var temporaryReferences = response._tempRefs;
1812
-
1813
- if (temporaryReferences == null) {
1814
- throw new Error('Missing a temporary reference set but the RSC response returned a temporary reference. ' + 'Pass a temporaryReference option with the set that was used with the reply.');
1815
- }
1816
-
1817
- return readTemporaryReference(temporaryReferences, _id3);
1818
- }
1819
-
1820
- case 'Q':
1821
- {
1822
- // Map
1823
- var _id4 = parseInt(value.slice(2), 16);
1824
-
1825
- return getOutlinedModel(response, _id4, parentObject, key, createMap);
1826
- }
1827
-
1828
- case 'W':
1829
- {
1830
- // Set
1831
- var _id5 = parseInt(value.slice(2), 16);
1832
-
1833
- return getOutlinedModel(response, _id5, parentObject, key, createSet);
1834
- }
1835
-
1836
- case 'B':
1837
- {
1838
-
1839
- return undefined;
1840
- }
1841
-
1842
- case 'K':
1843
- {
1844
- // FormData
1845
- var _id7 = parseInt(value.slice(2), 16);
1846
-
1847
- return getOutlinedModel(response, _id7, parentObject, key, createFormData);
1848
- }
1849
-
1850
- case 'I':
1851
- {
1852
- // $Infinity
1853
- return Infinity;
1854
- }
1855
-
1856
- case '-':
1857
- {
1858
- // $-0 or $-Infinity
1859
- if (value === '$-0') {
1860
- return -0;
1861
- } else {
1862
- return -Infinity;
1863
- }
1864
- }
1865
-
1866
- case 'N':
1867
- {
1868
- // $NaN
1869
- return NaN;
1870
- }
1871
-
1872
- case 'u':
1873
- {
1874
- // matches "$undefined"
1875
- // Special encoding for `undefined` which can't be serialized as JSON otherwise.
1876
- return undefined;
1877
- }
1878
-
1879
- case 'D':
1880
- {
1881
- // Date
1882
- return new Date(Date.parse(value.slice(2)));
1883
- }
1884
-
1885
- case 'n':
1886
- {
1887
- // BigInt
1888
- return BigInt(value.slice(2));
1889
- }
1890
-
1891
- case 'E':
1892
- {
1893
- {
1894
- // In DEV mode we allow indirect eval to produce functions for logging.
1895
- // This should not compile to eval() because then it has local scope access.
1896
- try {
1897
- // eslint-disable-next-line no-eval
1898
- return (0, eval)(value.slice(2));
1899
- } catch (x) {
1900
- // We currently use this to express functions so we fail parsing it,
1901
- // let's just return a blank function as a place holder.
1902
- return function () {};
1903
- }
1904
- } // Fallthrough
1905
-
1906
- }
1907
-
1908
- default:
1909
- {
1910
- // We assume that anything else is a reference ID.
1911
- var _id8 = parseInt(value.slice(1), 16);
1912
-
1913
- return getOutlinedModel(response, _id8, parentObject, key, createModel);
1914
- }
1915
- }
1916
- }
1917
-
1918
- return value;
1919
- }
1920
-
1921
- function parseModelTuple(response, value) {
1922
- var tuple = value;
1923
-
1924
- if (tuple[0] === REACT_ELEMENT_TYPE) {
1925
- // TODO: Consider having React just directly accept these arrays as elements.
1926
- // Or even change the ReactElement type to be an array.
1927
- return createElement(tuple[1], tuple[2], tuple[3], tuple[4] );
1928
- }
1929
-
1930
- return value;
1931
- }
1932
-
1933
- function missingCall() {
1934
- throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
1935
- }
1936
-
1937
- function createResponse(bundlerConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences) {
1938
- var chunks = new Map();
1939
- var response = {
1940
- _bundlerConfig: bundlerConfig,
1941
- _moduleLoading: moduleLoading,
1942
- _callServer: callServer !== undefined ? callServer : missingCall,
1943
- _encodeFormAction: encodeFormAction,
1944
- _nonce: nonce,
1945
- _chunks: chunks,
1946
- _stringDecoder: createStringDecoder(),
1947
- _fromJSON: null,
1948
- _rowState: 0,
1949
- _rowID: 0,
1950
- _rowTag: 0,
1951
- _rowLength: 0,
1952
- _buffer: [],
1953
- _tempRefs: temporaryReferences
1954
- }; // Don't inline this call because it causes closure to outline the call above.
1955
-
1956
- response._fromJSON = createFromJSONCallback(response);
1957
- return response;
1958
- }
1959
-
1960
- function resolveModel(response, id, model) {
1961
- var chunks = response._chunks;
1962
- var chunk = chunks.get(id);
1963
-
1964
- if (!chunk) {
1965
- chunks.set(id, createResolvedModelChunk(response, model));
1966
- } else {
1967
- resolveModelChunk(chunk, model);
1968
- }
1969
- }
1970
-
1971
- function resolveText(response, id, text) {
1972
- var chunks = response._chunks;
1973
-
1974
- chunks.set(id, createInitializedTextChunk(response, text));
1975
- }
1976
-
1977
- function resolveModule(response, id, model) {
1978
- var chunks = response._chunks;
1979
- var chunk = chunks.get(id);
1980
- var clientReferenceMetadata = parseModel(response, model);
1981
- var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
1982
- // For now we preload all modules as early as possible since it's likely
1983
- // that we'll need them.
1984
-
1985
- var promise = preloadModule(clientReference);
1986
-
1987
- if (promise) {
1988
- var blockedChunk;
1989
-
1990
- if (!chunk) {
1991
- // Technically, we should just treat promise as the chunk in this
1992
- // case. Because it'll just behave as any other promise.
1993
- blockedChunk = createBlockedChunk(response);
1994
- chunks.set(id, blockedChunk);
1995
- } else {
1996
- // This can't actually happen because we don't have any forward
1997
- // references to modules.
1998
- blockedChunk = chunk;
1999
- blockedChunk.status = BLOCKED;
2000
- }
2001
-
2002
- promise.then(function () {
2003
- return resolveModuleChunk(blockedChunk, clientReference);
2004
- }, function (error) {
2005
- return triggerErrorOnChunk(blockedChunk, error);
2006
- });
2007
- } else {
2008
- if (!chunk) {
2009
- chunks.set(id, createResolvedModuleChunk(response, clientReference));
2010
- } else {
2011
- // This can't actually happen because we don't have any forward
2012
- // references to modules.
2013
- resolveModuleChunk(chunk, clientReference);
2014
- }
2015
- }
2016
- }
2017
-
2018
- var ASYNC_ITERATOR = Symbol.asyncIterator;
2019
-
2020
- function resolveErrorDev(response, id, digest, message, stack) {
2021
-
2022
-
2023
- var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
2024
- error.stack = stack;
2025
- error.digest = digest;
2026
- var errorWithDigest = error;
2027
- var chunks = response._chunks;
2028
- var chunk = chunks.get(id);
2029
-
2030
- if (!chunk) {
2031
- chunks.set(id, createErrorChunk(response, errorWithDigest));
2032
- } else {
2033
- triggerErrorOnChunk(chunk, errorWithDigest);
2034
- }
2035
- }
2036
-
2037
- function resolveHint(response, code, model) {
2038
- var hintModel = parseModel(response, model);
2039
- dispatchHint(code, hintModel);
2040
- }
2041
-
2042
- function resolveDebugInfo(response, id, debugInfo) {
2043
-
2044
- var chunk = getChunk(response, id);
2045
- var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
2046
- chunkDebugInfo.push(debugInfo);
2047
- }
2048
-
2049
- function resolveConsoleEntry(response, value) {
2050
-
2051
- var payload = parseModel(response, value);
2052
- var methodName = payload[0]; // TODO: Restore the fake stack before logging.
2053
- // const stackTrace = payload[1];
2054
- // const owner = payload[2];
2055
-
2056
- var env = payload[3];
2057
- var args = payload.slice(4);
2058
- printToConsole(methodName, args, env);
2059
- }
2060
-
2061
- function processFullRow(response, id, tag, buffer, chunk) {
2062
-
2063
- var stringDecoder = response._stringDecoder;
2064
- var row = '';
2065
-
2066
- for (var i = 0; i < buffer.length; i++) {
2067
- row += readPartialStringChunk(stringDecoder, buffer[i]);
2068
- }
2069
-
2070
- row += readFinalStringChunk(stringDecoder, chunk);
2071
-
2072
- switch (tag) {
2073
- case 73
2074
- /* "I" */
2075
- :
2076
- {
2077
- resolveModule(response, id, row);
2078
- return;
2079
- }
2080
-
2081
- case 72
2082
- /* "H" */
2083
- :
2084
- {
2085
- var code = row[0];
2086
- resolveHint(response, code, row.slice(1));
2087
- return;
2088
- }
2089
-
2090
- case 69
2091
- /* "E" */
2092
- :
2093
- {
2094
- var errorInfo = JSON.parse(row);
2095
-
2096
- {
2097
- resolveErrorDev(response, id, errorInfo.digest, errorInfo.message, errorInfo.stack);
2098
- }
2099
-
2100
- return;
2101
- }
2102
-
2103
- case 84
2104
- /* "T" */
2105
- :
2106
- {
2107
- resolveText(response, id, row);
2108
- return;
2109
- }
2110
-
2111
- case 68
2112
- /* "D" */
2113
- :
2114
- {
2115
- {
2116
- var debugInfo = parseModel(response, row);
2117
- resolveDebugInfo(response, id, debugInfo);
2118
- return;
2119
- } // Fallthrough to share the error with Console entries.
2120
-
2121
- }
2122
-
2123
- case 87
2124
- /* "W" */
2125
- :
2126
- {
2127
- {
2128
- resolveConsoleEntry(response, row);
2129
- return;
2130
- }
2131
- }
2132
-
2133
- case 82
2134
- /* "R" */
2135
- :
2136
- // Fallthrough
2137
-
2138
- case 114
2139
- /* "r" */
2140
- :
2141
- // Fallthrough
2142
-
2143
- case 88
2144
- /* "X" */
2145
- :
2146
- // Fallthrough
2147
-
2148
- case 120
2149
- /* "x" */
2150
- :
2151
- // Fallthrough
2152
-
2153
- case 67
2154
- /* "C" */
2155
- :
2156
- // Fallthrough
2157
-
2158
- case 80
2159
- /* "P" */
2160
- :
2161
- // Fallthrough
2162
-
2163
- default:
2164
- /* """ "{" "[" "t" "f" "n" "0" - "9" */
2165
- {
2166
- // We assume anything else is JSON.
2167
- resolveModel(response, id, row);
2168
- return;
2169
- }
2170
- }
2171
- }
2172
-
2173
- function processBinaryChunk(response, chunk) {
2174
- var i = 0;
2175
- var rowState = response._rowState;
2176
- var rowID = response._rowID;
2177
- var rowTag = response._rowTag;
2178
- var rowLength = response._rowLength;
2179
- var buffer = response._buffer;
2180
- var chunkLength = chunk.length;
2181
-
2182
- while (i < chunkLength) {
2183
- var lastIdx = -1;
2184
-
2185
- switch (rowState) {
2186
- case ROW_ID:
2187
- {
2188
- var byte = chunk[i++];
2189
-
2190
- if (byte === 58
2191
- /* ":" */
2192
- ) {
2193
- // Finished the rowID, next we'll parse the tag.
2194
- rowState = ROW_TAG;
2195
- } else {
2196
- rowID = rowID << 4 | (byte > 96 ? byte - 87 : byte - 48);
2197
- }
2198
-
2199
- continue;
2200
- }
2201
-
2202
- case ROW_TAG:
2203
- {
2204
- var resolvedRowTag = chunk[i];
2205
-
2206
- if (resolvedRowTag === 84
2207
- /* "T" */
2208
- || enableBinaryFlight
2209
- /* "V" */
2210
- ) {
2211
- rowTag = resolvedRowTag;
2212
- rowState = ROW_LENGTH;
2213
- i++;
2214
- } else if (resolvedRowTag > 64 && resolvedRowTag < 91 ||
2215
- /* "A"-"Z" */
2216
- resolvedRowTag === 114
2217
- /* "r" */
2218
- || resolvedRowTag === 120
2219
- /* "x" */
2220
- ) {
2221
- rowTag = resolvedRowTag;
2222
- rowState = ROW_CHUNK_BY_NEWLINE;
2223
- i++;
2224
- } else {
2225
- rowTag = 0;
2226
- rowState = ROW_CHUNK_BY_NEWLINE; // This was an unknown tag so it was probably part of the data.
2227
- }
2228
-
2229
- continue;
2230
- }
2231
-
2232
- case ROW_LENGTH:
2233
- {
2234
- var _byte = chunk[i++];
2235
-
2236
- if (_byte === 44
2237
- /* "," */
2238
- ) {
2239
- // Finished the rowLength, next we'll buffer up to that length.
2240
- rowState = ROW_CHUNK_BY_LENGTH;
2241
- } else {
2242
- rowLength = rowLength << 4 | (_byte > 96 ? _byte - 87 : _byte - 48);
2243
- }
2244
-
2245
- continue;
2246
- }
2247
-
2248
- case ROW_CHUNK_BY_NEWLINE:
2249
- {
2250
- // We're looking for a newline
2251
- lastIdx = chunk.indexOf(10
2252
- /* "\n" */
2253
- , i);
2254
- break;
2255
- }
2256
-
2257
- case ROW_CHUNK_BY_LENGTH:
2258
- {
2259
- // We're looking for the remaining byte length
2260
- lastIdx = i + rowLength;
2261
-
2262
- if (lastIdx > chunk.length) {
2263
- lastIdx = -1;
2264
- }
2265
-
2266
- break;
2267
- }
2268
- }
2269
-
2270
- var offset = chunk.byteOffset + i;
2271
-
2272
- if (lastIdx > -1) {
2273
- // We found the last chunk of the row
2274
- var length = lastIdx - i;
2275
- var lastChunk = new Uint8Array(chunk.buffer, offset, length);
2276
- processFullRow(response, rowID, rowTag, buffer, lastChunk); // Reset state machine for a new row
2277
-
2278
- i = lastIdx;
2279
-
2280
- if (rowState === ROW_CHUNK_BY_NEWLINE) {
2281
- // If we're trailing by a newline we need to skip it.
2282
- i++;
2283
- }
2284
-
2285
- rowState = ROW_ID;
2286
- rowTag = 0;
2287
- rowID = 0;
2288
- rowLength = 0;
2289
- buffer.length = 0;
2290
- } else {
2291
- // The rest of this row is in a future chunk. We stash the rest of the
2292
- // current chunk until we can process the full row.
2293
- var _length = chunk.byteLength - i;
2294
-
2295
- var remainingSlice = new Uint8Array(chunk.buffer, offset, _length);
2296
- buffer.push(remainingSlice); // Update how many bytes we're still waiting for. If we're looking for
2297
- // a newline, this doesn't hurt since we'll just ignore it.
2298
-
2299
- rowLength -= remainingSlice.byteLength;
2300
- break;
2301
- }
2302
- }
2303
-
2304
- response._rowState = rowState;
2305
- response._rowID = rowID;
2306
- response._rowTag = rowTag;
2307
- response._rowLength = rowLength;
2308
- }
2309
-
2310
- function parseModel(response, json) {
2311
- return JSON.parse(json, response._fromJSON);
2312
- }
2313
-
2314
- function createFromJSONCallback(response) {
2315
- // $FlowFixMe[missing-this-annot]
2316
- return function (key, value) {
2317
- if (typeof value === 'string') {
2318
- // We can't use .bind here because we need the "this" value.
2319
- return parseModelString(response, this, key, value);
2320
- }
2321
-
2322
- if (typeof value === 'object' && value !== null) {
2323
- return parseModelTuple(response, value);
2324
- }
2325
-
2326
- return value;
2327
- };
2328
- }
2329
-
2330
- function close(response) {
2331
- // In case there are any remaining unresolved chunks, they won't
2332
- // be resolved now. So we need to issue an error to those.
2333
- // Ideally we should be able to early bail out if we kept a
2334
- // ref count of pending chunks.
2335
- reportGlobalError(response, new Error('Connection closed.'));
2336
- }
2337
-
2338
- function createResponseFromOptions(options) {
2339
- return createResponse(null, null, options && options.callServer ? options.callServer : undefined, undefined, // encodeFormAction
2340
- undefined, // nonce
2341
- options && options.temporaryReferences ? options.temporaryReferences : undefined);
2342
- }
2343
-
2344
- function startReadingFromStream(response, stream) {
2345
- var reader = stream.getReader();
2346
-
2347
- function progress(_ref) {
2348
- var done = _ref.done,
2349
- value = _ref.value;
2350
-
2351
- if (done) {
2352
- close(response);
2353
- return;
2354
- }
2355
-
2356
- var buffer = value;
2357
- processBinaryChunk(response, buffer);
2358
- return reader.read().then(progress).catch(error);
2359
- }
2360
-
2361
- function error(e) {
2362
- reportGlobalError(response, e);
2363
- }
2364
-
2365
- reader.read().then(progress).catch(error);
2366
- }
2367
-
2368
- function createFromReadableStream(stream, options) {
2369
- var response = createResponseFromOptions(options);
2370
- startReadingFromStream(response, stream);
2371
- return getRoot(response);
2372
- }
2373
-
2374
- function createFromFetch(promiseForResponse, options) {
2375
- var response = createResponseFromOptions(options);
2376
- promiseForResponse.then(function (r) {
2377
- startReadingFromStream(response, r.body);
2378
- }, function (e) {
2379
- reportGlobalError(response, e);
2380
- });
2381
- return getRoot(response);
2382
- }
2383
-
2384
- function encodeReply(value, options)
2385
- /* We don't use URLSearchParams yet but maybe */
2386
- {
2387
- return new Promise(function (resolve, reject) {
2388
- processReply(value, '', options && options.temporaryReferences ? options.temporaryReferences : undefined, resolve, reject);
2389
- });
2390
- }
2391
-
2392
- exports.createFromFetch = createFromFetch;
2393
- exports.createFromReadableStream = createFromReadableStream;
2394
- exports.createServerReference = createServerReference;
2395
- exports.createTemporaryReferenceSet = createTemporaryReferenceSet;
2396
- exports.encodeReply = encodeReply;
2397
-
2398
- }));