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