@async/framework 0.11.9 → 0.11.11
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/CHANGELOG.md +26 -0
- package/browser.js +79 -5
- package/browser.min.js +1 -1
- package/browser.ts +79 -5
- package/browser.umd.js +79 -5
- package/browser.umd.min.js +1 -1
- package/framework.ts +79 -5
- package/package.json +1 -1
- package/server.js +79 -5
package/browser.ts
CHANGED
|
@@ -132,9 +132,9 @@ const __asyncSignalModule = (() => {
|
|
|
132
132
|
|
|
133
133
|
snapshot() {
|
|
134
134
|
return {
|
|
135
|
-
value,
|
|
135
|
+
value: value === undefined && error !== null ? null : value,
|
|
136
136
|
loading,
|
|
137
|
-
error,
|
|
137
|
+
error: serializeAsyncError(error),
|
|
138
138
|
status,
|
|
139
139
|
version
|
|
140
140
|
};
|
|
@@ -151,7 +151,7 @@ const __asyncSignalModule = (() => {
|
|
|
151
151
|
cancelCurrentRun(new Error(`Async signal "${registeredId}" restored from snapshot.`));
|
|
152
152
|
value = snapshot.value;
|
|
153
153
|
loading = Boolean(snapshot.loading);
|
|
154
|
-
error = snapshot.error
|
|
154
|
+
error = restoreAsyncError(snapshot.error);
|
|
155
155
|
status = typeof snapshot.status === "string" ? snapshot.status : inferStatus({ value, loading, error });
|
|
156
156
|
if (Number.isFinite(snapshot.version)) {
|
|
157
157
|
version = snapshot.version;
|
|
@@ -403,6 +403,51 @@ const __asyncSignalModule = (() => {
|
|
|
403
403
|
return value === undefined ? "idle" : "ready";
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
function serializeAsyncError(value) {
|
|
407
|
+
if (value == null) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const record = {
|
|
412
|
+
name: readErrorName(value),
|
|
413
|
+
message: readErrorMessage(value)
|
|
414
|
+
};
|
|
415
|
+
const code = readErrorCode(value);
|
|
416
|
+
if (code !== undefined) {
|
|
417
|
+
record.code = code;
|
|
418
|
+
}
|
|
419
|
+
return record;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function restoreAsyncError(value) {
|
|
423
|
+
return serializeAsyncError(value);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function readErrorName(value) {
|
|
427
|
+
if (value && typeof value === "object" && typeof value.name === "string" && value.name.length > 0) {
|
|
428
|
+
return value.name;
|
|
429
|
+
}
|
|
430
|
+
return "Error";
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function readErrorMessage(value) {
|
|
434
|
+
if (value instanceof Error) {
|
|
435
|
+
return value.message;
|
|
436
|
+
}
|
|
437
|
+
if (value && typeof value === "object" && typeof value.message === "string") {
|
|
438
|
+
return value.message;
|
|
439
|
+
}
|
|
440
|
+
return String(value);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function readErrorCode(value) {
|
|
444
|
+
if (!value || typeof value !== "object" || !Object.hasOwn(value, "code")) {
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
const code = value.code;
|
|
448
|
+
return typeof code === "string" || typeof code === "number" ? code : undefined;
|
|
449
|
+
}
|
|
450
|
+
|
|
406
451
|
function attachCancel(signal, controller, onCancel) {
|
|
407
452
|
Object.defineProperty(signal, "cancel", {
|
|
408
453
|
configurable: true,
|
|
@@ -3240,7 +3285,7 @@ const __schedulerModule = (() => {
|
|
|
3240
3285
|
scheduled = true;
|
|
3241
3286
|
scheduleMicrotask(() => {
|
|
3242
3287
|
if (!destroyed) {
|
|
3243
|
-
void api.flush();
|
|
3288
|
+
void api.flush().catch(reportAutomaticFlushError);
|
|
3244
3289
|
}
|
|
3245
3290
|
});
|
|
3246
3291
|
}
|
|
@@ -3276,12 +3321,22 @@ const __schedulerModule = (() => {
|
|
|
3276
3321
|
if (onError) {
|
|
3277
3322
|
onError(error, job);
|
|
3278
3323
|
} else {
|
|
3279
|
-
throw error;
|
|
3324
|
+
throw annotateSchedulerError(error, job);
|
|
3280
3325
|
}
|
|
3281
3326
|
}
|
|
3282
3327
|
}
|
|
3283
3328
|
}
|
|
3284
3329
|
|
|
3330
|
+
function reportAutomaticFlushError(error) {
|
|
3331
|
+
if (typeof globalThis.reportError === "function") {
|
|
3332
|
+
globalThis.reportError(error);
|
|
3333
|
+
return;
|
|
3334
|
+
}
|
|
3335
|
+
setTimeout(() => {
|
|
3336
|
+
throw error;
|
|
3337
|
+
}, 0);
|
|
3338
|
+
}
|
|
3339
|
+
|
|
3285
3340
|
function hasJobs() {
|
|
3286
3341
|
for (const queue of queues.values()) {
|
|
3287
3342
|
if (queue.some((job) => !job.canceled)) {
|
|
@@ -3340,6 +3395,25 @@ const __schedulerModule = (() => {
|
|
|
3340
3395
|
return (typeof scope === "object" && scope !== null) || typeof scope === "function";
|
|
3341
3396
|
}
|
|
3342
3397
|
|
|
3398
|
+
function annotateSchedulerError(error, job) {
|
|
3399
|
+
if (!error || (typeof error !== "object" && typeof error !== "function")) {
|
|
3400
|
+
return error;
|
|
3401
|
+
}
|
|
3402
|
+
try {
|
|
3403
|
+
Object.defineProperty(error, "scheduler", {
|
|
3404
|
+
configurable: true,
|
|
3405
|
+
value: {
|
|
3406
|
+
phase: job.phase,
|
|
3407
|
+
scope: job.scope,
|
|
3408
|
+
key: job.key
|
|
3409
|
+
}
|
|
3410
|
+
});
|
|
3411
|
+
} catch {
|
|
3412
|
+
// Non-extensible thrown values still need to propagate through the chosen error channel.
|
|
3413
|
+
}
|
|
3414
|
+
return error;
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3343
3417
|
function scheduleMicrotask(fn) {
|
|
3344
3418
|
if (typeof queueMicrotask === "function") {
|
|
3345
3419
|
queueMicrotask(fn);
|
package/browser.umd.js
CHANGED
|
@@ -142,9 +142,9 @@
|
|
|
142
142
|
|
|
143
143
|
snapshot() {
|
|
144
144
|
return {
|
|
145
|
-
value,
|
|
145
|
+
value: value === undefined && error !== null ? null : value,
|
|
146
146
|
loading,
|
|
147
|
-
error,
|
|
147
|
+
error: serializeAsyncError(error),
|
|
148
148
|
status,
|
|
149
149
|
version
|
|
150
150
|
};
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
cancelCurrentRun(new Error(`Async signal "${registeredId}" restored from snapshot.`));
|
|
162
162
|
value = snapshot.value;
|
|
163
163
|
loading = Boolean(snapshot.loading);
|
|
164
|
-
error = snapshot.error
|
|
164
|
+
error = restoreAsyncError(snapshot.error);
|
|
165
165
|
status = typeof snapshot.status === "string" ? snapshot.status : inferStatus({ value, loading, error });
|
|
166
166
|
if (Number.isFinite(snapshot.version)) {
|
|
167
167
|
version = snapshot.version;
|
|
@@ -413,6 +413,51 @@
|
|
|
413
413
|
return value === undefined ? "idle" : "ready";
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
+
function serializeAsyncError(value) {
|
|
417
|
+
if (value == null) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const record = {
|
|
422
|
+
name: readErrorName(value),
|
|
423
|
+
message: readErrorMessage(value)
|
|
424
|
+
};
|
|
425
|
+
const code = readErrorCode(value);
|
|
426
|
+
if (code !== undefined) {
|
|
427
|
+
record.code = code;
|
|
428
|
+
}
|
|
429
|
+
return record;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function restoreAsyncError(value) {
|
|
433
|
+
return serializeAsyncError(value);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function readErrorName(value) {
|
|
437
|
+
if (value && typeof value === "object" && typeof value.name === "string" && value.name.length > 0) {
|
|
438
|
+
return value.name;
|
|
439
|
+
}
|
|
440
|
+
return "Error";
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function readErrorMessage(value) {
|
|
444
|
+
if (value instanceof Error) {
|
|
445
|
+
return value.message;
|
|
446
|
+
}
|
|
447
|
+
if (value && typeof value === "object" && typeof value.message === "string") {
|
|
448
|
+
return value.message;
|
|
449
|
+
}
|
|
450
|
+
return String(value);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function readErrorCode(value) {
|
|
454
|
+
if (!value || typeof value !== "object" || !Object.hasOwn(value, "code")) {
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
const code = value.code;
|
|
458
|
+
return typeof code === "string" || typeof code === "number" ? code : undefined;
|
|
459
|
+
}
|
|
460
|
+
|
|
416
461
|
function attachCancel(signal, controller, onCancel) {
|
|
417
462
|
Object.defineProperty(signal, "cancel", {
|
|
418
463
|
configurable: true,
|
|
@@ -3250,7 +3295,7 @@
|
|
|
3250
3295
|
scheduled = true;
|
|
3251
3296
|
scheduleMicrotask(() => {
|
|
3252
3297
|
if (!destroyed) {
|
|
3253
|
-
void api.flush();
|
|
3298
|
+
void api.flush().catch(reportAutomaticFlushError);
|
|
3254
3299
|
}
|
|
3255
3300
|
});
|
|
3256
3301
|
}
|
|
@@ -3286,12 +3331,22 @@
|
|
|
3286
3331
|
if (onError) {
|
|
3287
3332
|
onError(error, job);
|
|
3288
3333
|
} else {
|
|
3289
|
-
throw error;
|
|
3334
|
+
throw annotateSchedulerError(error, job);
|
|
3290
3335
|
}
|
|
3291
3336
|
}
|
|
3292
3337
|
}
|
|
3293
3338
|
}
|
|
3294
3339
|
|
|
3340
|
+
function reportAutomaticFlushError(error) {
|
|
3341
|
+
if (typeof globalThis.reportError === "function") {
|
|
3342
|
+
globalThis.reportError(error);
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3345
|
+
setTimeout(() => {
|
|
3346
|
+
throw error;
|
|
3347
|
+
}, 0);
|
|
3348
|
+
}
|
|
3349
|
+
|
|
3295
3350
|
function hasJobs() {
|
|
3296
3351
|
for (const queue of queues.values()) {
|
|
3297
3352
|
if (queue.some((job) => !job.canceled)) {
|
|
@@ -3350,6 +3405,25 @@
|
|
|
3350
3405
|
return (typeof scope === "object" && scope !== null) || typeof scope === "function";
|
|
3351
3406
|
}
|
|
3352
3407
|
|
|
3408
|
+
function annotateSchedulerError(error, job) {
|
|
3409
|
+
if (!error || (typeof error !== "object" && typeof error !== "function")) {
|
|
3410
|
+
return error;
|
|
3411
|
+
}
|
|
3412
|
+
try {
|
|
3413
|
+
Object.defineProperty(error, "scheduler", {
|
|
3414
|
+
configurable: true,
|
|
3415
|
+
value: {
|
|
3416
|
+
phase: job.phase,
|
|
3417
|
+
scope: job.scope,
|
|
3418
|
+
key: job.key
|
|
3419
|
+
}
|
|
3420
|
+
});
|
|
3421
|
+
} catch {
|
|
3422
|
+
// Non-extensible thrown values still need to propagate through the chosen error channel.
|
|
3423
|
+
}
|
|
3424
|
+
return error;
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3353
3427
|
function scheduleMicrotask(fn) {
|
|
3354
3428
|
if (typeof queueMicrotask === "function") {
|
|
3355
3429
|
queueMicrotask(fn);
|