praxis-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/_shared/diagnostics.d.ts +312 -0
- package/dist/_shared/diagnostics.js +360 -0
- package/dist/build-runtime-CJ_nQEaZ.js +5065 -0
- package/dist/codemod/index.d.ts +2 -0
- package/dist/codemod/index.js +176520 -0
- package/dist/contract/index.d.ts +677 -0
- package/dist/contract/index.js +341 -0
- package/dist/eslint/index.d.ts +90 -0
- package/dist/eslint/index.js +1047 -0
- package/dist/guards/index.d.ts +78 -0
- package/dist/guards/index.js +118 -0
- package/dist/html/index.d.ts +151 -0
- package/dist/html/index.js +1244 -0
- package/dist/index-BIBd_iPD.d.ts +951 -0
- package/dist/lit/index.d.ts +862 -0
- package/dist/lit/index.js +4893 -0
- package/dist/preact/index.d.ts +796 -0
- package/dist/preact/index.js +5043 -0
- package/dist/react/index.d.ts +28 -0
- package/dist/react/index.js +205 -0
- package/dist/react/legacy.d.ts +29 -0
- package/dist/react/legacy.js +80 -0
- package/dist/solid/index.d.ts +728 -0
- package/dist/solid/index.js +4821 -0
- package/dist/svelte/Polymorphic.svelte +190 -0
- package/dist/svelte/_polymorphic-runtime.d.ts +102 -0
- package/dist/svelte/_polymorphic-runtime.js +371 -0
- package/dist/svelte/index.d.ts +994 -0
- package/dist/svelte/index.js +4482 -0
- package/dist/tailwind/index.d.ts +197 -0
- package/dist/tailwind/index.js +767 -0
- package/dist/tailwind/safelist.css +20 -0
- package/dist/ts-plugin/index.cjs +166 -0
- package/dist/ts-plugin/index.d.cts +9 -0
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.js +21 -0
- package/dist/vite-plugin/index.d.ts +200 -0
- package/dist/vite-plugin/index.js +2106 -0
- package/dist/vue/index.d.ts +729 -0
- package/dist/vue/index.js +4945 -0
- package/dist/web/index.d.ts +832 -0
- package/dist/web/index.js +4868 -0
- package/package.json +258 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 K Huehn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# praxis-kit (packages/kit)
|
|
2
|
+
|
|
3
|
+
The **single published package**. Everything users install comes from here; every other workspace in
|
|
4
|
+
the repo is private and gets bundled into this package's entry points at build time.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pnpm add praxis-kit
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Status
|
|
11
|
+
|
|
12
|
+
Built (`tsdown`). The public `exports` surface, the framework-neutral entry files (`contract.ts` /
|
|
13
|
+
`guards.ts` / `html.ts` / `utils.ts` — thin re-exports of `@praxis-kit/core`, `primitive`, and
|
|
14
|
+
`diagnostics`), and Changesets (this is the only package it versions) are all in place. All 7
|
|
15
|
+
framework adapters are ready, including Solid and Svelte's declaration file — both formerly deferred
|
|
16
|
+
gaps, now resolved (see below). **Not yet published** (`private: true`) — pending review of the
|
|
17
|
+
build itself and the release-process wiring (CI release job, `private: false` flip, first tag), not
|
|
18
|
+
on any remaining source gap.
|
|
19
|
+
|
|
20
|
+
| Entry | Bundles | State |
|
|
21
|
+
| ----------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| `praxis-kit/react` (+ `/react/legacy`) | `adapters/react` | ✅ ready |
|
|
23
|
+
| `praxis-kit/preact` | `adapters/preact` | ✅ ready |
|
|
24
|
+
| `praxis-kit/vue` | `adapters/vue` | ✅ ready |
|
|
25
|
+
| `praxis-kit/solid` | `adapters/solid` | ✅ ready — real Solid JSX transform via `unplugin-solid/rolldown` |
|
|
26
|
+
| `praxis-kit/svelte` | `adapters/svelte` | ✅ ready — declarations generate correctly as of `rolldown-plugin-dts@^0.28.5` (via tsdown 0.23.0) |
|
|
27
|
+
| `praxis-kit/lit` | `adapters/lit` | ✅ ready |
|
|
28
|
+
| `praxis-kit/web` | `adapters/web` | ✅ ready |
|
|
29
|
+
| `praxis-kit/tailwind` (+ `.css`) | `lib/tailwind` | ✅ ready |
|
|
30
|
+
| `praxis-kit/eslint` | `plugins/eslint` | ✅ ready |
|
|
31
|
+
| `praxis-kit/ts-plugin` | `plugins/typescript` (CJS) | ✅ ready |
|
|
32
|
+
| `praxis-kit/vite-plugin` | `plugins/vite` | ✅ ready — requires the consumer's own `typescript` at runtime (real `import ts from 'typescript'`, not a build artifact) |
|
|
33
|
+
| `praxis-kit/codemod` | `tooling/codemod` | ✅ ready — fully self-contained; `ts-morph` vendors its own TypeScript, no peer needed |
|
|
34
|
+
| `praxis-kit/{contract,guards,html,utils}` | this folder | ✅ ready |
|
|
35
|
+
|
|
36
|
+
## Formerly-deferred gaps, now resolved
|
|
37
|
+
|
|
38
|
+
- **Solid.** No rolldown-native Solid JSX transform was known to exist in this workspace when this
|
|
39
|
+
build was first written. `unplugin-solid/rolldown` (backed by `babel-preset-solid`, the same
|
|
40
|
+
compiler `esbuild-plugin-solid` wraps for `../pk`'s tsup build) fills that gap — confirmed via
|
|
41
|
+
tsdown's own documented Solid recipe.
|
|
42
|
+
- **Svelte's type declarations.** `svelte`'s own shipped types use an ambient
|
|
43
|
+
`declare module 'svelte' { ... }` augmentation rather than plain top-level `export`s, which
|
|
44
|
+
`rolldown-plugin-dts@0.27.x` couldn't bundle through. Fixed upstream in
|
|
45
|
+
`rolldown-plugin-dts@^0.28.5` ("treat script-style ambient declarations as modules"), pulled in
|
|
46
|
+
via a `tsdown` bump to `0.23.0`.
|
|
47
|
+
|
|
48
|
+
## Build
|
|
49
|
+
|
|
50
|
+
`tsdown.config.ts` (this folder) — one entry per published subpath, plus a shared
|
|
51
|
+
`_shared/diagnostics` chunk. Two invariants `scripts/postbuild.ts` enforces after the build:
|
|
52
|
+
|
|
53
|
+
1. **No unpublished names in output.** JS bundles internal `@praxis-kit/*` packages directly
|
|
54
|
+
(`deps.neverBundle` opts out only each entry's framework peer and `@praxis-kit/diagnostics`);
|
|
55
|
+
declarations resolve `@praxis-kit/*` sources via `dts.compilerOptions.paths`. `publint` checks
|
|
56
|
+
the packed result (`pnpm lint:pkg`).
|
|
57
|
+
2. **Single `Diagnostics` identity.** `@praxis-kit/diagnostics` is built once into
|
|
58
|
+
`dist/_shared/diagnostics.*` and every other entry's external `@praxis-kit/diagnostics` specifier
|
|
59
|
+
is rewritten to a relative import into it — a class with private members bundled per entry would
|
|
60
|
+
be a different type and a different runtime class in each.
|
|
61
|
+
|
|
62
|
+
Framework packages (`react`, `vue`, `preact`, `solid-js`, `lit`, `svelte`) stay optional peer
|
|
63
|
+
dependencies. `typescript` is an optional peer too, for `vite-plugin` specifically — `codemod` needs
|
|
64
|
+
none (see above), and no other entry touches it.
|
|
65
|
+
|
|
66
|
+
## Verifying a release candidate
|
|
67
|
+
|
|
68
|
+
`publint` and a workspace typecheck check `dist/` shape and source types — neither installs the
|
|
69
|
+
published package the way a real consumer would. `pnpm --filter praxis-kit test:pack` does: builds
|
|
70
|
+
fresh, packs, installs the tarball plus every framework peer into an isolated fixture (outside this
|
|
71
|
+
repo's own pnpm workspace, so nothing resolves via hoisting), imports every plain-JS public entry,
|
|
72
|
+
resolves types for every typed entry, and runs `praxis-codemod` through its real `.bin` symlink —
|
|
73
|
+
the exact sequence that caught two real bugs no amount of `publint`/typecheck/lint surfaced (see
|
|
74
|
+
`DECISIONS.md`). Wired into `prepublishOnly`, so a real `npm publish` can't skip it.
|
|
75
|
+
|
|
76
|
+
See `DECISIONS.md` ("`packages/kit` — real build (tsup → tsdown)") for the full writeup, including
|
|
77
|
+
why this isn't a straight port of `../pk`'s `tsup` config.
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import "clsx";
|
|
2
|
+
//#region ../../lib/diagnostics/src/category.d.ts
|
|
3
|
+
/** The kind of rule a diagnostic reports. The load-bearing distinction:
|
|
4
|
+
*
|
|
5
|
+
* - `HTML` / `ARIA` — **spec compliance**. The markup or ARIA usage is invalid
|
|
6
|
+
* per the HTML standard or the ARIA spec. A fact, not a judgement.
|
|
7
|
+
* - `Accessibility` — **best-practice guidance**. The usage is spec-valid but
|
|
8
|
+
* inadvisable (e.g. a placeholder standing in for a label). Advisory.
|
|
9
|
+
*
|
|
10
|
+
* Keep that split deliberate: a rule belongs in `Accessibility` only when it is
|
|
11
|
+
* *not* an `HTML`/`ARIA` validity fact. The code ranges mirror it — `ARIA2xxx`
|
|
12
|
+
* and `HTML3xxx` are validity, `A11Y8xxx` is guidance (see `codes.ts`). */
|
|
13
|
+
export declare enum DiagnosticCategory {
|
|
14
|
+
Contract = 0,
|
|
15
|
+
HTML = 1,
|
|
16
|
+
ARIA = 2,
|
|
17
|
+
Composition = 3,
|
|
18
|
+
Rendering = 4,
|
|
19
|
+
Accessibility = 5,
|
|
20
|
+
Performance = 6,
|
|
21
|
+
Internal = 7,
|
|
22
|
+
Deprecation = 8,
|
|
23
|
+
Lint = 9
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ../../lib/diagnostics/src/codes.d.ts
|
|
27
|
+
export declare enum DiagnosticCode {
|
|
28
|
+
MissingRequiredChild = "COMP1001",
|
|
29
|
+
InvalidParent = "COMP1002",
|
|
30
|
+
InvalidChild = "COMP1003",
|
|
31
|
+
UnexpectedChild = "COMP1004",
|
|
32
|
+
AmbiguousChild = "COMP1005",
|
|
33
|
+
CardinalityMin = "COMP1006",
|
|
34
|
+
CardinalityMax = "COMP1007",
|
|
35
|
+
PositionViolation = "COMP1008",
|
|
36
|
+
AllowedAsViolation = "COMP1009",
|
|
37
|
+
SlotExclusive = "SLOT1001",
|
|
38
|
+
SlotSingleChild = "SLOT1002",
|
|
39
|
+
SlotDiscardedChildren = "SLOT1003",
|
|
40
|
+
SlotRenderFn = "SLOT1004",
|
|
41
|
+
MissingAriaRelationship = "ARIA2001",
|
|
42
|
+
AriaViolation = "ARIA2002",
|
|
43
|
+
AriaAttributeInvalid = "ARIA2003",
|
|
44
|
+
AriaMissingLiveRegion = "ARIA2004",
|
|
45
|
+
AriaMissingAtomic = "ARIA2005",
|
|
46
|
+
AriaRelevantInvalidToken = "ARIA2006",
|
|
47
|
+
AriaRelevantSuperseded = "ARIA2007",
|
|
48
|
+
AriaInvalidRole = "ARIA2008",
|
|
49
|
+
AriaMissingAccessibleName = "ARIA2009",
|
|
50
|
+
AriaAttributeOnPresentational = "ARIA2010",
|
|
51
|
+
AriaHiddenOnFocusable = "ARIA2011",
|
|
52
|
+
AriaRequiredProperty = "ARIA2012",
|
|
53
|
+
AriaInvalidAttributeValue = "ARIA2013",
|
|
54
|
+
AriaRedundantLevelAttribute = "ARIA2014",
|
|
55
|
+
AriaNameProhibited = "ARIA2015",
|
|
56
|
+
InvalidHeadingHierarchy = "HTML3001",
|
|
57
|
+
HtmlEmptyRole = "HTML3002",
|
|
58
|
+
HtmlImplicitRoleRedundant = "HTML3003",
|
|
59
|
+
HtmlImplicitRoleOverride = "HTML3004",
|
|
60
|
+
HtmlStandaloneRegionOverride = "HTML3005",
|
|
61
|
+
HtmlLandmarkRoleOverride = "HTML3006",
|
|
62
|
+
HtmlInvalidChild = "HTML3007",
|
|
63
|
+
HtmlRoleNotPermitted = "HTML3008",
|
|
64
|
+
HtmlInputUnsupportedType = "HTML3101",
|
|
65
|
+
HtmlInputCheckedIgnoredForType = "HTML3102",
|
|
66
|
+
HtmlInputMultipleIgnoredForType = "HTML3103",
|
|
67
|
+
HtmlInputMaxLengthIgnoredForType = "HTML3104",
|
|
68
|
+
HtmlInputMinLengthIgnoredForType = "HTML3105",
|
|
69
|
+
HtmlInputPatternIgnoredForType = "HTML3106",
|
|
70
|
+
HtmlInputMinIgnoredForType = "HTML3107",
|
|
71
|
+
HtmlInputMaxIgnoredForType = "HTML3108",
|
|
72
|
+
HtmlInputStepIgnoredForType = "HTML3109",
|
|
73
|
+
HtmlInputAcceptIgnoredForType = "HTML3110",
|
|
74
|
+
HtmlInputCaptureIgnoredForType = "HTML3111",
|
|
75
|
+
HtmlInputSizeIgnoredForType = "HTML3112",
|
|
76
|
+
HtmlInputAltIgnoredForType = "HTML3113",
|
|
77
|
+
HtmlInputHeightIgnoredForType = "HTML3114",
|
|
78
|
+
HtmlInputWidthIgnoredForType = "HTML3115",
|
|
79
|
+
HtmlAnchorDangerousHref = "HTML3201",
|
|
80
|
+
A11yInputMissingAccessibleName = "A11Y8100",
|
|
81
|
+
A11yInputPlaceholderNotLabel = "A11Y8101",
|
|
82
|
+
A11yInputPasswordAutocomplete = "A11Y8102",
|
|
83
|
+
A11yInputRequiredReadOnlyConflict = "A11Y8103",
|
|
84
|
+
A11yAnchorRoleButtonWithHref = "A11Y8200",
|
|
85
|
+
A11yAnchorAriaDisabledInert = "A11Y8201",
|
|
86
|
+
InvalidRenderingTarget = "RENDER4001",
|
|
87
|
+
LintDeadCompoundKey = "LINT5001",
|
|
88
|
+
LintDeadCompoundValue = "LINT5002",
|
|
89
|
+
LintDeadCompoundNonLiteral = "LINT5003",
|
|
90
|
+
LintMissingStrict = "LINT5004",
|
|
91
|
+
LintInvalidDefaultKey = "LINT5005",
|
|
92
|
+
LintInvalidDefaultValue = "LINT5006",
|
|
93
|
+
LintInvalidDefaultNonLiteral = "LINT5007",
|
|
94
|
+
LintNegativeMin = "LINT5008",
|
|
95
|
+
LintNegativeMax = "LINT5009",
|
|
96
|
+
LintMaxLessThanMin = "LINT5010",
|
|
97
|
+
LintZeroMax = "LINT5011",
|
|
98
|
+
LintMultipleFirst = "LINT5012",
|
|
99
|
+
LintMultipleLast = "LINT5013",
|
|
100
|
+
LintMinSumExceedsCapacity = "LINT5014",
|
|
101
|
+
LintCardinalityViolation = "LINT5015",
|
|
102
|
+
LintAriaTagOverride = "LINT5016",
|
|
103
|
+
ContractUnknownVariantDim = "COMP1010",
|
|
104
|
+
ContractUnknownVariantValue = "COMP1011",
|
|
105
|
+
ContractUnknownRecipeKey = "COMP1012",
|
|
106
|
+
ContractInvalidVariantValue = "COMP1013",
|
|
107
|
+
TailwindMultipleDisplayProps = "CSS6001",
|
|
108
|
+
TailwindReservedLayoutLiteral = "CSS6002",
|
|
109
|
+
TailwindDeadVariantClass = "CSS6003",
|
|
110
|
+
TailwindLayoutOnVoidTag = "CSS6004",
|
|
111
|
+
PluginInvalidShape = "PLUGIN7001",
|
|
112
|
+
PluginPipelineReturnType = "PLUGIN7002",
|
|
113
|
+
InternalError = "INTERNAL9000"
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region ../../lib/diagnostics/src/severity.d.ts
|
|
117
|
+
export declare enum Severity {
|
|
118
|
+
Debug = 0,
|
|
119
|
+
Info = 1,
|
|
120
|
+
Warning = 2,
|
|
121
|
+
Error = 3,
|
|
122
|
+
Fatal = 4
|
|
123
|
+
}
|
|
124
|
+
export declare function isAtLeast(s: Severity, threshold: Severity): boolean;
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region ../../lib/foundation/src/string-map.d.ts
|
|
127
|
+
/**
|
|
128
|
+
* A string-keyed object whose values are of type `T`.
|
|
129
|
+
*/
|
|
130
|
+
type StringMap<T = unknown> = Record<string, T>;
|
|
131
|
+
/**
|
|
132
|
+
* A string-keyed object with values of unknown type.
|
|
133
|
+
*/
|
|
134
|
+
type AnyRecord = StringMap<unknown>;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region ../../lib/diagnostics/src/types/diagnostic.d.ts
|
|
137
|
+
/** Data a *reader* needs to understand this diagnostic — the values a formatter
|
|
138
|
+
* would interpolate into `rationale`/`message` (the offending prop name, the
|
|
139
|
+
* expected vs actual child, the ARIA token). Human-oriented. */
|
|
140
|
+
type Context = AnyRecord;
|
|
141
|
+
/** Data a *consumer* (build plugin, editor integration, telemetry) keys off —
|
|
142
|
+
* never rendered to a person. Machine-oriented. Keep the split with `Context`
|
|
143
|
+
* deliberate: without it, both degrade into interchangeable dumping grounds. */
|
|
144
|
+
type Metadata = AnyRecord;
|
|
145
|
+
interface SourcePosition {
|
|
146
|
+
line: number;
|
|
147
|
+
col: number;
|
|
148
|
+
}
|
|
149
|
+
interface SourceLocation {
|
|
150
|
+
file: string;
|
|
151
|
+
start: SourcePosition;
|
|
152
|
+
end?: SourcePosition;
|
|
153
|
+
}
|
|
154
|
+
interface DiagnosticSuggestion {
|
|
155
|
+
title: string;
|
|
156
|
+
description?: string;
|
|
157
|
+
fix?: string;
|
|
158
|
+
}
|
|
159
|
+
interface Diagnostic {
|
|
160
|
+
code: DiagnosticCode;
|
|
161
|
+
severity: Severity;
|
|
162
|
+
category: DiagnosticCategory;
|
|
163
|
+
message: string;
|
|
164
|
+
rationale?: string;
|
|
165
|
+
component?: string;
|
|
166
|
+
contract?: string;
|
|
167
|
+
location?: SourceLocation;
|
|
168
|
+
suggestions?: DiagnosticSuggestion[];
|
|
169
|
+
/** Values a formatter interpolates into the message — human-oriented. */
|
|
170
|
+
context?: Context;
|
|
171
|
+
/** Structured data for tooling — never rendered. Machine-oriented. */
|
|
172
|
+
metadata?: Metadata;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region ../../lib/diagnostics/src/types/reporter.d.ts
|
|
176
|
+
/** Sink for diagnostics the policy decided to surface. Implementations decide
|
|
177
|
+
* what "report" means — collect, print, throw, forward. Injected into
|
|
178
|
+
* `Diagnostics`; nothing in this package picks one for you. */
|
|
179
|
+
interface DiagnosticReporter {
|
|
180
|
+
report(diagnostic: Diagnostic): void;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region ../../lib/diagnostics/src/policy.d.ts
|
|
184
|
+
export declare enum Enforcement {
|
|
185
|
+
Ignore = 0,
|
|
186
|
+
Report = 1,
|
|
187
|
+
Throw = 2
|
|
188
|
+
}
|
|
189
|
+
interface DiagnosticPolicy {
|
|
190
|
+
resolve(diagnostic: Diagnostic): Enforcement;
|
|
191
|
+
}
|
|
192
|
+
interface DefaultPolicyOptions {
|
|
193
|
+
/** Severities `>=` this are reported. Default `Severity.Info`. */
|
|
194
|
+
reportThreshold?: Severity;
|
|
195
|
+
/** Severities `>=` this throw instead. Default `Severity.Fatal`. Must be
|
|
196
|
+
* `>= reportThreshold` — a throw threshold below the report threshold makes
|
|
197
|
+
* the report band empty and is always a misconfiguration. */
|
|
198
|
+
throwThreshold?: Severity;
|
|
199
|
+
}
|
|
200
|
+
export declare class DefaultPolicy implements DiagnosticPolicy {
|
|
201
|
+
private readonly reportThreshold;
|
|
202
|
+
private readonly throwThreshold;
|
|
203
|
+
constructor({ reportThreshold, throwThreshold }?: DefaultPolicyOptions);
|
|
204
|
+
resolve(diagnostic: Diagnostic): Enforcement;
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region ../../lib/diagnostics/src/diagnostics.d.ts
|
|
208
|
+
/** The write-side shape: everything on `Diagnostic` except `severity`, which the
|
|
209
|
+
* `debug`/`info`/`warn`/`error`/`fatal` helpers stamp. */
|
|
210
|
+
type DiagnosticInput = Omit<Diagnostic, 'severity'>;
|
|
211
|
+
export declare class Diagnostics {
|
|
212
|
+
private readonly reporter;
|
|
213
|
+
private readonly policy;
|
|
214
|
+
/** Cheap gate for callers: `false` means a `Severity.Warning` diagnostic would
|
|
215
|
+
* be ignored by the policy, so warning-level validation work (often the
|
|
216
|
+
* expensive kind) can be skipped entirely. Precomputed at construction.
|
|
217
|
+
*
|
|
218
|
+
* Scoped to Warning deliberately — it is **not** a general "diagnostics on"
|
|
219
|
+
* flag. A policy that ignores Warning but reports Info or throws on Error
|
|
220
|
+
* still reads `false` here; check the policy directly for other severities. */
|
|
221
|
+
readonly warnActive: boolean;
|
|
222
|
+
constructor(reporter: DiagnosticReporter, policy?: DiagnosticPolicy);
|
|
223
|
+
report(diagnostic: Diagnostic): Diagnostic;
|
|
224
|
+
debug(input: DiagnosticInput): Diagnostic;
|
|
225
|
+
info(input: DiagnosticInput): Diagnostic;
|
|
226
|
+
warn(input: DiagnosticInput): Diagnostic;
|
|
227
|
+
error(input: DiagnosticInput): Diagnostic;
|
|
228
|
+
fatal(input: DiagnosticInput): Diagnostic;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region ../../lib/diagnostics/src/error.d.ts
|
|
232
|
+
export declare class PraxisError extends Error {
|
|
233
|
+
readonly diagnostic: Diagnostic;
|
|
234
|
+
constructor(diagnostic: Diagnostic);
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region ../../lib/diagnostics/src/formatter.d.ts
|
|
238
|
+
type Formatter = (diagnostic: Diagnostic) => string;
|
|
239
|
+
export declare function formatDiagnostic(diagnostic: Diagnostic): string;
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region ../../lib/diagnostics/src/result.d.ts
|
|
242
|
+
interface ValidationResult {
|
|
243
|
+
valid: boolean;
|
|
244
|
+
diagnostics: readonly Diagnostic[];
|
|
245
|
+
}
|
|
246
|
+
type Ok<T> = {
|
|
247
|
+
readonly ok: true;
|
|
248
|
+
readonly value: T;
|
|
249
|
+
};
|
|
250
|
+
type Err<E> = {
|
|
251
|
+
readonly ok: false;
|
|
252
|
+
readonly error: E;
|
|
253
|
+
};
|
|
254
|
+
type Result<T, E = ValidationResult> = Ok<T> | Err<E>;
|
|
255
|
+
export declare function ok<T>(value: T): Ok<T>;
|
|
256
|
+
export declare function err<E>(error: E): Err<E>;
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region ../../lib/diagnostics/src/async-console-reporter.d.ts
|
|
259
|
+
/** A console reporter that batches a microtask's worth of diagnostics into one
|
|
260
|
+
* flush and drops duplicates within that window.
|
|
261
|
+
*
|
|
262
|
+
* Dedup key is the **formatted string**, on purpose: this reporter's job is
|
|
263
|
+
* console UX — don't print the same line twice. Two distinct diagnostics that
|
|
264
|
+
* format identically (same code + message, different file/location) collapse to
|
|
265
|
+
* one printed line. If you need every distinct diagnostic preserved, use
|
|
266
|
+
* `CollectingReporter`; this one is not a lossless channel. (A
|
|
267
|
+
* location-aware key is a possible future refinement if `formatDiagnostic`
|
|
268
|
+
* stops including enough identity.) */
|
|
269
|
+
export declare class AsyncConsoleReporter implements DiagnosticReporter {
|
|
270
|
+
private readonly pending;
|
|
271
|
+
private scheduled;
|
|
272
|
+
report(diagnostic: Diagnostic): void;
|
|
273
|
+
/** Clears pending messages. Exposed for test isolation only. */
|
|
274
|
+
reset(): void;
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region ../../lib/diagnostics/src/collecting-reporter.d.ts
|
|
278
|
+
export declare class CollectingReporter implements DiagnosticReporter {
|
|
279
|
+
private readonly collected;
|
|
280
|
+
report(diagnostic: Diagnostic): void;
|
|
281
|
+
get diagnostics(): readonly Diagnostic[];
|
|
282
|
+
clear(): void;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region ../../lib/diagnostics/src/console-reporter.d.ts
|
|
286
|
+
export declare class ConsoleReporter implements DiagnosticReporter {
|
|
287
|
+
report(diagnostic: Diagnostic): void;
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region ../../lib/diagnostics/src/null-reporter.d.ts
|
|
291
|
+
export declare const nullReporter: DiagnosticReporter;
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region ../../lib/diagnostics/src/presets.d.ts
|
|
294
|
+
/** `'silent'` mode — every diagnostic is ignored. */
|
|
295
|
+
export declare const silentDiagnostics: Diagnostics;
|
|
296
|
+
/** `'warn'` mode — Warning and above print to the console; only `Fatal` throws. */
|
|
297
|
+
export declare const warnDiagnostics: Diagnostics;
|
|
298
|
+
/** `'throw'` mode — Warning prints, **`Error` and above throw**. Note this is
|
|
299
|
+
* "errors throw", not "everything throws"; a Warning is still just logged. */
|
|
300
|
+
export declare const throwDiagnostics: Diagnostics;
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region ../../lib/diagnostics/src/resolve-diagnostics.d.ts
|
|
303
|
+
type DiagnosticsMode = 'warn' | 'throw' | 'silent';
|
|
304
|
+
/**
|
|
305
|
+
* Resolves an `enforcement.diagnostics` value — a preset name, a full `Diagnostics`
|
|
306
|
+
* instance, or `undefined` — to a concrete `Diagnostics` instance. Lets authors write
|
|
307
|
+
* `enforcement: { diagnostics: 'warn' }` without importing `Diagnostics` or the presets
|
|
308
|
+
* themselves.
|
|
309
|
+
*/
|
|
310
|
+
export declare function resolveDiagnostics(value: Diagnostics | DiagnosticsMode | undefined, fallback: Diagnostics): Diagnostics;
|
|
311
|
+
//#endregion
|
|
312
|
+
export type { DefaultPolicyOptions, Diagnostic, DiagnosticInput, DiagnosticPolicy, DiagnosticReporter, DiagnosticSuggestion, DiagnosticsMode, Err, Formatter, Ok, Result, SourceLocation, SourcePosition, ValidationResult };
|