mol_wire_lib 1.0.92 → 1.0.93

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
@@ -807,9 +807,6 @@ var $;
807
807
  return;
808
808
  return this.cache;
809
809
  }
810
- persistent() {
811
- return this instanceof $mol_wire_fiber_persist;
812
- }
813
810
  field() {
814
811
  return this.task.name + '()';
815
812
  }
@@ -822,23 +819,6 @@ var $;
822
819
  this.pub_from = this.sub_from = args.length;
823
820
  this[Symbol.toStringTag] = id;
824
821
  }
825
- destructor() {
826
- super.destructor();
827
- const prev = this.cache;
828
- if ($mol_owning_check(this, prev)) {
829
- prev.destructor();
830
- }
831
- if (this instanceof $mol_wire_fiber_persist) {
832
- if (this.pub_from === 0) {
833
- ;
834
- (this.host ?? this.task)[this.field()] = null;
835
- }
836
- else {
837
- ;
838
- (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
839
- }
840
- }
841
- }
842
822
  plan() {
843
823
  $mol_wire_fiber.planning.push(this);
844
824
  $mol_wire_fiber.plan();
@@ -871,15 +851,6 @@ var $;
871
851
  else
872
852
  super.emit(quant);
873
853
  }
874
- commit() {
875
- if (this instanceof $mol_wire_fiber_persist)
876
- return;
877
- super.commit();
878
- if (this.host instanceof $mol_wire_fiber) {
879
- this.host.put(this.cache);
880
- }
881
- this.destructor();
882
- }
883
854
  refresh() {
884
855
  if (this.cursor === $mol_wire_cursor.fresh)
885
856
  return;
@@ -1022,6 +993,10 @@ var $;
1022
993
  return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
1023
994
  };
1024
995
  }
996
+ commit() {
997
+ super.commit();
998
+ this.destructor();
999
+ }
1025
1000
  }
1026
1001
  $.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
1027
1002
  class $mol_wire_fiber_persist extends $mol_wire_fiber {
@@ -1058,7 +1033,23 @@ var $;
1058
1033
  }
1059
1034
  }
1060
1035
  recall(...args) {
1061
- return this.task.call(this.host, ...args);
1036
+ return this.put(this.task.call(this.host, ...args));
1037
+ }
1038
+ commit() { }
1039
+ destructor() {
1040
+ super.destructor();
1041
+ const prev = this.cache;
1042
+ if ($mol_owning_check(this, prev)) {
1043
+ prev.destructor();
1044
+ }
1045
+ if (this.pub_from === 0) {
1046
+ ;
1047
+ (this.host ?? this.task)[this.field()] = null;
1048
+ }
1049
+ else {
1050
+ ;
1051
+ (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1052
+ }
1062
1053
  }
1063
1054
  }
