@uapkg/registry-tools 1.3.0 → 1.3.2

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.
Files changed (73) hide show
  1. package/dist/aggregator/RegistryToolsAggregator.d.ts +31 -28
  2. package/dist/aggregator/RegistryToolsAggregator.d.ts.map +1 -1
  3. package/dist/aggregator/RegistryToolsAggregator.js +71 -73
  4. package/dist/aggregator/RegistryToolsAggregator.js.map +1 -1
  5. package/dist/contracts/RegistryToolsTypes.d.ts +101 -98
  6. package/dist/contracts/RegistryToolsTypes.d.ts.map +1 -1
  7. package/dist/contracts/RegistryToolsTypes.js +5 -4
  8. package/dist/contracts/RegistryToolsTypes.js.map +1 -1
  9. package/dist/index.d.ts +18 -18
  10. package/dist/index.js +18 -30
  11. package/dist/io/IntegrityCalculator.d.ts +16 -13
  12. package/dist/io/IntegrityCalculator.d.ts.map +1 -1
  13. package/dist/io/IntegrityCalculator.js +96 -92
  14. package/dist/io/IntegrityCalculator.js.map +1 -1
  15. package/dist/io/ManifestStore.d.ts +31 -28
  16. package/dist/io/ManifestStore.d.ts.map +1 -1
  17. package/dist/io/ManifestStore.js +127 -124
  18. package/dist/io/ManifestStore.js.map +1 -1
  19. package/dist/listing/PackageLister.d.ts +18 -15
  20. package/dist/listing/PackageLister.d.ts.map +1 -1
  21. package/dist/listing/PackageLister.js +75 -77
  22. package/dist/listing/PackageLister.js.map +1 -1
  23. package/dist/mutation/AddPackageVersionPlanner.d.ts +18 -15
  24. package/dist/mutation/AddPackageVersionPlanner.d.ts.map +1 -1
  25. package/dist/mutation/AddPackageVersionPlanner.js +110 -117
  26. package/dist/mutation/AddPackageVersionPlanner.js.map +1 -1
  27. package/dist/mutation/RemovePackagePlanner.d.ts +15 -12
  28. package/dist/mutation/RemovePackagePlanner.d.ts.map +1 -1
  29. package/dist/mutation/RemovePackagePlanner.js +45 -37
  30. package/dist/mutation/RemovePackagePlanner.js.map +1 -1
  31. package/dist/mutation/RemovePackageVersionPlanner.d.ts +15 -12
  32. package/dist/mutation/RemovePackageVersionPlanner.d.ts.map +1 -1
  33. package/dist/mutation/RemovePackageVersionPlanner.js +60 -52
  34. package/dist/mutation/RemovePackageVersionPlanner.js.map +1 -1
  35. package/dist/mutation/VersionSorter.d.ts +4 -1
  36. package/dist/mutation/VersionSorter.d.ts.map +1 -1
  37. package/dist/mutation/VersionSorter.js +24 -24
  38. package/dist/mutation/VersionSorter.js.map +1 -1
  39. package/dist/paths/RegistryRepoPaths.d.ts +15 -12
  40. package/dist/paths/RegistryRepoPaths.d.ts.map +1 -1
  41. package/dist/paths/RegistryRepoPaths.js +38 -33
  42. package/dist/paths/RegistryRepoPaths.js.map +1 -1
  43. package/dist/tools/RegistryTools.d.ts +53 -50
  44. package/dist/tools/RegistryTools.d.ts.map +1 -1
  45. package/dist/tools/RegistryTools.js +205 -220
  46. package/dist/tools/RegistryTools.js.map +1 -1
  47. package/dist/validation/DependencyReachabilityValidator.d.ts +15 -12
  48. package/dist/validation/DependencyReachabilityValidator.d.ts.map +1 -1
  49. package/dist/validation/DependencyReachabilityValidator.js +62 -55
  50. package/dist/validation/DependencyReachabilityValidator.js.map +1 -1
  51. package/dist/validation/ExternalRegistryPolicyValidator.d.ts +13 -10
  52. package/dist/validation/ExternalRegistryPolicyValidator.d.ts.map +1 -1
  53. package/dist/validation/ExternalRegistryPolicyValidator.js +63 -63
  54. package/dist/validation/ExternalRegistryPolicyValidator.js.map +1 -1
  55. package/dist/validation/ManifestValidator.d.ts +11 -8
  56. package/dist/validation/ManifestValidator.d.ts.map +1 -1
  57. package/dist/validation/ManifestValidator.js +29 -24
  58. package/dist/validation/ManifestValidator.js.map +1 -1
  59. package/dist/validation/OfficialRegistryPolicyValidator.d.ts +18 -15
  60. package/dist/validation/OfficialRegistryPolicyValidator.d.ts.map +1 -1
  61. package/dist/validation/OfficialRegistryPolicyValidator.js +80 -89
  62. package/dist/validation/OfficialRegistryPolicyValidator.js.map +1 -1
  63. package/dist/validation/RegistryValidator.d.ts +25 -22
  64. package/dist/validation/RegistryValidator.d.ts.map +1 -1
  65. package/dist/validation/RegistryValidator.js +89 -87
  66. package/dist/validation/RegistryValidator.js.map +1 -1
  67. package/dist/validation/ReleaseFileNameValidator.d.ts +12 -9
  68. package/dist/validation/ReleaseFileNameValidator.d.ts.map +1 -1
  69. package/dist/validation/ReleaseFileNameValidator.js +36 -29
  70. package/dist/validation/ReleaseFileNameValidator.js.map +1 -1
  71. package/package.json +19 -21
  72. package/dist/index.d.ts.map +0 -1
  73. package/dist/index.js.map +0 -1
