hyoo_sync_client 0.0.365 → 0.0.367

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
@@ -2805,6 +2805,410 @@ var $;
2805
2805
  $.$mol_state_local = $mol_state_local;
2806
2806
  })($ || ($ = {}));
2807
2807
 
2808
+ ;
2809
+ "use strict";
2810
+ var $;
2811
+ (function ($) {
2812
+ class $mol_file_not_found extends Error {
2813
+ }
2814
+ $.$mol_file_not_found = $mol_file_not_found;
2815
+ class $mol_file extends $mol_object {
2816
+ static absolute(path) {
2817
+ throw new Error('Not implemented yet');
2818
+ }
2819
+ static relative(path) {
2820
+ throw new Error('Not implemented yet');
2821
+ }
2822
+ static base = '';
2823
+ path() {
2824
+ return '.';
2825
+ }
2826
+ parent() {
2827
+ return this.resolve('..');
2828
+ }
2829
+ reset() {
2830
+ try {
2831
+ this.stat(null);
2832
+ }
2833
+ catch (error) {
2834
+ if (error instanceof $mol_file_not_found)
2835
+ return;
2836
+ return $mol_fail_hidden(error);
2837
+ }
2838
+ }
2839
+ version() {
2840
+ return this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
2841
+ }
2842
+ watcher() {
2843
+ console.warn('$mol_file_web.watcher() not implemented');
2844
+ return {
2845
+ destructor() { }
2846
+ };
2847
+ }
2848
+ exists(next) {
2849
+ let exists = Boolean(this.stat());
2850
+ if (next === undefined)
2851
+ return exists;
2852
+ if (next === exists)
2853
+ return exists;
2854
+ if (next) {
2855
+ this.parent().exists(true);
2856
+ this.ensure();
2857
+ }
2858
+ else {
2859
+ this.drop();
2860
+ }
2861
+ this.reset();
2862
+ return next;
2863
+ }
2864
+ type() {
2865
+ return this.stat()?.type ?? '';
2866
+ }
2867
+ name() {
2868
+ return this.path().replace(/^.*\//, '');
2869
+ }
2870
+ ext() {
2871
+ const match = /((?:\.\w+)+)$/.exec(this.path());
2872
+ return match ? match[1].substring(1) : '';
2873
+ }
2874
+ text(next, virt) {
2875
+ if (virt) {
2876
+ const now = new Date;
2877
+ this.stat({
2878
+ type: 'file',
2879
+ size: 0,
2880
+ atime: now,
2881
+ mtime: now,
2882
+ ctime: now,
2883
+ }, 'virt');
2884
+ return next;
2885
+ }
2886
+ if (next === undefined) {
2887
+ return $mol_charset_decode(this.buffer(undefined));
2888
+ }
2889
+ else {
2890
+ const buffer = next === undefined ? undefined : $mol_charset_encode(next);
2891
+ this.buffer(buffer);
2892
+ return next;
2893
+ }
2894
+ }
2895
+ find(include, exclude) {
2896
+ const found = [];
2897
+ const sub = this.sub();
2898
+ for (const child of sub) {
2899
+ const child_path = child.path();
2900
+ if (exclude && child_path.match(exclude))
2901
+ continue;
2902
+ if (!include || child_path.match(include))
2903
+ found.push(child);
2904
+ if (child.type() === 'dir') {
2905
+ const sub_child = child.find(include, exclude);
2906
+ for (const child of sub_child)
2907
+ found.push(child);
2908
+ }
2909
+ }
2910
+ return found;
2911
+ }
2912
+ size() {
2913
+ switch (this.type()) {
2914
+ case 'file': return this.stat()?.size ?? 0;
2915
+ default: return 0;
2916
+ }
2917
+ }
2918
+ open(...modes) {
2919
+ return 0;
2920
+ }
2921
+ toJSON() {
2922
+ return this.path();
2923
+ }
2924
+ }
2925
+ __decorate([
2926
+ $mol_mem
2927
+ ], $mol_file.prototype, "exists", null);
2928
+ __decorate([
2929
+ $mol_mem
2930
+ ], $mol_file.prototype, "text", null);
2931
+ __decorate([
2932
+ $mol_mem_key
2933
+ ], $mol_file, "absolute", null);
2934
+ $.$mol_file = $mol_file;
2935
+ })($ || ($ = {}));
2936
+
2937
+ ;
2938
+ "use strict";
2939
+ var $;
2940
+ (function ($) {
2941
+ function $mol_const(value) {
2942
+ const getter = (() => value);
2943
+ getter['()'] = value;
2944
+ getter[Symbol.toStringTag] = value;
2945
+ getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
2946
+ return getter;
2947
+ }
2948
+ $.$mol_const = $mol_const;
2949
+ })($ || ($ = {}));
2950
+
2951
+ ;
2952
+ "use strict";
2953
+ var $;
2954
+ (function ($) {
2955
+ $.$mol_action = $mol_wire_method;
2956
+ })($ || ($ = {}));
2957
+
2958
+ ;
2959
+ "use strict";
2960
+ var $;
2961
+ (function ($) {
2962
+ function $mol_compare_array(a, b) {
2963
+ if (a === b)
2964
+ return true;
2965
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
2966
+ return false;
2967
+ if (a.length !== b.length)
2968
+ return false;
2969
+ for (let i = 0; i < a.length; i++)
2970
+ if (a[i] !== b[i])
2971
+ return false;
2972
+ return true;
2973
+ }
2974
+ $.$mol_compare_array = $mol_compare_array;
2975
+ })($ || ($ = {}));
2976
+
2977
+ ;
2978
+ "use strict";
2979
+ var $;
2980
+ (function ($) {
2981
+ function stat_convert(stat) {
2982
+ if (!stat)
2983
+ return null;
2984
+ let type;
2985
+ if (stat.isDirectory())
2986
+ type = 'dir';
2987
+ if (stat.isFile())
2988
+ type = 'file';
2989
+ if (stat.isSymbolicLink())
2990
+ type = 'link';
2991
+ if (!type)
2992
+ return $mol_fail(new Error(`Unsupported file type`));
2993
+ return {
2994
+ type,
2995
+ size: Number(stat.size),
2996
+ atime: stat.atime,
2997
+ mtime: stat.mtime,
2998
+ ctime: stat.ctime
2999
+ };
3000
+ }
3001
+ function buffer_normalize(buf) {
3002
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
3003
+ }
3004
+ let $mol_file_mode_open;
3005
+ (function ($mol_file_mode_open) {
3006
+ $mol_file_mode_open[$mol_file_mode_open["create"] = $node.fs.constants.O_CREAT] = "create";
3007
+ $mol_file_mode_open[$mol_file_mode_open["exists_truncate"] = $node.fs.constants.O_TRUNC] = "exists_truncate";
3008
+ $mol_file_mode_open[$mol_file_mode_open["exists_fail"] = $node.fs.constants.O_EXCL] = "exists_fail";
3009
+ $mol_file_mode_open[$mol_file_mode_open["read_only"] = $node.fs.constants.O_RDONLY] = "read_only";
3010
+ $mol_file_mode_open[$mol_file_mode_open["write_only"] = $node.fs.constants.O_WRONLY] = "write_only";
3011
+ $mol_file_mode_open[$mol_file_mode_open["read_write"] = $node.fs.constants.O_RDWR] = "read_write";
3012
+ $mol_file_mode_open[$mol_file_mode_open["append"] = $node.fs.constants.O_APPEND] = "append";
3013
+ })($mol_file_mode_open = $.$mol_file_mode_open || ($.$mol_file_mode_open = {}));
3014
+ class $mol_file_node extends $mol_file {
3015
+ static absolute(path) {
3016
+ return this.make({
3017
+ path: $mol_const(path)
3018
+ });
3019
+ }
3020
+ static relative(path) {
3021
+ return this.absolute($node.path.resolve(this.base, path).replace(/\\/g, '/'));
3022
+ }
3023
+ watcher() {
3024
+ const watcher = $node.chokidar.watch(this.path(), {
3025
+ persistent: true,
3026
+ ignored: /(^\.|___$)/,
3027
+ depth: 0,
3028
+ ignoreInitial: true,
3029
+ awaitWriteFinish: {
3030
+ stabilityThreshold: 100,
3031
+ },
3032
+ });
3033
+ watcher
3034
+ .on('all', (type, path) => {
3035
+ const file = $mol_file.relative(path.replace(/\\/g, '/'));
3036
+ file.reset();
3037
+ if (type === 'change') {
3038
+ this.stat(null);
3039
+ }
3040
+ else {
3041
+ file.parent().reset();
3042
+ }
3043
+ })
3044
+ .on('error', $mol_fail_log);
3045
+ return {
3046
+ destructor() {
3047
+ watcher.close();
3048
+ }
3049
+ };
3050
+ }
3051
+ stat(next, virt) {
3052
+ let stat = next;
3053
+ const path = this.path();
3054
+ this.parent().watcher();
3055
+ if (virt)
3056
+ return next;
3057
+ try {
3058
+ stat = next ?? stat_convert($node.fs.statSync(path, { throwIfNoEntry: false }));
3059
+ }
3060
+ catch (error) {
3061
+ if (error.code === 'ENOENT')
3062
+ error = new $mol_file_not_found(`File not found`);
3063
+ error.message += '\n' + path;
3064
+ return this.$.$mol_fail_hidden(error);
3065
+ }
3066
+ return stat;
3067
+ }
3068
+ ensure() {
3069
+ const path = this.path();
3070
+ try {
3071
+ $node.fs.mkdirSync(path);
3072
+ }
3073
+ catch (e) {
3074
+ e.message += '\n' + path;
3075
+ this.$.$mol_fail_hidden(e);
3076
+ }
3077
+ }
3078
+ drop() {
3079
+ $node.fs.unlinkSync(this.path());
3080
+ }
3081
+ buffer(next) {
3082
+ const path = this.path();
3083
+ if (next === undefined) {
3084
+ if (!this.stat())
3085
+ return new Uint8Array;
3086
+ try {
3087
+ const prev = $mol_mem_cached(() => this.buffer());
3088
+ next = buffer_normalize($node.fs.readFileSync(path));
3089
+ if (prev !== undefined && !$mol_compare_array(prev, next)) {
3090
+ this.$.$mol_log3_rise({
3091
+ place: `$mol_file_node..buffer()`,
3092
+ message: 'Changed',
3093
+ path: this.relate(),
3094
+ });
3095
+ }
3096
+ return next;
3097
+ }
3098
+ catch (error) {
3099
+ error.message += '\n' + path;
3100
+ return this.$.$mol_fail_hidden(error);
3101
+ }
3102
+ }
3103
+ this.parent().exists(true);
3104
+ const now = new Date;
3105
+ this.stat({
3106
+ type: 'file',
3107
+ size: next.length,
3108
+ atime: now,
3109
+ mtime: now,
3110
+ ctime: now,
3111
+ }, 'virt');
3112
+ try {
3113
+ $node.fs.writeFileSync(path, next);
3114
+ }
3115
+ catch (error) {
3116
+ error.message += '\n' + path;
3117
+ return this.$.$mol_fail_hidden(error);
3118
+ }
3119
+ return next;
3120
+ }
3121
+ sub() {
3122
+ if (!this.exists())
3123
+ return [];
3124
+ if (this.type() !== 'dir')
3125
+ return [];
3126
+ const path = this.path();
3127
+ this.stat();
3128
+ try {
3129
+ return $node.fs.readdirSync(path)
3130
+ .filter(name => !/^\.+$/.test(name))
3131
+ .map(name => this.resolve(name));
3132
+ }
3133
+ catch (e) {
3134
+ e.message += '\n' + path;
3135
+ return this.$.$mol_fail_hidden(e);
3136
+ }
3137
+ }
3138
+ resolve(path) {
3139
+ return this.constructor.relative($node.path.join(this.path(), path));
3140
+ }
3141
+ relate(base = this.constructor.relative('.')) {
3142
+ return $node.path.relative(base.path(), this.path()).replace(/\\/g, '/');
3143
+ }
3144
+ append(next) {
3145
+ const path = this.path();
3146
+ try {
3147
+ $node.fs.appendFileSync(path, next);
3148
+ }
3149
+ catch (e) {
3150
+ e.message += '\n' + path;
3151
+ return this.$.$mol_fail_hidden(e);
3152
+ }
3153
+ }
3154
+ open(...modes) {
3155
+ return $node.fs.openSync(this.path(), modes.reduce((res, mode) => res | $mol_file_mode_open[mode], 0));
3156
+ }
3157
+ }
3158
+ __decorate([
3159
+ $mol_mem
3160
+ ], $mol_file_node.prototype, "watcher", null);
3161
+ __decorate([
3162
+ $mol_mem
3163
+ ], $mol_file_node.prototype, "stat", null);
3164
+ __decorate([
3165
+ $mol_mem
3166
+ ], $mol_file_node.prototype, "ensure", null);
3167
+ __decorate([
3168
+ $mol_action
3169
+ ], $mol_file_node.prototype, "drop", null);
3170
+ __decorate([
3171
+ $mol_mem
3172
+ ], $mol_file_node.prototype, "buffer", null);
3173
+ __decorate([
3174
+ $mol_mem
3175
+ ], $mol_file_node.prototype, "sub", null);
3176
+ __decorate([
3177
+ $mol_mem_key
3178
+ ], $mol_file_node, "absolute", null);
3179
+ $.$mol_file_node = $mol_file_node;
3180
+ $.$mol_file = $mol_file_node;
3181
+ })($ || ($ = {}));
3182
+
3183
+ ;
3184
+ "use strict";
3185
+ var $;
3186
+ (function ($) {
3187
+ class $mol_state_local_node extends $mol_state_local {
3188
+ static dir() {
3189
+ const base = process.env.XDG_DATA_HOME || ($node.os.homedir() + '/.local/share');
3190
+ return $mol_file.absolute(base).resolve('./hyoo_state_local');
3191
+ }
3192
+ static value(key, next) {
3193
+ const file = this.dir().resolve(encodeURIComponent(key) + '.json');
3194
+ if (next === null) {
3195
+ file.exists(false);
3196
+ return null;
3197
+ }
3198
+ const arg = next === undefined ? undefined : JSON.stringify(next);
3199
+ return JSON.parse(file.text(arg) || 'null');
3200
+ }
3201
+ }
3202
+ __decorate([
3203
+ $mol_mem
3204
+ ], $mol_state_local_node, "dir", null);
3205
+ __decorate([
3206
+ $mol_mem_key
3207
+ ], $mol_state_local_node, "value", null);
3208
+ $.$mol_state_local_node = $mol_state_local_node;
3209
+ $.$mol_state_local = $mol_state_local_node;
3210
+ })($ || ($ = {}));
3211
+
2808
3212
  ;
2809
3213
  "use strict";
2810
3214
  var $;
@@ -3113,20 +3517,6 @@ var $;
3113
3517
  $.$hyoo_crowd_struct = $hyoo_crowd_struct;
3114
3518
  })($ || ($ = {}));
