memfs 4.7.7 → 4.8.0
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/lib/cas/types.d.ts +5 -5
- package/lib/crud-to-cas/CrudCas.d.ts +3 -7
- package/lib/crud-to-cas/CrudCas.js +4 -46
- package/lib/crud-to-cas/CrudCas.js.map +1 -1
- package/lib/crud-to-cas/CrudCasBase.d.ts +14 -0
- package/lib/crud-to-cas/CrudCasBase.js +58 -0
- package/lib/crud-to-cas/CrudCasBase.js.map +1 -0
- package/package.json +1 -1
package/lib/cas/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CrudResourceInfo } from '../crud/types';
|
|
2
|
-
export interface CasApi {
|
|
3
|
-
put(blob: Uint8Array): Promise<
|
|
4
|
-
get(hash:
|
|
5
|
-
del(hash:
|
|
6
|
-
info(hash:
|
|
2
|
+
export interface CasApi<Hash> {
|
|
3
|
+
put(blob: Uint8Array): Promise<Hash>;
|
|
4
|
+
get(hash: Hash, options?: CasGetOptions): Promise<Uint8Array>;
|
|
5
|
+
del(hash: Hash, silent?: boolean): Promise<void>;
|
|
6
|
+
info(hash: Hash): Promise<CrudResourceInfo>;
|
|
7
7
|
}
|
|
8
8
|
export interface CasGetOptions {
|
|
9
9
|
skipVerification?: boolean;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { CrudApi
|
|
1
|
+
import { CrudCasBase } from './CrudCasBase';
|
|
2
|
+
import type { CrudApi } from '../crud/types';
|
|
3
3
|
export interface CrudCasOptions {
|
|
4
4
|
hash: (blob: Uint8Array) => Promise<string>;
|
|
5
5
|
}
|
|
6
|
-
export declare class CrudCas
|
|
6
|
+
export declare class CrudCas extends CrudCasBase<string> {
|
|
7
7
|
protected readonly crud: CrudApi;
|
|
8
8
|
protected readonly options: CrudCasOptions;
|
|
9
9
|
constructor(crud: CrudApi, options: CrudCasOptions);
|
|
10
|
-
readonly put: (blob: Uint8Array) => Promise<string>;
|
|
11
|
-
readonly get: (hash: string, options?: CasGetOptions) => Promise<Uint8Array>;
|
|
12
|
-
readonly del: (hash: string, silent?: boolean) => Promise<void>;
|
|
13
|
-
readonly info: (hash: string) => Promise<CrudResourceInfo>;
|
|
14
10
|
}
|
|
@@ -2,55 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CrudCas = void 0;
|
|
4
4
|
const util_1 = require("./util");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
catch (error) {
|
|
10
|
-
if (error && typeof error === 'object') {
|
|
11
|
-
switch (error.name) {
|
|
12
|
-
case 'ResourceNotFound':
|
|
13
|
-
case 'CollectionNotFound':
|
|
14
|
-
throw new DOMException(error.message, 'BlobNotFound');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
class CrudCas {
|
|
5
|
+
const CrudCasBase_1 = require("./CrudCasBase");
|
|
6
|
+
const hashEqual = (h1, h2) => h1 === h2;
|
|
7
|
+
class CrudCas extends CrudCasBase_1.CrudCasBase {
|
|
21
8
|
constructor(crud, options) {
|
|
9
|
+
super(crud, options.hash, util_1.hashToLocation, hashEqual);
|
|
22
10
|
this.crud = crud;
|
|
23
11
|
this.options = options;
|
|
24
|
-
this.put = async (blob) => {
|
|
25
|
-
const digest = await this.options.hash(blob);
|
|
26
|
-
const [collection, resource] = (0, util_1.hashToLocation)(digest);
|
|
27
|
-
await this.crud.put(collection, resource, blob);
|
|
28
|
-
return digest;
|
|
29
|
-
};
|
|
30
|
-
this.get = async (hash, options) => {
|
|
31
|
-
const [collection, resource] = (0, util_1.hashToLocation)(hash);
|
|
32
|
-
return await normalizeErrors(async () => {
|
|
33
|
-
const blob = await this.crud.get(collection, resource);
|
|
34
|
-
if (!(options === null || options === void 0 ? void 0 : options.skipVerification)) {
|
|
35
|
-
const digest = await this.options.hash(blob);
|
|
36
|
-
if (hash !== digest)
|
|
37
|
-
throw new DOMException('Blob contents does not match hash', 'Integrity');
|
|
38
|
-
}
|
|
39
|
-
return blob;
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
this.del = async (hash, silent) => {
|
|
43
|
-
const [collection, resource] = (0, util_1.hashToLocation)(hash);
|
|
44
|
-
await normalizeErrors(async () => {
|
|
45
|
-
return await this.crud.del(collection, resource, silent);
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
this.info = async (hash) => {
|
|
49
|
-
const [collection, resource] = (0, util_1.hashToLocation)(hash);
|
|
50
|
-
return await normalizeErrors(async () => {
|
|
51
|
-
return await this.crud.info(collection, resource);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
12
|
}
|
|
55
13
|
}
|
|
56
14
|
exports.CrudCas = CrudCas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudCas.js","sourceRoot":"","sources":["../../src/crud-to-cas/CrudCas.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;
|
|
1
|
+
{"version":3,"file":"CrudCas.js","sourceRoot":"","sources":["../../src/crud-to-cas/CrudCas.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AACxC,+CAA4C;AAO5C,MAAM,SAAS,GAAG,CAAC,EAAU,EAAE,EAAU,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAExD,MAAa,OAAQ,SAAQ,yBAAmB;IAC9C,YACqB,IAAa,EACb,OAAuB;QAE1C,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,qBAAc,EAAE,SAAS,CAAC,CAAC;QAHlC,SAAI,GAAJ,IAAI,CAAS;QACb,YAAO,GAAP,OAAO,CAAgB;IAG5C,CAAC;CACF;AAPD,0BAOC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CasApi, CasGetOptions } from '../cas/types';
|
|
2
|
+
import type { CrudApi, CrudResourceInfo } from '../crud/types';
|
|
3
|
+
import type { FsLocation } from '../fsa-to-node/types';
|
|
4
|
+
export declare class CrudCasBase<Hash> implements CasApi<Hash> {
|
|
5
|
+
protected readonly crud: CrudApi;
|
|
6
|
+
protected readonly hash: (blob: Uint8Array) => Promise<Hash>;
|
|
7
|
+
protected readonly hash2Loc: (hash: Hash) => FsLocation;
|
|
8
|
+
protected readonly hashEqual: (h1: Hash, h2: Hash) => boolean;
|
|
9
|
+
constructor(crud: CrudApi, hash: (blob: Uint8Array) => Promise<Hash>, hash2Loc: (hash: Hash) => FsLocation, hashEqual: (h1: Hash, h2: Hash) => boolean);
|
|
10
|
+
readonly put: (blob: Uint8Array) => Promise<Hash>;
|
|
11
|
+
readonly get: (hash: Hash, options?: CasGetOptions) => Promise<Uint8Array>;
|
|
12
|
+
readonly del: (hash: Hash, silent?: boolean) => Promise<void>;
|
|
13
|
+
readonly info: (hash: Hash) => Promise<CrudResourceInfo>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrudCasBase = void 0;
|
|
4
|
+
const normalizeErrors = async (code) => {
|
|
5
|
+
try {
|
|
6
|
+
return await code();
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (error && typeof error === 'object') {
|
|
10
|
+
switch (error.name) {
|
|
11
|
+
case 'ResourceNotFound':
|
|
12
|
+
case 'CollectionNotFound':
|
|
13
|
+
throw new DOMException(error.message, 'BlobNotFound');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
class CrudCasBase {
|
|
20
|
+
constructor(crud, hash, hash2Loc, hashEqual) {
|
|
21
|
+
this.crud = crud;
|
|
22
|
+
this.hash = hash;
|
|
23
|
+
this.hash2Loc = hash2Loc;
|
|
24
|
+
this.hashEqual = hashEqual;
|
|
25
|
+
this.put = async (blob) => {
|
|
26
|
+
const digest = await this.hash(blob);
|
|
27
|
+
const [collection, resource] = this.hash2Loc(digest);
|
|
28
|
+
await this.crud.put(collection, resource, blob);
|
|
29
|
+
return digest;
|
|
30
|
+
};
|
|
31
|
+
this.get = async (hash, options) => {
|
|
32
|
+
const [collection, resource] = this.hash2Loc(hash);
|
|
33
|
+
return await normalizeErrors(async () => {
|
|
34
|
+
const blob = await this.crud.get(collection, resource);
|
|
35
|
+
if (!(options === null || options === void 0 ? void 0 : options.skipVerification)) {
|
|
36
|
+
const digest = await this.hash(blob);
|
|
37
|
+
if (!this.hashEqual(digest, hash))
|
|
38
|
+
throw new DOMException('Blob contents does not match hash', 'Integrity');
|
|
39
|
+
}
|
|
40
|
+
return blob;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
this.del = async (hash, silent) => {
|
|
44
|
+
const [collection, resource] = this.hash2Loc(hash);
|
|
45
|
+
await normalizeErrors(async () => {
|
|
46
|
+
return await this.crud.del(collection, resource, silent);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
this.info = async (hash) => {
|
|
50
|
+
const [collection, resource] = this.hash2Loc(hash);
|
|
51
|
+
return await normalizeErrors(async () => {
|
|
52
|
+
return await this.crud.info(collection, resource);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.CrudCasBase = CrudCasBase;
|
|
58
|
+
//# sourceMappingURL=CrudCasBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CrudCasBase.js","sourceRoot":"","sources":["../../src/crud-to-cas/CrudCasBase.ts"],"names":[],"mappings":";;;AAIA,MAAM,eAAe,GAAG,KAAK,EAAK,IAAsB,EAAc,EAAE;IACtE,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,IAAI,OAAO,KAAK,K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