repo-contract 0.3.0 → 0.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.
- package/CHANGELOG.md +23 -0
- package/README.md +46 -0
- package/dist/.dts/config/define-repo-contract.d.ts +36 -0
- package/dist/.dts/config/define-repo-contract.d.ts.map +1 -0
- package/dist/.dts/config/tokenize-command.d.ts +33 -0
- package/dist/.dts/config/tokenize-command.d.ts.map +1 -0
- package/dist/.dts/config/validate-config.d.ts +32 -0
- package/dist/.dts/config/validate-config.d.ts.map +1 -0
- package/dist/.dts/errors.d.ts +172 -0
- package/dist/.dts/errors.d.ts.map +1 -0
- package/dist/.dts/evidence/build-evidence.d.ts +26 -0
- package/dist/.dts/evidence/build-evidence.d.ts.map +1 -0
- package/dist/.dts/execution/abort-signals.d.ts +29 -0
- package/dist/.dts/execution/abort-signals.d.ts.map +1 -0
- package/dist/.dts/execution/concurrency-pool.d.ts +14 -0
- package/dist/.dts/execution/concurrency-pool.d.ts.map +1 -0
- package/dist/.dts/execution/dependency-scheduler.d.ts +30 -0
- package/dist/.dts/execution/dependency-scheduler.d.ts.map +1 -0
- package/dist/.dts/execution/process-tree.d.ts +59 -0
- package/dist/.dts/execution/process-tree.d.ts.map +1 -0
- package/dist/.dts/execution/run-checks.d.ts +31 -0
- package/dist/.dts/execution/run-checks.d.ts.map +1 -0
- package/dist/.dts/execution/spawn-check.d.ts +49 -0
- package/dist/.dts/execution/spawn-check.d.ts.map +1 -0
- package/dist/.dts/index.d.ts +14 -0
- package/dist/.dts/index.d.ts.map +1 -0
- package/dist/.dts/parsing/format-schema-issues.d.ts +11 -0
- package/dist/.dts/parsing/format-schema-issues.d.ts.map +1 -0
- package/dist/.dts/parsing/parse-json.d.ts +8 -0
- package/dist/.dts/parsing/parse-json.d.ts.map +1 -0
- package/dist/.dts/parsing/parse-output.d.ts +25 -0
- package/dist/.dts/parsing/parse-output.d.ts.map +1 -0
- package/dist/.dts/parsing/parse-text.d.ts +8 -0
- package/dist/.dts/parsing/parse-text.d.ts.map +1 -0
- package/dist/.dts/parsing/parse-yaml.d.ts +21 -0
- package/dist/.dts/parsing/parse-yaml.d.ts.map +1 -0
- package/dist/.dts/policy/run-policies.d.ts +38 -0
- package/dist/.dts/policy/run-policies.d.ts.map +1 -0
- package/dist/.dts/presets/arethetypeswrong.d.ts +39 -0
- package/dist/.dts/presets/arethetypeswrong.d.ts.map +1 -0
- package/dist/.dts/presets/broken-links.d.ts +16 -0
- package/dist/.dts/presets/broken-links.d.ts.map +1 -0
- package/dist/.dts/presets/commitlint.d.ts +22 -0
- package/dist/.dts/presets/commitlint.d.ts.map +1 -0
- package/dist/.dts/presets/dead-code.d.ts +23 -0
- package/dist/.dts/presets/dead-code.d.ts.map +1 -0
- package/dist/.dts/presets/duplication.d.ts +14 -0
- package/dist/.dts/presets/duplication.d.ts.map +1 -0
- package/dist/.dts/presets/e2e.d.ts +4 -0
- package/dist/.dts/presets/e2e.d.ts.map +1 -0
- package/dist/.dts/presets/format.d.ts +4 -0
- package/dist/.dts/presets/format.d.ts.map +1 -0
- package/dist/.dts/presets/index.d.ts +31 -0
- package/dist/.dts/presets/index.d.ts.map +1 -0
- package/dist/.dts/presets/license.d.ts +4 -0
- package/dist/.dts/presets/license.d.ts.map +1 -0
- package/dist/.dts/presets/lint.d.ts +20 -0
- package/dist/.dts/presets/lint.d.ts.map +1 -0
- package/dist/.dts/presets/markdownlint.d.ts +23 -0
- package/dist/.dts/presets/markdownlint.d.ts.map +1 -0
- package/dist/.dts/presets/publint.d.ts +13 -0
- package/dist/.dts/presets/publint.d.ts.map +1 -0
- package/dist/.dts/presets/security-deps.d.ts +4 -0
- package/dist/.dts/presets/security-deps.d.ts.map +1 -0
- package/dist/.dts/presets/security-secrets.d.ts +4 -0
- package/dist/.dts/presets/security-secrets.d.ts.map +1 -0
- package/dist/.dts/presets/shared/error-warning-pass-policy.d.ts +13 -0
- package/dist/.dts/presets/shared/error-warning-pass-policy.d.ts.map +1 -0
- package/dist/.dts/presets/shared/exit-code-fail-rationale.d.ts +23 -0
- package/dist/.dts/presets/shared/exit-code-fail-rationale.d.ts.map +1 -0
- package/dist/.dts/presets/shared/missing-dependency.d.ts +19 -0
- package/dist/.dts/presets/shared/missing-dependency.d.ts.map +1 -0
- package/dist/.dts/presets/shared/read-json-report.d.ts +33 -0
- package/dist/.dts/presets/shared/read-json-report.d.ts.map +1 -0
- package/dist/.dts/presets/shared/terminal-status.d.ts +25 -0
- package/dist/.dts/presets/shared/terminal-status.d.ts.map +1 -0
- package/dist/.dts/presets/shared/vitest-json-policy.d.ts +20 -0
- package/dist/.dts/presets/shared/vitest-json-policy.d.ts.map +1 -0
- package/dist/.dts/presets/stylelint.d.ts +17 -0
- package/dist/.dts/presets/stylelint.d.ts.map +1 -0
- package/dist/.dts/presets/test.d.ts +4 -0
- package/dist/.dts/presets/test.d.ts.map +1 -0
- package/dist/.dts/presets/typecheck.d.ts +4 -0
- package/dist/.dts/presets/typecheck.d.ts.map +1 -0
- package/dist/.dts/run-repo-contract.d.ts +38 -0
- package/dist/.dts/run-repo-contract.d.ts.map +1 -0
- package/dist/.dts/standard-schema/types.d.ts +76 -0
- package/dist/.dts/standard-schema/types.d.ts.map +1 -0
- package/dist/.dts/types.d.ts +424 -0
- package/dist/.dts/types.d.ts.map +1 -0
- package/dist/index.cjs +99 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +99 -5
- package/dist/index.js.map +1 -1
- package/dist/presets.d.cts +1 -0
- package/dist/presets.d.ts +1 -0
- package/package.json +1 -1
- package/schemas/evidence.schema.json +2 -2
- package/src/config/validate-config.ts +55 -1
- package/src/errors.ts +26 -0
- package/src/evidence/build-evidence.ts +6 -1
- package/src/index.ts +3 -0
- package/src/parsing/format-schema-issues.ts +56 -0
- package/src/parsing/parse-output.ts +50 -3
- package/src/standard-schema/types.ts +93 -0
- package/src/types.ts +48 -12
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PolicyResult } from "../../types.js";
|
|
2
|
+
/** The report, already JSON-parsed and narrowed to `T`, or the fail `PolicyResult` to return verbatim when reading or parsing it failed. See `readJsonReport`. */
|
|
3
|
+
type ReadJsonReportResult<T> = {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly value: T;
|
|
6
|
+
} | {
|
|
7
|
+
readonly ok: false;
|
|
8
|
+
readonly result: PolicyResult;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Reads and JSON-parses a report a tool wrote to disk rather than printing to stdout -- the "read,
|
|
12
|
+
* fail with one rationale if the read itself fails, fail with a different rationale if the JSON is
|
|
13
|
+
* invalid" shape shared by every preset whose tool has no stdout JSON mode (jscpd,
|
|
14
|
+
* markdownlint-cli2, secretlint). Each failure takes its own caller-supplied rationale rather than a
|
|
15
|
+
* generic shared message, since a missing report and invalid JSON usually point a consumer at a
|
|
16
|
+
* different fix (a misconfigured reporter/output flag vs. a genuinely broken tool run), and each
|
|
17
|
+
* tool's own advice differs (markdownlint's own read-failure rationale, for instance, names the
|
|
18
|
+
* specific config field to check).
|
|
19
|
+
*
|
|
20
|
+
* Takes the read itself as a thunk (`readRaw`), rather than a `path` this function reads from
|
|
21
|
+
* directly, so every call site's own `readFile(LITERAL_PATH, "utf8")` stays written as a literal
|
|
22
|
+
* argument in the caller's own file -- required by this repo's `security/detect-non-literal-fs-filename`
|
|
23
|
+
* policy, which forbids suppressing that rule outright (see policy-config.ts's `eslint.rules["security/*"]`)
|
|
24
|
+
* and would otherwise flag a `path: string` function parameter threaded into `readFile` here as
|
|
25
|
+
* non-literal.
|
|
26
|
+
* @param readRaw - reads the report's raw text (typically `() => readFile(REPORT_PATH, "utf8")`).
|
|
27
|
+
* @param onReadFailed - the rationale to fail with if `readRaw` rejects.
|
|
28
|
+
* @param onParseFailed - the rationale to fail with if the read text isn't valid JSON.
|
|
29
|
+
* @returns `{ ok: true, value }` with the parsed JSON narrowed to `T`, or `{ ok: false, result }` with the fail `PolicyResult` to return verbatim.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readJsonReport<T>(readRaw: () => Promise<string>, onReadFailed: string, onParseFailed: string): Promise<ReadJsonReportResult<T>>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=read-json-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-json-report.d.ts","sourceRoot":"","sources":["../../../../src/presets/shared/read-json-report.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,kKAAkK;AAClK,KAAK,oBAAoB,CAAC,CAAC,IACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAAE,CAAA;AAElG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAC9B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAclC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CheckEvidence, PolicyResult } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The guard every preset needs immediately after `checkDependencyInstalled`
|
|
4
|
+
* and before its own pass/fail logic: a check whose process did not run to a
|
|
5
|
+
* normal exit on its own -- it timed out, was aborted via `options.signal`,
|
|
6
|
+
* was killed by a host `SIGINT`/`SIGTERM`, received an external signal, or
|
|
7
|
+
* failed to spawn for a reason other than a missing executable -- has a
|
|
8
|
+
* `null` `exitCode` and only whatever partial output the tool managed before
|
|
9
|
+
* termination. Interpreting that with an exit-code comparison or a JSON
|
|
10
|
+
* parse would present an operational failure to the consumer as a fabricated
|
|
11
|
+
* tool-specific verdict ("TypeScript reported type errors (exit code null)",
|
|
12
|
+
* "ESLint output could not be parsed as JSON"). This reports the real
|
|
13
|
+
* terminal cause instead.
|
|
14
|
+
*
|
|
15
|
+
* `"completed"` returns `undefined` -- the process reached its own exit and
|
|
16
|
+
* the preset interprets the (possibly non-zero) exit code itself. The
|
|
17
|
+
* ENOENT `"spawn_error"` case is already handled by `checkDependencyInstalled`;
|
|
18
|
+
* this catches the remaining spawn failures (`EACCES`, `ENOEXEC`) that
|
|
19
|
+
* `missing-dependency.ts` documents as falling through.
|
|
20
|
+
* @param result - the check's raw execution evidence to inspect.
|
|
21
|
+
* @param toolName - the tool's own display name for the rationale (e.g. "ESLint", "TypeScript").
|
|
22
|
+
* @returns a fail `PolicyResult` describing the abnormal termination, or `undefined` if the process ran to its own exit and the caller should proceed.
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkTerminatedAbnormally(result: CheckEvidence, toolName: string): PolicyResult | undefined;
|
|
25
|
+
//# sourceMappingURL=terminal-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-status.d.ts","sourceRoot":"","sources":["../../../../src/presets/shared/terminal-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAGjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,GACf,YAAY,GAAG,SAAS,CAyC1B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ParsedOutput, PolicyResult } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Interprets Vitest's own `--reporter=json` output shape -- and nothing
|
|
4
|
+
* else. Shared between the `test` preset (a single, un-categorized
|
|
5
|
+
* `vitest run --reporter=json`) and this repository's own
|
|
6
|
+
* `test-unit`/`test-integration`/`test-property`/`test-e2e` checks, whose
|
|
7
|
+
* `run` splits tests into four mutually exclusive categories via
|
|
8
|
+
* scripts/run-test-category.mjs -- a repository-specific concern this
|
|
9
|
+
* function knows nothing about. Each of those four checks owns its own
|
|
10
|
+
* category-specific semantics on top of this evaluator; this function must
|
|
11
|
+
* stay narrowly scoped to "parse Vitest's JSON reporter shape," never grow
|
|
12
|
+
* into a general "testing policy" abstraction. A category's own
|
|
13
|
+
* `output.success === false` (vitest crashed / produced unparseable output)
|
|
14
|
+
* is kept distinct from a substantive test failure, exactly as every other
|
|
15
|
+
* preset in this package already does via `ParsedOutput.success`.
|
|
16
|
+
* @param output - the vitest check's parsed `--reporter=json` output to evaluate.
|
|
17
|
+
* @returns the pass/fail outcome and its rationale.
|
|
18
|
+
*/
|
|
19
|
+
export declare function evaluateVitestJsonPolicy(output: ParsedOutput<unknown> | undefined): PolicyResult;
|
|
20
|
+
//# sourceMappingURL=vitest-json-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest-json-policy.d.ts","sourceRoot":"","sources":["../../../../src/presets/shared/vitest-json-policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAMhE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,GAAG,YAAY,CAsEhG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CheckDefinitionConfig } from "../types.js";
|
|
2
|
+
/** Options accepted by {@link stylelint}. */
|
|
3
|
+
interface StylelintOptions {
|
|
4
|
+
/** Glob passed straight through to stylelint as its positional target. Defaults to `"**\/*.{css,scss}"` -- adjust it for your own stylesheet file extensions (e.g. `.less`, `.vue`, `.svelte`). */
|
|
5
|
+
readonly glob?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* CSS/SCSS lint via stylelint, using whatever stylelint config the
|
|
9
|
+
* consumer's own repository already has. `severity: "error"` blocks;
|
|
10
|
+
* `severity: "warning"` is reported but never blocks, matching how the
|
|
11
|
+
* `lint` preset treats ESLint's own severities.
|
|
12
|
+
* @param options - configuration for this check; see {@link StylelintOptions}.
|
|
13
|
+
* @returns the configured check.
|
|
14
|
+
*/
|
|
15
|
+
export declare function stylelint(options?: StylelintOptions): CheckDefinitionConfig;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=stylelint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stylelint.d.ts","sourceRoot":"","sources":["../../../src/presets/stylelint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAqBxD,6CAA6C;AAC7C,UAAU,gBAAgB;IACxB,mMAAmM;IACnM,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,qBAAqB,CAiE/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../../src/presets/test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAKxD,oFAAoF;AACpF,eAAO,MAAM,IAAI,EAAE,qBAYlB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typecheck.d.ts","sourceRoot":"","sources":["../../../src/presets/typecheck.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAKxD,wCAAwC;AACxC,eAAO,MAAM,SAAS,EAAE,qBAkBvB,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CheckSchema, Evidence, RepoContractConfig, RunRepoContractOptions, Verdict } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Executes every configured check, collects its evidence, optionally parses
|
|
4
|
+
* its output, evaluates every check's repository-owned policy against the
|
|
5
|
+
* complete evidence, and aggregates a verdict. Never calls `process.exit()`
|
|
6
|
+
* -- returns data; the caller decides what to do with `verdict.passed`.
|
|
7
|
+
*
|
|
8
|
+
* Structural configuration problems throw synchronously before any process
|
|
9
|
+
* spawns. Anything only discoverable by attempting execution (a missing
|
|
10
|
+
* binary, a bad `cwd`) becomes evidence on that check (`status:
|
|
11
|
+
* "spawn_error"`), never a throw. A policy function throwing or rejecting
|
|
12
|
+
* rejects this function's own returned promise (`PolicyThrewError`, or an
|
|
13
|
+
* `AggregateError` of them if more than one policy failed this way) --
|
|
14
|
+
* distinct from a policy that ran fine and simply returned a failure
|
|
15
|
+
* string. See `src/errors.ts` for the full distinction.
|
|
16
|
+
*
|
|
17
|
+
* Execution and policy evaluation are strictly phased: every check finishes
|
|
18
|
+
* running and every check's evidence is fully assembled before any policy
|
|
19
|
+
* is invoked (see specs/architecture.md) -- a policy can safely read
|
|
20
|
+
* `ctx.evidence` for any sibling check's result.
|
|
21
|
+
*
|
|
22
|
+
* Deliberately not declared `async`: validation runs and can throw before this function returns
|
|
23
|
+
* anything at all, so a config problem is a genuine synchronous exception to the caller (as
|
|
24
|
+
* documented above and on `InvalidRepoContractConfigError`/`InvalidCheckConfigError`/
|
|
25
|
+
* `DependencyDeclaredLaterError`) -- an `async function`'s body runs to its first `await` still
|
|
26
|
+
* inside the caller's own call stack, but any throw before that point is nonetheless converted by
|
|
27
|
+
* the language into a rejected `Promise`, never surfaced as a synchronous exception. Splitting
|
|
28
|
+
* validation out into this synchronous wrapper, with the rest of the work in the `async` function
|
|
29
|
+
* below, keeps the documented synchronous-throw guarantee actually true rather than aspirational.
|
|
30
|
+
* @param config - the repo-contract configuration to run: its checks, concurrency, and their policies
|
|
31
|
+
* @param options - run options; `options.checks` restricts execution to specific check ids, `options.signal` allows cancelling the run
|
|
32
|
+
* @returns the assembled `evidence` for every check together with the aggregated `verdict`
|
|
33
|
+
*/
|
|
34
|
+
export declare function runRepoContract<const TChecks extends CheckSchema>(config: RepoContractConfig<TChecks>, options?: RunRepoContractOptions): Promise<{
|
|
35
|
+
evidence: Evidence<TChecks>;
|
|
36
|
+
verdict: Verdict<TChecks>;
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=run-repo-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-repo-contract.d.ts","sourceRoot":"","sources":["../../src/run-repo-contract.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,sBAAsB,EACtB,OAAO,EACR,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,eAAe,CAAC,KAAK,CAAC,OAAO,SAAS,WAAW,EAC/D,MAAM,EAAE,kBAAkB,CAAC,OAAO,CAAC,EACnC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,CAGrE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hand-vendored from `@standard-schema/spec@1.1.0` (https://standardschema.dev), pinned
|
|
3
|
+
* 2026-09-04 -- see specs/decisions/0012-hand-vendored-standard-schema-support-for-optional-output-validation.md for why this is
|
|
4
|
+
* vendored rather than an installed dependency, and for the version-pin/re-diff process. Pure type
|
|
5
|
+
* declarations, zero runtime code -- assigning any real Zod/Valibot/ArkType (etc.) schema to this
|
|
6
|
+
* type costs nothing at runtime. Only `StandardSchemaV1` (validation) is vendored here -- the
|
|
7
|
+
* separate, optional `StandardJSONSchemaV1` (JSON Schema conversion) extension
|
|
8
|
+
* (https://standardschema.dev/json-schema) is out of scope; see the ADR.
|
|
9
|
+
*
|
|
10
|
+
* Upstream's `StandardSchemaV1.Props` actually extends a shared `StandardTypedV1.Props` base
|
|
11
|
+
* (`version`/`vendor`/`types`); this vendored copy inlines those fields directly into one flat
|
|
12
|
+
* interface, since repo-contract has no use for the shared base on its own -- structurally
|
|
13
|
+
* identical for any real schema object assigned to it. Re-diff against
|
|
14
|
+
* `@standard-schema/spec`'s published `dist/index.d.ts` if this file is ever touched.
|
|
15
|
+
*/
|
|
16
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
17
|
+
/** The Standard Schema properties. */
|
|
18
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
19
|
+
}
|
|
20
|
+
/** Namespaced members of {@link StandardSchemaV1}: `Props`, `Result`, `SuccessResult`, `FailureResult`, `Issue`, `PathSegment`, `Types`, `InferInput`, `InferOutput`. */
|
|
21
|
+
export declare namespace StandardSchemaV1 {
|
|
22
|
+
/** The Standard Schema properties interface. */
|
|
23
|
+
interface Props<Input = unknown, Output = Input> {
|
|
24
|
+
/** The version number of the standard. */
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
/** The vendor name of the schema library. */
|
|
27
|
+
readonly vendor: string;
|
|
28
|
+
/** Validates unknown input values. */
|
|
29
|
+
readonly validate: (value: unknown, options?: Options) => Result<Output> | Promise<Result<Output>>;
|
|
30
|
+
/** Inferred types associated with the schema. */
|
|
31
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** Options passable to `validate`. */
|
|
34
|
+
interface Options {
|
|
35
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
36
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
37
|
+
}
|
|
38
|
+
/** The result interface of the validate function. */
|
|
39
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
40
|
+
/** The result interface if validation succeeds. */
|
|
41
|
+
interface SuccessResult<Output> {
|
|
42
|
+
/** The typed output value. */
|
|
43
|
+
readonly value: Output;
|
|
44
|
+
/** A falsy value for `issues` indicates success. */
|
|
45
|
+
readonly issues?: undefined;
|
|
46
|
+
}
|
|
47
|
+
/** The result interface if validation fails. */
|
|
48
|
+
interface FailureResult {
|
|
49
|
+
/** The issues of failed validation. */
|
|
50
|
+
readonly issues: readonly Issue[];
|
|
51
|
+
}
|
|
52
|
+
/** The issue interface of the failure output. */
|
|
53
|
+
interface Issue {
|
|
54
|
+
/** The error message of the issue. */
|
|
55
|
+
readonly message: string;
|
|
56
|
+
/** The path of the issue, if any. */
|
|
57
|
+
readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;
|
|
58
|
+
}
|
|
59
|
+
/** The path segment interface of the issue. */
|
|
60
|
+
interface PathSegment {
|
|
61
|
+
/** The key representing a path segment. */
|
|
62
|
+
readonly key: PropertyKey;
|
|
63
|
+
}
|
|
64
|
+
/** The Standard Schema types interface. */
|
|
65
|
+
interface Types<Input = unknown, Output = Input> {
|
|
66
|
+
/** The input type of the schema. */
|
|
67
|
+
readonly input: Input;
|
|
68
|
+
/** The output type of the schema. */
|
|
69
|
+
readonly output: Output;
|
|
70
|
+
}
|
|
71
|
+
/** Infers the input type of a Standard Schema. */
|
|
72
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
73
|
+
/** Infers the output type of a Standard Schema. */
|
|
74
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/standard-schema/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,K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