bagit-node 0.0.0-stage → 1.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/NOTICE +6 -0
- package/README.md +246 -2
- package/dist/cjs/bag.d.ts +59 -0
- package/dist/cjs/bag.d.ts.map +1 -0
- package/dist/cjs/bag.js +329 -0
- package/dist/cjs/bag.js.map +1 -0
- package/dist/cjs/errors.d.ts +32 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +60 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +29 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/util.d.ts +39 -0
- package/dist/cjs/util.d.ts.map +1 -0
- package/dist/cjs/util.js +355 -0
- package/dist/cjs/util.js.map +1 -0
- package/dist/cjs/zip.d.ts +49 -0
- package/dist/cjs/zip.d.ts.map +1 -0
- package/dist/cjs/zip.js +371 -0
- package/dist/cjs/zip.js.map +1 -0
- package/dist/esm/bag.d.ts +59 -0
- package/dist/esm/bag.d.ts.map +1 -0
- package/dist/esm/bag.js +322 -0
- package/dist/esm/bag.js.map +1 -0
- package/dist/esm/errors.d.ts +32 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +50 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +29 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util.d.ts +39 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/util.js +326 -0
- package/dist/esm/util.js.map +1 -0
- package/dist/esm/zip.d.ts +49 -0
- package/dist/esm/zip.d.ts.map +1 -0
- package/dist/esm/zip.js +365 -0
- package/dist/esm/zip.js.map +1 -0
- package/package.json +47 -4
package/dist/cjs/bag.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bag = void 0;
|
|
4
|
+
exports.makeBag = makeBag;
|
|
5
|
+
exports.makeManifests = makeManifests;
|
|
6
|
+
exports.makeTagManifests = makeTagManifests;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const errors_js_1 = require("./errors.js");
|
|
11
|
+
const util_js_1 = require("./util.js");
|
|
12
|
+
class Bag {
|
|
13
|
+
path;
|
|
14
|
+
tags = Object.create(null);
|
|
15
|
+
info = Object.create(null);
|
|
16
|
+
entries = Object.create(null);
|
|
17
|
+
algorithms = [];
|
|
18
|
+
versionInfo;
|
|
19
|
+
version;
|
|
20
|
+
encoding;
|
|
21
|
+
tagFileName;
|
|
22
|
+
normalizedFilesystemNames = Object.create(null);
|
|
23
|
+
normalizedManifestNames = Object.create(null);
|
|
24
|
+
/** Reads declaration, metadata and manifests synchronously; file hashing is asynchronous. */
|
|
25
|
+
constructor(path) {
|
|
26
|
+
this.path = (0, node_path_1.resolve)(path);
|
|
27
|
+
const declaration = (0, node_path_1.join)(this.path, 'bagit.txt');
|
|
28
|
+
if (!(0, util_js_1.isFile)(declaration))
|
|
29
|
+
throw new errors_js_1.BagError(`Expected bagit.txt does not exist: ${declaration}`);
|
|
30
|
+
this.tags = (0, util_js_1.parseTagFile)((0, util_js_1.decodeText)((0, node_fs_1.readFileSync)(declaration)), 'bagit.txt');
|
|
31
|
+
const missing = ['BagIt-Version', 'Tag-File-Character-Encoding'].filter(k => !(k in this.tags));
|
|
32
|
+
if (missing.length)
|
|
33
|
+
throw new errors_js_1.BagError(`Missing required tag in bagit.txt: ${missing.join(', ')}`);
|
|
34
|
+
const version = this.tags['BagIt-Version'];
|
|
35
|
+
if (typeof version !== 'string' || !/^\d+\.\d+$/.test(version)) {
|
|
36
|
+
throw new errors_js_1.BagError(`Bag version numbers must be MAJOR.MINOR numbers, not ${String(version)}`);
|
|
37
|
+
}
|
|
38
|
+
this.version = version;
|
|
39
|
+
const [major, minor] = version.split('.').map(Number);
|
|
40
|
+
this.versionInfo = [major, minor];
|
|
41
|
+
if (major === 0 && minor >= 93 && minor <= 95)
|
|
42
|
+
this.tagFileName = 'package-info.txt';
|
|
43
|
+
else if ((major === 0 && minor >= 96) || major === 1)
|
|
44
|
+
this.tagFileName = 'bag-info.txt';
|
|
45
|
+
else
|
|
46
|
+
throw new errors_js_1.BagError(`Unsupported bag version: ${version}`);
|
|
47
|
+
const encoding = this.tags['Tag-File-Character-Encoding'];
|
|
48
|
+
if (typeof encoding !== 'string')
|
|
49
|
+
throw new errors_js_1.BagValidationError('Tag-File-Character-Encoding must occur once');
|
|
50
|
+
this.encoding = encoding;
|
|
51
|
+
(0, util_js_1.checkEncoding)(encoding);
|
|
52
|
+
const infoPath = (0, node_path_1.join)(this.path, this.tagFileName);
|
|
53
|
+
if ((0, util_js_1.isFile)(infoPath))
|
|
54
|
+
this.info = (0, util_js_1.parseTagFile)((0, util_js_1.decodeText)((0, node_fs_1.readFileSync)(infoPath), encoding), this.tagFileName);
|
|
55
|
+
this.loadManifests();
|
|
56
|
+
}
|
|
57
|
+
toString() { return this.path; }
|
|
58
|
+
get algs() { return this.algorithms; }
|
|
59
|
+
get version_info() { return this.versionInfo; }
|
|
60
|
+
get tag_file_name() { return this.tagFileName; }
|
|
61
|
+
get verifiesTagFiles() { return this.versionInfo[0] >= 1 || this.versionInfo[1] >= 97; }
|
|
62
|
+
*manifestFiles() {
|
|
63
|
+
for (const a of util_js_1.CHECKSUM_ALGOS)
|
|
64
|
+
if ((0, util_js_1.isFile)((0, node_path_1.join)(this.path, `manifest-${a}.txt`)))
|
|
65
|
+
yield (0, node_path_1.join)(this.path, `manifest-${a}.txt`);
|
|
66
|
+
}
|
|
67
|
+
*tagmanifestFiles() {
|
|
68
|
+
for (const a of util_js_1.CHECKSUM_ALGOS)
|
|
69
|
+
if ((0, util_js_1.isFile)((0, node_path_1.join)(this.path, `tagmanifest-${a}.txt`)))
|
|
70
|
+
yield (0, node_path_1.join)(this.path, `tagmanifest-${a}.txt`);
|
|
71
|
+
}
|
|
72
|
+
loadManifests() {
|
|
73
|
+
this.entries = Object.create(null);
|
|
74
|
+
this.algorithms = [];
|
|
75
|
+
const manifests = [...this.manifestFiles(), ...(this.verifiesTagFiles ? this.tagmanifestFiles() : [])];
|
|
76
|
+
for (const manifest of manifests) {
|
|
77
|
+
const algorithm = (0, node_path_1.basename)(manifest).replace(/^(?:tag)?manifest-/, '').replace(/\.txt$/, '');
|
|
78
|
+
if (!this.algorithms.includes(algorithm))
|
|
79
|
+
this.algorithms.push(algorithm);
|
|
80
|
+
const text = (0, util_js_1.decodeText)((0, node_fs_1.readFileSync)(manifest), this.encoding);
|
|
81
|
+
for (const raw of text.split(/\r\n|\n|\r/)) {
|
|
82
|
+
const line = raw.trim();
|
|
83
|
+
if (!line || line.startsWith('#'))
|
|
84
|
+
continue;
|
|
85
|
+
const entry = /^(\S+)\s+(.+)$/.exec(line);
|
|
86
|
+
if (!entry)
|
|
87
|
+
continue; // Python logs and skips malformed lines.
|
|
88
|
+
const digest = entry[1];
|
|
89
|
+
const filename = (0, util_js_1.decodeFilename)(node_path_1.posix.normalize(entry[2].replace(/^\*+/, '')));
|
|
90
|
+
(0, util_js_1.assertSafePath)(this.path, filename, `manifest "${manifest}"`);
|
|
91
|
+
const hashes = this.entries[filename] ??= Object.create(null);
|
|
92
|
+
if (Object.hasOwn(hashes, algorithm)) {
|
|
93
|
+
const same = hashes[algorithm] === digest;
|
|
94
|
+
if (!same || this.versionInfo[0] >= 1) {
|
|
95
|
+
throw new errors_js_1.BagError(`${this.path}: ${algorithm} manifest lists ${filename} multiple times with ${same ? 'the same value' : 'conflicting values'}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
hashes[algorithm] = digest;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
this.normalizedManifestNames = (0, util_js_1.buildUnicodeNormalizedLookupDict)(Object.keys(this.entries));
|
|
102
|
+
}
|
|
103
|
+
*payloadFiles() {
|
|
104
|
+
this.normalizedFilesystemNames = Object.create(null);
|
|
105
|
+
for (const filename of (0, util_js_1.walkFiles)((0, node_path_1.join)(this.path, 'data'), 'data/')) {
|
|
106
|
+
this.normalizedFilesystemNames[(0, util_js_1.normalizeUnicode)(filename)] = filename;
|
|
107
|
+
yield filename;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
payloadEntries() { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => p.startsWith('data/'))); }
|
|
111
|
+
tagfileEntries() { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => !p.startsWith('data/'))); }
|
|
112
|
+
*missingOptionalTagfiles() {
|
|
113
|
+
for (const filename of Object.keys(this.tagfileEntries()))
|
|
114
|
+
if (!(0, util_js_1.isFile)((0, node_path_1.join)(this.path, filename)))
|
|
115
|
+
yield filename;
|
|
116
|
+
}
|
|
117
|
+
compareManifestsWithFs() {
|
|
118
|
+
const files = [...this.payloadFiles()];
|
|
119
|
+
this.normalizedFilesystemNames = (0, util_js_1.buildUnicodeNormalizedLookupDict)(files);
|
|
120
|
+
const onFs = new Set(files.map(util_js_1.normalizeUnicode));
|
|
121
|
+
const inManifest = new Set(Object.keys(this.payloadEntries()).map(util_js_1.normalizeUnicode));
|
|
122
|
+
if (this.verifiesTagFiles)
|
|
123
|
+
for (const f of this.missingOptionalTagfiles())
|
|
124
|
+
inManifest.add((0, util_js_1.normalizeUnicode)(f));
|
|
125
|
+
return [
|
|
126
|
+
[...inManifest].filter(p => !onFs.has(p)).map(p => this.normalizedManifestNames[p]),
|
|
127
|
+
[...onFs].filter(p => !inManifest.has(p)).map(p => this.normalizedFilesystemNames[p]),
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
*fetchEntries() {
|
|
131
|
+
const path = (0, node_path_1.join)(this.path, 'fetch.txt');
|
|
132
|
+
if (!(0, util_js_1.isFile)(path))
|
|
133
|
+
return;
|
|
134
|
+
for (const line of (0, util_js_1.decodeText)((0, node_fs_1.readFileSync)(path), this.encoding).split(/\r\n|\n|\r/)) {
|
|
135
|
+
if (!line.trim())
|
|
136
|
+
continue;
|
|
137
|
+
const parts = /^(\S+)\s+(\S+)\s+(.+)$/.exec(line.trim());
|
|
138
|
+
if (!parts)
|
|
139
|
+
throw new errors_js_1.BagError(`Malformed entry in fetch.txt: ${line}`);
|
|
140
|
+
const filename = parts[3];
|
|
141
|
+
(0, util_js_1.assertSafePath)(this.path, filename, `"${path}"`);
|
|
142
|
+
yield [parts[1], parts[2], filename];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
*filesToBeFetched() { for (const [, , filename] of this.fetchEntries())
|
|
146
|
+
yield filename; }
|
|
147
|
+
compareFetchWithFs() {
|
|
148
|
+
const files = new Set(this.payloadFiles());
|
|
149
|
+
return [...new Set(this.filesToBeFetched())].filter(f => !files.has(f));
|
|
150
|
+
}
|
|
151
|
+
validateFetch() {
|
|
152
|
+
for (const [url] of this.fetchEntries()) {
|
|
153
|
+
// Like urllib.urlparse: permit any scheme with an authority, or file: URLs.
|
|
154
|
+
if (!/^file:/i.test(url) && !/^[a-z][a-z\d+.-]*:\/\/[^/\s?#]+/i.test(url))
|
|
155
|
+
throw new errors_js_1.BagError(`Malformed URL in fetch.txt: ${url}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
hasOxum() { return Object.hasOwn(this.info, 'Payload-Oxum'); }
|
|
159
|
+
async validate(options = {}) {
|
|
160
|
+
const concurrency = (0, util_js_1.checkConcurrency)(options.concurrency);
|
|
161
|
+
options.signal?.throwIfAborted();
|
|
162
|
+
if (!(0, util_js_1.isDirectory)((0, node_path_1.join)(this.path, 'data')))
|
|
163
|
+
throw new errors_js_1.BagValidationError(`Expected data directory ${(0, node_path_1.join)(this.path, 'data')} does not exist`);
|
|
164
|
+
if (![...this.manifestFiles()].length)
|
|
165
|
+
throw new errors_js_1.BagValidationError('No manifest files found');
|
|
166
|
+
const declaration = (0, node_path_1.join)(this.path, 'bagit.txt');
|
|
167
|
+
if (!(0, util_js_1.isFile)(declaration))
|
|
168
|
+
throw new errors_js_1.BagValidationError(`Expected ${this.path} to contain "bagit.txt"`);
|
|
169
|
+
if ((0, node_fs_1.readFileSync)(declaration).subarray(0, 3).equals(Buffer.from([0xef, 0xbb, 0xbf])))
|
|
170
|
+
throw new errors_js_1.BagValidationError('bagit.txt must not contain a byte-order mark');
|
|
171
|
+
this.validateFetch();
|
|
172
|
+
if (options.fast && !this.hasOxum())
|
|
173
|
+
throw new errors_js_1.BagValidationError('Fast validation requires bag-info.txt to include Payload-Oxum');
|
|
174
|
+
this.validateOxum();
|
|
175
|
+
if (options.fast)
|
|
176
|
+
return true;
|
|
177
|
+
const [missing, unexpected] = this.compareManifestsWithFs();
|
|
178
|
+
const errors = [...missing.map(p => new errors_js_1.FileMissing(p)), ...unexpected.map(p => new errors_js_1.UnexpectedFile(p))];
|
|
179
|
+
if (errors.length)
|
|
180
|
+
throw new errors_js_1.BagValidationError('Bag is incomplete', errors);
|
|
181
|
+
if (options.completenessOnly || options.completeness_only)
|
|
182
|
+
return true;
|
|
183
|
+
const results = await (0, util_js_1.mapConcurrent)(Object.entries(this.entries), concurrency, async ([filename, expected]) => {
|
|
184
|
+
options.signal?.throwIfAborted();
|
|
185
|
+
const actualName = this.normalizedFilesystemNames[(0, util_js_1.normalizeUnicode)(filename)] ?? filename;
|
|
186
|
+
(0, util_js_1.assertSafePath)(this.path, actualName);
|
|
187
|
+
let hashes;
|
|
188
|
+
try {
|
|
189
|
+
({ hashes } = await (0, util_js_1.hashFile)((0, node_path_1.join)(this.path, actualName), Object.keys(expected), options.signal));
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (!(error instanceof errors_js_1.BagValidationError))
|
|
193
|
+
throw error;
|
|
194
|
+
hashes = Object.fromEntries(Object.keys(expected).map(a => [a, error.message]));
|
|
195
|
+
}
|
|
196
|
+
return Object.entries(expected).filter(([a, h]) => h.toLowerCase() !== hashes[a]).map(([a, h]) => new errors_js_1.ChecksumMismatch(filename, a, h.toLowerCase(), hashes[a]));
|
|
197
|
+
});
|
|
198
|
+
errors.push(...results.flat());
|
|
199
|
+
if (errors.length)
|
|
200
|
+
throw new errors_js_1.BagValidationError('Bag validation failed', errors);
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
validateOxum() {
|
|
204
|
+
let oxum = this.info['Payload-Oxum'];
|
|
205
|
+
if (oxum === undefined)
|
|
206
|
+
return;
|
|
207
|
+
if (Array.isArray(oxum))
|
|
208
|
+
oxum = oxum[0];
|
|
209
|
+
if (!/^\d+\.\d+$/.test(oxum))
|
|
210
|
+
throw new errors_js_1.BagError(`Malformed Payload-Oxum value: ${oxum}`);
|
|
211
|
+
const [expectedBytes, expectedFiles] = oxum.split('.').map(BigInt);
|
|
212
|
+
const files = [...this.payloadFiles()];
|
|
213
|
+
let bytes = 0n;
|
|
214
|
+
for (const f of files) {
|
|
215
|
+
(0, util_js_1.assertSafePath)(this.path, f);
|
|
216
|
+
bytes += (0, node_fs_1.statSync)((0, node_path_1.join)(this.path, f), { bigint: true }).size;
|
|
217
|
+
}
|
|
218
|
+
if (bytes !== expectedBytes || BigInt(files.length) !== expectedFiles) {
|
|
219
|
+
throw new errors_js_1.BagValidationError(`Payload-Oxum validation failed. Expected ${expectedFiles} files and ${expectedBytes} bytes but found ${files.length} files and ${bytes} bytes`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async isValid(options = {}) {
|
|
223
|
+
try {
|
|
224
|
+
await this.validate(options);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (error instanceof errors_js_1.BagError)
|
|
229
|
+
return false;
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async save(options = {}) {
|
|
234
|
+
(0, util_js_1.checkConcurrency)(options.concurrency);
|
|
235
|
+
options.signal?.throwIfAborted();
|
|
236
|
+
(0, util_js_1.checkPermissions)(this.path, true);
|
|
237
|
+
if (options.manifests) {
|
|
238
|
+
const { bytes, files } = await makeManifests(this.path, { checksums: this.algorithms, concurrency: options.concurrency, signal: options.signal }, this.encoding);
|
|
239
|
+
this.info['Payload-Oxum'] = `${bytes}.${files}`;
|
|
240
|
+
}
|
|
241
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(this.path, this.tagFileName), (0, util_js_1.encodeText)((0, util_js_1.serializeTagFile)(this.info), this.encoding));
|
|
242
|
+
await makeTagManifests(this.path, this.algorithms, this.encoding, options.signal);
|
|
243
|
+
this.loadManifests();
|
|
244
|
+
}
|
|
245
|
+
// Python-style method aliases ease migration while the primary API uses Node naming conventions.
|
|
246
|
+
manifest_files = this.manifestFiles;
|
|
247
|
+
tagmanifest_files = this.tagmanifestFiles;
|
|
248
|
+
payload_files = this.payloadFiles;
|
|
249
|
+
payload_entries = this.payloadEntries;
|
|
250
|
+
tagfile_entries = this.tagfileEntries;
|
|
251
|
+
missing_optional_tagfiles = this.missingOptionalTagfiles;
|
|
252
|
+
compare_manifests_with_fs = this.compareManifestsWithFs;
|
|
253
|
+
compare_fetch_with_fs = this.compareFetchWithFs;
|
|
254
|
+
fetch_entries = this.fetchEntries;
|
|
255
|
+
files_to_be_fetched = this.filesToBeFetched;
|
|
256
|
+
validate_fetch = this.validateFetch;
|
|
257
|
+
has_oxum = this.hasOxum;
|
|
258
|
+
is_valid = this.isValid;
|
|
259
|
+
}
|
|
260
|
+
exports.Bag = Bag;
|
|
261
|
+
/** Convert a directory in place. Existing contents, including an existing data/, become payload. */
|
|
262
|
+
async function makeBag(directory, options = {}) {
|
|
263
|
+
const root = (0, node_path_1.resolve)(directory);
|
|
264
|
+
const algorithms = (0, util_js_1.algorithmsFor)(options.checksums);
|
|
265
|
+
(0, util_js_1.checkConcurrency)(options.concurrency);
|
|
266
|
+
if (options.encoding && options.encoding.toLowerCase() !== 'utf-8')
|
|
267
|
+
throw new errors_js_1.BagError('New bags must use UTF-8');
|
|
268
|
+
options.signal?.throwIfAborted();
|
|
269
|
+
if (!(0, util_js_1.isDirectory)(root))
|
|
270
|
+
throw new errors_js_1.BagError(`Bag directory ${root} does not exist`);
|
|
271
|
+
const cwdRelative = (0, node_path_1.relative)(root, process.cwd());
|
|
272
|
+
if (cwdRelative && !cwdRelative.startsWith(`..${node_path_1.sep}`) && cwdRelative !== '..' && !(0, node_path_1.isAbsolute)(cwdRelative)) {
|
|
273
|
+
throw new errors_js_1.BagError('Bagging a parent of the current directory is not supported');
|
|
274
|
+
}
|
|
275
|
+
(0, util_js_1.checkPermissions)(root);
|
|
276
|
+
const sourceFiles = [...(0, util_js_1.walkFiles)(root)];
|
|
277
|
+
(0, util_js_1.buildUnicodeNormalizedLookupDict)(sourceFiles);
|
|
278
|
+
for (const f of sourceFiles)
|
|
279
|
+
(0, util_js_1.assertSafePath)(root, f, 'source directory');
|
|
280
|
+
const originalMode = (await (0, promises_1.stat)(root)).mode;
|
|
281
|
+
const children = await (0, promises_1.readdir)(root);
|
|
282
|
+
const staging = await (0, promises_1.mkdtemp)((0, node_path_1.join)(root, '.bagit-'));
|
|
283
|
+
const moved = [];
|
|
284
|
+
try {
|
|
285
|
+
for (const name of children) {
|
|
286
|
+
await (0, promises_1.rename)((0, node_path_1.join)(root, name), (0, node_path_1.join)(staging, name));
|
|
287
|
+
moved.push(name);
|
|
288
|
+
}
|
|
289
|
+
await (0, promises_1.rename)(staging, (0, node_path_1.join)(root, 'data'));
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
for (const name of moved.reverse())
|
|
293
|
+
await (0, promises_1.rename)((0, node_path_1.join)(staging, name), (0, node_path_1.join)(root, name));
|
|
294
|
+
await (0, promises_1.rm)(staging, { recursive: true, force: true });
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
await (0, promises_1.chmod)((0, node_path_1.join)(root, 'data'), originalMode);
|
|
298
|
+
const { bytes, files } = await makeManifests(root, { ...options, checksums: algorithms });
|
|
299
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'bagit.txt'), util_js_1.BAG_DECLARATION);
|
|
300
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'bag-info.txt'), (0, util_js_1.serializeTagFile)((0, util_js_1.makeBagInfo)(options.bagInfo, bytes, files)));
|
|
301
|
+
await makeTagManifests(root, algorithms, 'utf-8', options.signal);
|
|
302
|
+
return new Bag(root);
|
|
303
|
+
}
|
|
304
|
+
async function makeManifests(root, options = {}, encoding = 'utf-8') {
|
|
305
|
+
const algorithms = (0, util_js_1.algorithmsFor)(options.checksums);
|
|
306
|
+
const filenames = [...(0, util_js_1.walkFiles)((0, node_path_1.join)(root, 'data'), 'data/')];
|
|
307
|
+
(0, util_js_1.buildUnicodeNormalizedLookupDict)(filenames);
|
|
308
|
+
const records = await (0, util_js_1.mapConcurrent)(filenames, options.concurrency ?? 1, async (filename) => {
|
|
309
|
+
(0, util_js_1.assertSafePath)(root, filename);
|
|
310
|
+
return { filename, ...await (0, util_js_1.hashFile)((0, node_path_1.join)(root, filename), algorithms, options.signal) };
|
|
311
|
+
});
|
|
312
|
+
for (const a of algorithms) {
|
|
313
|
+
const text = records.map(r => `${r.hashes[a]} ${(0, util_js_1.encodeFilename)(r.filename)}\n`).join('');
|
|
314
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, `manifest-${a}.txt`), (0, util_js_1.encodeText)(text, encoding));
|
|
315
|
+
}
|
|
316
|
+
return { bytes: records.reduce((sum, r) => sum + r.bytes, 0n), files: records.length };
|
|
317
|
+
}
|
|
318
|
+
async function makeTagManifests(root, algorithms = util_js_1.DEFAULT_CHECKSUMS, encoding = 'utf-8', signal) {
|
|
319
|
+
const tagFiles = [...(0, util_js_1.walkFiles)(root)].filter(f => !f.startsWith('data/') && !(0, node_path_1.basename)(f).startsWith('tagmanifest-'));
|
|
320
|
+
const records = [];
|
|
321
|
+
for (const filename of tagFiles) {
|
|
322
|
+
(0, util_js_1.assertSafePath)(root, filename);
|
|
323
|
+
records.push({ filename, ...await (0, util_js_1.hashFile)((0, node_path_1.join)(root, filename), algorithms, signal) });
|
|
324
|
+
}
|
|
325
|
+
for (const a of (0, util_js_1.algorithmsFor)(algorithms)) {
|
|
326
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, `tagmanifest-${a}.txt`), (0, util_js_1.encodeText)(records.map(r => `${r.hashes[a]} ${(0, util_js_1.encodeFilename)(r.filename)}\n`).join(''), encoding));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=bag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bag.js","sourceRoot":"","sources":["../../src/bag.ts"],"names":[],"mappings":";;;AA8NA,0BAiCC;AAED,sCAaC;AAED,4CAUC;AA1RD,qCAAiD;AACjD,+CAAwF;AACxF,yCAAsF;AACtF,2CAAoI;AAEpI,uCAKmB;AAEnB,MAAa,GAAG;IACL,IAAI,CAAS;IACtB,IAAI,GAAY,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,GAAY,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,GAAY,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvC,UAAU,GAAa,EAAE,CAAC;IAC1B,WAAW,CAA6B;IACxC,OAAO,CAAU;IACjB,QAAQ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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAA,oBAAQ,EAAC,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC;IACrH,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;QAChC,IAAA,wBAAc,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,kBAAQ,EAAC,IAAA,gBAAI,EAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,IAAA,uBAAa,EAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAA,oBAAS,EAAC,IAAA,gBAAI,EAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,IAAA,oBAAU,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAA,wBAAc,EAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;IACzJ,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync, statSync } from 'node:fs';\nimport { chmod, mkdtemp, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';\nimport { basename, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';\nimport { BagError, BagValidationError, ChecksumMismatch, FileMissing, UnexpectedFile, type ManifestErrorDetail } from './errors.js';\nimport type { BagInfo, Checksums, Entries, FetchEntry, MakeBagOptions, SaveOptions, ValidationOptions } from './types.js';\nimport {\n algorithmsFor, assertSafePath, BAG_DECLARATION, buildUnicodeNormalizedLookupDict, checkConcurrency,\n checkEncoding, checkPermissions, CHECKSUM_ALGOS, decodeFilename, decodeText, DEFAULT_CHECKSUMS,\n encodeFilename, encodeText, hashFile, isDirectory, isFile, makeBagInfo, mapConcurrent, normalizeUnicode,\n parseTagFile, serializeTagFile, walkFiles,\n} from './util.js';\n\nexport class Bag {\n readonly path: string;\n tags: BagInfo = Object.create(null);\n info: BagInfo = Object.create(null);\n entries: Entries = Object.create(null);\n algorithms: string[] = [];\n versionInfo!: readonly [number, number];\n version!: string;\n encoding!: string;\n tagFileName!: string;\n normalizedFilesystemNames: Record<string, string> = Object.create(null);\n normalizedManifestNames: Record<string, string> = Object.create(null);\n\n /** Reads declaration, metadata and manifests synchronously; file hashing is asynchronous. */\n constructor(path: string) {\n this.path = resolve(path);\n const declaration = join(this.path, 'bagit.txt');\n if (!isFile(declaration)) throw new BagError(`Expected bagit.txt does not exist: ${declaration}`);\n this.tags = parseTagFile(decodeText(readFileSync(declaration)), 'bagit.txt');\n const missing = ['BagIt-Version', 'Tag-File-Character-Encoding'].filter(k => !(k in this.tags));\n if (missing.length) throw new BagError(`Missing required tag in bagit.txt: ${missing.join(', ')}`);\n const version = this.tags['BagIt-Version'];\n if (typeof version !== 'string' || !/^\\d+\\.\\d+$/.test(version)) {\n throw new BagError(`Bag version numbers must be MAJOR.MINOR numbers, not ${String(version)}`);\n }\n this.version = version;\n const [major, minor] = version.split('.').map(Number) as [number, number];\n this.versionInfo = [major, minor];\n if (major === 0 && minor >= 93 && minor <= 95) this.tagFileName = 'package-info.txt';\n else if ((major === 0 && minor >= 96) || major === 1) this.tagFileName = 'bag-info.txt';\n else throw new BagError(`Unsupported bag version: ${version}`);\n const encoding = this.tags['Tag-File-Character-Encoding'];\n if (typeof encoding !== 'string') throw new BagValidationError('Tag-File-Character-Encoding must occur once');\n this.encoding = encoding;\n checkEncoding(encoding);\n const infoPath = join(this.path, this.tagFileName);\n if (isFile(infoPath)) this.info = parseTagFile(decodeText(readFileSync(infoPath), encoding), this.tagFileName);\n this.loadManifests();\n }\n\n toString(): string { return this.path; }\n get algs(): string[] { return this.algorithms; }\n get version_info(): readonly [number, number] { return this.versionInfo; }\n get tag_file_name(): string { return this.tagFileName; }\n private get verifiesTagFiles(): boolean { return this.versionInfo[0] >= 1 || this.versionInfo[1] >= 97; }\n\n *manifestFiles(): Generator<string> {\n for (const a of CHECKSUM_ALGOS) if (isFile(join(this.path, `manifest-${a}.txt`))) yield join(this.path, `manifest-${a}.txt`);\n }\n *tagmanifestFiles(): Generator<string> {\n for (const a of CHECKSUM_ALGOS) if (isFile(join(this.path, `tagmanifest-${a}.txt`))) yield join(this.path, `tagmanifest-${a}.txt`);\n }\n private loadManifests(): void {\n this.entries = Object.create(null);\n this.algorithms = [];\n const manifests = [...this.manifestFiles(), ...(this.verifiesTagFiles ? this.tagmanifestFiles() : [])];\n for (const manifest of manifests) {\n const algorithm = basename(manifest).replace(/^(?:tag)?manifest-/, '').replace(/\\.txt$/, '');\n if (!this.algorithms.includes(algorithm)) this.algorithms.push(algorithm);\n const text = decodeText(readFileSync(manifest), this.encoding);\n for (const raw of text.split(/\\r\\n|\\n|\\r/)) {\n const line = raw.trim();\n if (!line || line.startsWith('#')) continue;\n const entry = /^(\\S+)\\s+(.+)$/.exec(line);\n if (!entry) continue; // Python logs and skips malformed lines.\n const digest = entry[1]!;\n const filename = decodeFilename(posix.normalize(entry[2]!.replace(/^\\*+/, '')));\n assertSafePath(this.path, filename, `manifest \"${manifest}\"`);\n const hashes = this.entries[filename] ??= Object.create(null) as Checksums;\n if (Object.hasOwn(hashes, algorithm)) {\n const same = hashes[algorithm] === digest;\n if (!same || this.versionInfo[0] >= 1) {\n throw new BagError(`${this.path}: ${algorithm} manifest lists ${filename} multiple times with ${same ? 'the same value' : 'conflicting values'}`);\n }\n }\n hashes[algorithm] = digest;\n }\n }\n this.normalizedManifestNames = buildUnicodeNormalizedLookupDict(Object.keys(this.entries));\n }\n *payloadFiles(): Generator<string> {\n this.normalizedFilesystemNames = Object.create(null);\n for (const filename of walkFiles(join(this.path, 'data'), 'data/')) {\n this.normalizedFilesystemNames[normalizeUnicode(filename)] = filename;\n yield filename;\n }\n }\n payloadEntries(): Entries { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => p.startsWith('data/'))); }\n tagfileEntries(): Entries { return Object.fromEntries(Object.entries(this.entries).filter(([p]) => !p.startsWith('data/'))); }\n *missingOptionalTagfiles(): Generator<string> {\n for (const filename of Object.keys(this.tagfileEntries())) if (!isFile(join(this.path, filename))) yield filename;\n }\n compareManifestsWithFs(): [string[], string[]] {\n const files = [...this.payloadFiles()];\n this.normalizedFilesystemNames = buildUnicodeNormalizedLookupDict(files);\n const onFs = new Set(files.map(normalizeUnicode));\n const inManifest = new Set(Object.keys(this.payloadEntries()).map(normalizeUnicode));\n if (this.verifiesTagFiles) for (const f of this.missingOptionalTagfiles()) inManifest.add(normalizeUnicode(f));\n return [\n [...inManifest].filter(p => !onFs.has(p)).map(p => this.normalizedManifestNames[p]!),\n [...onFs].filter(p => !inManifest.has(p)).map(p => this.normalizedFilesystemNames[p]!),\n ];\n }\n *fetchEntries(): Generator<FetchEntry> {\n const path = join(this.path, 'fetch.txt');\n if (!isFile(path)) return;\n for (const line of decodeText(readFileSync(path), this.encoding).split(/\\r\\n|\\n|\\r/)) {\n if (!line.trim()) continue;\n const parts = /^(\\S+)\\s+(\\S+)\\s+(.+)$/.exec(line.trim());\n if (!parts) throw new BagError(`Malformed entry in fetch.txt: ${line}`);\n const filename = parts[3]!;\n assertSafePath(this.path, filename, `\"${path}\"`);\n yield [parts[1]!, parts[2]!, filename];\n }\n }\n *filesToBeFetched(): Generator<string> { for (const [, , filename] of this.fetchEntries()) yield filename; }\n compareFetchWithFs(): string[] {\n const files = new Set(this.payloadFiles());\n return [...new Set(this.filesToBeFetched())].filter(f => !files.has(f));\n }\n validateFetch(): void {\n for (const [url] of this.fetchEntries()) {\n // Like urllib.urlparse: permit any scheme with an authority, or file: URLs.\n if (!/^file:/i.test(url) && !/^[a-z][a-z\\d+.-]*:\\/\\/[^/\\s?#]+/i.test(url)) throw new BagError(`Malformed URL in fetch.txt: ${url}`);\n }\n }\n hasOxum(): boolean { return Object.hasOwn(this.info, 'Payload-Oxum'); }\n\n async validate(options: ValidationOptions = {}): Promise<true> {\n const concurrency = checkConcurrency(options.concurrency);\n options.signal?.throwIfAborted();\n if (!isDirectory(join(this.path, 'data'))) throw new BagValidationError(`Expected data directory ${join(this.path, 'data')} does not exist`);\n if (![...this.manifestFiles()].length) throw new BagValidationError('No manifest files found');\n const declaration = join(this.path, 'bagit.txt');\n if (!isFile(declaration)) throw new BagValidationError(`Expected ${this.path} to contain \"bagit.txt\"`);\n if (readFileSync(declaration).subarray(0, 3).equals(Buffer.from([0xef, 0xbb, 0xbf]))) throw new BagValidationError('bagit.txt must not contain a byte-order mark');\n this.validateFetch();\n if (options.fast && !this.hasOxum()) throw new BagValidationError('Fast validation requires bag-info.txt to include Payload-Oxum');\n this.validateOxum();\n if (options.fast) return true;\n const [missing, unexpected] = this.compareManifestsWithFs();\n const errors: ManifestErrorDetail[] = [...missing.map(p => new FileMissing(p)), ...unexpected.map(p => new UnexpectedFile(p))];\n if (errors.length) throw new BagValidationError('Bag is incomplete', errors);\n if (options.completenessOnly || options.completeness_only) return true;\n const results = await mapConcurrent(Object.entries(this.entries), concurrency, async ([filename, expected]) => {\n options.signal?.throwIfAborted();\n const actualName = this.normalizedFilesystemNames[normalizeUnicode(filename)] ?? filename;\n assertSafePath(this.path, actualName);\n let hashes: Checksums;\n try { ({ hashes } = await hashFile(join(this.path, actualName), Object.keys(expected), options.signal)); }\n catch (error) {\n if (!(error instanceof BagValidationError)) throw error;\n hashes = Object.fromEntries(Object.keys(expected).map(a => [a, error.message]));\n }\n return Object.entries(expected).filter(([a, h]) => h.toLowerCase() !== hashes[a]).map(([a, h]) => new ChecksumMismatch(filename, a, h.toLowerCase(), hashes[a]!));\n });\n errors.push(...results.flat());\n if (errors.length) throw new BagValidationError('Bag validation failed', errors);\n return true;\n }\n private validateOxum(): void {\n let oxum = this.info['Payload-Oxum'];\n if (oxum === undefined) return;\n if (Array.isArray(oxum)) oxum = oxum[0]!;\n if (!/^\\d+\\.\\d+$/.test(oxum)) throw new BagError(`Malformed Payload-Oxum value: ${oxum}`);\n const [expectedBytes, expectedFiles] = oxum.split('.').map(BigInt);\n const files = [...this.payloadFiles()];\n let bytes = 0n;\n for (const f of files) {\n assertSafePath(this.path, f);\n bytes += statSync(join(this.path, f), { bigint: true }).size;\n }\n if (bytes !== expectedBytes || BigInt(files.length) !== expectedFiles) {\n throw new BagValidationError(`Payload-Oxum validation failed. Expected ${expectedFiles} files and ${expectedBytes} bytes but found ${files.length} files and ${bytes} bytes`);\n }\n }\n async isValid(options: ValidationOptions = {}): Promise<boolean> {\n try { await this.validate(options); return true; }\n catch (error) { if (error instanceof BagError) return false; throw error; }\n }\n async save(options: SaveOptions = {}): Promise<void> {\n checkConcurrency(options.concurrency);\n options.signal?.throwIfAborted();\n checkPermissions(this.path, true);\n if (options.manifests) {\n const { bytes, files } = await makeManifests(this.path, { checksums: this.algorithms, concurrency: options.concurrency, signal: options.signal }, this.encoding);\n this.info['Payload-Oxum'] = `${bytes}.${files}`;\n }\n await writeFile(join(this.path, this.tagFileName), encodeText(serializeTagFile(this.info), this.encoding));\n await makeTagManifests(this.path, this.algorithms, this.encoding, options.signal);\n this.loadManifests();\n }\n\n // Python-style method aliases ease migration while the primary API uses Node naming conventions.\n manifest_files = this.manifestFiles;\n tagmanifest_files = this.tagmanifestFiles;\n payload_files = this.payloadFiles;\n payload_entries = this.payloadEntries;\n tagfile_entries = this.tagfileEntries;\n missing_optional_tagfiles = this.missingOptionalTagfiles;\n compare_manifests_with_fs = this.compareManifestsWithFs;\n compare_fetch_with_fs = this.compareFetchWithFs;\n fetch_entries = this.fetchEntries;\n files_to_be_fetched = this.filesToBeFetched;\n validate_fetch = this.validateFetch;\n has_oxum = this.hasOxum;\n is_valid = this.isValid;\n}\n\n/** Convert a directory in place. Existing contents, including an existing data/, become payload. */\nexport async function makeBag(directory: string, options: MakeBagOptions = {}): Promise<Bag> {\n const root = resolve(directory);\n const algorithms = algorithmsFor(options.checksums);\n checkConcurrency(options.concurrency);\n if (options.encoding && options.encoding.toLowerCase() !== 'utf-8') throw new BagError('New bags must use UTF-8');\n options.signal?.throwIfAborted();\n if (!isDirectory(root)) throw new BagError(`Bag directory ${root} does not exist`);\n const cwdRelative = relative(root, process.cwd());\n if (cwdRelative && !cwdRelative.startsWith(`..${sep}`) && cwdRelative !== '..' && !isAbsolute(cwdRelative)) {\n throw new BagError('Bagging a parent of the current directory is not supported');\n }\n checkPermissions(root);\n const sourceFiles = [...walkFiles(root)];\n buildUnicodeNormalizedLookupDict(sourceFiles);\n for (const f of sourceFiles) assertSafePath(root, f, 'source directory');\n const originalMode = (await stat(root)).mode;\n const children = await readdir(root);\n const staging = await mkdtemp(join(root, '.bagit-'));\n const moved: string[] = [];\n try {\n for (const name of children) { await rename(join(root, name), join(staging, name)); moved.push(name); }\n await rename(staging, join(root, 'data'));\n } catch (error) {\n for (const name of moved.reverse()) await rename(join(staging, name), join(root, name));\n await rm(staging, { recursive: true, force: true });\n throw error;\n }\n await chmod(join(root, 'data'), originalMode);\n const { bytes, files } = await makeManifests(root, { ...options, checksums: algorithms });\n await writeFile(join(root, 'bagit.txt'), BAG_DECLARATION);\n await writeFile(join(root, 'bag-info.txt'), serializeTagFile(makeBagInfo(options.bagInfo, bytes, files)));\n await makeTagManifests(root, algorithms, 'utf-8', options.signal);\n return new Bag(root);\n}\n\nexport async function makeManifests(root: string, options: Pick<MakeBagOptions, 'checksums' | 'concurrency' | 'signal'> = {}, encoding = 'utf-8'): Promise<{ bytes: bigint; files: number }> {\n const algorithms = algorithmsFor(options.checksums);\n const filenames = [...walkFiles(join(root, 'data'), 'data/')];\n buildUnicodeNormalizedLookupDict(filenames);\n const records = await mapConcurrent(filenames, options.concurrency ?? 1, async filename => {\n assertSafePath(root, filename);\n return { filename, ...await hashFile(join(root, filename), algorithms, options.signal) };\n });\n for (const a of algorithms) {\n const text = records.map(r => `${r.hashes[a]} ${encodeFilename(r.filename)}\\n`).join('');\n await writeFile(join(root, `manifest-${a}.txt`), encodeText(text, encoding));\n }\n return { bytes: records.reduce((sum, r) => sum + r.bytes, 0n), files: records.length };\n}\n\nexport async function makeTagManifests(root: string, algorithms: readonly string[] = DEFAULT_CHECKSUMS, encoding = 'utf-8', signal?: AbortSignal): Promise<void> {\n const tagFiles = [...walkFiles(root)].filter(f => !f.startsWith('data/') && !basename(f).startsWith('tagmanifest-'));\n const records = [];\n for (const filename of tagFiles) {\n assertSafePath(root, filename);\n records.push({ filename, ...await hashFile(join(root, filename), algorithms, signal) });\n }\n for (const a of algorithmsFor(algorithms)) {\n await writeFile(join(root, `tagmanifest-${a}.txt`), encodeText(records.map(r => `${r.hashes[a]} ${encodeFilename(r.filename)}\\n`).join(''), encoding));\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class BagError extends Error {
|
|
2
|
+
constructor(message: string, options?: ErrorOptions);
|
|
3
|
+
toString(): string;
|
|
4
|
+
}
|
|
5
|
+
export declare class ManifestErrorDetail extends BagError {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
constructor(path: string, message?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class ChecksumMismatch extends ManifestErrorDetail {
|
|
10
|
+
readonly algorithm: string;
|
|
11
|
+
readonly expected: string;
|
|
12
|
+
readonly found: string;
|
|
13
|
+
constructor(path: string, algorithm: string, expected: string, found: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class FileMissing extends ManifestErrorDetail {
|
|
16
|
+
constructor(path: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class UnexpectedFile extends ManifestErrorDetail {
|
|
19
|
+
constructor(path: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class BagValidationError extends BagError {
|
|
22
|
+
readonly details: ManifestErrorDetail[];
|
|
23
|
+
constructor(message: string, details?: ManifestErrorDetail[], options?: ErrorOptions);
|
|
24
|
+
}
|
|
25
|
+
export declare class FileNormalizationConflict extends BagError {
|
|
26
|
+
readonly fileA: string;
|
|
27
|
+
readonly fileB: string;
|
|
28
|
+
constructor(fileA: string, fileB: string);
|
|
29
|
+
get file_a(): string;
|
|
30
|
+
get file_b(): string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAI1C,QAAQ,IAAI,MAAM;CAC5B;AAED,qBAAa,mBAAoB,SAAQ,QAAQ;aACnB,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EAAE,OAAO,SAAO;CACzD;AAED,qBAAa,gBAAiB,SAAQ,mBAAmB;aACb,SAAS,EAAE,MAAM;aAAkB,QAAQ,EAAE,MAAM;aAAkB,KAAK,EAAE,MAAM;gBAAhH,IAAI,EAAE,MAAM,EAAkB,SAAS,EAAE,MAAM,EAAkB,QAAQ,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM;CAG7H;AAED,qBAAa,WAAY,SAAQ,mBAAmB;gBACtC,IAAI,EAAE,MAAM;CACzB;AAED,qBAAa,cAAe,SAAQ,mBAAmB;gBACzC,IAAI,EAAE,MAAM;CACzB;AAED,qBAAa,kBAAmB,SAAQ,QAAQ;aACD,OAAO,EAAE,mBAAmB,EAAE;gBAA/D,OAAO,EAAE,MAAM,EAAkB,OAAO,GAAE,mBAAmB,EAAO,EAAE,OAAO,CAAC,EAAE,YAAY;CAGzG;AAED,qBAAa,yBAA0B,SAAQ,QAAQ;aACzB,KAAK,EAAE,MAAM;aAAkB,KAAK,EAAE,MAAM;gBAA5C,KAAK,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM;IAGxE,IAAI,MAAM,IAAI,MAAM,CAAuB;IAC3C,IAAI,MAAM,IAAI,MAAM,CAAuB;CAC5C"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileNormalizationConflict = exports.BagValidationError = exports.UnexpectedFile = exports.FileMissing = exports.ChecksumMismatch = exports.ManifestErrorDetail = exports.BagError = void 0;
|
|
4
|
+
class BagError extends Error {
|
|
5
|
+
constructor(message, options) {
|
|
6
|
+
super(message, options);
|
|
7
|
+
this.name = new.target.name;
|
|
8
|
+
}
|
|
9
|
+
toString() { return this.message; }
|
|
10
|
+
}
|
|
11
|
+
exports.BagError = BagError;
|
|
12
|
+
class ManifestErrorDetail extends BagError {
|
|
13
|
+
path;
|
|
14
|
+
constructor(path, message = path) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.path = path;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ManifestErrorDetail = ManifestErrorDetail;
|
|
20
|
+
class ChecksumMismatch extends ManifestErrorDetail {
|
|
21
|
+
algorithm;
|
|
22
|
+
expected;
|
|
23
|
+
found;
|
|
24
|
+
constructor(path, algorithm, expected, found) {
|
|
25
|
+
super(path, `${path} ${algorithm} validation failed: expected="${expected}" found="${found}"`);
|
|
26
|
+
this.algorithm = algorithm;
|
|
27
|
+
this.expected = expected;
|
|
28
|
+
this.found = found;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.ChecksumMismatch = ChecksumMismatch;
|
|
32
|
+
class FileMissing extends ManifestErrorDetail {
|
|
33
|
+
constructor(path) { super(path, `${path} exists in manifest but was not found on filesystem`); }
|
|
34
|
+
}
|
|
35
|
+
exports.FileMissing = FileMissing;
|
|
36
|
+
class UnexpectedFile extends ManifestErrorDetail {
|
|
37
|
+
constructor(path) { super(path, `${path} exists on filesystem but is not in the manifest`); }
|
|
38
|
+
}
|
|
39
|
+
exports.UnexpectedFile = UnexpectedFile;
|
|
40
|
+
class BagValidationError extends BagError {
|
|
41
|
+
details;
|
|
42
|
+
constructor(message, details = [], options) {
|
|
43
|
+
super(details.length ? `${message}: ${details.join('; ')}` : message, options);
|
|
44
|
+
this.details = details;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.BagValidationError = BagValidationError;
|
|
48
|
+
class FileNormalizationConflict extends BagError {
|
|
49
|
+
fileA;
|
|
50
|
+
fileB;
|
|
51
|
+
constructor(fileA, fileB) {
|
|
52
|
+
super(`Unicode normalization conflict for file "${fileA}" and "${fileB}"`);
|
|
53
|
+
this.fileA = fileA;
|
|
54
|
+
this.fileB = fileB;
|
|
55
|
+
}
|
|
56
|
+
get file_a() { return this.fileA; }
|
|
57
|
+
get file_b() { return this.fileB; }
|
|
58
|
+
}
|
|
59
|
+
exports.FileNormalizationConflict = FileNormalizationConflict;
|
|
60
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;IACQ,QAAQ,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;CACrD;AAND,4BAMC;AAED,MAAa,mBAAoB,SAAQ,QAAQ;IACnB;IAA5B,YAA4B,IAAY,EAAE,OAAO,GAAG,IAAI;QAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAA/C,SAAI,GAAJ,IAAI,CAAQ;IAAoC,CAAC;CAC9E;AAFD,kDAEC;AAED,MAAa,gBAAiB,SAAQ,mBAAmB;IACb;IAAmC;IAAkC;IAA/G,YA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,CAAC;CAC5C;AAND,8DAMC","sourcesContent":["export class BagError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n }\n override toString(): string { return this.message; }\n}\n\nexport class ManifestErrorDetail extends BagError {\n constructor(public readonly path: string, message = path) { super(message); }\n}\n\nexport class ChecksumMismatch extends ManifestErrorDetail {\n constructor(path: string, public readonly algorithm: string, public readonly expected: string, public readonly found: string) {\n super(path, `${path} ${algorithm} validation failed: expected=\"${expected}\" found=\"${found}\"`);\n }\n}\n\nexport class FileMissing extends ManifestErrorDetail {\n constructor(path: string) { super(path, `${path} exists in manifest but was not found on filesystem`); }\n}\n\nexport class UnexpectedFile extends ManifestErrorDetail {\n constructor(path: string) { super(path, `${path} exists on filesystem but is not in the manifest`); }\n}\n\nexport class BagValidationError extends BagError {\n constructor(message: string, public readonly details: ManifestErrorDetail[] = [], options?: ErrorOptions) {\n super(details.length ? `${message}: ${details.join('; ')}` : message, options);\n }\n}\n\nexport class FileNormalizationConflict extends BagError {\n constructor(public readonly fileA: string, public readonly fileB: string) {\n super(`Unicode normalization conflict for file \"${fileA}\" and \"${fileB}\"`);\n }\n get file_a(): string { return this.fileA; }\n get file_b(): string { return this.fileB; }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Bag, makeBag, makeManifests, makeTagManifests, makeBag as make_bag } from './bag.js';
|
|
2
|
+
export { BagError, BagValidationError, ManifestErrorDetail, ChecksumMismatch, FileMissing, UnexpectedFile, FileNormalizationConflict } from './errors.js';
|
|
3
|
+
export { createBagZipStream, createBagZipStreamFromEntries, folderToBagZip, folderToBagitZip, type BagZipOptions, type BagZipEntry, type BagZipProgress, type BagZipResult, } from './zip.js';
|
|
4
|
+
export { VERSION, DEFAULT_CHECKSUMS, CHECKSUM_ALGOS, HASH_BLOCK_SIZE, BAG_DECLARATION, STANDARD_BAG_INFO_HEADERS, normalizeUnicode, buildUnicodeNormalizedLookupDict, encodeFilename, decodeFilename, parseTagFile, serializeTagFile, loadTagFile, getHashers, generateManifestLines, } from './util.js';
|
|
5
|
+
export type { BagInfo, BagInfoInput, TagValue, Checksums, Entries, FetchEntry, MakeBagOptions, ValidationOptions, SaveOptions } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC1J,OAAO,EACL,kBAAkB,EAAE,6BAA6B,EAAE,cAAc,EAAE,gBAAgB,EACnF,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,GAC7E,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,yBAAyB,EACvG,gBAAgB,EAAE,gCAAgC,EAAE,cAAc,EAAE,cAAc,EAClF,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,GAC/E,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateManifestLines = exports.getHashers = exports.loadTagFile = exports.serializeTagFile = exports.parseTagFile = exports.decodeFilename = exports.encodeFilename = exports.buildUnicodeNormalizedLookupDict = exports.normalizeUnicode = exports.STANDARD_BAG_INFO_HEADERS = exports.BAG_DECLARATION = exports.HASH_BLOCK_SIZE = exports.CHECKSUM_ALGOS = exports.DEFAULT_CHECKSUMS = exports.VERSION = exports.folderToBagitZip = exports.folderToBagZip = exports.createBagZipStreamFromEntries = exports.createBagZipStream = exports.FileNormalizationConflict = exports.UnexpectedFile = exports.FileMissing = exports.ChecksumMismatch = exports.ManifestErrorDetail = exports.BagValidationError = exports.BagError = exports.make_bag = exports.makeTagManifests = exports.makeManifests = exports.makeBag = exports.Bag = void 0;
|
|
4
|
+
var bag_js_1 = require("./bag.js");
|
|
5
|
+
Object.defineProperty(exports, "Bag", { enumerable: true, get: function () { return bag_js_1.Bag; } });
|
|
6
|
+
Object.defineProperty(exports, "makeBag", { enumerable: true, get: function () { return bag_js_1.makeBag; } });
|
|
7
|
+
Object.defineProperty(exports, "makeManifests", { enumerable: true, get: function () { return bag_js_1.makeManifests; } });
|
|
8
|
+
Object.defineProperty(exports, "makeTagManifests", { enumerable: true, get: function () { return bag_js_1.makeTagManifests; } });
|
|
9
|
+
Object.defineProperty(exports, "make_bag", { enumerable: true, get: function () { return bag_js_1.makeBag; } });
|
|
10
|
+
var errors_js_1 = require("./errors.js");
|
|
11
|
+
Object.defineProperty(exports, "BagError", { enumerable: true, get: function () { return errors_js_1.BagError; } });
|
|
12
|
+
Object.defineProperty(exports, "BagValidationError", { enumerable: true, get: function () { return errors_js_1.BagValidationError; } });
|
|
13
|
+
Object.defineProperty(exports, "ManifestErrorDetail", { enumerable: true, get: function () { return errors_js_1.ManifestErrorDetail; } });
|
|
14
|
+
Object.defineProperty(exports, "ChecksumMismatch", { enumerable: true, get: function () { return errors_js_1.ChecksumMismatch; } });
|
|
15
|
+
Object.defineProperty(exports, "FileMissing", { enumerable: true, get: function () { return errors_js_1.FileMissing; } });
|
|
16
|
+
Object.defineProperty(exports, "UnexpectedFile", { enumerable: true, get: function () { return errors_js_1.UnexpectedFile; } });
|
|
17
|
+
Object.defineProperty(exports, "FileNormalizationConflict", { enumerable: true, get: function () { return errors_js_1.FileNormalizationConflict; } });
|
|
18
|
+
var zip_js_1 = require("./zip.js");
|
|
19
|
+
Object.defineProperty(exports, "createBagZipStream", { enumerable: true, get: function () { return zip_js_1.createBagZipStream; } });
|
|
20
|
+
Object.defineProperty(exports, "createBagZipStreamFromEntries", { enumerable: true, get: function () { return zip_js_1.createBagZipStreamFromEntries; } });
|
|
21
|
+
Object.defineProperty(exports, "folderToBagZip", { enumerable: true, get: function () { return zip_js_1.folderToBagZip; } });
|
|
22
|
+
Object.defineProperty(exports, "folderToBagitZip", { enumerable: true, get: function () { return zip_js_1.folderToBagitZip; } });
|
|
23
|
+
var util_js_1 = require("./util.js");
|
|
24
|
+
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return util_js_1.VERSION; } });
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_CHECKSUMS", { enumerable: true, get: function () { return util_js_1.DEFAULT_CHECKSUMS; } });
|
|
26
|
+
Object.defineProperty(exports, "CHECKSUM_ALGOS", { enumerable: true, get: function () { return util_js_1.CHECKSUM_ALGOS; } });
|
|
27
|
+
Object.defineProperty(exports, "HASH_BLOCK_SIZE", { enumerable: true, get: function () { return util_js_1.HASH_BLOCK_SIZE; } });
|
|
28
|
+
Object.defineProperty(exports, "BAG_DECLARATION", { enumerable: true, get: function () { return util_js_1.BAG_DECLARATION; } });
|
|
29
|
+
Object.defineProperty(exports, "STANDARD_BAG_INFO_HEADERS", { enumerable: true, get: function () { return util_js_1.STANDARD_BAG_INFO_HEADERS; } });
|
|
30
|
+
Object.defineProperty(exports, "normalizeUnicode", { enumerable: true, get: function () { return util_js_1.normalizeUnicode; } });
|
|
31
|
+
Object.defineProperty(exports, "buildUnicodeNormalizedLookupDict", { enumerable: true, get: function () { return util_js_1.buildUnicodeNormalizedLookupDict; } });
|
|
32
|
+
Object.defineProperty(exports, "encodeFilename", { enumerable: true, get: function () { return util_js_1.encodeFilename; } });
|
|
33
|
+
Object.defineProperty(exports, "decodeFilename", { enumerable: true, get: function () { return util_js_1.decodeFilename; } });
|
|
34
|
+
Object.defineProperty(exports, "parseTagFile", { enumerable: true, get: function () { return util_js_1.parseTagFile; } });
|
|
35
|
+
Object.defineProperty(exports, "serializeTagFile", { enumerable: true, get: function () { return util_js_1.serializeTagFile; } });
|
|
36
|
+
Object.defineProperty(exports, "loadTagFile", { enumerable: true, get: function () { return util_js_1.loadTagFile; } });
|
|
37
|
+
Object.defineProperty(exports, "getHashers", { enumerable: true, get: function () { return util_js_1.getHashers; } });
|
|
38
|
+
Object.defineProperty(exports, "generateManifestLines", { enumerable: true, get: function () { return util_js_1.generateManifestLines; } });
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA8F;AAArF,6FAAA,GAAG,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,uGAAA,aAAa,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAAE,kGAAA,OAAO,OAAY;AAC3E,yCAA0J;AAAjJ,qGAAA,QAAQ,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,2GAAA,cAAc,OAAA;AAAE,sHAAA,yBAAyB,OAAA;AACpI,mCAGkB;AAFhB,4GAAA,kBAAkB,OAAA;AAAE,uHAAA,6BAA6B,OAAA;AAAE,wGAAA,cAAc,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAGrF,qCAImB;AAHjB,kGAAA,OAAO,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,0GAAA,eAAe,OAAA;AAAE,0GAAA,eAAe,OAAA;AAAE,oHAAA,yBAAyB,OAAA;AACvG,2GAAA,gBAAgB,OAAA;AAAE,2HAAA,gCAAgC,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,yGAAA,cAAc,OAAA;AAClF,uGAAA,YAAY,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,qGAAA,UAAU,OAAA;AAAE,gHAAA,qBAAqB,OAAA","sourcesContent":["export { Bag, makeBag, makeManifests, makeTagManifests, makeBag as make_bag } from './bag.js';\nexport { BagError, BagValidationError, ManifestErrorDetail, ChecksumMismatch, FileMissing, UnexpectedFile, FileNormalizationConflict } from './errors.js';\nexport {\n createBagZipStream, createBagZipStreamFromEntries, folderToBagZip, folderToBagitZip,\n type BagZipOptions, type BagZipEntry, type BagZipProgress, type BagZipResult,\n} from './zip.js';\nexport {\n VERSION, DEFAULT_CHECKSUMS, CHECKSUM_ALGOS, HASH_BLOCK_SIZE, BAG_DECLARATION, STANDARD_BAG_INFO_HEADERS,\n normalizeUnicode, buildUnicodeNormalizedLookupDict, encodeFilename, decodeFilename,\n parseTagFile, serializeTagFile, loadTagFile, getHashers, generateManifestLines,\n} from './util.js';\nexport type { BagInfo, BagInfoInput, TagValue, Checksums, Entries, FetchEntry, MakeBagOptions, ValidationOptions, SaveOptions } from './types.js';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type TagValue = string | string[];
|
|
2
|
+
export type BagInfo = Record<string, TagValue>;
|
|
3
|
+
export type BagInfoInput = Record<string, string | number | boolean | readonly (string | number | boolean)[]>;
|
|
4
|
+
export type Checksums = Record<string, string>;
|
|
5
|
+
export type Entries = Record<string, Checksums>;
|
|
6
|
+
export interface MakeBagOptions {
|
|
7
|
+
bagInfo?: BagInfoInput;
|
|
8
|
+
checksums?: readonly string[];
|
|
9
|
+
/** Tag files written by this library use UTF-8. */
|
|
10
|
+
encoding?: 'utf-8' | 'UTF-8';
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
/** Maximum simultaneous file reads. */
|
|
13
|
+
concurrency?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ValidationOptions {
|
|
16
|
+
fast?: boolean;
|
|
17
|
+
completenessOnly?: boolean;
|
|
18
|
+
/** Alias for Python callers. */
|
|
19
|
+
completeness_only?: boolean;
|
|
20
|
+
concurrency?: number;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export interface SaveOptions {
|
|
24
|
+
manifests?: boolean;
|
|
25
|
+
concurrency?: number;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}
|
|
28
|
+
export type FetchEntry = [url: string, size: string, filename: string];
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AACzC,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC/C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAC9G,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gCAAgC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type TagValue = string | string[];\nexport type BagInfo = Record<string, TagValue>;\nexport type BagInfoInput = Record<string, string | number | boolean | readonly (string | number | boolean)[]>;\nexport type Checksums = Record<string, string>;\nexport type Entries = Record<string, Checksums>;\n\nexport interface MakeBagOptions {\n bagInfo?: BagInfoInput;\n checksums?: readonly string[];\n /** Tag files written by this library use UTF-8. */\n encoding?: 'utf-8' | 'UTF-8';\n signal?: AbortSignal;\n /** Maximum simultaneous file reads. */\n concurrency?: number;\n}\n\nexport interface ValidationOptions {\n fast?: boolean;\n completenessOnly?: boolean;\n /** Alias for Python callers. */\n completeness_only?: boolean;\n concurrency?: number;\n signal?: AbortSignal;\n}\n\nexport interface SaveOptions {\n manifests?: boolean;\n concurrency?: number;\n signal?: AbortSignal;\n}\n\nexport type FetchEntry = [url: string, size: string, filename: string];\n"]}
|