mol_crypto_lib 0.1.1288 → 0.1.1289

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
@@ -144,6 +144,68 @@ require = (req => Object.assign(function require(name) {
144
144
  return $node[name];
145
145
  }, req))(require);
146
146
 
147
+ ;
148
+ "use strict";
149
+ var $;
150
+ (function ($) {
151
+ const named = new WeakSet();
152
+ function $mol_func_name(func) {
153
+ let name = func.name;
154
+ if (name?.length > 1)
155
+ return name;
156
+ if (named.has(func))
157
+ return name;
158
+ for (let key in this) {
159
+ try {
160
+ if (this[key] !== func)
161
+ continue;
162
+ name = key;
163
+ Object.defineProperty(func, 'name', { value: name });
164
+ break;
165
+ }
166
+ catch { }
167
+ }
168
+ named.add(func);
169
+ return name;
170
+ }
171
+ $.$mol_func_name = $mol_func_name;
172
+ function $mol_func_name_from(target, source) {
173
+ Object.defineProperty(target, 'name', { value: source.name });
174
+ return target;
175
+ }
176
+ $.$mol_func_name_from = $mol_func_name_from;
177
+ })($ || ($ = {}));
178
+
179
+ ;
180
+ "use strict";
181
+ var $;
182
+ (function ($) {
183
+ class $mol_error_mix extends AggregateError {
184
+ cause;
185
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
186
+ constructor(message, cause = {}, ...errors) {
187
+ super(errors, message, { cause });
188
+ this.cause = cause;
189
+ const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
190
+ Object.defineProperty(this, 'stack', {
191
+ 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()
192
+ .replace(/at /gm, ' at ')
193
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
194
+ });
195
+ }
196
+ static [Symbol.toPrimitive]() {
197
+ return this.toString();
198
+ }
199
+ static toString() {
200
+ return $$.$mol_func_name(this);
201
+ }
202
+ static make(...params) {
203
+ return new this(...params);
204
+ }
205
+ }
206
+ $.$mol_error_mix = $mol_error_mix;
207
+ })($ || ($ = {}));
208
+
147
209
  ;
148
210
  "use strict";
149
211
  var $;
@@ -275,38 +337,6 @@ var $;
275
337
  ;
276
338
  "use strict";
277
339
 
278
- ;
279
- "use strict";
280
- var $;
281
- (function ($) {
282
- const named = new WeakSet();
283
- function $mol_func_name(func) {
284
- let name = func.name;
285
- if (name?.length > 1)
286
- return name;
287
- if (named.has(func))
288
- return name;
289
- for (let key in this) {
290
- try {
291
- if (this[key] !== func)
292
- continue;
293
- name = key;
294
- Object.defineProperty(func, 'name', { value: name });
295
- break;
296
- }
297
- catch { }
298
- }
299
- named.add(func);
300
- return name;
301
- }
302
- $.$mol_func_name = $mol_func_name;
303
- function $mol_func_name_from(target, source) {
304
- Object.defineProperty(target, 'name', { value: source.name });
305
- return target;
306
- }
307
- $.$mol_func_name_from = $mol_func_name_from;
308
- })($ || ($ = {}));
309
-
310
340
  ;
311
341
  "use strict";
312
342
  var $;
@@ -866,215 +896,1110 @@ var $;
866
896
  "use strict";
867
897
  var $;
868
898
  (function ($) {
869
- function $mol_exec(dir, command, ...args) {
870
- let [app, ...args0] = command.split(' ');
871
- args = [...args0, ...args];
872
- this.$mol_log3_come({
873
- place: '$mol_exec',
874
- dir: $node.path.relative('', dir),
875
- message: 'Run',
876
- command: `${app} ${args.join(' ')}`,
877
- });
878
- var res = $node['child_process'].spawnSync(app, args, {
879
- cwd: $node.path.resolve(dir),
880
- shell: true,
881
- env: this.$mol_env(),
882
- });
883
- if (res.status || res.error) {
884
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
885
- }
886
- if (!res.stdout)
887
- res.stdout = Buffer.from([]);
888
- return res;
889
- }
890
- $.$mol_exec = $mol_exec;
891
- })($ || ($ = {}));
892
-
893
- ;
894
- "use strict";
895
- var $;
896
- (function ($) {
897
- $.$mol_crypto_native = $node.crypto.webcrypto;
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;
899
+ let $mol_wire_cursor;
900
+ (function ($mol_wire_cursor) {
901
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
902
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
903
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
904
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
905
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
910
906
  })($ || ($ = {}));
911
907
 
912
908
  ;
913
909
  "use strict";
914
910
  var $;
915
911
  (function ($) {
916
- const algorithm = {
917
- name: 'AES-CBC',
918
- length: 128,
919
- tagLength: 32,
920
- };
921
- class $mol_crypto_secret extends Object {
922
- native;
923
- static size = 16;
924
- constructor(native) {
925
- super();
926
- this.native = native;
927
- }
928
- static async generate() {
929
- return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
912
+ class $mol_wire_pub extends Object {
913
+ data = [];
914
+ static get [Symbol.species]() {
915
+ return Array;
916
+ }
917
+ sub_from = 0;
918
+ get sub_list() {
919
+ const res = [];
920
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
921
+ res.push(this.data[i]);
922
+ }
923
+ return res;
930
924
  }
931
- static async from(serial) {
932
- return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
925
+ get sub_empty() {
926
+ return this.sub_from === this.data.length;
933
927
  }
934
- static async pass(pass, salt) {
935
- return new this(await $mol_crypto_native.subtle.deriveKey({
936
- name: "PBKDF2",
937
- salt,
938
- iterations: 10_000,
939
- hash: "SHA-256",
940
- }, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
928
+ sub_on(sub, pub_pos) {
929
+ const pos = this.data.length;
930
+ this.data.push(sub, pub_pos);
931
+ return pos;
941
932
  }
942
- static async derive(private_serial, public_serial) {
943
- const ecdh = { name: "ECDH", namedCurve: "P-256" };
944
- const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
945
- const private_key = await $mol_crypto_native.subtle.importKey('jwk', {
946
- ...jwk,
947
- key_ops: ['deriveKey'],
948
- x: private_serial.slice(0, 43),
949
- y: private_serial.slice(43, 86),
950
- d: private_serial.slice(86, 129),
951
- }, ecdh, true, ['deriveKey']);
952
- const public_key = await $mol_crypto_native.subtle.importKey('jwk', {
953
- ...jwk,
954
- key_ops: [],
955
- x: public_serial.slice(0, 43),
956
- y: public_serial.slice(43, 86),
957
- }, ecdh, true, []);
958
- const secret = await $mol_crypto_native.subtle.deriveKey({
959
- name: "ECDH",
960
- public: public_key,
961
- }, private_key, algorithm, true, ["encrypt", "decrypt"]);
962
- return new this(secret);
933
+ sub_off(sub_pos) {
934
+ if (!(sub_pos < this.data.length)) {
935
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
936
+ }
937
+ const end = this.data.length - 2;
938
+ if (sub_pos !== end) {
939
+ this.peer_move(end, sub_pos);
940
+ }
941
+ this.data.pop();
942
+ this.data.pop();
943
+ if (this.data.length === this.sub_from)
944
+ this.reap();
945
+ }
946
+ reap() { }
947
+ promote() {
948
+ $mol_wire_auto()?.track_next(this);
949
+ }
950
+ fresh() { }
951
+ complete() { }
952
+ get incompleted() {
953
+ return false;
963
954
  }
964
- async serial() {
965
- return new Uint8Array(await $mol_crypto_native.subtle.exportKey('raw', this.native));
955
+ emit(quant = $mol_wire_cursor.stale) {
956
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
957
+ ;
958
+ this.data[i].absorb(quant);
959
+ }
966
960
  }
967
- async encrypt(open, salt) {
968
- return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
969
- ...algorithm,
970
- iv: salt,
971
- }, this.native, open));
961
+ peer_move(from_pos, to_pos) {
962
+ const peer = this.data[from_pos];
963
+ const self_pos = this.data[from_pos + 1];
964
+ this.data[to_pos] = peer;
965
+ this.data[to_pos + 1] = self_pos;
966
+ peer.peer_repos(self_pos, to_pos);
972
967
  }
973
- async decrypt(closed, salt) {
974
- return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
975
- ...algorithm,
976
- iv: salt,
977
- }, this.native, closed));
968
+ peer_repos(peer_pos, self_pos) {
969
+ this.data[peer_pos + 1] = self_pos;
978
970
  }
979
971
  }
980
- $.$mol_crypto_secret = $mol_crypto_secret;
972
+ $.$mol_wire_pub = $mol_wire_pub;
981
973
  })($ || ($ = {}));
982
974
 
983
975
  ;
984
976
  "use strict";
985
- var $;
986
- (function ($) {
987
- })($ || ($ = {}));
988
977
 
989
978
  ;
990
979
  "use strict";
991
980
  var $;
992
981
  (function ($) {
993
- $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
982
+ $.$mol_wire_auto_sub = null;
983
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
984
+ return $.$mol_wire_auto_sub = next;
985
+ }
986
+ $.$mol_wire_auto = $mol_wire_auto;
987
+ $.$mol_wire_affected = [];
994
988
  })($ || ($ = {}));
995
989
 
996
990
  ;
997
991
  "use strict";
998
992
  var $;
999
993
  (function ($) {
1000
- async function $mol_crypto_secret_id() {
1001
- const signed = this.$mol_dom_context.localStorage.getItem('$mol_crypto_secret');
1002
- if (signed === '')
1003
- return await this.$mol_crypto_secret_id_get();
1004
- const id = await this.$mol_crypto_secret_id_new();
1005
- this.$mol_dom_context.localStorage.setItem('$mol_crypto_secret', '');
1006
- return id;
994
+ $['devtoolsFormatters'] ||= [];
995
+ function $mol_dev_format_register(config) {
996
+ $['devtoolsFormatters'].push(config);
1007
997
  }
1008
- $.$mol_crypto_secret_id = $mol_crypto_secret_id;
1009
- async function $mol_crypto_secret_id_new() {
1010
- const cred = await this.$mol_dom_context.navigator.credentials.create({
1011
- publicKey: {
1012
- rp: {
1013
- name: "$mol_crypto_id",
1014
- },
1015
- user: {
1016
- id: new Uint8Array([0]),
1017
- name: "",
1018
- displayName: ""
1019
- },
1020
- pubKeyCredParams: [
1021
- { type: "public-key", alg: -7 },
1022
- { type: "public-key", alg: -257 },
1023
- ],
1024
- challenge: new Uint8Array().buffer,
998
+ $.$mol_dev_format_register = $mol_dev_format_register;
999
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
1000
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
1001
+ $mol_dev_format_register({
1002
+ header: (val, config = false) => {
1003
+ if (config)
1004
+ return null;
1005
+ if (!val)
1006
+ return null;
1007
+ if ($.$mol_dev_format_head in val) {
1008
+ try {
1009
+ return val[$.$mol_dev_format_head]();
1010
+ }
1011
+ catch (error) {
1012
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1013
+ }
1014
+ }
1015
+ if (typeof val === 'function') {
1016
+ return $mol_dev_format_native(val);
1017
+ }
1018
+ if (Symbol.toStringTag in val) {
1019
+ return $mol_dev_format_native(val);
1020
+ }
1021
+ return null;
1022
+ },
1023
+ hasBody: val => val[$.$mol_dev_format_body],
1024
+ body: val => val[$.$mol_dev_format_body](),
1025
+ });
1026
+ function $mol_dev_format_native(obj) {
1027
+ if (typeof obj === 'undefined')
1028
+ return $.$mol_dev_format_shade('undefined');
1029
+ return [
1030
+ 'object',
1031
+ {
1032
+ object: obj,
1033
+ config: true,
1025
1034
  },
1026
- });
1027
- return $mol_crypto_secret.from(cred.rawId);
1035
+ ];
1028
1036
  }
1029
- $.$mol_crypto_secret_id_new = $mol_crypto_secret_id_new;
1030
- async function $mol_crypto_secret_id_get() {
1031
- const cred = await this.$mol_dom_context.navigator.credentials.get({
1032
- mediation: 'silent',
1033
- publicKey: {
1034
- userVerification: 'discouraged',
1035
- challenge: new Uint8Array().buffer,
1037
+ $.$mol_dev_format_native = $mol_dev_format_native;
1038
+ function $mol_dev_format_auto(obj) {
1039
+ if (obj == null)
1040
+ return $.$mol_dev_format_shade(String(obj));
1041
+ return [
1042
+ 'object',
1043
+ {
1044
+ object: obj,
1045
+ config: false,
1036
1046
  },
1037
- });
1038
- return $mol_crypto_secret.from(cred.rawId);
1047
+ ];
1039
1048
  }
1040
- $.$mol_crypto_secret_id_get = $mol_crypto_secret_id_get;
1041
- })($ || ($ = {}));
1042
-
1043
- ;
1044
- "use strict";
1045
- var $;
1046
- (function ($) {
1047
- function $mol_base64_encode(src) {
1048
- throw new Error('Not implemented');
1049
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
1050
+ function $mol_dev_format_element(element, style, ...content) {
1051
+ const styles = [];
1052
+ for (let key in style)
1053
+ styles.push(`${key} : ${style[key]}`);
1054
+ return [
1055
+ element,
1056
+ {
1057
+ style: styles.join(' ; '),
1058
+ },
1059
+ ...content,
1060
+ ];
1049
1061
  }
1050
- $.$mol_base64_encode = $mol_base64_encode;
1051
- })($ || ($ = {}));
1052
-
1053
- ;
1054
- "use strict";
1055
- var $;
1056
- (function ($) {
1057
- function $mol_base64_encode_node(str) {
1058
- if (!str)
1059
- return '';
1060
- if (Buffer.isBuffer(str))
1061
- return str.toString('base64');
1062
- return Buffer.from(str).toString('base64');
1062
+ $.$mol_dev_format_element = $mol_dev_format_element;
1063
+ function $mol_dev_format_span(style, ...content) {
1064
+ return $mol_dev_format_element('span', {
1065
+ ...style,
1066
+ }, ...content);
1063
1067
  }
1064
- $.$mol_base64_encode_node = $mol_base64_encode_node;
1065
- $.$mol_base64_encode = $mol_base64_encode_node;
1068
+ $.$mol_dev_format_span = $mol_dev_format_span;
1069
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
1070
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
1071
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
1072
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
1073
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
1074
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
1075
+ $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
1076
+ 'color': 'magenta',
1077
+ });
1078
+ $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
1079
+ 'font-weight': 'bold',
1080
+ });
1081
+ $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
1082
+ 'color': 'green',
1083
+ });
1084
+ $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
1085
+ 'color': 'gray',
1086
+ });
1087
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
1088
+ 'margin-left': '13px'
1089
+ });
1066
1090
  })($ || ($ = {}));
