@uapkg/diagnostics 1.2.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/base/Diagnostic.d.ts +22 -19
- package/dist/base/Diagnostic.d.ts.map +1 -1
- package/dist/base/Diagnostic.js +23 -24
- package/dist/base/Diagnostic.js.map +1 -1
- package/dist/base/DiagnosticBag.d.ts +32 -29
- package/dist/base/DiagnosticBag.d.ts.map +1 -1
- package/dist/base/DiagnosticBag.js +75 -76
- package/dist/base/DiagnosticBag.js.map +1 -1
- package/dist/base/DiagnosticFingerprint.d.ts +10 -8
- package/dist/base/DiagnosticFingerprint.d.ts.map +1 -1
- package/dist/base/DiagnosticFingerprint.js +18 -19
- package/dist/base/DiagnosticFingerprint.js.map +1 -1
- package/dist/base/DiagnosticLevel.d.ts +4 -1
- package/dist/base/DiagnosticLevel.d.ts.map +1 -1
- package/dist/base/DiagnosticLevel.js +1 -2
- package/dist/base/Result.d.ts +15 -12
- package/dist/base/Result.d.ts.map +1 -1
- package/dist/base/Result.js +28 -16
- package/dist/base/Result.js.map +1 -1
- package/dist/config/ConfigDiagnostics.d.ts +36 -33
- package/dist/config/ConfigDiagnostics.d.ts.map +1 -1
- package/dist/config/ConfigDiagnostics.js +51 -41
- package/dist/config/ConfigDiagnostics.js.map +1 -1
- package/dist/controlPlane/ControlPlaneDiagnostics.d.ts +22 -19
- package/dist/controlPlane/ControlPlaneDiagnostics.d.ts.map +1 -1
- package/dist/controlPlane/ControlPlaneDiagnostics.js +11 -7
- package/dist/controlPlane/ControlPlaneDiagnostics.js.map +1 -1
- package/dist/general/GeneralDiagnostics.d.ts +16 -13
- package/dist/general/GeneralDiagnostics.d.ts.map +1 -1
- package/dist/general/GeneralDiagnostics.js +34 -27
- package/dist/general/GeneralDiagnostics.js.map +1 -1
- package/dist/index.d.ts +20 -33
- package/dist/index.js +19 -20
- package/dist/installer/InstallerDiagnostics.d.ts +41 -38
- package/dist/installer/InstallerDiagnostics.d.ts.map +1 -1
- package/dist/installer/InstallerDiagnostics.js +86 -56
- package/dist/installer/InstallerDiagnostics.js.map +1 -1
- package/dist/manifest/ManifestDiagnostics.d.ts +50 -47
- package/dist/manifest/ManifestDiagnostics.d.ts.map +1 -1
- package/dist/manifest/ManifestDiagnostics.js +99 -80
- package/dist/manifest/ManifestDiagnostics.js.map +1 -1
- package/dist/pack/PackDiagnostics.d.ts +31 -28
- package/dist/pack/PackDiagnostics.d.ts.map +1 -1
- package/dist/pack/PackDiagnostics.js +70 -64
- package/dist/pack/PackDiagnostics.js.map +1 -1
- package/dist/postinstall/PostinstallDiagnostics.d.ts +35 -32
- package/dist/postinstall/PostinstallDiagnostics.d.ts.map +1 -1
- package/dist/postinstall/PostinstallDiagnostics.js +75 -52
- package/dist/postinstall/PostinstallDiagnostics.js.map +1 -1
- package/dist/publishing/PublishingDiagnostics.d.ts +78 -0
- package/dist/publishing/PublishingDiagnostics.d.ts.map +1 -0
- package/dist/publishing/PublishingDiagnostics.js +14 -0
- package/dist/publishing/PublishingDiagnostics.js.map +1 -0
- package/dist/registry/RegistryDiagnostics.d.ts +51 -48
- package/dist/registry/RegistryDiagnostics.d.ts.map +1 -1
- package/dist/registry/RegistryDiagnostics.js +106 -82
- package/dist/registry/RegistryDiagnostics.js.map +1 -1
- package/dist/registryTools/RegistryToolsDiagnostics.d.ts +97 -94
- package/dist/registryTools/RegistryToolsDiagnostics.d.ts.map +1 -1
- package/dist/registryTools/RegistryToolsDiagnostics.js +91 -40
- package/dist/registryTools/RegistryToolsDiagnostics.js.map +1 -1
- package/dist/resolver/ResolverDiagnostics.d.ts +27 -24
- package/dist/resolver/ResolverDiagnostics.d.ts.map +1 -1
- package/dist/resolver/ResolverDiagnostics.js +59 -43
- package/dist/resolver/ResolverDiagnostics.js.map +1 -1
- package/dist/safety/SafetyDiagnostics.d.ts +19 -16
- package/dist/safety/SafetyDiagnostics.d.ts.map +1 -1
- package/dist/safety/SafetyDiagnostics.js +38 -26
- package/dist/safety/SafetyDiagnostics.js.map +1 -1
- package/dist/spec/SpecDiagnostics.d.ts +17 -14
- package/dist/spec/SpecDiagnostics.d.ts.map +1 -1
- package/dist/spec/SpecDiagnostics.js +37 -27
- package/dist/spec/SpecDiagnostics.js.map +1 -1
- package/dist/types.d.ts +20 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -2
- package/package.json +14 -16
- package/dist/base/DiagnosticLevel.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { DiagnosticLevel } from "./DiagnosticLevel.js";
|
|
2
|
+
//#region src/base/Diagnostic.d.ts
|
|
3
|
+
type DiagnosticEmitPolicy = 'always' | 'once';
|
|
3
4
|
/**
|
|
4
5
|
* Base shape for all diagnostics. Every concrete diagnostic must extend this
|
|
5
6
|
* interface, discriminating on `code` so that `data` is always strongly typed.
|
|
@@ -7,24 +8,26 @@ export type DiagnosticEmitPolicy = 'always' | 'once';
|
|
|
7
8
|
* @typeParam C - The string literal diagnostic code.
|
|
8
9
|
* @typeParam D - The shape of the typed data payload (defaults to `undefined`).
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
interface DiagnosticBase<C extends string = string, D = undefined> {
|
|
12
|
+
/** Severity of this diagnostic. */
|
|
13
|
+
readonly level: DiagnosticLevel;
|
|
14
|
+
/** Stable, machine-readable code used for discrimination. */
|
|
15
|
+
readonly code: C;
|
|
16
|
+
/** Human-readable summary. */
|
|
17
|
+
readonly message: string;
|
|
18
|
+
/** Actionable hint shown to the user. */
|
|
19
|
+
readonly hint?: string;
|
|
20
|
+
/** Emit strategy for user-facing reporting. */
|
|
21
|
+
readonly emitPolicy?: DiagnosticEmitPolicy;
|
|
22
|
+
/** Stable dedupe key used when `emitPolicy` is `once`. */
|
|
23
|
+
readonly emitFingerprint?: string;
|
|
24
|
+
/** Strongly typed payload whose shape is determined by `code`. */
|
|
25
|
+
readonly data: D;
|
|
25
26
|
}
|
|
26
27
|
/** Create an error-level diagnostic. */
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
declare function createDiagnostic<C extends string, D = undefined>(code: C, level: DiagnosticLevel, message: string, data: D, hint?: string, options?: {
|
|
29
|
+
readonly emitPolicy?: DiagnosticEmitPolicy;
|
|
29
30
|
}): DiagnosticBase<C, D>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { DiagnosticBase, DiagnosticEmitPolicy, createDiagnostic };
|
|
30
33
|
//# sourceMappingURL=Diagnostic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diagnostic.d.ts","
|
|
1
|
+
{"version":3,"file":"Diagnostic.d.ts","names":[],"sources":["../../src/base/Diagnostic.ts"],"mappings":";;KAGY;;;;;;;;UASK,eAAe,2BAA2B;;WAEhD,OAAO;;WAGP,MAAM;;WAGN;;WAGA;;WAGA,aAAa;;WAGb;;WAGA,MAAM;;;iBAQD,iBAAiB,kBAAkB,eACjD,MAAM,GACN,OAAO,iBACP,iBACA,MAAM,GACN,eACA;WACW,aAAa;IAEvB,eAAe,GAAG"}
|
package/dist/base/Diagnostic.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { createDiagnosticFingerprint } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
1
|
+
import { createDiagnosticFingerprint } from "./DiagnosticFingerprint.js";
|
|
2
|
+
|
|
3
|
+
//#region src/base/Diagnostic.ts
|
|
5
4
|
/** Create an error-level diagnostic. */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
emitPolicy,
|
|
24
|
-
emitFingerprint,
|
|
25
|
-
};
|
|
5
|
+
function createDiagnostic(code, level, message, data, hint, options) {
|
|
6
|
+
const emitPolicy = options?.emitPolicy;
|
|
7
|
+
return {
|
|
8
|
+
level,
|
|
9
|
+
code,
|
|
10
|
+
message,
|
|
11
|
+
data,
|
|
12
|
+
hint,
|
|
13
|
+
emitPolicy,
|
|
14
|
+
emitFingerprint: emitPolicy === "once" ? createDiagnosticFingerprint({
|
|
15
|
+
level,
|
|
16
|
+
code,
|
|
17
|
+
message,
|
|
18
|
+
hint,
|
|
19
|
+
data
|
|
20
|
+
}) : void 0
|
|
21
|
+
};
|
|
26
22
|
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createDiagnostic };
|
|
27
26
|
//# sourceMappingURL=Diagnostic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diagnostic.js","
|
|
1
|
+
{"version":3,"file":"Diagnostic.js","names":[],"sources":["../../src/base/Diagnostic.ts"],"sourcesContent":["import { createDiagnosticFingerprint } from './DiagnosticFingerprint.js';\nimport type { DiagnosticLevel } from './DiagnosticLevel.js';\n\nexport type DiagnosticEmitPolicy = 'always' | 'once';\n\n/**\n * Base shape for all diagnostics. Every concrete diagnostic must extend this\n * interface, discriminating on `code` so that `data` is always strongly typed.\n *\n * @typeParam C - The string literal diagnostic code.\n * @typeParam D - The shape of the typed data payload (defaults to `undefined`).\n */\nexport interface DiagnosticBase<C extends string = string, D = undefined> {\n /** Severity of this diagnostic. */\n readonly level: DiagnosticLevel;\n\n /** Stable, machine-readable code used for discrimination. */\n readonly code: C;\n\n /** Human-readable summary. */\n readonly message: string;\n\n /** Actionable hint shown to the user. */\n readonly hint?: string;\n\n /** Emit strategy for user-facing reporting. */\n readonly emitPolicy?: DiagnosticEmitPolicy;\n\n /** Stable dedupe key used when `emitPolicy` is `once`. */\n readonly emitFingerprint?: string;\n\n /** Strongly typed payload whose shape is determined by `code`. */\n readonly data: D;\n}\n\n// ---------------------------------------------------------------------------\n// Convenience helpers to construct a diagnostic without specifying every field\n// ---------------------------------------------------------------------------\n\n/** Create an error-level diagnostic. */\nexport function createDiagnostic<C extends string, D = undefined>(\n code: C,\n level: DiagnosticLevel,\n message: string,\n data: D,\n hint?: string,\n options?: {\n readonly emitPolicy?: DiagnosticEmitPolicy;\n },\n): DiagnosticBase<C, D> {\n const emitPolicy = options?.emitPolicy;\n const emitFingerprint =\n emitPolicy === 'once'\n ? createDiagnosticFingerprint({\n level,\n code,\n message,\n hint,\n data,\n })\n : undefined;\n\n return {\n level,\n code,\n message,\n data,\n hint,\n emitPolicy,\n emitFingerprint,\n };\n}\n"],"mappings":";;;;AAwCA,SAAgB,iBACd,MACA,OACA,SACA,MACA,MACA,SAGsB;CACtB,MAAM,aAAa,SAAS;CAY5B,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA,iBAjBA,eAAe,SACX,4BAA4B;GAC1B;GACA;GACA;GACA;GACA;EACF,CAAC,IACD;CAUN;AACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { DiagnosticLevel } from "./DiagnosticLevel.js";
|
|
2
|
+
import { Diagnostic } from "../types.js";
|
|
3
|
+
import { Result } from "./Result.js";
|
|
4
|
+
//#region src/base/DiagnosticBag.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* Mutable accumulator for diagnostics produced during an operation.
|
|
6
7
|
*
|
|
@@ -12,31 +13,33 @@ import { type Result } from './Result.js';
|
|
|
12
13
|
* return bag.toResult(value);
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
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
|
-
|
|
16
|
+
declare class DiagnosticBag {
|
|
17
|
+
private readonly items;
|
|
18
|
+
/** Number of diagnostics collected so far. */
|
|
19
|
+
get length(): number;
|
|
20
|
+
/** Add a pre-built diagnostic. */
|
|
21
|
+
add(diagnostic: Diagnostic): this;
|
|
22
|
+
/** Shorthand: add an error-level diagnostic. */
|
|
23
|
+
addError<C extends string, D = undefined>(code: C, message: string, data: D, hint?: string): this;
|
|
24
|
+
/** Shorthand: add a warning-level diagnostic. */
|
|
25
|
+
addWarning<C extends string, D = undefined>(code: C, message: string, data: D, hint?: string): this;
|
|
26
|
+
/** Shorthand: add an info-level diagnostic. */
|
|
27
|
+
addInfo<C extends string, D = undefined>(code: C, message: string, data: D, hint?: string): this;
|
|
28
|
+
/** Merge another bag's diagnostics into this one. */
|
|
29
|
+
merge(other: DiagnosticBag): this;
|
|
30
|
+
/** Merge a readonly diagnostic array into this bag. */
|
|
31
|
+
mergeArray(diagnostics: readonly Diagnostic[]): this;
|
|
32
|
+
/** True if at least one diagnostic has level `error`. */
|
|
33
|
+
hasErrors(): boolean;
|
|
34
|
+
/** True if at least one diagnostic has the given level. */
|
|
35
|
+
hasLevel(level: DiagnosticLevel): boolean;
|
|
36
|
+
/** Return all collected diagnostics as a readonly array. */
|
|
37
|
+
all(): readonly Diagnostic[];
|
|
38
|
+
/** Build a successful `Result<T>` carrying accumulated diagnostics. */
|
|
39
|
+
toResult<T>(value: T): Result<T>;
|
|
40
|
+
/** Build a failed `Result` from the accumulated diagnostics. */
|
|
41
|
+
toFailure(): Result<never>;
|
|
41
42
|
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { DiagnosticBag };
|
|
42
45
|
//# sourceMappingURL=DiagnosticBag.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagnosticBag.d.ts","
|
|
1
|
+
{"version":3,"file":"DiagnosticBag.d.ts","names":[],"sources":["../../src/base/DiagnosticBag.ts"],"mappings":";;;;;;;;;;;;;;;cAgBa;mBACM;;MAGb;;EAKJ,IAAI,YAAY;;EAMhB,SAAS,kBAAkB,eAAe,MAAM,GAAG,iBAAiB,MAAM,GAAG;;EAM7E,WAAW,kBAAkB,eAAe,MAAM,GAAG,iBAAiB,MAAM,GAAG;;EAM/E,QAAQ,kBAAkB,eAAe,MAAM,GAAG,iBAAiB,MAAM,GAAG;;EAM5E,MAAM,OAAO;;EAQb,WAAW,sBAAsB;;EAQjC;;EAKA,SAAS,OAAO;;EAKhB,gBAAgB;;EAKhB,SAAS,GAAG,OAAO,IAAI,OAAO;;EAQ9B,aAAa"}
|
|
@@ -1,78 +1,77 @@
|
|
|
1
|
-
import { createDiagnostic } from
|
|
2
|
-
import { fail, ok } from
|
|
1
|
+
import { createDiagnostic } from "./Diagnostic.js";
|
|
2
|
+
import { fail, ok } from "./Result.js";
|
|
3
|
+
|
|
4
|
+
//#region src/base/DiagnosticBag.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
return fail(this.items);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
6
|
+
* Mutable accumulator for diagnostics produced during an operation.
|
|
7
|
+
*
|
|
8
|
+
* Typical usage:
|
|
9
|
+
* ```ts
|
|
10
|
+
* const bag = new DiagnosticBag();
|
|
11
|
+
* bag.addError('MY_CODE', 'Something broke', undefined, 'Try X');
|
|
12
|
+
* if (bag.hasErrors()) return bag.toFailure();
|
|
13
|
+
* return bag.toResult(value);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
var DiagnosticBag = class {
|
|
17
|
+
items = [];
|
|
18
|
+
/** Number of diagnostics collected so far. */
|
|
19
|
+
get length() {
|
|
20
|
+
return this.items.length;
|
|
21
|
+
}
|
|
22
|
+
/** Add a pre-built diagnostic. */
|
|
23
|
+
add(diagnostic) {
|
|
24
|
+
this.items.push(diagnostic);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
/** Shorthand: add an error-level diagnostic. */
|
|
28
|
+
addError(code, message, data, hint) {
|
|
29
|
+
this.items.push(createDiagnostic(code, "error", message, data, hint));
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
/** Shorthand: add a warning-level diagnostic. */
|
|
33
|
+
addWarning(code, message, data, hint) {
|
|
34
|
+
this.items.push(createDiagnostic(code, "warning", message, data, hint));
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/** Shorthand: add an info-level diagnostic. */
|
|
38
|
+
addInfo(code, message, data, hint) {
|
|
39
|
+
this.items.push(createDiagnostic(code, "info", message, data, hint));
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/** Merge another bag's diagnostics into this one. */
|
|
43
|
+
merge(other) {
|
|
44
|
+
for (const d of other.items) this.items.push(d);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/** Merge a readonly diagnostic array into this bag. */
|
|
48
|
+
mergeArray(diagnostics) {
|
|
49
|
+
for (const d of diagnostics) this.items.push(d);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/** True if at least one diagnostic has level `error`. */
|
|
53
|
+
hasErrors() {
|
|
54
|
+
return this.items.some((d) => d.level === "error");
|
|
55
|
+
}
|
|
56
|
+
/** True if at least one diagnostic has the given level. */
|
|
57
|
+
hasLevel(level) {
|
|
58
|
+
return this.items.some((d) => d.level === level);
|
|
59
|
+
}
|
|
60
|
+
/** Return all collected diagnostics as a readonly array. */
|
|
61
|
+
all() {
|
|
62
|
+
return this.items;
|
|
63
|
+
}
|
|
64
|
+
/** Build a successful `Result<T>` carrying accumulated diagnostics. */
|
|
65
|
+
toResult(value) {
|
|
66
|
+
if (this.hasErrors()) return fail(this.items);
|
|
67
|
+
return ok(value, this.items);
|
|
68
|
+
}
|
|
69
|
+
/** Build a failed `Result` from the accumulated diagnostics. */
|
|
70
|
+
toFailure() {
|
|
71
|
+
return fail(this.items);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { DiagnosticBag };
|
|
78
77
|
//# sourceMappingURL=DiagnosticBag.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagnosticBag.js","
|
|
1
|
+
{"version":3,"file":"DiagnosticBag.js","names":[],"sources":["../../src/base/DiagnosticBag.ts"],"sourcesContent":["import type { Diagnostic } from '../types.js';\nimport { createDiagnostic } from './Diagnostic.js';\nimport type { DiagnosticLevel } from './DiagnosticLevel.js';\nimport { fail, ok, type Result } from './Result.js';\n\n/**\n * Mutable accumulator for diagnostics produced during an operation.\n *\n * Typical usage:\n * ```ts\n * const bag = new DiagnosticBag();\n * bag.addError('MY_CODE', 'Something broke', undefined, 'Try X');\n * if (bag.hasErrors()) return bag.toFailure();\n * return bag.toResult(value);\n * ```\n */\nexport class DiagnosticBag {\n private readonly items: Diagnostic[] = [];\n\n /** Number of diagnostics collected so far. */\n get length(): number {\n return this.items.length;\n }\n\n /** Add a pre-built diagnostic. */\n add(diagnostic: Diagnostic): this {\n this.items.push(diagnostic);\n return this;\n }\n\n /** Shorthand: add an error-level diagnostic. */\n addError<C extends string, D = undefined>(code: C, message: string, data: D, hint?: string): this {\n this.items.push(createDiagnostic(code, 'error', message, data, hint) as Diagnostic);\n return this;\n }\n\n /** Shorthand: add a warning-level diagnostic. */\n addWarning<C extends string, D = undefined>(code: C, message: string, data: D, hint?: string): this {\n this.items.push(createDiagnostic(code, 'warning', message, data, hint) as Diagnostic);\n return this;\n }\n\n /** Shorthand: add an info-level diagnostic. */\n addInfo<C extends string, D = undefined>(code: C, message: string, data: D, hint?: string): this {\n this.items.push(createDiagnostic(code, 'info', message, data, hint) as Diagnostic);\n return this;\n }\n\n /** Merge another bag's diagnostics into this one. */\n merge(other: DiagnosticBag): this {\n for (const d of other.items) {\n this.items.push(d);\n }\n return this;\n }\n\n /** Merge a readonly diagnostic array into this bag. */\n mergeArray(diagnostics: readonly Diagnostic[]): this {\n for (const d of diagnostics) {\n this.items.push(d);\n }\n return this;\n }\n\n /** True if at least one diagnostic has level `error`. */\n hasErrors(): boolean {\n return this.items.some((d) => d.level === 'error');\n }\n\n /** True if at least one diagnostic has the given level. */\n hasLevel(level: DiagnosticLevel): boolean {\n return this.items.some((d) => d.level === level);\n }\n\n /** Return all collected diagnostics as a readonly array. */\n all(): readonly Diagnostic[] {\n return this.items;\n }\n\n /** Build a successful `Result<T>` carrying accumulated diagnostics. */\n toResult<T>(value: T): Result<T> {\n if (this.hasErrors()) {\n return fail(this.items);\n }\n return ok(value, this.items);\n }\n\n /** Build a failed `Result` from the accumulated diagnostics. */\n toFailure(): Result<never> {\n return fail(this.items);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,IAAa,gBAAb,MAA2B;CACzB,AAAiB,QAAsB,CAAC;;CAGxC,IAAI,SAAiB;EACnB,OAAO,KAAK,MAAM;CACpB;;CAGA,IAAI,YAA8B;EAChC,KAAK,MAAM,KAAK,UAAU;EAC1B,OAAO;CACT;;CAGA,SAA0C,MAAS,SAAiB,MAAS,MAAqB;EAChG,KAAK,MAAM,KAAK,iBAAiB,MAAM,SAAS,SAAS,MAAM,IAAI,CAAe;EAClF,OAAO;CACT;;CAGA,WAA4C,MAAS,SAAiB,MAAS,MAAqB;EAClG,KAAK,MAAM,KAAK,iBAAiB,MAAM,WAAW,SAAS,MAAM,IAAI,CAAe;EACpF,OAAO;CACT;;CAGA,QAAyC,MAAS,SAAiB,MAAS,MAAqB;EAC/F,KAAK,MAAM,KAAK,iBAAiB,MAAM,QAAQ,SAAS,MAAM,IAAI,CAAe;EACjF,OAAO;CACT;;CAGA,MAAM,OAA4B;EAChC,KAAK,MAAM,KAAK,MAAM,OACpB,KAAK,MAAM,KAAK,CAAC;EAEnB,OAAO;CACT;;CAGA,WAAW,aAA0C;EACnD,KAAK,MAAM,KAAK,aACd,KAAK,MAAM,KAAK,CAAC;EAEnB,OAAO;CACT;;CAGA,YAAqB;EACnB,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,UAAU,OAAO;CACnD;;CAGA,SAAS,OAAiC;EACxC,OAAO,KAAK,MAAM,MAAM,MAAM,EAAE,UAAU,KAAK;CACjD;;CAGA,MAA6B;EAC3B,OAAO,KAAK;CACd;;CAGA,SAAY,OAAqB;EAC/B,IAAI,KAAK,UAAU,GACjB,OAAO,KAAK,KAAK,KAAK;EAExB,OAAO,GAAG,OAAO,KAAK,KAAK;CAC7B;;CAGA,YAA2B;EACzB,OAAO,KAAK,KAAK,KAAK;CACxB;AACF"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DiagnosticLevel } from "./DiagnosticLevel.js";
|
|
2
|
+
//#region src/base/DiagnosticFingerprint.d.ts
|
|
2
3
|
interface FingerprintInput {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
readonly level: DiagnosticLevel;
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly hint?: string;
|
|
8
|
+
readonly data: unknown;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
declare function createDiagnosticFingerprint(input: FingerprintInput): string;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createDiagnosticFingerprint };
|
|
11
13
|
//# sourceMappingURL=DiagnosticFingerprint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagnosticFingerprint.d.ts","
|
|
1
|
+
{"version":3,"file":"DiagnosticFingerprint.d.ts","names":[],"sources":["../../src/base/DiagnosticFingerprint.ts"],"mappings":";;UAGU;WACC,OAAO;WACP;WACA;WACA;WACA;;iBAGK,4BAA4B,OAAO"}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { createHash } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
//#region src/base/DiagnosticFingerprint.ts
|
|
4
|
+
function createDiagnosticFingerprint(input) {
|
|
5
|
+
const serialized = stableSerialize({
|
|
6
|
+
level: input.level,
|
|
7
|
+
code: input.code,
|
|
8
|
+
message: input.message,
|
|
9
|
+
hint: input.hint ?? null,
|
|
10
|
+
data: input.data ?? null
|
|
11
|
+
});
|
|
12
|
+
return createHash("sha256").update(serialized).digest("hex");
|
|
11
13
|
}
|
|
12
14
|
function stableSerialize(value) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (Array.isArray(value)) {
|
|
17
|
-
return `[${value.map((item) => stableSerialize(item)).join(',')}]`;
|
|
18
|
-
}
|
|
19
|
-
const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
|
|
20
|
-
const body = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item)}`).join(',');
|
|
21
|
-
return `{${body}}`;
|
|
15
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
16
|
+
if (Array.isArray(value)) return `[${value.map((item) => stableSerialize(item)).join(",")}]`;
|
|
17
|
+
return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item)}`).join(",")}}`;
|
|
22
18
|
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { createDiagnosticFingerprint };
|
|
23
22
|
//# sourceMappingURL=DiagnosticFingerprint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagnosticFingerprint.js","
|
|
1
|
+
{"version":3,"file":"DiagnosticFingerprint.js","names":[],"sources":["../../src/base/DiagnosticFingerprint.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport type { DiagnosticLevel } from './DiagnosticLevel.js';\n\ninterface FingerprintInput {\n readonly level: DiagnosticLevel;\n readonly code: string;\n readonly message: string;\n readonly hint?: string;\n readonly data: unknown;\n}\n\nexport function createDiagnosticFingerprint(input: FingerprintInput): string {\n const serialized = stableSerialize({\n level: input.level,\n code: input.code,\n message: input.message,\n hint: input.hint ?? null,\n data: input.data ?? null,\n });\n\n return createHash('sha256').update(serialized).digest('hex');\n}\n\nfunction stableSerialize(value: unknown): string {\n if (value === null || typeof value !== 'object') {\n return JSON.stringify(value);\n }\n\n if (Array.isArray(value)) {\n return `[${value.map((item) => stableSerialize(item)).join(',')}]`;\n }\n\n const entries = Object.entries(value as Record<string, unknown>).sort(([a], [b]) => a.localeCompare(b));\n const body = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item)}`).join(',');\n return `{${body}}`;\n}\n"],"mappings":";;;AAWA,SAAgB,4BAA4B,OAAiC;CAC3E,MAAM,aAAa,gBAAgB;EACjC,OAAO,MAAM;EACb,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,MAAM,MAAM,QAAQ;EACpB,MAAM,MAAM,QAAQ;CACtB,CAAC;CAED,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,UAAU,CAAC,CAAC,OAAO,KAAK;AAC7D;AAEA,SAAS,gBAAgB,OAAwB;CAC/C,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO,KAAK,UAAU,KAAK;CAG7B,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,IAAI,MAAM,KAAK,SAAS,gBAAgB,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;CAKlE,OAAO,IAFS,OAAO,QAAQ,KAAgC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAClF,CAAC,CAAC,KAAK,CAAC,KAAK,UAAU,GAAG,KAAK,UAAU,GAAG,EAAE,GAAG,gBAAgB,IAAI,GAAG,CAAC,CAAC,KAAK,GACpF,EAAE;AAClB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/base/DiagnosticLevel.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Diagnostic severity levels.
|
|
3
4
|
*
|
|
@@ -5,5 +6,7 @@
|
|
|
5
6
|
* - `warning` – operation can continue but something is concerning
|
|
6
7
|
* - `info` – informational only
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
type DiagnosticLevel = 'error' | 'warning' | 'info';
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DiagnosticLevel };
|
|
9
12
|
//# sourceMappingURL=DiagnosticLevel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiagnosticLevel.d.ts","
|
|
1
|
+
{"version":3,"file":"DiagnosticLevel.d.ts","names":[],"sources":["../../src/base/DiagnosticLevel.ts"],"mappings":";;;;;;;;KAOY"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=DiagnosticLevel.js.map
|
|
1
|
+
export { };
|
package/dist/base/Result.d.ts
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Diagnostic } from "../types.js";
|
|
2
|
+
//#region src/base/Result.d.ts
|
|
2
3
|
/** Successful result carrying a value and optional diagnostics. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
interface ResultOk<T> {
|
|
5
|
+
readonly ok: true;
|
|
6
|
+
readonly value: T;
|
|
7
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
7
8
|
}
|
|
8
9
|
/** Failed result carrying at least one diagnostic. */
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
interface ResultFail {
|
|
11
|
+
readonly ok: false;
|
|
12
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
12
13
|
}
|
|
13
14
|
/** Discriminated union returned by every fallible uapkg operation. */
|
|
14
|
-
|
|
15
|
+
type Result<T> = ResultOk<T> | ResultFail;
|
|
15
16
|
/** Create a successful result. */
|
|
16
|
-
|
|
17
|
+
declare function ok<T>(value: T, diagnostics?: readonly Diagnostic[]): ResultOk<T>;
|
|
17
18
|
/** Create a failed result. */
|
|
18
|
-
|
|
19
|
+
declare function fail(diagnostics: readonly Diagnostic[]): ResultFail;
|
|
19
20
|
/**
|
|
20
21
|
* Build a result from a diagnostics array and an optional value.
|
|
21
22
|
* If any diagnostic has level `error`, the result is a failure.
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
declare function fromDiagnostics<T>(diagnostics: readonly Diagnostic[], value?: T): Result<T>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Result, ResultFail, ResultOk, fail, fromDiagnostics, ok };
|
|
24
27
|
//# sourceMappingURL=Result.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Result.d.ts","
|
|
1
|
+
{"version":3,"file":"Result.d.ts","names":[],"sources":["../../src/base/Result.ts"],"mappings":";;;UAOiB,SAAS;WACf;WACA,OAAO;WACP,sBAAsB;;;UAIhB;WACN;WACA,sBAAsB;;;KAIrB,OAAO,KAAK,SAAS,KAAK;;iBAOtB,GAAG,GAAG,OAAO,GAAG,uBAAsB,eAAoB,SAAS;;iBAKnE,KAAK,sBAAsB,eAAe;;;;;iBAQ1C,gBAAgB,GAAG,sBAAsB,cAAc,QAAQ,IAAI,OAAO"}
|
package/dist/base/Result.js
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
// Factory helpers
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
1
|
+
//#region src/base/Result.ts
|
|
4
2
|
/** Create a successful result. */
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
function ok(value, diagnostics = []) {
|
|
4
|
+
return {
|
|
5
|
+
ok: true,
|
|
6
|
+
value,
|
|
7
|
+
diagnostics
|
|
8
|
+
};
|
|
7
9
|
}
|
|
8
10
|
/** Create a failed result. */
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
function fail(diagnostics) {
|
|
12
|
+
return {
|
|
13
|
+
ok: false,
|
|
14
|
+
diagnostics
|
|
15
|
+
};
|
|
11
16
|
}
|
|
12
17
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
* Build a result from a diagnostics array and an optional value.
|
|
19
|
+
* If any diagnostic has level `error`, the result is a failure.
|
|
20
|
+
*/
|
|
21
|
+
function fromDiagnostics(diagnostics, value) {
|
|
22
|
+
if (diagnostics.some((d) => d.level === "error") || value === void 0) return {
|
|
23
|
+
ok: false,
|
|
24
|
+
diagnostics
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
ok: true,
|
|
28
|
+
value,
|
|
29
|
+
diagnostics
|
|
30
|
+
};
|
|
22
31
|
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { fail, fromDiagnostics, ok };
|
|
23
35
|
//# sourceMappingURL=Result.js.map
|
package/dist/base/Result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Result.js","
|
|
1
|
+
{"version":3,"file":"Result.js","names":[],"sources":["../../src/base/Result.ts"],"sourcesContent":["import type { Diagnostic } from '../types.js';\n\n// ---------------------------------------------------------------------------\n// Result<T> — the universal return type for fallible operations.\n// ---------------------------------------------------------------------------\n\n/** Successful result carrying a value and optional diagnostics. */\nexport interface ResultOk<T> {\n readonly ok: true;\n readonly value: T;\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/** Failed result carrying at least one diagnostic. */\nexport interface ResultFail {\n readonly ok: false;\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/** Discriminated union returned by every fallible uapkg operation. */\nexport type Result<T> = ResultOk<T> | ResultFail;\n\n// ---------------------------------------------------------------------------\n// Factory helpers\n// ---------------------------------------------------------------------------\n\n/** Create a successful result. */\nexport function ok<T>(value: T, diagnostics: readonly Diagnostic[] = []): ResultOk<T> {\n return { ok: true, value, diagnostics };\n}\n\n/** Create a failed result. */\nexport function fail(diagnostics: readonly Diagnostic[]): ResultFail {\n return { ok: false, diagnostics };\n}\n\n/**\n * Build a result from a diagnostics array and an optional value.\n * If any diagnostic has level `error`, the result is a failure.\n */\nexport function fromDiagnostics<T>(diagnostics: readonly Diagnostic[], value?: T): Result<T> {\n const hasError = diagnostics.some((d) => d.level === 'error');\n if (hasError || value === undefined) {\n return { ok: false, diagnostics };\n }\n return { ok: true, value, diagnostics };\n}\n"],"mappings":";;AA2BA,SAAgB,GAAM,OAAU,cAAqC,CAAC,GAAgB;CACpF,OAAO;EAAE,IAAI;EAAM;EAAO;CAAY;AACxC;;AAGA,SAAgB,KAAK,aAAgD;CACnE,OAAO;EAAE,IAAI;EAAO;CAAY;AAClC;;;;;AAMA,SAAgB,gBAAmB,aAAoC,OAAsB;CAE3F,IADiB,YAAY,MAAM,MAAM,EAAE,UAAU,OAC1C,KAAK,UAAU,QACxB,OAAO;EAAE,IAAI;EAAO;CAAY;CAElC,OAAO;EAAE,IAAI;EAAM;EAAO;CAAY;AACxC"}
|