3115
3519
 
3116
- ;
3117
- "use strict";
3118
- var $;
3119
- (function ($) {
3120
- function $mol_const(value) {
3121
- const getter = (() => value);
3122
- getter['()'] = value;
3123
- getter[Symbol.toStringTag] = value;
3124
- getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
3125
- return getter;
3126
- }
3127
- $.$mol_const = $mol_const;
3128
- })($ || ($ = {}));
3129
-
3130
3520
  ;
3131
3521
  "use strict";
3132
3522
  var $;
@@ -3482,13 +3872,6 @@ var $;
3482
3872
  $.$hyoo_crowd_land = $hyoo_crowd_land;
3483
3873
  })($ || ($ = {}));
3484
3874
 
3485
- ;
3486
- "use strict";
3487
- var $;
3488
- (function ($) {
3489
- $.$mol_action = $mol_wire_method;
3490
- })($ || ($ = {}));
3491
-
3492
3875
  ;
3493
3876
  "use strict";
3494
3877
  var $;
@@ -6765,6 +7148,37 @@ var $;
6765
7148
  });
6766
7149
  })($ || ($ = {}));
6767
7150
 
7151
+ ;
7152
+ "use strict";
7153
+ var $;
7154
+ (function ($) {
7155
+ $mol_test({
7156
+ 'const returns stored value'() {
7157
+ const foo = { bar: $mol_const(Math.random()) };
7158
+ $mol_assert_equal(foo.bar(), foo.bar());
7159
+ $mol_assert_equal(foo.bar(), foo.bar['()']);
7160
+ },
7161
+ });
7162
+ })($ || ($ = {}));
7163
+
7164
+ ;
7165
+ "use strict";
7166
+ var $;
7167
+ (function ($) {
7168
+ class TestClass extends Uint8Array {
7169
+ }
7170
+ $mol_test({
7171
+ 'Uint8Array vs itself'() {
7172
+ $mol_assert_ok($mol_compare_array(new Uint8Array, new Uint8Array));
7173
+ $mol_assert_ok($mol_compare_array(new Uint8Array([0]), new Uint8Array([0])));
7174
+ $mol_assert_not($mol_compare_array(new Uint8Array([0]), new Uint8Array([1])));
7175
+ },
7176
+ 'Uint8Array vs subclassed array'() {
7177
+ $mol_assert_not($mol_compare_array(new Uint8Array, new TestClass));
7178
+ },
7179
+ });
7180
+ })($ || ($ = {}));
7181
+
6768
7182
  ;
6769
7183
  "use strict";
6770
7184
  var $;
@@ -7018,19 +7432,6 @@ var $;
7018
7432
  });
7019
7433
  })($ || ($ = {}));
7020
7434
 
7021
- ;
7022
- "use strict";
7023
- var $;
7024
- (function ($) {
7025
- $mol_test({
7026
- 'const returns stored value'() {
7027
- const foo = { bar: $mol_const(Math.random()) };
7028
- $mol_assert_equal(foo.bar(), foo.bar());
7029
- $mol_assert_equal(foo.bar(), foo.bar['()']);
7030
- },
7031
- });
7032
- })($ || ($ = {}));
7033
-
7034
7435
  ;
7035
7436
  "use strict";
7036
7437
  var $;