-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
28 lines (26 loc) · 742 Bytes
/
proxy.js
File metadata and controls
28 lines (26 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Proxy {
constructor({ registry, storage }){
this.storage = storage;
this.registry = registry;
}
async fetch(name, version){
const { registry, storage } = this;
let pkg = await storage.fetch(name, version);
if(pkg) return pkg;
console.warn(`[upkg] cache missing ${name}`);
pkg = await registry.fetch(name);
if(!pkg) return;
await storage.save(pkg);
version = pkg['dist-tags'][version] || version;
return version ? (pkg.versions[version]) : pkg;
}
async publish(pkg){
const { storage } = this;
await storage.publish(pkg);
}
async getFileStream(name, filename){
const { storage } = this;
return storage.getFileStream(name, filename);
}
}
module.exports = Proxy;