mol_dump_lib 0.0.539 → 0.0.541

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/web.js CHANGED
@@ -4740,6 +4740,65 @@ var $;
4740
4740
  self.addEventListener('storage', event => $.$mol_state_local.changes(event));
4741
4741
  })($ || ($ = {}));
4742
4742
 
4743
+ ;
4744
+ "use strict";
4745
+ var $;
4746
+ (function ($) {
4747
+ $.$mol_action = $mol_wire_method;
4748
+ })($ || ($ = {}));
4749
+
4750
+ ;
4751
+ "use strict";
4752
+ var $;
4753
+ (function ($) {
4754
+ class $mol_lock extends $mol_object {
4755
+ promise = null;
4756
+ async wait() {
4757
+ let next = () => { };
4758
+ let destructed = false;
4759
+ const task = $mol_wire_auto();
4760
+ if (!task)
4761
+ return next;
4762
+ const destructor = task.destructor.bind(task);
4763
+ task.destructor = () => {
4764
+ destructor();
4765
+ destructed = true;
4766
+ next();
4767
+ };
4768
+ let promise;
4769
+ do {
4770
+ promise = this.promise;
4771
+ await promise;
4772
+ if (destructed)
4773
+ return next;
4774
+ } while (promise !== this.promise);
4775
+ this.promise = new Promise(done => { next = done; });
4776
+ return next;
4777
+ }
4778
+ grab() { return $mol_wire_sync(this).wait(); }
4779
+ }
4780
+ $.$mol_lock = $mol_lock;
4781
+ })($ || ($ = {}));
4782
+
4783
+ ;
4784
+ "use strict";
4785
+ var $;
4786
+ (function ($) {
4787
+ function $mol_compare_array(a, b) {
4788
+ if (a === b)
4789
+ return true;
4790
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
4791
+ return false;
4792
+ if (a.length !== b.length)
4793
+ return false;
4794
+ for (let i = 0; i < a.length; i++)
4795
+ if (a[i] !== b[i])
4796
+ return false;
4797
+ return true;
4798
+ }
4799
+ $.$mol_compare_array = $mol_compare_array;
4800
+ })($ || ($ = {}));
4801
+
4743
4802
  ;
4744
4803
  "use strict";
4745
4804
 
@@ -4773,12 +4832,55 @@ var $;
4773
4832
  "use strict";
4774
4833
  var $;
