braid-text 0.0.18 → 0.0.19
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/index.js +28 -29
- package/package.json +1 -1
- package/braid-text-db/!.1 +0 -0
- package/braid-text-db/!favicon.ico.1 +0 -0
- package/braid-text-db/!hi.1 +0 -0
- package/braid-text-db/!hi10.1 +0 -0
- package/braid-text-db/!hi11.1 +0 -0
- package/braid-text-db/!hi2.1 +0 -0
- package/braid-text-db/!hi3.1 +0 -0
- package/braid-text-db/!hi4.1 +0 -0
- package/braid-text-db/!hi5.1 +0 -0
- package/braid-text-db/!hi6.1 +0 -0
- package/braid-text-db/!hi7.1 +0 -0
- package/braid-text-db/!hi8.1 +0 -0
- package/braid-text-db/!hi9.1 +0 -0
package/index.js
CHANGED
|
@@ -194,10 +194,8 @@ braid_text.serve = async (req, res, options = {}) => {
|
|
|
194
194
|
|
|
195
195
|
braid_text.get = async (key, options) => {
|
|
196
196
|
if (!options) {
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
// if it doesn't exist on disk, don't create it in this case
|
|
200
|
-
if (!(await get_files_for_key(key)).length) return
|
|
197
|
+
// if it doesn't exist already, don't create it in this case
|
|
198
|
+
if (!get_resource.cache?.[key]) return
|
|
201
199
|
return (await get_resource(key)).doc.get()
|
|
202
200
|
}
|
|
203
201
|
|
|
@@ -496,38 +494,39 @@ braid_text.list = async () => {
|
|
|
496
494
|
|
|
497
495
|
async function get_resource(key) {
|
|
498
496
|
let cache = get_resource.cache || (get_resource.cache = {})
|
|
499
|
-
if (cache[key])
|
|
497
|
+
if (!cache[key]) cache[key] = new Promise(async done => {
|
|
498
|
+
let resource = {}
|
|
499
|
+
resource.clients = new Set()
|
|
500
|
+
resource.simpleton_clients = new Set()
|
|
500
501
|
|
|
501
|
-
|
|
502
|
-
resource.clients = new Set()
|
|
503
|
-
resource.simpleton_clients = new Set()
|
|
502
|
+
resource.doc = new Doc("server")
|
|
504
503
|
|
|
505
|
-
|
|
504
|
+
let { change, delete_me } = braid_text.db_folder
|
|
505
|
+
? await file_sync(key,
|
|
506
|
+
(bytes) => resource.doc.mergeBytes(bytes),
|
|
507
|
+
() => resource.doc.toBytes())
|
|
508
|
+
: { change: () => { }, delete_me: () => { } }
|
|
506
509
|
|
|
507
|
-
|
|
508
|
-
? await file_sync(key,
|
|
509
|
-
(bytes) => resource.doc.mergeBytes(bytes),
|
|
510
|
-
() => resource.doc.toBytes())
|
|
511
|
-
: { change: () => { }, delete_me: () => { } }
|
|
510
|
+
resource.db_delta = change
|
|
512
511
|
|
|
513
|
-
|
|
512
|
+
resource.doc = defrag_dt(resource.doc)
|
|
513
|
+
resource.need_defrag = false
|
|
514
514
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
let v = resource.doc.localToRemoteVersion([i])[0]
|
|
522
|
-
resource.actor_seqs[v[0]] = Math.max(v[1], resource.actor_seqs[v[0]] ?? -1)
|
|
523
|
-
}
|
|
515
|
+
resource.actor_seqs = {}
|
|
516
|
+
let max_version = resource.doc.getLocalVersion()[0] ?? -1
|
|
517
|
+
for (let i = 0; i <= max_version; i++) {
|
|
518
|
+
let v = resource.doc.localToRemoteVersion([i])[0]
|
|
519
|
+
resource.actor_seqs[v[0]] = Math.max(v[1], resource.actor_seqs[v[0]] ?? -1)
|
|
520
|
+
}
|
|
524
521
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
522
|
+
resource.delete_me = () => {
|
|
523
|
+
delete_me()
|
|
524
|
+
delete cache[key]
|
|
525
|
+
}
|
|
529
526
|
|
|
530
|
-
|
|
527
|
+
done(resource)
|
|
528
|
+
})
|
|
529
|
+
return await cache[key]
|
|
531
530
|
}
|
|
532
531
|
|
|
533
532
|
async function db_folder_init() {
|
package/package.json
CHANGED
package/braid-text-db/!.1
DELETED
|
Binary file
|
|
Binary file
|
package/braid-text-db/!hi.1
DELETED
|
Binary file
|
package/braid-text-db/!hi10.1
DELETED
|
Binary file
|
package/braid-text-db/!hi11.1
DELETED
|
Binary file
|
package/braid-text-db/!hi2.1
DELETED
|
Binary file
|
package/braid-text-db/!hi3.1
DELETED
|
Binary file
|
package/braid-text-db/!hi4.1
DELETED
|
Binary file
|
package/braid-text-db/!hi5.1
DELETED
|
Binary file
|
package/braid-text-db/!hi6.1
DELETED
|
Binary file
|
package/braid-text-db/!hi7.1
DELETED
|
Binary file
|
package/braid-text-db/!hi8.1
DELETED
|
Binary file
|
package/braid-text-db/!hi9.1
DELETED
|
Binary file
|