1067
1091
 
1068
1092
  ;
1069
1093
  "use strict";
1070
1094
  var $;
1071
1095
  (function ($) {
1072
- function $mol_base64_decode(base64) {
1073
- throw new Error('Not implemented');
1074
- }
1075
- $.$mol_base64_decode = $mol_base64_decode;
1076
- })($ || ($ = {}));
1077
-
1096
+ class $mol_wire_pub_sub extends $mol_wire_pub {
1097
+ pub_from = 0;
1098
+ cursor = $mol_wire_cursor.stale;
1099
+ get temp() {
1100
+ return false;
1101
+ }
1102
+ get pub_list() {
1103
+ const res = [];
1104
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
1105
+ for (let i = this.pub_from; i < max; i += 2) {
1106
+ if (this.data[i])
1107
+ res.push(this.data[i]);
1108
+ }
1109
+ return res;
1110
+ }
1111
+ track_on() {
1112
+ this.cursor = this.pub_from;
1113
+ const sub = $mol_wire_auto();
1114
+ $mol_wire_auto(this);
1115
+ return sub;
1116
+ }
1117
+ promote() {
1118
+ if (this.cursor >= this.pub_from) {
1119
+ $mol_fail(new Error('Circular subscription'));
1120
+ }
1121
+ super.promote();
1122
+ }
1123
+ track_next(pub) {
1124
+ if (this.cursor < 0)
1125
+ $mol_fail(new Error('Promo to non begun sub'));
1126
+ if (this.cursor < this.sub_from) {
1127
+ const next = this.data[this.cursor];
1128
+ if (pub === undefined)
1129
+ return next ?? null;
1130
+ if (next === pub) {
1131
+ this.cursor += 2;
1132
+ return next;
1133
+ }
1134
+ if (next) {
1135
+ if (this.sub_from < this.data.length) {
1136
+ this.peer_move(this.sub_from, this.data.length);
1137
+ }
1138
+ this.peer_move(this.cursor, this.sub_from);
1139
+ this.sub_from += 2;
1140
+ }
1141
+ }
1142
+ else {
1143
+ if (pub === undefined)
1144
+ return null;
1145
+ if (this.sub_from < this.data.length) {
1146
+ this.peer_move(this.sub_from, this.data.length);
1147
+ }
1148
+ this.sub_from += 2;
1149
+ }
1150
+ this.data[this.cursor] = pub;
1151
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1152
+ this.cursor += 2;
1153
+ return pub;
1154
+ }
1155
+ track_off(sub) {
1156
+ $mol_wire_auto(sub);
1157
+ if (this.cursor < 0) {
1158
+ $mol_fail(new Error('End of non begun sub'));
1159
+ }
1160
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1161
+ const pub = this.data[cursor];
1162
+ pub.fresh();
1163
+ }
1164
+ this.cursor = $mol_wire_cursor.fresh;
1165
+ }
1166
+ pub_off(sub_pos) {
1167
+ this.data[sub_pos] = undefined;
1168
+ this.data[sub_pos + 1] = undefined;
1169
+ }
1170
+ destructor() {
1171
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1172
+ const sub = this.data[cursor];
1173
+ const pos = this.data[cursor + 1];
1174
+ sub.pub_off(pos);
1175
+ this.data.pop();
1176
+ this.data.pop();
1177
+ }
1178
+ this.cursor = this.pub_from;
1179
+ this.track_cut();
1180
+ this.cursor = $mol_wire_cursor.final;
1181
+ }
1182
+ track_cut() {
1183
+ if (this.cursor < this.pub_from) {
1184
+ $mol_fail(new Error('Cut of non begun sub'));
1185
+ }
1186
+ let tail = 0;
1187
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1188
+ const pub = this.data[cursor];
1189
+ pub?.sub_off(this.data[cursor + 1]);
1190
+ if (this.sub_from < this.data.length) {
1191
+ this.peer_move(this.data.length - 2, cursor);
1192
+ this.data.pop();
1193
+ this.data.pop();
1194
+ }
1195
+ else {
1196
+ ++tail;
1197
+ }
1198
+ }
1199
+ for (; tail; --tail) {
1200
+ this.data.pop();
1201
+ this.data.pop();
1202
+ }
1203
+ this.sub_from = this.cursor;
1204
+ }
1205
+ complete() { }
1206
+ complete_pubs() {
1207
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1208
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1209
+ const pub = this.data[cursor];
1210
+ if (pub?.incompleted)
1211
+ return;
1212
+ }
1213
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1214
+ const pub = this.data[cursor];
1215
+ pub?.complete();
1216
+ }
1217
+ }
1218
+ absorb(quant = $mol_wire_cursor.stale) {
1219
+ if (this.cursor === $mol_wire_cursor.final)
1220
+ return;
1221
+ if (this.cursor >= quant)
1222
+ return;
1223
+ this.cursor = quant;
1224
+ this.emit($mol_wire_cursor.doubt);
1225
+ }
1226
+ [$mol_dev_format_head]() {
1227
+ return $mol_dev_format_native(this);
1228
+ }
1229
+ get pub_empty() {
1230
+ return this.sub_from === this.pub_from;
1231
+ }
1232
+ }
1233
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1234
+ })($ || ($ = {}));
1235
+
1236
+ ;
1237
+ "use strict";
1238
+ var $;
1239
+ (function ($) {
1240
+ class $mol_after_tick extends $mol_object2 {
1241
+ task;
1242
+ static promise = null;
1243
+ cancelled = false;
1244
+ constructor(task) {
1245
+ super();
1246
+ this.task = task;
1247
+ if (!$mol_after_tick.promise)
1248
+ $mol_after_tick.promise = Promise.resolve().then(() => {
1249
+ $mol_after_tick.promise = null;
1250
+ });
1251
+ $mol_after_tick.promise.then(() => {
1252
+ if (this.cancelled)
1253
+ return;
1254
+ task();
1255
+ });
1256
+ }
1257
+ destructor() {
1258
+ this.cancelled = true;
1259
+ }
1260
+ }
1261
+ $.$mol_after_tick = $mol_after_tick;
1262
+ })($ || ($ = {}));
1263
+
1264
+ ;
1265
+ "use strict";
1266
+ var $;
1267
+ (function ($) {
1268
+ const handled = new WeakSet();
1269
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1270
+ task;
1271
+ host;
1272
+ static warm = true;
1273
+ static planning = new Set();
1274
+ static reaping = new Set();
1275
+ static plan_task = null;
1276
+ static plan() {
1277
+ if (this.plan_task)
1278
+ return;
1279
+ this.plan_task = new $mol_after_tick(() => {
1280
+ try {
1281
+ this.sync();
1282
+ }
1283
+ finally {
1284
+ $mol_wire_fiber.plan_task = null;
1285
+ }
1286
+ });
1287
+ }
1288
+ static sync() {
1289
+ while (this.planning.size) {
1290
+ for (const fiber of this.planning) {
1291
+ this.planning.delete(fiber);
1292
+ if (fiber.cursor >= 0)
1293
+ continue;
1294
+ if (fiber.cursor === $mol_wire_cursor.final)
1295
+ continue;
1296
+ fiber.fresh();
1297
+ }
1298
+ }
1299
+ while (this.reaping.size) {
1300
+ const fibers = this.reaping;
1301
+ this.reaping = new Set;
1302
+ for (const fiber of fibers) {
1303
+ if (!fiber.sub_empty)
1304
+ continue;
1305
+ fiber.destructor();
1306
+ }
1307
+ }
1308
+ }
1309
+ [Symbol.toStringTag];
1310
+ cache = undefined;
1311
+ get args() {
1312
+ return this.data.slice(0, this.pub_from);
1313
+ }
1314
+ result() {
1315
+ if ($mol_promise_like(this.cache))
1316
+ return;
1317
+ if (this.cache instanceof Error)
1318
+ return;
1319
+ return this.cache;
1320
+ }
1321
+ get incompleted() {
1322
+ return $mol_promise_like(this.cache);
1323
+ }
1324
+ field() {
1325
+ return this.task.name + '<>';
1326
+ }
1327
+ constructor(id, task, host, args) {
1328
+ super();
1329
+ this.task = task;
1330
+ this.host = host;
1331
+ if (args)
1332
+ this.data.push(...args);
1333
+ this.pub_from = this.sub_from = args?.length ?? 0;
1334
+ this[Symbol.toStringTag] = id;
1335
+ }
1336
+ plan() {
1337
+ $mol_wire_fiber.planning.add(this);
1338
+ $mol_wire_fiber.plan();
1339
+ return this;
1340
+ }
1341
+ reap() {
1342
+ $mol_wire_fiber.reaping.add(this);
1343
+ $mol_wire_fiber.plan();
1344
+ }
1345
+ toString() {
1346
+ return this[Symbol.toStringTag];
1347
+ }
1348
+ toJSON() {
1349
+ return this[Symbol.toStringTag];
1350
+ }
1351
+ [$mol_dev_format_head]() {
1352
+ const cursor = {
1353
+ [$mol_wire_cursor.stale]: '🔴',
1354
+ [$mol_wire_cursor.doubt]: '🟡',
1355
+ [$mol_wire_cursor.fresh]: '🟢',
1356
+ [$mol_wire_cursor.final]: '🔵',
1357
+ }[this.cursor] ?? this.cursor.toString();
1358
+ return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
1359
+ ? $mol_dev_format_auto({
1360
+ [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
1361
+ [$mol_dev_format_body]: () => $mol_dev_format_native(this),
1362
+ })
1363
+ : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
1364
+ }
1365
+ get $() {
1366
+ return (this.host ?? this.task)['$'];
1367
+ }
1368
+ emit(quant = $mol_wire_cursor.stale) {
1369
+ if (this.sub_empty)
1370
+ this.plan();
1371
+ else
1372
+ super.emit(quant);
1373
+ }
1374
+ fresh() {
1375
+ if (this.cursor === $mol_wire_cursor.fresh)
1376
+ return;
1377
+ if (this.cursor === $mol_wire_cursor.final)
1378
+ return;
1379
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1380
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1381
+ ;
1382
+ this.data[i]?.fresh();
1383
+ if (this.cursor !== $mol_wire_cursor.doubt)
1384
+ break check;
1385
+ }
1386
+ this.cursor = $mol_wire_cursor.fresh;
1387
+ return;
1388
+ }
1389
+ const bu = this.track_on();
1390
+ let result;
1391
+ try {
1392
+ switch (this.pub_from) {
1393
+ case 0:
1394
+ result = this.task.call(this.host);
1395
+ break;
1396
+ case 1:
1397
+ result = this.task.call(this.host, this.data[0]);
1398
+ break;
1399
+ default:
1400
+ result = this.task.call(this.host, ...this.args);
1401
+ break;
1402
+ }
1403
+ if ($mol_promise_like(result) && !handled.has(result)) {
1404
+ const put = (res) => {
1405
+ if (this.cache === result)
1406
+ this.put(res);
1407
+ return res;
1408
+ };
1409
+ result = result.then(put, put);
1410
+ }
1411
+ }
1412
+ catch (error) {
1413
+ if (error instanceof Error || $mol_promise_like(error)) {
1414
+ result = error;
1415
+ }
1416
+ else {
1417
+ result = new Error(String(error), { cause: error });
1418
+ }
1419
+ if ($mol_promise_like(result) && !handled.has(result)) {
1420
+ result = result.finally(() => {
1421
+ if (this.cache === result)
1422
+ this.absorb();
1423
+ });
1424
+ }
1425
+ }
1426
+ if ($mol_promise_like(result) && !handled.has(result)) {
1427
+ result = Object.assign(result, {
1428
+ destructor: result['destructor'] ?? (() => { })
1429
+ });
1430
+ handled.add(result);
1431
+ const error = new Error(`Promise in ${this}`);
1432
+ Object.defineProperty(result, 'stack', { get: () => error.stack });
1433
+ }
1434
+ if (!$mol_promise_like(result)) {
1435
+ this.track_cut();
1436
+ }
1437
+ this.track_off(bu);
1438
+ this.put(result);
1439
+ return this;
1440
+ }
1441
+ refresh() {
1442
+ this.cursor = $mol_wire_cursor.stale;
1443
+ this.fresh();
1444
+ }
1445
+ sync() {
1446
+ if (!$mol_wire_fiber.warm) {
1447
+ return this.result();
1448
+ }
1449
+ this.promote();
1450
+ this.fresh();
1451
+ if (this.cache instanceof Error) {
1452
+ return $mol_fail_hidden(this.cache);
1453
+ }
1454
+ if ($mol_promise_like(this.cache)) {
1455
+ return $mol_fail_hidden(this.cache);
1456
+ }
1457
+ return this.cache;
1458
+ }
1459
+ async async() {
1460
+ while (true) {
1461
+ this.fresh();
1462
+ if (this.cache instanceof Error) {
1463
+ $mol_fail_hidden(this.cache);
1464
+ }
1465
+ if (!$mol_promise_like(this.cache))
1466
+ return this.cache;
1467
+ await Promise.race([this.cache, this.step()]);
1468
+ if (!$mol_promise_like(this.cache))
1469
+ return this.cache;
1470
+ if (this.cursor === $mol_wire_cursor.final) {
1471
+ await new Promise(() => { });
1472
+ }
1473
+ }
1474
+ }
1475
+ step() {
1476
+ return new Promise(done => {
1477
+ const sub = new $mol_wire_pub_sub;
1478
+ const prev = sub.track_on();
1479
+ sub.track_next(this);
1480
+ sub.track_off(prev);
1481
+ sub.absorb = () => {
1482
+ done(null);
1483
+ setTimeout(() => sub.destructor());
1484
+ };
1485
+ });
1486
+ }
1487
+ }
1488
+ $.$mol_wire_fiber = $mol_wire_fiber;
1489
+ })($ || ($ = {}));
1490
+
1491
+ ;
1492
+ "use strict";
1493
+ var $;
1494
+ (function ($) {
1495
+ $.$mol_compare_deep_cache = new WeakMap();
1496
+ function $mol_compare_deep(left, right) {
1497
+ if (Object.is(left, right))
1498
+ return true;
1499
+ if (left === null)
1500
+ return false;
1501
+ if (right === null)
1502
+ return false;
1503
+ if (typeof left !== 'object')
1504
+ return false;
1505
+ if (typeof right !== 'object')
1506
+ return false;
1507
+ const left_proto = Reflect.getPrototypeOf(left);
1508
+ const right_proto = Reflect.getPrototypeOf(right);
1509
+ if (left_proto !== right_proto)
1510
+ return false;
1511
+ if (left instanceof Boolean)
1512
+ return Object.is(left.valueOf(), right['valueOf']());
1513
+ if (left instanceof Number)
1514
+ return Object.is(left.valueOf(), right['valueOf']());
1515
+ if (left instanceof String)
1516
+ return Object.is(left.valueOf(), right['valueOf']());
1517
+ if (left instanceof Date)
1518
+ return Object.is(left.valueOf(), right['valueOf']());
1519
+ if (left instanceof RegExp)
1520
+ return left.source === right.source && left.flags === right.flags;
1521
+ if (left instanceof Error)
1522
+ return left.message === right.message && left.stack === right.stack;
1523
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1524
+ if (left_cache) {
1525
+ const right_cache = left_cache.get(right);
1526
+ if (typeof right_cache === 'boolean')
1527
+ return right_cache;
1528
+ }
1529
+ else {
1530
+ left_cache = new WeakMap();
1531
+ $.$mol_compare_deep_cache.set(left, left_cache);
1532
+ }
1533
+ left_cache.set(right, true);
1534
+ let result;
1535
+ try {
1536
+ if (!left_proto)
1537
+ result = compare_pojo(left, right);
1538
+ else if (!Reflect.getPrototypeOf(left_proto))
1539
+ result = compare_pojo(left, right);
1540
+ else if (Symbol.toPrimitive in left)
1541
+ result = compare_primitive(left, right);
1542
+ else if (Array.isArray(left))
1543
+ result = compare_array(left, right);
1544
+ else if (left instanceof Set)
1545
+ result = compare_set(left, right);
1546
+ else if (left instanceof Map)
1547
+ result = compare_map(left, right);
1548
+ else if (ArrayBuffer.isView(left))
1549
+ result = compare_buffer(left, right);
1550
+ else if (Symbol.iterator in left)
1551
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1552
+ else
1553
+ result = false;
1554
+ }
1555
+ finally {
1556
+ left_cache.set(right, result);
1557
+ }
1558
+ return result;
1559
+ }
1560
+ $.$mol_compare_deep = $mol_compare_deep;
1561
+ function compare_array(left, right) {
1562
+ const len = left.length;
1563
+ if (len !== right.length)
1564
+ return false;
1565
+ for (let i = 0; i < len; ++i) {
1566
+ if (!$mol_compare_deep(left[i], right[i]))
1567
+ return false;
1568
+ }
1569
+ return true;
1570
+ }
1571
+ function compare_buffer(left, right) {
1572
+ const len = left.byteLength;
1573
+ if (len !== right.byteLength)
1574
+ return false;
1575
+ if (left instanceof DataView)
1576
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1577
+ for (let i = 0; i < len; ++i) {
1578
+ if (left[i] !== right[i])
1579
+ return false;
1580
+ }
1581
+ return true;
1582
+ }
1583
+ function compare_iterator(left, right) {
1584
+ while (true) {
1585
+ const left_next = left.next();
1586
+ const right_next = right.next();
1587
+ if (left_next.done !== right_next.done)
1588
+ return false;
1589
+ if (left_next.done)
1590
+ break;
1591
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1592
+ return false;
1593
+ }
1594
+ return true;
1595
+ }
1596
+ function compare_set(left, right) {
1597
+ if (left.size !== right.size)
1598
+ return false;
1599
+ return compare_iterator(left.values(), right.values());
1600
+ }
1601
+ function compare_map(left, right) {
1602
+ if (left.size !== right.size)
1603
+ return false;
1604
+ return compare_iterator(left.keys(), right.keys())
1605
+ && compare_iterator(left.values(), right.values());
1606
+ }
1607
+ function compare_pojo(left, right) {
1608
+ const left_keys = Object.getOwnPropertyNames(left);
1609
+ const right_keys = Object.getOwnPropertyNames(right);
1610
+ if (!compare_array(left_keys, right_keys))
1611
+ return false;
1612
+ for (let key of left_keys) {
1613
+ if (!$mol_compare_deep(left[key], right[key]))
1614
+ return false;
1615
+ }
1616
+ const left_syms = Object.getOwnPropertySymbols(left);
1617
+ const right_syms = Object.getOwnPropertySymbols(right);
1618
+ if (!compare_array(left_syms, right_syms))
1619
+ return false;
1620
+ for (let key of left_syms) {
1621
+ if (!$mol_compare_deep(left[key], right[key]))
1622
+ return false;
1623
+ }
1624
+ return true;
1625
+ }
1626
+ function compare_primitive(left, right) {
1627
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1628
+ }
1629
+ })($ || ($ = {}));
1630
+
1631
+ ;
1632
+ "use strict";
1633
+ var $;
1634
+ (function ($) {
1635
+ class $mol_wire_task extends $mol_wire_fiber {
1636
+ static getter(task) {
1637
+ return function $mol_wire_task_get(host, args) {
1638
+ const sub = $mol_wire_auto();
1639
+ const existen = sub?.track_next();
1640
+ reuse: if (existen) {
1641
+ if (!existen.temp)
1642
+ break reuse;
1643
+ if (existen.host !== host)
1644
+ break reuse;
1645
+ if (existen.task !== task)
1646
+ break reuse;
1647
+ if (!$mol_compare_deep(existen.args, args))
1648
+ break reuse;
1649
+ return existen;
1650
+ }
1651
+ const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
1652
+ const next = new $mol_wire_task(key, task, host, args);
1653
+ if (existen?.temp) {
1654
+ $$.$mol_log3_warn({
1655
+ place: '$mol_wire_task',
1656
+ message: `Non idempotency`,
1657
+ existen,
1658
+ next,
1659
+ hint: 'Ignore it',
1660
+ });
1661
+ }
1662
+ return next;
1663
+ };
1664
+ }
1665
+ get temp() {
1666
+ return true;
1667
+ }
1668
+ complete() {
1669
+ if ($mol_promise_like(this.cache))
1670
+ return;
1671
+ this.destructor();
1672
+ }
1673
+ put(next) {
1674
+ const prev = this.cache;
1675
+ this.cache = next;
1676
+ if ($mol_promise_like(next)) {
1677
+ this.cursor = $mol_wire_cursor.fresh;
1678
+ if (next !== prev)
1679
+ this.emit();
1680
+ return next;
1681
+ }
1682
+ this.cursor = $mol_wire_cursor.final;
1683
+ if (this.sub_empty)
1684
+ this.destructor();
1685
+ else if (next !== prev)
1686
+ this.emit();
1687
+ return next;
1688
+ }
1689
+ }
1690
+ $.$mol_wire_task = $mol_wire_task;
1691
+ })($ || ($ = {}));
1692
+
1693
+ ;
1694
+ "use strict";
1695
+ var $;
1696
+ (function ($) {
1697
+ function $mol_wire_sync(obj) {
1698
+ return new Proxy(obj, {
1699
+ get(obj, field) {
1700
+ const val = obj[field];
1701
+ if (typeof val !== 'function')
1702
+ return val;
1703
+ const temp = $mol_wire_task.getter(val);
1704
+ return function $mol_wire_sync(...args) {
1705
+ const fiber = temp(obj, args);
1706
+ return fiber.sync();
1707
+ };
1708
+ },
1709
+ apply(obj, self, args) {
1710
+ const temp = $mol_wire_task.getter(obj);
1711
+ const fiber = temp(self, args);
1712
+ return fiber.sync();
1713
+ },
1714
+ });
1715
+ }
1716
+ $.$mol_wire_sync = $mol_wire_sync;
1717
+ })($ || ($ = {}));
1718
+
1719
+ ;
1720
+ "use strict";
1721
+ var $;
1722
+ (function ($) {
1723
+ class $mol_run_error extends $mol_error_mix {
1724
+ }
1725
+ $.$mol_run_error = $mol_run_error;
1726
+ const child_process = $node['child_process'];
1727
+ $.$mol_run_spawn = child_process.spawn.bind(child_process);
1728
+ function $mol_run_async({ dir, timeout, command, env }) {
1729
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
1730
+ const [app, ...args] = args_raw;
1731
+ const sub = this.$mol_run_spawn(app, args, {
1732
+ shell: true,
1733
+ cwd: dir,
1734
+ env
1735
+ });
1736
+ this.$mol_log3_come({
1737
+ place: '$mol_run_async',
1738
+ pid: sub.pid,
1739
+ message: 'Run',
1740
+ command: args_raw.join(' '),
1741
+ dir: $node.path.relative('', dir),
1742
+ });
1743
+ let killed = false;
1744
+ let timer;
1745
+ const std_data = [];
1746
+ const error_data = [];
1747
+ const add = (std_chunk, error_chunk) => {
1748
+ if (std_chunk)
1749
+ std_data.push(std_chunk);
1750
+ if (error_chunk)
1751
+ error_data.push(error_chunk);
1752
+ if (!timeout)
1753
+ return;
1754
+ clearTimeout(timer);
1755
+ timer = setTimeout(() => {
1756
+ const signal = killed ? 'SIGKILL' : 'SIGTERM';
1757
+ killed = true;
1758
+ add();
1759
+ sub.kill(signal);
1760
+ }, timeout);
1761
+ };
1762
+ add();
1763
+ sub.stdout?.on('data', data => add(data));
1764
+ sub.stderr?.on('data', data => add(undefined, data));
1765
+ const promise = new Promise((done, fail) => {
1766
+ const close = (error, status = null, signal = null) => {
1767
+ if (!timer && timeout)
1768
+ return;
1769
+ clearTimeout(timer);
1770
+ timer = undefined;
1771
+ const res = {
1772
+ pid: sub.pid,
1773
+ status,
1774
+ signal,
1775
+ get stdout() { return Buffer.concat(std_data); },
1776
+ get stderr() { return Buffer.concat(error_data); }
1777
+ };
1778
+ this.$mol_log3_done({
1779
+ place: '$mol_run_async',
1780
+ pid: sub.pid,
1781
+ message: 'Run',
1782
+ status,
1783
+ command: args_raw.join(' '),
1784
+ dir: $node.path.relative('', dir),
1785
+ });
1786
+ if (error || status || killed)
1787
+ return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
1788
+ done(res);
1789
+ };
1790
+ sub.on('disconnect', () => close(new Error('Disconnected')));
1791
+ sub.on('error', err => close(err));
1792
+ sub.on('exit', (status, signal) => close(null, status, signal));
1793
+ });
1794
+ return Object.assign(promise, { destructor: () => {
1795
+ clearTimeout(timer);
1796
+ sub.kill('SIGKILL');
1797
+ } });
1798
+ }
1799
+ $.$mol_run_async = $mol_run_async;
1800
+ function $mol_run(options) {
1801
+ if (!options.env)
1802
+ options = { ...options, env: this.$mol_env() };
1803
+ return $mol_wire_sync(this).$mol_run_async(options);
1804
+ }
1805
+ $.$mol_run = $mol_run;
1806
+ })($ || ($ = {}));
1807
+
1808
+ ;
1809
+ "use strict";
1810
+ var $;
1811
+ (function ($) {
1812
+ function $mol_exec(dir, command, ...args) {
1813
+ return this.$mol_run({ command: [command, ...args], dir });
1814
+ }
1815
+ $.$mol_exec = $mol_exec;
1816
+ })($ || ($ = {}));
1817
+
1818
+ ;
1819
+ "use strict";
1820
+ var $;
1821
+ (function ($) {
1822
+ $.$mol_crypto_native = $node.crypto.webcrypto;
1823
+ })($ || ($ = {}));
1824
+
1825
+ ;
1826
+ "use strict";
1827
+ var $;
1828
+ (function ($) {
1829
+ const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
1830
+ const encoder = new TextEncoder();
1831
+ function $mol_charset_encode(value) {
1832
+ return encoder.encode(value);
1833
+ }
1834
+ $.$mol_charset_encode = $mol_charset_encode;
1835
+ })($ || ($ = {}));
1836
+
1837
+ ;
1838
+ "use strict";
1839
+ var $;
1840
+ (function ($) {
1841
+ const algorithm = {
1842
+ name: 'AES-CBC',
1843
+ length: 128,
1844
+ tagLength: 32,
1845
+ };
1846
+ class $mol_crypto_secret extends Object {
1847
+ native;
1848
+ static size = 16;
1849
+ constructor(native) {
1850
+ super();
1851
+ this.native = native;
1852
+ }
1853
+ static async generate() {
1854
+ return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
1855
+ }
1856
+ static async from(serial) {
1857
+ return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
1858
+ }
1859
+ static async pass(pass, salt) {
1860
+ return new this(await $mol_crypto_native.subtle.deriveKey({
1861
+ name: "PBKDF2",
1862
+ salt,
1863
+ iterations: 10_000,
1864
+ hash: "SHA-256",
1865
+ }, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
1866
+ }
1867
+ static async derive(private_serial, public_serial) {
1868
+ const ecdh = { name: "ECDH", namedCurve: "P-256" };
1869
+ const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
1870
+ const private_key = await $mol_crypto_native.subtle.importKey('jwk', {
1871
+ ...jwk,
1872
+ key_ops: ['deriveKey'],
1873
+ x: private_serial.slice(0, 43),
1874
+ y: private_serial.slice(43, 86),
1875
+ d: private_serial.slice(86, 129),
1876
+ }, ecdh, true, ['deriveKey']);
1877
+ const public_key = await $mol_crypto_native.subtle.importKey('jwk', {
1878
+ ...jwk,
1879
+ key_ops: [],
1880
+ x: public_serial.slice(0, 43),
1881
+ y: public_serial.slice(43, 86),
1882
+ }, ecdh, true, []);
1883
+ const secret = await $mol_crypto_native.subtle.deriveKey({
1884
+ name: "ECDH",
1885
+ public: public_key,
1886
+ }, private_key, algorithm, true, ["encrypt", "decrypt"]);
1887
+ return new this(secret);
1888
+ }
1889
+ async serial() {
1890
+ return new Uint8Array(await $mol_crypto_native.subtle.exportKey('raw', this.native));
1891
+ }
1892
+ async encrypt(open, salt) {
1893
+ return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
1894
+ ...algorithm,
1895
+ iv: salt,
1896
+ }, this.native, open));
1897
+ }
1898
+ async decrypt(closed, salt) {
1899
+ return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
1900
+ ...algorithm,
1901
+ iv: salt,
1902
+ }, this.native, closed));
1903
+ }
1904
+ }
1905
+ $.$mol_crypto_secret = $mol_crypto_secret;
1906
+ })($ || ($ = {}));
1907
+
1908
+ ;
1909
+ "use strict";
1910
+ var $;
1911
+ (function ($) {
1912
+ })($ || ($ = {}));
1913
+
1914
+ ;
1915
+ "use strict";
1916
+ var $;
1917
+ (function ($) {
1918
+ $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
1919
+ })($ || ($ = {}));
1920
+
1921
+ ;
1922
+ "use strict";
1923
+ var $;
1924
+ (function ($) {
1925
+ async function $mol_crypto_secret_id() {
1926
+ const signed = this.$mol_dom_context.localStorage.getItem('$mol_crypto_secret');
1927
+ if (signed === '')
1928
+ return await this.$mol_crypto_secret_id_get();
1929
+ const id = await this.$mol_crypto_secret_id_new();
1930
+ this.$mol_dom_context.localStorage.setItem('$mol_crypto_secret', '');
1931
+ return id;
1932
+ }
1933
+ $.$mol_crypto_secret_id = $mol_crypto_secret_id;
1934
+ async function $mol_crypto_secret_id_new() {
1935
+ const cred = await this.$mol_dom_context.navigator.credentials.create({
1936
+ publicKey: {
1937
+ rp: {
1938
+ name: "$mol_crypto_id",
1939
+ },
1940
+ user: {
1941
+ id: new Uint8Array([0]),
1942
+ name: "",
1943
+ displayName: ""
1944
+ },
1945
+ pubKeyCredParams: [
1946
+ { type: "public-key", alg: -7 },
1947
+ { type: "public-key", alg: -257 },
1948
+ ],
1949
+ challenge: new Uint8Array().buffer,
1950
+ },
1951
+ });
1952
+ return $mol_crypto_secret.from(cred.rawId);
1953
+ }
1954
+ $.$mol_crypto_secret_id_new = $mol_crypto_secret_id_new;
1955
+ async function $mol_crypto_secret_id_get() {
1956
+ const cred = await this.$mol_dom_context.navigator.credentials.get({
1957
+ mediation: 'silent',
1958
+ publicKey: {
1959
+ userVerification: 'discouraged',
1960
+ challenge: new Uint8Array().buffer,
1961
+ },
1962
+ });
1963
+ return $mol_crypto_secret.from(cred.rawId);
1964
+ }
1965
+ $.$mol_crypto_secret_id_get = $mol_crypto_secret_id_get;
1966
+ })($ || ($ = {}));
1967
+
1968
+ ;
1969
+ "use strict";
1970
+ var $;
1971
+ (function ($) {
1972
+ function $mol_base64_encode(src) {
1973
+ throw new Error('Not implemented');
1974
+ }
1975
+ $.$mol_base64_encode = $mol_base64_encode;
1976
+ })($ || ($ = {}));
1977
+
1978
+ ;
1979
+ "use strict";
1980
+ var $;
1981
+ (function ($) {
1982
+ function $mol_base64_encode_node(str) {
1983
+ if (!str)
1984
+ return '';
1985
+ if (Buffer.isBuffer(str))
1986
+ return str.toString('base64');
1987
+ return Buffer.from(str).toString('base64');
1988
+ }
1989
+ $.$mol_base64_encode_node = $mol_base64_encode_node;
1990
+ $.$mol_base64_encode = $mol_base64_encode_node;
1991
+ })($ || ($ = {}));
1992
+
1993
+ ;
1994
+ "use strict";
1995
+ var $;
1996
+ (function ($) {
1997
+ function $mol_base64_decode(base64) {
1998
+ throw new Error('Not implemented');
1999
+ }
2000
+ $.$mol_base64_decode = $mol_base64_decode;
2001
+ })($ || ($ = {}));
2002
+
1078
2003
  ;
