@driftsys/markspec 0.2.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/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 +7 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +61 -14
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +20 -1
- 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 +4 -0
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +27 -16
- package/esm/formatter/mod.d.ts +12 -2
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +130 -22
- package/esm/mod.d.ts +10 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +5 -2
- 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 +255 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +27 -1
- 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 +13 -1
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +47 -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.js +11 -2
- package/esm/parser/markdown.d.ts +11 -4
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +85 -38
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +39 -9
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +20 -13
- 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.js +14 -27
- 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 +27 -6
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +132 -124
- 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 +1 -1
- 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 +7 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +62 -14
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +20 -1
- 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 +4 -0
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +28 -16
- package/script/formatter/mod.d.ts +12 -2
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +131 -22
- package/script/mod.d.ts +10 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +48 -19
- 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 +255 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +34 -2
- 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 +13 -1
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +48 -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.js +11 -2
- package/script/parser/markdown.d.ts +11 -4
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +84 -37
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +41 -10
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +20 -13
- 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.js +14 -27
- 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 +27 -6
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +145 -123
- 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,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/merge
|
|
3
|
+
*
|
|
4
|
+
* Fold a {@linkcode ProfileChain} into a single {@linkcode EffectiveProfile},
|
|
5
|
+
* applying additive, tightening, and subset merge rules across tiers
|
|
6
|
+
* (root → leaf). Violations surface as `PROFILE-MERGE-*` diagnostics.
|
|
7
|
+
*
|
|
8
|
+
* Merge happens once at load. Callers should not call `mergeChain` lazily.
|
|
9
|
+
*/
|
|
10
|
+
import type { Diagnostic, EffectiveProfile, ProfileChain } from "../model/mod.js";
|
|
11
|
+
/** Result of merging a {@linkcode ProfileChain}. */
|
|
12
|
+
export interface MergeResult {
|
|
13
|
+
/** The merged profile, or `null` when any merge constraint was violated. */
|
|
14
|
+
readonly effective: EffectiveProfile | null;
|
|
15
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Merge all tiers of a chain into one EffectiveProfile. Tiers are processed
|
|
19
|
+
* in root → leaf order; later tiers can add to or tighten earlier tiers'
|
|
20
|
+
* rules. Returns `{ effective: null }` if any tier relaxes an ancestor.
|
|
21
|
+
*
|
|
22
|
+
* Task 3.4: additive merge (union across tiers). Tasks 3.5–3.7 extend this
|
|
23
|
+
* with tightening and subset rules.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mergeChain(chain: ProfileChain): MergeResult;
|
|
26
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/profile/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,UAAU,EAEV,gBAAgB,EAIhB,YAAY,EASb,MAAM,iBAAiB,CAAC;AAEzB,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CA8C3D"}
|
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/profile/merge
|
|
4
|
+
*
|
|
5
|
+
* Fold a {@linkcode ProfileChain} into a single {@linkcode EffectiveProfile},
|
|
6
|
+
* applying additive, tightening, and subset merge rules across tiers
|
|
7
|
+
* (root → leaf). Violations surface as `PROFILE-MERGE-*` diagnostics.
|
|
8
|
+
*
|
|
9
|
+
* Merge happens once at load. Callers should not call `mergeChain` lazily.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.mergeChain = mergeChain;
|
|
13
|
+
/**
|
|
14
|
+
* Merge all tiers of a chain into one EffectiveProfile. Tiers are processed
|
|
15
|
+
* in root → leaf order; later tiers can add to or tighten earlier tiers'
|
|
16
|
+
* rules. Returns `{ effective: null }` if any tier relaxes an ancestor.
|
|
17
|
+
*
|
|
18
|
+
* Task 3.4: additive merge (union across tiers). Tasks 3.5–3.7 extend this
|
|
19
|
+
* with tightening and subset rules.
|
|
20
|
+
*/
|
|
21
|
+
function mergeChain(chain) {
|
|
22
|
+
const diagnostics = [];
|
|
23
|
+
const tiers = chain.tiers;
|
|
24
|
+
if (tiers.length === 0) {
|
|
25
|
+
return {
|
|
26
|
+
effective: null,
|
|
27
|
+
diagnostics: [
|
|
28
|
+
{
|
|
29
|
+
code: "PROFILE-MERGE-001",
|
|
30
|
+
severity: "error",
|
|
31
|
+
message: "cannot merge an empty profile chain",
|
|
32
|
+
location: { file: "<chain>", line: 1, column: 1 },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// TODO(Phase 5): §3.3 cross-scope layering within one profile.
|
|
38
|
+
// The spec requires that tightening rules apply across scopes within a
|
|
39
|
+
// single tier (profile.required ⊂ shape.required ⊂ type.required etc.).
|
|
40
|
+
// Phase 3 implements cross-tier merging only; within-tier scope coherence
|
|
41
|
+
// is deferred to the validator pipeline which sees the final EffectiveProfile.
|
|
42
|
+
// When Phase 5 lands the validator, add a check here (or in a separate
|
|
43
|
+
// validateScopeLayering helper) to catch a profile whose type-scope
|
|
44
|
+
// required is narrower than its shape-scope required, for example.
|
|
45
|
+
// Start from root, fold each subsequent tier.
|
|
46
|
+
let effective = seedFromTier(tiers[0]);
|
|
47
|
+
for (let i = 1; i < tiers.length; i++) {
|
|
48
|
+
effective = foldTier(effective, tiers[i], diagnostics);
|
|
49
|
+
}
|
|
50
|
+
// Validate per-type color references against the FINAL merged colors map.
|
|
51
|
+
// Running this only after all tiers fold avoids false positives when a parent
|
|
52
|
+
// tier references a color that a child tier supplies in its colors: block.
|
|
53
|
+
validateTypeColors(effective, diagnostics, tiers[tiers.length - 1].sourcePath);
|
|
54
|
+
// If any merge error was recorded, drop the effective profile.
|
|
55
|
+
const hasError = diagnostics.some((d) => d.severity === "error");
|
|
56
|
+
return hasError
|
|
57
|
+
? { effective: null, diagnostics }
|
|
58
|
+
: { effective, diagnostics };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Apply a child tier's additions on top of the current accumulated
|
|
62
|
+
* EffectiveProfile. Task 3.4 implements additive only; Tasks 3.5–3.7 extend
|
|
63
|
+
* this with tightening and subset checks.
|
|
64
|
+
*/
|
|
65
|
+
function foldTier(base, tier, diagnostics) {
|
|
66
|
+
const origin = tier.id;
|
|
67
|
+
const m = tier.manifest;
|
|
68
|
+
// Universal additive.
|
|
69
|
+
const required = unionList(base.required, m.universalRequired, origin);
|
|
70
|
+
const labels = unionList(base.labels, m.labels, origin);
|
|
71
|
+
const attributes = unionAttrMap(base.attributes, m.universalAttributes, origin, diagnostics);
|
|
72
|
+
// Colors map: last-write-wins per key, additive across tiers.
|
|
73
|
+
const colors = unionColorsMap(base.colors, m.colors, origin);
|
|
74
|
+
// Shape scopes — same additive pattern.
|
|
75
|
+
const identified = {
|
|
76
|
+
required: unionList(base.identified.required, m.identified.required, origin),
|
|
77
|
+
attributes: unionAttrMap(base.identified.attributes, m.identified.attributes, origin, diagnostics),
|
|
78
|
+
traceability: unionTraceMap(base.identified.traceability, m.identified.traceability, origin, diagnostics),
|
|
79
|
+
};
|
|
80
|
+
const referenced = {
|
|
81
|
+
required: unionList(base.referenced.required, m.referenced.required, origin),
|
|
82
|
+
attributes: unionAttrMap(base.referenced.attributes, m.referenced.attributes, origin, diagnostics),
|
|
83
|
+
traceability: base.referenced.traceability, // always empty
|
|
84
|
+
};
|
|
85
|
+
// Types — add new types, fold existing ones.
|
|
86
|
+
const types = new Map(base.types);
|
|
87
|
+
for (const [name, td] of m.types) {
|
|
88
|
+
const existing = types.get(name);
|
|
89
|
+
if (!existing) {
|
|
90
|
+
// Fresh type contributed by this tier.
|
|
91
|
+
const eff = {
|
|
92
|
+
name,
|
|
93
|
+
shape: td.shape,
|
|
94
|
+
displayIdPattern: { value: td.displayIdPattern, origin },
|
|
95
|
+
displayIdPatternEnforcement: {
|
|
96
|
+
value: td.displayIdPatternEnforcement,
|
|
97
|
+
origin,
|
|
98
|
+
},
|
|
99
|
+
color: { value: td.color, origin },
|
|
100
|
+
required: { value: td.required, origin },
|
|
101
|
+
attributes: mapFromAttrList(td.attributes, origin),
|
|
102
|
+
traceability: mapFromTrace(td.traceability, origin),
|
|
103
|
+
};
|
|
104
|
+
types.set(name, { value: eff, origin });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const tightened = tightenType(existing, td, origin, diagnostics);
|
|
108
|
+
if (tightened) {
|
|
109
|
+
types.set(name, tightened);
|
|
110
|
+
}
|
|
111
|
+
// If tightening failed, parent entry is kept (diagnostics already pushed).
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Documents — add new doc types + frontMatter.
|
|
115
|
+
const docTypes = new Map(base.documents.types);
|
|
116
|
+
for (const dt of m.documents.types) {
|
|
117
|
+
if (!docTypes.has(dt.id)) {
|
|
118
|
+
docTypes.set(dt.id, { value: dt, origin });
|
|
119
|
+
}
|
|
120
|
+
// Overlap handling deferred.
|
|
121
|
+
}
|
|
122
|
+
const frontMatter = unionAttrMap(base.documents.frontMatter, m.documents.frontMatter, origin, diagnostics);
|
|
123
|
+
const result = {
|
|
124
|
+
required,
|
|
125
|
+
attributes,
|
|
126
|
+
labels,
|
|
127
|
+
colors,
|
|
128
|
+
identified,
|
|
129
|
+
referenced,
|
|
130
|
+
types,
|
|
131
|
+
documents: {
|
|
132
|
+
types: docTypes,
|
|
133
|
+
frontMatter,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
// Additive merge primitives
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
/**
|
|
142
|
+
* Union of color maps: last-write-wins per key, additive across tiers.
|
|
143
|
+
* Each redefinition in a child tier overrides the parent's binding for that
|
|
144
|
+
* key while preserving the override history for provenance.
|
|
145
|
+
*/
|
|
146
|
+
function unionColorsMap(parent, childColors, childOrigin) {
|
|
147
|
+
if (childColors.size === 0) {
|
|
148
|
+
return parent;
|
|
149
|
+
}
|
|
150
|
+
const out = new Map(parent);
|
|
151
|
+
for (const [name, hue] of childColors) {
|
|
152
|
+
const prior = out.get(name);
|
|
153
|
+
out.set(name, {
|
|
154
|
+
value: hue,
|
|
155
|
+
origin: childOrigin,
|
|
156
|
+
overrides: prior ? [...(prior.overrides ?? []), prior.origin] : undefined,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Validate per-type `color:` references resolve to a name declared in the
|
|
163
|
+
* effective `colors:` map. Emits MSL-PROFILE-COLOR-003 for unknown names.
|
|
164
|
+
* Validation runs against the FINAL effective type entry (after all tiers
|
|
165
|
+
* have folded), so only the latest tier's color choice is checked.
|
|
166
|
+
*/
|
|
167
|
+
function validateTypeColors(effective, diagnostics, fallbackFile) {
|
|
168
|
+
for (const [typeName, entry] of effective.types) {
|
|
169
|
+
const colorName = entry.value.color.value;
|
|
170
|
+
if (colorName === undefined)
|
|
171
|
+
continue;
|
|
172
|
+
if (!effective.colors.has(colorName)) {
|
|
173
|
+
diagnostics.push({
|
|
174
|
+
code: "MSL-PROFILE-COLOR-003",
|
|
175
|
+
severity: "error",
|
|
176
|
+
message: `type '${typeName}' references unknown color '${colorName}' (not declared in profile.colors of this profile or any parent)`,
|
|
177
|
+
location: { file: fallbackFile, line: 1, column: 1 },
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Union of two string lists; parent entries first, child entries appended,
|
|
184
|
+
* duplicates dropped. Origin = child tier if anything was added, else parent.
|
|
185
|
+
*/
|
|
186
|
+
function unionList(parent, childList, childOrigin) {
|
|
187
|
+
if (childList.length === 0) {
|
|
188
|
+
return parent;
|
|
189
|
+
}
|
|
190
|
+
const seen = new Set(parent.value);
|
|
191
|
+
const merged = [...parent.value];
|
|
192
|
+
let anyAdded = false;
|
|
193
|
+
for (const s of childList) {
|
|
194
|
+
if (!seen.has(s)) {
|
|
195
|
+
merged.push(s);
|
|
196
|
+
seen.add(s);
|
|
197
|
+
anyAdded = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return anyAdded ? { value: merged, origin: childOrigin } : parent;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Union of attribute maps. When the child redeclares an attribute the parent
|
|
204
|
+
* already declared, the child's declaration must not relax the parent's
|
|
205
|
+
* constraints (Task 3.5). Narrowing is allowed; relaxation records a
|
|
206
|
+
* PROFILE-MERGE-001 diagnostic and keeps the parent entry so downstream code
|
|
207
|
+
* still sees a valid attribute.
|
|
208
|
+
*/
|
|
209
|
+
function unionAttrMap(parent, childAttrs, childOrigin, diagnostics) {
|
|
210
|
+
const out = new Map(parent);
|
|
211
|
+
for (const a of childAttrs) {
|
|
212
|
+
const existing = out.get(a.name);
|
|
213
|
+
if (!existing) {
|
|
214
|
+
out.set(a.name, { value: a, origin: childOrigin });
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const tightened = tightenAttr(existing, a, childOrigin, diagnostics);
|
|
218
|
+
if (tightened) {
|
|
219
|
+
out.set(a.name, tightened);
|
|
220
|
+
}
|
|
221
|
+
// If tightening failed (returned undefined), diagnostics were recorded;
|
|
222
|
+
// keep the parent entry so downstream code still sees a valid attribute.
|
|
223
|
+
}
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Tighten a parent attribute declaration with a child's redeclaration.
|
|
228
|
+
* Returns the new effective entry on success, or `undefined` if the child
|
|
229
|
+
* relaxes (caller records PROFILE-MERGE-001).
|
|
230
|
+
*/
|
|
231
|
+
function tightenAttr(existing, child, childOrigin, diagnostics) {
|
|
232
|
+
const parent = existing.value;
|
|
233
|
+
// Value-type must match exactly.
|
|
234
|
+
if (parent.type !== child.type) {
|
|
235
|
+
diagnostics.push(mergeRelaxation(`attribute '${parent.name}'`, "type", `${parent.type} (${existing.origin})`, `${child.type} (${childOrigin})`));
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
// Cardinality: child lower ≥ parent lower AND child upper ≤ parent upper.
|
|
239
|
+
if (child.cardinality.lower < parent.cardinality.lower) {
|
|
240
|
+
diagnostics.push(mergeRelaxation(`attribute '${parent.name}'`, "cardinality.lower", `${parent.cardinality.lower} (${existing.origin})`, `${child.cardinality.lower} (${childOrigin})`));
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
if (child.cardinality.upper > parent.cardinality.upper) {
|
|
244
|
+
diagnostics.push(mergeRelaxation(`attribute '${parent.name}'`, "cardinality.upper", `${formatUpper(parent.cardinality.upper)} (${existing.origin})`, `${formatUpper(child.cardinality.upper)} (${childOrigin})`));
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
// Required flag: once required, cannot be un-required.
|
|
248
|
+
if (parent.required === true && child.required === false) {
|
|
249
|
+
diagnostics.push(mergeRelaxation(`attribute '${parent.name}'`, "required", `true (${existing.origin})`, `false (${childOrigin})`));
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
// Enum: child.values must be a subset of parent.values.
|
|
253
|
+
if (parent.type === "enum") {
|
|
254
|
+
const parentSet = new Set(parent.values ?? []);
|
|
255
|
+
const childValues = child.values ?? [];
|
|
256
|
+
for (const v of childValues) {
|
|
257
|
+
if (!parentSet.has(v)) {
|
|
258
|
+
diagnostics.push(mergeRelaxation(`attribute '${parent.name}'`, "enum values", `[${[...parentSet].join(",")}] (${existing.origin})`, `added '${v}' (${childOrigin})`));
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Build the tightened value (field-by-field, child wins on narrower bounds).
|
|
264
|
+
const merged = {
|
|
265
|
+
name: parent.name,
|
|
266
|
+
type: parent.type,
|
|
267
|
+
required: parent.required || child.required,
|
|
268
|
+
cardinality: child.cardinality,
|
|
269
|
+
values: parent.type === "enum" ? child.values : parent.values,
|
|
270
|
+
inverse: child.inverse ?? parent.inverse,
|
|
271
|
+
};
|
|
272
|
+
const overrides = [
|
|
273
|
+
...(existing.overrides ?? []),
|
|
274
|
+
existing.origin,
|
|
275
|
+
];
|
|
276
|
+
return { value: merged, origin: childOrigin, overrides };
|
|
277
|
+
}
|
|
278
|
+
const ENFORCEMENT_ORDER = { off: 0, warn: 1, error: 2 };
|
|
279
|
+
/**
|
|
280
|
+
* Tighten a parent type declaration with a child's redeclaration. Returns the
|
|
281
|
+
* new effective entry on success, or `undefined` if the child relaxes (caller
|
|
282
|
+
* keeps the parent entry; diagnostics already recorded).
|
|
283
|
+
*/
|
|
284
|
+
function tightenType(existing, child, childOrigin, diagnostics) {
|
|
285
|
+
const name = child.name;
|
|
286
|
+
const effExisting = existing.value;
|
|
287
|
+
// Shape must match.
|
|
288
|
+
if (effExisting.shape !== child.shape) {
|
|
289
|
+
diagnostics.push(mergeRelaxation(`type '${name}'`, "shape", `${effExisting.shape} (${existing.origin})`, `${child.shape} (${childOrigin})`));
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
// Display-ID pattern: if parent set one, child cannot change it. If parent
|
|
293
|
+
// had none, child may set it.
|
|
294
|
+
let displayIdPattern = effExisting.displayIdPattern;
|
|
295
|
+
if (child.displayIdPattern !== undefined) {
|
|
296
|
+
if (effExisting.displayIdPattern.value !== undefined &&
|
|
297
|
+
effExisting.displayIdPattern.value !== child.displayIdPattern) {
|
|
298
|
+
diagnostics.push(mergeRelaxation(`type '${name}'`, "display-id-pattern", `'${effExisting.displayIdPattern.value}' (${effExisting.displayIdPattern.origin})`, `'${child.displayIdPattern}' (${childOrigin})`));
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
if (effExisting.displayIdPattern.value === undefined) {
|
|
302
|
+
// Parent had no pattern — child contributes it.
|
|
303
|
+
displayIdPattern = { value: child.displayIdPattern, origin: childOrigin };
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// Enforcement — tighten only (off < warn < error).
|
|
307
|
+
let enforcement = effExisting.displayIdPatternEnforcement;
|
|
308
|
+
if (child.displayIdPatternEnforcement !== enforcement.value) {
|
|
309
|
+
const parentLevel = ENFORCEMENT_ORDER[enforcement.value];
|
|
310
|
+
const childLevel = ENFORCEMENT_ORDER[child.displayIdPatternEnforcement];
|
|
311
|
+
if (childLevel < parentLevel) {
|
|
312
|
+
diagnostics.push(mergeRelaxation(`type '${name}'`, "display-id-pattern-enforcement", `${enforcement.value} (${enforcement.origin})`, `${child.displayIdPatternEnforcement} (${childOrigin})`));
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
enforcement = {
|
|
316
|
+
value: child.displayIdPatternEnforcement,
|
|
317
|
+
origin: childOrigin,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
// Fold child's attributes + traceability + required (same additive/tightening
|
|
321
|
+
// primitives as the existing fold).
|
|
322
|
+
const attributes = unionAttrMap(effExisting.attributes, child.attributes, childOrigin, diagnostics);
|
|
323
|
+
const traceability = unionTraceMap(effExisting.traceability, child.traceability, childOrigin, diagnostics);
|
|
324
|
+
const required = unionList(effExisting.required, child.required, childOrigin);
|
|
325
|
+
// Color: child overrides parent when set; otherwise parent's color stays.
|
|
326
|
+
const color = child.color !== undefined
|
|
327
|
+
? { value: child.color, origin: childOrigin }
|
|
328
|
+
: effExisting.color;
|
|
329
|
+
const merged = {
|
|
330
|
+
name,
|
|
331
|
+
shape: effExisting.shape,
|
|
332
|
+
displayIdPattern,
|
|
333
|
+
displayIdPatternEnforcement: enforcement,
|
|
334
|
+
color,
|
|
335
|
+
required,
|
|
336
|
+
attributes,
|
|
337
|
+
traceability,
|
|
338
|
+
};
|
|
339
|
+
const overrides = [
|
|
340
|
+
...(existing.overrides ?? []),
|
|
341
|
+
existing.origin,
|
|
342
|
+
];
|
|
343
|
+
return { value: merged, origin: childOrigin, overrides };
|
|
344
|
+
}
|
|
345
|
+
function mergeRelaxation(subject, field, parentView, childView) {
|
|
346
|
+
return {
|
|
347
|
+
code: "PROFILE-MERGE-001",
|
|
348
|
+
severity: "error",
|
|
349
|
+
message: `${subject}: field '${field}' relaxed by child (parent: ${parentView}, child: ${childView})`,
|
|
350
|
+
location: { file: "<merge>", line: 1, column: 1 },
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function formatUpper(u) {
|
|
354
|
+
return u === Infinity ? "N" : String(u);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Union of traceability rule maps, same pattern as attributes.
|
|
358
|
+
*/
|
|
359
|
+
function unionTraceMap(parent, childTrace, childOrigin, diagnostics) {
|
|
360
|
+
const out = new Map(parent);
|
|
361
|
+
for (const [name, rule] of childTrace) {
|
|
362
|
+
const existing = out.get(name);
|
|
363
|
+
if (!existing) {
|
|
364
|
+
out.set(name, { value: rule, origin: childOrigin });
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const tightened = tightenTraceRule(existing, name, rule, childOrigin, diagnostics);
|
|
368
|
+
if (tightened) {
|
|
369
|
+
out.set(name, tightened);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return out;
|
|
373
|
+
}
|
|
374
|
+
function tightenTraceRule(existing, linkName, child, childOrigin, diagnostics) {
|
|
375
|
+
const parent = existing.value;
|
|
376
|
+
// Subset check: every child target must be covered by some parent target.
|
|
377
|
+
for (const ct of child.target) {
|
|
378
|
+
if (!targetCoveredBy(ct, parent.target)) {
|
|
379
|
+
diagnostics.push({
|
|
380
|
+
code: "PROFILE-MERGE-002",
|
|
381
|
+
severity: "error",
|
|
382
|
+
message: `traceability '${linkName}': child target ${stringifyMatcher(ct)} not covered by parent target [${parent.target.map(stringifyMatcher).join(", ")}] (${existing.origin} vs ${childOrigin})`,
|
|
383
|
+
location: { file: "<merge>", line: 1, column: 1 },
|
|
384
|
+
});
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
// Cardinality tightening (same rule as attribute cardinality).
|
|
389
|
+
let cardinality = parent.cardinality;
|
|
390
|
+
if (child.cardinality !== undefined) {
|
|
391
|
+
const parentCard = parent.cardinality ?? { lower: 0, upper: Infinity };
|
|
392
|
+
if (child.cardinality.lower < parentCard.lower) {
|
|
393
|
+
diagnostics.push(mergeRelaxation(`traceability '${linkName}'`, "cardinality.lower", `${parentCard.lower} (${existing.origin})`, `${child.cardinality.lower} (${childOrigin})`));
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
if (child.cardinality.upper > parentCard.upper) {
|
|
397
|
+
diagnostics.push(mergeRelaxation(`traceability '${linkName}'`, "cardinality.upper", `${formatUpper(parentCard.upper)} (${existing.origin})`, `${formatUpper(child.cardinality.upper)} (${childOrigin})`));
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
cardinality = child.cardinality;
|
|
401
|
+
}
|
|
402
|
+
// Required flag: once required, cannot be un-required.
|
|
403
|
+
if (parent.required === true && child.required === false) {
|
|
404
|
+
diagnostics.push(mergeRelaxation(`traceability '${linkName}'`, "required", `true (${existing.origin})`, `false (${childOrigin})`));
|
|
405
|
+
return undefined;
|
|
406
|
+
}
|
|
407
|
+
const merged = {
|
|
408
|
+
target: child.target, // already proven to be a subset
|
|
409
|
+
cardinality,
|
|
410
|
+
required: parent.required || child.required,
|
|
411
|
+
};
|
|
412
|
+
const overrides = [
|
|
413
|
+
...(existing.overrides ?? []),
|
|
414
|
+
existing.origin,
|
|
415
|
+
];
|
|
416
|
+
return { value: merged, origin: childOrigin, overrides };
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* True when a child target matcher is covered by the parent's target list.
|
|
420
|
+
* - Type-name child covered by identical type-name in parent OR by ANY shape
|
|
421
|
+
* matcher in parent.
|
|
422
|
+
* - Shape-matcher child covered only by identical shape matcher in parent.
|
|
423
|
+
*/
|
|
424
|
+
function targetCoveredBy(child, parentList) {
|
|
425
|
+
if (typeof child === "string") {
|
|
426
|
+
for (const p of parentList) {
|
|
427
|
+
if (typeof p === "string" && p === child)
|
|
428
|
+
return true;
|
|
429
|
+
if (typeof p !== "string")
|
|
430
|
+
return true; // any shape matcher covers type names
|
|
431
|
+
}
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
for (const p of parentList) {
|
|
435
|
+
if (typeof p !== "string" && p.shape === child.shape)
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
function stringifyMatcher(m) {
|
|
441
|
+
return typeof m === "string" ? m : `{shape: ${m.shape}}`;
|
|
442
|
+
}
|
|
443
|
+
// ---------------------------------------------------------------------------
|
|
444
|
+
// Helpers: construct an EffectiveProfile from a single tier's manifest.
|
|
445
|
+
// ---------------------------------------------------------------------------
|
|
446
|
+
function seedFromTier(tier) {
|
|
447
|
+
const origin = tier.id;
|
|
448
|
+
const m = tier.manifest;
|
|
449
|
+
return {
|
|
450
|
+
required: { value: m.universalRequired, origin },
|
|
451
|
+
attributes: mapFromAttrList(m.universalAttributes, origin),
|
|
452
|
+
labels: { value: m.labels, origin },
|
|
453
|
+
colors: mapFromColors(m.colors, origin),
|
|
454
|
+
identified: buildShapeScope(m.identified, origin),
|
|
455
|
+
referenced: {
|
|
456
|
+
required: { value: m.referenced.required, origin },
|
|
457
|
+
attributes: mapFromAttrList(m.referenced.attributes, origin),
|
|
458
|
+
traceability: new Map(),
|
|
459
|
+
},
|
|
460
|
+
types: mapFromTypes(m.types, origin),
|
|
461
|
+
documents: {
|
|
462
|
+
types: mapFromDocTypes(m.documents.types, origin),
|
|
463
|
+
frontMatter: mapFromAttrList(m.documents.frontMatter, origin),
|
|
464
|
+
},
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function mapFromColors(colors, origin) {
|
|
468
|
+
const out = new Map();
|
|
469
|
+
for (const [name, hue] of colors) {
|
|
470
|
+
out.set(name, { value: hue, origin });
|
|
471
|
+
}
|
|
472
|
+
return out;
|
|
473
|
+
}
|
|
474
|
+
function buildShapeScope(raw, origin) {
|
|
475
|
+
return {
|
|
476
|
+
required: { value: raw.required, origin },
|
|
477
|
+
attributes: mapFromAttrList(raw.attributes, origin),
|
|
478
|
+
traceability: mapFromTrace(raw.traceability, origin),
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
function mapFromAttrList(attrs, origin) {
|
|
482
|
+
const out = new Map();
|
|
483
|
+
for (const a of attrs) {
|
|
484
|
+
out.set(a.name, { value: a, origin });
|
|
485
|
+
}
|
|
486
|
+
return out;
|
|
487
|
+
}
|
|
488
|
+
function mapFromTrace(trace, origin) {
|
|
489
|
+
const out = new Map();
|
|
490
|
+
for (const [name, rule] of trace) {
|
|
491
|
+
out.set(name, { value: rule, origin });
|
|
492
|
+
}
|
|
493
|
+
return out;
|
|
494
|
+
}
|
|
495
|
+
function mapFromTypes(types, origin) {
|
|
496
|
+
const out = new Map();
|
|
497
|
+
for (const [name, td] of types) {
|
|
498
|
+
const eff = {
|
|
499
|
+
name,
|
|
500
|
+
shape: td.shape,
|
|
501
|
+
displayIdPattern: { value: td.displayIdPattern, origin },
|
|
502
|
+
displayIdPatternEnforcement: {
|
|
503
|
+
value: td.displayIdPatternEnforcement,
|
|
504
|
+
origin,
|
|
505
|
+
},
|
|
506
|
+
color: { value: td.color, origin },
|
|
507
|
+
required: { value: td.required, origin },
|
|
508
|
+
attributes: mapFromAttrList(td.attributes, origin),
|
|
509
|
+
traceability: mapFromTrace(td.traceability, origin),
|
|
510
|
+
};
|
|
511
|
+
out.set(name, { value: eff, origin });
|
|
512
|
+
}
|
|
513
|
+
return out;
|
|
514
|
+
}
|
|
515
|
+
function mapFromDocTypes(docTypes, origin) {
|
|
516
|
+
const out = new Map();
|
|
517
|
+
for (const dt of docTypes) {
|
|
518
|
+
out.set(dt.id, { value: dt, origin });
|
|
519
|
+
}
|
|
520
|
+
return out;
|
|
521
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile
|
|
3
|
+
*
|
|
4
|
+
* Public API for the profile system: loading, manifest parsing, chain
|
|
5
|
+
* resolution, and merging. Consumed by the validator pipeline and the CLI.
|
|
6
|
+
*/
|
|
7
|
+
export { parseManifest } from "./manifest.js";
|
|
8
|
+
export type { ParseManifestResult } from "./manifest.js";
|
|
9
|
+
export { resolveGitSpecifier, resolveLocalSpecifier } from "./resolver.js";
|
|
10
|
+
export type { ResolvedProfileSource, ResolveGitOptions } from "./resolver.js";
|
|
11
|
+
export { computeCacheKey, computeCacheLocation, defaultAppendFile, defaultRunGit, ensureCacheGitignored, } from "./git-cache.js";
|
|
12
|
+
export type { AppendFile, CacheLocation, GitCacheKeyInput, RunGit, RunGitResult, } from "./git-cache.js";
|
|
13
|
+
export { loadChain } from "./chain.js";
|
|
14
|
+
export type { LoadChainOptions, LoadChainResult } from "./chain.js";
|
|
15
|
+
export { loadProfileForCommand } from "./load.js";
|
|
16
|
+
export type { LoadProfileForCommandResult } from "./load.js";
|
|
17
|
+
export { mergeChain } from "./merge.js";
|
|
18
|
+
export type { MergeResult } from "./merge.js";
|
|
19
|
+
export { cacheDir } from "./cache.js";
|
|
20
|
+
export type { CacheEnv } from "./cache.js";
|
|
21
|
+
export { defaultRunNpm, resolveNpmSpecifier } from "./npm.js";
|
|
22
|
+
export type { ResolveNpmOptions, RunNpm } from "./npm.js";
|
|
23
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/profile/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3E,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,MAAM,EACN,YAAY,GACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC9D,YAAY,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/profile
|
|
4
|
+
*
|
|
5
|
+
* Public API for the profile system: loading, manifest parsing, chain
|
|
6
|
+
* resolution, and merging. Consumed by the validator pipeline and the CLI.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.resolveNpmSpecifier = exports.defaultRunNpm = exports.cacheDir = exports.mergeChain = exports.loadProfileForCommand = exports.loadChain = exports.ensureCacheGitignored = exports.defaultRunGit = exports.defaultAppendFile = exports.computeCacheLocation = exports.computeCacheKey = exports.resolveLocalSpecifier = exports.resolveGitSpecifier = exports.parseManifest = void 0;
|
|
10
|
+
var manifest_js_1 = require("./manifest.js");
|
|
11
|
+
Object.defineProperty(exports, "parseManifest", { enumerable: true, get: function () { return manifest_js_1.parseManifest; } });
|
|
12
|
+
var resolver_js_1 = require("./resolver.js");
|
|
13
|
+
Object.defineProperty(exports, "resolveGitSpecifier", { enumerable: true, get: function () { return resolver_js_1.resolveGitSpecifier; } });
|
|
14
|
+
Object.defineProperty(exports, "resolveLocalSpecifier", { enumerable: true, get: function () { return resolver_js_1.resolveLocalSpecifier; } });
|
|
15
|
+
var git_cache_js_1 = require("./git-cache.js");
|
|
16
|
+
Object.defineProperty(exports, "computeCacheKey", { enumerable: true, get: function () { return git_cache_js_1.computeCacheKey; } });
|
|
17
|
+
Object.defineProperty(exports, "computeCacheLocation", { enumerable: true, get: function () { return git_cache_js_1.computeCacheLocation; } });
|
|
18
|
+
Object.defineProperty(exports, "defaultAppendFile", { enumerable: true, get: function () { return git_cache_js_1.defaultAppendFile; } });
|
|
19
|
+
Object.defineProperty(exports, "defaultRunGit", { enumerable: true, get: function () { return git_cache_js_1.defaultRunGit; } });
|
|
20
|
+
Object.defineProperty(exports, "ensureCacheGitignored", { enumerable: true, get: function () { return git_cache_js_1.ensureCacheGitignored; } });
|
|
21
|
+
var chain_js_1 = require("./chain.js");
|
|
22
|
+
Object.defineProperty(exports, "loadChain", { enumerable: true, get: function () { return chain_js_1.loadChain; } });
|
|
23
|
+
var load_js_1 = require("./load.js");
|
|
24
|
+
Object.defineProperty(exports, "loadProfileForCommand", { enumerable: true, get: function () { return load_js_1.loadProfileForCommand; } });
|
|
25
|
+
var merge_js_1 = require("./merge.js");
|
|
26
|
+
Object.defineProperty(exports, "mergeChain", { enumerable: true, get: function () { return merge_js_1.mergeChain; } });
|
|
27
|
+
var cache_js_1 = require("./cache.js");
|
|
28
|
+
Object.defineProperty(exports, "cacheDir", { enumerable: true, get: function () { return cache_js_1.cacheDir; } });
|
|
29
|
+
var npm_js_1 = require("./npm.js");
|
|
30
|
+
Object.defineProperty(exports, "defaultRunNpm", { enumerable: true, get: function () { return npm_js_1.defaultRunNpm; } });
|
|
31
|
+
Object.defineProperty(exports, "resolveNpmSpecifier", { enumerable: true, get: function () { return npm_js_1.resolveNpmSpecifier; } });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/npm
|
|
3
|
+
*
|
|
4
|
+
* Resolve an npm profile specifier by downloading the package tarball
|
|
5
|
+
* via `npm pack` and extracting `markspec.yaml` from it. Results are
|
|
6
|
+
* cached under the global XDG cache directory.
|
|
7
|
+
*/
|
|
8
|
+
import type { Diagnostic, ProfileSpecifier } from "../model/mod.js";
|
|
9
|
+
import type { ResolvedProfileSource } from "./resolver.js";
|
|
10
|
+
/** Result of running an npm command. Same shape as {@linkcode RunGit}. */
|
|
11
|
+
export type RunNpm = (args: readonly string[], cwd?: string) => Promise<{
|
|
12
|
+
code: number;
|
|
13
|
+
stdout: string;
|
|
14
|
+
stderr: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Options for {@linkcode resolveNpmSpecifier}. */
|
|
17
|
+
export interface ResolveNpmOptions {
|
|
18
|
+
/** Injectable npm runner — defaults to {@linkcode defaultRunNpm}. */
|
|
19
|
+
readonly runNpm?: RunNpm;
|
|
20
|
+
/** Global cache root (from {@linkcode cacheDir}). */
|
|
21
|
+
readonly cacheRoot: string;
|
|
22
|
+
/** File reader — returns contents or undefined if missing. */
|
|
23
|
+
readonly readFile: (path: string) => Promise<string | undefined>;
|
|
24
|
+
/** Pre-resolved version for cache lookup (testing only). */
|
|
25
|
+
readonly resolvedVersion?: string;
|
|
26
|
+
/** Injectable temp dir creator — defaults to `Deno.makeTempDir`. */
|
|
27
|
+
readonly makeTempDir?: () => Promise<string>;
|
|
28
|
+
/** Injectable temp dir remover — defaults to `Deno.remove`. */
|
|
29
|
+
readonly removeTempDir?: (path: string) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Default npm runner using `Deno.Command`. */
|
|
32
|
+
export declare function defaultRunNpm(args: readonly string[], cwd?: string): Promise<{
|
|
33
|
+
code: number;
|
|
34
|
+
stdout: string;
|
|
35
|
+
stderr: string;
|
|
36
|
+
}>;
|
|
37
|
+
/** Extract semver from a tarball filename like `profile-default-1.0.0.tgz`. */
|
|
38
|
+
export declare function extractVersionFromTarball(filename: string): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Resolve an npm specifier into a {@linkcode ResolvedProfileSource}.
|
|
41
|
+
*
|
|
42
|
+
* 1. Check the cache for an existing resolution
|
|
43
|
+
* 2. On miss, run `npm pack <pkg>@<range> --pack-destination <tmpdir>`
|
|
44
|
+
* 3. Extract `markspec.yaml` from the tarball
|
|
45
|
+
* 4. Cache to `<cacheRoot>/npm/<pkg>/<version>/`
|
|
46
|
+
* 5. Return the resolved source
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveNpmSpecifier(specifier: Extract<ProfileSpecifier, {
|
|
49
|
+
kind: "npm";
|
|
50
|
+
}>, diagnostics: Diagnostic[], opts: ResolveNpmOptions): Promise<ResolvedProfileSource | null>;
|
|
51
|
+
//# sourceMappingURL=npm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm.d.ts","sourceRoot":"","sources":["../../src/profile/npm.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,0EAA0E;AAC1E,MAAM,MAAM,MAAM,GAAG,CACnB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,CAAC,EAAE,MAAM,KACT,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE/D,mDAAmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACjE,4DAA4D;IAC5D,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,oEAAoE;IACpE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED,+CAA+C;AAC/C,wBAAsB,aAAa,CACjC,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAa3D;AAgBD,+EAA+E;AAC/E,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKzE;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC,EACrD,WAAW,EAAE,UAAU,EAAE,EACzB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CA4IvC"}
|