hyoo_sync_client 0.0.506 → 0.0.508

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