@yaks/git 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +754 -2
- package/_dist/address.d.ts +6 -0
- package/_dist/address.d.ts.map +1 -0
- package/_dist/checkout_vocab.d.ts +3 -0
- package/_dist/checkout_vocab.d.ts.map +1 -0
- package/_dist/cites.d.ts +48 -0
- package/_dist/cites.d.ts.map +1 -0
- package/_dist/commit.d.ts +36 -0
- package/_dist/commit.d.ts.map +1 -0
- package/_dist/comp.d.ts +29 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/door.d.ts +29 -0
- package/_dist/door.d.ts.map +1 -0
- package/_dist/format.d.ts +2 -0
- package/_dist/format.d.ts.map +1 -0
- package/_dist/hold.d.ts +6 -0
- package/_dist/hold.d.ts.map +1 -0
- package/_dist/host.d.ts +126 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/http.d.ts +33 -0
- package/_dist/http.d.ts.map +1 -0
- package/_dist/import.d.ts +13 -0
- package/_dist/import.d.ts.map +1 -0
- package/_dist/index.d.ts +80 -0
- package/_dist/index.d.ts.map +1 -0
- package/_dist/land.d.ts +77 -0
- package/_dist/land.d.ts.map +1 -0
- package/_dist/mod.d.ts +73 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/objects.d.ts +40 -0
- package/_dist/objects.d.ts.map +1 -0
- package/_dist/oid.d.ts +24 -0
- package/_dist/oid.d.ts.map +1 -0
- package/_dist/pack-store.d.ts +9 -0
- package/_dist/pack-store.d.ts.map +1 -0
- package/_dist/pack.d.ts +26 -0
- package/_dist/pack.d.ts.map +1 -0
- package/_dist/pkt.d.ts +14 -0
- package/_dist/pkt.d.ts.map +1 -0
- package/_dist/placement.d.ts +4 -0
- package/_dist/placement.d.ts.map +1 -0
- package/_dist/plugin.d.ts +43 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/project.d.ts +20 -0
- package/_dist/project.d.ts.map +1 -0
- package/_dist/push.d.ts +42 -0
- package/_dist/push.d.ts.map +1 -0
- package/_dist/refs.d.ts +81 -0
- package/_dist/refs.d.ts.map +1 -0
- package/_dist/rewrite.d.ts +35 -0
- package/_dist/rewrite.d.ts.map +1 -0
- package/_dist/service.d.ts +35 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/sha1.d.ts +11 -0
- package/_dist/sha1.d.ts.map +1 -0
- package/_dist/source.d.ts +12 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/tools.d.ts +11 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/tree.d.ts +28 -0
- package/_dist/tree.d.ts.map +1 -0
- package/_dist/unpack.d.ts +5 -0
- package/_dist/unpack.d.ts.map +1 -0
- package/_dist/vocab.d.ts +8 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/workspace.d.ts +17 -0
- package/_dist/workspace.d.ts.map +1 -0
- package/address.js +9 -0
- package/address.js.map +1 -0
- package/address.ts +15 -0
- package/cache.js +9 -0
- package/cache.js.map +1 -0
- package/cache.ts +6 -0
- package/checkout.js +18 -0
- package/checkout.js.map +1 -0
- package/checkout.ts +24 -0
- package/checkout_vocab.js +14 -0
- package/checkout_vocab.js.map +1 -0
- package/checkout_vocab.ts +11 -0
- package/cites.js +189 -0
- package/cites.js.map +1 -0
- package/cites.ts +206 -0
- package/commit.js +128 -0
- package/commit.js.map +1 -0
- package/commit.ts +183 -0
- package/comp.js +94 -0
- package/comp.js.map +1 -0
- package/comp.ts +111 -0
- package/deno.json +1 -0
- package/door.js +88 -0
- package/door.js.map +1 -0
- package/door.ts +142 -0
- package/format.js +43 -0
- package/format.js.map +1 -0
- package/format.ts +49 -0
- package/hold.js +17 -0
- package/hold.js.map +1 -0
- package/hold.ts +21 -0
- package/host.js +1024 -0
- package/host.js.map +1 -0
- package/host.ts +1140 -0
- package/http.js +268 -0
- package/http.js.map +1 -0
- package/http.ts +329 -0
- package/import.js +141 -0
- package/import.js.map +1 -0
- package/import.ts +128 -0
- package/index.js +496 -0
- package/index.js.map +1 -0
- package/index.ts +634 -0
- package/land.js +788 -0
- package/land.js.map +1 -0
- package/land.ts +871 -0
- package/mod.js +73 -0
- package/mod.js.map +1 -0
- package/mod.ts +74 -0
- package/objects.js +331 -0
- package/objects.js.map +1 -0
- package/objects.ts +390 -0
- package/oid.js +50 -0
- package/oid.js.map +1 -0
- package/oid.ts +83 -0
- package/pack-index.js +103 -0
- package/pack-index.js.map +1 -0
- package/pack-index.ts +104 -0
- package/pack-store.js +216 -0
- package/pack-store.js.map +1 -0
- package/pack-store.ts +292 -0
- package/pack.js +121 -0
- package/pack.js.map +1 -0
- package/pack.ts +146 -0
- package/package.json +78 -4
- package/pkt.js +73 -0
- package/pkt.js.map +1 -0
- package/pkt.ts +93 -0
- package/placement.js +44 -0
- package/placement.js.map +1 -0
- package/placement.ts +38 -0
- package/plugin.js +66 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +88 -0
- package/process-cwd.py +57 -0
- package/project.js +142 -0
- package/project.js.map +1 -0
- package/project.ts +151 -0
- package/push.js +401 -0
- package/push.js.map +1 -0
- package/push.ts +451 -0
- package/refs.js +176 -0
- package/refs.js.map +1 -0
- package/refs.ts +285 -0
- package/rewrite.js +176 -0
- package/rewrite.js.map +1 -0
- package/rewrite.ts +173 -0
- package/service.js +104 -0
- package/service.js.map +1 -0
- package/service.ts +194 -0
- package/sha1.js +115 -0
- package/sha1.js.map +1 -0
- package/sha1.ts +146 -0
- package/source.js +100 -0
- package/source.js.map +1 -0
- package/source.ts +116 -0
- package/spare.js +108 -0
- package/spare.js.map +1 -0
- package/spare.ts +94 -0
- package/tools.js +278 -0
- package/tools.js.map +1 -0
- package/tools.ts +310 -0
- package/tree.js +105 -0
- package/tree.js.map +1 -0
- package/tree.ts +132 -0
- package/unpack.js +207 -0
- package/unpack.js.map +1 -0
- package/unpack.ts +210 -0
- package/vocab.js +20 -0
- package/vocab.js.map +1 -0
- package/vocab.json +386 -0
- package/vocab.ts +22 -0
- package/workspace.js +449 -0
- package/workspace.js.map +1 -0
- package/workspace.ts +445 -0
package/pack.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// A packfile, version 2, written as a stream: `PACK`, how many objects follow,
|
|
2
|
+
// then each one's header and deflated body, then the SHA-1 of all of it.
|
|
3
|
+
//
|
|
4
|
+
// The format is small enough to give here in full:
|
|
5
|
+
//
|
|
6
|
+
// 'pack' 0x00000002 <count> 12 bytes, big-endian
|
|
7
|
+
// per object: <type+size varint> <zlib(body)>
|
|
8
|
+
// <sha1 of every byte above> 20 bytes
|
|
9
|
+
//
|
|
10
|
+
// Three details are most of it, and each is somewhere a hand-written packer
|
|
11
|
+
// usually goes wrong:
|
|
12
|
+
//
|
|
13
|
+
// - **The count is in the header**, so it is a parameter here rather than
|
|
14
|
+
// something counted on the way past: a packfile cannot be written without
|
|
15
|
+
// knowing first how many objects it holds. Whatever enumerated the objects
|
|
16
|
+
// (./objects.ts) already knows.
|
|
17
|
+
// - **The size in an entry's header is the unpacked size**, and after the
|
|
18
|
+
// first byte it is little-endian in seven-bit groups; the first byte carries
|
|
19
|
+
// the type in bits 4-6 and only the low four bits of the size.
|
|
20
|
+
// - **The body is zlib, not raw deflate.** `CompressionStream('deflate')` is
|
|
21
|
+
// the zlib wrapper Git expects; `'deflate-raw'` (what a zip file uses)
|
|
22
|
+
// writes a packfile no Git will read.
|
|
23
|
+
//
|
|
24
|
+
// No deltas. Every object is stored whole (`OBJ_*`, never `OBJ_*_DELTA`),
|
|
25
|
+
// which the format always permits — a first clone is the full reachable set,
|
|
26
|
+
// and delta compression is a size optimisation for later (D-34943).
|
|
27
|
+
//
|
|
28
|
+
// It streams because a clone is as big as a repository: the trailer digest is
|
|
29
|
+
// folded in by ./sha1.ts as the bytes go past. Object bodies can stream
|
|
30
|
+
// straight from storage through compression.
|
|
31
|
+
import { fromChunks, gathered } from "@yaks/blob";
|
|
32
|
+
import { concat } from "./oid.js";
|
|
33
|
+
import { sha1 } from "./sha1.js";
|
|
34
|
+
// The type numbers a packfile entry uses. 5 is unused, and 6 and 7 are the
|
|
35
|
+
// delta types this package does not write.
|
|
36
|
+
let CODE = {
|
|
37
|
+
commit: 1,
|
|
38
|
+
tree: 2,
|
|
39
|
+
blob: 3,
|
|
40
|
+
tag: 4
|
|
41
|
+
};
|
|
42
|
+
let utf8 = new TextEncoder();
|
|
43
|
+
/** The twelve bytes a packfile opens with. */ export let head = (count)=>{
|
|
44
|
+
let out = new Uint8Array(12);
|
|
45
|
+
out.set(utf8.encode('PACK'));
|
|
46
|
+
let view = new DataView(out.buffer);
|
|
47
|
+
view.setUint32(4, 2);
|
|
48
|
+
view.setUint32(8, count);
|
|
49
|
+
return out;
|
|
50
|
+
};
|
|
51
|
+
/** One object's header: its type, and its unpacked size as Git's varint. */ export let entry = (type, size)=>{
|
|
52
|
+
let rest = Math.floor(size / 16);
|
|
53
|
+
let out = [
|
|
54
|
+
(rest ? 0x80 : 0) | CODE[type] << 4 | size % 16
|
|
55
|
+
];
|
|
56
|
+
while(rest){
|
|
57
|
+
let seven = rest % 128;
|
|
58
|
+
rest = Math.floor(rest / 128);
|
|
59
|
+
out.push((rest ? 0x80 : 0) | seven);
|
|
60
|
+
}
|
|
61
|
+
return Uint8Array.from(out);
|
|
62
|
+
};
|
|
63
|
+
/** A body as a packfile stores it: zlib, which is `deflate`, not
|
|
64
|
+
* `deflate-raw`. */ export let deflate = (bytes)=>gathered({
|
|
65
|
+
stream: fromChunks(zipped(whole(bytes), bytes.length))
|
|
66
|
+
});
|
|
67
|
+
async function* whole(bytes) {
|
|
68
|
+
yield bytes;
|
|
69
|
+
}
|
|
70
|
+
// Let downstream backpressure reach the source, checking the size promised
|
|
71
|
+
// in the entry header as the bytes go through.
|
|
72
|
+
async function* zipped(body, size) {
|
|
73
|
+
let measured = 0;
|
|
74
|
+
async function* checked() {
|
|
75
|
+
for await (let chunk of body){
|
|
76
|
+
measured += chunk.byteLength;
|
|
77
|
+
if (measured > size) throw new Error('git: object exceeds its size');
|
|
78
|
+
yield chunk.buffer instanceof ArrayBuffer ? chunk : concat([
|
|
79
|
+
chunk
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
if (measured != size) throw new Error('git: truncated object body');
|
|
83
|
+
}
|
|
84
|
+
let input = fromChunks(checked());
|
|
85
|
+
yield* input.pipeThrough(new CompressionStream('deflate'));
|
|
86
|
+
}
|
|
87
|
+
// Every byte of the packfile, in order, with the trailer digest folded in as
|
|
88
|
+
// they pass.
|
|
89
|
+
async function* chunks(count, objects, prior) {
|
|
90
|
+
let sum = sha1();
|
|
91
|
+
let said = 0;
|
|
92
|
+
let out = (bytes)=>(sum.update(bytes), bytes);
|
|
93
|
+
yield out(head(count));
|
|
94
|
+
if (prior) {
|
|
95
|
+
said = prior.count;
|
|
96
|
+
for await (let bytes of prior.entries)yield out(bytes);
|
|
97
|
+
}
|
|
98
|
+
for await (let o of objects){
|
|
99
|
+
said++;
|
|
100
|
+
let size = 'bytes' in o ? o.bytes.length : o.size;
|
|
101
|
+
yield out(entry(o.type, size));
|
|
102
|
+
let body = 'bytes' in o ? whole(o.bytes) : await o.body();
|
|
103
|
+
for await (let part of zipped(body, size))yield out(part);
|
|
104
|
+
}
|
|
105
|
+
// The header states how many objects follow, and a reader that trusted a
|
|
106
|
+
// wrong count would stop early or run off the end. Better a broken stream
|
|
107
|
+
// than a corrupt packfile.
|
|
108
|
+
if (said != count) {
|
|
109
|
+
throw new Error(`git: pack said ${count} objects and wrote ${said}`);
|
|
110
|
+
}
|
|
111
|
+
yield sum.digest();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A version 2 packfile over these objects, in this order.
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* // let bytes = pack(2, [{ type: 'blob', bytes: hello }, commitObj])
|
|
118
|
+
* // await new Response(bytes).arrayBuffer()
|
|
119
|
+
* ```
|
|
120
|
+
*/ export let pack = (count, objects, prior)=>fromChunks(chunks(count, objects, prior));
|
|
121
|
+
//# sourceMappingURL=pack.js.map
|
package/pack.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.js","sources":["./pack.ts"],"names":[],"mappings":"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"}
|
package/pack.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// A packfile, version 2, written as a stream: `PACK`, how many objects follow,
|
|
2
|
+
// then each one's header and deflated body, then the SHA-1 of all of it.
|
|
3
|
+
//
|
|
4
|
+
// The format is small enough to give here in full:
|
|
5
|
+
//
|
|
6
|
+
// 'pack' 0x00000002 <count> 12 bytes, big-endian
|
|
7
|
+
// per object: <type+size varint> <zlib(body)>
|
|
8
|
+
// <sha1 of every byte above> 20 bytes
|
|
9
|
+
//
|
|
10
|
+
// Three details are most of it, and each is somewhere a hand-written packer
|
|
11
|
+
// usually goes wrong:
|
|
12
|
+
//
|
|
13
|
+
// - **The count is in the header**, so it is a parameter here rather than
|
|
14
|
+
// something counted on the way past: a packfile cannot be written without
|
|
15
|
+
// knowing first how many objects it holds. Whatever enumerated the objects
|
|
16
|
+
// (./objects.ts) already knows.
|
|
17
|
+
// - **The size in an entry's header is the unpacked size**, and after the
|
|
18
|
+
// first byte it is little-endian in seven-bit groups; the first byte carries
|
|
19
|
+
// the type in bits 4-6 and only the low four bits of the size.
|
|
20
|
+
// - **The body is zlib, not raw deflate.** `CompressionStream('deflate')` is
|
|
21
|
+
// the zlib wrapper Git expects; `'deflate-raw'` (what a zip file uses)
|
|
22
|
+
// writes a packfile no Git will read.
|
|
23
|
+
//
|
|
24
|
+
// No deltas. Every object is stored whole (`OBJ_*`, never `OBJ_*_DELTA`),
|
|
25
|
+
// which the format always permits — a first clone is the full reachable set,
|
|
26
|
+
// and delta compression is a size optimisation for later (D-34943).
|
|
27
|
+
//
|
|
28
|
+
// It streams because a clone is as big as a repository: the trailer digest is
|
|
29
|
+
// folded in by ./sha1.ts as the bytes go past. Object bodies can stream
|
|
30
|
+
// straight from storage through compression.
|
|
31
|
+
|
|
32
|
+
import { fromChunks, gathered } from '@yaks/blob'
|
|
33
|
+
import { concat, type Kind } from './oid.js'
|
|
34
|
+
import { sha1 } from './sha1.js'
|
|
35
|
+
|
|
36
|
+
/** One object to pack: its type, and the bytes its id was taken over. */
|
|
37
|
+
export type Obj = { type: Kind; bytes: Uint8Array }
|
|
38
|
+
|
|
39
|
+
type PackedObject = Obj | {
|
|
40
|
+
type: Kind
|
|
41
|
+
size: number
|
|
42
|
+
body: () => Promise<ReadableStream<Uint8Array>>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The type numbers a packfile entry uses. 5 is unused, and 6 and 7 are the
|
|
46
|
+
// delta types this package does not write.
|
|
47
|
+
let CODE: Record<Kind, number> = { commit: 1, tree: 2, blob: 3, tag: 4 }
|
|
48
|
+
|
|
49
|
+
let utf8 = new TextEncoder()
|
|
50
|
+
|
|
51
|
+
/** The twelve bytes a packfile opens with. */
|
|
52
|
+
export let head = (count: number): Uint8Array<ArrayBuffer> => {
|
|
53
|
+
let out = new Uint8Array(12)
|
|
54
|
+
out.set(utf8.encode('PACK'))
|
|
55
|
+
let view = new DataView(out.buffer)
|
|
56
|
+
view.setUint32(4, 2)
|
|
57
|
+
view.setUint32(8, count)
|
|
58
|
+
return out
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One object's header: its type, and its unpacked size as Git's varint. */
|
|
62
|
+
export let entry = (type: Kind, size: number): Uint8Array => {
|
|
63
|
+
let rest = Math.floor(size / 16)
|
|
64
|
+
let out = [(rest ? 0x80 : 0) | (CODE[type] << 4) | (size % 16)]
|
|
65
|
+
while (rest) {
|
|
66
|
+
let seven = rest % 128
|
|
67
|
+
rest = Math.floor(rest / 128)
|
|
68
|
+
out.push((rest ? 0x80 : 0) | seven)
|
|
69
|
+
}
|
|
70
|
+
return Uint8Array.from(out)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A body as a packfile stores it: zlib, which is `deflate`, not
|
|
74
|
+
* `deflate-raw`. */
|
|
75
|
+
export let deflate = (bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> =>
|
|
76
|
+
gathered({ stream: fromChunks(zipped(whole(bytes), bytes.length)) })
|
|
77
|
+
|
|
78
|
+
async function* whole(bytes: Uint8Array) {
|
|
79
|
+
yield bytes
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Let downstream backpressure reach the source, checking the size promised
|
|
83
|
+
// in the entry header as the bytes go through.
|
|
84
|
+
async function* zipped(
|
|
85
|
+
body: AsyncIterable<Uint8Array>,
|
|
86
|
+
size: number,
|
|
87
|
+
) {
|
|
88
|
+
let measured = 0
|
|
89
|
+
async function* checked() {
|
|
90
|
+
for await (let chunk of body) {
|
|
91
|
+
measured += chunk.byteLength
|
|
92
|
+
if (measured > size) throw new Error('git: object exceeds its size')
|
|
93
|
+
yield chunk.buffer instanceof ArrayBuffer
|
|
94
|
+
? chunk as Uint8Array<ArrayBuffer>
|
|
95
|
+
: concat([chunk])
|
|
96
|
+
}
|
|
97
|
+
if (measured != size) throw new Error('git: truncated object body')
|
|
98
|
+
}
|
|
99
|
+
let input = fromChunks(checked()) as ReadableStream<BufferSource>
|
|
100
|
+
yield* input.pipeThrough(new CompressionStream('deflate'))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Every byte of the packfile, in order, with the trailer digest folded in as
|
|
104
|
+
// they pass.
|
|
105
|
+
async function* chunks(
|
|
106
|
+
count: number,
|
|
107
|
+
objects: AsyncIterable<PackedObject> | Iterable<PackedObject>,
|
|
108
|
+
prior?: { count: number; entries: ReadableStream<Uint8Array> },
|
|
109
|
+
): AsyncGenerator<Uint8Array> {
|
|
110
|
+
let sum = sha1()
|
|
111
|
+
let said = 0
|
|
112
|
+
let out = (bytes: Uint8Array) => (sum.update(bytes), bytes)
|
|
113
|
+
yield out(head(count))
|
|
114
|
+
if (prior) {
|
|
115
|
+
said = prior.count
|
|
116
|
+
for await (let bytes of prior.entries) yield out(bytes)
|
|
117
|
+
}
|
|
118
|
+
for await (let o of objects) {
|
|
119
|
+
said++
|
|
120
|
+
let size = 'bytes' in o ? o.bytes.length : o.size
|
|
121
|
+
yield out(entry(o.type, size))
|
|
122
|
+
let body = 'bytes' in o ? whole(o.bytes) : await o.body()
|
|
123
|
+
for await (let part of zipped(body, size)) yield out(part)
|
|
124
|
+
}
|
|
125
|
+
// The header states how many objects follow, and a reader that trusted a
|
|
126
|
+
// wrong count would stop early or run off the end. Better a broken stream
|
|
127
|
+
// than a corrupt packfile.
|
|
128
|
+
if (said != count) {
|
|
129
|
+
throw new Error(`git: pack said ${count} objects and wrote ${said}`)
|
|
130
|
+
}
|
|
131
|
+
yield sum.digest()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A version 2 packfile over these objects, in this order.
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* // let bytes = pack(2, [{ type: 'blob', bytes: hello }, commitObj])
|
|
139
|
+
* // await new Response(bytes).arrayBuffer()
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export let pack = (
|
|
143
|
+
count: number,
|
|
144
|
+
objects: AsyncIterable<PackedObject> | Iterable<PackedObject>,
|
|
145
|
+
prior?: { count: number; entries: ReadableStream<Uint8Array> },
|
|
146
|
+
): ReadableStream<Uint8Array> => fromChunks(chunks(count, objects, prior))
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/git",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/git",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./cites": {
|
|
12
|
+
"types": "./_dist/cites.d.ts",
|
|
13
|
+
"default": "./cites.js"
|
|
14
|
+
},
|
|
15
|
+
"./door": {
|
|
16
|
+
"types": "./_dist/door.d.ts",
|
|
17
|
+
"default": "./door.js"
|
|
18
|
+
},
|
|
19
|
+
"./address": {
|
|
20
|
+
"types": "./_dist/address.d.ts",
|
|
21
|
+
"default": "./address.js"
|
|
22
|
+
},
|
|
23
|
+
"./push": {
|
|
24
|
+
"types": "./_dist/push.d.ts",
|
|
25
|
+
"default": "./push.js"
|
|
26
|
+
},
|
|
27
|
+
"./host": {
|
|
28
|
+
"types": "./_dist/host.d.ts",
|
|
29
|
+
"default": "./host.js"
|
|
30
|
+
},
|
|
31
|
+
"./land": {
|
|
32
|
+
"types": "./_dist/land.d.ts",
|
|
33
|
+
"default": "./land.js"
|
|
34
|
+
},
|
|
35
|
+
"./hold": {
|
|
36
|
+
"types": "./_dist/hold.d.ts",
|
|
37
|
+
"default": "./hold.js"
|
|
38
|
+
},
|
|
39
|
+
"./tools": {
|
|
40
|
+
"types": "./_dist/tools.d.ts",
|
|
41
|
+
"default": "./tools.js"
|
|
42
|
+
},
|
|
43
|
+
"./vocab": {
|
|
44
|
+
"types": "./_dist/vocab.d.ts",
|
|
45
|
+
"default": "./vocab.js"
|
|
46
|
+
},
|
|
47
|
+
"./service": {
|
|
48
|
+
"types": "./_dist/service.d.ts",
|
|
49
|
+
"default": "./service.js"
|
|
50
|
+
},
|
|
51
|
+
"./source": {
|
|
52
|
+
"types": "./_dist/source.d.ts",
|
|
53
|
+
"default": "./source.js"
|
|
54
|
+
},
|
|
55
|
+
"./workspace": {
|
|
56
|
+
"types": "./_dist/workspace.d.ts",
|
|
57
|
+
"default": "./workspace.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"license": "Apache-2.0",
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@jsr/std__jsonc": "1.0.2",
|
|
63
|
+
"@yaks/blob": "0.2.36",
|
|
64
|
+
"@yaks/edge": "0.2.36",
|
|
65
|
+
"@yaks/effects": "0.2.36",
|
|
66
|
+
"@yaks/file": "0.2.36",
|
|
67
|
+
"@yaks/fp": "0.2.36",
|
|
68
|
+
"@yaks/graph": "0.2.36",
|
|
69
|
+
"@yaks/id": "0.2.36",
|
|
70
|
+
"@yaks/kernel": "0.2.36",
|
|
71
|
+
"@yaks/key": "0.2.36",
|
|
72
|
+
"@yaks/machine": "0.2.36",
|
|
73
|
+
"@yaks/process": "0.2.36",
|
|
74
|
+
"@yaks/query": "0.2.36",
|
|
75
|
+
"@yaks/tools": "0.2.36",
|
|
76
|
+
"@yaks/vocab": "0.2.36"
|
|
77
|
+
},
|
|
78
|
+
"description": "Builds Git trees and commits from a file manifest, stores the objects as graph entities, and serves clones and pushes over Git smart HTTP.",
|
|
79
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
80
|
+
}
|
package/pkt.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// pkt-line: the framing every byte of Git's protocol travels in. Four hex
|
|
2
|
+
// digits giving the packet's length, counting the four digits themselves, then
|
|
3
|
+
// that many bytes.
|
|
4
|
+
//
|
|
5
|
+
// 0009done\n a line: 9 bytes in all, 5 of payload
|
|
6
|
+
// 0000 flush — the end of a message
|
|
7
|
+
// 0001 delim — the end of a command's capabilities
|
|
8
|
+
// 0002 response-end — the end of a multiplexed response
|
|
9
|
+
//
|
|
10
|
+
// The length includes itself, which is the one thing a hand-written encoder
|
|
11
|
+
// gets wrong, and the reason `0000`-`0003` can be markers at all: no real
|
|
12
|
+
// packet can be shorter than its own header. `0003` is unused, and `0004` is a
|
|
13
|
+
// legal empty line rather than a marker.
|
|
14
|
+
//
|
|
15
|
+
// A marker is read back as its own number, and a line as its text with the
|
|
16
|
+
// trailing newline removed — so `typeof p == 'string'` is all it takes to tell
|
|
17
|
+
// a line from a marker, and no line's text can be mistaken for one.
|
|
18
|
+
//
|
|
19
|
+
// The longest packet is 65520 bytes, so the longest payload is 65516; Git
|
|
20
|
+
// calls that LARGE_PACKET_MAX. A side-band packet spends one more byte on the
|
|
21
|
+
// band it belongs to, which is why {@link BAND} is one less again.
|
|
22
|
+
//
|
|
23
|
+
// Nothing here streams. A request body is wants and haves — kilobytes — and
|
|
24
|
+
// reading it whole is simpler than a decoder that can resume mid-packet. The
|
|
25
|
+
// response is what streams (./http.ts), and it is written, not parsed.
|
|
26
|
+
import { concat } from "./oid.js";
|
|
27
|
+
let utf8 = new TextEncoder();
|
|
28
|
+
let text = new TextDecoder();
|
|
29
|
+
/** The end of a message. */ export let FLUSH = 0;
|
|
30
|
+
/** The end of a command's capabilities, before its arguments. */ export let DELIM = 1;
|
|
31
|
+
/** The end of one response inside a multiplexed stream. */ export let END = 2;
|
|
32
|
+
/** The most one packet can carry. */ export let MAX = 65516;
|
|
33
|
+
/** The most one side-band packet can carry: a packet, less the band byte. */ export let BAND = MAX - 1;
|
|
34
|
+
let four = (n)=>n.toString(16).padStart(4, '0');
|
|
35
|
+
/** One of the markers, as the four bytes it is sent as. */ export let mark = (which)=>utf8.encode(four(which));
|
|
36
|
+
/** One pkt-line over this payload. Give a line its own trailing newline: Git
|
|
37
|
+
* writes one and this does not add it, because a packet is just bytes. */ export let pkt = (data)=>{
|
|
38
|
+
let body = typeof data == 'string' ? utf8.encode(data) : data;
|
|
39
|
+
if (body.length > MAX) {
|
|
40
|
+
throw new Error(`git: pkt-line of ${body.length} bytes, max ${MAX}`);
|
|
41
|
+
}
|
|
42
|
+
return concat([
|
|
43
|
+
utf8.encode(four(4 + body.length)),
|
|
44
|
+
body
|
|
45
|
+
]);
|
|
46
|
+
};
|
|
47
|
+
/** One side-band packet: which band these bytes belong to (1 pack data, 2
|
|
48
|
+
* progress, 3 error), then the bytes. */ export let band = (which, data)=>pkt(concat([
|
|
49
|
+
Uint8Array.of(which),
|
|
50
|
+
data
|
|
51
|
+
]));
|
|
52
|
+
let LEN = /^[0-9a-f]{4}$/;
|
|
53
|
+
/** Every packet in these bytes, in order: lines as text without their trailing
|
|
54
|
+
* newline, markers as their number. */ export let read = (bytes)=>{
|
|
55
|
+
let out = [];
|
|
56
|
+
let at = 0;
|
|
57
|
+
while(at < bytes.length){
|
|
58
|
+
let head = text.decode(bytes.subarray(at, at + 4));
|
|
59
|
+
if (!LEN.test(head)) throw new Error(`git: pkt-line length ${head}`);
|
|
60
|
+
let len = parseInt(head, 16);
|
|
61
|
+
if (len < 4) {
|
|
62
|
+
out.push(len);
|
|
63
|
+
at += 4;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (at + len > bytes.length) throw new Error('git: pkt-line runs past end');
|
|
67
|
+
let line = text.decode(bytes.subarray(at + 4, at + len));
|
|
68
|
+
out.push(line.endsWith('\n') ? line.slice(0, -1) : line);
|
|
69
|
+
at += len;
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=pkt.js.map
|
package/pkt.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkt.js","sources":["./pkt.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+EAA+E;AAC/E,mBAAmB;AACnB,EAAE;AACF,+DAA+D;AAC/D,uDAAuD;AACvD,sEAAsE;AACtE,2EAA2E;AAC3E,EAAE;AACF,4EAA4E;AAC5E,0EAA0E;AAC1E,+EAA+E;AAC/E,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,oEAAoE;AACpE,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,mEAAmE;AACnE,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,uEAAuE;AAEvE,SAAS,MAAM,mBAAkB;AAEjC,IAAI,OAAO,IAAI;AACf,IAAI,OAAO,IAAI;AAEf,0BAA0B,GAC1B,OAAO,IAAI,QAAQ,EAAC;AAEpB,+DAA+D,GAC/D,OAAO,IAAI,QAAQ,EAAC;AAEpB,yDAAyD,GACzD,OAAO,IAAI,MAAM,EAAC;AAKlB,mCAAmC,GACnC,OAAO,IAAI,MAAM,MAAK;AAEtB,2EAA2E,GAC3E,OAAO,IAAI,OAAO,MAAM,EAAC;AAEzB,IAAI,OAAO,CAAC,IAAc,EAAE,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG;AAErD,yDAAyD,GACzD,OAAO,IAAI,OAAO,CAAC,QACjB,KAAK,MAAM,CAAC,KAAK,QAAO;AAE1B;wEACwE,GACxE,OAAO,IAAI,MAAM,CAAC;EAChB,IAAI,OAAO,OAAO,QAAQ,WAAW,KAAK,MAAM,CAAC,QAAQ;EACzD,IAAI,KAAK,MAAM,GAAG,KAAK;IACrB,MAAM,IAAI,MAAM,CAAC,iBAAiB,EAAE,KAAK,MAAM,CAAC,YAAY,EAAE,KAAK;EACrE;EACA,OAAO,OAAO;IAAC,KAAK,MAAM,CAAC,KAAK,IAAI,KAAK,MAAM;IAAI;GAAK;AAC1D,EAAC;AAED;uCACuC,GACvC,OAAO,IAAI,OAAO,CAAC,OAAe,OAChC,IAAI,OAAO;IAAC,WAAW,EAAE,CAAC;IAAQ;GAAK,GAAE;AAE3C,IAAI,MAAM;AAEV;qCACqC,GACrC,OAAO,IAAI,OAAO,CAAC;EACjB,IAAI,MAAa,EAAE;EACnB,IAAI,KAAK;EACT,MAAO,KAAK,MAAM,MAAM,CAAE;IACxB,IAAI,OAAO,KAAK,MAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,KAAK;IAC/C,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,CAAC,qBAAqB,EAAE,MAAM;IACnE,IAAI,MAAM,SAAS,MAAM;IACzB,IAAI,MAAM,GAAG;MACX,IAAI,IAAI,CAAC;MACT,MAAM;MACN;IACF;IACA,IAAI,KAAK,MAAM,MAAM,MAAM,EAAE,MAAM,IAAI,MAAM;IAC7C,IAAI,OAAO,KAAK,MAAM,CAAC,MAAM,QAAQ,CAAC,KAAK,GAAG,KAAK;IACnD,IAAI,IAAI,CAAC,KAAK,QAAQ,CAAC,QAAQ,KAAK,KAAK,CAAC,GAAG,CAAC,KAAK;IACnD,MAAM;EACR;EACA,OAAO;AACT,EAAC"}
|
package/pkt.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// pkt-line: the framing every byte of Git's protocol travels in. Four hex
|
|
2
|
+
// digits giving the packet's length, counting the four digits themselves, then
|
|
3
|
+
// that many bytes.
|
|
4
|
+
//
|
|
5
|
+
// 0009done\n a line: 9 bytes in all, 5 of payload
|
|
6
|
+
// 0000 flush — the end of a message
|
|
7
|
+
// 0001 delim — the end of a command's capabilities
|
|
8
|
+
// 0002 response-end — the end of a multiplexed response
|
|
9
|
+
//
|
|
10
|
+
// The length includes itself, which is the one thing a hand-written encoder
|
|
11
|
+
// gets wrong, and the reason `0000`-`0003` can be markers at all: no real
|
|
12
|
+
// packet can be shorter than its own header. `0003` is unused, and `0004` is a
|
|
13
|
+
// legal empty line rather than a marker.
|
|
14
|
+
//
|
|
15
|
+
// A marker is read back as its own number, and a line as its text with the
|
|
16
|
+
// trailing newline removed — so `typeof p == 'string'` is all it takes to tell
|
|
17
|
+
// a line from a marker, and no line's text can be mistaken for one.
|
|
18
|
+
//
|
|
19
|
+
// The longest packet is 65520 bytes, so the longest payload is 65516; Git
|
|
20
|
+
// calls that LARGE_PACKET_MAX. A side-band packet spends one more byte on the
|
|
21
|
+
// band it belongs to, which is why {@link BAND} is one less again.
|
|
22
|
+
//
|
|
23
|
+
// Nothing here streams. A request body is wants and haves — kilobytes — and
|
|
24
|
+
// reading it whole is simpler than a decoder that can resume mid-packet. The
|
|
25
|
+
// response is what streams (./http.ts), and it is written, not parsed.
|
|
26
|
+
|
|
27
|
+
import { concat } from './oid.js'
|
|
28
|
+
|
|
29
|
+
let utf8 = new TextEncoder()
|
|
30
|
+
let text = new TextDecoder()
|
|
31
|
+
|
|
32
|
+
/** The end of a message. */
|
|
33
|
+
export let FLUSH = 0
|
|
34
|
+
|
|
35
|
+
/** The end of a command's capabilities, before its arguments. */
|
|
36
|
+
export let DELIM = 1
|
|
37
|
+
|
|
38
|
+
/** The end of one response inside a multiplexed stream. */
|
|
39
|
+
export let END = 2
|
|
40
|
+
|
|
41
|
+
/** A packet as it is read back: a line's text, or a marker's own number. */
|
|
42
|
+
export type Pkt = string | number
|
|
43
|
+
|
|
44
|
+
/** The most one packet can carry. */
|
|
45
|
+
export let MAX = 65516
|
|
46
|
+
|
|
47
|
+
/** The most one side-band packet can carry: a packet, less the band byte. */
|
|
48
|
+
export let BAND = MAX - 1
|
|
49
|
+
|
|
50
|
+
let four = (n: number) => n.toString(16).padStart(4, '0')
|
|
51
|
+
|
|
52
|
+
/** One of the markers, as the four bytes it is sent as. */
|
|
53
|
+
export let mark = (which: number): Uint8Array<ArrayBuffer> =>
|
|
54
|
+
utf8.encode(four(which))
|
|
55
|
+
|
|
56
|
+
/** One pkt-line over this payload. Give a line its own trailing newline: Git
|
|
57
|
+
* writes one and this does not add it, because a packet is just bytes. */
|
|
58
|
+
export let pkt = (data: string | Uint8Array): Uint8Array<ArrayBuffer> => {
|
|
59
|
+
let body = typeof data == 'string' ? utf8.encode(data) : data
|
|
60
|
+
if (body.length > MAX) {
|
|
61
|
+
throw new Error(`git: pkt-line of ${body.length} bytes, max ${MAX}`)
|
|
62
|
+
}
|
|
63
|
+
return concat([utf8.encode(four(4 + body.length)), body])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One side-band packet: which band these bytes belong to (1 pack data, 2
|
|
67
|
+
* progress, 3 error), then the bytes. */
|
|
68
|
+
export let band = (which: number, data: Uint8Array): Uint8Array<ArrayBuffer> =>
|
|
69
|
+
pkt(concat([Uint8Array.of(which), data]))
|
|
70
|
+
|
|
71
|
+
let LEN = /^[0-9a-f]{4}$/
|
|
72
|
+
|
|
73
|
+
/** Every packet in these bytes, in order: lines as text without their trailing
|
|
74
|
+
* newline, markers as their number. */
|
|
75
|
+
export let read = (bytes: Uint8Array): Pkt[] => {
|
|
76
|
+
let out: Pkt[] = []
|
|
77
|
+
let at = 0
|
|
78
|
+
while (at < bytes.length) {
|
|
79
|
+
let head = text.decode(bytes.subarray(at, at + 4))
|
|
80
|
+
if (!LEN.test(head)) throw new Error(`git: pkt-line length ${head}`)
|
|
81
|
+
let len = parseInt(head, 16)
|
|
82
|
+
if (len < 4) {
|
|
83
|
+
out.push(len)
|
|
84
|
+
at += 4
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
if (at + len > bytes.length) throw new Error('git: pkt-line runs past end')
|
|
88
|
+
let line = text.decode(bytes.subarray(at + 4, at + len))
|
|
89
|
+
out.push(line.endsWith('\n') ? line.slice(0, -1) : line)
|
|
90
|
+
at += len
|
|
91
|
+
}
|
|
92
|
+
return out
|
|
93
|
+
}
|
package/placement.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Filesystem contexts are stable across linked checkouts and directory defaults.
|
|
2
|
+
// Only explicitly host-local entry points may select this computer.
|
|
3
|
+
import { derivedEid } from "@yaks/graph/identity";
|
|
4
|
+
import { here } from "@yaks/file/local";
|
|
5
|
+
/** One canonical root workspace per computer filesystem. */ export let filesystemEid = (machine)=>derivedEid('computer filesystem|' + machine);
|
|
6
|
+
/** Select this computer (@yaks/file's `here`) and its filesystem workspace,
|
|
7
|
+
* creating the workspace once. A directory is never a computer identity.
|
|
8
|
+
* Remote APIs never call this helper. */ let select = async (g)=>{
|
|
9
|
+
let machine = await here(g);
|
|
10
|
+
let eid = filesystemEid(machine);
|
|
11
|
+
let [known] = await g.get([
|
|
12
|
+
eid
|
|
13
|
+
]);
|
|
14
|
+
if (!known?.workspace) {
|
|
15
|
+
await g.apply([
|
|
16
|
+
{
|
|
17
|
+
entity: {
|
|
18
|
+
eid
|
|
19
|
+
},
|
|
20
|
+
workspace: {
|
|
21
|
+
machine,
|
|
22
|
+
root: '/'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
]);
|
|
26
|
+
[known] = await g.get([
|
|
27
|
+
eid
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
let place = known.workspace;
|
|
31
|
+
if (place.machine != machine || place.root != '/' || place.sandbox) {
|
|
32
|
+
throw Error('Canonical local filesystem workspace has conflicting placement');
|
|
33
|
+
}
|
|
34
|
+
return known;
|
|
35
|
+
};
|
|
36
|
+
let selecting = new WeakMap();
|
|
37
|
+
export let localFilesystem = (g)=>{
|
|
38
|
+
let current = selecting.get(g);
|
|
39
|
+
if (current) return current;
|
|
40
|
+
let next = select(g).finally(()=>selecting.delete(g));
|
|
41
|
+
selecting.set(g, next);
|
|
42
|
+
return next;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=placement.js.map
|
package/placement.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement.js","sources":["./placement.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,oEAAoE;AAEpE,SAAS,UAAU,oCAAyC;AAC5D,SAAS,IAAI,gCAAqC;AAElD,0DAA0D,GAC1D,OAAO,IAAI,gBAAgB,CAAC,UAC1B,WAAW,yBAAyB,SAAQ;AAE9C;;uCAEuC,GACvC,IAAI,SAAS,OAAO;EAClB,IAAI,UAAU,MAAM,KAAK;EACzB,IAAI,MAAM,cAAc;EACxB,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC;IAAC;GAAI;EAC/B,IAAI,CAAC,OAAO,WAAW;IACrB,MAAM,EAAE,KAAK,CAAC;MAAC;QAAE,QAAQ;UAAE;QAAI;QAAG,WAAW;UAAE;UAAS,MAAM;QAAI;MAAE;KAAE;IACrE,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC;MAAC;KAAI;EAC9B;EACA,IAAI,QAAQ,MAAO,SAAS;EAC5B,IAAI,MAAM,OAAO,IAAI,WAAW,MAAM,IAAI,IAAI,OAAO,MAAM,OAAO,EAAE;IAClE,MAAM,MACJ;EAEJ;EACA,OAAO;AACT;AAEA,IAAI,YAAY,IAAI;AACpB,OAAO,IAAI,kBAAkB,CAAC;EAC5B,IAAI,UAAU,UAAU,GAAG,CAAC;EAC5B,IAAI,SAAS,OAAO;EACpB,IAAI,OAAO,OAAO,GAAG,OAAO,CAAC,IAAM,UAAU,MAAM,CAAC;EACpD,UAAU,GAAG,CAAC,GAAG;EACjB,OAAO;AACT,EAAC"}
|
package/placement.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Filesystem contexts are stable across linked checkouts and directory defaults.
|
|
2
|
+
// Only explicitly host-local entry points may select this computer.
|
|
3
|
+
import type { Bundle, Comp, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
4
|
+
import { derivedEid } from '@yaks/graph/identity'
|
|
5
|
+
import { here } from '@yaks/file/local'
|
|
6
|
+
|
|
7
|
+
/** One canonical root workspace per computer filesystem. */
|
|
8
|
+
export let filesystemEid = (machine: string): string =>
|
|
9
|
+
derivedEid('computer filesystem|' + machine)
|
|
10
|
+
|
|
11
|
+
/** Select this computer (@yaks/file's `here`) and its filesystem workspace,
|
|
12
|
+
* creating the workspace once. A directory is never a computer identity.
|
|
13
|
+
* Remote APIs never call this helper. */
|
|
14
|
+
let select = async (g: Graph): Promise<Bundle> => {
|
|
15
|
+
let machine = await here(g)
|
|
16
|
+
let eid = filesystemEid(machine)
|
|
17
|
+
let [known] = await g.get([eid])
|
|
18
|
+
if (!known?.workspace) {
|
|
19
|
+
await g.apply([{ entity: { eid }, workspace: { machine, root: '/' } }])
|
|
20
|
+
;[known] = await g.get([eid])
|
|
21
|
+
}
|
|
22
|
+
let place = known!.workspace as Comp
|
|
23
|
+
if (place.machine != machine || place.root != '/' || place.sandbox) {
|
|
24
|
+
throw Error(
|
|
25
|
+
'Canonical local filesystem workspace has conflicting placement',
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
return known!
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let selecting = new WeakMap<Graph, Promise<Bundle>>()
|
|
32
|
+
export let localFilesystem = (g: Graph): Promise<Bundle> => {
|
|
33
|
+
let current = selecting.get(g)
|
|
34
|
+
if (current) return current
|
|
35
|
+
let next = select(g).finally(() => selecting.delete(g))
|
|
36
|
+
selecting.set(g, next)
|
|
37
|
+
return next
|
|
38
|
+
}
|