mol_wire_lib 1.0.1631 → 1.0.1632

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
@@ -2884,13 +2884,7 @@ var $node = new Proxy({ require }, {
2884
2884
  target.require.resolve(name);
2885
2885
  }
2886
2886
  catch {
2887
- try {
2888
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
2889
- }
2890
- catch (e) {
2891
- if ($$.$mol_promise_like(e))
2892
- $$.$mol_fail_hidden(e);
2893
- }
2887
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
2894
2888
  try {
2895
2889
  $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
2896
2890
  }
@@ -2899,6 +2893,11 @@ var $node = new Proxy({ require }, {
2899
2893
  $$.$mol_fail_hidden(e);
2900
2894
  $$.$mol_fail_log(e);
2901
2895
  }
2896
+ const mam_node_modules = target.require('node:path').join(process.cwd(), 'node_modules');
2897
+ if (!process.env.NODE_PATH?.includes(mam_node_modules)) {
2898
+ process.env.NODE_PATH = `${mam_node_modules}${process.env.NODE_PATH ? `:${process.env.NODE_PATH}` : ''}`;
2899
+ target.require('node:module').Module._initPaths();
2900
+ }
2902
2901
  }
2903
2902
  return target.require(name);
2904
2903
  },
@@ -2915,70 +2914,97 @@ require = (req => Object.assign(function require(name) {
2915
2914
  ;
2916
2915
  "use strict";
2917
2916
  var $;
2918
- (function ($) {
2919
- $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
2917
+ (function ($_1) {
2918
+ $mol_test({
2919
+ 'FQN of anon function'($) {
2920
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
2921
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
2922
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
2923
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
2924
+ },
2925
+ });
2920
2926
  })($ || ($ = {}));
2921
2927
 
2922
2928
  ;
2923
2929
  "use strict";
2924
2930
  var $;
2925
2931
  (function ($) {
2926
- $.$mol_dom = $mol_dom_context;
2932
+ function cause_serialize(cause) {
2933
+ return JSON.stringify(cause, null, ' ')
2934
+ .replace(/\(/, '<')
2935
+ .replace(/\)/, ' >');
2936
+ }
2937
+ function frame_normalize(frame) {
2938
+ return (typeof frame === 'string' ? frame : cause_serialize(frame))
2939
+ .trim()
2940
+ .replace(/at /gm, ' at ')
2941
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
2942
+ }
2943
+ class $mol_error_mix extends AggregateError {
2944
+ cause;
2945
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
2946
+ constructor(message, cause = {}, ...errors) {
2947
+ super(errors, message, { cause });
2948
+ this.cause = cause;
2949
+ const desc = Object.getOwnPropertyDescriptor(this, 'stack');
2950
+ const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
2951
+ Object.defineProperty(this, 'stack', {
2952
+ get: () => stack_get() + '\n' + [
2953
+ this.cause ?? 'no cause',
2954
+ ...this.errors.flatMap(e => [
2955
+ String(e.stack),
2956
+ ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
2957
+ ])
2958
+ ].map(frame_normalize).join('\n')
2959
+ });
2960
+ Object.defineProperty(this, 'cause', {
2961
+ get: () => cause
2962
+ });
2963
+ }
2964
+ static [Symbol.toPrimitive]() {
2965
+ return this.toString();
2966
+ }
2967
+ static toString() {
2968
+ return $$.$mol_func_name(this);
2969
+ }
2970
+ static make(...params) {
2971
+ return new this(...params);
2972
+ }
2973
+ }
2974
+ $.$mol_error_mix = $mol_error_mix;
2927
2975
  })($ || ($ = {}));
2928
2976
 
2929
2977
  ;
2930
2978
  "use strict";
2931
2979
  var $;
2932
2980
  (function ($) {
2933
- function $mol_dom_render_children(el, childNodes) {
2934
- const node_set = new Set(childNodes);
2935
- let nextNode = el.firstChild;
2936
- for (let view of childNodes) {
2937
- if (view == null)
2938
- continue;
2939
- if (view instanceof $mol_dom_context.Node) {
2940
- while (true) {
2941
- if (!nextNode) {
2942
- el.appendChild(view);
2943
- break;
2944
- }
2945
- if (nextNode == view) {
2946
- nextNode = nextNode.nextSibling;
2947
- break;
2948
- }
2949
- else {
2950
- if (node_set.has(nextNode)) {
2951
- el.insertBefore(view, nextNode);
2952
- break;
2953
- }
2954
- else {
2955
- const nn = nextNode.nextSibling;
2956
- el.removeChild(nextNode);
2957
- nextNode = nn;
2958
- }
2959
- }
2960
- }
2981
+ $mol_test({
2982
+ 'auto name'() {
2983
+ class Invalid extends $mol_error_mix {
2961
2984
  }
2962
- else {
2963
- if (nextNode && nextNode.nodeName === '#text') {
2964
- const str = String(view);
2965
- if (nextNode.nodeValue !== str)
2966
- nextNode.nodeValue = str;
2967
- nextNode = nextNode.nextSibling;
2968
- }
2969
- else {
2970
- const textNode = $mol_dom_context.document.createTextNode(String(view));
2971
- el.insertBefore(textNode, nextNode);
2985
+ const mix = new Invalid('foo');
2986
+ $mol_assert_equal(mix.name, 'Invalid_Error');
2987
+ },
2988
+ 'simpe mix'() {
2989
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
2990
+ $mol_assert_equal(mix.message, 'foo');
2991
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
2992
+ },
2993
+ 'provide additional info'() {
2994
+ class Invalid extends $mol_error_mix {
2995
+ }
2996
+ 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' }));
2997
+ const hints = [];
2998
+ if (mix instanceof $mol_error_mix) {
2999
+ for (const er of mix.errors) {
3000
+ if (er instanceof Invalid) {
3001
+ hints.push(er.cause?.hint ?? '');
3002
+ }
2972
3003
  }
2973
3004
  }
2974
- }
2975
- while (nextNode) {
2976
- const currNode = nextNode;
2977
- nextNode = currNode.nextSibling;
2978
- el.removeChild(currNode);
2979
- }
2980
- }
2981
- $.$mol_dom_render_children = $mol_dom_render_children;
3005
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
3006
+ },
3007
+ });
2982
3008
  })($ || ($ = {}));
2983
3009
 
2984
3010
  ;
@@ -2996,151 +3022,525 @@ var $;
2996
3022
  ;
2997
3023
  "use strict";
2998
3024
 
3025
+ ;
3026
+ "use strict";
3027
+
3028
+ ;
3029
+ "use strict";
3030
+ var $;
3031
+ (function ($_1) {
3032
+ $mol_test({
3033
+ 'init with overload'() {
3034
+ class X extends $mol_object {
3035
+ foo() {
3036
+ return 1;
3037
+ }
3038
+ }
3039
+ var x = X.make({
3040
+ foo: () => 2,
3041
+ });
3042
+ $mol_assert_equal(x.foo(), 2);
3043
+ },
3044
+ 'Context in instance inherits from class'($) {
3045
+ const custom = $.$mol_ambient({});
3046
+ class X extends $.$mol_object {
3047
+ static $ = custom;
3048
+ }
3049
+ $mol_assert_equal(new X().$, custom);
3050
+ },
3051
+ });
3052
+ })($ || ($ = {}));
3053
+
2999
3054
  ;
3000
3055
  "use strict";
3001
3056
  var $;
3002
3057
  (function ($) {
3003
- function $mol_dom_serialize(node) {
3004
- const serializer = new $mol_dom_context.XMLSerializer;
3005
- return serializer.serializeToString(node);
3058
+ function $mol_env() {
3059
+ return {};
3006
3060
  }
3007
- $.$mol_dom_serialize = $mol_dom_serialize;
3061
+ $.$mol_env = $mol_env;
3008
3062
  })($ || ($ = {}));
3009
3063
 
3010
3064
  ;
3011
3065
  "use strict";
3012
3066
  var $;
3013
3067
  (function ($) {
3014
- $.$mol_jsx_prefix = '';
3015
- $.$mol_jsx_crumbs = '';
3016
- $.$mol_jsx_booked = null;
3017
- $.$mol_jsx_document = {
3018
- getElementById: () => null,
3019
- createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
3020
- createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
3068
+ $.$mol_env = function $mol_env() {
3069
+ return this.process.env;
3021
3070
  };
3022
- $.$mol_jsx_frag = '';
3023
- function $mol_jsx(Elem, props, ...childNodes) {
3024
- const id = props && props.id || '';
3025
- const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
3026
- const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
3027
- if (Elem && $.$mol_jsx_booked) {
3028
- if ($.$mol_jsx_booked.has(id)) {
3029
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
3071
+ })($ || ($ = {}));
3072
+
3073
+ ;
3074
+ "use strict";
3075
+ var $;
3076
+ (function ($_1) {
3077
+ $mol_test({
3078
+ 'test types'($) {
3079
+ class A {
3080
+ static a() {
3081
+ return Promise.resolve('');
3082
+ }
3083
+ static b() {
3084
+ return $mol_wire_sync(this).a();
3085
+ }
3030
3086
  }
3031
- else {
3032
- $.$mol_jsx_booked.add(id);
3087
+ },
3088
+ async 'test method from host'($) {
3089
+ let count = 0;
3090
+ class A {
3091
+ static a() {
3092
+ return $mol_wire_sync(this).b();
3093
+ }
3094
+ static b() { return Promise.resolve(++count); }
3033
3095
  }
3034
- }
3035
- let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
3036
- if ($.$mol_jsx_prefix) {
3037
- const prefix_ext = $.$mol_jsx_prefix;
3038
- const booked_ext = $.$mol_jsx_booked;
3039
- const crumbs_ext = $.$mol_jsx_crumbs;
3040
- for (const field in props) {
3041
- const func = props[field];
3042
- if (typeof func !== 'function')
3043
- continue;
3044
- const wrapper = function (...args) {
3045
- const prefix = $.$mol_jsx_prefix;
3046
- const booked = $.$mol_jsx_booked;
3047
- const crumbs = $.$mol_jsx_crumbs;
3048
- try {
3049
- $.$mol_jsx_prefix = prefix_ext;
3050
- $.$mol_jsx_booked = booked_ext;
3051
- $.$mol_jsx_crumbs = crumbs_ext;
3052
- return func.call(this, ...args);
3053
- }
3054
- finally {
3055
- $.$mol_jsx_prefix = prefix;
3056
- $.$mol_jsx_booked = booked;
3057
- $.$mol_jsx_crumbs = crumbs;
3058
- }
3059
- };
3060
- $mol_func_name_from(wrapper, func);
3061
- props[field] = wrapper;
3096
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
3097
+ },
3098
+ async 'test function'($) {
3099
+ let count = 0;
3100
+ class A {
3101
+ static a() {
3102
+ return $mol_wire_sync(this.b)();
3103
+ }
3104
+ static b() { return Promise.resolve(++count); }
3062
3105
  }
3063
- }
3064
- if (typeof Elem !== 'string') {
3065
- if ('prototype' in Elem) {
3066
- const view = node && node[String(Elem)] || new Elem;
3067
- Object.assign(view, props);
3068
- view[Symbol.toStringTag] = guid;
3069
- view.childNodes = childNodes;
3070
- if (!view.ownerDocument)
3071
- view.ownerDocument = $.$mol_jsx_document;
3072
- view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3073
- node = view.valueOf();
3074
- node[String(Elem)] = view;
3075
- return node;
3106
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
3107
+ },
3108
+ async 'test construct itself'($) {
3109
+ class A {
3110
+ static instances = [];
3111
+ static a() {
3112
+ const a = new ($mol_wire_sync(A))();
3113
+ this.instances.push(a);
3114
+ $mol_wire_sync(this).b();
3115
+ }
3116
+ static b() { return Promise.resolve(); }
3076
3117
  }
3077
- else {
3078
- const prefix = $.$mol_jsx_prefix;
3079
- const booked = $.$mol_jsx_booked;
3080
- const crumbs = $.$mol_jsx_crumbs;
3118
+ await $mol_wire_async(A).a();
3119
+ $mol_assert_equal(A.instances.length, 2);
3120
+ $mol_assert_equal(A.instances[0] instanceof A, true);
3121
+ $mol_assert_equal(A.instances[0], A.instances[1]);
3122
+ }
3123
+ });
3124
+ })($ || ($ = {}));
3125
+
3126
+ ;
3127
+ "use strict";
3128
+ var $;
3129
+ (function ($_1) {
3130
+ $mol_test_mocks.push($ => {
3131
+ $.$mol_log3_come = () => { };
3132
+ $.$mol_log3_done = () => { };
3133
+ $.$mol_log3_fail = () => { };
3134
+ $.$mol_log3_warn = () => { };
3135
+ $.$mol_log3_rise = () => { };
3136
+ $.$mol_log3_area = () => () => { };
3137
+ });
3138
+ })($ || ($ = {}));
3139
+
3140
+ ;
3141
+ "use strict";
3142
+ var $;
3143
+ (function ($) {
3144
+ class $mol_run_error extends $mol_error_mix {
3145
+ }
3146
+ $.$mol_run_error = $mol_run_error;
3147
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
3148
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
3149
+ class $mol_run extends $mol_object {
3150
+ static async_enabled() {
3151
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
3152
+ }
3153
+ static spawn(options) {
3154
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
3155
+ const env = options.env ?? this.$.$mol_env();
3156
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
3157
+ }
3158
+ static spawn_async({ dir, sync, timeout, command, env }) {
3159
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
3160
+ const [app, ...args] = args_raw;
3161
+ const opts = { shell: true, cwd: dir, env };
3162
+ const log_object = {
3163
+ place: `${this}.spawn()`,
3164
+ message: 'Run',
3165
+ command: args_raw.join(' '),
3166
+ dir: $node.path.relative('', dir),
3167
+ };
3168
+ if (sync) {
3169
+ this.$.$mol_log3_come({
3170
+ hint: 'Run inside fiber',
3171
+ ...log_object
3172
+ });
3173
+ let error;
3174
+ let res;
3081
3175
  try {
3082
- $.$mol_jsx_prefix = guid;
3083
- $.$mol_jsx_booked = new Set;
3084
- $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3085
- return Elem(props, ...childNodes);
3176
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
3177
+ error = res.error;
3086
3178
  }
3087
- finally {
3088
- $.$mol_jsx_prefix = prefix;
3089
- $.$mol_jsx_booked = booked;
3090
- $.$mol_jsx_crumbs = crumbs;
3179
+ catch (err) {
3180
+ error = err;
3091
3181
  }
3182
+ if (!res || error || res.status) {
3183
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
3184
+ }
3185
+ return res;
3186
+ }
3187
+ let sub;
3188
+ try {
3189
+ sub = this.$.$mol_run_spawn(app, args, {
3190
+ ...opts,
3191
+ stdio: ['pipe', 'inherit', 'inherit'],
3192
+ });
3193
+ }
3194
+ catch (error) {
3195
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
3092
3196
  }
3197
+ const pid = sub.pid ?? 0;
3198
+ this.$.$mol_log3_come({
3199
+ ...log_object,
3200
+ pid,
3201
+ });
3202
+ let timeout_kill = false;
3203
+ let timer;
3204
+ const std_data = [];
3205
+ const error_data = [];
3206
+ const add = (std_chunk, error_chunk) => {
3207
+ if (std_chunk)
3208
+ std_data.push(std_chunk);
3209
+ if (error_chunk)
3210
+ error_data.push(error_chunk);
3211
+ if (!timeout)
3212
+ return;
3213
+ clearTimeout(timer);
3214
+ timer = setTimeout(() => {
3215
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
3216
+ timeout_kill = true;
3217
+ add();
3218
+ sub.kill(signal);
3219
+ }, timeout);
3220
+ };
3221
+ add();
3222
+ sub.stdout?.on('data', data => add(data));
3223
+ sub.stderr?.on('data', data => add(undefined, data));
3224
+ const result_promise = new Promise((done, fail) => {
3225
+ const close = (error, status = null, signal = null) => {
3226
+ if (!timer && timeout)
3227
+ return;
3228
+ clearTimeout(timer);
3229
+ timer = undefined;
3230
+ const res = {
3231
+ pid,
3232
+ signal,
3233
+ get stdout() { return Buffer.concat(std_data); },
3234
+ get stderr() { return Buffer.concat(error_data); }
3235
+ };
3236
+ if (error || status || timeout_kill)
3237
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
3238
+ this.$.$mol_log3_done({
3239
+ ...log_object,
3240
+ pid,
3241
+ });
3242
+ done(res);
3243
+ };
3244
+ sub.on('disconnect', () => close(new Error('Disconnected')));
3245
+ sub.on('error', err => close(err));
3246
+ sub.on('exit', (status, signal) => close(null, status, signal));
3247
+ });
3248
+ return Object.assign(result_promise, { destructor: () => {
3249
+ clearTimeout(timer);
3250
+ sub.kill('SIGKILL');
3251
+ } });
3093
3252
  }
3094
- if (!node) {
3095
- node = Elem
3096
- ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
3097
- : $.$mol_jsx_document.createDocumentFragment();
3253
+ static error_message(res) {
3254
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
3098
3255
  }
3099
- $mol_dom_render_children(node, [].concat(...childNodes));
3100
- if (!Elem)
3101
- return node;
3102
- if (guid)
3103
- node.id = guid;
3104
- for (const key in props) {
3105
- if (key === 'id')
3106
- continue;
3107
- if (typeof props[key] === 'string') {
3108
- if (typeof node[key] === 'string')
3109
- node[key] = props[key];
3110
- node.setAttribute(key, props[key]);
3256
+ }
3257
+ $.$mol_run = $mol_run;
3258
+ })($ || ($ = {}));
3259
+
3260
+ ;
3261
+ "use strict";
3262
+ var $;
3263
+ (function ($_1) {
3264
+ $mol_test({
3265
+ async 'exec timeout auto kill child process'($) {
3266
+ let close_mock = () => { };
3267
+ const error_message = 'Run error, timeout';
3268
+ function mol_run_spawn_sync_mock() {
3269
+ return {
3270
+ output: [],
3271
+ stdout: error_message,
3272
+ stderr: '',
3273
+ status: 0,
3274
+ signal: null,
3275
+ pid: 123,
3276
+ };
3111
3277
  }
3112
- else if (props[key] &&
3113
- typeof props[key] === 'object' &&
3114
- Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
3115
- if (typeof node[key] === 'object') {
3116
- Object.assign(node[key], props[key]);
3117
- continue;
3278
+ function mol_run_spawn_mock() {
3279
+ return {
3280
+ on(name, cb) {
3281
+ if (name === 'exit')
3282
+ close_mock = cb;
3283
+ },
3284
+ kill() { close_mock(); }
3285
+ };
3286
+ }
3287
+ const context_mock = $.$mol_ambient({
3288
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
3289
+ $mol_run_spawn: mol_run_spawn_mock
3290
+ });
3291
+ class $mol_run_mock extends $mol_run {
3292
+ static get $() { return context_mock; }
3293
+ static async_enabled() {
3294
+ return true;
3118
3295
  }
3119
3296
  }
3120
- else {
3121
- node[key] = props[key];
3297
+ let message = '';
3298
+ try {
3299
+ const res = await $mol_wire_async($mol_run_mock).spawn({
3300
+ command: 'sleep 10',
3301
+ dir: '.',
3302
+ timeout: 10,
3303
+ env: { 'MOL_RUN_ASYNC': '1' }
3304
+ });
3305
+ }
3306
+ catch (e) {
3307
+ message = e.message;
3122
3308
  }
3309
+ $mol_assert_equal(message, error_message);
3123
3310
  }
3124
- if ($.$mol_jsx_crumbs)
3125
- node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
3126
- return node;
3311
+ });
3312
+ })($ || ($ = {}));
3313
+
3314
+ ;
3315
+ "use strict";
3316
+ var $;
3317
+ (function ($) {
3318
+ function $mol_exec(dir, command, ...args) {
3319
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
3127
3320
  }
3128
- $.$mol_jsx = $mol_jsx;
3321
+ $.$mol_exec = $mol_exec;
3129
3322
  })($ || ($ = {}));
3130
3323
 
3131
3324
  ;
3132
3325
  "use strict";
3133
3326
  var $;
3134
3327
  (function ($) {
3135
- $mol_test({
3136
- 'Make empty div'() {
3137
- $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
3138
- },
3139
- 'Define native field'() {
3140
- const dom = $mol_jsx("input", { value: '123' });
3141
- $mol_assert_equal(dom.outerHTML, '<input value="123">');
3142
- $mol_assert_equal(dom.value, '123');
3143
- },
3328
+ $.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
3329
+ })($ || ($ = {}));
3330
+
3331
+ ;
3332
+ "use strict";
3333
+ var $;
3334
+ (function ($) {
3335
+ $.$mol_dom = $mol_dom_context;
3336
+ })($ || ($ = {}));
3337
+
3338
+ ;
3339
+ "use strict";
3340
+ var $;
3341
+ (function ($) {
3342
+ function $mol_dom_render_children(el, childNodes) {
3343
+ const node_set = new Set(childNodes);
3344
+ let nextNode = el.firstChild;
3345
+ for (let view of childNodes) {
3346
+ if (view == null)
3347
+ continue;
3348
+ if (view instanceof $mol_dom_context.Node) {
3349
+ while (true) {
3350
+ if (!nextNode) {
3351
+ el.appendChild(view);
3352
+ break;
3353
+ }
3354
+ if (nextNode == view) {
3355
+ nextNode = nextNode.nextSibling;
3356
+ break;
3357
+ }
3358
+ else {
3359
+ if (node_set.has(nextNode)) {
3360
+ el.insertBefore(view, nextNode);
3361
+ break;
3362
+ }
3363
+ else {
3364
+ const nn = nextNode.nextSibling;
3365
+ el.removeChild(nextNode);
3366
+ nextNode = nn;
3367
+ }
3368
+ }
3369
+ }
3370
+ }
3371
+ else {
3372
+ if (nextNode && nextNode.nodeName === '#text') {
3373
+ const str = String(view);
3374
+ if (nextNode.nodeValue !== str)
3375
+ nextNode.nodeValue = str;
3376
+ nextNode = nextNode.nextSibling;
3377
+ }
3378
+ else {
3379
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
3380
+ el.insertBefore(textNode, nextNode);
3381
+ }
3382
+ }
3383
+ }
3384
+ while (nextNode) {
3385
+ const currNode = nextNode;
3386
+ nextNode = currNode.nextSibling;
3387
+ el.removeChild(currNode);
3388
+ }
3389
+ }
3390
+ $.$mol_dom_render_children = $mol_dom_render_children;
3391
+ })($ || ($ = {}));
3392
+
3393
+ ;
3394
+ "use strict";
3395
+
3396
+ ;
3397
+ "use strict";
3398
+
3399
+ ;
3400
+ "use strict";
3401
+ var $;
3402
+ (function ($) {
3403
+ function $mol_dom_serialize(node) {
3404
+ const serializer = new $mol_dom_context.XMLSerializer;
3405
+ return serializer.serializeToString(node);
3406
+ }
3407
+ $.$mol_dom_serialize = $mol_dom_serialize;
3408
+ })($ || ($ = {}));
3409
+
3410
+ ;
3411
+ "use strict";
3412
+ var $;
3413
+ (function ($) {
3414
+ $.$mol_jsx_prefix = '';
3415
+ $.$mol_jsx_crumbs = '';
3416
+ $.$mol_jsx_booked = null;
3417
+ $.$mol_jsx_document = {
3418
+ getElementById: () => null,
3419
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
3420
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
3421
+ };
3422
+ $.$mol_jsx_frag = '';
3423
+ function $mol_jsx(Elem, props, ...childNodes) {
3424
+ const id = props && props.id || '';
3425
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
3426
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
3427
+ if (Elem && $.$mol_jsx_booked) {
3428
+ if ($.$mol_jsx_booked.has(id)) {
3429
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
3430
+ }
3431
+ else {
3432
+ $.$mol_jsx_booked.add(id);
3433
+ }
3434
+ }
3435
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
3436
+ if ($.$mol_jsx_prefix) {
3437
+ const prefix_ext = $.$mol_jsx_prefix;
3438
+ const booked_ext = $.$mol_jsx_booked;
3439
+ const crumbs_ext = $.$mol_jsx_crumbs;
3440
+ for (const field in props) {
3441
+ const func = props[field];
3442
+ if (typeof func !== 'function')
3443
+ continue;
3444
+ const wrapper = function (...args) {
3445
+ const prefix = $.$mol_jsx_prefix;
3446
+ const booked = $.$mol_jsx_booked;
3447
+ const crumbs = $.$mol_jsx_crumbs;
3448
+ try {
3449
+ $.$mol_jsx_prefix = prefix_ext;
3450
+ $.$mol_jsx_booked = booked_ext;
3451
+ $.$mol_jsx_crumbs = crumbs_ext;
3452
+ return func.call(this, ...args);
3453
+ }
3454
+ finally {
3455
+ $.$mol_jsx_prefix = prefix;
3456
+ $.$mol_jsx_booked = booked;
3457
+ $.$mol_jsx_crumbs = crumbs;
3458
+ }
3459
+ };
3460
+ $mol_func_name_from(wrapper, func);
3461
+ props[field] = wrapper;
3462
+ }
3463
+ }
3464
+ if (typeof Elem !== 'string') {
3465
+ if ('prototype' in Elem) {
3466
+ const view = node && node[String(Elem)] || new Elem;
3467
+ Object.assign(view, props);
3468
+ view[Symbol.toStringTag] = guid;
3469
+ view.childNodes = childNodes;
3470
+ if (!view.ownerDocument)
3471
+ view.ownerDocument = $.$mol_jsx_document;
3472
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3473
+ node = view.valueOf();
3474
+ node[String(Elem)] = view;
3475
+ return node;
3476
+ }
3477
+ else {
3478
+ const prefix = $.$mol_jsx_prefix;
3479
+ const booked = $.$mol_jsx_booked;
3480
+ const crumbs = $.$mol_jsx_crumbs;
3481
+ try {
3482
+ $.$mol_jsx_prefix = guid;
3483
+ $.$mol_jsx_booked = new Set;
3484
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3485
+ return Elem(props, ...childNodes);
3486
+ }
3487
+ finally {
3488
+ $.$mol_jsx_prefix = prefix;
3489
+ $.$mol_jsx_booked = booked;
3490
+ $.$mol_jsx_crumbs = crumbs;
3491
+ }
3492
+ }
3493
+ }
3494
+ if (!node) {
3495
+ node = Elem
3496
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
3497
+ : $.$mol_jsx_document.createDocumentFragment();
3498
+ }
3499
+ $mol_dom_render_children(node, [].concat(...childNodes));
3500
+ if (!Elem)
3501
+ return node;
3502
+ if (guid)
3503
+ node.id = guid;
3504
+ for (const key in props) {
3505
+ if (key === 'id')
3506
+ continue;
3507
+ if (typeof props[key] === 'string') {
3508
+ if (typeof node[key] === 'string')
3509
+ node[key] = props[key];
3510
+ node.setAttribute(key, props[key]);
3511
+ }
3512
+ else if (props[key] &&
3513
+ typeof props[key] === 'object' &&
3514
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
3515
+ if (typeof node[key] === 'object') {
3516
+ Object.assign(node[key], props[key]);
3517
+ continue;
3518
+ }
3519
+ }
3520
+ else {
3521
+ node[key] = props[key];
3522
+ }
3523
+ }
3524
+ if ($.$mol_jsx_crumbs)
3525
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
3526
+ return node;
3527
+ }
3528
+ $.$mol_jsx = $mol_jsx;
3529
+ })($ || ($ = {}));
3530
+
3531
+ ;
3532
+ "use strict";
3533
+ var $;
3534
+ (function ($) {
3535
+ $mol_test({
3536
+ 'Make empty div'() {
3537
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
3538
+ },
3539
+ 'Define native field'() {
3540
+ const dom = $mol_jsx("input", { value: '123' });
3541
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
3542
+ $mol_assert_equal(dom.value, '123');
3543
+ },
3144
3544
  'Define classes'() {
3145
3545
  const dom = $mol_jsx("div", { class: 'foo bar' });
3146
3546
  $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
@@ -3749,43 +4149,6 @@ var $;
3749
4149
  });
3750
4150
  })($ || ($ = {}));
3751
4151
 
3752
- ;
3753
- "use strict";
3754
- var $;
3755
- (function ($_1) {
3756
- $mol_test_mocks.push($ => {
3757
- $.$mol_log3_come = () => { };
3758
- $.$mol_log3_done = () => { };
3759
- $.$mol_log3_fail = () => { };
3760
- $.$mol_log3_warn = () => { };
3761
- $.$mol_log3_rise = () => { };
3762
- $.$mol_log3_area = () => () => { };
3763
- });
3764
- })($ || ($ = {}));
3765
-
3766
- ;
3767
- "use strict";
3768
-
3769
- ;
3770
- "use strict";
3771
-
3772
- ;
3773
- "use strict";
3774
-
3775
- ;
3776
- "use strict";
3777
- var $;
3778
- (function ($_1) {
3779
- $mol_test({
3780
- 'FQN of anon function'($) {
3781
- const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
3782
- $mol_assert_equal($$.$mol_func_name_test.name, '');
3783
- $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
3784
- $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
3785
- },
3786
- });
3787
- })($ || ($ = {}));
3788
-
3789
4152
  ;
3790
4153
  "use strict";
3791
4154
  var $;
@@ -4384,112 +4747,6 @@ var $;
4384
4747
  ;
4385
4748
  "use strict";
4386
4749
 
4387
- ;
4388
- "use strict";
4389
- var $;
4390
- (function ($_1) {
4391
- $mol_test({
4392
- 'test types'($) {
4393
- class A {
4394
- static a() {
4395
- return '';
4396
- }
4397
- static b() {
4398
- return $mol_wire_async(this).a();
4399
- }
4400
- }
4401
- },
4402
- async 'Latest method calls wins'($) {
4403
- class NameLogger extends $mol_object2 {
4404
- static $ = $;
4405
- static first = [];
4406
- static last = [];
4407
- static send(next) {
4408
- $mol_wire_sync(this.first).push(next);
4409
- $$.$mol_wait_timeout(0);
4410
- this.last.push(next);
4411
- }
4412
- }
4413
- const name = $mol_wire_async(NameLogger).send;
4414
- name('john');
4415
- const promise = name('jin');
4416
- $.$mol_after_mock_warp();
4417
- await promise;
4418
- $mol_assert_equal(NameLogger.first, ['john', 'jin']);
4419
- $mol_assert_equal(NameLogger.last, ['jin']);
4420
- },
4421
- async 'Latest function calls wins'($) {
4422
- const first = [];
4423
- const last = [];
4424
- function send_name(next) {
4425
- $mol_wire_sync(first).push(next);
4426
- $$.$mol_wait_timeout(0);
4427
- last.push(next);
4428
- }
4429
- const name = $mol_wire_async(send_name);
4430
- name('john');
4431
- const promise = name('jin');
4432
- $.$mol_after_mock_warp();
4433
- await promise;
4434
- $mol_assert_equal(first, ['john', 'jin']);
4435
- $mol_assert_equal(last, ['jin']);
4436
- },
4437
- });
4438
- })($ || ($ = {}));
4439
-
4440
- ;
4441
- "use strict";
4442
- var $;
4443
- (function ($_1) {
4444
- $mol_test({
4445
- 'test types'($) {
4446
- class A {
4447
- static a() {
4448
- return Promise.resolve('');
4449
- }
4450
- static b() {
4451
- return $mol_wire_sync(this).a();
4452
- }
4453
- }
4454
- },
4455
- async 'test method from host'($) {
4456
- let count = 0;
4457
- class A {
4458
- static a() {
4459
- return $mol_wire_sync(this).b();
4460
- }
4461
- static b() { return Promise.resolve(++count); }
4462
- }
4463
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
4464
- },
4465
- async 'test function'($) {
4466
- let count = 0;
4467
- class A {
4468
- static a() {
4469
- return $mol_wire_sync(this.b)();
4470
- }
4471
- static b() { return Promise.resolve(++count); }
4472
- }
4473
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
4474
- },
4475
- async 'test construct itself'($) {
4476
- class A {
4477
- static instances = [];
4478
- static a() {
4479
- const a = new ($mol_wire_sync(A))();
4480
- this.instances.push(a);
4481
- $mol_wire_sync(this).b();
4482
- }
4483
- static b() { return Promise.resolve(); }
4484
- }
4485
- await $mol_wire_async(A).a();
4486
- $mol_assert_equal(A.instances.length, 2);
4487
- $mol_assert_equal(A.instances[0] instanceof A, true);
4488
- $mol_assert_equal(A.instances[0], A.instances[1]);
4489
- }
4490
- });
4491
- })($ || ($ = {}));
4492
-
4493
4750
  ;
4494
4751
  "use strict";
4495
4752
  var $;
@@ -4565,6 +4822,59 @@ var $;
4565
4822
  })($$ = $_1.$$ || ($_1.$$ = {}));
4566
4823
  })($ || ($ = {}));
4567
4824
 
4825
+ ;
4826
+ "use strict";
4827
+ var $;
4828
+ (function ($_1) {
4829
+ $mol_test({
4830
+ 'test types'($) {
4831
+ class A {
4832
+ static a() {
4833
+ return '';
4834
+ }
4835
+ static b() {
4836
+ return $mol_wire_async(this).a();
4837
+ }
4838
+ }
4839
+ },
4840
+ async 'Latest method calls wins'($) {
4841
+ class NameLogger extends $mol_object2 {
4842
+ static $ = $;
4843
+ static first = [];
4844
+ static last = [];
4845
+ static send(next) {
4846
+ $mol_wire_sync(this.first).push(next);
4847
+ $$.$mol_wait_timeout(0);
4848
+ this.last.push(next);
4849
+ }
4850
+ }
4851
+ const name = $mol_wire_async(NameLogger).send;
4852
+ name('john');
4853
+ const promise = name('jin');
4854
+ $.$mol_after_mock_warp();
4855
+ await promise;
4856
+ $mol_assert_equal(NameLogger.first, ['john', 'jin']);
4857
+ $mol_assert_equal(NameLogger.last, ['jin']);
4858
+ },
4859
+ async 'Latest function calls wins'($) {
4860
+ const first = [];
4861
+ const last = [];
4862
+ function send_name(next) {
4863
+ $mol_wire_sync(first).push(next);
4864
+ $$.$mol_wait_timeout(0);
4865
+ last.push(next);
4866
+ }
4867
+ const name = $mol_wire_async(send_name);
4868
+ name('john');
4869
+ const promise = name('jin');
4870
+ $.$mol_after_mock_warp();
4871
+ await promise;
4872
+ $mol_assert_equal(first, ['john', 'jin']);
4873
+ $mol_assert_equal(last, ['jin']);
4874
+ },
4875
+ });
4876
+ })($ || ($ = {}));
4877
+
4568
4878
  ;
4569
4879
  "use strict";
4570
4880
  var $;
@@ -5229,32 +5539,6 @@ var $;
5229
5539
  });
5230
5540
  })($ || ($ = {}));
5231
5541
 
5232
- ;
5233
- "use strict";
5234
- var $;
5235
- (function ($_1) {
5236
- $mol_test({
5237
- 'init with overload'() {
5238
- class X extends $mol_object {
5239
- foo() {
5240
- return 1;
5241
- }
5242
- }
5243
- var x = X.make({
5244
- foo: () => 2,
5245
- });
5246
- $mol_assert_equal(x.foo(), 2);
5247
- },
5248
- 'Context in instance inherits from class'($) {
5249
- const custom = $.$mol_ambient({});
5250
- class X extends $.$mol_object {
5251
- static $ = custom;
5252
- }
5253
- $mol_assert_equal(new X().$, custom);
5254
- },
5255
- });
5256
- })($ || ($ = {}));
5257
-
5258
5542
  ;
5259
5543
  "use strict";
5260
5544
 
@@ -5583,290 +5867,5 @@ var $;
5583
5867
  });
5584
5868
  })($ || ($ = {}));
5585
5869
 
5586
- ;
5587
- "use strict";
5588
- var $;
5589
- (function ($) {
5590
- function cause_serialize(cause) {
5591
- return JSON.stringify(cause, null, ' ')
5592
- .replace(/\(/, '<')
5593
- .replace(/\)/, ' >');
5594
- }
5595
- function frame_normalize(frame) {
5596
- return (typeof frame === 'string' ? frame : cause_serialize(frame))
5597
- .trim()
5598
- .replace(/at /gm, ' at ')
5599
- .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
5600
- }
5601
- class $mol_error_mix extends AggregateError {
5602
- cause;
5603
- name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
5604
- constructor(message, cause = {}, ...errors) {
5605
- super(errors, message, { cause });
5606
- this.cause = cause;
5607
- const desc = Object.getOwnPropertyDescriptor(this, 'stack');
5608
- const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
5609
- Object.defineProperty(this, 'stack', {
5610
- get: () => stack_get() + '\n' + [
5611
- this.cause ?? 'no cause',
5612
- ...this.errors.flatMap(e => [
5613
- String(e.stack),
5614
- ...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
5615
- ])
5616
- ].map(frame_normalize).join('\n')
5617
- });
5618
- Object.defineProperty(this, 'cause', {
5619
- get: () => cause
5620
- });
5621
- }
5622
- static [Symbol.toPrimitive]() {
5623
- return this.toString();
5624
- }
5625
- static toString() {
5626
- return $$.$mol_func_name(this);
5627
- }
5628
- static make(...params) {
5629
- return new this(...params);
5630
- }
5631
- }
5632
- $.$mol_error_mix = $mol_error_mix;
5633
- })($ || ($ = {}));
5634
-
5635
- ;
5636
- "use strict";
5637
- var $;
5638
- (function ($) {
5639
- $mol_test({
5640
- 'auto name'() {
5641
- class Invalid extends $mol_error_mix {
5642
- }
5643
- const mix = new Invalid('foo');
5644
- $mol_assert_equal(mix.name, 'Invalid_Error');
5645
- },
5646
- 'simpe mix'() {
5647
- const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
5648
- $mol_assert_equal(mix.message, 'foo');
5649
- $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
5650
- },
5651
- 'provide additional info'() {
5652
- class Invalid extends $mol_error_mix {
5653
- }
5654
- 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' }));
5655
- const hints = [];
5656
- if (mix instanceof $mol_error_mix) {
5657
- for (const er of mix.errors) {
5658
- if (er instanceof Invalid) {
5659
- hints.push(er.cause?.hint ?? '');
5660
- }
5661
- }
5662
- }
5663
- $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
5664
- },
5665
- });
5666
- })($ || ($ = {}));
5667
-
5668
- ;
5669
- "use strict";
5670
- var $;
5671
- (function ($) {
5672
- function $mol_env() {
5673
- return {};
5674
- }
5675
- $.$mol_env = $mol_env;
5676
- })($ || ($ = {}));
5677
-
5678
- ;
5679
- "use strict";
5680
- var $;
5681
- (function ($) {
5682
- $.$mol_env = function $mol_env() {
5683
- return this.process.env;
5684
- };
5685
- })($ || ($ = {}));
5686
-
5687
- ;
5688
- "use strict";
5689
- var $;
5690
- (function ($) {
5691
- class $mol_run_error extends $mol_error_mix {
5692
- }
5693
- $.$mol_run_error = $mol_run_error;
5694
- $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
5695
- $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
5696
- class $mol_run extends $mol_object {
5697
- static async_enabled() {
5698
- return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
5699
- }
5700
- static spawn(options) {
5701
- const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
5702
- const env = options.env ?? this.$.$mol_env();
5703
- return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
5704
- }
5705
- static spawn_async({ dir, sync, timeout, command, env }) {
5706
- const args_raw = typeof command === 'string' ? command.split(' ') : command;
5707
- const [app, ...args] = args_raw;
5708
- const opts = { shell: true, cwd: dir, env };
5709
- const log_object = {
5710
- place: `${this}.spawn()`,
5711
- message: 'Run',
5712
- command: args_raw.join(' '),
5713
- dir: $node.path.relative('', dir),
5714
- };
5715
- if (sync) {
5716
- this.$.$mol_log3_come({
5717
- hint: 'Run inside fiber',
5718
- ...log_object
5719
- });
5720
- let error;
5721
- let res;
5722
- try {
5723
- res = this.$.$mol_run_spawn_sync(app, args, opts);
5724
- error = res.error;
5725
- }
5726
- catch (err) {
5727
- error = err;
5728
- }
5729
- if (!res || error || res.status) {
5730
- throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
5731
- }
5732
- return res;
5733
- }
5734
- let sub;
5735
- try {
5736
- sub = this.$.$mol_run_spawn(app, args, {
5737
- ...opts,
5738
- stdio: ['pipe', 'inherit', 'inherit'],
5739
- });
5740
- }
5741
- catch (error) {
5742
- throw new $mol_run_error(this.error_message(undefined), log_object, error);
5743
- }
5744
- const pid = sub.pid ?? 0;
5745
- this.$.$mol_log3_come({
5746
- ...log_object,
5747
- pid,
5748
- });
5749
- let timeout_kill = false;
5750
- let timer;
5751
- const std_data = [];
5752
- const error_data = [];
5753
- const add = (std_chunk, error_chunk) => {
5754
- if (std_chunk)
5755
- std_data.push(std_chunk);
5756
- if (error_chunk)
5757
- error_data.push(error_chunk);
5758
- if (!timeout)
5759
- return;
5760
- clearTimeout(timer);
5761
- timer = setTimeout(() => {
5762
- const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
5763
- timeout_kill = true;
5764
- add();
5765
- sub.kill(signal);
5766
- }, timeout);
5767
- };
5768
- add();
5769
- sub.stdout?.on('data', data => add(data));
5770
- sub.stderr?.on('data', data => add(undefined, data));
5771
- const result_promise = new Promise((done, fail) => {
5772
- const close = (error, status = null, signal = null) => {
5773
- if (!timer && timeout)
5774
- return;
5775
- clearTimeout(timer);
5776
- timer = undefined;
5777
- const res = {
5778
- pid,
5779
- signal,
5780
- get stdout() { return Buffer.concat(std_data); },
5781
- get stderr() { return Buffer.concat(error_data); }
5782
- };
5783
- if (error || status || timeout_kill)
5784
- return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
5785
- this.$.$mol_log3_done({
5786
- ...log_object,
5787
- pid,
5788
- });
5789
- done(res);
5790
- };
5791
- sub.on('disconnect', () => close(new Error('Disconnected')));
5792
- sub.on('error', err => close(err));
5793
- sub.on('exit', (status, signal) => close(null, status, signal));
5794
- });
5795
- return Object.assign(result_promise, { destructor: () => {
5796
- clearTimeout(timer);
5797
- sub.kill('SIGKILL');
5798
- } });
5799
- }
5800
- static error_message(res) {
5801
- return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
5802
- }
5803
- }
5804
- $.$mol_run = $mol_run;
5805
- })($ || ($ = {}));
5806
-
5807
- ;
5808
- "use strict";
5809
- var $;
5810
- (function ($_1) {
5811
- $mol_test({
5812
- async 'exec timeout auto kill child process'($) {
5813
- let close_mock = () => { };
5814
- const error_message = 'Run error, timeout';
5815
- function mol_run_spawn_sync_mock() {
5816
- return {
5817
- output: [],
5818
- stdout: error_message,
5819
- stderr: '',
5820
- status: 0,
5821
- signal: null,
5822
- pid: 123,
5823
- };
5824
- }
5825
- function mol_run_spawn_mock() {
5826
- return {
5827
- on(name, cb) {
5828
- if (name === 'exit')
5829
- close_mock = cb;
5830
- },
5831
- kill() { close_mock(); }
5832
- };
5833
- }
5834
- const context_mock = $.$mol_ambient({
5835
- $mol_run_spawn_sync: mol_run_spawn_sync_mock,
5836
- $mol_run_spawn: mol_run_spawn_mock
5837
- });
5838
- class $mol_run_mock extends $mol_run {
5839
- static get $() { return context_mock; }
5840
- static async_enabled() {
5841
- return true;
5842
- }
5843
- }
5844
- let message = '';
5845
- try {
5846
- const res = await $mol_wire_async($mol_run_mock).spawn({
5847
- command: 'sleep 10',
5848
- dir: '.',
5849
- timeout: 10,
5850
- env: { 'MOL_RUN_ASYNC': '1' }
5851
- });
5852
- }
5853
- catch (e) {
5854
- message = e.message;
5855
- }
5856
- $mol_assert_equal(message, error_message);
5857
- }
5858
- });
5859
- })($ || ($ = {}));
5860
-
5861
- ;
5862
- "use strict";
5863
- var $;
5864
- (function ($) {
5865
- function $mol_exec(dir, command, ...args) {
5866
- return this.$mol_run.spawn({ command: [command, ...args], dir });
5867
- }
5868
- $.$mol_exec = $mol_exec;
5869
- })($ || ($ = {}));
5870
-
5871
5870
 
5872
5871
  //# sourceMappingURL=node.test.js.map