gip-remote 1.0.0 → 1.0.2
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/README.md +13 -3
- package/index.js +20 -23
- package/lib/link.js +23 -0
- package/package.json +23 -5
- package/schema/hyperdb/db.json +69 -0
- package/schema/hyperdb/index.js +358 -0
- package/schema/hyperdb/messages.js +442 -0
- package/schema/hyperschema/index.js +289 -0
- package/schema/hyperschema/schema.json +199 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# gip-remote
|
|
2
2
|
|
|
3
|
-
Git-
|
|
3
|
+
Git-into-Pear remote database. Store and replicate p2p Git repositories [HyperDB](https://github.com/holepunchto/hyperdb).
|
|
4
|
+
|
|
5
|
+
Git objects are stored raw, and rebuilt to file when needed. Built for the [Git+Pear remote transport](https://github.com/holepunchto/git-remote-punch-transport).
|
|
4
6
|
|
|
5
7
|
```
|
|
6
8
|
npm install gip-remote
|
|
@@ -15,11 +17,19 @@ const { Remote } = require('gip-remote')
|
|
|
15
17
|
|
|
16
18
|
const store = new Corestore('./my-store')
|
|
17
19
|
const swarm = new Hyperswarm()
|
|
20
|
+
swarm.on('connection', (conn) => {
|
|
21
|
+
store.replicate(conn)
|
|
22
|
+
})
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
// new remote
|
|
25
|
+
const remote = new Remote(store.namespace('my-repo'), 'my-repo')
|
|
20
26
|
await remote.ready()
|
|
21
27
|
|
|
22
28
|
console.log(remote.key) // public key
|
|
29
|
+
|
|
30
|
+
// remote remote!
|
|
31
|
+
const remote2 = new Remote(store.namespace('my-other-repo'), 'git+pear://0.1.iain5rkqfenyjrcod53tb61cq3egpwbk6cnd15ca3pqm39g7wf1y/my-other-repo')
|
|
32
|
+
await remote2.ready()
|
|
23
33
|
```
|
|
24
34
|
|
|
25
35
|
### Push
|
|
@@ -38,7 +48,7 @@ const objects = await remote.getRefObjects(commitOid)
|
|
|
38
48
|
|
|
39
49
|
### toDrive
|
|
40
50
|
|
|
41
|
-
Get a Hyperdrive-compatible interface for a branch. Works with
|
|
51
|
+
Get a Hyperdrive-compatible interface for a branch. Works with [mirror-drive](https://github.com/holepunchto/mirror-drive/).
|
|
42
52
|
|
|
43
53
|
```js
|
|
44
54
|
const drive = await remote.toDrive('main')
|
package/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const ReadyResource = require('ready-resource')
|
|
2
2
|
const HyperDB = require('hyperdb')
|
|
3
3
|
const Hyperbee = require('hyperbee2')
|
|
4
|
+
const z32 = require('z32')
|
|
4
5
|
const def = require('./schema/hyperdb/index')
|
|
5
6
|
const RemoteDrive = require('./lib/drive')
|
|
7
|
+
const GitPearLink = require('./lib/link')
|
|
6
8
|
const { parseCommit, walkTree } = require('./lib/git')
|
|
7
9
|
|
|
8
10
|
class Remote extends ReadyResource {
|
|
@@ -11,59 +13,53 @@ class Remote extends ReadyResource {
|
|
|
11
13
|
_db = null
|
|
12
14
|
_key = null
|
|
13
15
|
|
|
14
|
-
constructor(
|
|
16
|
+
constructor(store, link, opts = {}) {
|
|
15
17
|
super()
|
|
16
18
|
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
this._timeout = args.timeout || 240_000
|
|
21
|
-
this._blind = args.blind
|
|
22
|
-
this._key = args.key
|
|
19
|
+
this._link =
|
|
20
|
+
typeof link === 'string' && link.startsWith('git+pear:') ? GitPearLink.parse(link) : link
|
|
21
|
+
const config = typeof this._link === 'string' ? { name: this._link } : this._link
|
|
23
22
|
|
|
24
|
-
const bee = new Hyperbee(
|
|
25
|
-
this._db = HyperDB.bee2(bee, def)
|
|
23
|
+
const bee = new Hyperbee(store, config, { autoUpdate: true })
|
|
24
|
+
this._db = HyperDB.bee2(bee, def, { autoUpdate: true })
|
|
26
25
|
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this._swarm.on('connection', this._onconnection)
|
|
26
|
+
this._name = config.name || config.pathname.split('/').slice(1)[0]
|
|
27
|
+
this._timeout = opts.timeout || 240_000
|
|
28
|
+
this._blind = opts.blind
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
async _open() {
|
|
36
32
|
await this._db.ready()
|
|
37
|
-
|
|
38
|
-
this._topic = this._swarm.join(this.discoveryKey)
|
|
39
|
-
|
|
40
|
-
await this._db.update()
|
|
41
33
|
}
|
|
42
34
|
|
|
43
35
|
async _close() {
|
|
44
|
-
this._swarm.off('connection', this._onconnection)
|
|
45
|
-
|
|
46
|
-
if (this._topic) await this._topic.destroy()
|
|
47
|
-
|
|
48
36
|
await this._db.close()
|
|
49
37
|
}
|
|
50
38
|
|
|
51
39
|
get name() {
|
|
52
40
|
return this._name
|
|
53
41
|
}
|
|
42
|
+
|
|
54
43
|
get core() {
|
|
55
44
|
return this._db.core
|
|
56
45
|
}
|
|
46
|
+
|
|
57
47
|
get key() {
|
|
58
48
|
return this._db.core.key
|
|
59
49
|
}
|
|
50
|
+
|
|
60
51
|
get discoveryKey() {
|
|
61
52
|
return this._db.core.discoveryKey
|
|
62
53
|
}
|
|
54
|
+
|
|
63
55
|
get availablePeers() {
|
|
64
56
|
return this._db.core.peers.length
|
|
65
57
|
}
|
|
66
58
|
|
|
59
|
+
get url() {
|
|
60
|
+
return `git+pear://${z32.encode(this.key)}/${this.name}`
|
|
61
|
+
}
|
|
62
|
+
|
|
67
63
|
// --- Objects ---
|
|
68
64
|
|
|
69
65
|
async getObject(oid) {
|
|
@@ -213,6 +209,7 @@ class Remote extends ReadyResource {
|
|
|
213
209
|
module.exports = {
|
|
214
210
|
Remote,
|
|
215
211
|
RemoteDrive,
|
|
212
|
+
GitPearLink,
|
|
216
213
|
parseCommit,
|
|
217
214
|
walkTree
|
|
218
215
|
}
|
package/lib/link.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { constructor: PearLink } = require('pear-link')
|
|
2
|
+
|
|
3
|
+
const protocol = 'git+pear:'
|
|
4
|
+
|
|
5
|
+
class GitPearLink extends PearLink {
|
|
6
|
+
serialize(o) {
|
|
7
|
+
if (o.protocol?.startsWith(protocol) === false) return super.serialize(o)
|
|
8
|
+
o.protocol = o.protocol.slice(4)
|
|
9
|
+
o.origin = o.origin.slice(4)
|
|
10
|
+
return 'git+' + super.serialize(o)
|
|
11
|
+
}
|
|
12
|
+
parse(link) {
|
|
13
|
+
if (link.startsWith(protocol) === false) return super.parse(link)
|
|
14
|
+
const parsed = super.parse(link.slice(4))
|
|
15
|
+
parsed.protocol = 'git+' + parsed.protocol
|
|
16
|
+
parsed.origin = 'git+' + parsed.origin
|
|
17
|
+
parsed.drive.length = parsed.drive.length ?? -1
|
|
18
|
+
|
|
19
|
+
return parsed
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = new GitPearLink()
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gip-remote",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Git+Pear remote DB for handling git data",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"format": "prettier . --write",
|
|
8
|
-
"test": "
|
|
9
|
-
"lint": "lunte"
|
|
8
|
+
"test": "brittle-bare test/all.js",
|
|
9
|
+
"lint": "prettier . --check && lunte"
|
|
10
10
|
},
|
|
11
11
|
"type": "commonjs",
|
|
12
12
|
"imports": {
|
|
@@ -17,19 +17,33 @@
|
|
|
17
17
|
"path": {
|
|
18
18
|
"bare": "bare-path",
|
|
19
19
|
"default": "path"
|
|
20
|
+
},
|
|
21
|
+
"child_process": {
|
|
22
|
+
"bare": "bare-subprocess",
|
|
23
|
+
"default": "child_process"
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
"exports": {
|
|
23
27
|
"./package": "./package.json",
|
|
24
28
|
".": {
|
|
25
29
|
"default": "./index.js"
|
|
30
|
+
},
|
|
31
|
+
"./git": {
|
|
32
|
+
"default": "./lib/git.js"
|
|
33
|
+
},
|
|
34
|
+
"./schema/hyperdb": {
|
|
35
|
+
"default": "./schema/hyperdb/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./schema/hyperschema": {
|
|
38
|
+
"default": "./schema/hyperschema/index.js"
|
|
26
39
|
}
|
|
27
40
|
},
|
|
28
41
|
"files": [
|
|
29
42
|
"package.json",
|
|
30
43
|
"index.js",
|
|
31
44
|
"index.d.ts",
|
|
32
|
-
"lib"
|
|
45
|
+
"lib",
|
|
46
|
+
"schema"
|
|
33
47
|
],
|
|
34
48
|
"keywords": [],
|
|
35
49
|
"repository": {
|
|
@@ -43,13 +57,16 @@
|
|
|
43
57
|
},
|
|
44
58
|
"homepage": "https://github.com/holepunchto/gip-remote",
|
|
45
59
|
"devDependencies": {
|
|
60
|
+
"b4a": "^1.8.0",
|
|
61
|
+
"bare-subprocess": "^5.2.3",
|
|
46
62
|
"brittle": "^3.19.1",
|
|
47
63
|
"corestore": "^7.9.2",
|
|
48
64
|
"hyperdht": "^6.29.6",
|
|
49
65
|
"hyperswarm": "^4.17.0",
|
|
50
66
|
"prettier": "^3.8.1",
|
|
51
67
|
"prettier-config-holepunch": "^2.0.0",
|
|
52
|
-
"test-tmp": "^1.4.0"
|
|
68
|
+
"test-tmp": "^1.4.0",
|
|
69
|
+
"z32": "^1.1.0"
|
|
53
70
|
},
|
|
54
71
|
"dependencies": {
|
|
55
72
|
"bare-fs": "^4.5.6",
|
|
@@ -57,6 +74,7 @@
|
|
|
57
74
|
"hyperbee2": "^2.8.0",
|
|
58
75
|
"hyperdb": "^6.3.0",
|
|
59
76
|
"mirror-drive": "^1.13.0",
|
|
77
|
+
"pear-link": "^4.2.1",
|
|
60
78
|
"ready-resource": "^1.2.0",
|
|
61
79
|
"rebuild-git": "^1.1.1",
|
|
62
80
|
"streamx": "^2.25.0"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"offset": 0,
|
|
4
|
+
"schema": [
|
|
5
|
+
{
|
|
6
|
+
"name": "repos",
|
|
7
|
+
"namespace": "gip",
|
|
8
|
+
"id": 0,
|
|
9
|
+
"type": 1,
|
|
10
|
+
"version": 1,
|
|
11
|
+
"versionField": null,
|
|
12
|
+
"indexes": [],
|
|
13
|
+
"schema": "@gip/repos",
|
|
14
|
+
"derived": false,
|
|
15
|
+
"key": ["name"],
|
|
16
|
+
"trigger": null
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "branches",
|
|
20
|
+
"namespace": "gip",
|
|
21
|
+
"id": 1,
|
|
22
|
+
"type": 1,
|
|
23
|
+
"version": 1,
|
|
24
|
+
"versionField": null,
|
|
25
|
+
"indexes": [],
|
|
26
|
+
"schema": "@gip/branches",
|
|
27
|
+
"derived": false,
|
|
28
|
+
"key": ["name"],
|
|
29
|
+
"trigger": null
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "files",
|
|
33
|
+
"namespace": "gip",
|
|
34
|
+
"id": 2,
|
|
35
|
+
"type": 1,
|
|
36
|
+
"version": 1,
|
|
37
|
+
"versionField": null,
|
|
38
|
+
"indexes": ["@gip/files-by-branch"],
|
|
39
|
+
"schema": "@gip/files",
|
|
40
|
+
"derived": false,
|
|
41
|
+
"key": ["branch", "path"],
|
|
42
|
+
"trigger": null
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "objects",
|
|
46
|
+
"namespace": "gip",
|
|
47
|
+
"id": 3,
|
|
48
|
+
"type": 1,
|
|
49
|
+
"version": 1,
|
|
50
|
+
"versionField": null,
|
|
51
|
+
"indexes": [],
|
|
52
|
+
"schema": "@gip/objects",
|
|
53
|
+
"derived": false,
|
|
54
|
+
"key": ["oid"],
|
|
55
|
+
"trigger": null
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": "files-by-branch",
|
|
59
|
+
"namespace": "gip",
|
|
60
|
+
"id": 4,
|
|
61
|
+
"type": 2,
|
|
62
|
+
"version": 1,
|
|
63
|
+
"collection": "@gip/files",
|
|
64
|
+
"unique": false,
|
|
65
|
+
"deprecated": false,
|
|
66
|
+
"key": ["branch"]
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// This file is autogenerated by the hyperdb compiler
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
|
|
4
|
+
const { IndexEncoder, c, b4a } = require('hyperdb/runtime')
|
|
5
|
+
const { version, getEncoding, setVersion } = require('./messages.js')
|
|
6
|
+
|
|
7
|
+
const versions = { schema: version, db: 1 }
|
|
8
|
+
|
|
9
|
+
// '@gip/repos' collection key
|
|
10
|
+
const collection0_key = new IndexEncoder([IndexEncoder.STRING], { prefix: 0 })
|
|
11
|
+
|
|
12
|
+
function collection0_indexify(record) {
|
|
13
|
+
const a = record.name
|
|
14
|
+
return a === undefined ? [] : [a]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// '@gip/repos' value encoding
|
|
18
|
+
const collection0_enc = getEncoding('@gip/repos/hyperdb#0')
|
|
19
|
+
|
|
20
|
+
// '@gip/repos' reconstruction function
|
|
21
|
+
function collection0_reconstruct(schemaVersion, keyBuf, valueBuf) {
|
|
22
|
+
const key = collection0_key.decode(keyBuf)
|
|
23
|
+
setVersion(schemaVersion)
|
|
24
|
+
const state = { start: 0, end: valueBuf.byteLength, buffer: valueBuf }
|
|
25
|
+
const type = c.uint.decode(state)
|
|
26
|
+
if (type !== 0) throw new Error('Unknown collection type: ' + type)
|
|
27
|
+
collection0.decodedVersion = c.uint.decode(state)
|
|
28
|
+
const record = collection0_enc.decode(state)
|
|
29
|
+
record.name = key[0]
|
|
30
|
+
return record
|
|
31
|
+
}
|
|
32
|
+
// '@gip/repos' key reconstruction function
|
|
33
|
+
function collection0_reconstruct_key(keyBuf) {
|
|
34
|
+
const key = collection0_key.decode(keyBuf)
|
|
35
|
+
return {
|
|
36
|
+
name: key[0]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// '@gip/repos'
|
|
41
|
+
const collection0 = {
|
|
42
|
+
name: '@gip/repos',
|
|
43
|
+
id: 0,
|
|
44
|
+
version: 1,
|
|
45
|
+
encodeKey(record) {
|
|
46
|
+
const key = [record.name]
|
|
47
|
+
return collection0_key.encode(key)
|
|
48
|
+
},
|
|
49
|
+
encodeKeyRange({ gt, lt, gte, lte } = {}) {
|
|
50
|
+
return collection0_key.encodeRange({
|
|
51
|
+
gt: gt ? collection0_indexify(gt) : null,
|
|
52
|
+
lt: lt ? collection0_indexify(lt) : null,
|
|
53
|
+
gte: gte ? collection0_indexify(gte) : null,
|
|
54
|
+
lte: lte ? collection0_indexify(lte) : null
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
encodeValue(schemaVersion, collectionVersion, record) {
|
|
58
|
+
setVersion(schemaVersion)
|
|
59
|
+
const state = { start: 0, end: 2, buffer: null }
|
|
60
|
+
collection0_enc.preencode(state, record)
|
|
61
|
+
state.buffer = b4a.allocUnsafe(state.end)
|
|
62
|
+
state.buffer[state.start++] = 0
|
|
63
|
+
state.buffer[state.start++] = collectionVersion
|
|
64
|
+
collection0_enc.encode(state, record)
|
|
65
|
+
return state.buffer
|
|
66
|
+
},
|
|
67
|
+
trigger: null,
|
|
68
|
+
reconstruct: collection0_reconstruct,
|
|
69
|
+
reconstructKey: collection0_reconstruct_key,
|
|
70
|
+
indexes: [],
|
|
71
|
+
decodedVersion: 0
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// '@gip/branches' collection key
|
|
75
|
+
const collection1_key = new IndexEncoder([IndexEncoder.STRING], { prefix: 1 })
|
|
76
|
+
|
|
77
|
+
function collection1_indexify(record) {
|
|
78
|
+
const a = record.name
|
|
79
|
+
return a === undefined ? [] : [a]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// '@gip/branches' value encoding
|
|
83
|
+
const collection1_enc = getEncoding('@gip/branches/hyperdb#1')
|
|
84
|
+
|
|
85
|
+
// '@gip/branches' reconstruction function
|
|
86
|
+
function collection1_reconstruct(schemaVersion, keyBuf, valueBuf) {
|
|
87
|
+
const key = collection1_key.decode(keyBuf)
|
|
88
|
+
setVersion(schemaVersion)
|
|
89
|
+
const state = { start: 0, end: valueBuf.byteLength, buffer: valueBuf }
|
|
90
|
+
const type = c.uint.decode(state)
|
|
91
|
+
if (type !== 0) throw new Error('Unknown collection type: ' + type)
|
|
92
|
+
collection1.decodedVersion = c.uint.decode(state)
|
|
93
|
+
const record = collection1_enc.decode(state)
|
|
94
|
+
record.name = key[0]
|
|
95
|
+
return record
|
|
96
|
+
}
|
|
97
|
+
// '@gip/branches' key reconstruction function
|
|
98
|
+
function collection1_reconstruct_key(keyBuf) {
|
|
99
|
+
const key = collection1_key.decode(keyBuf)
|
|
100
|
+
return {
|
|
101
|
+
name: key[0]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// '@gip/branches'
|
|
106
|
+
const collection1 = {
|
|
107
|
+
name: '@gip/branches',
|
|
108
|
+
id: 1,
|
|
109
|
+
version: 1,
|
|
110
|
+
encodeKey(record) {
|
|
111
|
+
const key = [record.name]
|
|
112
|
+
return collection1_key.encode(key)
|
|
113
|
+
},
|
|
114
|
+
encodeKeyRange({ gt, lt, gte, lte } = {}) {
|
|
115
|
+
return collection1_key.encodeRange({
|
|
116
|
+
gt: gt ? collection1_indexify(gt) : null,
|
|
117
|
+
lt: lt ? collection1_indexify(lt) : null,
|
|
118
|
+
gte: gte ? collection1_indexify(gte) : null,
|
|
119
|
+
lte: lte ? collection1_indexify(lte) : null
|
|
120
|
+
})
|
|
121
|
+
},
|
|
122
|
+
encodeValue(schemaVersion, collectionVersion, record) {
|
|
123
|
+
setVersion(schemaVersion)
|
|
124
|
+
const state = { start: 0, end: 2, buffer: null }
|
|
125
|
+
collection1_enc.preencode(state, record)
|
|
126
|
+
state.buffer = b4a.allocUnsafe(state.end)
|
|
127
|
+
state.buffer[state.start++] = 0
|
|
128
|
+
state.buffer[state.start++] = collectionVersion
|
|
129
|
+
collection1_enc.encode(state, record)
|
|
130
|
+
return state.buffer
|
|
131
|
+
},
|
|
132
|
+
trigger: null,
|
|
133
|
+
reconstruct: collection1_reconstruct,
|
|
134
|
+
reconstructKey: collection1_reconstruct_key,
|
|
135
|
+
indexes: [],
|
|
136
|
+
decodedVersion: 0
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// '@gip/files' collection key
|
|
140
|
+
const collection2_key = new IndexEncoder([IndexEncoder.STRING, IndexEncoder.STRING], { prefix: 2 })
|
|
141
|
+
|
|
142
|
+
function collection2_indexify(record) {
|
|
143
|
+
const arr = []
|
|
144
|
+
|
|
145
|
+
const a0 = record.branch
|
|
146
|
+
if (a0 === undefined) return arr
|
|
147
|
+
arr.push(a0)
|
|
148
|
+
|
|
149
|
+
const a1 = record.path
|
|
150
|
+
if (a1 === undefined) return arr
|
|
151
|
+
arr.push(a1)
|
|
152
|
+
|
|
153
|
+
return arr
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// '@gip/files' value encoding
|
|
157
|
+
const collection2_enc = getEncoding('@gip/files/hyperdb#2')
|
|
158
|
+
|
|
159
|
+
// '@gip/files' reconstruction function
|
|
160
|
+
function collection2_reconstruct(schemaVersion, keyBuf, valueBuf) {
|
|
161
|
+
const key = collection2_key.decode(keyBuf)
|
|
162
|
+
setVersion(schemaVersion)
|
|
163
|
+
const state = { start: 0, end: valueBuf.byteLength, buffer: valueBuf }
|
|
164
|
+
const type = c.uint.decode(state)
|
|
165
|
+
if (type !== 0) throw new Error('Unknown collection type: ' + type)
|
|
166
|
+
collection2.decodedVersion = c.uint.decode(state)
|
|
167
|
+
const record = collection2_enc.decode(state)
|
|
168
|
+
record.branch = key[0]
|
|
169
|
+
record.path = key[1]
|
|
170
|
+
return record
|
|
171
|
+
}
|
|
172
|
+
// '@gip/files' key reconstruction function
|
|
173
|
+
function collection2_reconstruct_key(keyBuf) {
|
|
174
|
+
const key = collection2_key.decode(keyBuf)
|
|
175
|
+
return {
|
|
176
|
+
branch: key[0],
|
|
177
|
+
path: key[1]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// '@gip/files'
|
|
182
|
+
const collection2 = {
|
|
183
|
+
name: '@gip/files',
|
|
184
|
+
id: 2,
|
|
185
|
+
version: 1,
|
|
186
|
+
encodeKey(record) {
|
|
187
|
+
const key = [record.branch, record.path]
|
|
188
|
+
return collection2_key.encode(key)
|
|
189
|
+
},
|
|
190
|
+
encodeKeyRange({ gt, lt, gte, lte } = {}) {
|
|
191
|
+
return collection2_key.encodeRange({
|
|
192
|
+
gt: gt ? collection2_indexify(gt) : null,
|
|
193
|
+
lt: lt ? collection2_indexify(lt) : null,
|
|
194
|
+
gte: gte ? collection2_indexify(gte) : null,
|
|
195
|
+
lte: lte ? collection2_indexify(lte) : null
|
|
196
|
+
})
|
|
197
|
+
},
|
|
198
|
+
encodeValue(schemaVersion, collectionVersion, record) {
|
|
199
|
+
setVersion(schemaVersion)
|
|
200
|
+
const state = { start: 0, end: 2, buffer: null }
|
|
201
|
+
collection2_enc.preencode(state, record)
|
|
202
|
+
state.buffer = b4a.allocUnsafe(state.end)
|
|
203
|
+
state.buffer[state.start++] = 0
|
|
204
|
+
state.buffer[state.start++] = collectionVersion
|
|
205
|
+
collection2_enc.encode(state, record)
|
|
206
|
+
return state.buffer
|
|
207
|
+
},
|
|
208
|
+
trigger: null,
|
|
209
|
+
reconstruct: collection2_reconstruct,
|
|
210
|
+
reconstructKey: collection2_reconstruct_key,
|
|
211
|
+
indexes: [],
|
|
212
|
+
decodedVersion: 0
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// '@gip/objects' collection key
|
|
216
|
+
const collection3_key = new IndexEncoder([IndexEncoder.STRING], { prefix: 3 })
|
|
217
|
+
|
|
218
|
+
function collection3_indexify(record) {
|
|
219
|
+
const a = record.oid
|
|
220
|
+
return a === undefined ? [] : [a]
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// '@gip/objects' value encoding
|
|
224
|
+
const collection3_enc = getEncoding('@gip/objects/hyperdb#3')
|
|
225
|
+
|
|
226
|
+
// '@gip/objects' reconstruction function
|
|
227
|
+
function collection3_reconstruct(schemaVersion, keyBuf, valueBuf) {
|
|
228
|
+
const key = collection3_key.decode(keyBuf)
|
|
229
|
+
setVersion(schemaVersion)
|
|
230
|
+
const state = { start: 0, end: valueBuf.byteLength, buffer: valueBuf }
|
|
231
|
+
const type = c.uint.decode(state)
|
|
232
|
+
if (type !== 0) throw new Error('Unknown collection type: ' + type)
|
|
233
|
+
collection3.decodedVersion = c.uint.decode(state)
|
|
234
|
+
const record = collection3_enc.decode(state)
|
|
235
|
+
record.oid = key[0]
|
|
236
|
+
return record
|
|
237
|
+
}
|
|
238
|
+
// '@gip/objects' key reconstruction function
|
|
239
|
+
function collection3_reconstruct_key(keyBuf) {
|
|
240
|
+
const key = collection3_key.decode(keyBuf)
|
|
241
|
+
return {
|
|
242
|
+
oid: key[0]
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// '@gip/objects'
|
|
247
|
+
const collection3 = {
|
|
248
|
+
name: '@gip/objects',
|
|
249
|
+
id: 3,
|
|
250
|
+
version: 1,
|
|
251
|
+
encodeKey(record) {
|
|
252
|
+
const key = [record.oid]
|
|
253
|
+
return collection3_key.encode(key)
|
|
254
|
+
},
|
|
255
|
+
encodeKeyRange({ gt, lt, gte, lte } = {}) {
|
|
256
|
+
return collection3_key.encodeRange({
|
|
257
|
+
gt: gt ? collection3_indexify(gt) : null,
|
|
258
|
+
lt: lt ? collection3_indexify(lt) : null,
|
|
259
|
+
gte: gte ? collection3_indexify(gte) : null,
|
|
260
|
+
lte: lte ? collection3_indexify(lte) : null
|
|
261
|
+
})
|
|
262
|
+
},
|
|
263
|
+
encodeValue(schemaVersion, collectionVersion, record) {
|
|
264
|
+
setVersion(schemaVersion)
|
|
265
|
+
const state = { start: 0, end: 2, buffer: null }
|
|
266
|
+
collection3_enc.preencode(state, record)
|
|
267
|
+
state.buffer = b4a.allocUnsafe(state.end)
|
|
268
|
+
state.buffer[state.start++] = 0
|
|
269
|
+
state.buffer[state.start++] = collectionVersion
|
|
270
|
+
collection3_enc.encode(state, record)
|
|
271
|
+
return state.buffer
|
|
272
|
+
},
|
|
273
|
+
trigger: null,
|
|
274
|
+
reconstruct: collection3_reconstruct,
|
|
275
|
+
reconstructKey: collection3_reconstruct_key,
|
|
276
|
+
indexes: [],
|
|
277
|
+
decodedVersion: 0
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// '@gip/files-by-branch' collection key
|
|
281
|
+
const index4_key = new IndexEncoder(
|
|
282
|
+
[IndexEncoder.STRING, IndexEncoder.STRING, IndexEncoder.STRING],
|
|
283
|
+
{ prefix: 4 }
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
function index4_indexify(record) {
|
|
287
|
+
const arr = []
|
|
288
|
+
|
|
289
|
+
const a0 = record.branch
|
|
290
|
+
if (a0 === undefined) return arr
|
|
291
|
+
arr.push(a0)
|
|
292
|
+
|
|
293
|
+
const a1 = record.branch
|
|
294
|
+
if (a1 === undefined) return arr
|
|
295
|
+
arr.push(a1)
|
|
296
|
+
|
|
297
|
+
const a2 = record.path
|
|
298
|
+
if (a2 === undefined) return arr
|
|
299
|
+
arr.push(a2)
|
|
300
|
+
|
|
301
|
+
return arr
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// '@gip/files-by-branch'
|
|
305
|
+
const index4 = {
|
|
306
|
+
name: '@gip/files-by-branch',
|
|
307
|
+
version: 1,
|
|
308
|
+
id: 4,
|
|
309
|
+
encodeKey(record) {
|
|
310
|
+
return index4_key.encode(index4_indexify(record))
|
|
311
|
+
},
|
|
312
|
+
encodeKeyRange({ gt, lt, gte, lte } = {}) {
|
|
313
|
+
return index4_key.encodeRange({
|
|
314
|
+
gt: gt ? index4_indexify(gt) : null,
|
|
315
|
+
lt: lt ? index4_indexify(lt) : null,
|
|
316
|
+
gte: gte ? index4_indexify(gte) : null,
|
|
317
|
+
lte: lte ? index4_indexify(lte) : null
|
|
318
|
+
})
|
|
319
|
+
},
|
|
320
|
+
encodeValue: (record) => index4.collection.encodeKey(record),
|
|
321
|
+
encodeIndexKeys(record, context) {
|
|
322
|
+
return [index4_key.encode([record.branch, record.branch, record.path])]
|
|
323
|
+
},
|
|
324
|
+
reconstruct: (keyBuf, valueBuf) => valueBuf,
|
|
325
|
+
offset: collection2.indexes.length,
|
|
326
|
+
collection: collection2
|
|
327
|
+
}
|
|
328
|
+
collection2.indexes.push(index4)
|
|
329
|
+
|
|
330
|
+
const collections = [collection0, collection1, collection2, collection3]
|
|
331
|
+
|
|
332
|
+
const indexes = [index4]
|
|
333
|
+
|
|
334
|
+
module.exports = { versions, collections, indexes, resolveCollection, resolveIndex }
|
|
335
|
+
|
|
336
|
+
function resolveCollection(name) {
|
|
337
|
+
switch (name) {
|
|
338
|
+
case '@gip/repos':
|
|
339
|
+
return collection0
|
|
340
|
+
case '@gip/branches':
|
|
341
|
+
return collection1
|
|
342
|
+
case '@gip/files':
|
|
343
|
+
return collection2
|
|
344
|
+
case '@gip/objects':
|
|
345
|
+
return collection3
|
|
346
|
+
default:
|
|
347
|
+
return null
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function resolveIndex(name) {
|
|
352
|
+
switch (name) {
|
|
353
|
+
case '@gip/files-by-branch':
|
|
354
|
+
return index4
|
|
355
|
+
default:
|
|
356
|
+
return null
|
|
357
|
+
}
|
|
358
|
+
}
|