@webpieces/rules-config 0.4.952 → 0.4.953

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/rules-config",
3
- "version": "0.4.952",
3
+ "version": "0.4.953",
4
4
  "description": "Shared webpieces.config.json loader. Single source of truth for validation rule configuration consumed by @webpieces/ai-hook-rules, @webpieces/code-rules, and @webpieces/nx-webpieces-rules.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -19,9 +19,9 @@
19
19
  "inversify": "7.10.4",
20
20
  "reflect-metadata": "0.2.2",
21
21
  "minimatch": "10.0.1",
22
- "@webpieces/tooling-common": "0.4.952",
23
- "@webpieces/repo-workflow-core": "0.4.952",
24
- "@webpieces/rules-sdk": "0.4.952"
22
+ "@webpieces/tooling-common": "0.4.953",
23
+ "@webpieces/repo-workflow-core": "0.4.953",
24
+ "@webpieces/rules-sdk": "0.4.953"
25
25
  },
26
26
  "author": "Dean Hiller",
27
27
  "license": "Apache-2.0",
@@ -34,7 +34,7 @@
34
34
  "access": "public"
35
35
  },
36
36
  "devDependencies": {
37
- "@webpieces/tooling-testkit": "0.4.952"
37
+ "@webpieces/tooling-testkit": "0.4.953"
38
38
  },
39
39
  "types": "./src/index.d.ts",
40
40
  "bin": {
@@ -55,7 +55,8 @@ class RuleRuntimeModules {
55
55
  // webpieces-disable no-any-unknown -- a selected provider explicitly advertises its debug capability
56
56
  async runBuildDebug(exports, request) {
57
57
  if (!exports || typeof exports !== 'object' || !('buildDebugRuntime' in exports)) {
58
- throw new tooling_common_1.InformAiError(`The build provider for ${request.selection.rule} does not support debug runs. Use its declared policy settings and normal validation.`);
58
+ throw new tooling_common_1.InformAiError(`The build provider for ${request.selection.rule} does not support debug runs: its implementation module exports no buildDebugRuntime. ` +
59
+ 'A LocalRulePack module adds `export const buildDebugRuntime = pack.buildDebugRuntime;`; otherwise use its declared policy settings and normal validation.');
59
60
  }
60
61
  const runtime = exports.buildDebugRuntime;
61
62
  if (!runtime || typeof runtime.run !== 'function')
@@ -1 +1 @@
1
- {"version":3,"file":"rule-runtime-modules.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/rule-runtime-modules.ts"],"names":[],"mappings":";;;;AAAA,wDAAkC;AAClC,6CAA4C;AAC5C,oDAS8B;AAC9B,8DAA6E;AAE7E,yEAAoE;AACpE,iEAA6D;AAE7D,0FAA0F;AAC1F,MAAa,wBAAwB;IAEpB;IACA;IACA;IACA;IAJb,YACa,YAAoB,EACpB,oBAA4B,EAC5B,aAA4B,EAC5B,OAA0B;QAH1B,iBAAY,GAAZ,YAAY,CAAQ;QACpB,yBAAoB,GAApB,oBAAoB,CAAQ;QAC5B,kBAAa,GAAb,aAAa,CAAe;QAC5B,YAAO,GAAP,OAAO,CAAmB;IACpC,CAAC;CACP;AAPD,4DAOC;AAED,MAAsB,uBAAuB;CAG5C;AAHD,0DAGC;AAED,MAAa,2BAA4B,SAAQ,uBAAuB;IACnD,UAAU,CAAyB;IACnC,aAAa,CAAc;IAE5C,YAAY,UAAkB;QAC1B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,iDAAsB,CAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,IAAA,2BAAa,EAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,gFAAgF;IACvE,IAAI,CAAC,UAAkB,EAAE,cAAsB;QACpD,6IAA6I;QAC7I,IAAI,CAAC;YACD,MAAM,QAAQ,GACV,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;gBACrD,CAAC,CAAC,IAAI,CAAC,OAAO,CACR,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC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gBAC9B,CAAC,KAAK,CAAC,IAAI;gBACX,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC;gBAC1C,OAAO,KAAK,CAAC,SAAS,KAAK,UAAU;gBACrC,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,EACjC,CAAC;gBACC,MAAM,IAAI,8BAAa,CACnB,mFAAmF,CACtF,CAAC;YACN,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QACD,KAAK,MAAM,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChB,MAAM,IAAI,8BAAa,CACnB,yCAAyC,EAAE,qCAAqC,CACnF,CAAC;QACV,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAnHD,gDAmHC","sourcesContent":["import * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport {\n BuildPolicy,\n BuildRuleRuntime,\n BuildDebugRequest,\n BuildDebugRuntime,\n BuildPolicyResult,\n ConfigObject,\n ExecutionKind,\n PolicyRuntimeRequest,\n} from '@webpieces/rules-sdk';\nimport { InformAiError, TypeScriptRequire } from '@webpieces/tooling-common';\nimport { RulePackRegistry } from './rule-pack-registry';\nimport { ClientModuleResolution } from './client-module-resolution';\nimport { toError } from '@webpieces/tooling-common/to-error';\n\n/** Describes an implementation without evaluating its module during config validation. */\nexport class RuntimeContributionGroup {\n constructor(\n readonly providerPack: string,\n readonly implementationModule: string,\n readonly executionKind: ExecutionKind,\n readonly ruleIds: readonly string[],\n ) {}\n}\n\nexport abstract class RuleRuntimeModuleLoader {\n // webpieces-disable no-any-unknown -- execution-family consumers validate external module contracts\n abstract load(moduleName: string, providerModule: string): unknown;\n}\n\nexport class NodeRuleRuntimeModuleLoader extends RuleRuntimeModuleLoader {\n private readonly resolution: ClientModuleResolution;\n private readonly requireModule: NodeRequire;\n\n constructor(clientRoot: string) {\n super();\n this.resolution = new ClientModuleResolution(clientRoot);\n this.requireModule = createRequire(path.join(clientRoot, 'package.json'));\n }\n\n // webpieces-disable no-any-unknown -- narrowed by its execution-family consumer\n override load(moduleName: string, providerModule: string): unknown {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- a declared module fault names the runtime and declaration needed for repair\n try {\n const resolved =\n moduleName.startsWith('.') || path.isAbsolute(moduleName)\n ? path.resolve(\n path.dirname(this.resolution.resolve(providerModule)),\n moduleName,\n )\n : this.resolution.resolve(moduleName);\n return new TypeScriptRequire().load(this.requireModule, resolved);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `Cannot load declared policy runtime ${moduleName} from ${providerModule}: ${error.message}. Repair its public implementation module or root declaration.`,\n { cause: error },\n );\n }\n }\n}\n\n/** Grouped module loading has no built-in package list or policy IDs. */\nexport class RuleRuntimeModules {\n // webpieces-disable no-any-unknown -- a selected provider explicitly advertises its debug capability\n async runBuildDebug(exports: unknown, request: BuildDebugRequest): Promise<BuildPolicyResult> {\n if (!exports || typeof exports !== 'object' || !('buildDebugRuntime' in exports)) {\n throw new InformAiError(\n `The build provider for ${request.selection.rule} does not support debug runs. Use its declared policy settings and normal validation.`,\n );\n }\n const runtime = exports.buildDebugRuntime as BuildDebugRuntime;\n if (!runtime || typeof runtime.run !== 'function')\n throw new InformAiError(\n 'Invalid buildDebugRuntime.run(request). Repair the provider export.',\n );\n const result = await runtime.run(request);\n if (!result || typeof result.success !== 'boolean')\n throw new InformAiError('Debug runtime must return an explicit success boolean.');\n return result;\n }\n\n groups(registry: RulePackRegistry, kind: ExecutionKind): readonly RuntimeContributionGroup[] {\n const groups: RuntimeContributionGroup[] = [];\n for (const manifest of registry.manifests) {\n const modules = new Map<string, string[]>();\n for (const contribution of manifest.contributions) {\n if (contribution.executionKind !== kind) continue;\n const ids = modules.get(contribution.implementationModule) ?? [];\n ids.push(contribution.ruleId);\n modules.set(contribution.implementationModule, ids);\n }\n for (const entry of modules) {\n const moduleName = entry[0], ids = entry[1];\n groups.push(\n new RuntimeContributionGroup(manifest.packageName, moduleName, kind, ids),\n );\n }\n }\n return groups;\n }\n\n // webpieces-disable no-any-unknown -- transport boundary for execution-family adapters\n load(\n group: RuntimeContributionGroup,\n providers: ReadonlyMap<string, string>,\n loader: RuleRuntimeModuleLoader,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n ): unknown {\n const provider = providers.get(group.providerPack);\n if (!provider)\n throw new InformAiError(\n `Missing declared manifest module for ${group.providerPack}. Repair rulePacks.`,\n );\n return loader.load(group.implementationModule, provider);\n }\n\n request(\n root: string,\n configs: Readonly<Record<string, ConfigObject>>,\n group: RuntimeContributionGroup,\n // The repo's top-level `excludePaths` — handed to the runtime so it applies them (#1253).\n excludePaths: readonly string[],\n ): PolicyRuntimeRequest {\n const selected: Record<string, ConfigObject> = {};\n for (const id of group.ruleIds) {\n if (!Object.hasOwn(configs, id))\n throw new InformAiError(\n `Missing explicit config for ${id}. Repair its declared owner file.`,\n );\n selected[id] = configs[id];\n }\n return new PolicyRuntimeRequest(root, selected, group.ruleIds, excludePaths);\n }\n\n // webpieces-disable no-any-unknown -- public exports are validated before use; no concrete execution package is imported\n async createBuildPolicies(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n exports: unknown,\n request: PolicyRuntimeRequest,\n ): Promise<readonly BuildPolicy[]> {\n if (!exports || typeof exports !== 'object' || !('buildRuleRuntime' in exports)) {\n throw new InformAiError(\n 'Build contribution must export buildRuleRuntime.create(request). Repair its public runtime export.',\n );\n }\n const runtime = exports.buildRuleRuntime as BuildRuleRuntime;\n if (!runtime || typeof runtime.create !== 'function')\n throw new InformAiError(\n 'Invalid buildRuleRuntime.create. Supply a build runtime factory.',\n );\n const checks = await runtime.create(request);\n if (!Array.isArray(checks))\n throw new InformAiError('Build runtime must return an array of configured checks.');\n const covered = new Set<string>();\n for (const check of checks) {\n if (\n !check ||\n typeof check.name !== 'string' ||\n !check.name ||\n !request.ruleIds.includes(check.configKey) ||\n typeof check.shouldRun !== 'function' ||\n typeof check.run !== 'function'\n ) {\n throw new InformAiError(\n 'Invalid build check. Supply name, declared configKey, shouldRun(), and run(root).',\n );\n }\n covered.add(check.configKey);\n }\n for (const id of request.ruleIds) {\n if (!covered.has(id))\n throw new InformAiError(\n `Build runtime omitted declared policy ${id}. Supply its actual implementation.`,\n );\n }\n return checks;\n }\n}\n"]}
1
+ {"version":3,"file":"rule-runtime-modules.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/rule-runtime-modules.ts"],"names":[],"mappings":";;;;AAAA,wDAAkC;AAClC,6CAA4C;AAC5C,oDAS8B;AAC9B,8DAA6E;AAE7E,yEAAoE;AACpE,iEAA6D;AAE7D,0FAA0F;AAC1F,MAAa,wBAAwB;IAEpB;IACA;IACA;IACA;IAJb,YACa,YAAoB,EACpB,oBAA4B,EAC5B,aAA4B,EAC5B,OAA0B;QAH1B,iBAAY,GAAZ,YAAY,CAAQ;QACpB,yBAAoB,GAApB,oBAAoB,CAAQ;QAC5B,kBAAa,GAAb,aAAa,CAAe;QAC5B,YAAO,GAAP,OAAO,CAAmB;IACpC,CAAC;CACP;AAPD,4DAOC;AAED,MAAsB,uBAAuB;CAG5C;AAHD,0DAGC;AAED,MAAa,2BAA4B,SAAQ,uBAAuB;IACnD,UAAU,CAAyB;IACnC,aAAa,CAAc;IAE5C,YAAY,UAAkB;QAC1B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,iDAAsB,CAAC,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,aAAa,GAAG,IAAA,2BAAa,EAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,gFAAgF;IACvE,IAAI,CAAC,UAAkB,EAAE,cAAsB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QAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YACtB,MAAM,IAAI,8BAAa,CAAC,0DAA0D,CAAC,CAAC;QACxF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;QAClC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACzB,IACI,CAAC,KAAK;gBACN,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAC9B,CAAC,KAAK,CAAC,IAAI;gBACX,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC;gBAC1C,OAAO,KAAK,CAAC,SAAS,KAAK,UAAU;gBACrC,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,EACjC,CAAC;gBACC,MAAM,IAAI,8BAAa,CACnB,mFAAmF,CACtF,CAAC;YACN,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QACD,KAAK,MAAM,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChB,MAAM,IAAI,8BAAa,CACnB,yCAAyC,EAAE,qCAAqC,CACnF,CAAC;QACV,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AApHD,gDAoHC","sourcesContent":["import * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport {\n BuildPolicy,\n BuildRuleRuntime,\n BuildDebugRequest,\n BuildDebugRuntime,\n BuildPolicyResult,\n ConfigObject,\n ExecutionKind,\n PolicyRuntimeRequest,\n} from '@webpieces/rules-sdk';\nimport { InformAiError, TypeScriptRequire } from '@webpieces/tooling-common';\nimport { RulePackRegistry } from './rule-pack-registry';\nimport { ClientModuleResolution } from './client-module-resolution';\nimport { toError } from '@webpieces/tooling-common/to-error';\n\n/** Describes an implementation without evaluating its module during config validation. */\nexport class RuntimeContributionGroup {\n constructor(\n readonly providerPack: string,\n readonly implementationModule: string,\n readonly executionKind: ExecutionKind,\n readonly ruleIds: readonly string[],\n ) {}\n}\n\nexport abstract class RuleRuntimeModuleLoader {\n // webpieces-disable no-any-unknown -- execution-family consumers validate external module contracts\n abstract load(moduleName: string, providerModule: string): unknown;\n}\n\nexport class NodeRuleRuntimeModuleLoader extends RuleRuntimeModuleLoader {\n private readonly resolution: ClientModuleResolution;\n private readonly requireModule: NodeRequire;\n\n constructor(clientRoot: string) {\n super();\n this.resolution = new ClientModuleResolution(clientRoot);\n this.requireModule = createRequire(path.join(clientRoot, 'package.json'));\n }\n\n // webpieces-disable no-any-unknown -- narrowed by its execution-family consumer\n override load(moduleName: string, providerModule: string): unknown {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- a declared module fault names the runtime and declaration needed for repair\n try {\n const resolved =\n moduleName.startsWith('.') || path.isAbsolute(moduleName)\n ? path.resolve(\n path.dirname(this.resolution.resolve(providerModule)),\n moduleName,\n )\n : this.resolution.resolve(moduleName);\n return new TypeScriptRequire().load(this.requireModule, resolved);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `Cannot load declared policy runtime ${moduleName} from ${providerModule}: ${error.message}. Repair its public implementation module or root declaration.`,\n { cause: error },\n );\n }\n }\n}\n\n/** Grouped module loading has no built-in package list or policy IDs. */\nexport class RuleRuntimeModules {\n // webpieces-disable no-any-unknown -- a selected provider explicitly advertises its debug capability\n async runBuildDebug(exports: unknown, request: BuildDebugRequest): Promise<BuildPolicyResult> {\n if (!exports || typeof exports !== 'object' || !('buildDebugRuntime' in exports)) {\n throw new InformAiError(\n `The build provider for ${request.selection.rule} does not support debug runs: its implementation module exports no buildDebugRuntime. ` +\n 'A LocalRulePack module adds `export const buildDebugRuntime = pack.buildDebugRuntime;`; otherwise use its declared policy settings and normal validation.',\n );\n }\n const runtime = exports.buildDebugRuntime as BuildDebugRuntime;\n if (!runtime || typeof runtime.run !== 'function')\n throw new InformAiError(\n 'Invalid buildDebugRuntime.run(request). Repair the provider export.',\n );\n const result = await runtime.run(request);\n if (!result || typeof result.success !== 'boolean')\n throw new InformAiError('Debug runtime must return an explicit success boolean.');\n return result;\n }\n\n groups(registry: RulePackRegistry, kind: ExecutionKind): readonly RuntimeContributionGroup[] {\n const groups: RuntimeContributionGroup[] = [];\n for (const manifest of registry.manifests) {\n const modules = new Map<string, string[]>();\n for (const contribution of manifest.contributions) {\n if (contribution.executionKind !== kind) continue;\n const ids = modules.get(contribution.implementationModule) ?? [];\n ids.push(contribution.ruleId);\n modules.set(contribution.implementationModule, ids);\n }\n for (const entry of modules) {\n const moduleName = entry[0], ids = entry[1];\n groups.push(\n new RuntimeContributionGroup(manifest.packageName, moduleName, kind, ids),\n );\n }\n }\n return groups;\n }\n\n // webpieces-disable no-any-unknown -- transport boundary for execution-family adapters\n load(\n group: RuntimeContributionGroup,\n providers: ReadonlyMap<string, string>,\n loader: RuleRuntimeModuleLoader,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n ): unknown {\n const provider = providers.get(group.providerPack);\n if (!provider)\n throw new InformAiError(\n `Missing declared manifest module for ${group.providerPack}. Repair rulePacks.`,\n );\n return loader.load(group.implementationModule, provider);\n }\n\n request(\n root: string,\n configs: Readonly<Record<string, ConfigObject>>,\n group: RuntimeContributionGroup,\n // The repo's top-level `excludePaths` — handed to the runtime so it applies them (#1253).\n excludePaths: readonly string[],\n ): PolicyRuntimeRequest {\n const selected: Record<string, ConfigObject> = {};\n for (const id of group.ruleIds) {\n if (!Object.hasOwn(configs, id))\n throw new InformAiError(\n `Missing explicit config for ${id}. Repair its declared owner file.`,\n );\n selected[id] = configs[id];\n }\n return new PolicyRuntimeRequest(root, selected, group.ruleIds, excludePaths);\n }\n\n // webpieces-disable no-any-unknown -- public exports are validated before use; no concrete execution package is imported\n async createBuildPolicies(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n exports: unknown,\n request: PolicyRuntimeRequest,\n ): Promise<readonly BuildPolicy[]> {\n if (!exports || typeof exports !== 'object' || !('buildRuleRuntime' in exports)) {\n throw new InformAiError(\n 'Build contribution must export buildRuleRuntime.create(request). Repair its public runtime export.',\n );\n }\n const runtime = exports.buildRuleRuntime as BuildRuleRuntime;\n if (!runtime || typeof runtime.create !== 'function')\n throw new InformAiError(\n 'Invalid buildRuleRuntime.create. Supply a build runtime factory.',\n );\n const checks = await runtime.create(request);\n if (!Array.isArray(checks))\n throw new InformAiError('Build runtime must return an array of configured checks.');\n const covered = new Set<string>();\n for (const check of checks) {\n if (\n !check ||\n typeof check.name !== 'string' ||\n !check.name ||\n !request.ruleIds.includes(check.configKey) ||\n typeof check.shouldRun !== 'function' ||\n typeof check.run !== 'function'\n ) {\n throw new InformAiError(\n 'Invalid build check. Supply name, declared configKey, shouldRun(), and run(root).',\n );\n }\n covered.add(check.configKey);\n }\n for (const id of request.ruleIds) {\n if (!covered.has(id))\n throw new InformAiError(\n `Build runtime omitted declared policy ${id}. Supply its actual implementation.`,\n );\n }\n return checks;\n }\n}\n"]}