mol_wire_lib 1.0.1631 → 1.0.1633
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 +616 -622
- package/node.test.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
}
|
|
@@ -2915,70 +2909,97 @@ require = (req => Object.assign(function require(name) {
|
|
|
2915
2909
|
;
|
|
2916
2910
|
"use strict";
|
|
2917
2911
|
var $;
|
|
2918
|
-
(function ($) {
|
|
2919
|
-
|
|
2912
|
+
(function ($_1) {
|
|
2913
|
+
$mol_test({
|
|
2914
|
+
'FQN of anon function'($) {
|
|
2915
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
2916
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
2917
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
2918
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
2919
|
+
},
|
|
2920
|
+
});
|
|
2920
2921
|
})($ || ($ = {}));
|
|
2921
2922
|
|
|
2922
2923
|
;
|
|
2923
2924
|
"use strict";
|
|
2924
2925
|
var $;
|
|
2925
2926
|
(function ($) {
|
|
2926
|
-
|
|
2927
|
+
function cause_serialize(cause) {
|
|
2928
|
+
return JSON.stringify(cause, null, ' ')
|
|
2929
|
+
.replace(/\(/, '<')
|
|
2930
|
+
.replace(/\)/, ' >');
|
|
2931
|
+
}
|
|
2932
|
+
function frame_normalize(frame) {
|
|
2933
|
+
return (typeof frame === 'string' ? frame : cause_serialize(frame))
|
|
2934
|
+
.trim()
|
|
2935
|
+
.replace(/at /gm, ' at ')
|
|
2936
|
+
.replace(/^(?! +at )(.*)/gm, ' at | $1 (#)');
|
|
2937
|
+
}
|
|
2938
|
+
class $mol_error_mix extends AggregateError {
|
|
2939
|
+
cause;
|
|
2940
|
+
name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
|
|
2941
|
+
constructor(message, cause = {}, ...errors) {
|
|
2942
|
+
super(errors, message, { cause });
|
|
2943
|
+
this.cause = cause;
|
|
2944
|
+
const desc = Object.getOwnPropertyDescriptor(this, 'stack');
|
|
2945
|
+
const stack_get = () => desc?.get?.() ?? super.stack ?? desc?.value ?? this.message;
|
|
2946
|
+
Object.defineProperty(this, 'stack', {
|
|
2947
|
+
get: () => stack_get() + '\n' + [
|
|
2948
|
+
this.cause ?? 'no cause',
|
|
2949
|
+
...this.errors.flatMap(e => [
|
|
2950
|
+
String(e.stack),
|
|
2951
|
+
...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
|
|
2952
|
+
])
|
|
2953
|
+
].map(frame_normalize).join('\n')
|
|
2954
|
+
});
|
|
2955
|
+
Object.defineProperty(this, 'cause', {
|
|
2956
|
+
get: () => cause
|
|
2957
|
+
});
|
|
2958
|
+
}
|
|
2959
|
+
static [Symbol.toPrimitive]() {
|
|
2960
|
+
return this.toString();
|
|
2961
|
+
}
|
|
2962
|
+
static toString() {
|
|
2963
|
+
return $$.$mol_func_name(this);
|
|
2964
|
+
}
|
|
2965
|
+
static make(...params) {
|
|
2966
|
+
return new this(...params);
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
$.$mol_error_mix = $mol_error_mix;
|
|
2927
2970
|
})($ || ($ = {}));
|
|
2928
2971
|
|
|
2929
2972
|
;
|
|
2930
2973
|
"use strict";
|
|
2931
2974
|
var $;
|
|
2932
2975
|
(function ($) {
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
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
|
-
}
|
|
2976
|
+
$mol_test({
|
|
2977
|
+
'auto name'() {
|
|
2978
|
+
class Invalid extends $mol_error_mix {
|
|
2961
2979
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2980
|
+
const mix = new Invalid('foo');
|
|
2981
|
+
$mol_assert_equal(mix.name, 'Invalid_Error');
|
|
2982
|
+
},
|
|
2983
|
+
'simpe mix'() {
|
|
2984
|
+
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
|
2985
|
+
$mol_assert_equal(mix.message, 'foo');
|
|
2986
|
+
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
|
2987
|
+
},
|
|
2988
|
+
'provide additional info'() {
|
|
2989
|
+
class Invalid extends $mol_error_mix {
|
|
2990
|
+
}
|
|
2991
|
+
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' }));
|
|
2992
|
+
const hints = [];
|
|
2993
|
+
if (mix instanceof $mol_error_mix) {
|
|
2994
|
+
for (const er of mix.errors) {
|
|
2995
|
+
if (er instanceof Invalid) {
|
|
2996
|
+
hints.push(er.cause?.hint ?? '');
|
|
2997
|
+
}
|
|
2972
2998
|
}
|
|
2973
2999
|
}
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
nextNode = currNode.nextSibling;
|
|
2978
|
-
el.removeChild(currNode);
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
|
-
$.$mol_dom_render_children = $mol_dom_render_children;
|
|
3000
|
+
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
|
3001
|
+
},
|
|
3002
|
+
});
|
|
2982
3003
|
})($ || ($ = {}));
|
|
2983
3004
|
|
|
2984
3005
|
;
|
|
@@ -2996,152 +3017,526 @@ var $;
|
|
|
2996
3017
|
;
|
|
2997
3018
|
"use strict";
|
|
2998
3019
|
|
|
3020
|
+
;
|
|
3021
|
+
"use strict";
|
|
3022
|
+
|
|
3023
|
+
;
|
|
3024
|
+
"use strict";
|
|
3025
|
+
var $;
|
|
3026
|
+
(function ($_1) {
|
|
3027
|
+
$mol_test({
|
|
3028
|
+
'init with overload'() {
|
|
3029
|
+
class X extends $mol_object {
|
|
3030
|
+
foo() {
|
|
3031
|
+
return 1;
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
var x = X.make({
|
|
3035
|
+
foo: () => 2,
|
|
3036
|
+
});
|
|
3037
|
+
$mol_assert_equal(x.foo(), 2);
|
|
3038
|
+
},
|
|
3039
|
+
'Context in instance inherits from class'($) {
|
|
3040
|
+
const custom = $.$mol_ambient({});
|
|
3041
|
+
class X extends $.$mol_object {
|
|
3042
|
+
static $ = custom;
|
|
3043
|
+
}
|
|
3044
|
+
$mol_assert_equal(new X().$, custom);
|
|
3045
|
+
},
|
|
3046
|
+
});
|
|
3047
|
+
})($ || ($ = {}));
|
|
3048
|
+
|
|
2999
3049
|
;
|
|
3000
3050
|
"use strict";
|
|
3001
3051
|
var $;
|
|
3002
3052
|
(function ($) {
|
|
3003
|
-
function $
|
|
3004
|
-
|
|
3005
|
-
return serializer.serializeToString(node);
|
|
3053
|
+
function $mol_env() {
|
|
3054
|
+
return {};
|
|
3006
3055
|
}
|
|
3007
|
-
$.$
|
|
3056
|
+
$.$mol_env = $mol_env;
|
|
3008
3057
|
})($ || ($ = {}));
|
|
3009
3058
|
|
|
3010
3059
|
;
|
|
3011
3060
|
"use strict";
|
|
3012
3061
|
var $;
|
|
3013
3062
|
(function ($) {
|
|
3014
|
-
$.$
|
|
3015
|
-
|
|
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(),
|
|
3063
|
+
$.$mol_env = function $mol_env() {
|
|
3064
|
+
return this.process.env;
|
|
3021
3065
|
};
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3066
|
+
})($ || ($ = {}));
|
|
3067
|
+
|
|
3068
|
+
;
|
|
3069
|
+
"use strict";
|
|
3070
|
+
var $;
|
|
3071
|
+
(function ($_1) {
|
|
3072
|
+
$mol_test({
|
|
3073
|
+
'test types'($) {
|
|
3074
|
+
class A {
|
|
3075
|
+
static a() {
|
|
3076
|
+
return Promise.resolve('');
|
|
3077
|
+
}
|
|
3078
|
+
static b() {
|
|
3079
|
+
return $mol_wire_sync(this).a();
|
|
3080
|
+
}
|
|
3030
3081
|
}
|
|
3031
|
-
|
|
3032
|
-
|
|
3082
|
+
},
|
|
3083
|
+
async 'test method from host'($) {
|
|
3084
|
+
let count = 0;
|
|
3085
|
+
class A {
|
|
3086
|
+
static a() {
|
|
3087
|
+
return $mol_wire_sync(this).b();
|
|
3088
|
+
}
|
|
3089
|
+
static b() { return Promise.resolve(++count); }
|
|
3033
3090
|
}
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
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;
|
|
3091
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
3092
|
+
},
|
|
3093
|
+
async 'test function'($) {
|
|
3094
|
+
let count = 0;
|
|
3095
|
+
class A {
|
|
3096
|
+
static a() {
|
|
3097
|
+
return $mol_wire_sync(this.b)();
|
|
3098
|
+
}
|
|
3099
|
+
static b() { return Promise.resolve(++count); }
|
|
3062
3100
|
}
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
node[String(Elem)] = view;
|
|
3075
|
-
return node;
|
|
3101
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
3102
|
+
},
|
|
3103
|
+
async 'test construct itself'($) {
|
|
3104
|
+
class A {
|
|
3105
|
+
static instances = [];
|
|
3106
|
+
static a() {
|
|
3107
|
+
const a = new ($mol_wire_sync(A))();
|
|
3108
|
+
this.instances.push(a);
|
|
3109
|
+
$mol_wire_sync(this).b();
|
|
3110
|
+
}
|
|
3111
|
+
static b() { return Promise.resolve(); }
|
|
3076
3112
|
}
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3113
|
+
await $mol_wire_async(A).a();
|
|
3114
|
+
$mol_assert_equal(A.instances.length, 2);
|
|
3115
|
+
$mol_assert_equal(A.instances[0] instanceof A, true);
|
|
3116
|
+
$mol_assert_equal(A.instances[0], A.instances[1]);
|
|
3117
|
+
}
|
|
3118
|
+
});
|
|
3119
|
+
})($ || ($ = {}));
|
|
3120
|
+
|
|
3121
|
+
;
|
|
3122
|
+
"use strict";
|
|
3123
|
+
var $;
|
|
3124
|
+
(function ($_1) {
|
|
3125
|
+
$mol_test_mocks.push($ => {
|
|
3126
|
+
$.$mol_log3_come = () => { };
|
|
3127
|
+
$.$mol_log3_done = () => { };
|
|
3128
|
+
$.$mol_log3_fail = () => { };
|
|
3129
|
+
$.$mol_log3_warn = () => { };
|
|
3130
|
+
$.$mol_log3_rise = () => { };
|
|
3131
|
+
$.$mol_log3_area = () => () => { };
|
|
3132
|
+
});
|
|
3133
|
+
})($ || ($ = {}));
|
|
3134
|
+
|
|
3135
|
+
;
|
|
3136
|
+
"use strict";
|
|
3137
|
+
var $;
|
|
3138
|
+
(function ($) {
|
|
3139
|
+
class $mol_run_error extends $mol_error_mix {
|
|
3140
|
+
}
|
|
3141
|
+
$.$mol_run_error = $mol_run_error;
|
|
3142
|
+
$.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
|
|
3143
|
+
$.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
|
|
3144
|
+
class $mol_run extends $mol_object {
|
|
3145
|
+
static async_enabled() {
|
|
3146
|
+
return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
|
|
3147
|
+
}
|
|
3148
|
+
static spawn(options) {
|
|
3149
|
+
const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
|
|
3150
|
+
const env = options.env ?? this.$.$mol_env();
|
|
3151
|
+
return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
|
|
3152
|
+
}
|
|
3153
|
+
static spawn_async({ dir, sync, timeout, command, env }) {
|
|
3154
|
+
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
3155
|
+
const [app, ...args] = args_raw;
|
|
3156
|
+
const opts = { shell: true, cwd: dir, env };
|
|
3157
|
+
const log_object = {
|
|
3158
|
+
place: `${this}.spawn()`,
|
|
3159
|
+
message: 'Run',
|
|
3160
|
+
command: args_raw.join(' '),
|
|
3161
|
+
dir: $node.path.relative('', dir),
|
|
3162
|
+
};
|
|
3163
|
+
if (sync) {
|
|
3164
|
+
this.$.$mol_log3_come({
|
|
3165
|
+
hint: 'Run inside fiber',
|
|
3166
|
+
...log_object
|
|
3167
|
+
});
|
|
3168
|
+
let error;
|
|
3169
|
+
let res;
|
|
3081
3170
|
try {
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
3085
|
-
return Elem(props, ...childNodes);
|
|
3171
|
+
res = this.$.$mol_run_spawn_sync(app, args, opts);
|
|
3172
|
+
error = res.error;
|
|
3086
3173
|
}
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3174
|
+
catch (err) {
|
|
3175
|
+
error = err;
|
|
3176
|
+
}
|
|
3177
|
+
if (!res || error || res.status) {
|
|
3178
|
+
throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
|
|
3091
3179
|
}
|
|
3180
|
+
return res;
|
|
3181
|
+
}
|
|
3182
|
+
let sub;
|
|
3183
|
+
try {
|
|
3184
|
+
sub = this.$.$mol_run_spawn(app, args, {
|
|
3185
|
+
...opts,
|
|
3186
|
+
stdio: ['pipe', 'inherit', 'inherit'],
|
|
3187
|
+
});
|
|
3188
|
+
}
|
|
3189
|
+
catch (error) {
|
|
3190
|
+
throw new $mol_run_error(this.error_message(undefined), log_object, error);
|
|
3092
3191
|
}
|
|
3192
|
+
const pid = sub.pid ?? 0;
|
|
3193
|
+
this.$.$mol_log3_come({
|
|
3194
|
+
...log_object,
|
|
3195
|
+
pid,
|
|
3196
|
+
});
|
|
3197
|
+
let timeout_kill = false;
|
|
3198
|
+
let timer;
|
|
3199
|
+
const std_data = [];
|
|
3200
|
+
const error_data = [];
|
|
3201
|
+
const add = (std_chunk, error_chunk) => {
|
|
3202
|
+
if (std_chunk)
|
|
3203
|
+
std_data.push(std_chunk);
|
|
3204
|
+
if (error_chunk)
|
|
3205
|
+
error_data.push(error_chunk);
|
|
3206
|
+
if (!timeout)
|
|
3207
|
+
return;
|
|
3208
|
+
clearTimeout(timer);
|
|
3209
|
+
timer = setTimeout(() => {
|
|
3210
|
+
const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
|
|
3211
|
+
timeout_kill = true;
|
|
3212
|
+
add();
|
|
3213
|
+
sub.kill(signal);
|
|
3214
|
+
}, timeout);
|
|
3215
|
+
};
|
|
3216
|
+
add();
|
|
3217
|
+
sub.stdout?.on('data', data => add(data));
|
|
3218
|
+
sub.stderr?.on('data', data => add(undefined, data));
|
|
3219
|
+
const result_promise = new Promise((done, fail) => {
|
|
3220
|
+
const close = (error, status = null, signal = null) => {
|
|
3221
|
+
if (!timer && timeout)
|
|
3222
|
+
return;
|
|
3223
|
+
clearTimeout(timer);
|
|
3224
|
+
timer = undefined;
|
|
3225
|
+
const res = {
|
|
3226
|
+
pid,
|
|
3227
|
+
signal,
|
|
3228
|
+
get stdout() { return Buffer.concat(std_data); },
|
|
3229
|
+
get stderr() { return Buffer.concat(error_data); }
|
|
3230
|
+
};
|
|
3231
|
+
if (error || status || timeout_kill)
|
|
3232
|
+
return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
|
|
3233
|
+
this.$.$mol_log3_done({
|
|
3234
|
+
...log_object,
|
|
3235
|
+
pid,
|
|
3236
|
+
});
|
|
3237
|
+
done(res);
|
|
3238
|
+
};
|
|
3239
|
+
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
3240
|
+
sub.on('error', err => close(err));
|
|
3241
|
+
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
3242
|
+
});
|
|
3243
|
+
return Object.assign(result_promise, { destructor: () => {
|
|
3244
|
+
clearTimeout(timer);
|
|
3245
|
+
sub.kill('SIGKILL');
|
|
3246
|
+
} });
|
|
3093
3247
|
}
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
|
|
3097
|
-
: $.$mol_jsx_document.createDocumentFragment();
|
|
3248
|
+
static error_message(res) {
|
|
3249
|
+
return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
|
|
3098
3250
|
}
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3251
|
+
}
|
|
3252
|
+
$.$mol_run = $mol_run;
|
|
3253
|
+
})($ || ($ = {}));
|
|
3254
|
+
|
|
3255
|
+
;
|
|
3256
|
+
"use strict";
|
|
3257
|
+
var $;
|
|
3258
|
+
(function ($_1) {
|
|
3259
|
+
$mol_test({
|
|
3260
|
+
async 'exec timeout auto kill child process'($) {
|
|
3261
|
+
let close_mock = () => { };
|
|
3262
|
+
const error_message = 'Run error, timeout';
|
|
3263
|
+
function mol_run_spawn_sync_mock() {
|
|
3264
|
+
return {
|
|
3265
|
+
output: [],
|
|
3266
|
+
stdout: error_message,
|
|
3267
|
+
stderr: '',
|
|
3268
|
+
status: 0,
|
|
3269
|
+
signal: null,
|
|
3270
|
+
pid: 123,
|
|
3271
|
+
};
|
|
3111
3272
|
}
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3273
|
+
function mol_run_spawn_mock() {
|
|
3274
|
+
return {
|
|
3275
|
+
on(name, cb) {
|
|
3276
|
+
if (name === 'exit')
|
|
3277
|
+
close_mock = cb;
|
|
3278
|
+
},
|
|
3279
|
+
kill() { close_mock(); }
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
const context_mock = $.$mol_ambient({
|
|
3283
|
+
$mol_run_spawn_sync: mol_run_spawn_sync_mock,
|
|
3284
|
+
$mol_run_spawn: mol_run_spawn_mock
|
|
3285
|
+
});
|
|
3286
|
+
class $mol_run_mock extends $mol_run {
|
|
3287
|
+
static get $() { return context_mock; }
|
|
3288
|
+
static async_enabled() {
|
|
3289
|
+
return true;
|
|
3118
3290
|
}
|
|
3119
3291
|
}
|
|
3120
|
-
|
|
3121
|
-
|
|
3292
|
+
let message = '';
|
|
3293
|
+
try {
|
|
3294
|
+
const res = await $mol_wire_async($mol_run_mock).spawn({
|
|
3295
|
+
command: 'sleep 10',
|
|
3296
|
+
dir: '.',
|
|
3297
|
+
timeout: 10,
|
|
3298
|
+
env: { 'MOL_RUN_ASYNC': '1' }
|
|
3299
|
+
});
|
|
3122
3300
|
}
|
|
3301
|
+
catch (e) {
|
|
3302
|
+
message = e.message;
|
|
3303
|
+
}
|
|
3304
|
+
$mol_assert_equal(message, error_message);
|
|
3123
3305
|
}
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3306
|
+
});
|
|
3307
|
+
})($ || ($ = {}));
|
|
3308
|
+
|
|
3309
|
+
;
|
|
3310
|
+
"use strict";
|
|
3311
|
+
var $;
|
|
3312
|
+
(function ($) {
|
|
3313
|
+
function $mol_exec(dir, command, ...args) {
|
|
3314
|
+
return this.$mol_run.spawn({ command: [command, ...args], dir });
|
|
3127
3315
|
}
|
|
3128
|
-
$.$
|
|
3316
|
+
$.$mol_exec = $mol_exec;
|
|
3129
3317
|
})($ || ($ = {}));
|
|
3130
3318
|
|
|
3131
3319
|
;
|
|
3132
3320
|
"use strict";
|
|
3133
3321
|
var $;
|
|
3134
3322
|
(function ($) {
|
|
3135
|
-
$
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3323
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
|
3324
|
+
})($ || ($ = {}));
|
|
3325
|
+
|
|
3326
|
+
;
|
|
3327
|
+
"use strict";
|
|
3328
|
+
var $;
|
|
3329
|
+
(function ($) {
|
|
3330
|
+
$.$mol_dom = $mol_dom_context;
|
|
3331
|
+
})($ || ($ = {}));
|
|
3332
|
+
|
|
3333
|
+
;
|
|
3334
|
+
"use strict";
|
|
3335
|
+
var $;
|
|
3336
|
+
(function ($) {
|
|
3337
|
+
function $mol_dom_render_children(el, childNodes) {
|
|
3338
|
+
const node_set = new Set(childNodes);
|
|
3339
|
+
let nextNode = el.firstChild;
|
|
3340
|
+
for (let view of childNodes) {
|
|
3341
|
+
if (view == null)
|
|
3342
|
+
continue;
|
|
3343
|
+
if (view instanceof $mol_dom_context.Node) {
|
|
3344
|
+
while (true) {
|
|
3345
|
+
if (!nextNode) {
|
|
3346
|
+
el.appendChild(view);
|
|
3347
|
+
break;
|
|
3348
|
+
}
|
|
3349
|
+
if (nextNode == view) {
|
|
3350
|
+
nextNode = nextNode.nextSibling;
|
|
3351
|
+
break;
|
|
3352
|
+
}
|
|
3353
|
+
else {
|
|
3354
|
+
if (node_set.has(nextNode)) {
|
|
3355
|
+
el.insertBefore(view, nextNode);
|
|
3356
|
+
break;
|
|
3357
|
+
}
|
|
3358
|
+
else {
|
|
3359
|
+
const nn = nextNode.nextSibling;
|
|
3360
|
+
el.removeChild(nextNode);
|
|
3361
|
+
nextNode = nn;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
else {
|
|
3367
|
+
if (nextNode && nextNode.nodeName === '#text') {
|
|
3368
|
+
const str = String(view);
|
|
3369
|
+
if (nextNode.nodeValue !== str)
|
|
3370
|
+
nextNode.nodeValue = str;
|
|
3371
|
+
nextNode = nextNode.nextSibling;
|
|
3372
|
+
}
|
|
3373
|
+
else {
|
|
3374
|
+
const textNode = $mol_dom_context.document.createTextNode(String(view));
|
|
3375
|
+
el.insertBefore(textNode, nextNode);
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
while (nextNode) {
|
|
3380
|
+
const currNode = nextNode;
|
|
3381
|
+
nextNode = currNode.nextSibling;
|
|
3382
|
+
el.removeChild(currNode);
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
$.$mol_dom_render_children = $mol_dom_render_children;
|
|
3386
|
+
})($ || ($ = {}));
|
|
3387
|
+
|
|
3388
|
+
;
|
|
3389
|
+
"use strict";
|
|
3390
|
+
|
|
3391
|
+
;
|
|
3392
|
+
"use strict";
|
|
3393
|
+
|
|
3394
|
+
;
|
|
3395
|
+
"use strict";
|
|
3396
|
+
var $;
|
|
3397
|
+
(function ($) {
|
|
3398
|
+
function $mol_dom_serialize(node) {
|
|
3399
|
+
const serializer = new $mol_dom_context.XMLSerializer;
|
|
3400
|
+
return serializer.serializeToString(node);
|
|
3401
|
+
}
|
|
3402
|
+
$.$mol_dom_serialize = $mol_dom_serialize;
|
|
3403
|
+
})($ || ($ = {}));
|
|
3404
|
+
|
|
3405
|
+
;
|
|
3406
|
+
"use strict";
|
|
3407
|
+
var $;
|
|
3408
|
+
(function ($) {
|
|
3409
|
+
$.$mol_jsx_prefix = '';
|
|
3410
|
+
$.$mol_jsx_crumbs = '';
|
|
3411
|
+
$.$mol_jsx_booked = null;
|
|
3412
|
+
$.$mol_jsx_document = {
|
|
3413
|
+
getElementById: () => null,
|
|
3414
|
+
createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
|
|
3415
|
+
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
3416
|
+
};
|
|
3417
|
+
$.$mol_jsx_frag = '';
|
|
3418
|
+
function $mol_jsx(Elem, props, ...childNodes) {
|
|
3419
|
+
const id = props && props.id || '';
|
|
3420
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
3421
|
+
const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
|
|
3422
|
+
if (Elem && $.$mol_jsx_booked) {
|
|
3423
|
+
if ($.$mol_jsx_booked.has(id)) {
|
|
3424
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
3425
|
+
}
|
|
3426
|
+
else {
|
|
3427
|
+
$.$mol_jsx_booked.add(id);
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
3431
|
+
if ($.$mol_jsx_prefix) {
|
|
3432
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
3433
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
3434
|
+
const crumbs_ext = $.$mol_jsx_crumbs;
|
|
3435
|
+
for (const field in props) {
|
|
3436
|
+
const func = props[field];
|
|
3437
|
+
if (typeof func !== 'function')
|
|
3438
|
+
continue;
|
|
3439
|
+
const wrapper = function (...args) {
|
|
3440
|
+
const prefix = $.$mol_jsx_prefix;
|
|
3441
|
+
const booked = $.$mol_jsx_booked;
|
|
3442
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
3443
|
+
try {
|
|
3444
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
3445
|
+
$.$mol_jsx_booked = booked_ext;
|
|
3446
|
+
$.$mol_jsx_crumbs = crumbs_ext;
|
|
3447
|
+
return func.call(this, ...args);
|
|
3448
|
+
}
|
|
3449
|
+
finally {
|
|
3450
|
+
$.$mol_jsx_prefix = prefix;
|
|
3451
|
+
$.$mol_jsx_booked = booked;
|
|
3452
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
3453
|
+
}
|
|
3454
|
+
};
|
|
3455
|
+
$mol_func_name_from(wrapper, func);
|
|
3456
|
+
props[field] = wrapper;
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
if (typeof Elem !== 'string') {
|
|
3460
|
+
if ('prototype' in Elem) {
|
|
3461
|
+
const view = node && node[String(Elem)] || new Elem;
|
|
3462
|
+
Object.assign(view, props);
|
|
3463
|
+
view[Symbol.toStringTag] = guid;
|
|
3464
|
+
view.childNodes = childNodes;
|
|
3465
|
+
if (!view.ownerDocument)
|
|
3466
|
+
view.ownerDocument = $.$mol_jsx_document;
|
|
3467
|
+
view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
3468
|
+
node = view.valueOf();
|
|
3469
|
+
node[String(Elem)] = view;
|
|
3470
|
+
return node;
|
|
3471
|
+
}
|
|
3472
|
+
else {
|
|
3473
|
+
const prefix = $.$mol_jsx_prefix;
|
|
3474
|
+
const booked = $.$mol_jsx_booked;
|
|
3475
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
3476
|
+
try {
|
|
3477
|
+
$.$mol_jsx_prefix = guid;
|
|
3478
|
+
$.$mol_jsx_booked = new Set;
|
|
3479
|
+
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
3480
|
+
return Elem(props, ...childNodes);
|
|
3481
|
+
}
|
|
3482
|
+
finally {
|
|
3483
|
+
$.$mol_jsx_prefix = prefix;
|
|
3484
|
+
$.$mol_jsx_booked = booked;
|
|
3485
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
if (!node) {
|
|
3490
|
+
node = Elem
|
|
3491
|
+
? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
|
|
3492
|
+
: $.$mol_jsx_document.createDocumentFragment();
|
|
3493
|
+
}
|
|
3494
|
+
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
3495
|
+
if (!Elem)
|
|
3496
|
+
return node;
|
|
3497
|
+
if (guid)
|
|
3498
|
+
node.id = guid;
|
|
3499
|
+
for (const key in props) {
|
|
3500
|
+
if (key === 'id')
|
|
3501
|
+
continue;
|
|
3502
|
+
if (typeof props[key] === 'string') {
|
|
3503
|
+
if (typeof node[key] === 'string')
|
|
3504
|
+
node[key] = props[key];
|
|
3505
|
+
node.setAttribute(key, props[key]);
|
|
3506
|
+
}
|
|
3507
|
+
else if (props[key] &&
|
|
3508
|
+
typeof props[key] === 'object' &&
|
|
3509
|
+
Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
|
|
3510
|
+
if (typeof node[key] === 'object') {
|
|
3511
|
+
Object.assign(node[key], props[key]);
|
|
3512
|
+
continue;
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
else {
|
|
3516
|
+
node[key] = props[key];
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
if ($.$mol_jsx_crumbs)
|
|
3520
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
3521
|
+
return node;
|
|
3522
|
+
}
|
|
3523
|
+
$.$mol_jsx = $mol_jsx;
|
|
3524
|
+
})($ || ($ = {}));
|
|
3525
|
+
|
|
3526
|
+
;
|
|
3527
|
+
"use strict";
|
|
3528
|
+
var $;
|
|
3529
|
+
(function ($) {
|
|
3530
|
+
$mol_test({
|
|
3531
|
+
'Make empty div'() {
|
|
3532
|
+
$mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
|
|
3533
|
+
},
|
|
3534
|
+
'Define native field'() {
|
|
3535
|
+
const dom = $mol_jsx("input", { value: '123' });
|
|
3536
|
+
$mol_assert_equal(dom.outerHTML, '<input value="123">');
|
|
3537
|
+
$mol_assert_equal(dom.value, '123');
|
|
3538
|
+
},
|
|
3539
|
+
'Define classes'() {
|
|
3145
3540
|
const dom = $mol_jsx("div", { class: 'foo bar' });
|
|
3146
3541
|
$mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
|
|
3147
3542
|
},
|
|
@@ -3749,43 +4144,6 @@ var $;
|
|
|
3749
4144
|
});
|
|
3750
4145
|
})($ || ($ = {}));
|
|
3751
4146
|
|
|
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
4147
|
;
|
|
3790
4148
|
"use strict";
|
|
3791
4149
|
var $;
|
|
@@ -4384,112 +4742,6 @@ var $;
|
|
|
4384
4742
|
;
|
|
4385
4743
|
"use strict";
|
|
4386
4744
|
|
|
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
4745
|
;
|
|
4494
4746
|
"use strict";
|
|
4495
4747
|
var $;
|
|
@@ -4565,6 +4817,59 @@ var $;
|
|
|
4565
4817
|
})($$ = $_1.$$ || ($_1.$$ = {}));
|
|
4566
4818
|
})($ || ($ = {}));
|
|
4567
4819
|
|
|
4820
|
+
;
|
|
4821
|
+
"use strict";
|
|
4822
|
+
var $;
|
|
4823
|
+
(function ($_1) {
|
|
4824
|
+
$mol_test({
|
|
4825
|
+
'test types'($) {
|
|
4826
|
+
class A {
|
|
4827
|
+
static a() {
|
|
4828
|
+
return '';
|
|
4829
|
+
}
|
|
4830
|
+
static b() {
|
|
4831
|
+
return $mol_wire_async(this).a();
|
|
4832
|
+
}
|
|
4833
|
+
}
|
|
4834
|
+
},
|
|
4835
|
+
async 'Latest method calls wins'($) {
|
|
4836
|
+
class NameLogger extends $mol_object2 {
|
|
4837
|
+
static $ = $;
|
|
4838
|
+
static first = [];
|
|
4839
|
+
static last = [];
|
|
4840
|
+
static send(next) {
|
|
4841
|
+
$mol_wire_sync(this.first).push(next);
|
|
4842
|
+
$$.$mol_wait_timeout(0);
|
|
4843
|
+
this.last.push(next);
|
|
4844
|
+
}
|
|
4845
|
+
}
|
|
4846
|
+
const name = $mol_wire_async(NameLogger).send;
|
|
4847
|
+
name('john');
|
|
4848
|
+
const promise = name('jin');
|
|
4849
|
+
$.$mol_after_mock_warp();
|
|
4850
|
+
await promise;
|
|
4851
|
+
$mol_assert_equal(NameLogger.first, ['john', 'jin']);
|
|
4852
|
+
$mol_assert_equal(NameLogger.last, ['jin']);
|
|
4853
|
+
},
|
|
4854
|
+
async 'Latest function calls wins'($) {
|
|
4855
|
+
const first = [];
|
|
4856
|
+
const last = [];
|
|
4857
|
+
function send_name(next) {
|
|
4858
|
+
$mol_wire_sync(first).push(next);
|
|
4859
|
+
$$.$mol_wait_timeout(0);
|
|
4860
|
+
last.push(next);
|
|
4861
|
+
}
|
|
4862
|
+
const name = $mol_wire_async(send_name);
|
|
4863
|
+
name('john');
|
|
4864
|
+
const promise = name('jin');
|
|
4865
|
+
$.$mol_after_mock_warp();
|
|
4866
|
+
await promise;
|
|
4867
|
+
$mol_assert_equal(first, ['john', 'jin']);
|
|
4868
|
+
$mol_assert_equal(last, ['jin']);
|
|
4869
|
+
},
|
|
4870
|
+
});
|
|
4871
|
+
})($ || ($ = {}));
|
|
4872
|
+
|
|
4568
4873
|
;
|
|
4569
4874
|
"use strict";
|
|
4570
4875
|
var $;
|
|
@@ -5229,32 +5534,6 @@ var $;
|
|
|
5229
5534
|
});
|
|
5230
5535
|
})($ || ($ = {}));
|
|
5231
5536
|
|
|
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
5537
|
;
|
|
5259
5538
|
"use strict";
|
|
5260
5539
|
|
|
@@ -5583,290 +5862,5 @@ var $;
|
|
|
5583
5862
|
});
|
|
5584
5863
|
})($ || ($ = {}));
|
|
5585
5864
|
|
|
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
5865
|
|
|
5872
5866
|
//# sourceMappingURL=node.test.js.map
|