@es-joy/jsoe 0.21.0 → 0.22.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@es-joy/jsoe",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./src/index.js",
@@ -484,47 +484,45 @@ const canonicalTypeToAvailableTypeAndSchema = (
484
484
 
485
485
  /** @type {import('../formats.js').Format} */
486
486
  const structuredCloning = {
487
- iterate (records, stateObj) {
487
+ async iterate (records, stateObj) {
488
488
  /* istanbul ignore if -- Just a guard */
489
489
  if (!stateObj.format) {
490
490
  stateObj.format = 'structuredCloning';
491
491
  }
492
- // Todo: Replace this with async typeson?
493
- // eslint-disable-next-line promise/avoid-new -- Our own API for now
494
- return new Promise((resolve, reject) => {
495
- const structuredCloningFixed = structuredCloningThrowing.filter(
496
- (typeSpecSet) => {
497
- return ![
498
- // Not yet supported within JSOE
499
- 'imagedata',
500
- 'imagebitmap',
501
- 'cryptokey',
502
- 'domquad'
503
- ].some((prop) => {
504
- return Object.hasOwn(typeSpecSet, prop);
505
- });
506
- }
507
- );
508
- structuredCloningFixed.splice(
509
- // Add after userObjects
510
- 1,
511
- 0,
512
- noneditable
513
- );
514
- const typeson = new Typeson({
515
- encapsulateObserver: encapsulateObserver(stateObj)
516
- }).register(structuredCloningFixed);
517
- typeson.encapsulate(records);
518
- // Todo (low): We might want to run async encapsulate for
519
- // async types (and put this after Promise resolves)
520
- if (stateObj.error) {
521
- reject(stateObj.error);
522
- } else {
523
- resolve(/** @type {Required<import('../types.js').StateObject>} */ (
524
- stateObj
525
- ));
492
+
493
+ const structuredCloningFixed = structuredCloningThrowing.filter(
494
+ (typeSpecSet) => {
495
+ return ![
496
+ // Not yet supported within JSOE
497
+ 'imagedata',
498
+ 'imagebitmap',
499
+ 'cryptokey',
500
+ 'domquad'
501
+ ].some((prop) => {
502
+ return Object.hasOwn(typeSpecSet, prop);
503
+ });
526
504
  }
505
+ );
506
+ structuredCloningFixed.splice(
507
+ // Add after userObjects
508
+ 1,
509
+ 0,
510
+ noneditable
511
+ );
512
+ const typeson = new Typeson({
513
+ encapsulateObserver: encapsulateObserver(stateObj)
514
+ }).register(structuredCloningFixed);
515
+
516
+ await typeson.encapsulateAsync(records, null, {
517
+ throwOnBadSyncType: false
527
518
  });
519
+
520
+ if (stateObj.error) {
521
+ throw stateObj.error;
522
+ }
523
+ return (/** @type {Required<import('../types.js').StateObject>} */ (
524
+ stateObj
525
+ ));
528
526
  },
529
527
  getTypesAndSchemasForState (types, state) {
530
528
  if (state && types.getContextInfo('structuredCloning', state)) {