rfphub-validate 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 +117 -0
- package/dist/chunk-QO7M2D7A.js +184 -0
- package/dist/chunk-QO7M2D7A.js.map +1 -0
- package/dist/cli.cjs +455 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +279 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +205 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +87 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Opportunity } from '@rfp-hub/standard';
|
|
2
|
+
export { Opportunity, SPEC_VERSION } from '@rfp-hub/standard';
|
|
3
|
+
import { ValidateFunction, ErrorObject } from 'ajv/dist/2020.js';
|
|
4
|
+
import { ErrorObject as ErrorObject$1 } from 'ajv';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The advisory tier.
|
|
8
|
+
*
|
|
9
|
+
* Schema errors and advisory warnings are deliberately different things. The schema stays
|
|
10
|
+
* permissive — open key→value eligibility, free-text deadline labels, an open programModel
|
|
11
|
+
* list — because a closed enum built from one publisher's vocabulary would force every other
|
|
12
|
+
* publisher into it. That permissiveness is what makes the registries load-bearing: nothing
|
|
13
|
+
* would ever notice drift if the only signal were pass/fail.
|
|
14
|
+
*
|
|
15
|
+
* So: a document that raises warnings is still CONFORMANT. Warnings are quality signal,
|
|
16
|
+
* reported separately, and only `--strict` turns them into a failing exit code.
|
|
17
|
+
*/
|
|
18
|
+
interface Warning {
|
|
19
|
+
/** Stable machine-readable identifier for the check that fired. */
|
|
20
|
+
code: string;
|
|
21
|
+
/** JSON-Pointer-ish path to the offending value, in the same shape ajv uses. */
|
|
22
|
+
instancePath: string;
|
|
23
|
+
/** One-line human-readable explanation, naming the offending value. */
|
|
24
|
+
message: string;
|
|
25
|
+
}
|
|
26
|
+
interface Check {
|
|
27
|
+
code: string;
|
|
28
|
+
/**
|
|
29
|
+
* Verb phrase completing "N of M entries …", for count-phrased text output.
|
|
30
|
+
* e.g. "use an unregistered eligibility key".
|
|
31
|
+
*/
|
|
32
|
+
entryPhrase: string;
|
|
33
|
+
run(entry: Record<string, unknown>): Warning[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The advisory checks, in report order. Each one covers something the schema deliberately
|
|
38
|
+
* leaves open — see ./types.ts for why the two tiers are separate.
|
|
39
|
+
*/
|
|
40
|
+
declare const checks: readonly Check[];
|
|
41
|
+
/** Run every advisory check against one entry. Never throws; non-objects yield no warnings. */
|
|
42
|
+
declare function runChecks(data: unknown): Warning[];
|
|
43
|
+
/** The count-phrase for a code, for "N of M entries <phrase>" output. */
|
|
44
|
+
declare function entryPhrase(code: string): string;
|
|
45
|
+
|
|
46
|
+
interface ValidationResult {
|
|
47
|
+
/** Schema conformance. Advisory warnings never affect this. */
|
|
48
|
+
valid: boolean;
|
|
49
|
+
/** Hard schema violations. A document with any of these is not conformant. */
|
|
50
|
+
errors: ErrorObject[];
|
|
51
|
+
/**
|
|
52
|
+
* Advisory findings from the check tier — quality signal about things the schema
|
|
53
|
+
* deliberately leaves open (unregistered vocabulary values, cross-object rules JSON Schema
|
|
54
|
+
* cannot express). A conformant document may still carry warnings.
|
|
55
|
+
*/
|
|
56
|
+
warnings: Warning[];
|
|
57
|
+
}
|
|
58
|
+
interface ValidateOptions {
|
|
59
|
+
/** Spec version to validate against. Only the bundled version is supported. */
|
|
60
|
+
spec?: string;
|
|
61
|
+
/** Inject a pre-compiled validator (e.g. to validate against a custom schema). */
|
|
62
|
+
validator?: ValidateFunction;
|
|
63
|
+
/** Run the advisory check tier. Default true. */
|
|
64
|
+
checks?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Compile an ajv validator. Uses the SAME configuration the standard is authored
|
|
68
|
+
* against: draft 2020-12, strict mode, `strictRequired` off (so the conditional
|
|
69
|
+
* type-block pattern — `opportunity[opportunity.fundingType]` — is permitted).
|
|
70
|
+
*/
|
|
71
|
+
declare function createValidator(schema?: Record<string, unknown>): ValidateFunction;
|
|
72
|
+
/** Validate arbitrary data against the RFP Hub Standard, plus the advisory check tier. */
|
|
73
|
+
declare function validateOpportunity(data: unknown, opts?: ValidateOptions): ValidationResult;
|
|
74
|
+
/** Assert that data is a valid Opportunity, narrowing its type. Throws otherwise. */
|
|
75
|
+
declare function assertOpportunity(data: unknown, opts?: ValidateOptions): asserts data is Opportunity;
|
|
76
|
+
|
|
77
|
+
/** Render a single ajv error as a concise, human-readable line naming the rule that failed. */
|
|
78
|
+
declare function humanizeError(e: ErrorObject$1, data?: unknown): string;
|
|
79
|
+
/**
|
|
80
|
+
* Render a list of ajv errors as human-readable lines.
|
|
81
|
+
*
|
|
82
|
+
* Pass the validated instance when you have it: it lets the one-block-per-fundingType rule name
|
|
83
|
+
* the block that should not be there, instead of ajv's bare "must NOT be valid".
|
|
84
|
+
*/
|
|
85
|
+
declare function humanizeErrors(errors: readonly ErrorObject$1[], data?: unknown): string[];
|
|
86
|
+
|
|
87
|
+
export { type Check, type ValidateOptions, type ValidationResult, type Warning, assertOpportunity, checks, createValidator, entryPhrase, humanizeError, humanizeErrors, runChecks, validateOpportunity };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rfphub-validate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Validate funding opportunities against the RFP Hub Standard (CLI + typed library).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"rfphub-validate": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"ajv": "^8.17.1",
|
|
30
|
+
"ajv-formats": "^3.0.1",
|
|
31
|
+
"@the-rfp-hub/standard": "1.0.0"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"rfp-hub",
|
|
35
|
+
"funding",
|
|
36
|
+
"grants",
|
|
37
|
+
"json-schema",
|
|
38
|
+
"validation",
|
|
39
|
+
"ethereum",
|
|
40
|
+
"cli"
|
|
41
|
+
],
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/The-RFP-Hub/the-rfp-hub",
|
|
45
|
+
"directory": "packages/validate"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test": "vitest run"
|
|
51
|
+
}
|
|
52
|
+
}
|