@driftsys/markspec 0.1.0 → 0.3.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/README.md +32 -8
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/compiler/inverses.d.ts +22 -0
- package/esm/compiler/inverses.d.ts.map +1 -0
- package/esm/compiler/inverses.js +147 -0
- package/esm/compiler/link_target.d.ts +19 -0
- package/esm/compiler/link_target.d.ts.map +1 -0
- package/esm/compiler/link_target.js +66 -0
- package/esm/compiler/mod.d.ts +43 -0
- package/esm/compiler/mod.d.ts.map +1 -0
- package/esm/compiler/mod.js +163 -0
- package/esm/compiler/schema.d.ts +38 -0
- package/esm/compiler/schema.d.ts.map +1 -0
- package/esm/compiler/schema.js +44 -0
- package/esm/config/markspec.d.ts +51 -0
- package/esm/config/markspec.d.ts.map +1 -0
- package/esm/config/markspec.js +216 -0
- package/esm/config/mod.d.ts +48 -0
- package/esm/config/mod.d.ts.map +1 -0
- package/esm/config/mod.js +243 -0
- package/esm/formatter/mod.d.ts +65 -0
- package/esm/formatter/mod.d.ts.map +1 -0
- package/esm/formatter/mod.js +306 -0
- package/esm/mod.d.ts +19 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +18 -0
- package/esm/model/attributes.d.ts +47 -0
- package/esm/model/attributes.d.ts.map +1 -0
- package/esm/model/attributes.js +97 -0
- package/esm/model/mod.d.ts +381 -0
- package/esm/model/mod.d.ts.map +1 -0
- package/esm/model/mod.js +73 -0
- package/esm/model/profile.d.ts +189 -0
- package/esm/model/profile.d.ts.map +1 -0
- package/esm/model/profile.js +31 -0
- package/esm/parser/attributes.d.ts +48 -0
- package/esm/parser/attributes.d.ts.map +1 -0
- package/esm/parser/attributes.js +131 -0
- package/esm/parser/captions.d.ts +25 -0
- package/esm/parser/captions.d.ts.map +1 -0
- package/esm/parser/captions.js +148 -0
- package/esm/parser/directives.d.ts +29 -0
- package/esm/parser/directives.d.ts.map +1 -0
- package/esm/parser/directives.js +88 -0
- package/esm/parser/frontmatter.d.ts +53 -0
- package/esm/parser/frontmatter.d.ts.map +1 -0
- package/esm/parser/frontmatter.js +185 -0
- package/esm/parser/grammars.d.ts +22 -0
- package/esm/parser/grammars.d.ts.map +1 -0
- package/esm/parser/grammars.js +70 -0
- package/esm/parser/markdown.d.ts +32 -0
- package/esm/parser/markdown.d.ts.map +1 -0
- package/esm/parser/markdown.js +225 -0
- package/esm/parser/mod.d.ts +73 -0
- package/esm/parser/mod.d.ts.map +1 -0
- package/esm/parser/mod.js +89 -0
- package/esm/parser/references.d.ts +24 -0
- package/esm/parser/references.d.ts.map +1 -0
- package/esm/parser/references.js +71 -0
- package/esm/parser/remark.d.ts +9 -0
- package/esm/parser/remark.d.ts.map +1 -0
- package/esm/parser/remark.js +11 -0
- package/esm/parser/source.d.ts +33 -0
- package/esm/parser/source.d.ts.map +1 -0
- package/esm/parser/source.js +192 -0
- package/esm/profile/cache.d.ts +29 -0
- package/esm/profile/cache.d.ts.map +1 -0
- package/esm/profile/cache.js +45 -0
- package/esm/profile/chain.d.ts +42 -0
- package/esm/profile/chain.d.ts.map +1 -0
- package/esm/profile/chain.js +193 -0
- package/esm/profile/git-cache.d.ts +73 -0
- package/esm/profile/git-cache.d.ts.map +1 -0
- package/esm/profile/git-cache.js +96 -0
- package/esm/profile/load.d.ts +28 -0
- package/esm/profile/load.d.ts.map +1 -0
- package/esm/profile/load.js +50 -0
- package/esm/profile/manifest.d.ts +21 -0
- package/esm/profile/manifest.d.ts.map +1 -0
- package/esm/profile/manifest.js +830 -0
- package/esm/profile/merge.d.ts +26 -0
- package/esm/profile/merge.d.ts.map +1 -0
- package/esm/profile/merge.js +518 -0
- package/esm/profile/mod.d.ts +23 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +14 -0
- package/esm/profile/npm.d.ts +51 -0
- package/esm/profile/npm.d.ts.map +1 -0
- package/esm/profile/npm.js +186 -0
- package/esm/profile/resolver.d.ts +60 -0
- package/esm/profile/resolver.d.ts.map +1 -0
- package/esm/profile/resolver.js +132 -0
- package/esm/reporter/mod.d.ts +31 -0
- package/esm/reporter/mod.d.ts.map +1 -0
- package/esm/reporter/mod.js +173 -0
- package/esm/validator/attributes.d.ts +43 -0
- package/esm/validator/attributes.d.ts.map +1 -0
- package/esm/validator/attributes.js +169 -0
- package/esm/validator/mod.d.ts +44 -0
- package/esm/validator/mod.d.ts.map +1 -0
- package/esm/validator/mod.js +214 -0
- package/esm/validator/normalize.d.ts +21 -0
- package/esm/validator/normalize.d.ts.map +1 -0
- package/esm/validator/normalize.js +58 -0
- package/esm/validator/pattern.d.ts +23 -0
- package/esm/validator/pattern.d.ts.map +1 -0
- package/esm/validator/pattern.js +44 -0
- package/esm/validator/pipeline.d.ts +30 -0
- package/esm/validator/pipeline.d.ts.map +1 -0
- package/esm/validator/pipeline.js +115 -0
- package/esm/validator/traceability.d.ts +48 -0
- package/esm/validator/traceability.d.ts.map +1 -0
- package/esm/validator/traceability.js +141 -0
- package/esm/validator/types.d.ts +48 -0
- package/esm/validator/types.d.ts.map +1 -0
- package/esm/validator/types.js +140 -0
- package/esm/validator/value_types.d.ts +20 -0
- package/esm/validator/value_types.d.ts.map +1 -0
- package/esm/validator/value_types.js +126 -0
- package/package.json +8 -1
- package/script/_dnt.polyfills.d.ts +101 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +130 -0
- package/script/compiler/inverses.d.ts +22 -0
- package/script/compiler/inverses.d.ts.map +1 -0
- package/script/compiler/inverses.js +150 -0
- package/script/compiler/link_target.d.ts +19 -0
- package/script/compiler/link_target.d.ts.map +1 -0
- package/script/compiler/link_target.js +69 -0
- package/script/compiler/mod.d.ts +43 -0
- package/script/compiler/mod.d.ts.map +1 -0
- package/script/compiler/mod.js +169 -0
- package/script/compiler/schema.d.ts +38 -0
- package/script/compiler/schema.d.ts.map +1 -0
- package/script/compiler/schema.js +47 -0
- package/script/config/markspec.d.ts +51 -0
- package/script/config/markspec.d.ts.map +1 -0
- package/script/config/markspec.js +222 -0
- package/script/config/mod.d.ts +48 -0
- package/script/config/mod.d.ts.map +1 -0
- package/script/config/mod.js +250 -0
- package/script/formatter/mod.d.ts +65 -0
- package/script/formatter/mod.d.ts.map +1 -0
- package/script/formatter/mod.js +313 -0
- package/script/mod.d.ts +19 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +65 -2
- package/script/model/attributes.d.ts +47 -0
- package/script/model/attributes.d.ts.map +1 -0
- package/script/model/attributes.js +101 -0
- package/script/model/mod.d.ts +381 -0
- package/script/model/mod.d.ts.map +1 -0
- package/script/model/mod.js +83 -0
- package/script/model/profile.d.ts +189 -0
- package/script/model/profile.d.ts.map +1 -0
- package/script/model/profile.js +34 -0
- package/script/parser/attributes.d.ts +48 -0
- package/script/parser/attributes.d.ts.map +1 -0
- package/script/parser/attributes.js +137 -0
- package/script/parser/captions.d.ts +25 -0
- package/script/parser/captions.d.ts.map +1 -0
- package/script/parser/captions.js +151 -0
- package/script/parser/directives.d.ts +29 -0
- package/script/parser/directives.d.ts.map +1 -0
- package/script/parser/directives.js +91 -0
- package/script/parser/frontmatter.d.ts +53 -0
- package/script/parser/frontmatter.d.ts.map +1 -0
- package/script/parser/frontmatter.js +188 -0
- package/script/parser/grammars.d.ts +22 -0
- package/script/parser/grammars.d.ts.map +1 -0
- package/script/parser/grammars.js +77 -0
- package/script/parser/markdown.d.ts +32 -0
- package/script/parser/markdown.d.ts.map +1 -0
- package/script/parser/markdown.js +228 -0
- package/script/parser/mod.d.ts +73 -0
- package/script/parser/mod.d.ts.map +1 -0
- package/script/parser/mod.js +101 -0
- package/script/parser/references.d.ts +24 -0
- package/script/parser/references.d.ts.map +1 -0
- package/script/parser/references.js +74 -0
- package/script/parser/remark.d.ts +9 -0
- package/script/parser/remark.d.ts.map +1 -0
- package/script/parser/remark.js +17 -0
- package/script/parser/source.d.ts +33 -0
- package/script/parser/source.d.ts.map +1 -0
- package/script/parser/source.js +198 -0
- package/script/profile/cache.d.ts +29 -0
- package/script/profile/cache.d.ts.map +1 -0
- package/script/profile/cache.js +48 -0
- package/script/profile/chain.d.ts +42 -0
- package/script/profile/chain.d.ts.map +1 -0
- package/script/profile/chain.js +229 -0
- package/script/profile/git-cache.d.ts +73 -0
- package/script/profile/git-cache.d.ts.map +1 -0
- package/script/profile/git-cache.js +104 -0
- package/script/profile/load.d.ts +28 -0
- package/script/profile/load.d.ts.map +1 -0
- package/script/profile/load.js +53 -0
- package/script/profile/manifest.d.ts +21 -0
- package/script/profile/manifest.d.ts.map +1 -0
- package/script/profile/manifest.js +833 -0
- package/script/profile/merge.d.ts +26 -0
- package/script/profile/merge.d.ts.map +1 -0
- package/script/profile/merge.js +521 -0
- package/script/profile/mod.d.ts +23 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +31 -0
- package/script/profile/npm.d.ts +51 -0
- package/script/profile/npm.d.ts.map +1 -0
- package/script/profile/npm.js +191 -0
- package/script/profile/resolver.d.ts +60 -0
- package/script/profile/resolver.d.ts.map +1 -0
- package/script/profile/resolver.js +136 -0
- package/script/reporter/mod.d.ts +31 -0
- package/script/reporter/mod.d.ts.map +1 -0
- package/script/reporter/mod.js +176 -0
- package/script/validator/attributes.d.ts +43 -0
- package/script/validator/attributes.d.ts.map +1 -0
- package/script/validator/attributes.js +173 -0
- package/script/validator/mod.d.ts +44 -0
- package/script/validator/mod.d.ts.map +1 -0
- package/script/validator/mod.js +231 -0
- package/script/validator/normalize.d.ts +21 -0
- package/script/validator/normalize.d.ts.map +1 -0
- package/script/validator/normalize.js +61 -0
- package/script/validator/pattern.d.ts +23 -0
- package/script/validator/pattern.d.ts.map +1 -0
- package/script/validator/pattern.js +47 -0
- package/script/validator/pipeline.d.ts +30 -0
- package/script/validator/pipeline.d.ts.map +1 -0
- package/script/validator/pipeline.js +118 -0
- package/script/validator/traceability.d.ts +48 -0
- package/script/validator/traceability.d.ts.map +1 -0
- package/script/validator/traceability.js +146 -0
- package/script/validator/types.d.ts +48 -0
- package/script/validator/types.d.ts.map +1 -0
- package/script/validator/types.js +144 -0
- package/script/validator/value_types.d.ts +20 -0
- package/script/validator/value_types.d.ts.map +1 -0
- package/script/validator/value_types.js +129 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module model
|
|
4
|
+
*
|
|
5
|
+
* MarkSpec document model — AST types, ID types, and project configuration.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.VALUE_TYPES = exports.LIST_VALUE_TYPES = exports.ConfigError = exports.DEFAULT_PROJECT_CONFIG = exports.REFHUB_URL = exports.URI_SCHEME_RE = exports.ULID_RE = exports.IDENTITY_KEY = exports.UNIVERSAL_ATTRIBUTE_KEYS = exports.attributeSpec = exports.ATTRIBUTE_CATALOG = void 0;
|
|
9
|
+
exports.shapeFromIdValue = shapeFromIdValue;
|
|
10
|
+
var attributes_js_1 = require("./attributes.js");
|
|
11
|
+
Object.defineProperty(exports, "ATTRIBUTE_CATALOG", { enumerable: true, get: function () { return attributes_js_1.ATTRIBUTE_CATALOG; } });
|
|
12
|
+
Object.defineProperty(exports, "attributeSpec", { enumerable: true, get: function () { return attributes_js_1.attributeSpec; } });
|
|
13
|
+
Object.defineProperty(exports, "UNIVERSAL_ATTRIBUTE_KEYS", { enumerable: true, get: function () { return attributes_js_1.UNIVERSAL_ATTRIBUTE_KEYS; } });
|
|
14
|
+
/** Core-reserved identity attribute name. */
|
|
15
|
+
exports.IDENTITY_KEY = "Id";
|
|
16
|
+
/** Regex matching a bare ULID (identified-entry `Id:` value). */
|
|
17
|
+
exports.ULID_RE = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
18
|
+
/**
|
|
19
|
+
* Regex matching a scheme-qualified URI (RFC 3986 §3.1 scheme).
|
|
20
|
+
*
|
|
21
|
+
* A scheme starts with a letter, followed by letters/digits/`+`/`-`/`.`,
|
|
22
|
+
* terminated by `:`. This is the gate that distinguishes a URI value from
|
|
23
|
+
* a bare slug in an `Id:` attribute.
|
|
24
|
+
*/
|
|
25
|
+
exports.URI_SCHEME_RE = /^[A-Za-z][A-Za-z0-9+\-.]*:/;
|
|
26
|
+
/**
|
|
27
|
+
* Decide the shape of an entry from its `Id:` value.
|
|
28
|
+
*
|
|
29
|
+
* Returns `undefined` for inputs that are neither a bare ULID nor a
|
|
30
|
+
* scheme-qualified URI — the caller emits a validation error.
|
|
31
|
+
*/
|
|
32
|
+
function shapeFromIdValue(value) {
|
|
33
|
+
if (exports.ULID_RE.test(value))
|
|
34
|
+
return "identified";
|
|
35
|
+
if (exports.URI_SCHEME_RE.test(value))
|
|
36
|
+
return "referenced";
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Project configuration
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/** Default RefHub URL used as implicit fallback for parent registries. */
|
|
43
|
+
exports.REFHUB_URL = "https://driftsys.github.io/refhub";
|
|
44
|
+
/** Default configuration used when no `project.yaml` is found. */
|
|
45
|
+
exports.DEFAULT_PROJECT_CONFIG = {
|
|
46
|
+
name: "",
|
|
47
|
+
version: "0.0.0",
|
|
48
|
+
labels: [],
|
|
49
|
+
parents: [],
|
|
50
|
+
parentFallback: exports.REFHUB_URL,
|
|
51
|
+
};
|
|
52
|
+
/** Error thrown when `project.yaml` is invalid. */
|
|
53
|
+
class ConfigError extends Error {
|
|
54
|
+
constructor(configPath, fieldErrors) {
|
|
55
|
+
const summary = fieldErrors
|
|
56
|
+
.map((e) => e.line !== undefined
|
|
57
|
+
? ` ${configPath}:${e.line} — ${e.field}: ${e.message}`
|
|
58
|
+
: ` ${e.field}: ${e.message}`)
|
|
59
|
+
.join("\n");
|
|
60
|
+
super(`invalid project.yaml:\n${summary}`);
|
|
61
|
+
/** Path to the `project.yaml` file. */
|
|
62
|
+
Object.defineProperty(this, "configPath", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
/** Individual field errors. */
|
|
69
|
+
Object.defineProperty(this, "fieldErrors", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
75
|
+
this.name = "ConfigError";
|
|
76
|
+
this.configPath = configPath;
|
|
77
|
+
this.fieldErrors = fieldErrors;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ConfigError = ConfigError;
|
|
81
|
+
var profile_js_1 = require("./profile.js");
|
|
82
|
+
Object.defineProperty(exports, "LIST_VALUE_TYPES", { enumerable: true, get: function () { return profile_js_1.LIST_VALUE_TYPES; } });
|
|
83
|
+
Object.defineProperty(exports, "VALUE_TYPES", { enumerable: true, get: function () { return profile_js_1.VALUE_TYPES; } });
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module model/profile
|
|
3
|
+
*
|
|
4
|
+
* Profile data model — TypeScript types that mirror ADR-008 §4 manifest
|
|
5
|
+
* schema. Used by the profile loader, merger, and validator.
|
|
6
|
+
*/
|
|
7
|
+
import type { EntryShape } from "./mod.js";
|
|
8
|
+
/** All 14 attribute value-type keywords recognized by the core. */
|
|
9
|
+
export declare const VALUE_TYPES: readonly ["id", "id-list", "uri", "url", "path", "path-or-id", "enum", "tag-list", "text", "citation", "external-id", "integer", "date", "boolean"];
|
|
10
|
+
export type ValueType = typeof VALUE_TYPES[number];
|
|
11
|
+
/** Types whose default cardinality is a list (`0..N`). */
|
|
12
|
+
export declare const LIST_VALUE_TYPES: ReadonlySet<ValueType>;
|
|
13
|
+
/** Count bounds `lower..upper` where upper = Infinity represents `N`. */
|
|
14
|
+
export interface Cardinality {
|
|
15
|
+
readonly lower: number;
|
|
16
|
+
readonly upper: number;
|
|
17
|
+
}
|
|
18
|
+
/** Inverse declaration for link attributes (`id` / `id-list`). */
|
|
19
|
+
export interface InverseDecl {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly category: string;
|
|
22
|
+
}
|
|
23
|
+
/** A single attribute declaration within a profile scope. */
|
|
24
|
+
export interface AttrDecl {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly type: ValueType;
|
|
27
|
+
readonly required: boolean;
|
|
28
|
+
readonly cardinality: Cardinality;
|
|
29
|
+
readonly values?: readonly string[];
|
|
30
|
+
readonly inverse?: InverseDecl;
|
|
31
|
+
}
|
|
32
|
+
/** Target matcher: either a type name or a shape matcher object. */
|
|
33
|
+
export type TargetMatcher = string | {
|
|
34
|
+
readonly shape: "identified" | "referenced";
|
|
35
|
+
};
|
|
36
|
+
/** Traceability rule declared on a shape or type scope. */
|
|
37
|
+
export interface TraceRule {
|
|
38
|
+
readonly target: readonly TargetMatcher[];
|
|
39
|
+
readonly cardinality?: Cardinality;
|
|
40
|
+
readonly required: boolean;
|
|
41
|
+
}
|
|
42
|
+
export type EnforcementMode = "off" | "warn" | "error";
|
|
43
|
+
export interface TypeDef {
|
|
44
|
+
readonly name: string;
|
|
45
|
+
readonly shape: EntryShape;
|
|
46
|
+
readonly displayIdPattern?: string;
|
|
47
|
+
readonly displayIdPatternEnforcement: EnforcementMode;
|
|
48
|
+
readonly required: readonly string[];
|
|
49
|
+
readonly attributes: readonly AttrDecl[];
|
|
50
|
+
readonly traceability: ReadonlyMap<string, TraceRule>;
|
|
51
|
+
/** Optional semantic color-role name (key into `ProfileManifest.colors`). */
|
|
52
|
+
readonly color?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface DocTypeDef {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly contains: readonly string[];
|
|
57
|
+
readonly description?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Specifier scheme identifying where a profile lives. */
|
|
60
|
+
export type ProfileSpecifier = {
|
|
61
|
+
readonly kind: "local";
|
|
62
|
+
readonly path: string;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "git";
|
|
65
|
+
readonly repo: string;
|
|
66
|
+
readonly subpath?: string;
|
|
67
|
+
readonly tag: string;
|
|
68
|
+
} | {
|
|
69
|
+
readonly kind: "npm";
|
|
70
|
+
readonly scope?: string;
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly range: string;
|
|
73
|
+
};
|
|
74
|
+
/** Parsed `markspec.yaml` content — the manifest authored in a profile. */
|
|
75
|
+
export interface ProfileManifest {
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly version: string;
|
|
78
|
+
readonly description?: string;
|
|
79
|
+
readonly license?: string;
|
|
80
|
+
readonly extends?: ProfileSpecifier;
|
|
81
|
+
readonly universalRequired: readonly string[];
|
|
82
|
+
readonly universalAttributes: readonly AttrDecl[];
|
|
83
|
+
readonly labels: readonly string[];
|
|
84
|
+
/**
|
|
85
|
+
* Semantic color-role bindings authored on this manifest.
|
|
86
|
+
* Maps a profile-author-chosen name (e.g. "primary") to a palette hue
|
|
87
|
+
* name (one of "blue", "cyan", "teal", "orange", "red", "purple", "grey").
|
|
88
|
+
* Empty when the manifest does not declare `profile.colors:`.
|
|
89
|
+
*/
|
|
90
|
+
readonly colors: ReadonlyMap<string, string>;
|
|
91
|
+
readonly identified: {
|
|
92
|
+
readonly required: readonly string[];
|
|
93
|
+
readonly attributes: readonly AttrDecl[];
|
|
94
|
+
readonly traceability: ReadonlyMap<string, TraceRule>;
|
|
95
|
+
};
|
|
96
|
+
readonly referenced: {
|
|
97
|
+
readonly required: readonly string[];
|
|
98
|
+
readonly attributes: readonly AttrDecl[];
|
|
99
|
+
};
|
|
100
|
+
readonly types: ReadonlyMap<string, TypeDef>;
|
|
101
|
+
readonly documents: {
|
|
102
|
+
readonly types: readonly DocTypeDef[];
|
|
103
|
+
readonly frontMatter: readonly AttrDecl[];
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A profile after it has been resolved and parsed. One tier of a
|
|
108
|
+
* {@linkcode ProfileChain}.
|
|
109
|
+
*
|
|
110
|
+
* `sourcePath` is the absolute path of the `markspec.yaml` the manifest was
|
|
111
|
+
* parsed from. `baseDir` is the directory containing that file — used as the
|
|
112
|
+
* context for resolving this profile's `extends:` (in Phase 3+).
|
|
113
|
+
*/
|
|
114
|
+
export interface LoadedProfile {
|
|
115
|
+
readonly id: string;
|
|
116
|
+
readonly version: string;
|
|
117
|
+
readonly specifier: ProfileSpecifier;
|
|
118
|
+
readonly manifest: ProfileManifest;
|
|
119
|
+
readonly sourcePath: string;
|
|
120
|
+
readonly baseDir: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The resolved profile chain for a project. A Phase 2 chain always contains
|
|
124
|
+
* exactly one tier (no `extends:` walking). Phase 3 introduces multi-tier
|
|
125
|
+
* chains ordered root-parent → leaf-child.
|
|
126
|
+
*/
|
|
127
|
+
export interface ProfileChain {
|
|
128
|
+
readonly tiers: readonly LoadedProfile[];
|
|
129
|
+
readonly effective: EffectiveProfile;
|
|
130
|
+
}
|
|
131
|
+
/** Identifier of the profile (tier) that contributed a value — `manifest.id`. */
|
|
132
|
+
export type ProfileId = string;
|
|
133
|
+
/** A single value annotated with the profile it originated from. */
|
|
134
|
+
export interface ProvenancedValue<T> {
|
|
135
|
+
readonly value: T;
|
|
136
|
+
readonly origin: ProfileId;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A map-valued entry: the current effective value, the tier that set it, and
|
|
140
|
+
* the ordered list of parent tiers whose values this entry narrowed or
|
|
141
|
+
* replaced. Used for fields where children can override parents (attributes,
|
|
142
|
+
* traceability rules, type definitions).
|
|
143
|
+
*/
|
|
144
|
+
export interface ProvenancedMapEntry<V> {
|
|
145
|
+
readonly value: V;
|
|
146
|
+
readonly origin: ProfileId;
|
|
147
|
+
readonly overrides?: readonly ProfileId[];
|
|
148
|
+
}
|
|
149
|
+
/** Map with per-entry provenance. Keys are always strings (attr/type/link names). */
|
|
150
|
+
export type ProvenancedMap<V> = ReadonlyMap<string, ProvenancedMapEntry<V>>;
|
|
151
|
+
/** Shape-scope rules after merging (identified or referenced). */
|
|
152
|
+
export interface EffectiveShapeScope {
|
|
153
|
+
readonly required: ProvenancedValue<readonly string[]>;
|
|
154
|
+
readonly attributes: ProvenancedMap<AttrDecl>;
|
|
155
|
+
/** Referenced scope's traceability is always empty (referenced entries don't originate links). */
|
|
156
|
+
readonly traceability: ProvenancedMap<TraceRule>;
|
|
157
|
+
}
|
|
158
|
+
/** Type-scope rules after merging. */
|
|
159
|
+
export interface EffectiveTypeDef {
|
|
160
|
+
readonly name: string;
|
|
161
|
+
/** Shape is frozen at the type's declaration — never changes across the chain. */
|
|
162
|
+
readonly shape: EntryShape;
|
|
163
|
+
readonly displayIdPattern: ProvenancedValue<string | undefined>;
|
|
164
|
+
readonly displayIdPatternEnforcement: ProvenancedValue<EnforcementMode>;
|
|
165
|
+
/** Resolved semantic color-role name, or `undefined` when unset. */
|
|
166
|
+
readonly color: ProvenancedValue<string | undefined>;
|
|
167
|
+
readonly required: ProvenancedValue<readonly string[]>;
|
|
168
|
+
readonly attributes: ProvenancedMap<AttrDecl>;
|
|
169
|
+
readonly traceability: ProvenancedMap<TraceRule>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The merged, validator-ready view of a profile chain. Every field carries
|
|
173
|
+
* per-rule provenance so a diagnostic can blame the right tier.
|
|
174
|
+
*/
|
|
175
|
+
export interface EffectiveProfile {
|
|
176
|
+
readonly required: ProvenancedValue<readonly string[]>;
|
|
177
|
+
readonly attributes: ProvenancedMap<AttrDecl>;
|
|
178
|
+
readonly labels: ProvenancedValue<readonly string[]>;
|
|
179
|
+
/** Semantic color-role bindings merged across the chain. */
|
|
180
|
+
readonly colors: ProvenancedMap<string>;
|
|
181
|
+
readonly identified: EffectiveShapeScope;
|
|
182
|
+
readonly referenced: EffectiveShapeScope;
|
|
183
|
+
readonly types: ProvenancedMap<EffectiveTypeDef>;
|
|
184
|
+
readonly documents: {
|
|
185
|
+
readonly types: ProvenancedMap<DocTypeDef>;
|
|
186
|
+
readonly frontMatter: ProvenancedMap<AttrDecl>;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/model/profile.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAM3C,mEAAmE;AACnE,eAAO,MAAM,WAAW,qJAed,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAEnD,0DAA0D;AAC1D,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,SAAS,CAGlD,CAAC;AAMH,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAMD,kEAAkE;AAClE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,6DAA6D;AAC7D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAA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Q,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE;QAClB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;QAC3C,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;KAChD,CAAC;CACH"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module model/profile
|
|
4
|
+
*
|
|
5
|
+
* Profile data model — TypeScript types that mirror ADR-008 §4 manifest
|
|
6
|
+
* schema. Used by the profile loader, merger, and validator.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LIST_VALUE_TYPES = exports.VALUE_TYPES = void 0;
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Value types (ADR-002 Annex C)
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
/** All 14 attribute value-type keywords recognized by the core. */
|
|
14
|
+
exports.VALUE_TYPES = [
|
|
15
|
+
"id",
|
|
16
|
+
"id-list",
|
|
17
|
+
"uri",
|
|
18
|
+
"url",
|
|
19
|
+
"path",
|
|
20
|
+
"path-or-id",
|
|
21
|
+
"enum",
|
|
22
|
+
"tag-list",
|
|
23
|
+
"text",
|
|
24
|
+
"citation",
|
|
25
|
+
"external-id",
|
|
26
|
+
"integer",
|
|
27
|
+
"date",
|
|
28
|
+
"boolean",
|
|
29
|
+
];
|
|
30
|
+
/** Types whose default cardinality is a list (`0..N`). */
|
|
31
|
+
exports.LIST_VALUE_TYPES = new Set([
|
|
32
|
+
"id-list",
|
|
33
|
+
"tag-list",
|
|
34
|
+
]);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/attributes
|
|
3
|
+
*
|
|
4
|
+
* Parses `Key: Value` attribute blocks from entry bodies.
|
|
5
|
+
* Handles trailing backslash separators and distinguishes
|
|
6
|
+
* trailing attribute blocks from body prose.
|
|
7
|
+
*/
|
|
8
|
+
import type { Attribute, TypedAttributes } from "../model/mod.js";
|
|
9
|
+
/**
|
|
10
|
+
* Parse an array of attribute lines into Attribute objects.
|
|
11
|
+
*
|
|
12
|
+
* Each line is expected to be in `Key: Value` format, with optional
|
|
13
|
+
* trailing backslash (`\`) as a continuation marker. Lines that do
|
|
14
|
+
* not match the pattern are silently skipped.
|
|
15
|
+
*
|
|
16
|
+
* @param lines - Raw attribute lines (already separated from body)
|
|
17
|
+
* @returns Parsed attributes
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseAttributes(lines: readonly string[]): Attribute[];
|
|
20
|
+
/**
|
|
21
|
+
* Pattern matching a `Key: Value` line (with or without trailing backslash).
|
|
22
|
+
* Used to detect attribute blocks at the end of entry bodies.
|
|
23
|
+
*/
|
|
24
|
+
export declare const ATTR_LINE_RE: RegExp;
|
|
25
|
+
/**
|
|
26
|
+
* Collate a flat list of parsed attributes into a typed, keyed map per
|
|
27
|
+
* ADR-002 §2.6.
|
|
28
|
+
*
|
|
29
|
+
* - Repeatable types (`id-list` / `tag-list` / `external-id`): multi-line
|
|
30
|
+
* entries merge; CSV values on a single line split on `,`.
|
|
31
|
+
* - `citation`: multi-line only (locators may contain commas).
|
|
32
|
+
* - Single-valued types: all occurrences are preserved in-order; the
|
|
33
|
+
* validator decides what to do about duplicates.
|
|
34
|
+
* - Unknown keys: preserved as-is, one entry per occurrence.
|
|
35
|
+
*/
|
|
36
|
+
export declare function collateAttributes(attributes: readonly Attribute[]): TypedAttributes;
|
|
37
|
+
/**
|
|
38
|
+
* Split raw entry content into body text and attribute lines.
|
|
39
|
+
*
|
|
40
|
+
* Attributes are `Key: Value` lines at the **end** of the entry content,
|
|
41
|
+
* forming a contiguous block. A `Key: Value` line in the middle of body
|
|
42
|
+
* prose is NOT treated as an attribute — only the trailing block counts.
|
|
43
|
+
*
|
|
44
|
+
* @param content - Raw text content of an entry (after title line, indentation stripped)
|
|
45
|
+
* @returns Tuple of [body, attributeLines]
|
|
46
|
+
*/
|
|
47
|
+
export declare function splitBodyAndAttributes(content: string): [string, string[]];
|
|
48
|
+
//# sourceMappingURL=attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/parser/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAUlE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,CAiBrE;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,QAA6B,CAAC;AAYvD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,eAAe,CA6BjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,GACd,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CA+BpB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module parser/attributes
|
|
4
|
+
*
|
|
5
|
+
* Parses `Key: Value` attribute blocks from entry bodies.
|
|
6
|
+
* Handles trailing backslash separators and distinguishes
|
|
7
|
+
* trailing attribute blocks from body prose.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ATTR_LINE_RE = void 0;
|
|
11
|
+
exports.parseAttributes = parseAttributes;
|
|
12
|
+
exports.collateAttributes = collateAttributes;
|
|
13
|
+
exports.splitBodyAndAttributes = splitBodyAndAttributes;
|
|
14
|
+
const attributes_js_1 = require("../model/attributes.js");
|
|
15
|
+
/**
|
|
16
|
+
* Pattern matching a `Key: Value` attribute line.
|
|
17
|
+
* Key must start with an uppercase letter, may contain lowercase letters and hyphens.
|
|
18
|
+
* Value is everything after `: `, with optional trailing backslash stripped.
|
|
19
|
+
*/
|
|
20
|
+
const ATTRIBUTE_RE = /^([A-Z][A-Za-z-]*): (.+?)\\?$/;
|
|
21
|
+
/**
|
|
22
|
+
* Parse an array of attribute lines into Attribute objects.
|
|
23
|
+
*
|
|
24
|
+
* Each line is expected to be in `Key: Value` format, with optional
|
|
25
|
+
* trailing backslash (`\`) as a continuation marker. Lines that do
|
|
26
|
+
* not match the pattern are silently skipped.
|
|
27
|
+
*
|
|
28
|
+
* @param lines - Raw attribute lines (already separated from body)
|
|
29
|
+
* @returns Parsed attributes
|
|
30
|
+
*/
|
|
31
|
+
function parseAttributes(lines) {
|
|
32
|
+
const attributes = [];
|
|
33
|
+
for (const line of lines) {
|
|
34
|
+
const trimmed = line.trim();
|
|
35
|
+
if (!trimmed)
|
|
36
|
+
continue;
|
|
37
|
+
const match = ATTRIBUTE_RE.exec(trimmed);
|
|
38
|
+
if (match) {
|
|
39
|
+
attributes.push({
|
|
40
|
+
key: match[1],
|
|
41
|
+
value: match[2].trim(),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return attributes;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Pattern matching a `Key: Value` line (with or without trailing backslash).
|
|
49
|
+
* Used to detect attribute blocks at the end of entry bodies.
|
|
50
|
+
*/
|
|
51
|
+
exports.ATTR_LINE_RE = /^[A-Z][A-Za-z-]*: .+\\?$/;
|
|
52
|
+
/**
|
|
53
|
+
* Types whose values may be CSV-split on input per ADR-002 §2.6.
|
|
54
|
+
* `citation` is deliberately excluded because locators may contain commas.
|
|
55
|
+
*/
|
|
56
|
+
const CSV_SPLITTABLE_TYPES = new Set([
|
|
57
|
+
"id-list",
|
|
58
|
+
"tag-list",
|
|
59
|
+
"external-id",
|
|
60
|
+
]);
|
|
61
|
+
/**
|
|
62
|
+
* Collate a flat list of parsed attributes into a typed, keyed map per
|
|
63
|
+
* ADR-002 §2.6.
|
|
64
|
+
*
|
|
65
|
+
* - Repeatable types (`id-list` / `tag-list` / `external-id`): multi-line
|
|
66
|
+
* entries merge; CSV values on a single line split on `,`.
|
|
67
|
+
* - `citation`: multi-line only (locators may contain commas).
|
|
68
|
+
* - Single-valued types: all occurrences are preserved in-order; the
|
|
69
|
+
* validator decides what to do about duplicates.
|
|
70
|
+
* - Unknown keys: preserved as-is, one entry per occurrence.
|
|
71
|
+
*/
|
|
72
|
+
function collateAttributes(attributes) {
|
|
73
|
+
const map = new Map();
|
|
74
|
+
for (const attr of attributes) {
|
|
75
|
+
const spec = (0, attributes_js_1.attributeSpec)(attr.key);
|
|
76
|
+
const type = spec?.type;
|
|
77
|
+
let values;
|
|
78
|
+
if (type && CSV_SPLITTABLE_TYPES.has(type) && attr.value.includes(",")) {
|
|
79
|
+
values = attr.value
|
|
80
|
+
.split(",")
|
|
81
|
+
.map((s) => s.trim())
|
|
82
|
+
.filter((s) => s.length > 0);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
values = [attr.value];
|
|
86
|
+
}
|
|
87
|
+
const existing = map.get(attr.key);
|
|
88
|
+
if (existing) {
|
|
89
|
+
existing.push(...values);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
map.set(attr.key, values);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Freeze value arrays to match the readonly contract.
|
|
96
|
+
return new Map(Array.from(map, ([key, values]) => [key, Object.freeze([...values])]));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Split raw entry content into body text and attribute lines.
|
|
100
|
+
*
|
|
101
|
+
* Attributes are `Key: Value` lines at the **end** of the entry content,
|
|
102
|
+
* forming a contiguous block. A `Key: Value` line in the middle of body
|
|
103
|
+
* prose is NOT treated as an attribute — only the trailing block counts.
|
|
104
|
+
*
|
|
105
|
+
* @param content - Raw text content of an entry (after title line, indentation stripped)
|
|
106
|
+
* @returns Tuple of [body, attributeLines]
|
|
107
|
+
*/
|
|
108
|
+
function splitBodyAndAttributes(content) {
|
|
109
|
+
const lines = content.split("\n");
|
|
110
|
+
// Walk backwards to find the contiguous trailing attribute block
|
|
111
|
+
let attrStart = lines.length;
|
|
112
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
113
|
+
const trimmed = lines[i].trim();
|
|
114
|
+
if (trimmed === "") {
|
|
115
|
+
// Empty line: if we haven't started collecting attributes, skip.
|
|
116
|
+
// If we have attributes below, this blank line is the boundary.
|
|
117
|
+
if (attrStart < lines.length)
|
|
118
|
+
break;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (exports.ATTR_LINE_RE.test(trimmed)) {
|
|
122
|
+
attrStart = i;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// Non-attribute, non-empty line — stop scanning
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const bodyLines = lines.slice(0, attrStart);
|
|
130
|
+
const attrLines = lines.slice(attrStart);
|
|
131
|
+
// Trim trailing empty lines from body
|
|
132
|
+
const body = bodyLines.join("\n").replace(/\n+$/, "");
|
|
133
|
+
const filteredAttrLines = attrLines
|
|
134
|
+
.map((l) => l.trim())
|
|
135
|
+
.filter((l) => l !== "");
|
|
136
|
+
return [body, filteredAttrLines];
|
|
137
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/captions
|
|
3
|
+
*
|
|
4
|
+
* Detects table and figure captions in Markdown documents.
|
|
5
|
+
*
|
|
6
|
+
* Caption patterns:
|
|
7
|
+
* - **Table**: `_Table: text_` paragraph immediately followed by a `table` sibling.
|
|
8
|
+
* - **Figure**: `image` node followed by `_Figure: text_` paragraph.
|
|
9
|
+
* - **Figure fallback**: `image` with non-empty alt text and no explicit caption.
|
|
10
|
+
*/
|
|
11
|
+
import type { Caption } from "../model/mod.js";
|
|
12
|
+
/** Options for {@linkcode detectCaptions}. */
|
|
13
|
+
export interface DetectCaptionsOptions {
|
|
14
|
+
/** File path used in source locations. */
|
|
15
|
+
readonly file?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Detect table and figure captions in a Markdown string.
|
|
19
|
+
*
|
|
20
|
+
* @param markdown - Markdown source text
|
|
21
|
+
* @param options - Detection options (file path for source locations)
|
|
22
|
+
* @returns Array of detected captions
|
|
23
|
+
*/
|
|
24
|
+
export declare function detectCaptions(markdown: string, options?: DetectCaptionsOptions): Caption[];
|
|
25
|
+
//# sourceMappingURL=captions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captions.d.ts","sourceRoot":"","sources":["../../src/parser/captions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,8CAA8C;AAC9C,MAAM,WAAW,qBAAqB;IACpC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAiED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,EAAE,CAiFX"}
|