Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { CrudCasBase } from './CrudCasBase';
import type { CrudApi } from '../crud/types';
export interface CrudCasOptions {
hash: (blob: Uint8Array) => Promise<string>;
}
export declare class CrudCas extends CrudCasBase<string> {
protected readonly crud: CrudApi;
protected readonly options: CrudCasOptions;
constructor(crud: CrudApi, options: CrudCasOptions);
}
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrudCas = void 0;
const util_1 = require("./util");
const CrudCasBase_1 = require("./CrudCasBase");
const hashEqual = (h1, h2) => h1 === h2;
class CrudCas extends CrudCasBase_1.CrudCasBase {
constructor(crud, options) {
super(crud, options.hash, util_1.hashToLocation, hashEqual);
this.crud = crud;
this.options = options;
}
}
exports.CrudCas = CrudCas;
//# sourceMappingURL=CrudCas.js.map
+1
View File
@@ -0,0 +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"}
+14
View File
@@ -0,0 +1,14 @@
import type { CasApi, CasGetOptions } from '../cas/types';
import type { CrudApi, CrudResourceInfo } from '../crud/types';
import type { FsLocation } from '../fsa-to-node/types';
export declare class CrudCasBase<Hash> implements CasApi<Hash> {
protected readonly crud: CrudApi;
protected readonly hash: (blob: Uint8Array) => Promise<Hash>;
protected readonly hash2Loc: (hash: Hash) => FsLocation;
protected readonly hashEqual: (h1: Hash, h2: Hash) => boolean;
constructor(crud: CrudApi, hash: (blob: Uint8Array) => Promise<Hash>, hash2Loc: (hash: Hash) => FsLocation, hashEqual: (h1: Hash, h2: Hash) => boolean);
readonly put: (blob: Uint8Array) => Promise<Hash>;
readonly get: (hash: Hash, options?: CasGetOptions) => Promise<Uint8Array>;
readonly del: (hash: Hash, silent?: boolean) => Promise<void>;
readonly info: (hash: Hash) => Promise<CrudResourceInfo>;
}
+58
View File
@@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrudCasBase = void 0;
const normalizeErrors = async (code) => {
try {
return await code();
}
catch (error) {
if (error && typeof error === 'object') {
switch (error.name) {
case 'ResourceNotFound':
case 'CollectionNotFound':
throw new DOMException(error.message, 'BlobNotFound');
}
}
throw error;
}
};
class CrudCasBase {
constructor(crud, hash, hash2Loc, hashEqual) {
this.crud = crud;
this.hash = hash;
this.hash2Loc = hash2Loc;
this.hashEqual = hashEqual;
this.put = async (blob) => {
const digest = await this.hash(blob);
const [collection, resource] = this.hash2Loc(digest);
await this.crud.put(collection, resource, blob);
return digest;
};
this.get = async (hash, options) => {
const [collection, resource] = this.hash2Loc(hash);
return await normalizeErrors(async () => {
const blob = await this.crud.get(collection, resource);
if (!(options === null || options === void 0 ? void 0 : options.skipVerification)) {
const digest = await this.hash(blob);
if (!this.hashEqual(digest, hash))
throw new DOMException('Blob contents does not match hash', 'Integrity');
}
return blob;
});
};
this.del = async (hash, silent) => {
const [collection, resource] = this.hash2Loc(hash);
await normalizeErrors(async () => {
return await this.crud.del(collection, resource, silent);
});
};
this.info = async (hash) => {
const [collection, resource] = this.hash2Loc(hash);
return await normalizeErrors(async () => {
return await this.crud.info(collection, resource);
});
};
}
}
exports.CrudCasBase = CrudCasBase;
//# sourceMappingURL=CrudCasBase.js.map
+1
View File
@@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kCAwCC"}
+1
View File
@@ -0,0 +1 @@
export { CrudCas, CrudCasOptions } from './CrudCas';
+6
View File
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrudCas = void 0;
var CrudCas_1 = require("./CrudCas");
Object.defineProperty(exports, "CrudCas", { enumerable: true, get: function () { return CrudCas_1.CrudCas; } });
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crud-to-cas/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoD;AAA3C,kGAAA,OAAO,OAAA"}
+2
View File
@@ -0,0 +1,2 @@
import type { FsLocation } from '../fsa-to-node/types';
export declare const hashToLocation: (hash: string) => FsLocation;
+13
View File
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hashToLocation = void 0;
const hashToLocation = (hash) => {
if (hash.length < 20)
throw new TypeError('Hash is too short');
const lastTwo = hash.slice(-2);
const twoBeforeLastTwo = hash.slice(-4, -2);
const folder = [lastTwo, twoBeforeLastTwo];
return [folder, hash];
};
exports.hashToLocation = hashToLocation;
//# sourceMappingURL=util.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/crud-to-cas/util.ts"],"names":[],"mappings":";;;AAEO,MAAM,cAAc,GAAG,CAAC,IAAY,EAAc,EAAE;IACzD,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAC3C,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxB,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB"}