mol_wire_lib 1.0.1680 → 1.0.1682
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/node.d.ts +6 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +44 -29
- package/node.js.map +1 -1
- package/node.mjs +44 -29
- package/node.test.js +59 -38
- package/node.test.js.map +1 -1
- package/package.json +3 -2
- package/web.d.ts +6 -1
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +44 -29
- package/web.js.map +1 -1
- package/web.mjs +44 -29
- package/web.test.js +15 -9
- package/web.test.js.map +1 -1
package/web.mjs
CHANGED
|
@@ -635,6 +635,14 @@ var $;
|
|
|
635
635
|
$.$mol_func_name_from = $mol_func_name_from;
|
|
636
636
|
})($ || ($ = {}));
|
|
637
637
|
|
|
638
|
+
;
|
|
639
|
+
"use strict";
|
|
640
|
+
var $;
|
|
641
|
+
(function ($) {
|
|
642
|
+
$.$mol_key_handle = Symbol.for('$mol_key_handle');
|
|
643
|
+
$.$mol_key_store = new WeakMap();
|
|
644
|
+
})($ || ($ = {}));
|
|
645
|
+
|
|
638
646
|
;
|
|
639
647
|
"use strict";
|
|
640
648
|
var $;
|
|
@@ -671,6 +679,9 @@ var $;
|
|
|
671
679
|
static toJSON() {
|
|
672
680
|
return this.toString();
|
|
673
681
|
}
|
|
682
|
+
static [$mol_key_handle]() {
|
|
683
|
+
return this.toString();
|
|
684
|
+
}
|
|
674
685
|
destructor() { }
|
|
675
686
|
static destructor() { }
|
|
676
687
|
[Symbol.dispose]() {
|
|
@@ -1262,46 +1273,50 @@ var $;
|
|
|
1262
1273
|
"use strict";
|
|
1263
1274
|
var $;
|
|
1264
1275
|
(function ($) {
|
|
1265
|
-
$.$mol_key_store = new WeakMap();
|
|
1266
1276
|
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
1267
1277
|
function $mol_key(value) {
|
|
1268
|
-
|
|
1269
|
-
return value.toString() + 'n';
|
|
1270
|
-
if (typeof value === 'symbol')
|
|
1271
|
-
return value.description;
|
|
1272
|
-
if (!value)
|
|
1273
|
-
return JSON.stringify(value);
|
|
1274
|
-
if (typeof value !== 'object' && typeof value !== 'function')
|
|
1275
|
-
return JSON.stringify(value);
|
|
1276
|
-
return JSON.stringify(value, (field, value) => {
|
|
1278
|
+
primitives: {
|
|
1277
1279
|
if (typeof value === 'bigint')
|
|
1278
1280
|
return value.toString() + 'n';
|
|
1279
1281
|
if (typeof value === 'symbol')
|
|
1280
|
-
return value.description
|
|
1282
|
+
return `Symbol(${value.description})`;
|
|
1281
1283
|
if (!value)
|
|
1282
|
-
return value;
|
|
1284
|
+
return JSON.stringify(value);
|
|
1283
1285
|
if (typeof value !== 'object' && typeof value !== 'function')
|
|
1284
|
-
return value;
|
|
1286
|
+
return JSON.stringify(value);
|
|
1287
|
+
}
|
|
1288
|
+
caching: {
|
|
1289
|
+
let key = $mol_key_store.get(value);
|
|
1290
|
+
if (key)
|
|
1291
|
+
return key;
|
|
1292
|
+
}
|
|
1293
|
+
objects: {
|
|
1294
|
+
if (value instanceof TypedArray) {
|
|
1295
|
+
return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
|
|
1296
|
+
}
|
|
1285
1297
|
if (Array.isArray(value))
|
|
1286
|
-
return value
|
|
1287
|
-
const proto = Reflect.getPrototypeOf(value);
|
|
1288
|
-
if (!proto)
|
|
1289
|
-
return value;
|
|
1290
|
-
if (Reflect.getPrototypeOf(proto) === null)
|
|
1291
|
-
return value;
|
|
1292
|
-
if ('toJSON' in value)
|
|
1293
|
-
return value;
|
|
1298
|
+
return `[${value.map(v => $mol_key(v))}]`;
|
|
1294
1299
|
if (value instanceof RegExp)
|
|
1295
1300
|
return value.toString();
|
|
1296
|
-
if (value instanceof
|
|
1297
|
-
return
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1301
|
+
if (value instanceof Date)
|
|
1302
|
+
return `Date(${value.valueOf()})`;
|
|
1303
|
+
}
|
|
1304
|
+
structures: {
|
|
1305
|
+
const proto = Reflect.getPrototypeOf(value);
|
|
1306
|
+
if (!proto || !Reflect.getPrototypeOf(proto)) {
|
|
1307
|
+
return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
handlers: {
|
|
1311
|
+
if ($mol_key_handle in value) {
|
|
1312
|
+
return value[$mol_key_handle]();
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
containers: {
|
|
1316
|
+
const key = JSON.stringify('#' + $mol_guid());
|
|
1317
|
+
$mol_key_store.set(value, key);
|
|
1303
1318
|
return key;
|
|
1304
|
-
}
|
|
1319
|
+
}
|
|
1305
1320
|
}
|
|
1306
1321
|
$.$mol_key = $mol_key;
|
|
1307
1322
|
})($ || ($ = {}));
|
package/web.test.js
CHANGED
|
@@ -1247,9 +1247,9 @@ var $;
|
|
|
1247
1247
|
$mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
|
|
1248
1248
|
},
|
|
1249
1249
|
'Uint8Array'() {
|
|
1250
|
-
$mol_assert_equal($mol_key(new Uint8Array([1, 2])), '[1,2]');
|
|
1251
|
-
$mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[[1,2]]');
|
|
1252
|
-
$mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":[1,2]}');
|
|
1250
|
+
$mol_assert_equal($mol_key(new Uint8Array([1, 2])), 'Uint8Array([1,2])');
|
|
1251
|
+
$mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[Uint8Array([1,2])]');
|
|
1252
|
+
$mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":Uint8Array([1,2])}');
|
|
1253
1253
|
},
|
|
1254
1254
|
'Function'() {
|
|
1255
1255
|
const func = () => { };
|
|
@@ -1269,6 +1269,12 @@ var $;
|
|
|
1269
1269
|
$mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
|
|
1270
1270
|
},
|
|
1271
1271
|
'Custom JSON representation'() {
|
|
1272
|
+
class User {
|
|
1273
|
+
toJSON() { return 'jin'; }
|
|
1274
|
+
}
|
|
1275
|
+
$mol_assert_unique([$mol_key(new User)], [$mol_key(new User)]);
|
|
1276
|
+
},
|
|
1277
|
+
'Custom key handler'() {
|
|
1272
1278
|
class User {
|
|
1273
1279
|
name;
|
|
1274
1280
|
age;
|
|
@@ -1276,15 +1282,15 @@ var $;
|
|
|
1276
1282
|
this.name = name;
|
|
1277
1283
|
this.age = age;
|
|
1278
1284
|
}
|
|
1279
|
-
|
|
1285
|
+
[$mol_key_handle]() { return `User(${JSON.stringify(this.name)})`; }
|
|
1280
1286
|
}
|
|
1281
|
-
$mol_assert_equal($mol_key(new User('jin', 18)), '
|
|
1287
|
+
$mol_assert_equal($mol_key([new User('jin', 16)]), $mol_key([new User('jin', 18)]), '[User("jin")]');
|
|
1282
1288
|
},
|
|
1283
1289
|
'Special native classes'() {
|
|
1284
|
-
$mol_assert_equal($mol_key(new Date('xyz')), '
|
|
1285
|
-
$mol_assert_equal($mol_key(new Date(
|
|
1286
|
-
$mol_assert_equal($mol_key(/./), '
|
|
1287
|
-
$mol_assert_equal($mol_key(/\./gimsu), '
|
|
1290
|
+
$mol_assert_equal($mol_key(new Date('xyz')), 'Date(NaN)');
|
|
1291
|
+
$mol_assert_equal($mol_key(new Date(12345)), 'Date(12345)');
|
|
1292
|
+
$mol_assert_equal($mol_key(/./), '/./');
|
|
1293
|
+
$mol_assert_equal($mol_key(/\./gimsu), '/\\./gimsu');
|
|
1288
1294
|
},
|
|
1289
1295
|
});
|
|
1290
1296
|
})($ || ($ = {}));
|