4775
4834
  (function ($) {
4776
- class $mol_file_not_found extends Error {
4835
+ class $mol_file_transaction extends $mol_object {
4836
+ path() { return ''; }
4837
+ modes() { return []; }
4838
+ write(options) {
4839
+ return 0;
4840
+ }
4841
+ read() {
4842
+ return new Uint8Array();
4843
+ }
4844
+ truncate(size) { }
4845
+ close() { }
4846
+ destructor() {
4847
+ this.close();
4848
+ }
4777
4849
  }
4778
- $.$mol_file_not_found = $mol_file_not_found;
4779
- class $mol_file extends $mol_object {
4850
+ $.$mol_file_transaction = $mol_file_transaction;
4851
+ })($ || ($ = {}));
4852
+
4853
+ ;
4854
+ "use strict";
4855
+ var $;
4856
+ (function ($) {
4857
+ class $mol_file_transaction_web extends $mol_file_transaction {
4858
+ write(options) {
4859
+ throw new Error('Not implemented');
4860
+ }
4861
+ truncate(size) {
4862
+ throw new Error('Not implemented');
4863
+ }
4864
+ read() {
4865
+ throw new Error('Not implemented');
4866
+ }
4867
+ close() {
4868
+ throw new Error('Not implemented');
4869
+ }
4870
+ }
4871
+ $.$mol_file_transaction_web = $mol_file_transaction_web;
4872
+ $.$mol_file_transaction = $mol_file_transaction_web;
4873
+ })($ || ($ = {}));
4874
+
4875
+ ;
4876
+ "use strict";
4877
+ var $;
4878
+ (function ($) {
4879
+ class $mol_file_base extends $mol_object {
4780
4880
  static absolute(path) {
4781
- throw new Error('Not implemented yet');
4881
+ return this.make({
4882
+ path: $mol_const(path)
4883
+ });
4782
4884
  }
4783
4885
  static relative(path) {
4784
4886
  throw new Error('Not implemented yet');
@@ -4790,27 +4892,164 @@ var $;
4790
4892
  parent() {
4791
4893
  return this.resolve('..');
4792
4894
  }
4895
+ exists_cut() { return this.exists(); }
4896
+ root() {
4897
+ const path = this.path();
4898
+ const base = this.constructor.base;
4899
+ return base.startsWith(path) || this == this.parent();
4900
+ }
4901
+ stat(next, virt) {
4902
+ const path = this.path();
4903
+ const parent = this.parent();
4904
+ if (!this.root()) {
4905
+ parent.version();
4906
+ }
4907
+ parent.watcher();
4908
+ if (virt)
4909
+ return next ?? null;
4910
+ return next ?? this.info(path);
4911
+ }
4912
+ static changed = new Set;
4913
+ static frame = null;
4914
+ static changed_add(type, path) {
4915
+ if (/([\/\\]\.|___$)/.test(path))
4916
+ return;
4917
+ const file = this.relative(path.at(-1) === '/' ? path.slice(0, -1) : path);
4918
+ this.changed.add(file);
4919
+ if (!this.watching)
4920
+ return;
4921
+ this.frame?.destructor();
4922
+ this.frame = new this.$.$mol_after_timeout(this.watch_debounce(), () => {
4923
+ if (!this.watching)
4924
+ return;
4925
+ this.watching = false;
4926
+ $mol_wire_async(this).flush();
4927
+ });
4928
+ }
4929
+ static watch_debounce() { return 500; }
4930
+ static flush() {
4931
+ for (const file of this.changed) {
4932
+ const parent = file.parent();
4933
+ try {
4934
+ if ($mol_wire_probe(() => parent.sub()))
4935
+ parent.sub(null);
4936
+ file.reset();
4937
+ }
4938
+ catch (error) {
4939
+ if ($mol_fail_catch(error))
4940
+ $mol_fail_log(error);
4941
+ }
4942
+ }
4943
+ this.changed.clear();
4944
+ this.watching = true;
4945
+ }
4946
+ static watching = true;
4947
+ static lock = new $mol_lock;
4948
+ static watch_off(path) {
4949
+ this.watching = false;
4950
+ this.flush();
4951
+ this.watching = false;
4952
+ this.changed.add(this.absolute(path));
4953
+ }
4954
+ static unwatched(side_effect, affected_dir) {
4955
+ const unlock = this.lock.grab();
4956
+ this.watch_off(affected_dir);
4957
+ try {
4958
+ const result = side_effect();
4959
+ this.flush();
4960
+ unlock();
4961
+ return result;
4962
+ }
4963
+ catch (e) {
4964
+ if (!$mol_promise_like(e)) {
4965
+ this.flush();
4966
+ unlock();
4967
+ }
4968
+ $mol_fail_hidden(e);
4969
+ }
4970
+ }
4793
4971
  reset() {
4972
+ this.stat(null);
4973
+ }
4974
+ modified() { return this.stat()?.mtime ?? null; }
4975
+ version() {
4976
+ const next = this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
4977
+ return next;
4978
+ }
4979
+ info(path) { return null; }
4980
+ ensure() { }
4981
+ drop() { }
4982
+ copy(to) { }
4983
+ read() { return new Uint8Array; }
4984
+ write(buffer) { }
4985
+ kids() {
4986
+ return [];
4987
+ }
4988
+ readable(opts) {
4989
+ return new ReadableStream;
4990
+ }
4991
+ writable(opts) {
4992
+ return new WritableStream;
4993
+ }
4994
+ buffer(next) {
4995
+ let readed = new Uint8Array();
4996
+ if (next === undefined) {
4997
+ if (this.version())
4998
+ readed = this.read();
4999
+ }
5000
+ const prev = $mol_mem_cached(() => this.buffer());
5001
+ const changed = prev === undefined || !$mol_compare_array(prev, next ?? readed);
5002
+ if (prev !== undefined && changed) {
5003
+ this.$.$mol_log3_rise({
5004
+ place: `$mol_file_node.buffer()`,
5005
+ message: 'Changed',
5006
+ path: this.relate(),
5007
+ });
5008
+ }
5009
+ if (next === undefined)
5010
+ return changed ? readed : prev;
5011
+ if (!changed && this.exists())
5012
+ return prev;
5013
+ this.parent().exists(true);
5014
+ this.stat(this.stat_make(next.length), 'virt');
5015
+ this.write(next);
5016
+ return next;
5017
+ }
5018
+ stat_make(size) {
5019
+ const now = new Date();
5020
+ return {
5021
+ type: 'file',
5022
+ size,
5023
+ atime: now,
5024
+ mtime: now,
5025
+ ctime: now,
5026
+ };
5027
+ }
5028
+ clone(to) {
5029
+ if (!this.exists())
5030
+ return null;
5031
+ const target = this.constructor.absolute(to);
4794
5032
  try {
4795
- this.stat(null);
5033
+ this.version();
5034
+ target.parent().exists(true);
5035
+ this.copy(to);
5036
+ target.reset();
5037
+ return target;
4796
5038
  }
4797
5039
  catch (error) {
4798
- if (error instanceof $mol_file_not_found)
4799
- return;
4800
- return $mol_fail_hidden(error);
5040
+ if ($mol_fail_catch(error)) {
5041
+ console.error(error);
5042
+ }
4801
5043
  }
4802
- }
4803
- version() {
4804
- return this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
5044
+ return null;
4805
5045
  }
4806
5046
  watcher() {
4807
- console.warn('$mol_file_web.watcher() not implemented');
4808
5047
  return {
4809
5048
  destructor() { }
4810
5049
  };
4811
5050
  }
4812
5051
  exists(next) {
4813
- let exists = Boolean(this.stat());
5052
+ const exists = Boolean(this.stat());
4814
5053
  if (next === undefined)
4815
5054
  return exists;
4816
5055
  if (next === exists)
@@ -4836,26 +5075,40 @@ var $;
4836
5075
  return match ? match[1].substring(1) : '';
4837
5076
  }
4838
5077
  text(next, virt) {
5078
+ if (next !== undefined)
5079
+ this.exists();
5080
+ return this.text_int(next, virt);
5081
+ }
5082
+ text_int(next, virt) {
4839
5083
  if (virt) {
4840
- const now = new Date;
4841
- this.stat({
4842
- type: 'file',
4843
- size: 0,
4844
- atime: now,
4845
- mtime: now,
4846
- ctime: now,
4847
- }, 'virt');
5084
+ this.stat(this.stat_make(0), 'virt');
4848
5085
  return next;
4849
5086
  }
4850
5087
  if (next === undefined) {
4851
- return $mol_charset_decode(this.buffer(undefined));
5088
+ return $mol_charset_decode(this.buffer());
4852
5089
  }
4853
5090
  else {
4854
- const buffer = next === undefined ? undefined : $mol_charset_encode(next);
5091
+ const buffer = $mol_charset_encode(next);
4855
5092
  this.buffer(buffer);
4856
5093
  return next;
4857
5094
  }
4858
5095
  }
5096
+ sub(reset) {
5097
+ if (!this.exists())
5098
+ return [];
5099
+ if (this.type() !== 'dir')
5100
+ return [];
5101
+ this.version();
5102
+ return this.kids().filter(file => file.exists());
5103
+ }
5104
+ resolve(path) {
5105
+ throw new Error('implement');
5106
+ }
5107
+ relate(base = this.constructor.relative('.')) {
5108
+ const base_path = base.path();
5109
+ const path = this.path();
5110
+ return path.startsWith(base_path) ? path.slice(base_path.length) : path;
5111
+ }
4859
5112
  find(include, exclude) {
4860
5113
  const found = [];
4861
5114
  const sub = this.sub();
@@ -4879,30 +5132,80 @@ var $;
4879
5132
  default: return 0;
4880
5133
  }
4881
5134
  }
4882
- open(...modes) {
4883
- return 0;
4884
- }
4885
5135
  toJSON() {
4886
5136
  return this.path();
4887
5137
  }
5138
+ open(...modes) {
5139
+ return this.$.$mol_file_transaction.make({
5140
+ path: () => this.path(),
5141
+ modes: () => modes
5142
+ });
5143
+ }
4888
5144
  }
5145
+ __decorate([
5146
+ $mol_action
5147
+ ], $mol_file_base.prototype, "exists_cut", null);
4889
5148
  __decorate([
4890
5149
  $mol_mem
4891
- ], $mol_file.prototype, "exists", null);
5150
+ ], $mol_file_base.prototype, "stat", null);
4892
5151
  __decorate([
4893
5152
  $mol_mem
4894
- ], $mol_file.prototype, "text", null);
5153
+ ], $mol_file_base.prototype, "modified", null);
5154
+ __decorate([
5155
+ $mol_mem
5156
+ ], $mol_file_base.prototype, "version", null);
4895
5157
  __decorate([
4896
5158
  $mol_mem_key
4897
- ], $mol_file, "absolute", null);
4898
- $.$mol_file = $mol_file;
5159
+ ], $mol_file_base.prototype, "readable", null);
5160
+ __decorate([
5161
+ $mol_mem_key
5162
+ ], $mol_file_base.prototype, "writable", null);
5163
+ __decorate([
5164
+ $mol_mem
5165
+ ], $mol_file_base.prototype, "buffer", null);
5166
+ __decorate([
5167
+ $mol_action
5168
+ ], $mol_file_base.prototype, "stat_make", null);
5169
+ __decorate([
5170
+ $mol_mem_key
5171
+ ], $mol_file_base.prototype, "clone", null);
5172
+ __decorate([
5173
+ $mol_mem
5174
+ ], $mol_file_base.prototype, "exists", null);
5175
+ __decorate([
5176
+ $mol_mem
5177
+ ], $mol_file_base.prototype, "type", null);
5178
+ __decorate([
5179
+ $mol_mem
5180
+ ], $mol_file_base.prototype, "text_int", null);
5181
+ __decorate([
5182
+ $mol_mem
5183
+ ], $mol_file_base.prototype, "sub", null);
5184
+ __decorate([
5185
+ $mol_mem
5186
+ ], $mol_file_base.prototype, "size", null);
5187
+ __decorate([
5188
+ $mol_action
5189
+ ], $mol_file_base.prototype, "open", null);
5190
+ __decorate([
5191
+ $mol_mem_key
5192
+ ], $mol_file_base, "absolute", null);
5193
+ __decorate([
5194
+ $mol_action
5195
+ ], $mol_file_base, "flush", null);
5196
+ __decorate([
5197
+ $mol_action
5198
+ ], $mol_file_base, "watch_off", null);
5199
+ $.$mol_file_base = $mol_file_base;
4899
5200
  })($ || ($ = {}));