1079
2004
  "use strict";
1080
2005
  var $;
@@ -1596,38 +2521,6 @@ var $;
1596
2521
  $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
1597
2522
  })($ || ($ = {}));
1598
2523
 
1599
- ;
1600
- "use strict";
1601
- var $;
1602
- (function ($_1) {
1603
- $mol_test_mocks.push($ => {
1604
- $.$mol_log3_come = () => { };
1605
- $.$mol_log3_done = () => { };
1606
- $.$mol_log3_fail = () => { };
1607
- $.$mol_log3_warn = () => { };
1608
- $.$mol_log3_rise = () => { };
1609
- $.$mol_log3_area = () => () => { };
1610
- });
1611
- })($ || ($ = {}));
1612
-
1613
- ;
1614
- "use strict";
1615
-
1616
- ;
1617
- "use strict";
1618
-
1619
- ;
1620
- "use strict";
1621
-
1622
- ;
1623
- "use strict";
1624
-
1625
- ;
1626
- "use strict";
1627
-
1628
- ;
1629
- "use strict";
1630
-
1631
2524
  ;
1632
2525
  "use strict";
1633
2526
  var $;
@@ -1689,6 +2582,15 @@ var $;
1689
2582
  ;
1690
2583
  "use strict";
1691
2584
 
2585
+ ;
2586
+ "use strict";
2587
+
2588
+ ;
2589
+ "use strict";
2590
+
2591
+ ;
2592
+ "use strict";
2593
+
1692
2594
  ;
1693
2595
  "use strict";
1694
2596
  var $;
@@ -2173,171 +3075,31 @@ var $;
2173
3075
  $mol_assert_equal(calls, 3);
2174
3076
  $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
2175
3077
  $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
2176
- },
2177
- 'lazyfy'() {
2178
- let calls = 0;
2179
- const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
2180
- $mol_assert_equal(true, list instanceof Array);
2181
- $mol_assert_equal(list.length, 4);
2182
- $mol_assert_equal(calls, 0);
2183
- $mol_assert_equal(list[0], 12);
2184
- $mol_assert_equal(list[3], 15);
2185
- $mol_assert_equal(list[4], undefined);
2186
- $mol_assert_equal(calls, 2);
2187
- },
2188
- 'prevent modification'() {
2189
- const list = $mol_range2(i => i, () => 5);
2190
- $mol_assert_fail(() => list.push(4), TypeError);
2191
- $mol_assert_fail(() => list.pop(), TypeError);
2192
- $mol_assert_fail(() => list.unshift(4), TypeError);
2193
- $mol_assert_fail(() => list.shift(), TypeError);
2194
- $mol_assert_fail(() => list.splice(1, 2), TypeError);
2195
- $mol_assert_fail(() => list[1] = 2, TypeError);
2196
- $mol_assert_fail(() => list.reverse(), TypeError);
2197
- $mol_assert_fail(() => list.sort(), TypeError);
2198
- $mol_assert_equal(list.toString(), '0,1,2,3,4');
2199
- }
2200
- });
2201
- })($ || ($ = {}));
2202
-
2203
- ;
2204
- "use strict";
2205
- var $;
2206
- (function ($) {
2207
- $.$mol_compare_deep_cache = new WeakMap();
2208
- function $mol_compare_deep(left, right) {
2209
- if (Object.is(left, right))
2210
- return true;
2211
- if (left === null)
2212
- return false;
2213
- if (right === null)
2214
- return false;
2215
- if (typeof left !== 'object')
2216
- return false;
2217
- if (typeof right !== 'object')
2218
- return false;
2219
- const left_proto = Reflect.getPrototypeOf(left);
2220
- const right_proto = Reflect.getPrototypeOf(right);
2221
- if (left_proto !== right_proto)
2222
- return false;
2223
- if (left instanceof Boolean)
2224
- return Object.is(left.valueOf(), right['valueOf']());
2225
- if (left instanceof Number)
2226
- return Object.is(left.valueOf(), right['valueOf']());
2227
- if (left instanceof String)
2228
- return Object.is(left.valueOf(), right['valueOf']());
2229
- if (left instanceof Date)
2230
- return Object.is(left.valueOf(), right['valueOf']());
2231
- if (left instanceof RegExp)
2232
- return left.source === right.source && left.flags === right.flags;
2233
- if (left instanceof Error)
2234
- return left.message === right.message && left.stack === right.stack;
2235
- let left_cache = $.$mol_compare_deep_cache.get(left);
2236
- if (left_cache) {
2237
- const right_cache = left_cache.get(right);
2238
- if (typeof right_cache === 'boolean')
2239
- return right_cache;
2240
- }
2241
- else {
2242
- left_cache = new WeakMap();
2243
- $.$mol_compare_deep_cache.set(left, left_cache);
2244
- }
2245
- left_cache.set(right, true);
2246
- let result;
2247
- try {
2248
- if (!left_proto)
2249
- result = compare_pojo(left, right);
2250
- else if (!Reflect.getPrototypeOf(left_proto))
2251
- result = compare_pojo(left, right);
2252
- else if (Symbol.toPrimitive in left)
2253
- result = compare_primitive(left, right);
2254
- else if (Array.isArray(left))
2255
- result = compare_array(left, right);
2256
- else if (left instanceof Set)
2257
- result = compare_set(left, right);
2258
- else if (left instanceof Map)
2259
- result = compare_map(left, right);
2260
- else if (ArrayBuffer.isView(left))
2261
- result = compare_buffer(left, right);
2262
- else if (Symbol.iterator in left)
2263
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
2264
- else
2265
- result = false;
2266
- }
2267
- finally {
2268
- left_cache.set(right, result);
2269
- }
2270
- return result;
2271
- }
2272
- $.$mol_compare_deep = $mol_compare_deep;
2273
- function compare_array(left, right) {
2274
- const len = left.length;
2275
- if (len !== right.length)
2276
- return false;
2277
- for (let i = 0; i < len; ++i) {
2278
- if (!$mol_compare_deep(left[i], right[i]))
2279
- return false;
2280
- }
2281
- return true;
2282
- }
2283
- function compare_buffer(left, right) {
2284
- const len = left.byteLength;
2285
- if (len !== right.byteLength)
2286
- return false;
2287
- if (left instanceof DataView)
2288
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
2289
- for (let i = 0; i < len; ++i) {
2290
- if (left[i] !== right[i])
2291
- return false;
2292
- }
2293
- return true;
2294
- }
2295
- function compare_iterator(left, right) {
2296
- while (true) {
2297
- const left_next = left.next();
2298
- const right_next = right.next();
2299
- if (left_next.done !== right_next.done)
2300
- return false;
2301
- if (left_next.done)
2302
- break;
2303
- if (!$mol_compare_deep(left_next.value, right_next.value))
2304
- return false;
2305
- }
2306
- return true;
2307
- }
2308
- function compare_set(left, right) {
2309
- if (left.size !== right.size)
2310
- return false;
2311
- return compare_iterator(left.values(), right.values());
2312
- }
2313
- function compare_map(left, right) {
2314
- if (left.size !== right.size)
2315
- return false;
2316
- return compare_iterator(left.keys(), right.keys())
2317
- && compare_iterator(left.values(), right.values());
2318
- }
2319
- function compare_pojo(left, right) {
2320
- const left_keys = Object.getOwnPropertyNames(left);
2321
- const right_keys = Object.getOwnPropertyNames(right);
2322
- if (!compare_array(left_keys, right_keys))
2323
- return false;
2324
- for (let key of left_keys) {
2325
- if (!$mol_compare_deep(left[key], right[key]))
2326
- return false;
2327
- }
2328
- const left_syms = Object.getOwnPropertySymbols(left);
2329
- const right_syms = Object.getOwnPropertySymbols(right);
2330
- if (!compare_array(left_syms, right_syms))
2331
- return false;
2332
- for (let key of left_syms) {
2333
- if (!$mol_compare_deep(left[key], right[key]))
2334
- return false;
3078
+ },
3079
+ 'lazyfy'() {
3080
+ let calls = 0;
3081
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
3082
+ $mol_assert_equal(true, list instanceof Array);
3083
+ $mol_assert_equal(list.length, 4);
3084
+ $mol_assert_equal(calls, 0);
3085
+ $mol_assert_equal(list[0], 12);
3086
+ $mol_assert_equal(list[3], 15);
3087
+ $mol_assert_equal(list[4], undefined);
3088
+ $mol_assert_equal(calls, 2);
3089
+ },
3090
+ 'prevent modification'() {
3091
+ const list = $mol_range2(i => i, () => 5);
3092
+ $mol_assert_fail(() => list.push(4), TypeError);
3093
+ $mol_assert_fail(() => list.pop(), TypeError);
3094
+ $mol_assert_fail(() => list.unshift(4), TypeError);
3095
+ $mol_assert_fail(() => list.shift(), TypeError);
3096
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
3097
+ $mol_assert_fail(() => list[1] = 2, TypeError);
3098
+ $mol_assert_fail(() => list.reverse(), TypeError);
3099
+ $mol_assert_fail(() => list.sort(), TypeError);
3100
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
2335
3101
  }
2336
- return true;
2337
- }
2338
- function compare_primitive(left, right) {
2339
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
2340
- }
3102
+ });
2341
3103
  })($ || ($ = {}));
