@webpieces/rules-config 0.4.847 → 0.4.849
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/package.json +10 -7
- package/src/WebpiecesRulesConfig.d.ts +1 -2
- package/src/WebpiecesRulesConfig.js +0 -1
- package/src/WebpiecesRulesConfig.js.map +1 -1
- package/src/client-module-resolution.d.ts +9 -0
- package/src/client-module-resolution.js +102 -0
- package/src/client-module-resolution.js.map +1 -0
- package/src/config-error-banner.d.ts +0 -2
- package/src/config-error-banner.js +1 -3
- package/src/config-error-banner.js.map +1 -1
- package/src/config-file.d.ts +3 -6
- package/src/config-file.js +14 -1
- package/src/config-file.js.map +1 -1
- package/src/config-key-rules.js +16 -5
- package/src/config-key-rules.js.map +1 -1
- package/src/config-pruner.d.ts +5 -42
- package/src/config-pruner.js +31 -76
- package/src/config-pruner.js.map +1 -1
- package/src/config-repair-access.d.ts +4 -0
- package/src/config-repair-access.js +17 -0
- package/src/config-repair-access.js.map +1 -0
- package/src/config-repair-bootstrap-source.d.ts +2 -0
- package/src/config-repair-bootstrap-source.js +7 -0
- package/src/config-repair-bootstrap-source.js.map +1 -0
- package/src/config-repair-probe.d.ts +13 -0
- package/src/config-repair-probe.js +115 -0
- package/src/config-repair-probe.js.map +1 -0
- package/src/first-path-match.d.ts +14 -0
- package/src/first-path-match.js +35 -0
- package/src/first-path-match.js.map +1 -0
- package/src/index.d.ts +15 -8
- package/src/index.js +40 -10
- package/src/index.js.map +1 -1
- package/src/legacy-config-upgrade.d.ts +22 -0
- package/src/legacy-config-upgrade.js +328 -0
- package/src/legacy-config-upgrade.js.map +1 -0
- package/src/load-config.d.ts +11 -23
- package/src/load-config.js +50 -138
- package/src/load-config.js.map +1 -1
- package/src/pack-policy-files.d.ts +29 -0
- package/src/pack-policy-files.js +194 -0
- package/src/pack-policy-files.js.map +1 -0
- package/src/policy-field-constraints.d.ts +9 -0
- package/src/policy-field-constraints.js +31 -0
- package/src/policy-field-constraints.js.map +1 -0
- package/src/repository-path.d.ts +7 -0
- package/src/repository-path.js +50 -0
- package/src/repository-path.js.map +1 -0
- package/src/rule-pack-artifacts.d.ts +23 -0
- package/src/rule-pack-artifacts.js +180 -0
- package/src/rule-pack-artifacts.js.map +1 -0
- package/src/rule-pack-registry.d.ts +7 -0
- package/src/rule-pack-registry.js +149 -47
- package/src/rule-pack-registry.js.map +1 -1
- package/src/rule-pack-sync.d.ts +26 -0
- package/src/rule-pack-sync.js +236 -0
- package/src/rule-pack-sync.js.map +1 -0
- package/src/rule-runtime-modules.d.ts +27 -0
- package/src/rule-runtime-modules.js +135 -0
- package/src/rule-runtime-modules.js.map +1 -0
- package/src/rules-sync-cli.d.ts +7 -0
- package/src/rules-sync-cli.js +48 -0
- package/src/rules-sync-cli.js.map +1 -0
- package/src/seed-entry.js +1 -3
- package/src/seed-entry.js.map +1 -1
- package/src/types.d.ts +4 -6
- package/src/types.js +4 -7
- package/src/types.js.map +1 -1
- package/src/validate-config.d.ts +3 -29
- package/src/validate-config.js +99 -244
- package/src/validate-config.js.map +1 -1
- package/src/validate-pr-gate.d.ts +8 -0
- package/src/validate-pr-gate.js +161 -0
- package/src/validate-pr-gate.js.map +1 -0
- package/templates/webpieces.guard-matrix.md +5 -4
- package/src/rule-pack-selection.d.ts +0 -6
- package/src/rule-pack-selection.js +0 -50
- package/src/rule-pack-selection.js.map +0 -1
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RulePackDiscovery = exports.RulePackRegistry = exports.NodeRulePackModuleLoader = exports.RulePackModuleLoader = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const policy_field_constraints_1 = require("./policy-field-constraints");
|
|
5
6
|
const inversify_1 = require("inversify");
|
|
6
7
|
const node_module_1 = require("node:module");
|
|
7
8
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
8
9
|
const path = tslib_1.__importStar(require("node:path"));
|
|
10
|
+
const client_module_resolution_1 = require("./client-module-resolution");
|
|
9
11
|
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
10
12
|
/** Loading is the only impure boundary; callers may supply an alternative module transport. */
|
|
11
13
|
class RulePackModuleLoader {
|
|
@@ -13,13 +15,15 @@ class RulePackModuleLoader {
|
|
|
13
15
|
exports.RulePackModuleLoader = RulePackModuleLoader;
|
|
14
16
|
class NodeRulePackModuleLoader extends RulePackModuleLoader {
|
|
15
17
|
requireModule;
|
|
18
|
+
resolution;
|
|
16
19
|
constructor(clientRoot) {
|
|
17
20
|
super();
|
|
18
21
|
this.requireModule = (0, node_module_1.createRequire)(path.join(clientRoot, 'package.json'));
|
|
22
|
+
this.resolution = new client_module_resolution_1.ClientModuleResolution(clientRoot);
|
|
19
23
|
}
|
|
20
24
|
load(moduleName) {
|
|
21
25
|
// webpieces-disable no-any-unknown -- external module boundary; registry validates its exported data before use
|
|
22
|
-
const exports = this.requireModule(moduleName);
|
|
26
|
+
const exports = this.requireModule(this.resolution.resolve(moduleName));
|
|
23
27
|
if (typeof exports !== 'object' || exports === null || !('rulePackManifest' in exports)) {
|
|
24
28
|
throw new tooling_common_1.InformAiError(`Rule pack ${moduleName} must export rulePackManifest. Add the public manifest export.`);
|
|
25
29
|
}
|
|
@@ -30,11 +34,14 @@ exports.NodeRulePackModuleLoader = NodeRulePackModuleLoader;
|
|
|
30
34
|
/** A registry depends only on declarations and the SDK, never on concrete execution packages. */
|
|
31
35
|
class RulePackRegistry {
|
|
32
36
|
manifests;
|
|
37
|
+
modules = new Map();
|
|
33
38
|
owners = new Map();
|
|
34
39
|
definitions = new Map();
|
|
35
40
|
safeguards = new Map();
|
|
36
41
|
constructor(manifests) {
|
|
37
42
|
this.manifests = manifests;
|
|
43
|
+
for (const manifest of manifests)
|
|
44
|
+
this.validateManifestHeader(manifest);
|
|
38
45
|
const packs = new Set();
|
|
39
46
|
for (const manifest of manifests) {
|
|
40
47
|
this.validateManifest(manifest);
|
|
@@ -50,9 +57,12 @@ class RulePackRegistry {
|
|
|
50
57
|
}
|
|
51
58
|
for (const manifest of manifests) {
|
|
52
59
|
for (const safeguard of manifest.safeguards) {
|
|
53
|
-
if (!safeguard ||
|
|
60
|
+
if (!safeguard ||
|
|
61
|
+
typeof safeguard.id !== 'string' ||
|
|
62
|
+
!safeguard.id ||
|
|
54
63
|
!['fixed', 'experimental'].includes(safeguard.activation) ||
|
|
55
|
-
typeof safeguard.description !== 'string' ||
|
|
64
|
+
typeof safeguard.description !== 'string' ||
|
|
65
|
+
!safeguard.description) {
|
|
56
66
|
throw new tooling_common_1.InformAiError('Invalid safeguard catalog. Supply id, activation, and description.');
|
|
57
67
|
}
|
|
58
68
|
if (this.owners.has(safeguard.id) || this.safeguards.has(safeguard.id)) {
|
|
@@ -62,23 +72,31 @@ class RulePackRegistry {
|
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
74
|
const executions = new Set();
|
|
65
|
-
for (const manifest of manifests)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
if (!['build', 'source-hook', 'workflow-guard', 'lint'].includes(contribution.executionKind)) {
|
|
75
|
-
throw new tooling_common_1.InformAiError(`Invalid execution kind for ${contribution.ruleId}. Use build, source-hook, workflow-guard, or lint.`);
|
|
76
|
-
}
|
|
77
|
-
const execution = `${contribution.ruleId}:${contribution.executionKind}`;
|
|
78
|
-
if (executions.has(execution))
|
|
79
|
-
throw new tooling_common_1.InformAiError(`Duplicate execution-kind contribution ${execution}. Keep one implementation per execution kind.`);
|
|
80
|
-
executions.add(execution);
|
|
75
|
+
for (const manifest of manifests)
|
|
76
|
+
this.registerContributions(manifest, executions);
|
|
77
|
+
}
|
|
78
|
+
registerContributions(manifest, executions) {
|
|
79
|
+
for (const contribution of manifest.contributions) {
|
|
80
|
+
if (!contribution ||
|
|
81
|
+
typeof contribution.ruleId !== 'string' ||
|
|
82
|
+
typeof contribution.ownerPack !== 'string') {
|
|
83
|
+
throw new tooling_common_1.InformAiError(`Invalid contribution in ${manifest.packageName}. Supply ruleId and ownerPack.`);
|
|
81
84
|
}
|
|
85
|
+
if (typeof contribution.implementationModule !== 'string' ||
|
|
86
|
+
!contribution.implementationModule.trim()) {
|
|
87
|
+
throw new tooling_common_1.InformAiError(`Missing implementation module for ${contribution.ruleId} in ${manifest.packageName}. Declare its public runtime module.`);
|
|
88
|
+
}
|
|
89
|
+
const owner = this.owners.get(contribution.ruleId);
|
|
90
|
+
if (!owner || owner !== contribution.ownerPack) {
|
|
91
|
+
throw new tooling_common_1.InformAiError(`Unknown owner ${contribution.ownerPack} for ${contribution.ruleId}. Declare the owning pack and use its exact name.`);
|
|
92
|
+
}
|
|
93
|
+
if (!['build', 'source-hook', 'workflow-guard', 'lint'].includes(contribution.executionKind)) {
|
|
94
|
+
throw new tooling_common_1.InformAiError(`Invalid execution kind for ${contribution.ruleId}. Use build, source-hook, workflow-guard, or lint.`);
|
|
95
|
+
}
|
|
96
|
+
const execution = `${contribution.ruleId}:${contribution.executionKind}`;
|
|
97
|
+
if (executions.has(execution))
|
|
98
|
+
throw new tooling_common_1.InformAiError(`Duplicate execution-kind contribution ${execution}. Keep one implementation per execution kind.`);
|
|
99
|
+
executions.add(execution);
|
|
82
100
|
}
|
|
83
101
|
}
|
|
84
102
|
ownerOf(ruleId) {
|
|
@@ -91,34 +109,85 @@ class RulePackRegistry {
|
|
|
91
109
|
this.ownerOf(ruleId);
|
|
92
110
|
return this.definitions.get(ruleId).schema;
|
|
93
111
|
}
|
|
112
|
+
/** The transport records the exact client declaration, including local manifest modules. */
|
|
113
|
+
recordModuleLocation(packName, moduleName) {
|
|
114
|
+
if (!this.manifests.some((manifest) => manifest.packageName === packName) ||
|
|
115
|
+
this.modules.has(packName)) {
|
|
116
|
+
throw new tooling_common_1.InformAiError(`Invalid or duplicate module location for ${packName}. Declare each selected pack once.`);
|
|
117
|
+
}
|
|
118
|
+
this.modules.set(packName, moduleName);
|
|
119
|
+
}
|
|
120
|
+
get manifestModules() {
|
|
121
|
+
return this.modules;
|
|
122
|
+
}
|
|
94
123
|
ruleIds() {
|
|
95
124
|
return [...this.definitions.keys()];
|
|
96
125
|
}
|
|
97
|
-
hasRule(ruleId) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
126
|
+
hasRule(ruleId) {
|
|
127
|
+
return this.definitions.has(ruleId);
|
|
128
|
+
}
|
|
129
|
+
isSafeguard(ruleId) {
|
|
130
|
+
return this.safeguards.has(ruleId);
|
|
131
|
+
}
|
|
132
|
+
sectionFor(ruleId) {
|
|
133
|
+
return this.definitionFor(ruleId).section;
|
|
134
|
+
}
|
|
135
|
+
optionalTuningFor(ruleId) {
|
|
136
|
+
return this.definitionFor(ruleId).optionalTuning;
|
|
137
|
+
}
|
|
138
|
+
seedFor(ruleId) {
|
|
139
|
+
return structuredClone(this.definitionFor(ruleId).recommendedSeed);
|
|
140
|
+
}
|
|
141
|
+
migrations() {
|
|
142
|
+
return this.manifests.flatMap((manifest) => [...manifest.migrations]);
|
|
143
|
+
}
|
|
144
|
+
safeguardCatalog() {
|
|
145
|
+
return [...this.safeguards.values()];
|
|
146
|
+
}
|
|
104
147
|
definitionFor(ruleId) {
|
|
105
148
|
this.ownerOf(ruleId);
|
|
106
149
|
return this.definitions.get(ruleId);
|
|
107
150
|
}
|
|
108
151
|
/** Validates explicit config values with the owner's schema; supplies no rule defaults. */
|
|
109
152
|
validateRuleConfig(ruleId, value) {
|
|
110
|
-
|
|
153
|
+
const errors = this.validateObject(ruleId, this.schemaFor(ruleId), value);
|
|
154
|
+
if (value && typeof value['turnOffRuleUntilEpoch'] === 'number') {
|
|
155
|
+
const epoch = new policy_field_constraints_1.PolicyFieldConstraints().epochError(`[${ruleId}]`, value['turnOffRuleUntilEpoch']);
|
|
156
|
+
if (epoch)
|
|
157
|
+
errors.push(epoch);
|
|
158
|
+
}
|
|
159
|
+
return errors;
|
|
111
160
|
}
|
|
112
|
-
|
|
113
|
-
if (!manifest ||
|
|
114
|
-
typeof manifest.
|
|
115
|
-
|
|
116
|
-
|
|
161
|
+
validateManifestHeader(manifest) {
|
|
162
|
+
if (!manifest ||
|
|
163
|
+
typeof manifest.packageName !== 'string' ||
|
|
164
|
+
manifest.packageName.length === 0 ||
|
|
165
|
+
typeof manifest.packageVersion !== 'string' ||
|
|
166
|
+
manifest.packageVersion.length === 0 ||
|
|
167
|
+
!Array.isArray(manifest.ownedRules) ||
|
|
168
|
+
!Array.isArray(manifest.contributions) ||
|
|
169
|
+
!Array.isArray(manifest.migrations) ||
|
|
170
|
+
!Array.isArray(manifest.safeguards)) {
|
|
117
171
|
throw new tooling_common_1.InformAiError('Invalid rule pack manifest. Supply packageName, packageVersion, ownedRules, contributions, migrations, and safeguards.');
|
|
118
172
|
}
|
|
119
173
|
if (manifest.apiVersion !== rules_sdk_1.RULE_PACK_API_VERSION) {
|
|
120
174
|
throw new tooling_common_1.InformAiError(`Unsupported manifest API ${manifest.apiVersion} for ${manifest.packageName}. Use API ${rules_sdk_1.RULE_PACK_API_VERSION}.`);
|
|
121
175
|
}
|
|
176
|
+
for (const migration of manifest.migrations) {
|
|
177
|
+
if (!migration ||
|
|
178
|
+
!['rule', 'key', 'field'].includes(migration.scope) ||
|
|
179
|
+
typeof migration.key !== 'string' ||
|
|
180
|
+
!migration.key ||
|
|
181
|
+
typeof migration.movedTo !== 'string' ||
|
|
182
|
+
typeof migration.instruction !== 'string' ||
|
|
183
|
+
!migration.instruction ||
|
|
184
|
+
typeof migration.label !== 'string' ||
|
|
185
|
+
typeof migration.prunable !== 'boolean') {
|
|
186
|
+
throw new tooling_common_1.InformAiError(`Invalid migration in ${manifest.packageName}. Supply the retired key and exact edit.`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
validateManifest(manifest) {
|
|
122
191
|
for (const definition of manifest.ownedRules) {
|
|
123
192
|
if (!definition || typeof definition.id !== 'string' || definition.id.length === 0) {
|
|
124
193
|
throw new tooling_common_1.InformAiError(`Invalid owned rule in ${manifest.packageName}. Supply a nonempty id.`);
|
|
@@ -127,14 +196,21 @@ class RulePackRegistry {
|
|
|
127
196
|
throw new tooling_common_1.InformAiError(`Unsupported schema API for ${definition.id}. Use API ${rules_sdk_1.RULE_SCHEMA_API_VERSION}.`);
|
|
128
197
|
}
|
|
129
198
|
this.validateSchema(definition.id, definition.schema);
|
|
199
|
+
if (!definition.help ||
|
|
200
|
+
typeof definition.help.description !== 'string' ||
|
|
201
|
+
!definition.help.description.trim() ||
|
|
202
|
+
typeof definition.help.remediation !== 'string' ||
|
|
203
|
+
!definition.help.remediation.trim()) {
|
|
204
|
+
throw new tooling_common_1.InformAiError(`Missing catalog help for ${definition.id}. Its owner must supply description and remediation.`);
|
|
205
|
+
}
|
|
130
206
|
this.validateOwnerSettings(definition);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
!
|
|
137
|
-
throw new tooling_common_1.InformAiError(`
|
|
207
|
+
const mode = definition.schema['mode'];
|
|
208
|
+
if (!mode ||
|
|
209
|
+
mode.type !== 'string' ||
|
|
210
|
+
mode.optional ||
|
|
211
|
+
mode.nullable ||
|
|
212
|
+
!mode.enumValues?.includes('OFF')) {
|
|
213
|
+
throw new tooling_common_1.InformAiError(`Policy ${definition.id} must declare a required string mode with explicit OFF opt-out. Fix its owner schema.`);
|
|
138
214
|
}
|
|
139
215
|
}
|
|
140
216
|
}
|
|
@@ -148,7 +224,9 @@ class RulePackRegistry {
|
|
|
148
224
|
}
|
|
149
225
|
for (const key of Object.keys(tuning)) {
|
|
150
226
|
const field = definition.schema[key];
|
|
151
|
-
if (!field ||
|
|
227
|
+
if (!field ||
|
|
228
|
+
!field.optional ||
|
|
229
|
+
['mode', 'turnOffRuleUntilEpoch', 'turnOffRuleWhileOnBranch'].includes(key)) {
|
|
152
230
|
throw new tooling_common_1.InformAiError(`${definition.id}.${key} cannot have a default. Keep required behaviour in explicit repository config.`);
|
|
153
231
|
}
|
|
154
232
|
const errors = this.validateObject(definition.id, { [key]: field }, { [key]: tuning[key] });
|
|
@@ -163,14 +241,18 @@ class RulePackRegistry {
|
|
|
163
241
|
if (!schema || typeof schema !== 'object' || Array.isArray(schema))
|
|
164
242
|
throw new tooling_common_1.InformAiError(`Invalid schema for ${location}. Supply a field map.`);
|
|
165
243
|
for (const [key, field] of Object.entries(schema)) {
|
|
166
|
-
if (!field ||
|
|
244
|
+
if (!field ||
|
|
245
|
+
!['string', 'number', 'boolean', 'string[]', 'object[]'].includes(field.type)) {
|
|
167
246
|
throw new tooling_common_1.InformAiError(`Invalid field ${location}.${key}. Supply a supported FieldDef type.`);
|
|
168
247
|
}
|
|
169
248
|
for (const flag of ['optional', 'nullable', 'nonEmpty']) {
|
|
170
249
|
if (field[flag] !== undefined && typeof field[flag] !== 'boolean')
|
|
171
250
|
throw new tooling_common_1.InformAiError(`Invalid ${flag} for ${location}.${key}. Supply a boolean.`);
|
|
172
251
|
}
|
|
173
|
-
if (field.enumValues !== undefined &&
|
|
252
|
+
if (field.enumValues !== undefined &&
|
|
253
|
+
(!Array.isArray(field.enumValues) ||
|
|
254
|
+
// webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution
|
|
255
|
+
field.enumValues.some((item) => typeof item !== 'string'))) {
|
|
174
256
|
throw new tooling_common_1.InformAiError(`Invalid enum for ${location}.${key}. Supply string values.`);
|
|
175
257
|
}
|
|
176
258
|
if (field.type === 'object[]')
|
|
@@ -181,9 +263,23 @@ class RulePackRegistry {
|
|
|
181
263
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
182
264
|
return [`${location} must be an explicitly configured object.`];
|
|
183
265
|
const errors = [];
|
|
184
|
-
for (const key of Object.keys(value))
|
|
185
|
-
if (
|
|
266
|
+
for (const key of Object.keys(value)) {
|
|
267
|
+
if (Object.hasOwn(schema, key))
|
|
268
|
+
continue;
|
|
269
|
+
const fields = new policy_field_constraints_1.PolicyFieldConstraints();
|
|
270
|
+
const renamed = fields.renamedField(key);
|
|
271
|
+
const retired = this.migrations().find((entry) => entry.scope === 'field' && entry.key === `${location}.${key}`);
|
|
272
|
+
if (renamed)
|
|
273
|
+
errors.push(`${location}.${key} was renamed to ${renamed}. Rename the field; the old spelling is rejected.`);
|
|
274
|
+
else if (retired)
|
|
275
|
+
errors.push(`${location}.${key}: ${retired.instruction}`);
|
|
276
|
+
else if (fields.isRationale(key)) {
|
|
277
|
+
if (typeof value[key] !== 'string')
|
|
278
|
+
errors.push(`${location}.${key} must be a string rationale note.`);
|
|
279
|
+
}
|
|
280
|
+
else
|
|
186
281
|
errors.push(`${location}.${key} is unknown. Use a field declared by its owner.`);
|
|
282
|
+
}
|
|
187
283
|
for (const [key, field] of Object.entries(schema)) {
|
|
188
284
|
const entry = Object.hasOwn(value, key) ? value[key] : undefined, label = `${location}.${key}`;
|
|
189
285
|
if (entry === undefined) {
|
|
@@ -193,7 +289,9 @@ class RulePackRegistry {
|
|
|
193
289
|
}
|
|
194
290
|
if (entry === null && field.nullable)
|
|
195
291
|
continue;
|
|
196
|
-
const valid = field.type.endsWith('[]')
|
|
292
|
+
const valid = field.type.endsWith('[]')
|
|
293
|
+
? Array.isArray(entry)
|
|
294
|
+
: typeof entry === field.type;
|
|
197
295
|
if (!valid || entry === null) {
|
|
198
296
|
errors.push(`${label} must be ${field.type}.`);
|
|
199
297
|
continue;
|
|
@@ -203,7 +301,8 @@ class RulePackRegistry {
|
|
|
203
301
|
if (Array.isArray(entry)) {
|
|
204
302
|
if (field.nonEmpty && entry.length === 0)
|
|
205
303
|
errors.push(`${label} must contain at least one entry.`);
|
|
206
|
-
if (field.type === 'string[]' &&
|
|
304
|
+
if (field.type === 'string[]' &&
|
|
305
|
+
entry.some((item) => typeof item !== 'string'))
|
|
207
306
|
errors.push(`${label} must contain only strings.`);
|
|
208
307
|
if (field.type === 'object[]')
|
|
209
308
|
entry.forEach((item, index) => errors.push(...this.validateObject(`${label}[${index}]`, field.elementSchema, item)));
|
|
@@ -220,7 +319,10 @@ let RulePackDiscovery = class RulePackDiscovery {
|
|
|
220
319
|
this.loader = loader;
|
|
221
320
|
}
|
|
222
321
|
discover(declarations) {
|
|
223
|
-
|
|
322
|
+
const manifests = declarations.map((declaration) => this.loader.load(declaration.module));
|
|
323
|
+
const registry = new RulePackRegistry(manifests);
|
|
324
|
+
manifests.forEach((manifest, index) => registry.recordModuleLocation(manifest.packageName, declarations[index].module));
|
|
325
|
+
return registry;
|
|
224
326
|
}
|
|
225
327
|
};
|
|
226
328
|
exports.RulePackDiscovery = RulePackDiscovery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-pack-registry.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/rule-pack-registry.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,6CAA4C;AAC5C,8DAA0D;AAC1D,wDAAkC;AAClC,oDAG8B;AAE9B,+FAA+F;AAC/F,MAAsB,oBAAoB;CAEzC;AAFD,oDAEC;AAED,MAAa,wBAAyB,SAAQ,oBAAoB;IAC7C,aAAa,CAAc;IAE5C,YAAY,UAAkB;QAC1B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAA,2BAAa,EAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;IAC9E,CAAC;IAEQ,IAAI,CAAC,UAAkB;QAC5B,gHAAgH;QAChH,MAAM,OAAO,GAAY,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACxD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,kBAAkB,IAAI,OAAO,CAAC,EAAE,CAAC;YACtF,MAAM,IAAI,8BAAa,CAAC,aAAa,UAAU,gEAAgE,CAAC,CAAC;QACrH,CAAC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C;gBACnG,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;oBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC;gBAClI,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;oBAAE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,KAAK,IAAI,KAAK,GAAG,EAAE,KAAK,CAAC,aAAc,EAAE,IAAoB,CAAC,CAAC,CAAC,CAAC;YACzK,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAjLD,4CAiLC;AAED,4FAA4F;AAErF,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACG;IAA7B,YAA6B,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;IAAG,CAAC;IAE7D,QAAQ,CAAC,YAA4C;QACjD,OAAO,IAAI,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvG,CAAC;CACJ,CAAA;AANY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEA,oBAAoB;GADhD,iBAAiB,CAM7B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { createRequire } from 'node:module';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport * as path from 'node:path';\nimport {\n FieldDef, RulePackManifest, RulePackDeclaration, OwnedRuleDefinition,\n RULE_PACK_API_VERSION, RULE_SCHEMA_API_VERSION, ConfigObject, RetiredConfigKey, SafeguardDefinition, RuleConfigSection,\n} from '@webpieces/rules-sdk';\n\n/** Loading is the only impure boundary; callers may supply an alternative module transport. */\nexport abstract class RulePackModuleLoader {\n abstract load(moduleName: string): RulePackManifest;\n}\n\nexport class NodeRulePackModuleLoader extends RulePackModuleLoader {\n private readonly requireModule: NodeRequire;\n\n constructor(clientRoot: string) {\n super();\n this.requireModule = createRequire(path.join(clientRoot, 'package.json'));\n }\n\n override load(moduleName: string): RulePackManifest {\n // webpieces-disable no-any-unknown -- external module boundary; registry validates its exported data before use\n const exports: unknown = this.requireModule(moduleName);\n if (typeof exports !== 'object' || exports === null || !('rulePackManifest' in exports)) {\n throw new InformAiError(`Rule pack ${moduleName} must export rulePackManifest. Add the public manifest export.`);\n }\n return exports.rulePackManifest as RulePackManifest;\n }\n}\n\n/** A registry depends only on declarations and the SDK, never on concrete execution packages. */\nexport class RulePackRegistry {\n private readonly owners = new Map<string, string>();\n private readonly definitions = new Map<string, OwnedRuleDefinition>();\n private readonly safeguards = new Map<string, SafeguardDefinition>();\n\n constructor(readonly manifests: readonly RulePackManifest[]) {\n const packs = new Set<string>();\n for (const manifest of manifests) {\n this.validateManifest(manifest);\n if (packs.has(manifest.packageName)) throw new InformAiError(`Duplicate pack ${manifest.packageName}. Declare it once.`);\n packs.add(manifest.packageName);\n for (const definition of manifest.ownedRules) {\n if (this.owners.has(definition.id)) throw new InformAiError(`Rule ${definition.id} has multiple owners. Keep exactly one owner.`);\n this.owners.set(definition.id, manifest.packageName);\n this.definitions.set(definition.id, definition);\n }\n }\n for (const manifest of manifests) {\n for (const safeguard of manifest.safeguards) {\n if (!safeguard || typeof safeguard.id !== 'string' || !safeguard.id ||\n !['fixed', 'experimental'].includes(safeguard.activation) ||\n typeof safeguard.description !== 'string' || !safeguard.description) {\n throw new InformAiError('Invalid safeguard catalog. Supply id, activation, and description.');\n }\n if (this.owners.has(safeguard.id) || this.safeguards.has(safeguard.id)) {\n throw new InformAiError(`Safeguard ${safeguard.id} cannot be configured or owned twice. Keep it outside configurable policies.`);\n }\n this.safeguards.set(safeguard.id, safeguard);\n }\n }\n const executions = new Set<string>();\n for (const manifest of manifests) {\n for (const contribution of manifest.contributions) {\n if (!contribution || typeof contribution.ruleId !== 'string' || typeof contribution.ownerPack !== 'string') {\n throw new InformAiError(`Invalid contribution in ${manifest.packageName}. Supply ruleId and ownerPack.`);\n }\n const owner = this.owners.get(contribution.ruleId);\n if (!owner || owner !== contribution.ownerPack) {\n throw new InformAiError(`Unknown owner ${contribution.ownerPack} for ${contribution.ruleId}. Declare the owning pack and use its exact name.`);\n }\n if (!['build', 'source-hook', 'workflow-guard', 'lint'].includes(contribution.executionKind)) {\n throw new InformAiError(`Invalid execution kind for ${contribution.ruleId}. Use build, source-hook, workflow-guard, or lint.`);\n }\n const execution = `${contribution.ruleId}:${contribution.executionKind}`;\n if (executions.has(execution)) throw new InformAiError(`Duplicate execution-kind contribution ${execution}. Keep one implementation per execution kind.`);\n executions.add(execution);\n }\n }\n }\n\n ownerOf(ruleId: string): string {\n const owner = this.owners.get(ruleId);\n if (!owner) throw new InformAiError(`Unknown rule ${ruleId}. Declare its owning pack.`);\n return owner;\n }\n\n schemaFor(ruleId: string): Readonly<Record<string, FieldDef>> {\n this.ownerOf(ruleId);\n return this.definitions.get(ruleId)!.schema;\n }\n\n ruleIds(): readonly string[] {\n return [...this.definitions.keys()];\n }\n\n hasRule(ruleId: string): boolean { return this.definitions.has(ruleId); }\n\n isSafeguard(ruleId: string): boolean { return this.safeguards.has(ruleId); }\n\n sectionFor(ruleId: string): RuleConfigSection { return this.definitionFor(ruleId).section; }\n\n optionalTuningFor(ruleId: string): ConfigObject { return this.definitionFor(ruleId).optionalTuning; }\n\n seedFor(ruleId: string): ConfigObject { return structuredClone(this.definitionFor(ruleId).recommendedSeed); }\n\n migrations(): readonly RetiredConfigKey[] { return this.manifests.flatMap(manifest => [...manifest.migrations]); }\n\n safeguardCatalog(): readonly SafeguardDefinition[] { return [...this.safeguards.values()]; }\n\n private definitionFor(ruleId: string): OwnedRuleDefinition {\n this.ownerOf(ruleId);\n return this.definitions.get(ruleId)!;\n }\n\n /** Validates explicit config values with the owner's schema; supplies no rule defaults. */\n validateRuleConfig(ruleId: string, value: ConfigObject): readonly string[] {\n return this.validateObject(ruleId, this.schemaFor(ruleId), value);\n }\n\n private validateManifest(manifest: RulePackManifest): void {\n if (!manifest || typeof manifest.packageName !== 'string' || manifest.packageName.length === 0 ||\n typeof manifest.packageVersion !== 'string' || manifest.packageVersion.length === 0 ||\n !Array.isArray(manifest.ownedRules) || !Array.isArray(manifest.contributions) ||\n !Array.isArray(manifest.migrations) || !Array.isArray(manifest.safeguards)) {\n throw new InformAiError('Invalid rule pack manifest. Supply packageName, packageVersion, ownedRules, contributions, migrations, and safeguards.');\n }\n if (manifest.apiVersion !== RULE_PACK_API_VERSION) {\n throw new InformAiError(`Unsupported manifest API ${manifest.apiVersion} for ${manifest.packageName}. Use API ${RULE_PACK_API_VERSION}.`);\n }\n for (const definition of manifest.ownedRules) {\n if (!definition || typeof definition.id !== 'string' || definition.id.length === 0) {\n throw new InformAiError(`Invalid owned rule in ${manifest.packageName}. Supply a nonempty id.`);\n }\n if (definition.schemaApiVersion !== RULE_SCHEMA_API_VERSION) {\n throw new InformAiError(`Unsupported schema API for ${definition.id}. Use API ${RULE_SCHEMA_API_VERSION}.`);\n }\n this.validateSchema(definition.id, definition.schema);\n this.validateOwnerSettings(definition);\n }\n for (const migration of manifest.migrations) {\n if (!migration || !['rule', 'key', 'field'].includes(migration.scope) ||\n typeof migration.key !== 'string' || !migration.key ||\n typeof migration.movedTo !== 'string' || typeof migration.instruction !== 'string' ||\n !migration.instruction || typeof migration.label !== 'string' || typeof migration.prunable !== 'boolean') {\n throw new InformAiError(`Invalid migration in ${manifest.packageName}. Supply the retired key and exact edit.`);\n }\n }\n }\n\n private validateOwnerSettings(definition: OwnedRuleDefinition): void {\n if (!['rules', 'hookGuards', 'lint'].includes(definition.section)) {\n throw new InformAiError(`Invalid config section for ${definition.id}. Use rules, hookGuards, or lint.`);\n }\n const tuning = definition.optionalTuning;\n if (!tuning || typeof tuning !== 'object' || Array.isArray(tuning)) {\n throw new InformAiError(`Missing optional tuning for ${definition.id}. Supply an explicit object, including {} when empty.`);\n }\n for (const key of Object.keys(tuning)) {\n const field = definition.schema[key];\n if (!field || !field.optional || key === 'mode') {\n throw new InformAiError(`${definition.id}.${key} cannot have a default. Keep required behaviour in explicit repository config.`);\n }\n const errors = this.validateObject(definition.id, { [key]: field }, { [key]: tuning[key] });\n if (errors.length) throw new InformAiError(errors.join('\\n'));\n }\n const errors = this.validateObject(definition.id, definition.schema, definition.recommendedSeed);\n if (errors.length) throw new InformAiError(`Invalid recommended seed: ${errors.join('\\n')}. Fix the owner's seed; the loader never applies it.`);\n }\n\n private validateSchema(location: string, schema: Readonly<Record<string, FieldDef>>): void {\n if (!schema || typeof schema !== 'object' || Array.isArray(schema)) throw new InformAiError(`Invalid schema for ${location}. Supply a field map.`);\n for (const [key, field] of Object.entries(schema)) {\n if (!field || !['string', 'number', 'boolean', 'string[]', 'object[]'].includes(field.type)) {\n throw new InformAiError(`Invalid field ${location}.${key}. Supply a supported FieldDef type.`);\n }\n for (const flag of ['optional', 'nullable', 'nonEmpty'] as const) {\n if (field[flag] !== undefined && typeof field[flag] !== 'boolean') throw new InformAiError(`Invalid ${flag} for ${location}.${key}. Supply a boolean.`);\n }\n if (field.enumValues !== undefined && (!Array.isArray(field.enumValues) || field.enumValues.some(item => typeof item !== 'string'))) {\n throw new InformAiError(`Invalid enum for ${location}.${key}. Supply string values.`);\n }\n if (field.type === 'object[]') this.validateSchema(`${location}.${key}[]`, field.elementSchema!);\n }\n }\n\n private validateObject(location: string, schema: Readonly<Record<string, FieldDef>>, value: ConfigObject): string[] {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return [`${location} must be an explicitly configured object.`];\n const errors: string[] = [];\n for (const key of Object.keys(value)) if (!Object.hasOwn(schema, key)) errors.push(`${location}.${key} is unknown. Use a field declared by its owner.`);\n for (const [key, field] of Object.entries(schema)) {\n const entry = Object.hasOwn(value, key) ? value[key] : undefined, label = `${location}.${key}`;\n if (entry === undefined) {\n if (!field.optional) errors.push(`${label} is required. Add an explicit ${field.type} value.`);\n continue;\n }\n if (entry === null && field.nullable) continue;\n const valid = field.type.endsWith('[]') ? Array.isArray(entry) : typeof entry === field.type;\n if (!valid || entry === null) { errors.push(`${label} must be ${field.type}.`); continue; }\n if (field.enumValues && !field.enumValues.includes(String(entry))) errors.push(`${label} must be one of ${field.enumValues.join(', ')}.`);\n if (Array.isArray(entry)) {\n if (field.nonEmpty && entry.length === 0) errors.push(`${label} must contain at least one entry.`);\n if (field.type === 'string[]' && entry.some(item => typeof item !== 'string')) errors.push(`${label} must contain only strings.`);\n if (field.type === 'object[]') entry.forEach((item, index) => errors.push(...this.validateObject(`${label}[${index}]`, field.elementSchema!, item as ConfigObject)));\n }\n }\n return errors;\n }\n}\n\n/** Inject the selected module transport; discovery never names a built-in owner package. */\n@injectable(bindingScopeValues.Singleton)\nexport class RulePackDiscovery {\n constructor(private readonly loader: RulePackModuleLoader) {}\n\n discover(declarations: readonly RulePackDeclaration[]): RulePackRegistry {\n return new RulePackRegistry(declarations.map(declaration => this.loader.load(declaration.module)));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rule-pack-registry.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/rule-pack-registry.ts"],"names":[],"mappings":";;;;AAAA,yEAAoE;AACpE,yCAA2D;AAC3D,6CAA4C;AAC5C,8DAA0D;AAC1D,wDAAkC;AAClC,yEAAoE;AACpE,oDAY8B;AAE9B,+FAA+F;AAC/F,MAAsB,oBAAoB;CAEzC;AAFD,oDAEC;AAED,MAAa,wBAAyB,SAAQ,oBAAoB;IAC7C,aAAa,CAAc;IAC3B,UAAU,CAAyB;IAEpD,YAAY,UAAkB;QAC1B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAA,2BAAa,EAAC,IAAI,CAAC,I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C,aAAc,EACpB,IAAoB,CACvB,CACJ,CACJ,CAAC;YACV,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAxYD,4CAwYC;AAED,4FAA4F;AAErF,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACG;IAA7B,YAA6B,MAA4B;QAA5B,WAAM,GAAN,MAAM,CAAsB;IAAG,CAAC;IAE7D,QAAQ,CAAC,YAA4C;QACjD,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,WAAgC,EAAE,EAAE,CACpE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CACvC,CAAC;QACF,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACjD,SAAS,CAAC,OAAO,CAAC,CAAC,QAA0B,EAAE,KAAa,EAAE,EAAE,CAC5D,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAClF,CAAC;QACF,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ,CAAA;AAbY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEA,oBAAoB;GADhD,iBAAiB,CAa7B","sourcesContent":["import { PolicyFieldConstraints } from './policy-field-constraints';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { createRequire } from 'node:module';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport * as path from 'node:path';\nimport { ClientModuleResolution } from './client-module-resolution';\nimport {\n FieldDef,\n RulePackManifest,\n RulePackDeclaration,\n OwnedRuleDefinition,\n RULE_PACK_API_VERSION,\n RULE_SCHEMA_API_VERSION,\n ConfigObject,\n RetiredConfigKey,\n SafeguardDefinition,\n RuleConfigSection,\n ConfigValue,\n} from '@webpieces/rules-sdk';\n\n/** Loading is the only impure boundary; callers may supply an alternative module transport. */\nexport abstract class RulePackModuleLoader {\n abstract load(moduleName: string): RulePackManifest;\n}\n\nexport class NodeRulePackModuleLoader extends RulePackModuleLoader {\n private readonly requireModule: NodeRequire;\n private readonly resolution: ClientModuleResolution;\n\n constructor(clientRoot: string) {\n super();\n this.requireModule = createRequire(path.join(clientRoot, 'package.json'));\n this.resolution = new ClientModuleResolution(clientRoot);\n }\n\n override load(moduleName: string): RulePackManifest {\n // webpieces-disable no-any-unknown -- external module boundary; registry validates its exported data before use\n const exports: unknown = this.requireModule(this.resolution.resolve(moduleName));\n if (typeof exports !== 'object' || exports === null || !('rulePackManifest' in exports)) {\n throw new InformAiError(\n `Rule pack ${moduleName} must export rulePackManifest. Add the public manifest export.`,\n );\n }\n return exports.rulePackManifest as RulePackManifest;\n }\n}\n\n/** A registry depends only on declarations and the SDK, never on concrete execution packages. */\nexport class RulePackRegistry {\n private readonly modules = new Map<string, string>();\n private readonly owners = new Map<string, string>();\n private readonly definitions = new Map<string, OwnedRuleDefinition>();\n private readonly safeguards = new Map<string, SafeguardDefinition>();\n\n constructor(readonly manifests: readonly RulePackManifest[]) {\n for (const manifest of manifests) this.validateManifestHeader(manifest);\n const packs = new Set<string>();\n for (const manifest of manifests) {\n this.validateManifest(manifest);\n if (packs.has(manifest.packageName))\n throw new InformAiError(`Duplicate pack ${manifest.packageName}. Declare it once.`);\n packs.add(manifest.packageName);\n for (const definition of manifest.ownedRules) {\n if (this.owners.has(definition.id))\n throw new InformAiError(\n `Rule ${definition.id} has multiple owners. Keep exactly one owner.`,\n );\n this.owners.set(definition.id, manifest.packageName);\n this.definitions.set(definition.id, definition);\n }\n }\n for (const manifest of manifests) {\n for (const safeguard of manifest.safeguards) {\n if (\n !safeguard ||\n typeof safeguard.id !== 'string' ||\n !safeguard.id ||\n !['fixed', 'experimental'].includes(safeguard.activation) ||\n typeof safeguard.description !== 'string' ||\n !safeguard.description\n ) {\n throw new InformAiError(\n 'Invalid safeguard catalog. Supply id, activation, and description.',\n );\n }\n if (this.owners.has(safeguard.id) || this.safeguards.has(safeguard.id)) {\n throw new InformAiError(\n `Safeguard ${safeguard.id} cannot be configured or owned twice. Keep it outside configurable policies.`,\n );\n }\n this.safeguards.set(safeguard.id, safeguard);\n }\n }\n const executions = new Set<string>();\n for (const manifest of manifests) this.registerContributions(manifest, executions);\n }\n\n private registerContributions(manifest: RulePackManifest, executions: Set<string>): void {\n for (const contribution of manifest.contributions) {\n if (\n !contribution ||\n typeof contribution.ruleId !== 'string' ||\n typeof contribution.ownerPack !== 'string'\n ) {\n throw new InformAiError(\n `Invalid contribution in ${manifest.packageName}. Supply ruleId and ownerPack.`,\n );\n }\n if (\n typeof contribution.implementationModule !== 'string' ||\n !contribution.implementationModule.trim()\n ) {\n throw new InformAiError(\n `Missing implementation module for ${contribution.ruleId} in ${manifest.packageName}. Declare its public runtime module.`,\n );\n }\n const owner = this.owners.get(contribution.ruleId);\n if (!owner || owner !== contribution.ownerPack) {\n throw new InformAiError(\n `Unknown owner ${contribution.ownerPack} for ${contribution.ruleId}. Declare the owning pack and use its exact name.`,\n );\n }\n if (\n !['build', 'source-hook', 'workflow-guard', 'lint'].includes(\n contribution.executionKind,\n )\n ) {\n throw new InformAiError(\n `Invalid execution kind for ${contribution.ruleId}. Use build, source-hook, workflow-guard, or lint.`,\n );\n }\n const execution = `${contribution.ruleId}:${contribution.executionKind}`;\n if (executions.has(execution))\n throw new InformAiError(\n `Duplicate execution-kind contribution ${execution}. Keep one implementation per execution kind.`,\n );\n executions.add(execution);\n }\n }\n\n ownerOf(ruleId: string): string {\n const owner = this.owners.get(ruleId);\n if (!owner) throw new InformAiError(`Unknown rule ${ruleId}. Declare its owning pack.`);\n return owner;\n }\n\n schemaFor(ruleId: string): Readonly<Record<string, FieldDef>> {\n this.ownerOf(ruleId);\n return this.definitions.get(ruleId)!.schema;\n }\n\n /** The transport records the exact client declaration, including local manifest modules. */\n recordModuleLocation(packName: string, moduleName: string): void {\n if (\n !this.manifests.some(\n (manifest: RulePackManifest) => manifest.packageName === packName,\n ) ||\n this.modules.has(packName)\n ) {\n throw new InformAiError(\n `Invalid or duplicate module location for ${packName}. Declare each selected pack once.`,\n );\n }\n this.modules.set(packName, moduleName);\n }\n\n get manifestModules(): ReadonlyMap<string, string> {\n return this.modules;\n }\n\n ruleIds(): readonly string[] {\n return [...this.definitions.keys()];\n }\n\n hasRule(ruleId: string): boolean {\n return this.definitions.has(ruleId);\n }\n\n isSafeguard(ruleId: string): boolean {\n return this.safeguards.has(ruleId);\n }\n\n sectionFor(ruleId: string): RuleConfigSection {\n return this.definitionFor(ruleId).section;\n }\n\n optionalTuningFor(ruleId: string): ConfigObject {\n return this.definitionFor(ruleId).optionalTuning;\n }\n\n seedFor(ruleId: string): ConfigObject {\n return structuredClone(this.definitionFor(ruleId).recommendedSeed);\n }\n\n migrations(): readonly RetiredConfigKey[] {\n return this.manifests.flatMap((manifest: RulePackManifest) => [...manifest.migrations]);\n }\n\n safeguardCatalog(): readonly SafeguardDefinition[] {\n return [...this.safeguards.values()];\n }\n\n private definitionFor(ruleId: string): OwnedRuleDefinition {\n this.ownerOf(ruleId);\n return this.definitions.get(ruleId)!;\n }\n\n /** Validates explicit config values with the owner's schema; supplies no rule defaults. */\n validateRuleConfig(ruleId: string, value: ConfigObject): readonly string[] {\n const errors = this.validateObject(ruleId, this.schemaFor(ruleId), value);\n if (value && typeof value['turnOffRuleUntilEpoch'] === 'number') {\n const epoch = new PolicyFieldConstraints().epochError(\n `[${ruleId}]`,\n value['turnOffRuleUntilEpoch'],\n );\n if (epoch) errors.push(epoch);\n }\n return errors;\n }\n\n private validateManifestHeader(manifest: RulePackManifest): void {\n if (\n !manifest ||\n typeof manifest.packageName !== 'string' ||\n manifest.packageName.length === 0 ||\n typeof manifest.packageVersion !== 'string' ||\n manifest.packageVersion.length === 0 ||\n !Array.isArray(manifest.ownedRules) ||\n !Array.isArray(manifest.contributions) ||\n !Array.isArray(manifest.migrations) ||\n !Array.isArray(manifest.safeguards)\n ) {\n throw new InformAiError(\n 'Invalid rule pack manifest. Supply packageName, packageVersion, ownedRules, contributions, migrations, and safeguards.',\n );\n }\n if (manifest.apiVersion !== RULE_PACK_API_VERSION) {\n throw new InformAiError(\n `Unsupported manifest API ${manifest.apiVersion} for ${manifest.packageName}. Use API ${RULE_PACK_API_VERSION}.`,\n );\n }\n for (const migration of manifest.migrations) {\n if (\n !migration ||\n !['rule', 'key', 'field'].includes(migration.scope) ||\n typeof migration.key !== 'string' ||\n !migration.key ||\n typeof migration.movedTo !== 'string' ||\n typeof migration.instruction !== 'string' ||\n !migration.instruction ||\n typeof migration.label !== 'string' ||\n typeof migration.prunable !== 'boolean'\n ) {\n throw new InformAiError(\n `Invalid migration in ${manifest.packageName}. Supply the retired key and exact edit.`,\n );\n }\n }\n }\n\n private validateManifest(manifest: RulePackManifest): void {\n for (const definition of manifest.ownedRules) {\n if (!definition || typeof definition.id !== 'string' || definition.id.length === 0) {\n throw new InformAiError(\n `Invalid owned rule in ${manifest.packageName}. Supply a nonempty id.`,\n );\n }\n if (definition.schemaApiVersion !== RULE_SCHEMA_API_VERSION) {\n throw new InformAiError(\n `Unsupported schema API for ${definition.id}. Use API ${RULE_SCHEMA_API_VERSION}.`,\n );\n }\n this.validateSchema(definition.id, definition.schema);\n if (\n !definition.help ||\n typeof definition.help.description !== 'string' ||\n !definition.help.description.trim() ||\n typeof definition.help.remediation !== 'string' ||\n !definition.help.remediation.trim()\n ) {\n throw new InformAiError(\n `Missing catalog help for ${definition.id}. Its owner must supply description and remediation.`,\n );\n }\n this.validateOwnerSettings(definition);\n const mode = definition.schema['mode'];\n if (\n !mode ||\n mode.type !== 'string' ||\n mode.optional ||\n mode.nullable ||\n !mode.enumValues?.includes('OFF')\n ) {\n throw new InformAiError(\n `Policy ${definition.id} must declare a required string mode with explicit OFF opt-out. Fix its owner schema.`,\n );\n }\n }\n }\n\n private validateOwnerSettings(definition: OwnedRuleDefinition): void {\n if (!['rules', 'hookGuards', 'lint'].includes(definition.section)) {\n throw new InformAiError(\n `Invalid config section for ${definition.id}. Use rules, hookGuards, or lint.`,\n );\n }\n const tuning = definition.optionalTuning;\n if (!tuning || typeof tuning !== 'object' || Array.isArray(tuning)) {\n throw new InformAiError(\n `Missing optional tuning for ${definition.id}. Supply an explicit object, including {} when empty.`,\n );\n }\n for (const key of Object.keys(tuning)) {\n const field = definition.schema[key];\n if (\n !field ||\n !field.optional ||\n ['mode', 'turnOffRuleUntilEpoch', 'turnOffRuleWhileOnBranch'].includes(key)\n ) {\n throw new InformAiError(\n `${definition.id}.${key} cannot have a default. Keep required behaviour in explicit repository config.`,\n );\n }\n const errors = this.validateObject(\n definition.id,\n { [key]: field },\n { [key]: tuning[key] },\n );\n if (errors.length) throw new InformAiError(errors.join('\\n'));\n }\n const errors = this.validateObject(\n definition.id,\n definition.schema,\n definition.recommendedSeed,\n );\n if (errors.length)\n throw new InformAiError(\n `Invalid recommended seed: ${errors.join('\\n')}. Fix the owner's seed; the loader never applies it.`,\n );\n }\n\n private validateSchema(location: string, schema: Readonly<Record<string, FieldDef>>): void {\n if (!schema || typeof schema !== 'object' || Array.isArray(schema))\n throw new InformAiError(`Invalid schema for ${location}. Supply a field map.`);\n for (const [key, field] of Object.entries(schema)) {\n if (\n !field ||\n !['string', 'number', 'boolean', 'string[]', 'object[]'].includes(field.type)\n ) {\n throw new InformAiError(\n `Invalid field ${location}.${key}. Supply a supported FieldDef type.`,\n );\n }\n for (const flag of ['optional', 'nullable', 'nonEmpty'] as const) {\n if (field[flag] !== undefined && typeof field[flag] !== 'boolean')\n throw new InformAiError(\n `Invalid ${flag} for ${location}.${key}. Supply a boolean.`,\n );\n }\n if (\n field.enumValues !== undefined &&\n (!Array.isArray(field.enumValues) ||\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n field.enumValues.some((item: unknown) => typeof item !== 'string'))\n ) {\n throw new InformAiError(\n `Invalid enum for ${location}.${key}. Supply string values.`,\n );\n }\n if (field.type === 'object[]')\n this.validateSchema(`${location}.${key}[]`, field.elementSchema!);\n }\n }\n\n private validateObject(\n location: string,\n schema: Readonly<Record<string, FieldDef>>,\n value: ConfigObject,\n ): string[] {\n if (!value || typeof value !== 'object' || Array.isArray(value))\n return [`${location} must be an explicitly configured object.`];\n const errors: string[] = [];\n for (const key of Object.keys(value)) {\n if (Object.hasOwn(schema, key)) continue;\n const fields = new PolicyFieldConstraints();\n const renamed = fields.renamedField(key);\n const retired = this.migrations().find(\n (entry: RetiredConfigKey) =>\n entry.scope === 'field' && entry.key === `${location}.${key}`,\n );\n if (renamed)\n errors.push(\n `${location}.${key} was renamed to ${renamed}. Rename the field; the old spelling is rejected.`,\n );\n else if (retired) errors.push(`${location}.${key}: ${retired.instruction}`);\n else if (fields.isRationale(key)) {\n if (typeof value[key] !== 'string')\n errors.push(`${location}.${key} must be a string rationale note.`);\n } else errors.push(`${location}.${key} is unknown. Use a field declared by its owner.`);\n }\n for (const [key, field] of Object.entries(schema)) {\n const entry = Object.hasOwn(value, key) ? value[key] : undefined,\n label = `${location}.${key}`;\n if (entry === undefined) {\n if (!field.optional)\n errors.push(`${label} is required. Add an explicit ${field.type} value.`);\n continue;\n }\n if (entry === null && field.nullable) continue;\n const valid = field.type.endsWith('[]')\n ? Array.isArray(entry)\n : typeof entry === field.type;\n if (!valid || entry === null) {\n errors.push(`${label} must be ${field.type}.`);\n continue;\n }\n if (field.enumValues && !field.enumValues.includes(String(entry)))\n errors.push(`${label} must be one of ${field.enumValues.join(', ')}.`);\n if (Array.isArray(entry)) {\n if (field.nonEmpty && entry.length === 0)\n errors.push(`${label} must contain at least one entry.`);\n if (\n field.type === 'string[]' &&\n entry.some((item: ConfigValue) => typeof item !== 'string')\n )\n errors.push(`${label} must contain only strings.`);\n if (field.type === 'object[]')\n entry.forEach((item: ConfigValue, index: number) =>\n errors.push(\n ...this.validateObject(\n `${label}[${index}]`,\n field.elementSchema!,\n item as ConfigObject,\n ),\n ),\n );\n }\n }\n return errors;\n }\n}\n\n/** Inject the selected module transport; discovery never names a built-in owner package. */\n@injectable(bindingScopeValues.Singleton)\nexport class RulePackDiscovery {\n constructor(private readonly loader: RulePackModuleLoader) {}\n\n discover(declarations: readonly RulePackDeclaration[]): RulePackRegistry {\n const manifests = declarations.map((declaration: RulePackDeclaration) =>\n this.loader.load(declaration.module),\n );\n const registry = new RulePackRegistry(manifests);\n manifests.forEach((manifest: RulePackManifest, index: number) =>\n registry.recordModuleLocation(manifest.packageName, declarations[index].module),\n );\n return registry;\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AtomicFile } from '@webpieces/tooling-common';
|
|
2
|
+
import { ConfigFile } from './config-file';
|
|
3
|
+
import { PackPolicyDeclaration, PackPolicyFiles } from './pack-policy-files';
|
|
4
|
+
import { RulePackArtifacts } from './rule-pack-artifacts';
|
|
5
|
+
export declare class RulePackSyncOptions {
|
|
6
|
+
readonly mode: 'sync' | 'upgrade';
|
|
7
|
+
readonly declarations: readonly PackPolicyDeclaration[] | null;
|
|
8
|
+
constructor(mode: 'sync' | 'upgrade', declarations: readonly PackPolicyDeclaration[] | null);
|
|
9
|
+
}
|
|
10
|
+
/** Explicit file mutation; normal configuration loading never calls this service. */
|
|
11
|
+
export declare class RulePackSync {
|
|
12
|
+
private readonly configFile;
|
|
13
|
+
private readonly files;
|
|
14
|
+
private readonly artifacts;
|
|
15
|
+
private readonly atomic;
|
|
16
|
+
constructor(configFile: ConfigFile, files: PackPolicyFiles, artifacts: RulePackArtifacts, atomic: AtomicFile);
|
|
17
|
+
run(root: string, options: RulePackSyncOptions): readonly string[];
|
|
18
|
+
private selectedDeclarations;
|
|
19
|
+
private upgradeDocument;
|
|
20
|
+
private legacyEntries;
|
|
21
|
+
private prepare;
|
|
22
|
+
private seedMissing;
|
|
23
|
+
private rootDocument;
|
|
24
|
+
private validateRoot;
|
|
25
|
+
private object;
|
|
26
|
+
}
|