@@ -1,18 +1,21 @@
1
- import { type Result } from '@uapkg/diagnostics';
2
- import { type Integrity } from '@uapkg/registry-schema';
3
- import type { RegistryToolsAggregator } from '../aggregator/RegistryToolsAggregator.js';
4
- import type { IntegrityAlgorithm, IntegrityVerificationResult } from '../contracts/RegistryToolsTypes.js';
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
- export declare class IntegrityCalculator {
9
- private readonly aggregator;
10
- constructor(aggregator: RegistryToolsAggregator);
11
- /** Stream-hash a local file and return a validated `Integrity` record. */
12
- compute(filePath: string, algorithm?: IntegrityAlgorithm): Promise<Result<Integrity>>;
13
- /** Recompute a file's integrity and compare it to an expected value. */
14
- verify(filePath: string, expected: Integrity): Promise<Result<IntegrityVerificationResult>>;
15
- /** Hash a file by streaming. */
16
- private streamHash;
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","sourceRoot":"","sources":["../../src/io/IntegrityCalculator.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAE1G;;GAEG;AACH,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,uBAAuB;IAEhE,0EAA0E;IACpE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,kBAA6B,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IA4BrG,wEAAwE;IAClE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;IAiCjG,gCAAgC;IAChC,OAAO,CAAC,UAAU;CA2BnB"}
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 'node:crypto';
2
- import { createReadStream } from 'node:fs';
3
- import { createIoErrorDiagnostic, createRegistryToolsIntegrityMismatchDiagnostic, DiagnosticBag, ok, } from '@uapkg/diagnostics';
4
- import { IntegritySchema } from '@uapkg/registry-schema';
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
- * Computes and verifies file integrity locally — never reaches the network.
7
- */
8
- export class IntegrityCalculator {
9
- aggregator;
10
- constructor(aggregator) {
11
- this.aggregator = aggregator;
12
- }
13
- /** Stream-hash a local file and return a validated `Integrity` record. */
14
- async compute(filePath, algorithm = 'sha256') {
15
- const bag = new DiagnosticBag();
16
- const computed = await this.streamHash(filePath, algorithm);
17
- if (!computed.ok) {
18
- bag.mergeArray(computed.diagnostics);
19
- this.aggregator.addMany(computed.diagnostics);
20
- return bag.toFailure();
21
- }
22
- const candidate = {
23
- hash: `${algorithm}:${computed.value.hex}`,
24
- size: computed.value.size,
25
- };
26
- const validated = IntegritySchema.safeParse(candidate);
27
- if (!validated.success) {
28
- // Should not happen unless the algorithm output is malformed.
29
- const reason = validated.error.issues.map((i) => i.message).join('; ');
30
- const diag = createIoErrorDiagnostic(filePath, `integrity validation failed: ${reason}`);
31
- bag.add(diag);
32
- this.aggregator.add(diag);
33
- return bag.toFailure();
34
- }
35
- return ok(validated.data, bag.all());
36
- }
37
- /** Recompute a file's integrity and compare it to an expected value. */
38
- async verify(filePath, expected) {
39
- const bag = new DiagnosticBag();
40
- const algo = parseAlgorithm(expected.hash) ?? 'sha256';
41
- const computed = await this.compute(filePath, algo);
42
- if (!computed.ok) {
43
- bag.mergeArray(computed.diagnostics);
44
- return bag.toFailure();
45
- }
46
- const matches = computed.value.hash === expected.hash && computed.value.size === expected.size;
47
- if (!matches) {
48
- const diag = createRegistryToolsIntegrityMismatchDiagnostic(filePath, expected.hash, computed.value.hash, expected.size, computed.value.size);
49
- bag.add(diag);
50
- this.aggregator.add(diag);
51
- }
52
- return ok({
53
- ok: matches,
54
- actual: computed.value,
55
- expected,
56
- }, bag.all());
57
- }
58
- /** Hash a file by streaming. */
59
- streamHash(filePath, algorithm) {
60
- return new Promise((resolve) => {
61
- const bag = new DiagnosticBag();
62
- const hash = createHash(algorithm);
63
- let size = 0;
64
- const stream = createReadStream(filePath);
65
- stream.on('data', (chunk) => {
66
- if (Buffer.isBuffer(chunk)) {
67
- hash.update(chunk);
68
- size += chunk.length;
69
- }
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({ hex: hash.digest('hex'), size }));
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
- const colon = assetHash.indexOf(':');
89
- if (colon < 0)
90
- return null;
91
- const algo = assetHash.slice(0, colon);
92
- if (algo === 'sha256' || algo === 'sha512')
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","sourceRoot":"","sources":["../../src/io/IntegrityCalculator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EACL,uBAAuB,EACvB,8CAA8C,EAC9C,aAAa,EACb,EAAE,GAEH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAkB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIzE;;GAEG;AACH,MAAM,OAAO,mBAAmB;IACD;IAA7B,YAA6B,UAAmC;QAAnC,eAAU,GAAV,UAAU,CAAyB;IAAG,CAAC;IAEpE,0EAA0E;IAC1E,KAAK,CAAC,OAAO,CAAC,QAAgB,EAAE,YAAgC,QAAQ;QACtE,MAAM,GAAG,GAAG,IAAI,aAAa,EAAE,CAAC;QAEhC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC5D,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YACrC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAC9C,OAAO,GAAG,CAAC,SAAS,EAAE,CAAC;QACzB,CAAC;QAED,MAAM,SAAS,GAAG;YAChB,IAAI,EAAE,GAAG,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAe;YACvD,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI;SAC1B,CAAC;QAEF,MAAM,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,S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,EAAE,EAAE;gBACzB,MAAM,IAAI,GAAG,uBAAuB,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC5D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACd,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACpB,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,cAAc,CAAC,SAAiB;IACvC,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACvC,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACxD,OAAO,IAAI,CAAC;AACd,CAAC"}
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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,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 type { PackageName } from '@uapkg/common-schema';
2
- import { type Result } from '@uapkg/diagnostics';
3
- import { type PackageRegistryManifest } from '@uapkg/registry-schema';
4
- import type { RegistryToolsAggregator } from '../aggregator/RegistryToolsAggregator.js';
5
- import type { WriteManifestResult } from '../contracts/RegistryToolsTypes.js';
6
- import type { RegistryRepoPaths } from '../paths/RegistryRepoPaths.js';
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
- export declare class ManifestStore {
17
- private readonly paths;
18
- private readonly aggregator;
19
- constructor(paths: RegistryRepoPaths, aggregator: RegistryToolsAggregator);
20
- /** Resolve the manifest path for a package. Pure path computation. */
21
- resolveManifestPath(packageName: PackageName): string;
22
- /** True if the manifest file exists on disk. */
23
- exists(packageName: PackageName): boolean;
24
- /** Read and validate a package manifest. Emits a missing-package diagnostic when absent. */
25
- read(packageName: PackageName): Promise<Result<PackageRegistryManifest>>;
26
- /** Read and validate a manifest file at an arbitrary path. */
27
- readFromPath(filePath: string): Promise<Result<PackageRegistryManifest>>;
28
- /**
29
- * Write a package manifest deterministically.
30
- *
31
- * Versions are pre-sorted newest-first by SemVer. The on-disk JSON uses
32
- * stable key ordering and a trailing newline so version control shows
33
- * minimal diffs.
34
- */
35
- write(manifest: PackageRegistryManifest): Promise<Result<WriteManifestResult>>;
36
- /** Sort versions newest-first by SemVer; preserves all other fields. */
37
- normalize(manifest: PackageRegistryManifest): PackageRegistryManifest;
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","sourceRoot":"","sources":["../../src/io/ManifestStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAQL,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,uBAAu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{ mkdir, readFile, writeFile } from 'node:fs/promises';
3
- import { dirname } from 'node:path';
4
- import { safeJsonParse, stableStringify } from '@uapkg/common';
5
- import { createIoErrorDiagnostic, createManifestReadErrorDiagnostic, createManifestWriteErrorDiagnostic, createRegistryToolsPackageMissingDiagnostic, createSchemaInvalidDiagnostic, DiagnosticBag, ok, } from '@uapkg/diagnostics';
6
- import { PackageRegistryManifestSchema, } from '@uapkg/registry-schema';
7
- import { sortVersionsNewestFirst } from '../mutation/VersionSorter.js';
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
- * Reads, validates, and writes registry-package manifests on disk.
10
- *
11
- * Responsibilities:
12
- * - Resolve manifest paths for a given package name.
13
- * - Decode JSON safely.
14
- * - Validate against `PackageRegistryManifestSchema`.
15
- * - Write deterministic, sorted, pretty-printed JSON.
16
- */
17
- export class ManifestStore {
18
- paths;
19
- aggregator;
20
- constructor(paths, aggregator) {
21
- this.paths = paths;
22
- this.aggregator = aggregator;
23
- }
24
- /** Resolve the manifest path for a package. Pure path computation. */
25
- resolveManifestPath(packageName) {
26
- return this.paths.manifestPath(packageName);
27
- }
28
- /** True if the manifest file exists on disk. */
29
- exists(packageName) {
30
- return existsSync(this.paths.manifestPath(packageName));
31
- }
32
- /** Read and validate a package manifest. Emits a missing-package diagnostic when absent. */
33
- async read(packageName) {
34
- const bag = new DiagnosticBag();
35
- const filePath = this.paths.manifestPath(packageName);
36
- if (!existsSync(filePath)) {
37
- const diag = createRegistryToolsPackageMissingDiagnostic(packageName, filePath);
38
- bag.add(diag);
39
- this.aggregator.add(diag);
40
- return bag.toFailure();
41
- }
42
- return this.readFromPath(filePath);
43
- }
44
- /** Read and validate a manifest file at an arbitrary path. */
45
- async readFromPath(filePath) {
46
- const bag = new DiagnosticBag();
47
- let raw;
48
- try {
49
- raw = await readFile(filePath, 'utf-8');
50
- }
51
- catch (err) {
52
- const reason = err instanceof Error ? err.message : String(err);
53
- const diag = createManifestReadErrorDiagnostic(filePath, reason);
54
- bag.add(diag);
55
- this.aggregator.add(diag);
56
- return bag.toFailure();
57
- }
58
- const parsed = safeJsonParse(raw, filePath);
59
- if (!parsed.ok) {
60
- bag.mergeArray(parsed.diagnostics);
61
- this.aggregator.addMany(parsed.diagnostics);
62
- return bag.toFailure();
63
- }
64
- const result = PackageRegistryManifestSchema.safeParse(parsed.value);
65
- if (!result.success) {
66
- const issues = result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`);
67
- const diag = createSchemaInvalidDiagnostic(filePath, issues);
68
- bag.add(diag);
69
- this.aggregator.add(diag);
70
- return bag.toFailure();
71
- }
72
- return ok(result.data, bag.all());
73
- }
74
- /**
75
- * Write a package manifest deterministically.
76
- *
77
- * Versions are pre-sorted newest-first by SemVer. The on-disk JSON uses
78
- * stable key ordering and a trailing newline so version control shows
79
- * minimal diffs.
80
- */
81
- async write(manifest) {
82
- const bag = new DiagnosticBag();
83
- const filePath = this.paths.manifestPath(manifest.name);
84
- const normalized = this.normalize(manifest);
85
- const body = `${stableStringify(normalized)}\n`;
86
- try {
87
- await mkdir(dirname(filePath), { recursive: true });
88
- }
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
- }
99
- catch (err) {
100
- const reason = err instanceof Error ? err.message : String(err);
101
- const diag = createManifestWriteErrorDiagnostic(filePath, reason);
102
- bag.add(diag);
103
- this.aggregator.add(diag);
104
- return bag.toFailure();
105
- }
106
- return ok({ manifestPath: filePath, bytesWritten: Buffer.byteLength(body, 'utf-8') }, bag.all());
107
- }
108
- /** Sort versions newest-first by SemVer; preserves all other fields. */
109
- normalize(manifest) {
110
- const sortedKeys = sortVersionsNewestFirst(Object.keys(manifest.versions));
111
- const source = manifest.versions;
112
- const versions = {};
113
- for (const k of sortedKeys) {
114
- const v = source[k];
115
- if (v !== undefined) {
116
- versions[k] = v;
117
- }
118
- }
119
- return {
120
- name: manifest.name,
121
- packageSource: manifest.packageSource,
122
- versions: versions,
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