2342
3104
 
2343
3105
  ;
@@ -2595,16 +3357,25 @@ var $;
2595
3357
  "use strict";
2596
3358
  var $;
2597
3359
  (function ($_1) {
2598
- $mol_test({
2599
- 'FQN of anon function'($) {
2600
- const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
2601
- $mol_assert_equal($$.$mol_func_name_test.name, '');
2602
- $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
2603
- $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
2604
- },
3360
+ $mol_test_mocks.push($ => {
3361
+ $.$mol_log3_come = () => { };
3362
+ $.$mol_log3_done = () => { };
3363
+ $.$mol_log3_fail = () => { };
3364
+ $.$mol_log3_warn = () => { };
3365
+ $.$mol_log3_rise = () => { };
3366
+ $.$mol_log3_area = () => () => { };
2605
3367
  });
2606
3368
  })($ || ($ = {}));
2607
3369
 
3370
+ ;
3371
+ "use strict";
3372
+
3373
+ ;
3374
+ "use strict";
3375
+
3376
+ ;
3377
+ "use strict";
3378
+
2608
3379
  ;
2609
3380
  "use strict";
2610
3381
  var $;
@@ -2849,6 +3620,462 @@ var $;
2849
3620
  });
2850
3621
  })($ || ($ = {}));
2851
3622
 
