braidfs 0.0.116 → 0.0.117

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.
Files changed (2) hide show
  1. package/index.js +31 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -114,7 +114,7 @@ async function main() {
114
114
  process.on("uncaughtException", (x) => console.log(`uncaughtException: ${x.stack}`))
115
115
  require('http').createServer(async (req, res) => {
116
116
  try {
117
- console.log(`${req.method} ${req.url}`)
117
+ // console.log(`${req.method} ${req.url}`)
118
118
 
119
119
  if (req.url === '/favicon.ico') return
120
120
 
@@ -159,6 +159,8 @@ async function main() {
159
159
  var patches = diff(parent_text, text)
160
160
 
161
161
  if (patches.length) {
162
+ console.log(`plugin edited ${path}`)
163
+
162
164
  sync.local_edit_counter += patches_to_code_points(patches, parent_text)
163
165
  var version = [sync.peer + "-" + (sync.local_edit_counter - 1)]
164
166
  await braid_text.put(sync.url, { version, parents, patches, merge_type: 'dt' })
@@ -231,7 +233,7 @@ async function main() {
231
233
  })
232
234
  sync_url('.braidfs/errors')
233
235
 
234
- console.log({ sync: config.sync })
236
+ // console.log({ sync: config.sync })
235
237
  for (let x of Object.entries(config.sync)) if (x[1]) sync_url(x[0])
236
238
 
237
239
  watch_files()
@@ -292,7 +294,7 @@ async function watch_files() {
292
294
  watch_files.watcher = 42
293
295
  await w?.close()
294
296
 
295
- console.log('watch files..')
297
+ // console.log('watch files..')
296
298
  watch_files.watcher = require('chokidar').watch(sync_base, {
297
299
  useFsEvents: true,
298
300
  usePolling: false,
@@ -438,7 +440,7 @@ async function sync_url(url) {
438
440
  async function init() {
439
441
  if (freed) return
440
442
 
441
- console.log(`sync_url: ${url}`)
443
+ // console.log(`sync_url: ${url}`)
442
444
 
443
445
  var resource = await braid_text.get_resource(url)
444
446
  if (freed) return
@@ -590,7 +592,7 @@ async function sync_url(url) {
590
592
  }
591
593
 
592
594
  if (file_needs_reading) {
593
- console.log(`reading file: ${fullpath}`)
595
+ // console.log(`reading file: ${fullpath}`)
594
596
 
595
597
  file_needs_reading = false
596
598
 
@@ -598,7 +600,7 @@ async function sync_url(url) {
598
600
  if (!(await wait_on(file_exists(fullpath)))) {
599
601
  if (freed) return
600
602
 
601
- console.log(`file not found, creating: ${fullpath}`)
603
+ // console.log(`file not found, creating: ${fullpath}`)
602
604
 
603
605
  file_needs_writing = true
604
606
  file_last_version = []
@@ -620,7 +622,7 @@ async function sync_url(url) {
620
622
 
621
623
  var patches = diff(self.file_last_text, text)
622
624
  if (patches.length) {
623
- console.log(`found changes in: ${fullpath}`)
625
+ console.log(`file change in ${path}`)
624
626
 
625
627
  // convert from js-indicies to code-points
626
628
  self.local_edit_counter += patches_to_code_points(patches, self.file_last_text)
@@ -641,12 +643,12 @@ async function sync_url(url) {
641
643
  } else {
642
644
  add_to_version_cache(text, file_last_version)
643
645
 
644
- console.log(`no changes found in: ${fullpath}`)
646
+ // console.log(`no changes found in: ${fullpath}`)
645
647
  if (stat_eq(stat, self.file_last_stat)) {
646
648
  if (Date.now() > (self.file_ignore_until ?? 0))
647
649
  on_watcher_miss(`expected change to: ${fullpath}`)
648
- else console.log(`no changes expected`)
649
- } else console.log('found change in file stat')
650
+ // else console.log(`no changes expected`)
651
+ } // else console.log('found change in file stat')
650
652
  }
651
653
  self.file_last_stat = stat
652
654
  self.file_ignore_until = Date.now() + 1000
@@ -671,7 +673,7 @@ async function sync_url(url) {
671
673
  continue
672
674
  }
673
675
 
674
- console.log(`writing file ${fullpath}`)
676
+ // console.log(`writing file ${fullpath}`)
675
677
 
676
678
  add_to_version_cache(body, version)
677
679
 
@@ -754,7 +756,7 @@ async function sync_url(url) {
754
756
  async function connect() {
755
757
  if (freed) return
756
758
  if (last_connect_timer) return
757
- console.log(`connecting to ${url}`)
759
+ // console.log(`connecting to ${url}`)
758
760
 
759
761
  var closed = false
760
762
  var prev_disconnect = self.disconnect
@@ -813,7 +815,8 @@ async function sync_url(url) {
813
815
  async function send_out(stuff) {
814
816
  if (freed || closed) return
815
817
 
816
- console.log(`send_out ${url} ${JSON.stringify(stuff, null, 4).slice(0, 1000)}`)
818
+ console.log(`sending to ${url}`)
819
+ // console.log(JSON.stringify(stuff, null, 4).slice(0, 1000))
817
820
 
818
821
  var r = await my_fetch({ method: "PUT", ...stuff })
819
822
  if (freed || closed) return
@@ -839,7 +842,7 @@ async function sync_url(url) {
839
842
 
840
843
  async function find_fork_point() {
841
844
  if (freed || closed) return
842
- console.log(`[find_fork_point] url: ${url}`)
845
+ // console.log(`[find_fork_point] url: ${url}`)
843
846
 
844
847
  // see if remote has the fork point
845
848
  if (self.fork_point) {
@@ -851,7 +854,10 @@ async function sync_url(url) {
851
854
 
852
855
  if (!r.ok && r.status !== 309 && r.status !== 500) return retry(new Error(`unexpected HEAD status: ${r.status}`))
853
856
 
854
- if (r.ok) return console.log(`[find_fork_point] "${url.split('/').pop()}" has our latest fork point, hooray!`)
857
+ if (r.ok) {
858
+ // console.log(`[find_fork_point] "${url.split('/').pop()}" has our latest fork point, hooray!`)
859
+ return
860
+ }
855
861
  }
856
862
 
857
863
  // otherwise let's binary search for new fork point..
@@ -866,12 +872,12 @@ async function sync_url(url) {
866
872
  var i = Math.floor((min + max)/2)
867
873
  var version = [events[i]]
868
874
 
869
- console.log(`min=${min}, max=${max}, i=${i}, version=${version}`)
875
+ // console.log(`min=${min}, max=${max}, i=${i}, version=${version}`)
870
876
 
871
- var st = Date.now()
877
+ //var st = Date.now()
872
878
  var r = await my_fetch({ method: "HEAD", version })
873
879
  if (freed || closed) return
874
- console.log(`fetched in ${Date.now() - st}`)
880
+ //console.log(`fetched in ${Date.now() - st}`)
875
881
 
876
882
  if (!r.ok && r.status !== 309 && r.status !== 500) return retry(new Error(`unexpected HEAD status: ${r.status}`))
877
883
 
@@ -880,7 +886,7 @@ async function sync_url(url) {
880
886
  self.fork_point = version
881
887
  } else max = i
882
888
  }
883
- console.log(`[find_fork_point] settled on: ${JSON.stringify(self.fork_point)}`)
889
+ // console.log(`[find_fork_point] settled on: ${JSON.stringify(self.fork_point)}`)
884
890
  self.signal_file_needs_writing(true)
885
891
  }
886
892
 
@@ -912,8 +918,7 @@ async function sync_url(url) {
912
918
  if (res.status !== 209)
913
919
  return log_error(`Can't sync ${url} -- got bad response ${res.status} from server (expected 209)`)
914
920
 
915
- console.log(`connected to ${url}`.padEnd(70, ' ')
916
- + `(editable: ${res.headers.get('editable')})`)
921
+ console.log(`connected to ${url}${res.headers.get('editable') !== 'true' ? ' (readonly)' : ''}`)
917
922
 
918
923
  reconnect_rate_limiter.on_conn(url)
919
924
 
@@ -925,7 +930,7 @@ async function sync_url(url) {
925
930
  if (freed || closed) return
926
931
 
927
932
  if (!update.status) {
928
- console.log(`got initial update about ${url}`)
933
+ // console.log(`got initial update about ${url}`)
929
934
 
930
935
  // manually apply the dt bytes..
931
936
  // ..code bits taken from braid-text put..
@@ -952,7 +957,7 @@ async function sync_url(url) {
952
957
  return
953
958
  }
954
959
 
955
- console.log(`got external update about ${url}`)
960
+ console.log(`update from ${url}`)
956
961
 
957
962
  if (update.body) update.body = update.body_text
958
963
  if (update.patches) for (let p of update.patches) p.content = p.content_text
@@ -1109,7 +1114,7 @@ function ReconnectRateLimiter(get_wait_time) {
1109
1114
  // If host has connections, give turn immediately
1110
1115
  if (self.conns.has(host)) return
1111
1116
 
1112
- console.log(`throttling reconn to ${url} (no conns yet to ${self.conns.size ? host : 'anything'})`)
1117
+ // console.log(`throttling reconn to ${url} (no conns yet to ${self.conns.size ? host : 'anything'})`)
1113
1118
 
1114
1119
  if (!self.host_to_q.has(host)) {
1115
1120
  var turns = []
@@ -1234,7 +1239,7 @@ async function fetch_http2(url, options = {}) {
1234
1239
  })
1235
1240
  } catch (err) {
1236
1241
  if (err.code?.includes("HTTP2") || err.message?.includes("HTTP/2")) {
1237
- console.log("HTTP/2 failed, falling back to HTTP/1.1:", err.message)
1242
+ // console.log("HTTP/2 failed, falling back to HTTP/1.1:", err.message)
1238
1243
  return fetch(url, options)
1239
1244
  }
1240
1245
  throw err
@@ -1348,7 +1353,7 @@ async function is_read_only(fullpath) {
1348
1353
  }
1349
1354
 
1350
1355
  async function set_read_only(fullpath, read_only) {
1351
- console.log(`set_read_only(${fullpath}, ${read_only})`)
1356
+ // console.log(`set_read_only(${fullpath}, ${read_only})`)
1352
1357
 
1353
1358
  if (require('os').platform() === "win32") {
1354
1359
  await new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.116",
3
+ "version": "0.0.117",
4
4
  "description": "braid technology synchronizing files and webpages",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidfs",