docmeta 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 +61 -0
- package/dist/chunk-NTXC32C4.js +1091 -0
- package/dist/chunk-NTXC32C4.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +280 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for docmeta.
|
|
3
|
+
*
|
|
4
|
+
* The pipeline is: load files -> extract metadata (format-specific) ->
|
|
5
|
+
* resolve a schema set per file -> validate against each schema -> report.
|
|
6
|
+
* Everything after extraction operates only on `ExtractedMetadata`, so new
|
|
7
|
+
* input formats never touch validation, resolution, or reporting.
|
|
8
|
+
*/
|
|
9
|
+
/** Result of pulling a metadata block out of a single document. */
|
|
10
|
+
interface ExtractedMetadata {
|
|
11
|
+
/** Parsed metadata key/values. `{}` when a block is present but empty. */
|
|
12
|
+
data: Record<string, unknown>;
|
|
13
|
+
/** Whether a metadata block was found at all. */
|
|
14
|
+
present: boolean;
|
|
15
|
+
/** Name of the extractor/format that produced this (e.g. "markdown"). */
|
|
16
|
+
format: string;
|
|
17
|
+
/**
|
|
18
|
+
* Map a JSON Pointer (Ajv `instancePath`, e.g. "/tags/0") or a bare top-level
|
|
19
|
+
* key to its 1-based source line, for precise annotations. Returns undefined
|
|
20
|
+
* when no position is known.
|
|
21
|
+
*/
|
|
22
|
+
lineFor(pointer: string): number | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** A pluggable metadata extractor for one document format. */
|
|
25
|
+
interface MetadataExtractor {
|
|
26
|
+
/** Stable name, also used as `ExtractedMetadata.format`. */
|
|
27
|
+
name: string;
|
|
28
|
+
/** Lowercase file extensions this extractor handles, incl. dot (e.g. ".md"). */
|
|
29
|
+
extensions: string[];
|
|
30
|
+
/** Whether this extractor is wired up (false for roadmap stubs). */
|
|
31
|
+
implemented: boolean;
|
|
32
|
+
/** Extract metadata from raw file content. */
|
|
33
|
+
extract(content: string, filePath: string): ExtractedMetadata;
|
|
34
|
+
}
|
|
35
|
+
/** A single schema violation for one file, attributed to one schema. */
|
|
36
|
+
interface FieldError {
|
|
37
|
+
/** Schema id/ref that produced this error (e.g. "google:okf:0.1"). */
|
|
38
|
+
schema: string;
|
|
39
|
+
/** Ajv instancePath, e.g. "/tags/0" or "" for the root. */
|
|
40
|
+
instancePath: string;
|
|
41
|
+
/** Human-readable message. */
|
|
42
|
+
message: string;
|
|
43
|
+
/** 1-based source line, when known. */
|
|
44
|
+
line?: number;
|
|
45
|
+
/** 1-based column, when known. */
|
|
46
|
+
col?: number;
|
|
47
|
+
}
|
|
48
|
+
/** Validation outcome for a single file. */
|
|
49
|
+
interface ValidationResult {
|
|
50
|
+
/** Absolute or cwd-relative path of the file. */
|
|
51
|
+
file: string;
|
|
52
|
+
/** Extractor/format used. */
|
|
53
|
+
format: string;
|
|
54
|
+
/** Whether validation passed against every schema in the set. */
|
|
55
|
+
ok: boolean;
|
|
56
|
+
/** Schema ids/refs the file was validated against. */
|
|
57
|
+
schemas: string[];
|
|
58
|
+
/** All violations, across every schema in the set. */
|
|
59
|
+
errors: FieldError[];
|
|
60
|
+
}
|
|
61
|
+
/** Aggregate run summary. */
|
|
62
|
+
interface RunSummary {
|
|
63
|
+
files: number;
|
|
64
|
+
passed: number;
|
|
65
|
+
failed: number;
|
|
66
|
+
errors: number;
|
|
67
|
+
}
|
|
68
|
+
/** An operational/usage failure that should map to exit code 2. */
|
|
69
|
+
declare class DocmetaError extends Error {
|
|
70
|
+
constructor(message: string);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ValidateOptions {
|
|
74
|
+
inputs: string[];
|
|
75
|
+
cliSchemas?: string[];
|
|
76
|
+
exts?: string[];
|
|
77
|
+
exclude?: string[];
|
|
78
|
+
/** `--as` format override (extractor name). */
|
|
79
|
+
as?: string;
|
|
80
|
+
configPath?: string;
|
|
81
|
+
cwd?: string;
|
|
82
|
+
/** Content for the `-` (stdin) input, injected by the CLI/tests. */
|
|
83
|
+
stdinContent?: string;
|
|
84
|
+
}
|
|
85
|
+
interface ValidateRun {
|
|
86
|
+
results: ValidationResult[];
|
|
87
|
+
summary: RunSummary;
|
|
88
|
+
}
|
|
89
|
+
declare function runValidate(opts: ValidateOptions): Promise<ValidateRun>;
|
|
90
|
+
|
|
91
|
+
interface GetOptions {
|
|
92
|
+
fields: string[];
|
|
93
|
+
inputs: string[];
|
|
94
|
+
as?: string;
|
|
95
|
+
exclude?: string[];
|
|
96
|
+
exts?: string[];
|
|
97
|
+
configPath?: string;
|
|
98
|
+
cwd?: string;
|
|
99
|
+
/** Content for the `-` (stdin) input, injected by the CLI/tests. */
|
|
100
|
+
stdinContent?: string;
|
|
101
|
+
}
|
|
102
|
+
interface GetFileResult {
|
|
103
|
+
file: string;
|
|
104
|
+
present: boolean;
|
|
105
|
+
values: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
declare function runGet(opts: GetOptions): Promise<GetFileResult[]>;
|
|
108
|
+
|
|
109
|
+
interface BuiltinInfo {
|
|
110
|
+
id: string;
|
|
111
|
+
title: string;
|
|
112
|
+
description: string;
|
|
113
|
+
}
|
|
114
|
+
declare function listBuiltins(): BuiltinInfo[];
|
|
115
|
+
type RefKind = "builtin" | "file" | "url";
|
|
116
|
+
declare function classifyRef(ref: string): {
|
|
117
|
+
kind: RefKind;
|
|
118
|
+
ref: string;
|
|
119
|
+
};
|
|
120
|
+
interface LoadSchemaOptions {
|
|
121
|
+
/** Abort a remote fetch after this many ms (default 10_000). */
|
|
122
|
+
timeoutMs?: number;
|
|
123
|
+
}
|
|
124
|
+
/** Load and return the JSON Schema object for a reference. */
|
|
125
|
+
declare function loadSchema(ref: string, options?: LoadSchemaOptions): Promise<Record<string, unknown>>;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* `schemas` command core. Reports built-in schemas and supported input formats.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
interface SchemasInfo {
|
|
132
|
+
builtins: BuiltinInfo[];
|
|
133
|
+
formats: {
|
|
134
|
+
name: string;
|
|
135
|
+
extensions: string[];
|
|
136
|
+
implemented: boolean;
|
|
137
|
+
}[];
|
|
138
|
+
}
|
|
139
|
+
declare function getSchemasInfo(): SchemasInfo;
|
|
140
|
+
|
|
141
|
+
declare class Validator {
|
|
142
|
+
private ajvByDialect;
|
|
143
|
+
private cache;
|
|
144
|
+
private ajvFor;
|
|
145
|
+
private compile;
|
|
146
|
+
/**
|
|
147
|
+
* Validate `data` against every schema in `refs`. Returns all violations,
|
|
148
|
+
* each tagged with the schema that produced it and a source line via
|
|
149
|
+
* `lineFor`.
|
|
150
|
+
*/
|
|
151
|
+
validate(data: Record<string, unknown>, refs: string[], lineFor: (pointer: string) => number | undefined): Promise<FieldError[]>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface SchemaOverride {
|
|
155
|
+
files: string;
|
|
156
|
+
schemas: string[];
|
|
157
|
+
}
|
|
158
|
+
interface DocmetaConfig {
|
|
159
|
+
paths?: string[];
|
|
160
|
+
exclude?: string[];
|
|
161
|
+
schemas?: string[];
|
|
162
|
+
overrides?: SchemaOverride[];
|
|
163
|
+
}
|
|
164
|
+
/** Parse and validate config YAML text. */
|
|
165
|
+
declare function parseConfig(text: string, source: string): DocmetaConfig;
|
|
166
|
+
/**
|
|
167
|
+
* Load config from an explicit path (error if missing) or by discovery in cwd.
|
|
168
|
+
* Returns null when no config is found via discovery.
|
|
169
|
+
*/
|
|
170
|
+
declare function loadConfig(explicitPath?: string, cwd?: string): Promise<{
|
|
171
|
+
config: DocmetaConfig;
|
|
172
|
+
path: string;
|
|
173
|
+
} | null>;
|
|
174
|
+
|
|
175
|
+
declare const DEFAULT_SCHEMA = "google:okf:0.1";
|
|
176
|
+
interface ResolveParams {
|
|
177
|
+
/** File path (relative is fine) used for override glob matching. */
|
|
178
|
+
filePath: string;
|
|
179
|
+
/** `$schema` value pulled from the file's metadata. */
|
|
180
|
+
fileSchema?: unknown;
|
|
181
|
+
/** Repeatable `--schema` values; non-empty means override. */
|
|
182
|
+
cliSchemas?: string[];
|
|
183
|
+
/** Loaded config, if any. */
|
|
184
|
+
config?: DocmetaConfig | null;
|
|
185
|
+
}
|
|
186
|
+
declare function resolveSchemaSet(params: ResolveParams): string[];
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Reporters render validation results to a string. The command layer writes
|
|
190
|
+
* the result to stdout; diagnostics go to stderr separately.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
type ReportFormat = "pretty" | "json" | "github";
|
|
194
|
+
interface ReportOptions {
|
|
195
|
+
color?: boolean;
|
|
196
|
+
/** In pretty output, omit passing files. */
|
|
197
|
+
quiet?: boolean;
|
|
198
|
+
}
|
|
199
|
+
declare function render(format: ReportFormat, results: ValidationResult[], summary: RunSummary, opts?: ReportOptions): string;
|
|
200
|
+
|
|
201
|
+
export { DEFAULT_SCHEMA, type DocmetaConfig, DocmetaError, type ExtractedMetadata, type FieldError, type GetFileResult, type GetOptions, type MetadataExtractor, type ReportFormat, type RunSummary, type ValidateOptions, type ValidateRun, type ValidationResult, Validator, classifyRef, getSchemasInfo, listBuiltins, loadConfig, loadSchema, parseConfig, render, resolveSchemaSet, runGet, runValidate };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_SCHEMA,
|
|
4
|
+
DocmetaError,
|
|
5
|
+
Validator,
|
|
6
|
+
classifyRef,
|
|
7
|
+
getSchemasInfo,
|
|
8
|
+
listBuiltins,
|
|
9
|
+
loadConfig,
|
|
10
|
+
loadSchema,
|
|
11
|
+
parseConfig,
|
|
12
|
+
render,
|
|
13
|
+
resolveSchemaSet,
|
|
14
|
+
runGet,
|
|
15
|
+
runValidate
|
|
16
|
+
} from "./chunk-NTXC32C4.js";
|
|
17
|
+
export {
|
|
18
|
+
DEFAULT_SCHEMA,
|
|
19
|
+
DocmetaError,
|
|
20
|
+
Validator,
|
|
21
|
+
classifyRef,
|
|
22
|
+
getSchemasInfo,
|
|
23
|
+
listBuiltins,
|
|
24
|
+
loadConfig,
|
|
25
|
+
loadSchema,
|
|
26
|
+
parseConfig,
|
|
27
|
+
render,
|
|
28
|
+
resolveSchemaSet,
|
|
29
|
+
runGet,
|
|
30
|
+
runValidate
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "docmeta",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Validate the presence and format of document metadata (Markdown frontmatter and more) against JSON Schema. CI-friendly.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"docmeta": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/hawkeyexl/docmeta.git"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://hawkeyexl.github.io/docmeta/",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/hawkeyexl/docmeta/issues"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=24"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"dev": "tsup --watch",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:watch": "vitest",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"docs:check-cli": "node scripts/check-cli-reference.mjs",
|
|
43
|
+
"commitlint": "commitlint --edit",
|
|
44
|
+
"semantic-release": "semantic-release",
|
|
45
|
+
"prepare": "husky",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"frontmatter",
|
|
50
|
+
"metadata",
|
|
51
|
+
"json-schema",
|
|
52
|
+
"markdown",
|
|
53
|
+
"validation",
|
|
54
|
+
"cli",
|
|
55
|
+
"ci",
|
|
56
|
+
"okf"
|
|
57
|
+
],
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@xmldom/xmldom": "^0.9.10",
|
|
61
|
+
"ajv": "^8.17.1",
|
|
62
|
+
"ajv-draft-04": "^1.0.0",
|
|
63
|
+
"ajv-formats": "^3.0.1",
|
|
64
|
+
"commander": "^15.0.0",
|
|
65
|
+
"fast-glob": "^3.3.2",
|
|
66
|
+
"parse5": "^8.0.1",
|
|
67
|
+
"picocolors": "^1.1.1",
|
|
68
|
+
"picomatch": "^4.0.4",
|
|
69
|
+
"yaml": "^2.6.1"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@commitlint/cli": "^21.0.2",
|
|
73
|
+
"@commitlint/config-conventional": "^21.0.2",
|
|
74
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
75
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
76
|
+
"@semantic-release/git": "^10.0.1",
|
|
77
|
+
"@semantic-release/github": "^12.0.8",
|
|
78
|
+
"@semantic-release/npm": "^13.1.5",
|
|
79
|
+
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
80
|
+
"@types/node": "^26.0.1",
|
|
81
|
+
"@types/picomatch": "^4.0.3",
|
|
82
|
+
"husky": "^9.1.7",
|
|
83
|
+
"semantic-release": "^25.0.3",
|
|
84
|
+
"tsup": "^8.3.5",
|
|
85
|
+
"typescript": "^6.0.3",
|
|
86
|
+
"vitest": "^4.1.9"
|
|
87
|
+
}
|
|
88
|
+
}
|