hyoo_sync_client 0.0.507 → 0.0.509

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.js CHANGED
@@ -299,30 +299,26 @@ var $node = new Proxy({ require }, {
299
299
  return target.require(name);
300
300
  if (name[0] === '.')
301
301
  return target.require(name);
302
- const path = target.require('path');
303
- const fs = target.require('fs');
304
- let dir = path.resolve('.');
305
- const suffix = `./node_modules/${name}`;
306
- const $$ = $;
307
- while (!fs.existsSync(path.join(dir, suffix))) {
308
- const parent = path.resolve(dir, '..');
309
- if (parent === dir) {
310
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
311
- try {
312
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
313
- }
314
- catch { }
315
- break;
302
+ try {
303
+ target.require.resolve(name);
304
+ }
305
+ catch {
306
+ const $$ = $;
307
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
308
+ try {
309
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
316
310
  }
317
- else {
318
- dir = parent;
311
+ catch (e) {
312
+ if ($$.$mol_fail_catch(e)) {
313
+ $$.$mol_fail_log(e);
314
+ }
319
315
  }
320
316
  }
321
317
  try {
322
318
  return target.require(name);
323
319
  }
324
320
  catch (error) {
325
- if (error.code === 'ERR_REQUIRE_ESM') {
321
+ if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
326
322
  const module = cache.get(name);
327
323
  if (module)
328
324
  return module;
@@ -342,6 +338,36 @@ require = (req => Object.assign(function require(name) {
342
338
  return $node[name];
343
339
  }, req))(require);
344
340
 
341
+ ;
342
+ "use strict";
343
+ var $;
344
+ (function ($) {
345
+ class $mol_error_mix extends AggregateError {
346
+ cause;
347
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
348
+ constructor(message, cause = {}, ...errors) {
349
+ super(errors, message, { cause });
350
+ this.cause = cause;
351
+ const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
352
+ Object.defineProperty(this, 'stack', {
353
+ get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
354
+ .replace(/at /gm, ' at ')
355
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
356
+ });
357
+ }
358
+ static [Symbol.toPrimitive]() {
359
+ return this.toString();
360
+ }
361
+ static toString() {
362
+ return $$.$mol_func_name(this);
363
+ }
364
+ static make(...params) {
365
+ return new this(...params);
366
+ }
367
+ }
368
+ $.$mol_error_mix = $mol_error_mix;
369
+ })($ || ($ = {}));
370
+
345
371
  ;
346
372
  "use strict";
347
373
  var $;
@@ -882,398 +908,95 @@ var $;
882
908
  "use strict";
883
909
  var $;
884
910
  (function ($) {
885
- function $mol_exec(dir, command, ...args) {
886
- let [app, ...args0] = command.split(' ');
887
- args = [...args0, ...args];
888
- this.$mol_log3_come({
889
- place: '$mol_exec',
890
- dir: $node.path.relative('', dir),
891
- message: 'Run',
892
- command: `${app} ${args.join(' ')}`,
893
- });
894
- var res = $node['child_process'].spawnSync(app, args, {
895
- cwd: $node.path.resolve(dir),
896
- shell: true,
897
- env: this.$mol_env(),
898
- });
899
- if (res.status || res.error) {
900
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
901
- }
902
- if (!res.stdout)
903
- res.stdout = Buffer.from([]);
904
- return res;
905
- }
906
- $.$mol_exec = $mol_exec;
907
- })($ || ($ = {}));
908
-
909
- ;
910
- "use strict";
911
- var $;
912
- (function ($) {
913
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
914
- const encoder = new TextEncoder();
915
- function $mol_charset_encode(value) {
916
- return encoder.encode(value);
917
- }
918
- $.$mol_charset_encode = $mol_charset_encode;
911
+ let $mol_wire_cursor;
912
+ (function ($mol_wire_cursor) {
913
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
914
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
915
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
916
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
917
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
919
918
  })($ || ($ = {}));
920
919
 
921
920
  ;
922
921
  "use strict";
923
922
  var $;
924
923
  (function ($) {
925
- function $mol_int62_string_ensure(str) {
926
- if (typeof str !== 'string')
927
- return null;
928
- return $mol_int62_from_string(str) && str;
929
- }
930
- $.$mol_int62_string_ensure = $mol_int62_string_ensure;
931
- $.$mol_int62_max = (2 ** 30) - 1;
932
- $.$mol_int62_min = -(2 ** 30);
933
- $.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
934
- function $mol_int62_to_string({ lo, hi }) {
935
- lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
936
- hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
937
- return lo.toString(36) + '_' + hi.toString(36);
938
- }
939
- $.$mol_int62_to_string = $mol_int62_to_string;
940
- function $mol_int62_from_string(str) {
941
- const [str_lo, str_hi] = str.split('_');
942
- const int_lo = parseInt(str_lo, 36);
943
- const int_hi = parseInt(str_hi, 36);
944
- if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
945
- return null;
924
+ class $mol_wire_pub extends Object {
925
+ data = [];
926
+ static get [Symbol.species]() {
927
+ return Array;
946
928
  }
947
- return {
948
- lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
949
- hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
950
- };
951
- }
952
- $.$mol_int62_from_string = $mol_int62_from_string;
953
- function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
954
- return (right_hi - left_hi) || (right_lo - left_lo);
955
- }
956
- $.$mol_int62_compare = $mol_int62_compare;
957
- function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
958
- if (lo === max) {
959
- return { lo: -max, hi: hi + 1 };
929
+ sub_from = 0;
930
+ get sub_list() {
931
+ const res = [];
932
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
933
+ res.push(this.data[i]);
934
+ }
935
+ return res;
960
936
  }
961
- else {
962
- return { lo: lo + 1, hi };
937
+ get sub_empty() {
938
+ return this.sub_from === this.data.length;
963
939
  }
964
- }
965
- $.$mol_int62_inc = $mol_int62_inc;
966
- function $mol_int62_random() {
967
- return {
968
- lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
969
- hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
970
- };
971
- }
972
- $.$mol_int62_random = $mol_int62_random;
973
- function $mol_int62_hash_string(str) {
974
- return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
975
- }
976
- $.$mol_int62_hash_string = $mol_int62_hash_string;
977
- function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
978
- let h1 = 0xdeadbeef ^ seed.lo;
979
- let h2 = 0x41c6ce57 ^ seed.hi;
980
- for (const byte of buf) {
981
- h1 = Math.imul(h1 ^ byte, 2654435761);
982
- h2 = Math.imul(h2 ^ byte, 1597334677);
940
+ sub_on(sub, pub_pos) {
941
+ const pos = this.data.length;
942
+ this.data.push(sub, pub_pos);
943
+ return pos;
983
944
  }
984
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
985
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
986
- return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
987
- }
988
- $.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
989
- })($ || ($ = {}));
990
-
991
- ;
992
- "use strict";
993
-
994
- ;
995
- "use strict";
996
- var $;
997
- (function ($) {
998
- function $mol_data_setup(value, config) {
999
- return Object.assign(value, {
1000
- config,
1001
- Value: null
1002
- });
1003
- }
1004
- $.$mol_data_setup = $mol_data_setup;
1005
- })($ || ($ = {}));
1006
-
1007
- ;
1008
- "use strict";
1009
- var $;
1010
- (function ($) {
1011
- class $mol_error_mix extends AggregateError {
1012
- cause;
1013
- name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
1014
- constructor(message, cause = {}, ...errors) {
1015
- super(errors, message, { cause });
1016
- this.cause = cause;
1017
- const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
1018
- Object.defineProperty(this, 'stack', {
1019
- get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
1020
- .replace(/at /gm, ' at ')
1021
- .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
1022
- });
945
+ sub_off(sub_pos) {
946
+ if (!(sub_pos < this.data.length)) {
947
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
948
+ }
949
+ const end = this.data.length - 2;
950
+ if (sub_pos !== end) {
951
+ this.peer_move(end, sub_pos);
952
+ }
953
+ this.data.pop();
954
+ this.data.pop();
955
+ if (this.data.length === this.sub_from)
956
+ this.reap();
1023
957
  }
1024
- static [Symbol.toPrimitive]() {
1025
- return this.toString();
958
+ reap() { }
959
+ promote() {
960
+ $mol_wire_auto()?.track_next(this);
1026
961
  }
1027
- static toString() {
1028
- return $$.$mol_func_name(this);
962
+ fresh() { }
963
+ complete() { }
964
+ get incompleted() {
965
+ return false;
1029
966
  }
1030
- static make(...params) {
1031
- return new this(...params);
967
+ emit(quant = $mol_wire_cursor.stale) {
968
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
969
+ ;
970
+ this.data[i].absorb(quant);
971
+ }
972
+ }
973
+ peer_move(from_pos, to_pos) {
974
+ const peer = this.data[from_pos];
975
+ const self_pos = this.data[from_pos + 1];
976
+ this.data[to_pos] = peer;
977
+ this.data[to_pos + 1] = self_pos;
978
+ peer.peer_repos(self_pos, to_pos);
979
+ }
980
+ peer_repos(peer_pos, self_pos) {
981
+ this.data[peer_pos + 1] = self_pos;
1032
982
  }
1033
983
  }
1034
- $.$mol_error_mix = $mol_error_mix;
984
+ $.$mol_wire_pub = $mol_wire_pub;
1035
985
  })($ || ($ = {}));
1036
986
 
1037
987
  ;
1038
988
  "use strict";
1039
- var $;
1040
- (function ($) {
1041
- class $mol_data_error extends $mol_error_mix {
1042
- }
1043
- $.$mol_data_error = $mol_data_error;
1044
- })($ || ($ = {}));
1045
989
 
1046
990
  ;
1047
991
  "use strict";
1048
992
  var $;
1049
993
  (function ($) {
1050
- function $mol_data_enum(name, dict) {
1051
- const index = {};
1052
- for (let key in dict) {
1053
- if (Number.isNaN(Number(key))) {
1054
- index[dict[key]] = key;
1055
- }
1056
- }
1057
- return $mol_data_setup((value) => {
1058
- if (typeof index[value] !== 'string') {
1059
- return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
1060
- }
1061
- return value;
1062
- }, { name, dict });
994
+ $.$mol_wire_auto_sub = null;
995
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
996
+ return $.$mol_wire_auto_sub = next;
1063
997
  }
1064
- $.$mol_data_enum = $mol_data_enum;
1065
- })($ || ($ = {}));
1066
-
1067
- ;
1068
- "use strict";
1069
- var $;
1070
- (function ($) {
1071
- $.$mol_crypto_native = $node.crypto.webcrypto;
1072
- })($ || ($ = {}));
1073
-
1074
- ;
1075
- "use strict";
1076
- var $;
1077
- (function ($) {
1078
- function $mol_base64_encode(src) {
1079
- throw new Error('Not implemented');
1080
- }
1081
- $.$mol_base64_encode = $mol_base64_encode;
1082
- })($ || ($ = {}));
1083
-
1084
- ;
1085
- "use strict";
1086
- var $;
1087
- (function ($) {
1088
- function $mol_base64_encode_node(str) {
1089
- if (!str)
1090
- return '';
1091
- if (Buffer.isBuffer(str))
1092
- return str.toString('base64');
1093
- return Buffer.from(str).toString('base64');
1094
- }
1095
- $.$mol_base64_encode_node = $mol_base64_encode_node;
1096
- $.$mol_base64_encode = $mol_base64_encode_node;
1097
- })($ || ($ = {}));
1098
-
1099
- ;
1100
- "use strict";
1101
- var $;
1102
- (function ($) {
1103
- function $mol_base64_decode(base64) {
1104
- throw new Error('Not implemented');
1105
- }
1106
- $.$mol_base64_decode = $mol_base64_decode;
1107
- })($ || ($ = {}));
1108
-
1109
- ;
1110
- "use strict";
1111
- var $;
1112
- (function ($) {
1113
- function $mol_base64_decode_node(base64Str) {
1114
- base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
1115
- const buffer = Buffer.from(base64Str, 'base64');
1116
- return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1117
- }
1118
- $.$mol_base64_decode_node = $mol_base64_decode_node;
1119
- $.$mol_base64_decode = $mol_base64_decode_node;
1120
- })($ || ($ = {}));
1121
-
1122
- ;
1123
- "use strict";
1124
- var $;
1125
- (function ($) {
1126
- function $mol_base64_url_encode(buffer) {
1127
- return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
1128
- }
1129
- $.$mol_base64_url_encode = $mol_base64_url_encode;
1130
- function $mol_base64_url_decode(str) {
1131
- return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
1132
- }
1133
- $.$mol_base64_url_decode = $mol_base64_url_decode;
1134
- })($ || ($ = {}));
1135
-
1136
- ;
1137
- "use strict";
1138
- var $;
1139
- (function ($) {
1140
- const algorithm = {
1141
- name: 'ECDSA',
1142
- hash: 'SHA-256',
1143
- namedCurve: "P-256",
1144
- };
1145
- async function $mol_crypto_auditor_pair() {
1146
- const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
1147
- return {
1148
- public: new $mol_crypto_auditor_public(pair.publicKey),
1149
- private: new $mol_crypto_auditor_private(pair.privateKey),
1150
- };
1151
- }
1152
- $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
1153
- class $mol_crypto_auditor_public extends Object {
1154
- native;
1155
- static size_str = 86;
1156
- static size_bin = 64;
1157
- constructor(native) {
1158
- super();
1159
- this.native = native;
1160
- }
1161
- static async from(serial) {
1162
- if (typeof serial !== 'string') {
1163
- serial = $mol_base64_url_encode(serial.subarray(0, 32))
1164
- + $mol_base64_url_encode(serial.subarray(32, 64));
1165
- }
1166
- return new this(await $mol_crypto_native.subtle.importKey('jwk', {
1167
- crv: "P-256",
1168
- ext: true,
1169
- key_ops: ['verify'],
1170
- kty: "EC",
1171
- x: serial.slice(0, 43),
1172
- y: serial.slice(43, 86),
1173
- }, algorithm, true, ['verify']));
1174
- }
1175
- async serial() {
1176
- const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1177
- return x + y;
1178
- }
1179
- async toArray() {
1180
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1181
- return new Uint8Array([
1182
- ...$mol_base64_url_decode(x),
1183
- ...$mol_base64_url_decode(y),
1184
- ]);
1185
- }
1186
- async verify(data, sign) {
1187
- return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
1188
- }
1189
- }
1190
- $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
1191
- class $mol_crypto_auditor_private extends Object {
1192
- native;
1193
- static size_str = 129;
1194
- static size_bin = 96;
1195
- constructor(native) {
1196
- super();
1197
- this.native = native;
1198
- }
1199
- static async from(serial) {
1200
- if (typeof serial !== 'string') {
1201
- serial = $mol_base64_url_encode(serial.subarray(0, 32))
1202
- + $mol_base64_url_encode(serial.subarray(32, 64))
1203
- + $mol_base64_url_encode(serial.subarray(64));
1204
- }
1205
- return new this(await $mol_crypto_native.subtle.importKey('jwk', {
1206
- crv: "P-256",
1207
- ext: true,
1208
- key_ops: ['sign'],
1209
- kty: "EC",
1210
- x: serial.slice(0, 43),
1211
- y: serial.slice(43, 86),
1212
- d: serial.slice(86, 129),
1213
- }, algorithm, true, ['sign']));
1214
- }
1215
- async serial() {
1216
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1217
- return x + y + d;
1218
- }
1219
- async toArray() {
1220
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1221
- return new Uint8Array([
1222
- ...$mol_base64_url_decode(x),
1223
- ...$mol_base64_url_decode(y),
1224
- ...$mol_base64_url_decode(d),
1225
- ]);
1226
- }
1227
- async sign(data) {
1228
- return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
1229
- }
1230
- async public() {
1231
- return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
1232
- }
1233
- }
1234
- $.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
1235
- $.$mol_crypto_auditor_sign_size = 64;
1236
- function $mol_crypto_auditor_private_to_public(serial) {
1237
- return serial.slice(0, 86);
1238
- }
1239
- $.$mol_crypto_auditor_private_to_public = $mol_crypto_auditor_private_to_public;
1240
- })($ || ($ = {}));
1241
-
1242
- ;
1243
- "use strict";
1244
- var $;
1245
- (function ($) {
1246
- let $hyoo_crowd_peer_level;
1247
- (function ($hyoo_crowd_peer_level) {
1248
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["get"] = 0] = "get";
1249
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["add"] = 1] = "add";
1250
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["mod"] = 2] = "mod";
1251
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["law"] = 3] = "law";
1252
- })($hyoo_crowd_peer_level = $.$hyoo_crowd_peer_level || ($.$hyoo_crowd_peer_level = {}));
1253
- class $hyoo_crowd_peer extends Object {
1254
- key_public;
1255
- key_public_serial;
1256
- key_private;
1257
- key_private_serial;
1258
- id;
1259
- constructor(key_public, key_public_serial, key_private, key_private_serial) {
1260
- super();
1261
- this.key_public = key_public;
1262
- this.key_public_serial = key_public_serial;
1263
- this.key_private = key_private;
1264
- this.key_private_serial = key_private_serial;
1265
- this.id = $mol_int62_hash_string(this.key_public_serial);
1266
- }
1267
- static async generate() {
1268
- const pair = await $$.$mol_crypto_auditor_pair();
1269
- const serial = await pair.private.serial();
1270
- return new this(pair.public, $mol_crypto_auditor_private_to_public(serial), pair.private, serial);
1271
- }
1272
- static async restore(serial) {
1273
- return new this(await $$.$mol_crypto_auditor_public.from(serial), $mol_crypto_auditor_private_to_public(serial), await $$.$mol_crypto_auditor_private.from(serial), serial);
1274
- }
1275
- }
1276
- $.$hyoo_crowd_peer = $hyoo_crowd_peer;
998
+ $.$mol_wire_auto = $mol_wire_auto;
999
+ $.$mol_wire_affected = [];
1277
1000
  })($ || ($ = {}));
1278
1001
 
1279
1002
  ;
@@ -1378,618 +1101,287 @@ var $;
1378
1101
  });
1379
1102
  })($ || ($ = {}));
1380
1103
 
1381
- ;
1382
- "use strict";
1383
-
1384
- ;
1385
- "use strict";
1386
- var $;
1387
- (function ($) {
1388
- const decoders = {};
1389
- function $mol_charset_decode(buffer, encoding = 'utf8') {
1390
- let decoder = decoders[encoding];
1391
- if (!decoder)
1392
- decoder = decoders[encoding] = new TextDecoder(encoding);
1393
- return decoder.decode(buffer);
1394
- }
1395
- $.$mol_charset_decode = $mol_charset_decode;
1396
- })($ || ($ = {}));
1397
-
1398
1104
  ;
1399
1105
  "use strict";
1400
1106
  var $;
1401
1107
  (function ($) {
1402
- const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
1403
- let $hyoo_crowd_unit_kind;
1404
- (function ($hyoo_crowd_unit_kind) {
1405
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
1406
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
1407
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
1408
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
1409
- })($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
1410
- let $hyoo_crowd_unit_group;
1411
- (function ($hyoo_crowd_unit_group) {
1412
- $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
1413
- $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
1414
- })($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
1415
- class $hyoo_crowd_unit extends Object {
1416
- land;
1417
- auth;
1418
- head;
1419
- self;
1420
- next;
1421
- prev;
1422
- time;
1423
- data;
1424
- bin;
1425
- constructor(land, auth, head, self, next, prev, time, data, bin) {
1426
- super();
1427
- this.land = land;
1428
- this.auth = auth;
1429
- this.head = head;
1430
- this.self = self;
1431
- this.next = next;
1432
- this.prev = prev;
1433
- this.time = time;
1434
- this.data = data;
1435
- this.bin = bin;
1436
- }
1437
- kind() {
1438
- if (this.head === this.self && this.auth === this.self) {
1439
- if (this.head === this.land) {
1440
- return $hyoo_crowd_unit_kind.grab;
1108
+ class $mol_wire_pub_sub extends $mol_wire_pub {
1109
+ pub_from = 0;
1110
+ cursor = $mol_wire_cursor.stale;
1111
+ get temp() {
1112
+ return false;
1113
+ }
1114
+ get pub_list() {
1115
+ const res = [];
1116
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1117
+ for (let i = this.pub_from; i < max; i += 2) {
1118
+ if (this.data[i])
1119
+ res.push(this.data[i]);
1120
+ }
1121
+ return res;
1122
+ }
1123
+ track_on() {
1124
+ this.cursor = this.pub_from;
1125
+ const sub = $mol_wire_auto();
1126
+ $mol_wire_auto(this);
1127
+ return sub;
1128
+ }
1129
+ promote() {
1130
+ if (this.cursor >= this.pub_from) {
1131
+ $mol_fail(new Error('Circular subscription'));
1132
+ }
1133
+ super.promote();
1134
+ }
1135
+ track_next(pub) {
1136
+ if (this.cursor < 0)
1137
+ $mol_fail(new Error('Promo to non begun sub'));
1138
+ if (this.cursor < this.sub_from) {
1139
+ const next = this.data[this.cursor];
1140
+ if (pub === undefined)
1141
+ return next ?? null;
1142
+ if (next === pub) {
1143
+ this.cursor += 2;
1144
+ return next;
1441
1145
  }
1442
- else {
1443
- return $hyoo_crowd_unit_kind.join;
1146
+ if (next) {
1147
+ if (this.sub_from < this.data.length) {
1148
+ this.peer_move(this.sub_from, this.data.length);
1149
+ }
1150
+ this.peer_move(this.cursor, this.sub_from);
1151
+ this.sub_from += 2;
1444
1152
  }
1445
1153
  }
1446
- if (this.head === this.land) {
1447
- return $hyoo_crowd_unit_kind.give;
1154
+ else {
1155
+ if (pub === undefined)
1156
+ return null;
1157
+ if (this.sub_from < this.data.length) {
1158
+ this.peer_move(this.sub_from, this.data.length);
1159
+ }
1160
+ this.sub_from += 2;
1448
1161
  }
1449
- return $hyoo_crowd_unit_kind.data;
1450
- }
1451
- group() {
1452
- return this.kind() === $hyoo_crowd_unit_kind.data
1453
- ? $hyoo_crowd_unit_group.data
1454
- : $hyoo_crowd_unit_group.auth;
1162
+ this.data[this.cursor] = pub;
1163
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1164
+ this.cursor += 2;
1165
+ return pub;
1455
1166
  }
1456
- level() {
1457
- switch (this.kind()) {
1458
- case $hyoo_crowd_unit_kind.grab: return $hyoo_crowd_peer_level.law;
1459
- case $hyoo_crowd_unit_kind.give: return level(this.data);
1460
- default: $mol_fail(new Error(`Wrong unit kind for getting level: ${this.kind()}`));
1167
+ track_off(sub) {
1168
+ $mol_wire_auto(sub);
1169
+ if (this.cursor < 0) {
1170
+ $mol_fail(new Error('End of non begun sub'));
1171
+ }
1172
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1173
+ const pub = this.data[cursor];
1174
+ pub.fresh();
1461
1175
  }
1176
+ this.cursor = $mol_wire_cursor.fresh;
1462
1177
  }
1463
- [Symbol.toPrimitive]() {
1464
- return JSON.stringify(this);
1178
+ pub_off(sub_pos) {
1179
+ this.data[sub_pos] = undefined;
1180
+ this.data[sub_pos + 1] = undefined;
1465
1181
  }
1466
- [$mol_dev_format_head]() {
1467
- switch (this.kind()) {
1468
- case $hyoo_crowd_unit_kind.grab:
1469
- return $mol_dev_format_div({}, $mol_dev_format_native(this), ' 👑');
1470
- case $hyoo_crowd_unit_kind.join:
1471
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🔑 ', this.self));
1472
- case $hyoo_crowd_unit_kind.give:
1473
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🏅 ', this.self, ' '), $mol_dev_format_native($hyoo_crowd_peer_level[this.data] ?? this.data));
1474
- case $hyoo_crowd_unit_kind.data:
1475
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 📦 ', this.head, '!', this.self, ' '), $mol_dev_format_native(this.data));
1182
+ destructor() {
1183
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1184
+ const sub = this.data[cursor];
1185
+ const pos = this.data[cursor + 1];
1186
+ sub.pub_off(pos);
1187
+ this.data.pop();
1188
+ this.data.pop();
1476
1189
  }
1190
+ this.cursor = this.pub_from;
1191
+ this.track_cut();
1192
+ this.cursor = $mol_wire_cursor.final;
1477
1193
  }
1478
- }
1479
- $.$hyoo_crowd_unit = $hyoo_crowd_unit;
1480
- const offset = {
1481
- land_lo: 0,
1482
- land_hi: 4,
1483
- auth_lo: 8,
1484
- auth_hi: 12,
1485
- head_lo: 16,
1486
- head_hi: 20,
1487
- self_lo: 24,
1488
- self_hi: 28,
1489
- next_lo: 32,
1490
- next_hi: 36,
1491
- prev_lo: 40,
1492
- prev_hi: 44,
1493
- time: 48,
1494
- size: 54,
1495
- data: 56,
1496
- };
1497
- class $hyoo_crowd_unit_bin extends DataView {
1498
- static from_buffer(buffer) {
1499
- const size = Math.ceil(Math.abs(buffer[offset.size / 2]) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
1500
- return new this(buffer.slice(0, size / 2).buffer);
1194
+ track_cut() {
1195
+ if (this.cursor < this.pub_from) {
1196
+ $mol_fail(new Error('Cut of non begun sub'));
1197
+ }
1198
+ let tail = 0;
1199
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1200
+ const pub = this.data[cursor];
1201
+ pub?.sub_off(this.data[cursor + 1]);
1202
+ if (this.sub_from < this.data.length) {
1203
+ this.peer_move(this.data.length - 2, cursor);
1204
+ this.data.pop();
1205
+ this.data.pop();
1206
+ }
1207
+ else {
1208
+ ++tail;
1209
+ }
1210
+ }
1211
+ for (; tail; --tail) {
1212
+ this.data.pop();
1213
+ this.data.pop();
1214
+ }
1215
+ this.sub_from = this.cursor;
1501
1216
  }
1502
- static from_unit(unit) {
1503
- if (unit.bin)
1504
- return unit.bin;
1505
- const type = unit.data === null
1506
- ? 0
1507
- : unit.data instanceof Uint8Array
1508
- ? -1
1509
- : 1;
1510
- const buff = type === 0 ? null
1511
- : type > 0 ? $mol_charset_encode(JSON.stringify(unit.data))
1512
- : unit.data;
1513
- const size = buff?.byteLength ?? 0;
1514
- if (type > 0 && size > 2 ** 15 - 1)
1515
- throw new Error(`Too large json data: ${size} > ${2 ** 15 - 1}`);
1516
- if (type < 0 && size > 2 ** 15)
1517
- throw new Error(`Too large binary data: ${size} > ${2 ** 15}`);
1518
- const total = offset.data + Math.ceil(size / 8) * 8 + $mol_crypto_auditor_sign_size;
1519
- const mem = new Uint8Array(total);
1520
- const bin = new $hyoo_crowd_unit_bin(mem.buffer);
1521
- const land = $mol_int62_from_string(unit.land);
1522
- bin.setInt32(offset.land_lo, land.lo, true);
1523
- bin.setInt32(offset.land_hi, land.hi, true);
1524
- const auth = $mol_int62_from_string(unit.auth);
1525
- bin.setInt32(offset.auth_lo, auth.lo, true);
1526
- bin.setInt32(offset.auth_hi, auth.hi, true);
1527
- const head = $mol_int62_from_string(unit.head);
1528
- bin.setInt32(offset.head_lo, head.lo, true);
1529
- bin.setInt32(offset.head_hi, head.hi, true);
1530
- const self = $mol_int62_from_string(unit.self);
1531
- bin.setInt32(offset.self_lo, self.lo, true);
1532
- bin.setInt32(offset.self_hi, self.hi, true);
1533
- const next = $mol_int62_from_string(unit.next);
1534
- bin.setInt32(offset.next_lo, next.lo, true);
1535
- bin.setInt32(offset.next_hi, next.hi, true);
1536
- const prev = $mol_int62_from_string(unit.prev);
1537
- bin.setInt32(offset.prev_lo, prev.lo, true);
1538
- bin.setInt32(offset.prev_hi, prev.hi, true);
1539
- bin.setInt32(offset.time, unit.time, true);
1540
- bin.setInt16(offset.size, type * size, true);
1541
- if (buff)
1542
- mem.set(buff, offset.data);
1543
- return bin;
1217
+ complete() { }
1218
+ complete_pubs() {
1219
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1220
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1221
+ const pub = this.data[cursor];
1222
+ if (pub?.incompleted)
1223
+ return;
1224
+ }
1225
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1226
+ const pub = this.data[cursor];
1227
+ pub?.complete();
1228
+ }
1544
1229
  }
1545
- sign(next) {
1546
- const sign_offset = this.byteOffset + this.byteLength - $mol_crypto_auditor_sign_size;
1547
- const buff = new Uint8Array(this.buffer, sign_offset, $mol_crypto_auditor_sign_size);
1548
- if (!next)
1549
- return buff;
1550
- buff.set(next);
1551
- return buff;
1230
+ absorb(quant = $mol_wire_cursor.stale) {
1231
+ if (this.cursor === $mol_wire_cursor.final)
1232
+ return;
1233
+ if (this.cursor >= quant)
1234
+ return;
1235
+ this.cursor = quant;
1236
+ this.emit($mol_wire_cursor.doubt);
1552
1237
  }
1553
- size() {
1554
- return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
1238
+ [$mol_dev_format_head]() {
1239
+ return $mol_dev_format_native(this);
1555
1240
  }
1556
- sens() {
1557
- return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
1241
+ get pub_empty() {
1242
+ return this.sub_from === this.pub_from;
1558
1243
  }
1559
- unit() {
1560
- const land = $mol_int62_to_string({
1561
- lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
1562
- hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
1244
+ }
1245
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1246
+ })($ || ($ = {}));
1247
+
1248
+ ;
1249
+ "use strict";
1250
+ var $;
1251
+ (function ($) {
1252
+ class $mol_after_tick extends $mol_object2 {
1253
+ task;
1254
+ static promise = null;
1255
+ cancelled = false;
1256
+ constructor(task) {
1257
+ super();
1258
+ this.task = task;
1259
+ if (!$mol_after_tick.promise)
1260
+ $mol_after_tick.promise = Promise.resolve().then(() => {
1261
+ $mol_after_tick.promise = null;
1262
+ });
1263
+ $mol_after_tick.promise.then(() => {
1264
+ if (this.cancelled)
1265
+ return;
1266
+ task();
1563
1267
  });
1564
- const auth = $mol_int62_to_string({
1565
- lo: this.getInt32(offset.auth_lo, true) << 1 >> 1,
1566
- hi: this.getInt32(offset.auth_hi, true) << 1 >> 1,
1567
- });
1568
- const head = $mol_int62_to_string({
1569
- lo: this.getInt32(offset.head_lo, true) << 1 >> 1,
1570
- hi: this.getInt32(offset.head_hi, true) << 1 >> 1,
1571
- });
1572
- const self = $mol_int62_to_string({
1573
- lo: this.getInt32(offset.self_lo, true) << 1 >> 1,
1574
- hi: this.getInt32(offset.self_hi, true) << 1 >> 1,
1575
- });
1576
- const next = $mol_int62_to_string({
1577
- lo: this.getInt32(offset.next_lo, true) << 1 >> 1,
1578
- hi: this.getInt32(offset.next_hi, true) << 1 >> 1,
1579
- });
1580
- const prev = $mol_int62_to_string({
1581
- lo: this.getInt32(offset.prev_lo, true) << 1 >> 1,
1582
- hi: this.getInt32(offset.prev_hi, true) << 1 >> 1,
1583
- });
1584
- const time = this.getInt32(offset.time, true) << 1 >> 1;
1585
- const type_size = this.getInt16(offset.size, true);
1586
- let data = null;
1587
- if (type_size) {
1588
- try {
1589
- var buff = new Uint8Array(this.buffer, this.byteOffset + offset.data, Math.abs(type_size));
1590
- }
1591
- catch (error) {
1592
- error['message'] += `\nhead=${head};self=${self}`;
1593
- $mol_fail_hidden(error);
1594
- }
1595
- if (type_size < 0)
1596
- data = buff;
1597
- else
1598
- data = JSON.parse($mol_charset_decode(buff));
1599
- }
1600
- return new $hyoo_crowd_unit(land, auth, head, self, next, prev, time, data, this);
1268
+ }
1269
+ destructor() {
1270
+ this.cancelled = true;
1601
1271
  }
1602
1272
  }
1603
- $.$hyoo_crowd_unit_bin = $hyoo_crowd_unit_bin;
1604
- function $hyoo_crowd_unit_compare(left, right) {
1605
- return (left.group() - right.group())
1606
- || (left.time - right.time)
1607
- || ((left.auth > right.auth) ? 1 : (left.auth < right.auth) ? -1 : 0)
1608
- || ((left.self > right.self) ? 1 : (left.self < right.self) ? -1 : 0)
1609
- || ((left.head > right.head) ? 1 : (left.head < right.head) ? -1 : 0)
1610
- || ((left.prev > right.prev) ? 1 : (left.prev < right.prev) ? -1 : 0)
1611
- || ((left.next > right.next) ? 1 : (left.next < right.next) ? -1 : 0)
1612
- || ((left.land > right.land) ? 1 : (left.land < right.land) ? -1 : 0);
1613
- }
1614
- $.$hyoo_crowd_unit_compare = $hyoo_crowd_unit_compare;
1615
- })($ || ($ = {}));
1616
-
1617
- ;
1618
- "use strict";
1619
- var $;
1620
- (function ($) {
1621
- let $mol_wire_cursor;
1622
- (function ($mol_wire_cursor) {
1623
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
1624
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
1625
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
1626
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
1627
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
1273
+ $.$mol_after_tick = $mol_after_tick;
1628
1274
  })($ || ($ = {}));
1629
1275
 
1630
1276
  ;
1631
1277
  "use strict";
1632
1278
  var $;
1633
1279
  (function ($) {
1634
- class $mol_wire_pub extends Object {
1635
- data = [];
1636
- static get [Symbol.species]() {
1637
- return Array;
1280
+ const handled = new WeakSet();
1281
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1282
+ task;
1283
+ host;
1284
+ static warm = true;
1285
+ static planning = new Set();
1286
+ static reaping = new Set();
1287
+ static plan_task = null;
1288
+ static plan() {
1289
+ if (this.plan_task)
1290
+ return;
1291
+ this.plan_task = new $mol_after_tick(() => {
1292
+ try {
1293
+ this.sync();
1294
+ }
1295
+ finally {
1296
+ $mol_wire_fiber.plan_task = null;
1297
+ }
1298
+ });
1638
1299
  }
1639
- sub_from = 0;
1640
- get sub_list() {
1641
- const res = [];
1642
- for (let i = this.sub_from; i < this.data.length; i += 2) {
1643
- res.push(this.data[i]);
1300
+ static sync() {
1301
+ while (this.planning.size) {
1302
+ for (const fiber of this.planning) {
1303
+ this.planning.delete(fiber);
1304
+ if (fiber.cursor >= 0)
1305
+ continue;
1306
+ if (fiber.cursor === $mol_wire_cursor.final)
1307
+ continue;
1308
+ fiber.fresh();
1309
+ }
1310
+ }
1311
+ while (this.reaping.size) {
1312
+ const fibers = this.reaping;
1313
+ this.reaping = new Set;
1314
+ for (const fiber of fibers) {
1315
+ if (!fiber.sub_empty)
1316
+ continue;
1317
+ fiber.destructor();
1318
+ }
1644
1319
  }
1645
- return res;
1646
1320
  }
1647
- get sub_empty() {
1648
- return this.sub_from === this.data.length;
1321
+ [Symbol.toStringTag];
1322
+ cache = undefined;
1323
+ get args() {
1324
+ return this.data.slice(0, this.pub_from);
1649
1325
  }
1650
- sub_on(sub, pub_pos) {
1651
- const pos = this.data.length;
1652
- this.data.push(sub, pub_pos);
1653
- return pos;
1326
+ result() {
1327
+ if ($mol_promise_like(this.cache))
1328
+ return;
1329
+ if (this.cache instanceof Error)
1330
+ return;
1331
+ return this.cache;
1654
1332
  }
1655
- sub_off(sub_pos) {
1656
- if (!(sub_pos < this.data.length)) {
1657
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
1658
- }
1659
- const end = this.data.length - 2;
1660
- if (sub_pos !== end) {
1661
- this.peer_move(end, sub_pos);
1662
- }
1663
- this.data.pop();
1664
- this.data.pop();
1665
- if (this.data.length === this.sub_from)
1666
- this.reap();
1333
+ get incompleted() {
1334
+ return $mol_promise_like(this.cache);
1667
1335
  }
1668
- reap() { }
1669
- promote() {
1670
- $mol_wire_auto()?.track_next(this);
1336
+ field() {
1337
+ return this.task.name + '<>';
1671
1338
  }
1672
- fresh() { }
1673
- complete() { }
1674
- get incompleted() {
1675
- return false;
1339
+ constructor(id, task, host, args) {
1340
+ super();
1341
+ this.task = task;
1342
+ this.host = host;
1343
+ if (args)
1344
+ this.data.push(...args);
1345
+ this.pub_from = this.sub_from = args?.length ?? 0;
1346
+ this[Symbol.toStringTag] = id;
1676
1347
  }
1677
- emit(quant = $mol_wire_cursor.stale) {
1678
- for (let i = this.sub_from; i < this.data.length; i += 2) {
1679
- ;
1680
- this.data[i].absorb(quant);
1681
- }
1348
+ plan() {
1349
+ $mol_wire_fiber.planning.add(this);
1350
+ $mol_wire_fiber.plan();
1351
+ return this;
1682
1352
  }
1683
- peer_move(from_pos, to_pos) {
1684
- const peer = this.data[from_pos];
1685
- const self_pos = this.data[from_pos + 1];
1686
- this.data[to_pos] = peer;
1687
- this.data[to_pos + 1] = self_pos;
1688
- peer.peer_repos(self_pos, to_pos);
1353
+ reap() {
1354
+ $mol_wire_fiber.reaping.add(this);
1355
+ $mol_wire_fiber.plan();
1689
1356
  }
1690
- peer_repos(peer_pos, self_pos) {
1691
- this.data[peer_pos + 1] = self_pos;
1357
+ toString() {
1358
+ return this[Symbol.toStringTag];
1692
1359
  }
1693
- }
1694
- $.$mol_wire_pub = $mol_wire_pub;
1695
- })($ || ($ = {}));
1696
-
1697
- ;
1698
- "use strict";
1699
-
1700
- ;
1701
- "use strict";
1702
- var $;
1703
- (function ($) {
1704
- $.$mol_wire_auto_sub = null;
1705
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
1706
- return $.$mol_wire_auto_sub = next;
1707
- }
1708
- $.$mol_wire_auto = $mol_wire_auto;
1709
- $.$mol_wire_affected = [];
1710
- })($ || ($ = {}));
1711
-
1712
- ;
1713
- "use strict";
1714
- var $;
1715
- (function ($) {
1716
- class $mol_wire_pub_sub extends $mol_wire_pub {
1717
- pub_from = 0;
1718
- cursor = $mol_wire_cursor.stale;
1719
- get temp() {
1720
- return false;
1360
+ toJSON() {
1361
+ return this[Symbol.toStringTag];
1721
1362
  }
1722
- get pub_list() {
1723
- const res = [];
1724
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1725
- for (let i = this.pub_from; i < max; i += 2) {
1726
- if (this.data[i])
1727
- res.push(this.data[i]);
1728
- }
1729
- return res;
1363
+ [$mol_dev_format_head]() {
1364
+ const cursor = {
1365
+ [$mol_wire_cursor.stale]: '🔴',
1366
+ [$mol_wire_cursor.doubt]: '🟡',
1367
+ [$mol_wire_cursor.fresh]: '🟢',
1368
+ [$mol_wire_cursor.final]: '🔵',
1369
+ }[this.cursor] ?? this.cursor.toString();
1370
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1371
+ ? $mol_dev_format_auto({
1372
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1373
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1374
+ })
1375
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1730
1376
  }
1731
- track_on() {
1732
- this.cursor = this.pub_from;
1733
- const sub = $mol_wire_auto();
1734
- $mol_wire_auto(this);
1735
- return sub;
1377
+ get $() {
1378
+ return (this.host ?? this.task)['$'];
1736
1379
  }
1737
- promote() {
1738
- if (this.cursor >= this.pub_from) {
1739
- $mol_fail(new Error('Circular subscription'));
1740
- }
1741
- super.promote();
1742
- }
1743
- track_next(pub) {
1744
- if (this.cursor < 0)
1745
- $mol_fail(new Error('Promo to non begun sub'));
1746
- if (this.cursor < this.sub_from) {
1747
- const next = this.data[this.cursor];
1748
- if (pub === undefined)
1749
- return next ?? null;
1750
- if (next === pub) {
1751
- this.cursor += 2;
1752
- return next;
1753
- }
1754
- if (next) {
1755
- if (this.sub_from < this.data.length) {
1756
- this.peer_move(this.sub_from, this.data.length);
1757
- }
1758
- this.peer_move(this.cursor, this.sub_from);
1759
- this.sub_from += 2;
1760
- }
1761
- }
1762
- else {
1763
- if (pub === undefined)
1764
- return null;
1765
- if (this.sub_from < this.data.length) {
1766
- this.peer_move(this.sub_from, this.data.length);
1767
- }
1768
- this.sub_from += 2;
1769
- }
1770
- this.data[this.cursor] = pub;
1771
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1772
- this.cursor += 2;
1773
- return pub;
1774
- }
1775
- track_off(sub) {
1776
- $mol_wire_auto(sub);
1777
- if (this.cursor < 0) {
1778
- $mol_fail(new Error('End of non begun sub'));
1779
- }
1780
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1781
- const pub = this.data[cursor];
1782
- pub.fresh();
1783
- }
1784
- this.cursor = $mol_wire_cursor.fresh;
1785
- }
1786
- pub_off(sub_pos) {
1787
- this.data[sub_pos] = undefined;
1788
- this.data[sub_pos + 1] = undefined;
1789
- }
1790
- destructor() {
1791
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1792
- const sub = this.data[cursor];
1793
- const pos = this.data[cursor + 1];
1794
- sub.pub_off(pos);
1795
- this.data.pop();
1796
- this.data.pop();
1797
- }
1798
- this.cursor = this.pub_from;
1799
- this.track_cut();
1800
- this.cursor = $mol_wire_cursor.final;
1801
- }
1802
- track_cut() {
1803
- if (this.cursor < this.pub_from) {
1804
- $mol_fail(new Error('Cut of non begun sub'));
1805
- }
1806
- let tail = 0;
1807
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1808
- const pub = this.data[cursor];
1809
- pub?.sub_off(this.data[cursor + 1]);
1810
- if (this.sub_from < this.data.length) {
1811
- this.peer_move(this.data.length - 2, cursor);
1812
- this.data.pop();
1813
- this.data.pop();
1814
- }
1815
- else {
1816
- ++tail;
1817
- }
1818
- }
1819
- for (; tail; --tail) {
1820
- this.data.pop();
1821
- this.data.pop();
1822
- }
1823
- this.sub_from = this.cursor;
1824
- }
1825
- complete() { }
1826
- complete_pubs() {
1827
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1828
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1829
- const pub = this.data[cursor];
1830
- if (pub?.incompleted)
1831
- return;
1832
- }
1833
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1834
- const pub = this.data[cursor];
1835
- pub?.complete();
1836
- }
1837
- }
1838
- absorb(quant = $mol_wire_cursor.stale) {
1839
- if (this.cursor === $mol_wire_cursor.final)
1840
- return;
1841
- if (this.cursor >= quant)
1842
- return;
1843
- this.cursor = quant;
1844
- this.emit($mol_wire_cursor.doubt);
1845
- }
1846
- [$mol_dev_format_head]() {
1847
- return $mol_dev_format_native(this);
1848
- }
1849
- get pub_empty() {
1850
- return this.sub_from === this.pub_from;
1851
- }
1852
- }
1853
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1854
- })($ || ($ = {}));
1855
-
1856
- ;
1857
- "use strict";
1858
- var $;
1859
- (function ($) {
1860
- class $mol_after_tick extends $mol_object2 {
1861
- task;
1862
- static promise = null;
1863
- cancelled = false;
1864
- constructor(task) {
1865
- super();
1866
- this.task = task;
1867
- if (!$mol_after_tick.promise)
1868
- $mol_after_tick.promise = Promise.resolve().then(() => {
1869
- $mol_after_tick.promise = null;
1870
- });
1871
- $mol_after_tick.promise.then(() => {
1872
- if (this.cancelled)
1873
- return;
1874
- task();
1875
- });
1876
- }
1877
- destructor() {
1878
- this.cancelled = true;
1879
- }
1880
- }
1881
- $.$mol_after_tick = $mol_after_tick;
1882
- })($ || ($ = {}));
1883
-
1884
- ;
1885
- "use strict";
1886
- var $;
1887
- (function ($) {
1888
- const handled = new WeakSet();
1889
- class $mol_wire_fiber extends $mol_wire_pub_sub {
1890
- task;
1891
- host;
1892
- static warm = true;
1893
- static planning = new Set();
1894
- static reaping = new Set();
1895
- static plan_task = null;
1896
- static plan() {
1897
- if (this.plan_task)
1898
- return;
1899
- this.plan_task = new $mol_after_tick(() => {
1900
- try {
1901
- this.sync();
1902
- }
1903
- finally {
1904
- $mol_wire_fiber.plan_task = null;
1905
- }
1906
- });
1907
- }
1908
- static sync() {
1909
- while (this.planning.size) {
1910
- for (const fiber of this.planning) {
1911
- this.planning.delete(fiber);
1912
- if (fiber.cursor >= 0)
1913
- continue;
1914
- if (fiber.cursor === $mol_wire_cursor.final)
1915
- continue;
1916
- fiber.fresh();
1917
- }
1918
- }
1919
- while (this.reaping.size) {
1920
- const fibers = this.reaping;
1921
- this.reaping = new Set;
1922
- for (const fiber of fibers) {
1923
- if (!fiber.sub_empty)
1924
- continue;
1925
- fiber.destructor();
1926
- }
1927
- }
1928
- }
1929
- [Symbol.toStringTag];
1930
- cache = undefined;
1931
- get args() {
1932
- return this.data.slice(0, this.pub_from);
1933
- }
1934
- result() {
1935
- if ($mol_promise_like(this.cache))
1936
- return;
1937
- if (this.cache instanceof Error)
1938
- return;
1939
- return this.cache;
1940
- }
1941
- get incompleted() {
1942
- return $mol_promise_like(this.cache);
1943
- }
1944
- field() {
1945
- return this.task.name + '<>';
1946
- }
1947
- constructor(id, task, host, args) {
1948
- super();
1949
- this.task = task;
1950
- this.host = host;
1951
- if (args)
1952
- this.data.push(...args);
1953
- this.pub_from = this.sub_from = args?.length ?? 0;
1954
- this[Symbol.toStringTag] = id;
1955
- }
1956
- plan() {
1957
- $mol_wire_fiber.planning.add(this);
1958
- $mol_wire_fiber.plan();
1959
- return this;
1960
- }
1961
- reap() {
1962
- $mol_wire_fiber.reaping.add(this);
1963
- $mol_wire_fiber.plan();
1964
- }
1965
- toString() {
1966
- return this[Symbol.toStringTag];
1967
- }
1968
- toJSON() {
1969
- return this[Symbol.toStringTag];
1970
- }
1971
- [$mol_dev_format_head]() {
1972
- const cursor = {
1973
- [$mol_wire_cursor.stale]: '🔴',
1974
- [$mol_wire_cursor.doubt]: '🟡',
1975
- [$mol_wire_cursor.fresh]: '🟢',
1976
- [$mol_wire_cursor.final]: '🔵',
1977
- }[this.cursor] ?? this.cursor.toString();
1978
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1979
- ? $mol_dev_format_auto({
1980
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1981
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1982
- })
1983
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1984
- }
1985
- get $() {
1986
- return (this.host ?? this.task)['$'];
1987
- }
1988
- emit(quant = $mol_wire_cursor.stale) {
1989
- if (this.sub_empty)
1990
- this.plan();
1991
- else
1992
- super.emit(quant);
1380
+ emit(quant = $mol_wire_cursor.stale) {
1381
+ if (this.sub_empty)
1382
+ this.plan();
1383
+ else
1384
+ super.emit(quant);
1993
1385
  }
1994
1386
  fresh() {
1995
1387
  if (this.cursor === $mol_wire_cursor.fresh)
@@ -2091,21 +1483,949 @@ var $;
2091
1483
  await new Promise(() => { });
2092
1484
  }
2093
1485
  }
2094
- }
2095
- step() {
2096
- return new Promise(done => {
2097
- const sub = new $mol_wire_pub_sub;
2098
- const prev = sub.track_on();
2099
- sub.track_next(this);
2100
- sub.track_off(prev);
2101
- sub.absorb = () => {
2102
- done(null);
2103
- setTimeout(() => sub.destructor());
2104
- };
2105
- });
1486
+ }
1487
+ step() {
1488
+ return new Promise(done => {
1489
+ const sub = new $mol_wire_pub_sub;
1490
+ const prev = sub.track_on();
1491
+ sub.track_next(this);
1492
+ sub.track_off(prev);
1493
+ sub.absorb = () => {
1494
+ done(null);
1495
+ setTimeout(() => sub.destructor());
1496
+ };
1497
+ });
1498
+ }
1499
+ }
1500
+ $.$mol_wire_fiber = $mol_wire_fiber;
1501
+ })($ || ($ = {}));
1502
+
1503
+ ;
1504
+ "use strict";
1505
+ var $;
1506
+ (function ($) {
1507
+ $.$mol_compare_deep_cache = new WeakMap();
1508
+ function $mol_compare_deep(left, right) {
1509
+ if (Object.is(left, right))
1510
+ return true;
1511
+ if (left === null)
1512
+ return false;
1513
+ if (right === null)
1514
+ return false;
1515
+ if (typeof left !== 'object')
1516
+ return false;
1517
+ if (typeof right !== 'object')
1518
+ return false;
1519
+ const left_proto = Reflect.getPrototypeOf(left);
1520
+ const right_proto = Reflect.getPrototypeOf(right);
1521
+ if (left_proto !== right_proto)
1522
+ return false;
1523
+ if (left instanceof Boolean)
1524
+ return Object.is(left.valueOf(), right['valueOf']());
1525
+ if (left instanceof Number)
1526
+ return Object.is(left.valueOf(), right['valueOf']());
1527
+ if (left instanceof String)
1528
+ return Object.is(left.valueOf(), right['valueOf']());
1529
+ if (left instanceof Date)
1530
+ return Object.is(left.valueOf(), right['valueOf']());
1531
+ if (left instanceof RegExp)
1532
+ return left.source === right.source && left.flags === right.flags;
1533
+ if (left instanceof Error)
1534
+ return left.message === right.message && left.stack === right.stack;
1535
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1536
+ if (left_cache) {
1537
+ const right_cache = left_cache.get(right);
1538
+ if (typeof right_cache === 'boolean')
1539
+ return right_cache;
1540
+ }
1541
+ else {
1542
+ left_cache = new WeakMap();
1543
+ $.$mol_compare_deep_cache.set(left, left_cache);
1544
+ }
1545
+ left_cache.set(right, true);
1546
+ let result;
1547
+ try {
1548
+ if (!left_proto)
1549
+ result = compare_pojo(left, right);
1550
+ else if (!Reflect.getPrototypeOf(left_proto))
1551
+ result = compare_pojo(left, right);
1552
+ else if (Symbol.toPrimitive in left)
1553
+ result = compare_primitive(left, right);
1554
+ else if (Array.isArray(left))
1555
+ result = compare_array(left, right);
1556
+ else if (left instanceof Set)
1557
+ result = compare_set(left, right);
1558
+ else if (left instanceof Map)
1559
+ result = compare_map(left, right);
1560
+ else if (ArrayBuffer.isView(left))
1561
+ result = compare_buffer(left, right);
1562
+ else if (Symbol.iterator in left)
1563
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1564
+ else
1565
+ result = false;
1566
+ }
1567
+ finally {
1568
+ left_cache.set(right, result);
1569
+ }
1570
+ return result;
1571
+ }
1572
+ $.$mol_compare_deep = $mol_compare_deep;
1573
+ function compare_array(left, right) {
1574
+ const len = left.length;
1575
+ if (len !== right.length)
1576
+ return false;
1577
+ for (let i = 0; i < len; ++i) {
1578
+ if (!$mol_compare_deep(left[i], right[i]))
1579
+ return false;
1580
+ }
1581
+ return true;
1582
+ }
1583
+ function compare_buffer(left, right) {
1584
+ const len = left.byteLength;
1585
+ if (len !== right.byteLength)
1586
+ return false;
1587
+ if (left instanceof DataView)
1588
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1589
+ for (let i = 0; i < len; ++i) {
1590
+ if (left[i] !== right[i])
1591
+ return false;
1592
+ }
1593
+ return true;
1594
+ }
1595
+ function compare_iterator(left, right) {
1596
+ while (true) {
1597
+ const left_next = left.next();
1598
+ const right_next = right.next();
1599
+ if (left_next.done !== right_next.done)
1600
+ return false;
1601
+ if (left_next.done)
1602
+ break;
1603
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1604
+ return false;
1605
+ }
1606
+ return true;
1607
+ }
1608
+ function compare_set(left, right) {
1609
+ if (left.size !== right.size)
1610
+ return false;
1611
+ return compare_iterator(left.values(), right.values());
1612
+ }
1613
+ function compare_map(left, right) {
1614
+ if (left.size !== right.size)
1615
+ return false;
1616
+ return compare_iterator(left.keys(), right.keys())
1617
+ && compare_iterator(left.values(), right.values());
1618
+ }
1619
+ function compare_pojo(left, right) {
1620
+ const left_keys = Object.getOwnPropertyNames(left);
1621
+ const right_keys = Object.getOwnPropertyNames(right);
1622
+ if (!compare_array(left_keys, right_keys))
1623
+ return false;
1624
+ for (let key of left_keys) {
1625
+ if (!$mol_compare_deep(left[key], right[key]))
1626
+ return false;
1627
+ }
1628
+ const left_syms = Object.getOwnPropertySymbols(left);
1629
+ const right_syms = Object.getOwnPropertySymbols(right);
1630
+ if (!compare_array(left_syms, right_syms))
1631
+ return false;
1632
+ for (let key of left_syms) {
1633
+ if (!$mol_compare_deep(left[key], right[key]))
1634
+ return false;
1635
+ }
1636
+ return true;
1637
+ }
1638
+ function compare_primitive(left, right) {
1639
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1640
+ }
1641
+ })($ || ($ = {}));
1642
+
1643
+ ;
1644
+ "use strict";
1645
+ var $;
1646
+ (function ($) {
1647
+ class $mol_wire_task extends $mol_wire_fiber {
1648
+ static getter(task) {
1649
+ return function $mol_wire_task_get(host, args) {
1650
+ const sub = $mol_wire_auto();
1651
+ const existen = sub?.track_next();
1652
+ reuse: if (existen) {
1653
+ if (!existen.temp)
1654
+ break reuse;
1655
+ if (existen.host !== host)
1656
+ break reuse;
1657
+ if (existen.task !== task)
1658
+ break reuse;
1659
+ if (!$mol_compare_deep(existen.args, args))
1660
+ break reuse;
1661
+ return existen;
1662
+ }
1663
+ const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1664
+ const next = new $mol_wire_task(key, task, host, args);
1665
+ if (existen?.temp) {
1666
+ $$.$mol_log3_warn({
1667
+ place: '$mol_wire_task',
1668
+ message: `Non idempotency`,
1669
+ existen,
1670
+ next,
1671
+ hint: 'Ignore it',
1672
+ });
1673
+ }
1674
+ return next;
1675
+ };
1676
+ }
1677
+ get temp() {
1678
+ return true;
1679
+ }
1680
+ complete() {
1681
+ if ($mol_promise_like(this.cache))
1682
+ return;
1683
+ this.destructor();
1684
+ }
1685
+ put(next) {
1686
+ const prev = this.cache;
1687
+ this.cache = next;
1688
+ if ($mol_promise_like(next)) {
1689
+ this.cursor = $mol_wire_cursor.fresh;
1690
+ if (next !== prev)
1691
+ this.emit();
1692
+ return next;
1693
+ }
1694
+ this.cursor = $mol_wire_cursor.final;
1695
+ if (this.sub_empty)
1696
+ this.destructor();
1697
+ else if (next !== prev)
1698
+ this.emit();
1699
+ return next;
1700
+ }
1701
+ }
1702
+ $.$mol_wire_task = $mol_wire_task;
1703
+ })($ || ($ = {}));
1704
+
1705
+ ;
1706
+ "use strict";
1707
+ var $;
1708
+ (function ($) {
1709
+ const factories = new WeakMap();
1710
+ function factory(val) {
1711
+ let make = factories.get(val);
1712
+ if (make)
1713
+ return make;
1714
+ make = $mol_func_name_from((...args) => new val(...args), val);
1715
+ factories.set(val, make);
1716
+ return make;
1717
+ }
1718
+ function $mol_wire_sync(obj) {
1719
+ return new Proxy(obj, {
1720
+ get(obj, field) {
1721
+ let val = obj[field];
1722
+ if (typeof val !== 'function')
1723
+ return val;
1724
+ const temp = $mol_wire_task.getter(val);
1725
+ return function $mol_wire_sync(...args) {
1726
+ const fiber = temp(obj, args);
1727
+ return fiber.sync();
1728
+ };
1729
+ },
1730
+ construct(obj, args) {
1731
+ const temp = $mol_wire_task.getter(factory(obj));
1732
+ return temp(obj, args).sync();
1733
+ },
1734
+ apply(obj, self, args) {
1735
+ const temp = $mol_wire_task.getter(obj);
1736
+ return temp(self, args).sync();
1737
+ },
1738
+ });
1739
+ }
1740
+ $.$mol_wire_sync = $mol_wire_sync;
1741
+ })($ || ($ = {}));
1742
+
1743
+ ;
1744
+ "use strict";
1745
+ var $;
1746
+ (function ($) {
1747
+ class $mol_run_error extends $mol_error_mix {
1748
+ }
1749
+ $.$mol_run_error = $mol_run_error;
1750
+ const child_process = $node['child_process'];
1751
+ $.$mol_run_spawn = child_process.spawn.bind(child_process);
1752
+ $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
1753
+ function $mol_run_async({ dir, timeout, command, env }) {
1754
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
1755
+ const [app, ...args] = args_raw;
1756
+ if (!env?.MOL_RUN_ASYNC) {
1757
+ this.$mol_log3_come({
1758
+ place: '$mol_run_sync',
1759
+ message: 'Run',
1760
+ command: args_raw.join(' '),
1761
+ dir: $node.path.relative('', dir),
1762
+ });
1763
+ const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
1764
+ if (res.status)
1765
+ $mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
1766
+ return res;
1767
+ }
1768
+ const sub = this.$mol_run_spawn(app, args, {
1769
+ shell: true,
1770
+ cwd: dir,
1771
+ env
1772
+ });
1773
+ this.$mol_log3_come({
1774
+ place: '$mol_run_async',
1775
+ pid: sub.pid,
1776
+ message: 'Run',
1777
+ command: args_raw.join(' '),
1778
+ dir: $node.path.relative('', dir),
1779
+ });
1780
+ let killed = false;
1781
+ let timer;
1782
+ const std_data = [];
1783
+ const error_data = [];
1784
+ const add = (std_chunk, error_chunk) => {
1785
+ if (std_chunk)
1786
+ std_data.push(std_chunk);
1787
+ if (error_chunk)
1788
+ error_data.push(error_chunk);
1789
+ if (!timeout)
1790
+ return;
1791
+ clearTimeout(timer);
1792
+ timer = setTimeout(() => {
1793
+ const signal = killed ? 'SIGKILL' : 'SIGTERM';
1794
+ killed = true;
1795
+ add();
1796
+ sub.kill(signal);
1797
+ }, timeout);
1798
+ };
1799
+ add();
1800
+ sub.stdout?.on('data', data => add(data));
1801
+ sub.stderr?.on('data', data => add(undefined, data));
1802
+ const promise = new Promise((done, fail) => {
1803
+ const close = (error, status = null, signal = null) => {
1804
+ if (!timer && timeout)
1805
+ return;
1806
+ clearTimeout(timer);
1807
+ timer = undefined;
1808
+ const res = {
1809
+ pid: sub.pid,
1810
+ status,
1811
+ signal,
1812
+ get stdout() { return Buffer.concat(std_data); },
1813
+ get stderr() { return Buffer.concat(error_data); }
1814
+ };
1815
+ this.$mol_log3_done({
1816
+ place: '$mol_run_async',
1817
+ pid: sub.pid,
1818
+ message: 'Run',
1819
+ status,
1820
+ command: args_raw.join(' '),
1821
+ dir: $node.path.relative('', dir),
1822
+ });
1823
+ if (error || status || killed)
1824
+ return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
1825
+ done(res);
1826
+ };
1827
+ sub.on('disconnect', () => close(new Error('Disconnected')));
1828
+ sub.on('error', err => close(err));
1829
+ sub.on('exit', (status, signal) => close(null, status, signal));
1830
+ });
1831
+ return Object.assign(promise, { destructor: () => {
1832
+ clearTimeout(timer);
1833
+ sub.kill('SIGKILL');
1834
+ } });
1835
+ }
1836
+ $.$mol_run_async = $mol_run_async;
1837
+ function $mol_run(options) {
1838
+ if (!options.env)
1839
+ options = { ...options, env: this.$mol_env() };
1840
+ return $mol_wire_sync(this).$mol_run_async(options);
1841
+ }
1842
+ $.$mol_run = $mol_run;
1843
+ })($ || ($ = {}));
1844
+
1845
+ ;
1846
+ "use strict";
1847
+ var $;
1848
+ (function ($) {
1849
+ function $mol_exec(dir, command, ...args) {
1850
+ return this.$mol_run({ command: [command, ...args], dir });
1851
+ }
1852
+ $.$mol_exec = $mol_exec;
1853
+ })($ || ($ = {}));
1854
+
1855
+ ;
1856
+ "use strict";
1857
+ var $;
1858
+ (function ($) {
1859
+ const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
1860
+ const encoder = new TextEncoder();
1861
+ function $mol_charset_encode(value) {
1862
+ return encoder.encode(value);
1863
+ }
1864
+ $.$mol_charset_encode = $mol_charset_encode;
1865
+ })($ || ($ = {}));
1866
+
1867
+ ;
1868
+ "use strict";
1869
+ var $;
1870
+ (function ($) {
1871
+ function $mol_int62_string_ensure(str) {
1872
+ if (typeof str !== 'string')
1873
+ return null;
1874
+ return $mol_int62_from_string(str) && str;
1875
+ }
1876
+ $.$mol_int62_string_ensure = $mol_int62_string_ensure;
1877
+ $.$mol_int62_max = (2 ** 30) - 1;
1878
+ $.$mol_int62_min = -(2 ** 30);
1879
+ $.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
1880
+ function $mol_int62_to_string({ lo, hi }) {
1881
+ lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
1882
+ hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
1883
+ return lo.toString(36) + '_' + hi.toString(36);
1884
+ }
1885
+ $.$mol_int62_to_string = $mol_int62_to_string;
1886
+ function $mol_int62_from_string(str) {
1887
+ const [str_lo, str_hi] = str.split('_');
1888
+ const int_lo = parseInt(str_lo, 36);
1889
+ const int_hi = parseInt(str_hi, 36);
1890
+ if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
1891
+ return null;
1892
+ }
1893
+ return {
1894
+ lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
1895
+ hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
1896
+ };
1897
+ }
1898
+ $.$mol_int62_from_string = $mol_int62_from_string;
1899
+ function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
1900
+ return (right_hi - left_hi) || (right_lo - left_lo);
1901
+ }
1902
+ $.$mol_int62_compare = $mol_int62_compare;
1903
+ function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
1904
+ if (lo === max) {
1905
+ return { lo: -max, hi: hi + 1 };
1906
+ }
1907
+ else {
1908
+ return { lo: lo + 1, hi };
1909
+ }
1910
+ }
1911
+ $.$mol_int62_inc = $mol_int62_inc;
1912
+ function $mol_int62_random() {
1913
+ return {
1914
+ lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
1915
+ hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
1916
+ };
1917
+ }
1918
+ $.$mol_int62_random = $mol_int62_random;
1919
+ function $mol_int62_hash_string(str) {
1920
+ return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
1921
+ }
1922
+ $.$mol_int62_hash_string = $mol_int62_hash_string;
1923
+ function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
1924
+ let h1 = 0xdeadbeef ^ seed.lo;
1925
+ let h2 = 0x41c6ce57 ^ seed.hi;
1926
+ for (const byte of buf) {
1927
+ h1 = Math.imul(h1 ^ byte, 2654435761);
1928
+ h2 = Math.imul(h2 ^ byte, 1597334677);
1929
+ }
1930
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
1931
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
1932
+ return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
1933
+ }
1934
+ $.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
1935
+ })($ || ($ = {}));
1936
+
1937
+ ;
1938
+ "use strict";
1939
+
1940
+ ;
1941
+ "use strict";
1942
+ var $;
1943
+ (function ($) {
1944
+ function $mol_data_setup(value, config) {
1945
+ return Object.assign(value, {
1946
+ config,
1947
+ Value: null
1948
+ });
1949
+ }
1950
+ $.$mol_data_setup = $mol_data_setup;
1951
+ })($ || ($ = {}));
1952
+
1953
+ ;
1954
+ "use strict";
1955
+ var $;
1956
+ (function ($) {
1957
+ class $mol_data_error extends $mol_error_mix {
1958
+ }
1959
+ $.$mol_data_error = $mol_data_error;
1960
+ })($ || ($ = {}));
1961
+
1962
+ ;
1963
+ "use strict";
1964
+ var $;
1965
+ (function ($) {
1966
+ function $mol_data_enum(name, dict) {
1967
+ const index = {};
1968
+ for (let key in dict) {
1969
+ if (Number.isNaN(Number(key))) {
1970
+ index[dict[key]] = key;
1971
+ }
1972
+ }
1973
+ return $mol_data_setup((value) => {
1974
+ if (typeof index[value] !== 'string') {
1975
+ return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
1976
+ }
1977
+ return value;
1978
+ }, { name, dict });
1979
+ }
1980
+ $.$mol_data_enum = $mol_data_enum;
1981
+ })($ || ($ = {}));
1982
+
1983
+ ;
1984
+ "use strict";
1985
+ var $;
1986
+ (function ($) {
1987
+ $.$mol_crypto_native = $node.crypto.webcrypto;
1988
+ })($ || ($ = {}));
1989
+
1990
+ ;
1991
+ "use strict";
1992
+ var $;
1993
+ (function ($) {
1994
+ function $mol_base64_encode(src) {
1995
+ throw new Error('Not implemented');
1996
+ }
1997
+ $.$mol_base64_encode = $mol_base64_encode;
1998
+ })($ || ($ = {}));
1999
+
2000
+ ;
2001
+ "use strict";
2002
+ var $;
2003
+ (function ($) {
2004
+ function $mol_base64_encode_node(str) {
2005
+ if (!str)
2006
+ return '';
2007
+ if (Buffer.isBuffer(str))
2008
+ return str.toString('base64');
2009
+ return Buffer.from(str).toString('base64');
2010
+ }
2011
+ $.$mol_base64_encode_node = $mol_base64_encode_node;
2012
+ $.$mol_base64_encode = $mol_base64_encode_node;
2013
+ })($ || ($ = {}));
2014
+
2015
+ ;
2016
+ "use strict";
2017
+ var $;
2018
+ (function ($) {
2019
+ function $mol_base64_decode(base64) {
2020
+ throw new Error('Not implemented');
2021
+ }
2022
+ $.$mol_base64_decode = $mol_base64_decode;
2023
+ })($ || ($ = {}));
2024
+
2025
+ ;
2026
+ "use strict";
2027
+ var $;
2028
+ (function ($) {
2029
+ function $mol_base64_decode_node(base64Str) {
2030
+ base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
2031
+ const buffer = Buffer.from(base64Str, 'base64');
2032
+ return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2033
+ }
2034
+ $.$mol_base64_decode_node = $mol_base64_decode_node;
2035
+ $.$mol_base64_decode = $mol_base64_decode_node;
2036
+ })($ || ($ = {}));
2037
+
2038
+ ;
2039
+ "use strict";
2040
+ var $;
2041
+ (function ($) {
2042
+ function $mol_base64_url_encode(buffer) {
2043
+ return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
2044
+ }
2045
+ $.$mol_base64_url_encode = $mol_base64_url_encode;
2046
+ function $mol_base64_url_decode(str) {
2047
+ return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
2048
+ }
2049
+ $.$mol_base64_url_decode = $mol_base64_url_decode;
2050
+ })($ || ($ = {}));
2051
+
2052
+ ;
2053
+ "use strict";
2054
+ var $;
2055
+ (function ($) {
2056
+ const algorithm = {
2057
+ name: 'ECDSA',
2058
+ hash: 'SHA-256',
2059
+ namedCurve: "P-256",
2060
+ };
2061
+ async function $mol_crypto_auditor_pair() {
2062
+ const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
2063
+ return {
2064
+ public: new $mol_crypto_auditor_public(pair.publicKey),
2065
+ private: new $mol_crypto_auditor_private(pair.privateKey),
2066
+ };
2067
+ }
2068
+ $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
2069
+ class $mol_crypto_auditor_public extends Object {
2070
+ native;
2071
+ static size_str = 86;
2072
+ static size_bin = 64;
2073
+ constructor(native) {
2074
+ super();
2075
+ this.native = native;
2076
+ }
2077
+ static async from(serial) {
2078
+ if (typeof serial !== 'string') {
2079
+ serial = $mol_base64_url_encode(serial.subarray(0, 32))
2080
+ + $mol_base64_url_encode(serial.subarray(32, 64));
2081
+ }
2082
+ return new this(await $mol_crypto_native.subtle.importKey('jwk', {
2083
+ crv: "P-256",
2084
+ ext: true,
2085
+ key_ops: ['verify'],
2086
+ kty: "EC",
2087
+ x: serial.slice(0, 43),
2088
+ y: serial.slice(43, 86),
2089
+ }, algorithm, true, ['verify']));
2090
+ }
2091
+ async serial() {
2092
+ const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
2093
+ return x + y;
2094
+ }
2095
+ async toArray() {
2096
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
2097
+ return new Uint8Array([
2098
+ ...$mol_base64_url_decode(x),
2099
+ ...$mol_base64_url_decode(y),
2100
+ ]);
2101
+ }
2102
+ async verify(data, sign) {
2103
+ return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
2104
+ }
2105
+ }
2106
+ $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
2107
+ class $mol_crypto_auditor_private extends Object {
2108
+ native;
2109
+ static size_str = 129;
2110
+ static size_bin = 96;
2111
+ constructor(native) {
2112
+ super();
2113
+ this.native = native;
2114
+ }
2115
+ static async from(serial) {
2116
+ if (typeof serial !== 'string') {
2117
+ serial = $mol_base64_url_encode(serial.subarray(0, 32))
2118
+ + $mol_base64_url_encode(serial.subarray(32, 64))
2119
+ + $mol_base64_url_encode(serial.subarray(64));
2120
+ }
2121
+ return new this(await $mol_crypto_native.subtle.importKey('jwk', {
2122
+ crv: "P-256",
2123
+ ext: true,
2124
+ key_ops: ['sign'],
2125
+ kty: "EC",
2126
+ x: serial.slice(0, 43),
2127
+ y: serial.slice(43, 86),
2128
+ d: serial.slice(86, 129),
2129
+ }, algorithm, true, ['sign']));
2130
+ }
2131
+ async serial() {
2132
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
2133
+ return x + y + d;
2134
+ }
2135
+ async toArray() {
2136
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
2137
+ return new Uint8Array([
2138
+ ...$mol_base64_url_decode(x),
2139
+ ...$mol_base64_url_decode(y),
2140
+ ...$mol_base64_url_decode(d),
2141
+ ]);
2142
+ }
2143
+ async sign(data) {
2144
+ return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
2145
+ }
2146
+ async public() {
2147
+ return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
2148
+ }
2149
+ }
2150
+ $.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
2151
+ $.$mol_crypto_auditor_sign_size = 64;
2152
+ function $mol_crypto_auditor_private_to_public(serial) {
2153
+ return serial.slice(0, 86);
2154
+ }
2155
+ $.$mol_crypto_auditor_private_to_public = $mol_crypto_auditor_private_to_public;
2156
+ })($ || ($ = {}));
2157
+
2158
+ ;
2159
+ "use strict";
2160
+ var $;
2161
+ (function ($) {
2162
+ let $hyoo_crowd_peer_level;
2163
+ (function ($hyoo_crowd_peer_level) {
2164
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["get"] = 0] = "get";
2165
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["add"] = 1] = "add";
2166
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["mod"] = 2] = "mod";
2167
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["law"] = 3] = "law";
2168
+ })($hyoo_crowd_peer_level = $.$hyoo_crowd_peer_level || ($.$hyoo_crowd_peer_level = {}));
2169
+ class $hyoo_crowd_peer extends Object {
2170
+ key_public;
2171
+ key_public_serial;
2172
+ key_private;
2173
+ key_private_serial;
2174
+ id;
2175
+ constructor(key_public, key_public_serial, key_private, key_private_serial) {
2176
+ super();
2177
+ this.key_public = key_public;
2178
+ this.key_public_serial = key_public_serial;
2179
+ this.key_private = key_private;
2180
+ this.key_private_serial = key_private_serial;
2181
+ this.id = $mol_int62_hash_string(this.key_public_serial);
2182
+ }
2183
+ static async generate() {
2184
+ const pair = await $$.$mol_crypto_auditor_pair();
2185
+ const serial = await pair.private.serial();
2186
+ return new this(pair.public, $mol_crypto_auditor_private_to_public(serial), pair.private, serial);
2187
+ }
2188
+ static async restore(serial) {
2189
+ return new this(await $$.$mol_crypto_auditor_public.from(serial), $mol_crypto_auditor_private_to_public(serial), await $$.$mol_crypto_auditor_private.from(serial), serial);
2190
+ }
2191
+ }
2192
+ $.$hyoo_crowd_peer = $hyoo_crowd_peer;
2193
+ })($ || ($ = {}));
2194
+
2195
+ ;
2196
+ "use strict";
2197
+
2198
+ ;
2199
+ "use strict";
2200
+ var $;
2201
+ (function ($) {
2202
+ const decoders = {};
2203
+ function $mol_charset_decode(buffer, encoding = 'utf8') {
2204
+ let decoder = decoders[encoding];
2205
+ if (!decoder)
2206
+ decoder = decoders[encoding] = new TextDecoder(encoding);
2207
+ return decoder.decode(buffer);
2208
+ }
2209
+ $.$mol_charset_decode = $mol_charset_decode;
2210
+ })($ || ($ = {}));
2211
+
2212
+ ;
2213
+ "use strict";
2214
+ var $;
2215
+ (function ($) {
2216
+ const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
2217
+ let $hyoo_crowd_unit_kind;
2218
+ (function ($hyoo_crowd_unit_kind) {
2219
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
2220
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
2221
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
2222
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
2223
+ })($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
2224
+ let $hyoo_crowd_unit_group;
2225
+ (function ($hyoo_crowd_unit_group) {
2226
+ $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
2227
+ $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
2228
+ })($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
2229
+ class $hyoo_crowd_unit extends Object {
2230
+ land;
2231
+ auth;
2232
+ head;
2233
+ self;
2234
+ next;
2235
+ prev;
2236
+ time;
2237
+ data;
2238
+ bin;
2239
+ constructor(land, auth, head, self, next, prev, time, data, bin) {
2240
+ super();
2241
+ this.land = land;
2242
+ this.auth = auth;
2243
+ this.head = head;
2244
+ this.self = self;
2245
+ this.next = next;
2246
+ this.prev = prev;
2247
+ this.time = time;
2248
+ this.data = data;
2249
+ this.bin = bin;
2250
+ }
2251
+ kind() {
2252
+ if (this.head === this.self && this.auth === this.self) {
2253
+ if (this.head === this.land) {
2254
+ return $hyoo_crowd_unit_kind.grab;
2255
+ }
2256
+ else {
2257
+ return $hyoo_crowd_unit_kind.join;
2258
+ }
2259
+ }
2260
+ if (this.head === this.land) {
2261
+ return $hyoo_crowd_unit_kind.give;
2262
+ }
2263
+ return $hyoo_crowd_unit_kind.data;
2264
+ }
2265
+ group() {
2266
+ return this.kind() === $hyoo_crowd_unit_kind.data
2267
+ ? $hyoo_crowd_unit_group.data
2268
+ : $hyoo_crowd_unit_group.auth;
2269
+ }
2270
+ level() {
2271
+ switch (this.kind()) {
2272
+ case $hyoo_crowd_unit_kind.grab: return $hyoo_crowd_peer_level.law;
2273
+ case $hyoo_crowd_unit_kind.give: return level(this.data);
2274
+ default: $mol_fail(new Error(`Wrong unit kind for getting level: ${this.kind()}`));
2275
+ }
2276
+ }
2277
+ [Symbol.toPrimitive]() {
2278
+ return JSON.stringify(this);
2279
+ }
2280
+ [$mol_dev_format_head]() {
2281
+ switch (this.kind()) {
2282
+ case $hyoo_crowd_unit_kind.grab:
2283
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), ' 👑');
2284
+ case $hyoo_crowd_unit_kind.join:
2285
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🔑 ', this.self));
2286
+ case $hyoo_crowd_unit_kind.give:
2287
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🏅 ', this.self, ' '), $mol_dev_format_native($hyoo_crowd_peer_level[this.data] ?? this.data));
2288
+ case $hyoo_crowd_unit_kind.data:
2289
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 📦 ', this.head, '!', this.self, ' '), $mol_dev_format_native(this.data));
2290
+ }
2291
+ }
2292
+ }
2293
+ $.$hyoo_crowd_unit = $hyoo_crowd_unit;
2294
+ const offset = {
2295
+ land_lo: 0,
2296
+ land_hi: 4,
2297
+ auth_lo: 8,
2298
+ auth_hi: 12,
2299
+ head_lo: 16,
2300
+ head_hi: 20,
2301
+ self_lo: 24,
2302
+ self_hi: 28,
2303
+ next_lo: 32,
2304
+ next_hi: 36,
2305
+ prev_lo: 40,
2306
+ prev_hi: 44,
2307
+ time: 48,
2308
+ size: 54,
2309
+ data: 56,
2310
+ };
2311
+ class $hyoo_crowd_unit_bin extends DataView {
2312
+ static from_buffer(buffer) {
2313
+ const size = Math.ceil(Math.abs(buffer[offset.size / 2]) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
2314
+ return new this(buffer.slice(0, size / 2).buffer);
2315
+ }
2316
+ static from_unit(unit) {
2317
+ if (unit.bin)
2318
+ return unit.bin;
2319
+ const type = unit.data === null
2320
+ ? 0
2321
+ : unit.data instanceof Uint8Array
2322
+ ? -1
2323
+ : 1;
2324
+ const buff = type === 0 ? null
2325
+ : type > 0 ? $mol_charset_encode(JSON.stringify(unit.data))
2326
+ : unit.data;
2327
+ const size = buff?.byteLength ?? 0;
2328
+ if (type > 0 && size > 2 ** 15 - 1)
2329
+ throw new Error(`Too large json data: ${size} > ${2 ** 15 - 1}`);
2330
+ if (type < 0 && size > 2 ** 15)
2331
+ throw new Error(`Too large binary data: ${size} > ${2 ** 15}`);
2332
+ const total = offset.data + Math.ceil(size / 8) * 8 + $mol_crypto_auditor_sign_size;
2333
+ const mem = new Uint8Array(total);
2334
+ const bin = new $hyoo_crowd_unit_bin(mem.buffer);
2335
+ const land = $mol_int62_from_string(unit.land);
2336
+ bin.setInt32(offset.land_lo, land.lo, true);
2337
+ bin.setInt32(offset.land_hi, land.hi, true);
2338
+ const auth = $mol_int62_from_string(unit.auth);
2339
+ bin.setInt32(offset.auth_lo, auth.lo, true);
2340
+ bin.setInt32(offset.auth_hi, auth.hi, true);
2341
+ const head = $mol_int62_from_string(unit.head);
2342
+ bin.setInt32(offset.head_lo, head.lo, true);
2343
+ bin.setInt32(offset.head_hi, head.hi, true);
2344
+ const self = $mol_int62_from_string(unit.self);
2345
+ bin.setInt32(offset.self_lo, self.lo, true);
2346
+ bin.setInt32(offset.self_hi, self.hi, true);
2347
+ const next = $mol_int62_from_string(unit.next);
2348
+ bin.setInt32(offset.next_lo, next.lo, true);
2349
+ bin.setInt32(offset.next_hi, next.hi, true);
2350
+ const prev = $mol_int62_from_string(unit.prev);
2351
+ bin.setInt32(offset.prev_lo, prev.lo, true);
2352
+ bin.setInt32(offset.prev_hi, prev.hi, true);
2353
+ bin.setInt32(offset.time, unit.time, true);
2354
+ bin.setInt16(offset.size, type * size, true);
2355
+ if (buff)
2356
+ mem.set(buff, offset.data);
2357
+ return bin;
2358
+ }
2359
+ sign(next) {
2360
+ const sign_offset = this.byteOffset + this.byteLength - $mol_crypto_auditor_sign_size;
2361
+ const buff = new Uint8Array(this.buffer, sign_offset, $mol_crypto_auditor_sign_size);
2362
+ if (!next)
2363
+ return buff;
2364
+ buff.set(next);
2365
+ return buff;
2366
+ }
2367
+ size() {
2368
+ return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
2369
+ }
2370
+ sens() {
2371
+ return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
2372
+ }
2373
+ unit() {
2374
+ const land = $mol_int62_to_string({
2375
+ lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
2376
+ hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
2377
+ });
2378
+ const auth = $mol_int62_to_string({
2379
+ lo: this.getInt32(offset.auth_lo, true) << 1 >> 1,
2380
+ hi: this.getInt32(offset.auth_hi, true) << 1 >> 1,
2381
+ });
2382
+ const head = $mol_int62_to_string({
2383
+ lo: this.getInt32(offset.head_lo, true) << 1 >> 1,
2384
+ hi: this.getInt32(offset.head_hi, true) << 1 >> 1,
2385
+ });
2386
+ const self = $mol_int62_to_string({
2387
+ lo: this.getInt32(offset.self_lo, true) << 1 >> 1,
2388
+ hi: this.getInt32(offset.self_hi, true) << 1 >> 1,
2389
+ });
2390
+ const next = $mol_int62_to_string({
2391
+ lo: this.getInt32(offset.next_lo, true) << 1 >> 1,
2392
+ hi: this.getInt32(offset.next_hi, true) << 1 >> 1,
2393
+ });
2394
+ const prev = $mol_int62_to_string({
2395
+ lo: this.getInt32(offset.prev_lo, true) << 1 >> 1,
2396
+ hi: this.getInt32(offset.prev_hi, true) << 1 >> 1,
2397
+ });
2398
+ const time = this.getInt32(offset.time, true) << 1 >> 1;
2399
+ const type_size = this.getInt16(offset.size, true);
2400
+ let data = null;
2401
+ if (type_size) {
2402
+ try {
2403
+ var buff = new Uint8Array(this.buffer, this.byteOffset + offset.data, Math.abs(type_size));
2404
+ }
2405
+ catch (error) {
2406
+ error['message'] += `\nhead=${head};self=${self}`;
2407
+ $mol_fail_hidden(error);
2408
+ }
2409
+ if (type_size < 0)
2410
+ data = buff;
2411
+ else
2412
+ data = JSON.parse($mol_charset_decode(buff));
2413
+ }
2414
+ return new $hyoo_crowd_unit(land, auth, head, self, next, prev, time, data, this);
2106
2415
  }
2107
2416
  }
2108
- $.$mol_wire_fiber = $mol_wire_fiber;
2417
+ $.$hyoo_crowd_unit_bin = $hyoo_crowd_unit_bin;
2418
+ function $hyoo_crowd_unit_compare(left, right) {
2419
+ return (left.group() - right.group())
2420
+ || (left.time - right.time)
2421
+ || ((left.auth > right.auth) ? 1 : (left.auth < right.auth) ? -1 : 0)
2422
+ || ((left.self > right.self) ? 1 : (left.self < right.self) ? -1 : 0)
2423
+ || ((left.head > right.head) ? 1 : (left.head < right.head) ? -1 : 0)
2424
+ || ((left.prev > right.prev) ? 1 : (left.prev < right.prev) ? -1 : 0)
2425
+ || ((left.next > right.next) ? 1 : (left.next < right.next) ? -1 : 0)
2426
+ || ((left.land > right.land) ? 1 : (left.land < right.land) ? -1 : 0);
2427
+ }
2428
+ $.$hyoo_crowd_unit_compare = $hyoo_crowd_unit_compare;
2109
2429
  })($ || ($ = {}));
2110
2430
 
2111
2431
  ;
@@ -2205,208 +2525,6 @@ var $;
2205
2525
  $.$mol_after_frame = $mol_after_frame;
2206
2526
  })($ || ($ = {}));
2207
2527
 
2208
- ;
2209
- "use strict";
2210
- var $;
2211
- (function ($) {
2212
- $.$mol_compare_deep_cache = new WeakMap();
2213
- function $mol_compare_deep(left, right) {
2214
- if (Object.is(left, right))
2215
- return true;
2216
- if (left === null)
2217
- return false;
2218
- if (right === null)
2219
- return false;
2220
- if (typeof left !== 'object')
2221
- return false;
2222
- if (typeof right !== 'object')
2223
- return false;
2224
- const left_proto = Reflect.getPrototypeOf(left);
2225
- const right_proto = Reflect.getPrototypeOf(right);
2226
- if (left_proto !== right_proto)
2227
- return false;
2228
- if (left instanceof Boolean)
2229
- return Object.is(left.valueOf(), right['valueOf']());
2230
- if (left instanceof Number)
2231
- return Object.is(left.valueOf(), right['valueOf']());
2232
- if (left instanceof String)
2233
- return Object.is(left.valueOf(), right['valueOf']());
2234
- if (left instanceof Date)
2235
- return Object.is(left.valueOf(), right['valueOf']());
2236
- if (left instanceof RegExp)
2237
- return left.source === right.source && left.flags === right.flags;
2238
- if (left instanceof Error)
2239
- return left.message === right.message && left.stack === right.stack;
2240
- let left_cache = $.$mol_compare_deep_cache.get(left);
2241
- if (left_cache) {
2242
- const right_cache = left_cache.get(right);
2243
- if (typeof right_cache === 'boolean')
2244
- return right_cache;
2245
- }
2246
- else {
2247
- left_cache = new WeakMap();
2248
- $.$mol_compare_deep_cache.set(left, left_cache);
2249
- }
2250
- left_cache.set(right, true);
2251
- let result;
2252
- try {
2253
- if (!left_proto)
2254
- result = compare_pojo(left, right);
2255
- else if (!Reflect.getPrototypeOf(left_proto))
2256
- result = compare_pojo(left, right);
2257
- else if (Symbol.toPrimitive in left)
2258
- result = compare_primitive(left, right);
2259
- else if (Array.isArray(left))
2260
- result = compare_array(left, right);
2261
- else if (left instanceof Set)
2262
- result = compare_set(left, right);
2263
- else if (left instanceof Map)
2264
- result = compare_map(left, right);
2265
- else if (ArrayBuffer.isView(left))
2266
- result = compare_buffer(left, right);
2267
- else if (Symbol.iterator in left)
2268
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
2269
- else
2270
- result = false;
2271
- }
2272
- finally {
2273
- left_cache.set(right, result);
2274
- }
2275
- return result;
2276
- }
2277
- $.$mol_compare_deep = $mol_compare_deep;
2278
- function compare_array(left, right) {
2279
- const len = left.length;
2280
- if (len !== right.length)
2281
- return false;
2282
- for (let i = 0; i < len; ++i) {
2283
- if (!$mol_compare_deep(left[i], right[i]))
2284
- return false;
2285
- }
2286
- return true;
2287
- }
2288
- function compare_buffer(left, right) {
2289
- const len = left.byteLength;
2290
- if (len !== right.byteLength)
2291
- return false;
2292
- if (left instanceof DataView)
2293
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
2294
- for (let i = 0; i < len; ++i) {
2295
- if (left[i] !== right[i])
2296
- return false;
2297
- }
2298
- return true;
2299
- }
2300
- function compare_iterator(left, right) {
2301
- while (true) {
2302
- const left_next = left.next();
2303
- const right_next = right.next();
2304
- if (left_next.done !== right_next.done)
2305
- return false;
2306
- if (left_next.done)
2307
- break;
2308
- if (!$mol_compare_deep(left_next.value, right_next.value))
2309
- return false;
2310
- }
2311
- return true;
2312
- }
2313
- function compare_set(left, right) {
2314
- if (left.size !== right.size)
2315
- return false;
2316
- return compare_iterator(left.values(), right.values());
2317
- }
2318
- function compare_map(left, right) {
2319
- if (left.size !== right.size)
2320
- return false;
2321
- return compare_iterator(left.keys(), right.keys())
2322
- && compare_iterator(left.values(), right.values());
2323
- }
2324
- function compare_pojo(left, right) {
2325
- const left_keys = Object.getOwnPropertyNames(left);
2326
- const right_keys = Object.getOwnPropertyNames(right);
2327
- if (!compare_array(left_keys, right_keys))
2328
- return false;
2329
- for (let key of left_keys) {
2330
- if (!$mol_compare_deep(left[key], right[key]))
2331
- return false;
2332
- }
2333
- const left_syms = Object.getOwnPropertySymbols(left);
2334
- const right_syms = Object.getOwnPropertySymbols(right);
2335
- if (!compare_array(left_syms, right_syms))
2336
- return false;
2337
- for (let key of left_syms) {
2338
- if (!$mol_compare_deep(left[key], right[key]))
2339
- return false;
2340
- }
2341
- return true;
2342
- }
2343
- function compare_primitive(left, right) {
2344
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
2345
- }
2346
- })($ || ($ = {}));
2347
-
2348
- ;
2349
- "use strict";
2350
- var $;
2351
- (function ($) {
2352
- class $mol_wire_task extends $mol_wire_fiber {
2353
- static getter(task) {
2354
- return function $mol_wire_task_get(host, args) {
2355
- const sub = $mol_wire_auto();
2356
- const existen = sub?.track_next();
2357
- reuse: if (existen) {
2358
- if (!existen.temp)
2359
- break reuse;
2360
- if (existen.host !== host)
2361
- break reuse;
2362
- if (existen.task !== task)
2363
- break reuse;
2364
- if (!$mol_compare_deep(existen.args, args))
2365
- break reuse;
2366
- return existen;
2367
- }
2368
- const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
2369
- const next = new $mol_wire_task(key, task, host, args);
2370
- if (existen?.temp) {
2371
- $$.$mol_log3_warn({
2372
- place: '$mol_wire_task',
2373
- message: `Non idempotency`,
2374
- existen,
2375
- next,
2376
- hint: 'Ignore it',
2377
- });
2378
- }
2379
- return next;
2380
- };
2381
- }
2382
- get temp() {
2383
- return true;
2384
- }
2385
- complete() {
2386
- if ($mol_promise_like(this.cache))
2387
- return;
2388
- this.destructor();
2389
- }
2390
- put(next) {
2391
- const prev = this.cache;
2392
- this.cache = next;
2393
- if ($mol_promise_like(next)) {
2394
- this.cursor = $mol_wire_cursor.fresh;
2395
- if (next !== prev)
2396
- this.emit();
2397
- return next;
2398
- }
2399
- this.cursor = $mol_wire_cursor.final;
2400
- if (this.sub_empty)
2401
- this.destructor();
2402
- else if (next !== prev)
2403
- this.emit();
2404
- return next;
2405
- }
2406
- }
2407
- $.$mol_wire_task = $mol_wire_task;
2408
- })($ || ($ = {}));
2409
-
2410
2528
  ;
2411
2529
  "use strict";
2412
2530
  var $;
@@ -2653,32 +2771,6 @@ var $;
2653
2771
  $.$mol_mem_key = $mol_wire_plex;
2654
2772
  })($ || ($ = {}));
2655
2773
 
2656
- ;
2657
- "use strict";
2658
- var $;
2659
- (function ($) {
2660
- function $mol_wire_sync(obj) {
2661
- return new Proxy(obj, {
2662
- get(obj, field) {
2663
- const val = obj[field];
2664
- if (typeof val !== 'function')
2665
- return val;
2666
- const temp = $mol_wire_task.getter(val);
2667
- return function $mol_wire_sync(...args) {
2668
- const fiber = temp(obj, args);
2669
- return fiber.sync();
2670
- };
2671
- },
2672
- apply(obj, self, args) {
2673
- const temp = $mol_wire_task.getter(obj);
2674
- const fiber = temp(self, args);
2675
- return fiber.sync();
2676
- },
2677
- });
2678
- }
2679
- $.$mol_wire_sync = $mol_wire_sync;
2680
- })($ || ($ = {}));
2681
-
2682
2774
  ;
2683
2775
  "use strict";
2684
2776
  var $;