@uapkg/registry-tools 1.3.0 → 1.3.1
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/dist/aggregator/RegistryToolsAggregator.d.ts +31 -28
- package/dist/aggregator/RegistryToolsAggregator.d.ts.map +1 -1
- package/dist/aggregator/RegistryToolsAggregator.js +71 -73
- package/dist/aggregator/RegistryToolsAggregator.js.map +1 -1
- package/dist/contracts/RegistryToolsTypes.d.ts +101 -98
- package/dist/contracts/RegistryToolsTypes.d.ts.map +1 -1
- package/dist/contracts/RegistryToolsTypes.js +5 -4
- package/dist/contracts/RegistryToolsTypes.js.map +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.js +18 -30
- package/dist/io/IntegrityCalculator.d.ts +16 -13
- package/dist/io/IntegrityCalculator.d.ts.map +1 -1
- package/dist/io/IntegrityCalculator.js +96 -92
- package/dist/io/IntegrityCalculator.js.map +1 -1
- package/dist/io/ManifestStore.d.ts +31 -28
- package/dist/io/ManifestStore.d.ts.map +1 -1
- package/dist/io/ManifestStore.js +127 -124
- package/dist/io/ManifestStore.js.map +1 -1
- package/dist/listing/PackageLister.d.ts +18 -15
- package/dist/listing/PackageLister.d.ts.map +1 -1
- package/dist/listing/PackageLister.js +75 -77
- package/dist/listing/PackageLister.js.map +1 -1
- package/dist/mutation/AddPackageVersionPlanner.d.ts +18 -15
- package/dist/mutation/AddPackageVersionPlanner.d.ts.map +1 -1
- package/dist/mutation/AddPackageVersionPlanner.js +110 -117
- package/dist/mutation/AddPackageVersionPlanner.js.map +1 -1
- package/dist/mutation/RemovePackagePlanner.d.ts +15 -12
- package/dist/mutation/RemovePackagePlanner.d.ts.map +1 -1
- package/dist/mutation/RemovePackagePlanner.js +45 -37
- package/dist/mutation/RemovePackagePlanner.js.map +1 -1
- package/dist/mutation/RemovePackageVersionPlanner.d.ts +15 -12
- package/dist/mutation/RemovePackageVersionPlanner.d.ts.map +1 -1
- package/dist/mutation/RemovePackageVersionPlanner.js +60 -52
- package/dist/mutation/RemovePackageVersionPlanner.js.map +1 -1
- package/dist/mutation/VersionSorter.d.ts +4 -1
- package/dist/mutation/VersionSorter.d.ts.map +1 -1
- package/dist/mutation/VersionSorter.js +24 -24
- package/dist/mutation/VersionSorter.js.map +1 -1
- package/dist/paths/RegistryRepoPaths.d.ts +15 -12
- package/dist/paths/RegistryRepoPaths.d.ts.map +1 -1
- package/dist/paths/RegistryRepoPaths.js +38 -33
- package/dist/paths/RegistryRepoPaths.js.map +1 -1
- package/dist/tools/RegistryTools.d.ts +53 -50
- package/dist/tools/RegistryTools.d.ts.map +1 -1
- package/dist/tools/RegistryTools.js +205 -220
- package/dist/tools/RegistryTools.js.map +1 -1
- package/dist/validation/DependencyReachabilityValidator.d.ts +15 -12
- package/dist/validation/DependencyReachabilityValidator.d.ts.map +1 -1
- package/dist/validation/DependencyReachabilityValidator.js +62 -55
- package/dist/validation/DependencyReachabilityValidator.js.map +1 -1
- package/dist/validation/ExternalRegistryPolicyValidator.d.ts +13 -10
- package/dist/validation/ExternalRegistryPolicyValidator.d.ts.map +1 -1
- package/dist/validation/ExternalRegistryPolicyValidator.js +63 -63
- package/dist/validation/ExternalRegistryPolicyValidator.js.map +1 -1
- package/dist/validation/ManifestValidator.d.ts +11 -8
- package/dist/validation/ManifestValidator.d.ts.map +1 -1
- package/dist/validation/ManifestValidator.js +29 -24
- package/dist/validation/ManifestValidator.js.map +1 -1
- package/dist/validation/OfficialRegistryPolicyValidator.d.ts +18 -15
- package/dist/validation/OfficialRegistryPolicyValidator.d.ts.map +1 -1
- package/dist/validation/OfficialRegistryPolicyValidator.js +80 -89
- package/dist/validation/OfficialRegistryPolicyValidator.js.map +1 -1
- package/dist/validation/RegistryValidator.d.ts +25 -22
- package/dist/validation/RegistryValidator.d.ts.map +1 -1
- package/dist/validation/RegistryValidator.js +89 -87
- package/dist/validation/RegistryValidator.js.map +1 -1
- package/dist/validation/ReleaseFileNameValidator.d.ts +12 -9
- package/dist/validation/ReleaseFileNameValidator.d.ts.map +1 -1
- package/dist/validation/ReleaseFileNameValidator.js +36 -29
- package/dist/validation/ReleaseFileNameValidator.js.map +1 -1
- package/package.json +19 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { RegistryToolsAggregator } from "../aggregator/RegistryToolsAggregator.js";
|
|
2
|
+
import { IntegrityAlgorithm, IntegrityVerificationResult } from "../contracts/RegistryToolsTypes.js";
|
|
3
|
+
import { Result } from "@uapkg/diagnostics";
|
|
4
|
+
import { Integrity } from "@uapkg/registry-schema";
|
|
5
|
+
//#region src/io/IntegrityCalculator.d.ts
|
|
5
6
|
/**
|
|
6
7
|
* Computes and verifies file integrity locally — never reaches the network.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
declare class IntegrityCalculator {
|
|
10
|
+
private readonly aggregator;
|
|
11
|
+
constructor(aggregator: RegistryToolsAggregator);
|
|
12
|
+
/** Stream-hash a local file and return a validated `Integrity` record. */
|
|
13
|
+
compute(filePath: string, algorithm?: IntegrityAlgorithm): Promise<Result<Integrity>>;
|
|
14
|
+
/** Recompute a file's integrity and compare it to an expected value. */
|
|
15
|
+
verify(filePath: string, expected: Integrity): Promise<Result<IntegrityVerificationResult>>;
|
|
16
|
+
/** Hash a file by streaming. */
|
|
17
|
+
private streamHash;
|
|
17
18
|
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { IntegrityCalculator };
|
|
18
21
|
//# sourceMappingURL=IntegrityCalculator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntegrityCalculator.d.ts","
|
|
1
|
+
{"version":3,"file":"IntegrityCalculator.d.ts","names":[],"sources":["../../src/io/IntegrityCalculator.ts"],"mappings":";;;;;;;;cAiBa;mBACkB;EAA7B,YAA6B,YAAY;;EAGnC,QAAQ,kBAAkB,YAAW,qBAAgC,QAAQ,OAAO;;EA6BpF,OAAO,kBAAkB,UAAU,YAAY,QAAQ,OAAO;;UAkC5D"}
|
|
@@ -1,96 +1,100 @@
|
|
|
1
|
-
import { createHash } from
|
|
2
|
-
import { createReadStream } from
|
|
3
|
-
import { createIoErrorDiagnostic, createRegistryToolsIntegrityMismatchDiagnostic,
|
|
4
|
-
import { IntegritySchema } from
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { DiagnosticBag, createIoErrorDiagnostic, createRegistryToolsIntegrityMismatchDiagnostic, ok } from "@uapkg/diagnostics";
|
|
4
|
+
import { IntegritySchema } from "@uapkg/registry-schema";
|
|
5
|
+
|
|
6
|
+
//#region src/io/IntegrityCalculator.ts
|
|
5
7
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
8
|
+
* Computes and verifies file integrity locally — never reaches the network.
|
|
9
|
+
*/
|
|
10
|
+
var IntegrityCalculator = class {
|
|
11
|
+
aggregator;
|
|
12
|
+
constructor(aggregator) {
|
|
13
|
+
this.aggregator = aggregator;
|
|
14
|
+
}
|
|
15
|
+
/** Stream-hash a local file and return a validated `Integrity` record. */
|
|
16
|
+
async compute(filePath, algorithm = "sha256") {
|
|
17
|
+
const bag = new DiagnosticBag();
|
|
18
|
+
const computed = await this.streamHash(filePath, algorithm);
|
|
19
|
+
if (!computed.ok) {
|
|
20
|
+
bag.mergeArray(computed.diagnostics);
|
|
21
|
+
this.aggregator.addMany(computed.diagnostics);
|
|
22
|
+
return bag.toFailure();
|
|
23
|
+
}
|
|
24
|
+
const candidate = {
|
|
25
|
+
hash: `${algorithm}:${computed.value.hex}`,
|
|
26
|
+
size: computed.value.size
|
|
27
|
+
};
|
|
28
|
+
const validated = IntegritySchema.safeParse(candidate);
|
|
29
|
+
if (!validated.success) {
|
|
30
|
+
const reason = validated.error.issues.map((i) => i.message).join("; ");
|
|
31
|
+
const diag = createIoErrorDiagnostic(filePath, `integrity validation failed: ${reason}`);
|
|
32
|
+
bag.add(diag);
|
|
33
|
+
this.aggregator.add(diag);
|
|
34
|
+
return bag.toFailure();
|
|
35
|
+
}
|
|
36
|
+
return ok(validated.data, bag.all());
|
|
37
|
+
}
|
|
38
|
+
/** Recompute a file's integrity and compare it to an expected value. */
|
|
39
|
+
async verify(filePath, expected) {
|
|
40
|
+
const bag = new DiagnosticBag();
|
|
41
|
+
const algo = parseAlgorithm(expected.hash) ?? "sha256";
|
|
42
|
+
const computed = await this.compute(filePath, algo);
|
|
43
|
+
if (!computed.ok) {
|
|
44
|
+
bag.mergeArray(computed.diagnostics);
|
|
45
|
+
return bag.toFailure();
|
|
46
|
+
}
|
|
47
|
+
const matches = computed.value.hash === expected.hash && computed.value.size === expected.size;
|
|
48
|
+
if (!matches) {
|
|
49
|
+
const diag = createRegistryToolsIntegrityMismatchDiagnostic(filePath, expected.hash, computed.value.hash, expected.size, computed.value.size);
|
|
50
|
+
bag.add(diag);
|
|
51
|
+
this.aggregator.add(diag);
|
|
52
|
+
}
|
|
53
|
+
return ok({
|
|
54
|
+
ok: matches,
|
|
55
|
+
actual: computed.value,
|
|
56
|
+
expected
|
|
57
|
+
}, bag.all());
|
|
58
|
+
}
|
|
59
|
+
/** Hash a file by streaming. */
|
|
60
|
+
streamHash(filePath, algorithm) {
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
const bag = new DiagnosticBag();
|
|
63
|
+
const hash = createHash(algorithm);
|
|
64
|
+
let size = 0;
|
|
65
|
+
const stream = createReadStream(filePath);
|
|
66
|
+
stream.on("data", (chunk) => {
|
|
67
|
+
if (Buffer.isBuffer(chunk)) {
|
|
68
|
+
hash.update(chunk);
|
|
69
|
+
size += chunk.length;
|
|
70
|
+
} else {
|
|
71
|
+
const buf = Buffer.from(chunk);
|
|
72
|
+
hash.update(buf);
|
|
73
|
+
size += buf.length;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
stream.on("error", (err) => {
|
|
77
|
+
const diag = createIoErrorDiagnostic(filePath, err.message);
|
|
78
|
+
bag.add(diag);
|
|
79
|
+
resolve(bag.toFailure());
|
|
80
|
+
});
|
|
81
|
+
stream.on("end", () => {
|
|
82
|
+
resolve(ok({
|
|
83
|
+
hex: hash.digest("hex"),
|
|
84
|
+
size
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
87
90
|
function parseAlgorithm(assetHash) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return algo;
|
|
94
|
-
return null;
|
|
91
|
+
const colon = assetHash.indexOf(":");
|
|
92
|
+
if (colon < 0) return null;
|
|
93
|
+
const algo = assetHash.slice(0, colon);
|
|
94
|
+
if (algo === "sha256" || algo === "sha512") return algo;
|
|
95
|
+
return null;
|
|
95
96
|
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { IntegrityCalculator };
|
|
96
100
|
//# sourceMappingURL=IntegrityCalculator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntegrityCalculator.js","
|
|
1
|
+
{"version":3,"file":"IntegrityCalculator.js","names":[],"sources":["../../src/io/IntegrityCalculator.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { createReadStream } from 'node:fs';\nimport type { AssetHash } from '@uapkg/common-schema';\nimport {\n createIoErrorDiagnostic,\n createRegistryToolsIntegrityMismatchDiagnostic,\n DiagnosticBag,\n ok,\n type Result,\n} from '@uapkg/diagnostics';\nimport { type Integrity, IntegritySchema } from '@uapkg/registry-schema';\nimport type { RegistryToolsAggregator } from '../aggregator/RegistryToolsAggregator.js';\nimport type { IntegrityAlgorithm, IntegrityVerificationResult } from '../contracts/RegistryToolsTypes.js';\n\n/**\n * Computes and verifies file integrity locally — never reaches the network.\n */\nexport class IntegrityCalculator {\n constructor(private readonly aggregator: RegistryToolsAggregator) {}\n\n /** Stream-hash a local file and return a validated `Integrity` record. */\n async compute(filePath: string, algorithm: IntegrityAlgorithm = 'sha256'): Promise<Result<Integrity>> {\n const bag = new DiagnosticBag();\n\n const computed = await this.streamHash(filePath, algorithm);\n if (!computed.ok) {\n bag.mergeArray(computed.diagnostics);\n this.aggregator.addMany(computed.diagnostics);\n return bag.toFailure();\n }\n\n const candidate = {\n hash: `${algorithm}:${computed.value.hex}` as AssetHash,\n size: computed.value.size,\n };\n\n const validated = IntegritySchema.safeParse(candidate);\n if (!validated.success) {\n // Should not happen unless the algorithm output is malformed.\n const reason = validated.error.issues.map((i) => i.message).join('; ');\n const diag = createIoErrorDiagnostic(filePath, `integrity validation failed: ${reason}`);\n bag.add(diag);\n this.aggregator.add(diag);\n return bag.toFailure();\n }\n\n return ok(validated.data, bag.all());\n }\n\n /** Recompute a file's integrity and compare it to an expected value. */\n async verify(filePath: string, expected: Integrity): Promise<Result<IntegrityVerificationResult>> {\n const bag = new DiagnosticBag();\n const algo = parseAlgorithm(expected.hash) ?? 'sha256';\n\n const computed = await this.compute(filePath, algo);\n if (!computed.ok) {\n bag.mergeArray(computed.diagnostics);\n return bag.toFailure();\n }\n\n const matches = computed.value.hash === expected.hash && computed.value.size === expected.size;\n if (!matches) {\n const diag = createRegistryToolsIntegrityMismatchDiagnostic(\n filePath,\n expected.hash,\n computed.value.hash,\n expected.size,\n computed.value.size,\n );\n bag.add(diag);\n this.aggregator.add(diag);\n }\n\n return ok(\n {\n ok: matches,\n actual: computed.value,\n expected,\n },\n bag.all(),\n );\n }\n\n /** Hash a file by streaming. */\n private streamHash(filePath: string, algorithm: IntegrityAlgorithm): Promise<Result<{ hex: string; size: number }>> {\n return new Promise((resolve) => {\n const bag = new DiagnosticBag();\n const hash = createHash(algorithm);\n let size = 0;\n const stream = createReadStream(filePath);\n\n stream.on('data', (chunk) => {\n if (Buffer.isBuffer(chunk)) {\n hash.update(chunk);\n size += chunk.length;\n } else {\n const buf = Buffer.from(chunk);\n hash.update(buf);\n size += buf.length;\n }\n });\n stream.on('error', (err) => {\n const diag = createIoErrorDiagnostic(filePath, err.message);\n bag.add(diag);\n resolve(bag.toFailure());\n });\n stream.on('end', () => {\n resolve(ok({ hex: hash.digest('hex'), size }));\n });\n });\n }\n}\n\nfunction parseAlgorithm(assetHash: string): IntegrityAlgorithm | null {\n const colon = assetHash.indexOf(':');\n if (colon < 0) return null;\n const algo = assetHash.slice(0, colon);\n if (algo === 'sha256' || algo === 'sha512') return algo;\n return null;\n}\n"],"mappings":";;;;;;;;;AAiBA,IAAa,sBAAb,MAAiC;CACF;CAA7B,YAAY,AAAiB,YAAqC;EAArC;CAAsC;;CAGnE,MAAM,QAAQ,UAAkB,YAAgC,UAAsC;EACpG,MAAM,MAAM,IAAI,cAAc;EAE9B,MAAM,WAAW,MAAM,KAAK,WAAW,UAAU,SAAS;EAC1D,IAAI,CAAC,SAAS,IAAI;GAChB,IAAI,WAAW,SAAS,WAAW;GACnC,KAAK,WAAW,QAAQ,SAAS,WAAW;GAC5C,OAAO,IAAI,UAAU;EACvB;EAEA,MAAM,YAAY;GAChB,MAAM,GAAG,UAAU,GAAG,SAAS,MAAM;GACrC,MAAM,SAAS,MAAM;EACvB;EAEA,MAAM,YAAY,gBAAgB,UAAU,SAAS;EACrD,IAAI,CAAC,UAAU,SAAS;GAEtB,MAAM,SAAS,UAAU,MAAM,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI;GACrE,MAAM,OAAO,wBAAwB,UAAU,gCAAgC,QAAQ;GACvF,IAAI,IAAI,IAAI;GACZ,KAAK,WAAW,IAAI,IAAI;GACxB,OAAO,IAAI,UAAU;EACvB;EAEA,OAAO,GAAG,UAAU,MAAM,IAAI,IAAI,CAAC;CACrC;;CAGA,MAAM,OAAO,UAAkB,UAAmE;EAChG,MAAM,MAAM,IAAI,cAAc;EAC9B,MAAM,OAAO,eAAe,SAAS,IAAI,KAAK;EAE9C,MAAM,WAAW,MAAM,KAAK,QAAQ,UAAU,IAAI;EAClD,IAAI,CAAC,SAAS,IAAI;GAChB,IAAI,WAAW,SAAS,WAAW;GACnC,OAAO,IAAI,UAAU;EACvB;EAEA,MAAM,UAAU,SAAS,MAAM,SAAS,SAAS,QAAQ,SAAS,MAAM,SAAS,SAAS;EAC1F,IAAI,CAAC,SAAS;GACZ,MAAM,OAAO,+CACX,UACA,SAAS,MACT,SAAS,MAAM,MACf,SAAS,MACT,SAAS,MAAM,IACjB;GACA,IAAI,IAAI,IAAI;GACZ,KAAK,WAAW,IAAI,IAAI;EAC1B;EAEA,OAAO,GACL;GACE,IAAI;GACJ,QAAQ,SAAS;GACjB;EACF,GACA,IAAI,IAAI,CACV;CACF;;CAGA,AAAQ,WAAW,UAAkB,WAA+E;EAClH,OAAO,IAAI,SAAS,YAAY;GAC9B,MAAM,MAAM,IAAI,cAAc;GAC9B,MAAM,OAAO,WAAW,SAAS;GACjC,IAAI,OAAO;GACX,MAAM,SAAS,iBAAiB,QAAQ;GAExC,OAAO,GAAG,SAAS,UAAU;IAC3B,IAAI,OAAO,SAAS,KAAK,GAAG;KAC1B,KAAK,OAAO,KAAK;KACjB,QAAQ,MAAM;IAChB,OAAO;KACL,MAAM,MAAM,OAAO,KAAK,KAAK;KAC7B,KAAK,OAAO,GAAG;KACf,QAAQ,IAAI;IACd;GACF,CAAC;GACD,OAAO,GAAG,UAAU,QAAQ;IAC1B,MAAM,OAAO,wBAAwB,UAAU,IAAI,OAAO;IAC1D,IAAI,IAAI,IAAI;IACZ,QAAQ,IAAI,UAAU,CAAC;GACzB,CAAC;GACD,OAAO,GAAG,aAAa;IACrB,QAAQ,GAAG;KAAE,KAAK,KAAK,OAAO,KAAK;KAAG;IAAK,CAAC,CAAC;GAC/C,CAAC;EACH,CAAC;CACH;AACF;AAEA,SAAS,eAAe,WAA8C;CACpE,MAAM,QAAQ,UAAU,QAAQ,GAAG;CACnC,IAAI,QAAQ,GAAG,OAAO;CACtB,MAAM,OAAO,UAAU,MAAM,GAAG,KAAK;CACrC,IAAI,SAAS,YAAY,SAAS,UAAU,OAAO;CACnD,OAAO;AACT"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { RegistryToolsAggregator } from "../aggregator/RegistryToolsAggregator.js";
|
|
2
|
+
import { WriteManifestResult } from "../contracts/RegistryToolsTypes.js";
|
|
3
|
+
import { RegistryRepoPaths } from "../paths/RegistryRepoPaths.js";
|
|
4
|
+
import { Result } from "@uapkg/diagnostics";
|
|
5
|
+
import { PackageRegistryManifest } from "@uapkg/registry-schema";
|
|
6
|
+
import { PackageName } from "@uapkg/common-schema";
|
|
7
|
+
//#region src/io/ManifestStore.d.ts
|
|
7
8
|
/**
|
|
8
9
|
* Reads, validates, and writes registry-package manifests on disk.
|
|
9
10
|
*
|
|
@@ -13,27 +14,29 @@ import type { RegistryRepoPaths } from '../paths/RegistryRepoPaths.js';
|
|
|
13
14
|
* - Validate against `PackageRegistryManifestSchema`.
|
|
14
15
|
* - Write deterministic, sorted, pretty-printed JSON.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
declare class ManifestStore {
|
|
18
|
+
private readonly paths;
|
|
19
|
+
private readonly aggregator;
|
|
20
|
+
constructor(paths: RegistryRepoPaths, aggregator: RegistryToolsAggregator);
|
|
21
|
+
/** Resolve the manifest path for a package. Pure path computation. */
|
|
22
|
+
resolveManifestPath(packageName: PackageName): string;
|
|
23
|
+
/** True if the manifest file exists on disk. */
|
|
24
|
+
exists(packageName: PackageName): boolean;
|
|
25
|
+
/** Read and validate a package manifest. Emits a missing-package diagnostic when absent. */
|
|
26
|
+
read(packageName: PackageName): Promise<Result<PackageRegistryManifest>>;
|
|
27
|
+
/** Read and validate a manifest file at an arbitrary path. */
|
|
28
|
+
readFromPath(filePath: string): Promise<Result<PackageRegistryManifest>>;
|
|
29
|
+
/**
|
|
30
|
+
* Write a package manifest deterministically.
|
|
31
|
+
*
|
|
32
|
+
* Versions are pre-sorted newest-first by SemVer. The on-disk JSON uses
|
|
33
|
+
* stable key ordering and a trailing newline so version control shows
|
|
34
|
+
* minimal diffs.
|
|
35
|
+
*/
|
|
36
|
+
write(manifest: PackageRegistryManifest): Promise<Result<WriteManifestResult>>;
|
|
37
|
+
/** Sort versions newest-first by SemVer; preserves all other fields. */
|
|
38
|
+
normalize(manifest: PackageRegistryManifest): PackageRegistryManifest;
|
|
38
39
|
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { ManifestStore };
|
|
39
42
|
//# sourceMappingURL=ManifestStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ManifestStore.d.ts","
|
|
1
|
+
{"version":3,"file":"ManifestStore.d.ts","names":[],"sources":["../../src/io/ManifestStore.ts"],"mappings":";;;;;;;;;;;;;;;;cAkCa;mBAEQ;mBACA;EAFnB,YACmB,OAAO,mBACP,YAAY;;EAI/B,oBAAoB,aAAa;;EAKjC,OAAO,aAAa;;EAKd,KAAK,aAAa,cAAc,QAAQ,OAAO;;EAe/C,aAAa,mBAAmB,QAAQ,OAAO;;;;;;;;EAwC/C,MAAM,UAAU,0BAA0B,QAAQ,OAAO;;EA+B/D,UAAU,UAAU,0BAA0B"}
|
package/dist/io/ManifestStore.js
CHANGED
|
@@ -1,126 +1,129 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { sortVersionsNewestFirst } from "../mutation/VersionSorter.js";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { DiagnosticBag, createIoErrorDiagnostic, createManifestReadErrorDiagnostic, createManifestWriteErrorDiagnostic, createRegistryToolsPackageMissingDiagnostic, createSchemaInvalidDiagnostic, ok } from "@uapkg/diagnostics";
|
|
4
|
+
import { PackageRegistryManifestSchema } from "@uapkg/registry-schema";
|
|
5
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
import { dirname } from "node:path";
|
|
7
|
+
import { safeJsonParse, stableStringify } from "@uapkg/common";
|
|
8
|
+
|
|
9
|
+
//#region src/io/ManifestStore.ts
|
|
8
10
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
11
|
+
* Reads, validates, and writes registry-package manifests on disk.
|
|
12
|
+
*
|
|
13
|
+
* Responsibilities:
|
|
14
|
+
* - Resolve manifest paths for a given package name.
|
|
15
|
+
* - Decode JSON safely.
|
|
16
|
+
* - Validate against `PackageRegistryManifestSchema`.
|
|
17
|
+
* - Write deterministic, sorted, pretty-printed JSON.
|
|
18
|
+
*/
|
|
19
|
+
var ManifestStore = class {
|
|
20
|
+
paths;
|
|
21
|
+
aggregator;
|
|
22
|
+
constructor(paths, aggregator) {
|
|
23
|
+
this.paths = paths;
|
|
24
|
+
this.aggregator = aggregator;
|
|
25
|
+
}
|
|
26
|
+
/** Resolve the manifest path for a package. Pure path computation. */
|
|
27
|
+
resolveManifestPath(packageName) {
|
|
28
|
+
return this.paths.manifestPath(packageName);
|
|
29
|
+
}
|
|
30
|
+
/** True if the manifest file exists on disk. */
|
|
31
|
+
exists(packageName) {
|
|
32
|
+
return existsSync(this.paths.manifestPath(packageName));
|
|
33
|
+
}
|
|
34
|
+
/** Read and validate a package manifest. Emits a missing-package diagnostic when absent. */
|
|
35
|
+
async read(packageName) {
|
|
36
|
+
const bag = new DiagnosticBag();
|
|
37
|
+
const filePath = this.paths.manifestPath(packageName);
|
|
38
|
+
if (!existsSync(filePath)) {
|
|
39
|
+
const diag = createRegistryToolsPackageMissingDiagnostic(packageName, filePath);
|
|
40
|
+
bag.add(diag);
|
|
41
|
+
this.aggregator.add(diag);
|
|
42
|
+
return bag.toFailure();
|
|
43
|
+
}
|
|
44
|
+
return this.readFromPath(filePath);
|
|
45
|
+
}
|
|
46
|
+
/** Read and validate a manifest file at an arbitrary path. */
|
|
47
|
+
async readFromPath(filePath) {
|
|
48
|
+
const bag = new DiagnosticBag();
|
|
49
|
+
let raw;
|
|
50
|
+
try {
|
|
51
|
+
raw = await readFile(filePath, "utf-8");
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
54
|
+
const diag = createManifestReadErrorDiagnostic(filePath, reason);
|
|
55
|
+
bag.add(diag);
|
|
56
|
+
this.aggregator.add(diag);
|
|
57
|
+
return bag.toFailure();
|
|
58
|
+
}
|
|
59
|
+
const parsed = safeJsonParse(raw, filePath);
|
|
60
|
+
if (!parsed.ok) {
|
|
61
|
+
bag.mergeArray(parsed.diagnostics);
|
|
62
|
+
this.aggregator.addMany(parsed.diagnostics);
|
|
63
|
+
return bag.toFailure();
|
|
64
|
+
}
|
|
65
|
+
const result = PackageRegistryManifestSchema.safeParse(parsed.value);
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
const issues = result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`);
|
|
68
|
+
const diag = createSchemaInvalidDiagnostic(filePath, issues);
|
|
69
|
+
bag.add(diag);
|
|
70
|
+
this.aggregator.add(diag);
|
|
71
|
+
return bag.toFailure();
|
|
72
|
+
}
|
|
73
|
+
return ok(result.data, bag.all());
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Write a package manifest deterministically.
|
|
77
|
+
*
|
|
78
|
+
* Versions are pre-sorted newest-first by SemVer. The on-disk JSON uses
|
|
79
|
+
* stable key ordering and a trailing newline so version control shows
|
|
80
|
+
* minimal diffs.
|
|
81
|
+
*/
|
|
82
|
+
async write(manifest) {
|
|
83
|
+
const bag = new DiagnosticBag();
|
|
84
|
+
const filePath = this.paths.manifestPath(manifest.name);
|
|
85
|
+
const normalized = this.normalize(manifest);
|
|
86
|
+
const body = `${stableStringify(normalized)}\n`;
|
|
87
|
+
try {
|
|
88
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
89
|
+
} catch (err) {
|
|
90
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
91
|
+
const diag = createIoErrorDiagnostic(dirname(filePath), reason);
|
|
92
|
+
bag.add(diag);
|
|
93
|
+
this.aggregator.add(diag);
|
|
94
|
+
return bag.toFailure();
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
await writeFile(filePath, body, "utf-8");
|
|
98
|
+
} catch (err) {
|
|
99
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
100
|
+
const diag = createManifestWriteErrorDiagnostic(filePath, reason);
|
|
101
|
+
bag.add(diag);
|
|
102
|
+
this.aggregator.add(diag);
|
|
103
|
+
return bag.toFailure();
|
|
104
|
+
}
|
|
105
|
+
return ok({
|
|
106
|
+
manifestPath: filePath,
|
|
107
|
+
bytesWritten: Buffer.byteLength(body, "utf-8")
|
|
108
|
+
}, bag.all());
|
|
109
|
+
}
|
|
110
|
+
/** Sort versions newest-first by SemVer; preserves all other fields. */
|
|
111
|
+
normalize(manifest) {
|
|
112
|
+
const sortedKeys = sortVersionsNewestFirst(Object.keys(manifest.versions));
|
|
113
|
+
const source = manifest.versions;
|
|
114
|
+
const versions = {};
|
|
115
|
+
for (const k of sortedKeys) {
|
|
116
|
+
const v = source[k];
|
|
117
|
+
if (v !== void 0) versions[k] = v;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
name: manifest.name,
|
|
121
|
+
packageSource: manifest.packageSource,
|
|
122
|
+
versions
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { ManifestStore };
|
|
126
129
|
//# sourceMappingURL=ManifestStore.js.map
|