pepr 0.55.6 → 1.0.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/dist/lib.js CHANGED
@@ -534,6 +534,9 @@ var Capability = class {
534
534
  * @param kind if using a custom KubernetesObject not available in `a.*`, specify the GroupVersionKind
535
535
  * @returns
536
536
  */
537
+ // This method intentionally defines a fluent, closure-based DSL for chaining capability actions.
538
+ // Multiple inline helper functions are required to preserve runtime behavior and readability.
539
+ // eslint-disable-next-line max-statements
537
540
  When = (model, kind3) => {
538
541
  const matchedKind = (0, import_kubernetes_fluent_client2.modelToGroupVersionKind)(model.name);
539
542
  if (!matchedKind && !kind3) {
@@ -1419,6 +1422,10 @@ var OnError = /* @__PURE__ */ ((OnError2) => {
1419
1422
  })(OnError || {});
1420
1423
 
1421
1424
  // src/lib/assets/ignoredNamespaces.ts
1425
+ function getIgnoreNamespaces(config) {
1426
+ const fromConfig = config?.alwaysIgnore?.namespaces?.length ? config.alwaysIgnore.namespaces : config?.admission?.alwaysIgnore?.namespaces;
1427
+ return resolveIgnoreNamespaces(fromConfig);
1428
+ }
1422
1429
  function resolveIgnoreNamespaces(ignoredNSConfig = []) {
1423
1430
  const ignoredNSEnv = process.env.PEPR_ADDITIONAL_IGNORED_NAMESPACES;
1424
1431
  if (!ignoredNSEnv) {
@@ -1524,9 +1531,7 @@ async function mutateProcessor(config, capabilities, req, reqMetadata) {
1524
1531
  bind.binding,
1525
1532
  bind.req,
1526
1533
  bind.namespaces,
1527
- resolveIgnoreNamespaces(
1528
- bind?.config?.alwaysIgnore?.namespaces?.length ? bind.config?.alwaysIgnore?.namespaces : bind.config?.admission?.alwaysIgnore?.namespaces
1529
- )
1534
+ getIgnoreNamespaces(config)
1530
1535
  );
1531
1536
  if (shouldSkip !== "") {
1532
1537
  logger_default.debug(shouldSkip);
@@ -1698,14 +1703,7 @@ async function validateProcessor(config, capabilities, req, reqMetadata) {
1698
1703
  if (!binding.validateCallback) {
1699
1704
  continue;
1700
1705
  }
1701
- const shouldSkip = shouldSkipRequest(
1702
- binding,
1703
- req,
1704
- namespaces,
1705
- resolveIgnoreNamespaces(
1706
- config?.alwaysIgnore?.namespaces?.length ? config?.alwaysIgnore?.namespaces : config?.admission?.alwaysIgnore?.namespaces
1707
- )
1708
- );
1706
+ const shouldSkip = shouldSkipRequest(binding, req, namespaces, getIgnoreNamespaces(config));
1709
1707
  if (shouldSkip !== "") {
1710
1708
  logger_default.debug(shouldSkip);
1711
1709
  continue;
@@ -2181,11 +2179,7 @@ var Controller = class _Controller {
2181
2179
  const startTime = MetricsCollector.observeStart();
2182
2180
  try {
2183
2181
  const request = req.body?.request || {};
2184
- const { name, namespace: namespace2, gvk } = {
2185
- name: request?.name ? `/${request.name}` : "",
2186
- namespace: request?.namespace || "",
2187
- gvk: request?.kind || { group: "", version: "", kind: "" }
2188
- };
2182
+ const { name, namespace: namespace2, gvk } = getRequestValues(request);
2189
2183
  const reqMetadata = { uid: request.uid, namespace: namespace2, name };
2190
2184
  logger_default.info(
2191
2185
  { ...reqMetadata, gvk, operation: request.operation, admissionKind },
@@ -2254,6 +2248,13 @@ var Controller = class _Controller {
2254
2248
  }
2255
2249
  }
2256
2250
  };
2251
+ function getRequestValues(request) {
2252
+ return {
2253
+ name: request?.name ? `/${request.name}` : "",
2254
+ namespace: request?.namespace || "",
2255
+ gvk: request?.kind || { group: "", version: "", kind: "" }
2256
+ };
2257
+ }
2257
2258
 
2258
2259
  // src/lib/errors.ts
2259
2260
  var ErrorList = Object.values(OnError);
@@ -2396,7 +2397,7 @@ var eventToPhaseMap = {
2396
2397
  function setupWatch(capabilities, ignoredNamespaces) {
2397
2398
  for (const capability of capabilities) {
2398
2399
  for (const binding of capability.bindings.filter((b) => b.isWatch)) {
2399
- runBinding(binding, capability.namespaces, ignoredNamespaces);
2400
+ void runBinding(binding, capability.namespaces, ignoredNamespaces);
2400
2401
  }
2401
2402
  }
2402
2403
  }
@@ -2530,52 +2531,60 @@ function createControllerHooks(opts, capabilities, ignoreNamespaces = []) {
2530
2531
  }
2531
2532
 
2532
2533
  // src/lib/core/module.ts
2533
- var PeprModule = class {
2534
+ var PeprModule = class _PeprModule {
2534
2535
  #controller;
2535
2536
  /**
2536
- * Create a new Pepr runtime
2537
+ * Initialize a new Pepr runtime module.
2537
2538
  *
2538
- * @param config The configuration for the Pepr runtime
2539
- * @param capabilities The capabilities to be loaded into the Pepr runtime
2540
- * @param opts Options for the Pepr runtime
2539
+ * @param pkg The package.json data containing Pepr configuration.
2540
+ * @param capabilities The list of capabilities to load.
2541
+ * @param opts Options for the Pepr runtime settings (e.g., deferStart).
2541
2542
  */
2542
2543
  constructor({ description, pepr }, capabilities = [], opts = {}) {
2543
- const config = (0, import_ramda13.clone)(pepr);
2544
- config.description = description;
2545
- ValidateError(config.onError);
2544
+ const config = _PeprModule.#initializeConfig(description, pepr);
2545
+ _PeprModule.#validateConfig(config);
2546
2546
  if (isBuildMode()) {
2547
- if (!process.send) {
2548
- throw new Error("process.send is not defined");
2549
- }
2550
- const exportedCapabilities = [];
2551
- for (const capability of capabilities) {
2552
- exportedCapabilities.push({
2553
- name: capability.name,
2554
- description: capability.description,
2555
- namespaces: capability.namespaces,
2556
- bindings: capability.bindings,
2557
- hasSchedule: capability.hasSchedule
2558
- });
2559
- }
2560
- process.send(exportedCapabilities);
2547
+ _PeprModule.#handleBuildMode(capabilities);
2561
2548
  return;
2562
2549
  }
2563
- const controllerHooks = createControllerHooks(
2564
- opts,
2565
- capabilities,
2566
- pepr?.alwaysIgnore?.namespaces?.length ? pepr.alwaysIgnore.namespaces : config?.watch?.alwaysIgnore?.namespaces
2567
- );
2550
+ const controllerHooks = _PeprModule.#createHooks(opts, capabilities, pepr, config);
2568
2551
  this.#controller = new Controller(config, capabilities, controllerHooks);
2569
- if (opts.deferStart) {
2570
- return;
2552
+ if (!opts.deferStart) {
2553
+ this.start();
2554
+ }
2555
+ }
2556
+ static #initializeConfig(description, pepr) {
2557
+ const config = (0, import_ramda13.clone)(pepr);
2558
+ config.description = description;
2559
+ return config;
2560
+ }
2561
+ static #validateConfig(config) {
2562
+ ValidateError(config.onError);
2563
+ }
2564
+ static #handleBuildMode(capabilities) {
2565
+ if (!process.send) {
2566
+ throw new Error("process.send is not defined");
2571
2567
  }
2572
- this.start();
2568
+ const exportedCapabilities = capabilities.map((cap) => ({
2569
+ name: cap.name,
2570
+ description: cap.description,
2571
+ namespaces: cap.namespaces,
2572
+ bindings: cap.bindings,
2573
+ hasSchedule: cap.hasSchedule
2574
+ }));
2575
+ process.send(exportedCapabilities);
2576
+ }
2577
+ static #createHooks(opts, capabilities, pepr, config) {
2578
+ const ignored = pepr?.alwaysIgnore?.namespaces?.length ? pepr.alwaysIgnore.namespaces : config?.watch?.alwaysIgnore?.namespaces;
2579
+ return createControllerHooks(opts, capabilities, ignored);
2573
2580
  }
2574
2581
  /**
2575
- * Start the Pepr runtime manually.
2576
- * Normally this is called automatically when the Pepr module is instantiated, but can be called manually if `deferStart` is set to `true` in the constructor.
2582
+ * Starts the Pepr runtime manually.
2583
+ *
2584
+ * Normally this is called automatically when the Pepr module is instantiated,
2585
+ * but it can be invoked manually if `deferStart` is set to `true` in the constructor.
2577
2586
  *
2578
- * @param port
2587
+ * @param port - The port number to start the server on (default: 3000).
2579
2588
  */
2580
2589
  start = (port = 3e3) => {
2581
2590
  this.#controller.startServer(port);