3623
+ ;
3624
+ "use strict";
3625
+ var $;
3626
+ (function ($_1) {
3627
+ $mol_test({
3628
+ 'FQN of anon function'($) {
3629
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
3630
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
3631
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
3632
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
3633
+ },
3634
+ });
3635
+ })($ || ($ = {}));
3636
+
3637
+ ;
3638
+ "use strict";
3639
+ var $;
3640
+ (function ($) {
3641
+ $mol_test({
3642
+ 'auto name'() {
3643
+ class Invalid extends $mol_error_mix {
3644
+ }
3645
+ const mix = new Invalid('foo');
3646
+ $mol_assert_equal(mix.name, 'Invalid_Error');
3647
+ },
3648
+ 'simpe mix'() {
3649
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
3650
+ $mol_assert_equal(mix.message, 'foo');
3651
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
3652
+ },
3653
+ 'provide additional info'() {
3654
+ class Invalid extends $mol_error_mix {
3655
+ }
3656
+ 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' }));
3657
+ const hints = [];
3658
+ if (mix instanceof $mol_error_mix) {
3659
+ for (const er of mix.errors) {
3660
+ if (er instanceof Invalid) {
3661
+ hints.push(er.cause?.hint ?? '');
3662
+ }
3663
+ }
3664
+ }
3665
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
3666
+ },
3667
+ });
3668
+ })($ || ($ = {}));
3669
+
3670
+ ;
3671
+ "use strict";
3672
+ var $;
3673
+ (function ($_1) {
3674
+ $mol_test({
3675
+ 'Collect deps'() {
3676
+ const pub1 = new $mol_wire_pub;
3677
+ const pub2 = new $mol_wire_pub;
3678
+ const sub = new $mol_wire_pub_sub;
3679
+ const bu1 = sub.track_on();
3680
+ try {
3681
+ pub1.promote();
3682
+ pub2.promote();
3683
+ pub2.promote();
3684
+ }
3685
+ finally {
3686
+ sub.track_cut();
3687
+ sub.track_off(bu1);
3688
+ }
3689
+ pub1.emit();
3690
+ pub2.emit();
3691
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3692
+ const bu2 = sub.track_on();
3693
+ try {
3694
+ pub1.promote();
3695
+ pub1.promote();
3696
+ pub2.promote();
3697
+ }
3698
+ finally {
3699
+ sub.track_cut();
3700
+ sub.track_off(bu2);
3701
+ }
3702
+ pub1.emit();
3703
+ pub2.emit();
3704
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3705
+ },
3706
+ 'cyclic detection'($) {
3707
+ const sub1 = new $mol_wire_pub_sub;
3708
+ const sub2 = new $mol_wire_pub_sub;
3709
+ const bu1 = sub1.track_on();
3710
+ try {
3711
+ const bu2 = sub2.track_on();
3712
+ try {
3713
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3714
+ }
3715
+ finally {
3716
+ sub2.track_cut();
3717
+ sub2.track_off(bu2);
3718
+ }
3719
+ }
3720
+ finally {
3721
+ sub1.track_cut();
3722
+ sub1.track_off(bu1);
3723
+ }
3724
+ },
3725
+ });
3726
+ })($ || ($ = {}));
3727
+
3728
+ ;
3729
+ "use strict";
3730
+ var $;
3731
+ (function ($) {
3732
+ $.$mol_after_mock_queue = [];
3733
+ function $mol_after_mock_warp() {
3734
+ const queue = $.$mol_after_mock_queue.splice(0);
3735
+ for (const task of queue)
3736
+ task();
3737
+ }
3738
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
3739
+ class $mol_after_mock_commmon extends $mol_object2 {
3740
+ task;
3741
+ promise = Promise.resolve();
3742
+ cancelled = false;
3743
+ id;
3744
+ constructor(task) {
3745
+ super();
3746
+ this.task = task;
3747
+ $.$mol_after_mock_queue.push(task);
3748
+ }
3749
+ destructor() {
3750
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
3751
+ if (index >= 0)
3752
+ $.$mol_after_mock_queue.splice(index, 1);
3753
+ }
3754
+ }
3755
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3756
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3757
+ delay;
3758
+ constructor(delay, task) {
3759
+ super(task);
3760
+ this.delay = delay;
3761
+ }
3762
+ }
3763
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
3764
+ })($ || ($ = {}));
3765
+
3766
+ ;
3767
+ "use strict";
3768
+ var $;
3769
+ (function ($_1) {
3770
+ $mol_test_mocks.push($ => {
3771
+ $.$mol_after_tick = $mol_after_mock_commmon;
3772
+ });
3773
+ })($ || ($ = {}));
3774
+
3775
+ ;
3776
+ "use strict";
3777
+ var $;
3778
+ (function ($) {
3779
+ $mol_test({
3780
+ 'Sync execution'() {
3781
+ class Sync extends $mol_object2 {
3782
+ static calc(a, b) {
3783
+ return a + b;
3784
+ }
3785
+ }
3786
+ __decorate([
3787
+ $mol_wire_method
3788
+ ], Sync, "calc", null);
3789
+ $mol_assert_equal(Sync.calc(1, 2), 3);
3790
+ },
3791
+ async 'async <=> sync'() {
3792
+ class SyncAsync extends $mol_object2 {
3793
+ static async val(a) {
3794
+ return a;
3795
+ }
3796
+ static sum(a, b) {
3797
+ const syn = $mol_wire_sync(this);
3798
+ return syn.val(a) + syn.val(b);
3799
+ }
3800
+ static async calc(a, b) {
3801
+ return 5 + await $mol_wire_async(this).sum(a, b);
3802
+ }
3803
+ }
3804
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3805
+ },
3806
+ async 'Idempotence control'() {
3807
+ class Idempotence extends $mol_object2 {
3808
+ static logs_idemp = 0;
3809
+ static logs_unidemp = 0;
3810
+ static log_idemp() {
3811
+ this.logs_idemp += 1;
3812
+ }
3813
+ static log_unidemp() {
3814
+ this.logs_unidemp += 1;
3815
+ }
3816
+ static async val(a) {
3817
+ return a;
3818
+ }
3819
+ static sum(a, b) {
3820
+ this.log_idemp();
3821
+ this.log_unidemp();
3822
+ const syn = $mol_wire_sync(this);
3823
+ return syn.val(a) + syn.val(b);
3824
+ }
3825
+ static async calc(a, b) {
3826
+ return 5 + await $mol_wire_async(this).sum(a, b);
3827
+ }
3828
+ }
3829
+ __decorate([
3830
+ $mol_wire_method
3831
+ ], Idempotence, "log_idemp", null);
3832
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3833
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
3834
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
3835
+ },
3836
+ async 'Error handling'() {
3837
+ class Handle extends $mol_object2 {
3838
+ static async sum(a, b) {
3839
+ $mol_fail(new Error('test error ' + (a + b)));
3840
+ }
3841
+ static check() {
3842
+ try {
3843
+ return $mol_wire_sync(Handle).sum(1, 2);
3844
+ }
3845
+ catch (error) {
3846
+ if ($mol_promise_like(error))
3847
+ $mol_fail_hidden(error);
3848
+ $mol_assert_equal(error.message, 'test error 3');
3849
+ }
3850
+ }
3851
+ }
3852
+ await $mol_wire_async(Handle).check();
3853
+ },
3854
+ });
3855
+ })($ || ($ = {}));
3856
+
3857
+ ;
3858
+ "use strict";
3859
+ var $;
3860
+ (function ($) {
3861
+ function $mol_wire_method(host, field, descr) {
3862
+ if (!descr)
3863
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
3864
+ const orig = descr?.value ?? host[field];
3865
+ const sup = Reflect.getPrototypeOf(host);
3866
+ if (typeof sup[field] === 'function') {
3867
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
3868
+ }
3869
+ const temp = $mol_wire_task.getter(orig);
3870
+ const value = function (...args) {
3871
+ const fiber = temp(this ?? null, args);
3872
+ return fiber.sync();
3873
+ };
3874
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
3875
+ Object.assign(value, { orig });
3876
+ const descr2 = { ...descr, value };
3877
+ Reflect.defineProperty(host, field, descr2);
3878
+ return descr2;
3879
+ }
3880
+ $.$mol_wire_method = $mol_wire_method;
3881
+ })($ || ($ = {}));
3882
+
3883
+ ;
3884
+ "use strict";
3885
+ var $;
3886
+ (function ($) {
3887
+ function $mol_wire_async(obj) {
3888
+ let fiber;
3889
+ const temp = $mol_wire_task.getter(obj);
3890
+ return new Proxy(obj, {
3891
+ get(obj, field) {
3892
+ const val = obj[field];
3893
+ if (typeof val !== 'function')
3894
+ return val;
3895
+ let fiber;
3896
+ const temp = $mol_wire_task.getter(val);
3897
+ return function $mol_wire_async(...args) {
3898
+ fiber?.destructor();
3899
+ fiber = temp(obj, args);
3900
+ return fiber.async();
3901
+ };
3902
+ },
3903
+ apply(obj, self, args) {
3904
+ fiber?.destructor();
3905
+ fiber = temp(self, args);
3906
+ return fiber.async();
3907
+ },
3908
+ });
3909
+ }
3910
+ $.$mol_wire_async = $mol_wire_async;
3911
+ })($ || ($ = {}));
3912
+
3913
+ ;
3914
+ "use strict";
3915
+ var $;
3916
+ (function ($_1) {
3917
+ $mol_test({
3918
+ 'test types'($) {
3919
+ class A {
3920
+ static a() {
3921
+ return '';
3922
+ }
3923
+ static b() {
3924
+ return $mol_wire_async(this).a();
3925
+ }
3926
+ }
3927
+ },
3928
+ async 'Latest method calls wins'($) {
3929
+ class NameLogger extends $mol_object2 {
3930
+ static $ = $;
3931
+ static first = [];
3932
+ static last = [];
3933
+ static send(next) {
3934
+ $mol_wire_sync(this.first).push(next);
3935
+ this.$.$mol_wait_timeout(0);
3936
+ this.last.push(next);
3937
+ }
3938
+ }
3939
+ const name = $mol_wire_async(NameLogger).send;
3940
+ name('john');
3941
+ const promise = name('jin');
3942
+ $.$mol_after_mock_warp();
3943
+ await promise;
3944
+ $mol_assert_like(NameLogger.first, ['john', 'jin']);
3945
+ $mol_assert_like(NameLogger.last, ['jin']);
3946
+ },
3947
+ async 'Latest function calls wins'($) {
3948
+ const first = [];
3949
+ const last = [];
3950
+ function send_name(next) {
3951
+ $mol_wire_sync(first).push(next);
3952
+ $.$mol_wait_timeout(0);
3953
+ last.push(next);
3954
+ }
3955
+ const name = $mol_wire_async(send_name);
3956
+ name('john');
3957
+ const promise = name('jin');
3958
+ $.$mol_after_mock_warp();
3959
+ await promise;
3960
+ $mol_assert_like(first, ['john', 'jin']);
3961
+ $mol_assert_like(last, ['jin']);
3962
+ },
3963
+ });
3964
+ })($ || ($ = {}));
3965
+
3966
+ ;
3967
+ "use strict";
3968
+ var $;
3969
+ (function ($_1) {
3970
+ $mol_test({
3971
+ 'test types'($) {
3972
+ class A {
3973
+ static a() {
3974
+ return Promise.resolve('');
3975
+ }
3976
+ static b() {
3977
+ return $mol_wire_sync(this).a();
3978
+ }
3979
+ }
3980
+ },
3981
+ });
3982
+ })($ || ($ = {}));
3983
+
3984
+ ;
3985
+ "use strict";
3986
+ var $;
3987
+ (function ($) {
3988
+ function $mol_promise() {
3989
+ let done;
3990
+ let fail;
3991
+ const promise = new Promise((d, f) => {
3992
+ done = d;
3993
+ fail = f;
3994
+ });
3995
+ return Object.assign(promise, {
3996
+ done,
3997
+ fail,
3998
+ });
3999
+ }
4000
+ $.$mol_promise = $mol_promise;
4001
+ })($ || ($ = {}));
4002
+
4003
+ ;
4004
+ "use strict";
4005
+ var $;
4006
+ (function ($) {
4007
+ class $mol_after_timeout extends $mol_object2 {
4008
+ delay;
4009
+ task;
4010
+ id;
4011
+ constructor(delay, task) {
4012
+ super();
4013
+ this.delay = delay;
4014
+ this.task = task;
4015
+ this.id = setTimeout(task, delay);
4016
+ }
4017
+ destructor() {
4018
+ clearTimeout(this.id);
4019
+ }
4020
+ }
4021
+ $.$mol_after_timeout = $mol_after_timeout;
4022
+ })($ || ($ = {}));
4023
+
4024
+ ;
4025
+ "use strict";
4026
+ var $;
4027
+ (function ($_1) {
4028
+ $mol_test_mocks.push($ => {
4029
+ $.$mol_after_timeout = $mol_after_mock_timeout;
4030
+ });
4031
+ })($ || ($ = {}));
4032
+
4033
+ ;
4034
+ "use strict";
4035
+ var $;
4036
+ (function ($) {
4037
+ function $mol_wait_timeout_async(timeout) {
4038
+ const promise = $mol_promise();
4039
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
4040
+ return Object.assign(promise, {
4041
+ destructor: () => task.destructor()
4042
+ });
4043
+ }
4044
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
4045
+ function $mol_wait_timeout(timeout) {
4046
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
4047
+ }
4048
+ $.$mol_wait_timeout = $mol_wait_timeout;
4049
+ })($ || ($ = {}));
4050
+
4051
+ ;
4052
+ "use strict";
4053
+ var $;
4054
+ (function ($_1) {
4055
+ $mol_test({
4056
+ async 'exec timeout auto kill child process'($) {
4057
+ let close_mock = () => { };
4058
+ const context_mock = $.$mol_ambient({
4059
+ $mol_run_spawn: () => ({
4060
+ on(name, cb) {
4061
+ if (name === 'exit')
4062
+ close_mock = cb;
4063
+ },
4064
+ kill() { close_mock(); }
4065
+ })
4066
+ });
4067
+ let message = '';
4068
+ try {
4069
+ const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10 });
4070
+ }
4071
+ catch (e) {
4072
+ message = e.message;
4073
+ }
4074
+ $mol_assert_equal(message, 'Run error, timeout');
4075
+ }
4076
+ });
4077
+ })($ || ($ = {}));
4078
+
2852
4079
  ;
2853
4080
  "use strict";
2854
4081
  var $;