4900
5201
 
4901
5202
  ;
4902
5203
  "use strict";
4903
5204
  var $;
4904
5205
  (function ($) {
4905
- $.$mol_action = $mol_wire_method;
5206
+ class $mol_file extends $mol_file_base {
5207
+ }
5208
+ $.$mol_file = $mol_file;
4906
5209
  })($ || ($ = {}));
4907
5210
 
4908
5211
  ;
@@ -4996,7 +5299,7 @@ var $;
4996
5299
  static request(input, init = {}) {
4997
5300
  const controller = new AbortController();
4998
5301
  let done = false;
4999
- const promise = globalThis.fetch(input, {
5302
+ const promise = fetch(input, {
5000
5303
  ...init,
5001
5304
  signal: controller.signal,
5002
5305
  }).finally(() => {
@@ -5016,7 +5319,7 @@ var $;
5016
5319
  const response = this.response(input, init);
5017
5320
  if (response.status() === 'success')
5018
5321
  return response;
5019
- throw new Error(response.message());
5322
+ throw new Error(response.message(), { cause: response });
5020
5323
  }
5021
5324
  static stream(input, init) {
5022
5325
  return this.success(input, init).stream();
@@ -5080,42 +5383,10 @@ var $;
5080
5383
  "use strict";
5081
5384
  var $;
5082
5385
  (function ($) {
5083
- class $mol_file_web extends $mol_file {
5084
- static absolute(path) {
5085
- return this.make({
5086
- path: $mol_const(path)
5087
- });
5088
- }
5386
+ class $mol_file_webdav extends $mol_file_base {
5089
5387
  static relative(path) {
5090
5388
  return this.absolute(new URL(path, this.base).toString());
5091
5389
  }
5092
- static base = $mol_dom_context.document?.currentScript
5093
- ? new URL('.', $mol_dom_context.document.currentScript['src']).toString()
5094
- : '';
5095
- buffer(next) {
5096
- if (next !== undefined)
5097
- throw new Error(`Saving content not supported: ${this.path}`);
5098
- const response = $mol_fetch.response(this.path());
5099
- if (response.native.status === 404)
5100
- throw new $mol_file_not_found(`File not found: ${this.path()}`);
5101
- return new Uint8Array(response.buffer());
5102
- }
5103
- stat(next, virt) {
5104
- let stat = next;
5105
- if (next === undefined) {
5106
- const content = this.text();
5107
- const ctime = new Date();
5108
- stat = {
5109
- type: 'file',
5110
- size: content.length,
5111
- ctime,
5112
- atime: ctime,
5113
- mtime: ctime
5114
- };
5115
- }
5116
- this.parent().watcher();
5117
- return stat;
5118
- }
5119
5390
  resolve(path) {
5120
5391
  let res = this.path() + '/' + path;
5121
5392
  while (true) {
@@ -5124,36 +5395,150 @@ var $;
5124
5395
  if (prev === res)
5125
5396
  break;
5126
5397
  }
5398
+ res = res.replace(/\/\.\.\/?$/, '');
5399
+ if (res === this.path())
5400
+ return this;
5127
5401
  return this.constructor.absolute(res);
5128
5402
  }
5129
- ensure() {
5130
- throw new Error('$mol_file_web.ensure() not implemented');
5403
+ static headers() { return {}; }
5404
+ headers() { return this.constructor.headers(); }
5405
+ fetch(init) {
5406
+ return this.$.$mol_fetch.success(this.path(), {
5407
+ ...init,
5408
+ headers: {
5409
+ ...this.headers(),
5410
+ ...init.headers,
5411
+ }
5412
+ });
5131
5413
  }
5132
- drop() {
5133
- throw new Error('$mol_file_web.drop() not implemented');
5414
+ read() {
5415
+ try {
5416
+ const response = this.fetch({});
5417
+ return new Uint8Array(response.buffer());
5418
+ }
5419
+ catch (error) {
5420
+ if (error instanceof Error
5421
+ && error.cause instanceof $mol_fetch_response
5422
+ && error.cause.native.status === 404)
5423
+ return new Uint8Array;
5424
+ $mol_fail_hidden(error);
5425
+ }
5426
+ }
5427
+ write(body) { this.fetch({ method: 'PUT', body }); }
5428
+ ensure() { this.fetch({ method: 'MKCOL' }); }
5429
+ drop() { this.fetch({ method: 'DELETE' }); }
5430
+ copy(to) {
5431
+ this.fetch({
5432
+ method: 'COPY',
5433
+ headers: { Destination: to }
5434
+ });
5134
5435
  }
5135
- sub() {
5136
- throw new Error('$mol_file_web.sub() not implemented');
5436
+ kids() {
5437
+ const response = this.fetch({ method: 'PROPFIND' });
5438
+ const xml = response.xml();
5439
+ const result = [];
5440
+ for (const multistatus of xml.childNodes) {
5441
+ if (multistatus.nodeName !== 'D:multistatus')
5442
+ continue;
5443
+ for (const response of multistatus.childNodes) {
5444
+ let path;
5445
+ if (response.nodeName === 'D:href')
5446
+ path = response.textContent ?? '';
5447
+ if (!path)
5448
+ continue;
5449
+ if (response.nodeName !== 'D:propstat')
5450
+ continue;
5451
+ const stat = webdav_stat(response);
5452
+ const file = this.resolve(path);
5453
+ file.stat(stat, 'virt');
5454
+ result.push(file);
5455
+ }
5456
+ }
5457
+ return result;
5137
5458
  }
5138
- relate(base = this.constructor.relative('.')) {
5139
- throw new Error('$mol_file_web.relate() not implemented');
5459
+ readable(opts) {
5460
+ return this.fetch({
5461
+ headers: !opts.start ? {} : {
5462
+ 'Range': `bytes=${opts.start}-${opts.end ?? ''}`
5463
+ }
5464
+ }).stream() || $mol_fail(new Error('Not found'));
5140
5465
  }
5141
- append(next) {
5142
- throw new Error('$mol_file_web.append() not implemented');
5466
+ info() {
5467
+ return this.kids().at(0)?.stat() ?? null;
5143
5468
  }
5144
5469
  }
5145
- __decorate([
5146
- $mol_mem
5147
- ], $mol_file_web.prototype, "buffer", null);
5148
- __decorate([
5149
- $mol_mem
5150
- ], $mol_file_web.prototype, "stat", null);
5151
- __decorate([
5152
- $mol_mem
5153
- ], $mol_file_web.prototype, "sub", null);
5154
5470
  __decorate([
5155
5471
  $mol_mem_key
5156
- ], $mol_file_web, "absolute", null);
5472
+ ], $mol_file_webdav.prototype, "readable", null);
5473
+ $.$mol_file_webdav = $mol_file_webdav;
5474
+ function webdav_stat(prop_stat) {
5475
+ const now = new Date();
5476
+ const stat = {
5477
+ type: 'file',
5478
+ size: 0,
5479
+ atime: now,
5480
+ mtime: now,
5481
+ ctime: now,
5482
+ };
5483
+ for (const prop of prop_stat.childNodes) {
5484
+ if (prop.nodeName !== 'D:prop')
5485
+ continue;
5486
+ for (const value of prop.childNodes) {
5487
+ const name = value.nodeName;
5488
+ const text = value.textContent ?? '';
5489
+ if (name === 'D:getcontenttype') {
5490
+ stat.type = text.endsWith('directory') ? 'dir' : 'file';
5491
+ }
5492
+ if (name === 'D:getcontentlength') {
5493
+ stat.size = Number(value.textContent || '0');
5494
+ if (Number.isNaN(stat.size))
5495
+ stat.size = 0;
5496
+ }
5497
+ if (name === 'D:getlastmodified')
5498
+ stat.mtime = stat.atime = new Date(text);
5499
+ if (name === 'D:creationdate')
5500
+ stat.ctime = new Date(text);
5501
+ }
5502
+ }
5503
+ return stat;
5504
+ }
5505
+ })($ || ($ = {}));
5506
+
5507
+ ;
5508
+ "use strict";
5509
+ var $;
5510
+ (function ($) {
5511
+ class $mol_file_web extends $mol_file_webdav {
5512
+ static base = $mol_dom_context.document?.currentScript
5513
+ ? new URL('.', $mol_dom_context.document.currentScript['src']).toString()
5514
+ : '';
5515
+ version() { return '1'; }
5516
+ info() {
5517
+ try {
5518
+ const response = this.fetch({ method: 'HEAD' });
5519
+ const headers = response.headers();
5520
+ let size = Number(headers.get('Content-Length'));
5521
+ if (Number.isNaN(size))
5522
+ size = 0;
5523
+ const last = headers.get('Last-Modified');
5524
+ const mtime = last ? new Date(last) : new Date();
5525
+ return {
5526
+ type: 'file',
5527
+ size,
5528
+ mtime,
5529
+ atime: mtime,
5530
+ ctime: mtime,
5531
+ };
5532
+ }
5533
+ catch (error) {
5534
+ if (error instanceof Error
5535
+ && error.cause instanceof $mol_fetch_response
5536
+ && error.cause.native.status === 404)
5537
+ return null;
5538
+ $mol_fail_hidden(error);
5539
+ }
5540
+ }
5541
+ }
5157
5542
  $.$mol_file_web = $mol_file_web;
5158
5543
  $.$mol_file = $mol_file_web;
5159
5544
  })($ || ($ = {}));