1064
1055
  __decorate([
@@ -1658,6 +1649,12 @@ var $;
1658
1649
  //mol/type/assert/assert.ts
1659
1650
  ;
1660
1651
  "use strict";
1652
+ //mol/type/equals/equals.test.ts
1653
+ ;
1654
+ "use strict";
1655
+ //mol/type/equals/equals.ts
1656
+ ;
1657
+ "use strict";
1661
1658
  //mol/type/partial/deep/deep.test.ts
1662
1659
  ;
1663
1660
  "use strict";
@@ -2045,6 +2042,118 @@ var $;
2045
2042
  ;
2046
2043
  "use strict";
2047
2044
  var $;
2045
+ (function ($) {
2046
+ function $mol_log3_area_lazy(event) {
2047
+ const self = this;
2048
+ const stack = self.$mol_log3_stack;
2049
+ const deep = stack.length;
2050
+ let logged = false;
2051
+ stack.push(() => {
2052
+ logged = true;
2053
+ self.$mol_log3_area.call(self, event);
2054
+ });
2055
+ return () => {
2056
+ if (logged)
2057
+ self.console.groupEnd();
2058
+ if (stack.length > deep)
2059
+ stack.length = deep;
2060
+ };
2061
+ }
2062
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
2063
+ $.$mol_log3_stack = [];
2064
+ })($ || ($ = {}));
2065
+ //mol/log3/log3.ts
2066
+ ;
2067
+ "use strict";
2068
+ var $;
2069
+ (function ($) {
2070
+ function $mol_log3_node_make(level, output, type, color) {
2071
+ return function $mol_log3_logger(event) {
2072
+ if (!event.time)
2073
+ event = { time: new Date().toISOString(), ...event };
2074
+ const tree = this.$mol_tree.fromJSON(event).clone({ type });
2075
+ let str = tree.toString();
2076
+ if (process[output].isTTY) {
2077
+ str = $node.colorette[color + 'Bright'](str);
2078
+ }
2079
+ ;
2080
+ this.console[level](str);
2081
+ const self = this;
2082
+ return () => self.console.groupEnd();
2083
+ };
2084
+ }
2085
+ $.$mol_log3_node_make = $mol_log3_node_make;
2086
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
2087
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
2088
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
2089
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
2090
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
2091
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
2092
+ })($ || ($ = {}));
2093
+ //mol/log3/log3.node.ts
2094
+ ;
2095
+ "use strict";
2096
+ var $;
2097
+ (function ($_1) {
2098
+ $mol_test_mocks.push($ => {
2099
+ $.$mol_log3_come = () => { };
2100
+ $.$mol_log3_done = () => { };
2101
+ $.$mol_log3_fail = () => { };
2102
+ $.$mol_log3_warn = () => { };
2103
+ $.$mol_log3_rise = () => { };
2104
+ $.$mol_log3_area = () => () => { };
2105
+ });
2106
+ })($ || ($ = {}));
2107
+ //mol/log3/log3.test.ts
2108
+ ;
2109
+ "use strict";
2110
+ var $;
2111
+ (function ($) {
2112
+ function $mol_env() {
2113
+ return {};
2114
+ }
2115
+ $.$mol_env = $mol_env;
2116
+ })($ || ($ = {}));
2117
+ //mol/env/env.ts
2118
+ ;
2119
+ "use strict";
2120
+ var $;
2121
+ (function ($) {
2122
+ $.$mol_env = function $mol_env() {
2123
+ return this.process.env;
2124
+ };
2125
+ })($ || ($ = {}));
2126
+ //mol/env/env.node.ts
2127
+ ;
2128
+ "use strict";
2129
+ var $;
2130
+ (function ($) {
2131
+ function $mol_exec(dir, command, ...args) {
2132
+ let [app, ...args0] = command.split(' ');
2133
+ args = [...args0, ...args];
2134
+ this.$mol_log3_come({
2135
+ place: '$mol_exec',
2136
+ dir: $node.path.relative('', dir),
2137
+ message: 'Run',
2138
+ command: `${app} ${args.join(' ')}`,
2139
+ });
2140
+ var res = $node['child_process'].spawnSync(app, args, {
2141
+ cwd: $node.path.resolve(dir),
2142
+ shell: true,
2143
+ env: this.$mol_env(),
2144
+ });
2145
+ if (res.status || res.error)
2146
+ return $mol_fail(res.error || new Error(res.stderr.toString()));
2147
+ if (!res.stdout)
2148
+ res.stdout = Buffer.from([]);
2149
+ return res;
2150
+ }
2151
+ $.$mol_exec = $mol_exec;
2152
+ })($ || ($ = {}));
2153
+ //mol/exec/exec.node.ts
2154
+ ;
2155
+ "use strict";
2156
+ var $;
2048
2157
  (function ($) {
2049
2158
  $mol_test({
2050
2159
  'get'() {
@@ -2945,556 +3054,111 @@ var $;
2945
3054
  "use strict";
2946
3055
  var $;
2947
3056
  (function ($) {
2948
- function $mol_log3_area_lazy(event) {
2949
- const self = this;
2950
- const stack = self.$mol_log3_stack;
2951
- const deep = stack.length;
2952
- let logged = false;
2953
- stack.push(() => {
2954
- logged = true;
2955
- self.$mol_log3_area.call(self, event);
2956
- });
2957
- return () => {
2958
- if (logged)
2959
- self.console.groupEnd();
2960
- if (stack.length > deep)
2961
- stack.length = deep;
2962
- };
2963
- }
2964
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
2965
- $.$mol_log3_stack = [];
2966
- })($ || ($ = {}));
2967
- //mol/log3/log3.ts
2968
- ;
2969
- "use strict";
2970
- var $;
2971
- (function ($) {
2972
- function $mol_log3_node_make(level, output, type, color) {
2973
- return function $mol_log3_logger(event) {
2974
- if (!event.time)
2975
- event = { time: new Date().toISOString(), ...event };
2976
- const tree = this.$mol_tree.fromJSON(event).clone({ type });
2977
- let str = tree.toString();
2978
- if (process[output].isTTY) {
2979
- str = $node.colorette[color + 'Bright'](str);
2980
- }
2981
- ;
2982
- this.console[level](str);
2983
- const self = this;
2984
- return () => self.console.groupEnd();
3057
+ function $mol_deprecated(message) {
3058
+ return (host, field, descr) => {
3059
+ const value = descr.value;
3060
+ let warned = false;
3061
+ descr.value = function $mol_deprecated_wrapper(...args) {
3062
+ if (!warned) {
3063
+ $$.$mol_log3_warn({
3064
+ place: `${host.constructor.name}::${field}`,
3065
+ message: `Deprecated`,
3066
+ hint: message,
3067
+ });
3068
+ warned = true;
3069
+ }
3070
+ return value.call(this, ...args);
3071
+ };
2985
3072
  };
2986
3073
  }
2987
- $.$mol_log3_node_make = $mol_log3_node_make;
2988
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
2989
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
2990
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
2991
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
2992
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
2993
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
3074
+ $.$mol_deprecated = $mol_deprecated;
2994
3075
  })($ || ($ = {}));
2995
- //mol/log3/log3.node.ts
2996
- ;
2997
- "use strict";
2998
- var $;
2999
- (function ($_1) {
3000
- $mol_test_mocks.push($ => {
3001
- $.$mol_log3_come = () => { };
3002
- $.$mol_log3_done = () => { };
3003
- $.$mol_log3_fail = () => { };
3004
- $.$mol_log3_warn = () => { };
3005
- $.$mol_log3_rise = () => { };
3006
- $.$mol_log3_area = () => () => { };
3007
- });
3008
- })($ || ($ = {}));
3009
- //mol/log3/log3.test.ts
3010
- ;
3011
- "use strict";
3012
- var $;
3013
- (function ($) {
3014
- class $mol_wire_log extends $mol_object2 {
3015
- static watch(task) {
3016
- return task;
3017
- }
3018
- static track(fiber) {
3019
- const prev = $mol_wire_probe(() => this.track(fiber));
3020
- let next;
3021
- try {
3022
- next = fiber.sync();
3023
- }
3024
- finally {
3025
- for (const pub of fiber.pub_list) {
3026
- if (pub instanceof $mol_wire_fiber) {
3027
- this.track(pub);
3028
- }
3029
- }
3030
- }
3031
- if (prev !== undefined && !$mol_compare_deep(prev, next)) {
3032
- this.$.$mol_log3_rise({
3033
- message: 'Changed',
3034
- place: fiber,
3035
- });
3036
- }
3037
- return next;
3038
- }
3039
- static active() {
3040
- try {
3041
- this.watch()?.();
3042
- }
3043
- finally {
3044
- for (const pub of $mol_wire_auto().pub_list) {
3045
- if (pub instanceof $mol_wire_fiber) {
3046
- this.track(pub);
3047
- }
3048
- }
3049
- }
3050
- }
3051
- }
3052
- __decorate([
3053
- $mol_mem
3054
- ], $mol_wire_log, "watch", null);
3055
- __decorate([
3056
- $mol_mem_key
3057
- ], $mol_wire_log, "track", null);
3058
- __decorate([
3059
- $mol_mem
3060
- ], $mol_wire_log, "active", null);
3061
- $.$mol_wire_log = $mol_wire_log;
3062
- })($ || ($ = {}));
3063
- //mol/wire/log/log.ts
3064
- ;
3065
- "use strict";
3066
- var $;
3067
- (function ($) {
3068
- $mol_wire_log.active();
3069
- })($ || ($ = {}));
3070
- //mol/wire/wire.test.ts
3071
- ;
3072
- "use strict";
3073
- var $;
3074
- (function ($) {
3075
- $mol_test({
3076
- 'const returns stored value'() {
3077
- const foo = { bar: $mol_const(Math.random()) };
3078
- $mol_assert_equal(foo.bar(), foo.bar());
3079
- $mol_assert_equal(foo.bar(), foo.bar['()']);
3080
- },
3081
- });
3082
- })($ || ($ = {}));
3083
- //mol/const/const.test.ts
3076
+ //mol/deprecated/deprecated.ts
3084
3077
  ;
3085
3078
  "use strict";
3086
3079
  var $;
3087
3080
  (function ($_1) {
3088
3081
  $mol_test({
3089
- 'Cached field'($) {
3090
- class App extends $mol_object2 {
3091
- static $ = $;
3092
- static low = 1;
3093
- static get high() {
3094
- return this.low + 1;
3095
- }
3096
- static set high(next) {
3097
- this.low = next - 1;
3098
- }
3099
- static test() {
3100
- $mol_assert_equal(App.high, 2);
3101
- App.high = 3;
3102
- $mol_assert_equal(App.high, 3);
3103
- }
3104
- }
3105
- __decorate([
3106
- $mol_wire_field
3107
- ], App, "low", void 0);
3108
- __decorate([
3109
- $mol_wire_field
3110
- ], App, "high", null);
3111
- __decorate([
3112
- $mol_wire_method
3113
- ], App, "test", null);
3114
- App.test();
3082
+ 'tree parsing'() {
3083
+ $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
3084
+ $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
3085
+ $mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
3086
+ $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
3087
+ $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
3088
+ $mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
3089
+ $mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
3090
+ $mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
3115
3091
  },
3116
- });
3117
- })($ || ($ = {}));
3118
- //mol/wire/field/field.test.ts
3119
- ;
3120
- "use strict";
3121
- var $;
3122
- (function ($_1) {
3123
- $mol_test({
3124
- 'Watch one value'($) {
3125
- class App extends $mol_object2 {
3126
- static $ = $;
3127
- static set = new $mol_wire_set();
3128
- static lucky() {
3129
- return this.set.has(777);
3130
- }
3131
- }
3132
- __decorate([
3133
- $mol_wire_mem(0)
3134
- ], App, "lucky", null);
3135
- $mol_assert_equal(App.lucky(), false);
3136
- App.set.add(666);
3137
- $mol_assert_equal(App.lucky(), false);
3138
- App.set.add(777);
3139
- $mol_assert_equal(App.lucky(), true);
3140
- App.set.delete(777);
3141
- $mol_assert_equal(App.lucky(), false);
3092
+ 'inserting'() {
3093
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
3094
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
3095
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
3096
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
3097
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
3098
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
3142
3099
  },
3143
- 'Watch item channel'($) {
3144
- class App extends $mol_object2 {
3145
- static $ = $;
3146
- static set = new $mol_wire_set();
3147
- static lucky() {
3148
- return this.set.item(777);
3149
- }
3150
- }
3151
- __decorate([
3152
- $mol_wire_mem(0)
3153
- ], App, "lucky", null);
3154
- $mol_assert_equal(App.lucky(), false);
3155
- App.set.item(666, true);
3156
- $mol_assert_equal(App.lucky(), false);
3157
- App.set.item(777, true);
3158
- $mol_assert_equal(App.lucky(), true);
3159
- App.set.item(777, false);
3160
- $mol_assert_equal(App.lucky(), false);
3100
+ 'fromJSON'() {
3101
+ $mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
3102
+ $mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3103
+ $mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3104
+ $mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
3105
+ $mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
3161
3106
  },
3162
- 'Watch size'($) {
3163
- class App extends $mol_object2 {
3164
- static $ = $;
3165
- static set = new $mol_wire_set();
3166
- static size() {
3167
- return this.set.size;
3168
- }
3169
- }
3170
- __decorate([
3171
- $mol_wire_mem(0)
3172
- ], App, "size", null);
3173
- $mol_assert_equal(App.size(), 0);
3174
- App.set.add(666);
3175
- $mol_assert_equal(App.size(), 1);
3176
- App.set.add(777);
3177
- $mol_assert_equal(App.size(), 2);
3178
- App.set.delete(777);
3179
- $mol_assert_equal(App.size(), 1);
3107
+ 'toJSON'() {
3108
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
3109
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
3110
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
3111
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
3112
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
3180
3113
  },
3181
- 'Watch for-of'($) {
3182
- class App extends $mol_object2 {
3183
- static $ = $;
3184
- static set = new $mol_wire_set();
3185
- static sum() {
3186
- let res = 0;
3187
- for (const val of this.set) {
3188
- res += val;
3189
- }
3190
- return res;
3191
- }
3192
- }
3193
- __decorate([
3194
- $mol_wire_mem(0)
3195
- ], App, "sum", null);
3196
- $mol_assert_equal(App.sum(), 0);
3197
- App.set.add(111);
3198
- $mol_assert_equal(App.sum(), 111);
3199
- App.set.add(222);
3200
- $mol_assert_equal(App.sum(), 333);
3201
- App.set.delete(111);
3202
- $mol_assert_equal(App.sum(), 222);
3114
+ 'hack'() {
3115
+ const res = $mol_tree.fromString(`foo bar xxx`).hack({
3116
+ '': (tree, context) => [tree.hack(context)],
3117
+ 'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
3118
+ });
3119
+ $mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
3203
3120
  },
3204
- 'Watch forEach'($) {
3205
- class App extends $mol_object2 {
3206
- static $ = $;
3207
- static set = new $mol_wire_set();
3208
- static sum() {
3209
- let res = 0;
3210
- this.set.forEach(val => res += val);
3211
- return res;
3212
- }
3121
+ 'errors handling'($) {
3122
+ const errors = [];
3123
+ class Tree extends $mol_tree {
3124
+ static $ = $.$mol_ambient({
3125
+ $mol_fail: error => errors.push(error.message)
3126
+ });
3213
3127
  }
3214
- __decorate([
3215
- $mol_wire_mem(0)
3216
- ], App, "sum", null);
3217
- $mol_assert_equal(App.sum(), 0);
3218
- App.set.add(111);
3219
- $mol_assert_equal(App.sum(), 111);
3220
- App.set.add(222);
3221
- $mol_assert_equal(App.sum(), 333);
3222
- App.set.delete(111);
3223
- $mol_assert_equal(App.sum(), 222);
3128
+ Tree.fromString(`
3129
+ \t \tfoo
3130
+ bar \\data
3131
+ `, 'test');
3132
+ $mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
3224
3133
  },
3225
3134
  });
3226
3135
  })($ || ($ = {}));
3227
- //mol/wire/set/set.test.ts
3136
+ //mol/tree/tree.test.ts
3228
3137
  ;
3229
3138
  "use strict";
3230
3139
  var $;
3231
- (function ($_1) {
3232
- $mol_test({
3233
- 'Watch one value'($) {
3234
- class App extends $mol_object2 {
3235
- static $ = $;
3236
- static dict = new $mol_wire_dict();
3237
- static lucky() {
3238
- return this.dict.get(777);
3239
- }
3240
- }
3241
- __decorate([
3242
- $mol_wire_mem(0)
3243
- ], App, "lucky", null);
3244
- $mol_assert_equal(App.lucky(), undefined);
3245
- App.dict.set(666, 6666);
3246
- $mol_assert_equal(App.lucky(), undefined);
3247
- App.dict.set(777, 7777);
3248
- $mol_assert_equal(App.lucky(), 7777);
3249
- App.dict.delete(777);
3250
- $mol_assert_equal(App.lucky(), undefined);
3251
- },
3252
- 'Watch item channel'($) {
3253
- class App extends $mol_object2 {
3254
- static $ = $;
3255
- static dict = new $mol_wire_dict();
3256
- static lucky() {
3257
- return this.dict.item(777);
3258
- }
3259
- }
3260
- __decorate([
3261
- $mol_wire_mem(0)
3262
- ], App, "lucky", null);
3263
- $mol_assert_equal(App.lucky(), null);
3264
- App.dict.item(666, 6666);
3265
- $mol_assert_equal(App.lucky(), null);
3266
- App.dict.item(777, 7777);
3267
- $mol_assert_equal(App.lucky(), 7777);
3268
- App.dict.item(777, null);
3269
- $mol_assert_equal(App.lucky(), null);
3270
- },
3271
- 'Watch size'($) {
3272
- class App extends $mol_object2 {
3273
- static $ = $;
3274
- static dict = new $mol_wire_dict();
3275
- static size() {
3276
- return this.dict.size;
3277
- }
3278
- }
3279
- __decorate([
3280
- $mol_wire_mem(0)
3281
- ], App, "size", null);
3282
- $mol_assert_equal(App.size(), 0);
3283
- App.dict.set(666, 6666);
3284
- $mol_assert_equal(App.size(), 1);
3285
- App.dict.set(777, 7777);
3286
- $mol_assert_equal(App.size(), 2);
3287
- App.dict.delete(777);
3288
- $mol_assert_equal(App.size(), 1);
3289
- },
3290
- 'Watch for-of'($) {
3291
- class App extends $mol_object2 {
3292
- static $ = $;
3293
- static dict = new $mol_wire_dict();
3294
- static sum() {
3295
- let keys = 0;
3296
- let vals = 0;
3297
- for (const [key, val] of this.dict) {
3298
- keys += key;
3299
- vals += val;
3300
- }
3301
- return [keys, vals];
3302
- }
3303
- }
3304
- __decorate([
3305
- $mol_wire_mem(0)
3306
- ], App, "sum", null);
3307
- $mol_assert_like(App.sum(), [0, 0]);
3308
- App.dict.set(111, 1111);
3309
- $mol_assert_like(App.sum(), [111, 1111]);
3310
- App.dict.set(222, 2222);
3311
- $mol_assert_like(App.sum(), [333, 3333]);
3312
- App.dict.delete(111);
3313
- $mol_assert_like(App.sum(), [222, 2222]);
3314
- },
3315
- 'Watch forEach'($) {
3316
- class App extends $mol_object2 {
3317
- static $ = $;
3318
- static dict = new $mol_wire_dict();
3319
- static sum() {
3320
- let keys = 0;
3321
- let vals = 0;
3322
- this.dict.forEach((val, key) => {
3323
- keys += key;
3324
- vals += val;
3325
- });
3326
- return [keys, vals];
3327
- }
3328
- }
3329
- __decorate([
3330
- $mol_wire_mem(0)
3331
- ], App, "sum", null);
3332
- $mol_assert_like(App.sum(), [0, 0]);
3333
- App.dict.set(111, 1111);
3334
- $mol_assert_like(App.sum(), [111, 1111]);
3335
- App.dict.set(222, 2222);
3336
- $mol_assert_like(App.sum(), [333, 3333]);
3337
- App.dict.delete(111);
3338
- $mol_assert_like(App.sum(), [222, 2222]);
3339
- },
3340
- });
3341
- })($ || ($ = {}));
3342
- //mol/wire/dict/dict.test.ts
3343
- ;
3344
- "use strict";
3345
- var $;
3346
- (function ($) {
3347
- function $mol_env() {
3348
- return {};
3349
- }
3350
- $.$mol_env = $mol_env;
3351
- })($ || ($ = {}));
3352
- //mol/env/env.ts
3353
- ;
3354
- "use strict";
3355
- var $;
3356
- (function ($) {
3357
- $.$mol_env = function $mol_env() {
3358
- return this.process.env;
3359
- };
3360
- })($ || ($ = {}));
3361
- //mol/env/env.node.ts
3362
- ;
3363
- "use strict";
3364
- var $;
3365
- (function ($) {
3366
- function $mol_exec(dir, command, ...args) {
3367
- let [app, ...args0] = command.split(' ');
3368
- args = [...args0, ...args];
3369
- this.$mol_log3_come({
3370
- place: '$mol_exec',
3371
- dir: $node.path.relative('', dir),
3372
- message: 'Run',
3373
- command: `${app} ${args.join(' ')}`,
3374
- });
3375
- var res = $node['child_process'].spawnSync(app, args, {
3376
- cwd: $node.path.resolve(dir),
3377
- shell: true,
3378
- env: this.$mol_env(),
3379
- });
3380
- if (res.status || res.error)
3381
- return $mol_fail(res.error || new Error(res.stderr.toString()));
3382
- if (!res.stdout)
3383
- res.stdout = Buffer.from([]);
3384
- return res;
3385
- }
3386
- $.$mol_exec = $mol_exec;
3387
- })($ || ($ = {}));
3388
- //mol/exec/exec.node.ts
3389
- ;
3390
- "use strict";
3391
- var $;
3392
- (function ($) {
3393
- function $mol_deprecated(message) {
3394
- return (host, field, descr) => {
3395
- const value = descr.value;
3396
- let warned = false;
3397
- descr.value = function $mol_deprecated_wrapper(...args) {
3398
- if (!warned) {
3399
- $$.$mol_log3_warn({
3400
- place: `${host.constructor.name}::${field}`,
3401
- message: `Deprecated`,
3402
- hint: message,
3403
- });
3404
- warned = true;
3405
- }
3406
- return value.call(this, ...args);
3407
- };
3408
- };
3409
- }
3410
- $.$mol_deprecated = $mol_deprecated;
3411
- })($ || ($ = {}));
3412
- //mol/deprecated/deprecated.ts
3413
- ;
3414
- "use strict";
3415
- var $;
3416
- (function ($_1) {
3417
- $mol_test({
3418
- 'tree parsing'() {
3419
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
3420
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
3421
- $mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
3422
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
3423
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
3424
- $mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
3425
- $mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
3426
- $mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
3427
- },
3428
- 'inserting'() {
3429
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
3430
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
3431
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
3432
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
3433
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
3434
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
3435
- },
3436
- 'fromJSON'() {
3437
- $mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
3438
- $mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3439
- $mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3440
- $mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
3441
- $mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
3442
- },
3443
- 'toJSON'() {
3444
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
3445
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
3446
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
3447
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
3448
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
3449
- },
3450
- 'hack'() {
3451
- const res = $mol_tree.fromString(`foo bar xxx`).hack({
3452
- '': (tree, context) => [tree.hack(context)],
3453
- 'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
3454
- });
3455
- $mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
3456
- },
3457
- 'errors handling'($) {
3458
- const errors = [];
3459
- class Tree extends $mol_tree {
3460
- static $ = $.$mol_ambient({
3461
- $mol_fail: error => errors.push(error.message)
3462
- });
3463
- }
3464
- Tree.fromString(`
3465
- \t \tfoo
3466
- bar \\data
3467
- `, 'test');
3468
- $mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
3469
- },
3470
- });
3471
- })($ || ($ = {}));
3472
- //mol/tree/tree.test.ts
3473
- ;
3474
- "use strict";
3475
- var $;
3476
- (function ($) {
3477
- $.$mol_tree_convert = Symbol('$mol_tree_convert');
3478
- class $mol_tree extends $mol_object2 {
3479
- type;
3480
- data;
3481
- sub;
3482
- baseUri;
3483
- row;
3484
- col;
3485
- length;
3486
- constructor(config = {}) {
3487
- super();
3488
- this.type = config.type || '';
3489
- if (config.value !== undefined) {
3490
- var sub = $mol_tree.values(config.value);
3491
- if (config.type || sub.length > 1) {
3492
- this.sub = [...sub, ...(config.sub || [])];
3493
- this.data = config.data || '';
3494
- }
3495
- else {
3496
- this.data = sub[0].data;
3497
- this.sub = config.sub || [];
3140
+ (function ($) {
3141
+ $.$mol_tree_convert = Symbol('$mol_tree_convert');
3142
+ class $mol_tree extends $mol_object2 {
3143
+ type;
3144
+ data;
3145
+ sub;
3146
+ baseUri;
3147
+ row;
3148
+ col;
3149
+ length;
3150
+ constructor(config = {}) {
3151
+ super();
3152
+ this.type = config.type || '';
3153
+ if (config.value !== undefined) {
3154
+ var sub = $mol_tree.values(config.value);
3155
+ if (config.type || sub.length > 1) {
3156
+ this.sub = [...sub, ...(config.sub || [])];
3157
+ this.data = config.data || '';
3158
+ }
3159
+ else {
3160
+ this.data = sub[0].data;
3161
+ this.sub = config.sub || [];
3498
3162
  }
3499
3163
  }
3500
3164
  else {
@@ -3577,237 +3241,564 @@ var $;
3577
3241
  parent_sub.push(next);
3578
3242
  parent = next;
3579
3243
  }
3580
- stack.push(parent);
3581
- });
3582
- return root;
3244
+ stack.push(parent);
3245
+ });
3246
+ return root;
3247
+ }
3248
+ static fromJSON(json, baseUri = '') {
3249
+ switch (true) {
3250
+ case typeof json === 'boolean':
3251
+ case typeof json === 'number':
3252
+ case json === null:
3253
+ return new $mol_tree({
3254
+ type: String(json),
3255
+ baseUri: baseUri
3256
+ });
3257
+ case typeof json === 'string':
3258
+ return new $mol_tree({
3259
+ value: json,
3260
+ baseUri: baseUri
3261
+ });
3262
+ case Array.isArray(json):
3263
+ return new $mol_tree({
3264
+ type: "/",
3265
+ sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
3266
+ });
3267
+ case json instanceof Date:
3268
+ return new $mol_tree({
3269
+ value: json.toISOString(),
3270
+ baseUri: baseUri
3271
+ });
3272
+ default:
3273
+ if (typeof json[$.$mol_tree_convert] === 'function') {
3274
+ return json[$.$mol_tree_convert]();
3275
+ }
3276
+ if (typeof json.toJSON === 'function') {
3277
+ return $mol_tree.fromJSON(json.toJSON());
3278
+ }
3279
+ if (json instanceof Error) {
3280
+ const { name, message, stack } = json;
3281
+ json = { ...json, name, message, stack };
3282
+ }
3283
+ var sub = [];
3284
+ for (var key in json) {
3285
+ if (json[key] === undefined)
3286
+ continue;
3287
+ const subsub = $mol_tree.fromJSON(json[key], baseUri);
3288
+ if (/^[^\n\t\\ ]+$/.test(key)) {
3289
+ var child = new $mol_tree({
3290
+ type: key,
3291
+ baseUri: baseUri,
3292
+ sub: [subsub],
3293
+ });
3294
+ }
3295
+ else {
3296
+ var child = new $mol_tree({
3297
+ value: key,
3298
+ baseUri: baseUri,
3299
+ sub: [subsub],
3300
+ });
3301
+ }
3302
+ sub.push(child);
3303
+ }
3304
+ return new $mol_tree({
3305
+ type: "*",
3306
+ sub: sub,
3307
+ baseUri: baseUri
3308
+ });
3309
+ }
3310
+ }
3311
+ get uri() {
3312
+ return this.baseUri + '#' + this.row + ':' + this.col;
3313
+ }
3314
+ toString(prefix = '') {
3315
+ var output = '';
3316
+ if (this.type.length) {
3317
+ if (!prefix.length) {
3318
+ prefix = "\t";
3319
+ }
3320
+ output += this.type;
3321
+ if (this.sub.length == 1) {
3322
+ return output + ' ' + this.sub[0].toString(prefix);
3323
+ }
3324
+ output += "\n";
3325
+ }
3326
+ else if (this.data.length || prefix.length) {
3327
+ output += "\\" + this.data + "\n";
3328
+ }
3329
+ for (var child of this.sub) {
3330
+ output += prefix;
3331
+ output += child.toString(prefix + "\t");
3332
+ }
3333
+ return output;
3334
+ }
3335
+ toJSON() {
3336
+ if (!this.type)
3337
+ return this.value;
3338
+ if (this.type === 'true')
3339
+ return true;
3340
+ if (this.type === 'false')
3341
+ return false;
3342
+ if (this.type === 'null')
3343
+ return null;
3344
+ if (this.type === '*') {
3345
+ var obj = {};
3346
+ for (var child of this.sub) {
3347
+ if (child.type === '-')
3348
+ continue;
3349
+ var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
3350
+ var val = child.sub[child.sub.length - 1].toJSON();
3351
+ if (val !== undefined)
3352
+ obj[key] = val;
3353
+ }
3354
+ return obj;
3355
+ }
3356
+ if (this.type === '/') {
3357
+ var res = [];
3358
+ this.sub.forEach(child => {
3359
+ if (child.type === '-')
3360
+ return;
3361
+ var val = child.toJSON();
3362
+ if (val !== undefined)
3363
+ res.push(val);
3364
+ });
3365
+ return res;
3366
+ }
3367
+ if (this.type === 'time') {
3368
+ return new Date(this.value);
3369
+ }
3370
+ const numb = Number(this.type);
3371
+ if (!Number.isNaN(numb) || this.type === 'NaN')
3372
+ return numb;
3373
+ throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
3374
+ }
3375
+ get value() {
3376
+ var values = [];
3377
+ for (var child of this.sub) {
3378
+ if (child.type)
3379
+ continue;
3380
+ values.push(child.value);
3381
+ }
3382
+ return this.data + values.join("\n");
3383
+ }
3384
+ insert(value, ...path) {
3385
+ if (path.length === 0)
3386
+ return value;
3387
+ const type = path[0];
3388
+ if (typeof type === 'string') {
3389
+ let replaced = false;
3390
+ const sub = this.sub.map((item, index) => {
3391
+ if (item.type !== type)
3392
+ return item;
3393
+ replaced = true;
3394
+ return item.insert(value, ...path.slice(1));
3395
+ });
3396
+ if (!replaced)
3397
+ sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
3398
+ return this.clone({ sub });
3399
+ }
3400
+ else if (typeof type === 'number') {
3401
+ const sub = this.sub.slice();
3402
+ sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
3403
+ return this.clone({ sub });
3404
+ }
3405
+ else {
3406
+ return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
3407
+ }
3408
+ }
3409
+ select(...path) {
3410
+ var next = [this];
3411
+ for (var type of path) {
3412
+ if (!next.length)
3413
+ break;
3414
+ var prev = next;
3415
+ next = [];
3416
+ for (var item of prev) {
3417
+ switch (typeof (type)) {
3418
+ case 'string':
3419
+ for (var child of item.sub) {
3420
+ if (!type || (child.type == type)) {
3421
+ next.push(child);
3422
+ }
3423
+ }
3424
+ break;
3425
+ case 'number':
3426
+ if (type < item.sub.length)
3427
+ next.push(item.sub[type]);
3428
+ break;
3429
+ default: next.push(...item.sub);
3430
+ }
3431
+ }
3432
+ }
3433
+ return new $mol_tree({ sub: next });
3434
+ }
3435
+ filter(path, value) {
3436
+ var sub = this.sub.filter(function (item) {
3437
+ var found = item.select(...path);
3438
+ if (value == null) {
3439
+ return Boolean(found.sub.length);
3440
+ }
3441
+ else {
3442
+ return found.sub.some(child => child.value == value);
3443
+ }
3444
+ });
3445
+ return new $mol_tree({ sub: sub });
3446
+ }
3447
+ transform(visit, stack = []) {
3448
+ const sub_stack = [this, ...stack];
3449
+ return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
3450
+ }
3451
+ hack(context) {
3452
+ const sub = [].concat(...this.sub.map(child => {
3453
+ const handle = context[child.type] || context[''];
3454
+ if (!handle)
3455
+ $mol_fail(child.error('Handler not defined'));
3456
+ return handle(child, context);
3457
+ }));
3458
+ return this.clone({ sub });
3459
+ }
3460
+ error(message) {
3461
+ return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
3462
+ }
3463
+ }
3464
+ __decorate([
3465
+ $mol_deprecated('Use $mol_tree:hack')
3466
+ ], $mol_tree.prototype, "transform", null);
3467
+ $.$mol_tree = $mol_tree;
3468
+ })($ || ($ = {}));
3469
+ //mol/tree/tree.ts
3470
+ ;
3471
+ "use strict";
3472
+ var $;
3473
+ (function ($) {
3474
+ class $mol_wire_log extends $mol_object2 {
3475
+ static watch(task) {
3476
+ return task;
3477
+ }
3478
+ static track(fiber) {
3479
+ const prev = $mol_wire_probe(() => this.track(fiber));
3480
+ let next;
3481
+ try {
3482
+ next = fiber.sync();
3483
+ }
3484
+ finally {
3485
+ for (const pub of fiber.pub_list) {
3486
+ if (pub instanceof $mol_wire_fiber) {
3487
+ this.track(pub);
3488
+ }
3489
+ }
3490
+ }
3491
+ if (prev !== undefined && !$mol_compare_deep(prev, next)) {
3492
+ this.$.$mol_log3_rise({
3493
+ message: 'Changed',
3494
+ place: fiber,
3495
+ });
3496
+ }
3497
+ return next;
3583
3498
  }
3584
- static fromJSON(json, baseUri = '') {
3585
- switch (true) {
3586
- case typeof json === 'boolean':
3587
- case typeof json === 'number':
3588
- case json === null:
3589
- return new $mol_tree({
3590
- type: String(json),
3591
- baseUri: baseUri
3592
- });
3593
- case typeof json === 'string':
3594
- return new $mol_tree({
3595
- value: json,
3596
- baseUri: baseUri
3597
- });
3598
- case Array.isArray(json):
3599
- return new $mol_tree({
3600
- type: "/",
3601
- sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
3602
- });
3603
- case json instanceof Date:
3604
- return new $mol_tree({
3605
- value: json.toISOString(),
3606
- baseUri: baseUri
3607
- });
3608
- default:
3609
- if (typeof json[$.$mol_tree_convert] === 'function') {
3610
- return json[$.$mol_tree_convert]();
3611
- }
3612
- if (typeof json.toJSON === 'function') {
3613
- return $mol_tree.fromJSON(json.toJSON());
3614
- }
3615
- if (json instanceof Error) {
3616
- const { name, message, stack } = json;
3617
- json = { ...json, name, message, stack };
3618
- }
3619
- var sub = [];
3620
- for (var key in json) {
3621
- if (json[key] === undefined)
3622
- continue;
3623
- const subsub = $mol_tree.fromJSON(json[key], baseUri);
3624
- if (/^[^\n\t\\ ]+$/.test(key)) {
3625
- var child = new $mol_tree({
3626
- type: key,
3627
- baseUri: baseUri,
3628
- sub: [subsub],
3629
- });
3630
- }
3631
- else {
3632
- var child = new $mol_tree({
3633
- value: key,
3634
- baseUri: baseUri,
3635
- sub: [subsub],
3636
- });
3637
- }
3638
- sub.push(child);
3499
+ static active() {
3500
+ try {
3501
+ this.watch()?.();
3502
+ }
3503
+ finally {
3504
+ for (const pub of $mol_wire_auto().pub_list) {
3505
+ if (pub instanceof $mol_wire_fiber) {
3506
+ this.track(pub);
3639
3507
  }
3640
- return new $mol_tree({
3641
- type: "*",
3642
- sub: sub,
3643
- baseUri: baseUri
3644
- });
3508
+ }
3645
3509
  }
3646
3510
  }
3647
- get uri() {
3648
- return this.baseUri + '#' + this.row + ':' + this.col;
3649
- }
3650
- toString(prefix = '') {
3651
- var output = '';
3652
- if (this.type.length) {
3653
- if (!prefix.length) {
3654
- prefix = "\t";
3511
+ }
3512
+ __decorate([
3513
+ $mol_mem
3514
+ ], $mol_wire_log, "watch", null);
3515
+ __decorate([
3516
+ $mol_mem_key
3517
+ ], $mol_wire_log, "track", null);
3518
+ __decorate([
3519
+ $mol_mem
3520
+ ], $mol_wire_log, "active", null);
3521
+ $.$mol_wire_log = $mol_wire_log;
3522
+ })($ || ($ = {}));
3523
+ //mol/wire/log/log.ts
3524
+ ;
3525
+ "use strict";
3526
+ var $;
3527
+ (function ($) {
3528
+ $mol_wire_log.active();
3529
+ })($ || ($ = {}));
3530
+ //mol/wire/wire.test.ts
3531
+ ;
3532
+ "use strict";
3533
+ var $;
3534
+ (function ($) {
3535
+ $mol_test({
3536
+ 'const returns stored value'() {
3537
+ const foo = { bar: $mol_const(Math.random()) };
3538
+ $mol_assert_equal(foo.bar(), foo.bar());
3539
+ $mol_assert_equal(foo.bar(), foo.bar['()']);
3540
+ },
3541
+ });
3542
+ })($ || ($ = {}));
3543
+ //mol/const/const.test.ts
3544
+ ;
3545
+ "use strict";
3546
+ var $;
3547
+ (function ($_1) {
3548
+ $mol_test({
3549
+ 'Cached field'($) {
3550
+ class App extends $mol_object2 {
3551
+ static $ = $;
3552
+ static low = 1;
3553
+ static get high() {
3554
+ return this.low + 1;
3655
3555
  }
3656
- output += this.type;
3657
- if (this.sub.length == 1) {
3658
- return output + ' ' + this.sub[0].toString(prefix);
3556
+ static set high(next) {
3557
+ this.low = next - 1;
3558
+ }
3559
+ static test() {
3560
+ $mol_assert_equal(App.high, 2);
3561
+ App.high = 3;
3562
+ $mol_assert_equal(App.high, 3);
3659
3563
  }
3660
- output += "\n";
3661
3564
  }
3662
- else if (this.data.length || prefix.length) {
3663
- output += "\\" + this.data + "\n";
3565
+ __decorate([
3566
+ $mol_wire_field
3567
+ ], App, "low", void 0);
3568
+ __decorate([
3569
+ $mol_wire_field
3570
+ ], App, "high", null);
3571
+ __decorate([
3572
+ $mol_wire_method
3573
+ ], App, "test", null);
3574
+ App.test();
3575
+ },
3576
+ });
3577
+ })($ || ($ = {}));
3578
+ //mol/wire/field/field.test.ts
3579
+ ;
3580
+ "use strict";
3581
+ var $;
3582
+ (function ($_1) {
3583
+ $mol_test({
3584
+ 'Watch one value'($) {
3585
+ class App extends $mol_object2 {
3586
+ static $ = $;
3587
+ static set = new $mol_wire_set();
3588
+ static lucky() {
3589
+ return this.set.has(777);
3590
+ }
3664
3591
  }
3665
- for (var child of this.sub) {
3666
- output += prefix;
3667
- output += child.toString(prefix + "\t");
3592
+ __decorate([
3593
+ $mol_wire_mem(0)
3594
+ ], App, "lucky", null);
3595
+ $mol_assert_equal(App.lucky(), false);
3596
+ App.set.add(666);
3597
+ $mol_assert_equal(App.lucky(), false);
3598
+ App.set.add(777);
3599
+ $mol_assert_equal(App.lucky(), true);
3600
+ App.set.delete(777);
3601
+ $mol_assert_equal(App.lucky(), false);
3602
+ },
3603
+ 'Watch item channel'($) {
3604
+ class App extends $mol_object2 {
3605
+ static $ = $;
3606
+ static set = new $mol_wire_set();
3607
+ static lucky() {
3608
+ return this.set.item(777);
3609
+ }
3668
3610
  }
3669
- return output;
3670
- }
3671
- toJSON() {
3672
- if (!this.type)
3673
- return this.value;
3674
- if (this.type === 'true')
3675
- return true;
3676
- if (this.type === 'false')
3677
- return false;
3678
- if (this.type === 'null')
3679
- return null;
3680
- if (this.type === '*') {
3681
- var obj = {};
3682
- for (var child of this.sub) {
3683
- if (child.type === '-')
3684
- continue;
3685
- var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
3686
- var val = child.sub[child.sub.length - 1].toJSON();
3687
- if (val !== undefined)
3688
- obj[key] = val;
3611
+ __decorate([
3612
+ $mol_wire_mem(0)
3613
+ ], App, "lucky", null);
3614
+ $mol_assert_equal(App.lucky(), false);
3615
+ App.set.item(666, true);
3616
+ $mol_assert_equal(App.lucky(), false);
3617
+ App.set.item(777, true);
3618
+ $mol_assert_equal(App.lucky(), true);
3619
+ App.set.item(777, false);
3620
+ $mol_assert_equal(App.lucky(), false);
3621
+ },
3622
+ 'Watch size'($) {
3623
+ class App extends $mol_object2 {
3624
+ static $ = $;
3625
+ static set = new $mol_wire_set();
3626
+ static size() {
3627
+ return this.set.size;
3628
+ }
3629
+ }
3630
+ __decorate([
3631
+ $mol_wire_mem(0)
3632
+ ], App, "size", null);
3633
+ $mol_assert_equal(App.size(), 0);
3634
+ App.set.add(666);
3635
+ $mol_assert_equal(App.size(), 1);
3636
+ App.set.add(777);
3637
+ $mol_assert_equal(App.size(), 2);
3638
+ App.set.delete(777);
3639
+ $mol_assert_equal(App.size(), 1);
3640
+ },
3641
+ 'Watch for-of'($) {
3642
+ class App extends $mol_object2 {
3643
+ static $ = $;
3644
+ static set = new $mol_wire_set();
3645
+ static sum() {
3646
+ let res = 0;
3647
+ for (const val of this.set) {
3648
+ res += val;
3649
+ }
3650
+ return res;
3689
3651
  }
3690
- return obj;
3691
- }
3692
- if (this.type === '/') {
3693
- var res = [];
3694
- this.sub.forEach(child => {
3695
- if (child.type === '-')
3696
- return;
3697
- var val = child.toJSON();
3698
- if (val !== undefined)
3699
- res.push(val);
3700
- });
3701
- return res;
3702
- }
3703
- if (this.type === 'time') {
3704
- return new Date(this.value);
3705
3652
  }
3706
- const numb = Number(this.type);
3707
- if (!Number.isNaN(numb) || this.type === 'NaN')
3708
- return numb;
3709
- throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
3710
- }
3711
- get value() {
3712
- var values = [];
3713
- for (var child of this.sub) {
3714
- if (child.type)
3715
- continue;
3716
- values.push(child.value);
3653
+ __decorate([
3654
+ $mol_wire_mem(0)
3655
+ ], App, "sum", null);
3656
+ $mol_assert_equal(App.sum(), 0);
3657
+ App.set.add(111);
3658
+ $mol_assert_equal(App.sum(), 111);
3659
+ App.set.add(222);
3660
+ $mol_assert_equal(App.sum(), 333);
3661
+ App.set.delete(111);
3662
+ $mol_assert_equal(App.sum(), 222);
3663
+ },
3664
+ 'Watch forEach'($) {
3665
+ class App extends $mol_object2 {
3666
+ static $ = $;
3667
+ static set = new $mol_wire_set();
3668
+ static sum() {
3669
+ let res = 0;
3670
+ this.set.forEach(val => res += val);
3671
+ return res;
3672
+ }
3717
3673
  }
3718
- return this.data + values.join("\n");
3719
- }
3720
- insert(value, ...path) {
3721
- if (path.length === 0)
3722
- return value;
3723
- const type = path[0];
3724
- if (typeof type === 'string') {
3725
- let replaced = false;
3726
- const sub = this.sub.map((item, index) => {
3727
- if (item.type !== type)
3728
- return item;
3729
- replaced = true;
3730
- return item.insert(value, ...path.slice(1));
3731
- });
3732
- if (!replaced)
3733
- sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
3734
- return this.clone({ sub });
3674
+ __decorate([
3675
+ $mol_wire_mem(0)
3676
+ ], App, "sum", null);
3677
+ $mol_assert_equal(App.sum(), 0);
3678
+ App.set.add(111);
3679
+ $mol_assert_equal(App.sum(), 111);
3680
+ App.set.add(222);
3681
+ $mol_assert_equal(App.sum(), 333);
3682
+ App.set.delete(111);
3683
+ $mol_assert_equal(App.sum(), 222);
3684
+ },
3685
+ });
3686
+ })($ || ($ = {}));
3687
+ //mol/wire/set/set.test.ts
3688
+ ;
3689
+ "use strict";
3690
+ var $;
3691
+ (function ($_1) {
3692
+ $mol_test({
3693
+ 'Watch one value'($) {
3694
+ class App extends $mol_object2 {
3695
+ static $ = $;
3696
+ static dict = new $mol_wire_dict();
3697
+ static lucky() {
3698
+ return this.dict.get(777);
3699
+ }
3735
3700
  }
3736
- else if (typeof type === 'number') {
3737
- const sub = this.sub.slice();
3738
- sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
3739
- return this.clone({ sub });
3701
+ __decorate([
3702
+ $mol_wire_mem(0)
3703
+ ], App, "lucky", null);
3704
+ $mol_assert_equal(App.lucky(), undefined);
3705
+ App.dict.set(666, 6666);
3706
+ $mol_assert_equal(App.lucky(), undefined);
3707
+ App.dict.set(777, 7777);
3708
+ $mol_assert_equal(App.lucky(), 7777);
3709
+ App.dict.delete(777);
3710
+ $mol_assert_equal(App.lucky(), undefined);
3711
+ },
3712
+ 'Watch item channel'($) {
3713
+ class App extends $mol_object2 {
3714
+ static $ = $;
3715
+ static dict = new $mol_wire_dict();
3716
+ static lucky() {
3717
+ return this.dict.item(777);
3718
+ }
3740
3719
  }
3741
- else {
3742
- return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
3720
+ __decorate([
3721
+ $mol_wire_mem(0)
3722
+ ], App, "lucky", null);
3723
+ $mol_assert_equal(App.lucky(), null);
3724
+ App.dict.item(666, 6666);
3725
+ $mol_assert_equal(App.lucky(), null);
3726
+ App.dict.item(777, 7777);
3727
+ $mol_assert_equal(App.lucky(), 7777);
3728
+ App.dict.item(777, null);
3729
+ $mol_assert_equal(App.lucky(), null);
3730
+ },
3731
+ 'Watch size'($) {
3732
+ class App extends $mol_object2 {
3733
+ static $ = $;
3734
+ static dict = new $mol_wire_dict();
3735
+ static size() {
3736
+ return this.dict.size;
3737
+ }
3743
3738
  }
3744
- }
3745
- select(...path) {
3746
- var next = [this];
3747
- for (var type of path) {
3748
- if (!next.length)
3749
- break;
3750
- var prev = next;
3751
- next = [];
3752
- for (var item of prev) {
3753
- switch (typeof (type)) {
3754
- case 'string':
3755
- for (var child of item.sub) {
3756
- if (!type || (child.type == type)) {
3757
- next.push(child);
3758
- }
3759
- }
3760
- break;
3761
- case 'number':
3762
- if (type < item.sub.length)
3763
- next.push(item.sub[type]);
3764
- break;
3765
- default: next.push(...item.sub);
3739
+ __decorate([
3740
+ $mol_wire_mem(0)
3741
+ ], App, "size", null);
3742
+ $mol_assert_equal(App.size(), 0);
3743
+ App.dict.set(666, 6666);
3744
+ $mol_assert_equal(App.size(), 1);
3745
+ App.dict.set(777, 7777);
3746
+ $mol_assert_equal(App.size(), 2);
3747
+ App.dict.delete(777);
3748
+ $mol_assert_equal(App.size(), 1);
3749
+ },
3750
+ 'Watch for-of'($) {
3751
+ class App extends $mol_object2 {
3752
+ static $ = $;
3753
+ static dict = new $mol_wire_dict();
3754
+ static sum() {
3755
+ let keys = 0;
3756
+ let vals = 0;
3757
+ for (const [key, val] of this.dict) {
3758
+ keys += key;
3759
+ vals += val;
3766
3760
  }
3761
+ return [keys, vals];
3767
3762
  }
3768
3763
  }
3769
- return new $mol_tree({ sub: next });
3770
- }
3771
- filter(path, value) {
3772
- var sub = this.sub.filter(function (item) {
3773
- var found = item.select(...path);
3774
- if (value == null) {
3775
- return Boolean(found.sub.length);
3776
- }
3777
- else {
3778
- return found.sub.some(child => child.value == value);
3764
+ __decorate([
3765
+ $mol_wire_mem(0)
3766
+ ], App, "sum", null);
3767
+ $mol_assert_like(App.sum(), [0, 0]);
3768
+ App.dict.set(111, 1111);
3769
+ $mol_assert_like(App.sum(), [111, 1111]);
3770
+ App.dict.set(222, 2222);
3771
+ $mol_assert_like(App.sum(), [333, 3333]);
3772
+ App.dict.delete(111);
3773
+ $mol_assert_like(App.sum(), [222, 2222]);
3774
+ },
3775
+ 'Watch forEach'($) {
3776
+ class App extends $mol_object2 {
3777
+ static $ = $;
3778
+ static dict = new $mol_wire_dict();
3779
+ static sum() {
3780
+ let keys = 0;
3781
+ let vals = 0;
3782
+ this.dict.forEach((val, key) => {
3783
+ keys += key;
3784
+ vals += val;
3785
+ });
3786
+ return [keys, vals];
3779
3787
  }
3780
- });
3781
- return new $mol_tree({ sub: sub });
3782
- }
3783
- transform(visit, stack = []) {
3784
- const sub_stack = [this, ...stack];
3785
- return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
3786
- }
3787
- hack(context) {
3788
- const sub = [].concat(...this.sub.map(child => {
3789
- const handle = context[child.type] || context[''];
3790
- if (!handle)
3791
- $mol_fail(child.error('Handler not defined'));
3792
- return handle(child, context);
3793
- }));
3794
- return this.clone({ sub });
3795
- }
3796
- error(message) {
3797
- return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
3798
- }
3799
- }
3800
- __decorate([
3801
- $mol_deprecated('Use $mol_tree:hack')
3802
- ], $mol_tree.prototype, "transform", null);
3803
- $.$mol_tree = $mol_tree;
3788
+ }
3789
+ __decorate([
3790
+ $mol_wire_mem(0)
3791
+ ], App, "sum", null);
3792
+ $mol_assert_like(App.sum(), [0, 0]);
3793
+ App.dict.set(111, 1111);
3794
+ $mol_assert_like(App.sum(), [111, 1111]);
3795
+ App.dict.set(222, 2222);
3796
+ $mol_assert_like(App.sum(), [333, 3333]);
3797
+ App.dict.delete(111);
3798
+ $mol_assert_like(App.sum(), [222, 2222]);
3799
+ },
3800
+ });
3804
3801
  })($ || ($ = {}));
3805
- //mol/tree/tree.ts
3806
- ;
3807
- "use strict";
3808
- //mol/type/equals/equals.test.ts
3809
- ;
3810
- "use strict";
3811
- //mol/type/equals/equals.ts
3802
+ //mol/wire/dict/dict.test.ts
3812
3803
 
3813
3804
  //# sourceMappingURL=node.test.js.map