@n8n/expression-runtime 0.10.1 → 0.12.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.
Files changed (61) hide show
  1. package/dist/cjs/build.tsbuildinfo +1 -1
  2. package/dist/cjs/evaluator/error-classification.d.ts +3 -0
  3. package/dist/cjs/evaluator/error-classification.d.ts.map +1 -0
  4. package/dist/cjs/evaluator/error-classification.js +26 -0
  5. package/dist/cjs/evaluator/error-classification.js.map +1 -0
  6. package/dist/cjs/evaluator/expression-evaluator.d.ts.map +1 -1
  7. package/dist/cjs/evaluator/expression-evaluator.js +31 -16
  8. package/dist/cjs/evaluator/expression-evaluator.js.map +1 -1
  9. package/dist/cjs/index.d.ts +5 -0
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +8 -2
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/observability/metrics.d.ts +65 -0
  14. package/dist/cjs/observability/metrics.d.ts.map +1 -0
  15. package/dist/cjs/observability/metrics.js +70 -0
  16. package/dist/cjs/observability/metrics.js.map +1 -0
  17. package/dist/cjs/observability/noop-provider.d.ts +3 -0
  18. package/dist/cjs/observability/noop-provider.d.ts.map +1 -0
  19. package/dist/cjs/observability/noop-provider.js +39 -0
  20. package/dist/cjs/observability/noop-provider.js.map +1 -0
  21. package/dist/cjs/pool/idle-scaling-pool.d.ts +35 -0
  22. package/dist/cjs/pool/idle-scaling-pool.d.ts.map +1 -0
  23. package/dist/cjs/pool/idle-scaling-pool.js +154 -0
  24. package/dist/cjs/pool/idle-scaling-pool.js.map +1 -0
  25. package/dist/cjs/pool/isolate-pool.d.ts +9 -1
  26. package/dist/cjs/pool/isolate-pool.d.ts.map +1 -1
  27. package/dist/cjs/pool/isolate-pool.js.map +1 -1
  28. package/dist/cjs/types/evaluator.d.ts +2 -0
  29. package/dist/cjs/types/evaluator.d.ts.map +1 -1
  30. package/dist/cjs/types/evaluator.js.map +1 -1
  31. package/dist/esm/build.tsbuildinfo +1 -1
  32. package/dist/esm/evaluator/error-classification.d.ts +3 -0
  33. package/dist/esm/evaluator/error-classification.d.ts.map +1 -0
  34. package/dist/esm/evaluator/error-classification.js +13 -0
  35. package/dist/esm/evaluator/error-classification.js.map +1 -0
  36. package/dist/esm/evaluator/expression-evaluator.d.ts.map +1 -1
  37. package/dist/esm/evaluator/expression-evaluator.js +30 -15
  38. package/dist/esm/evaluator/expression-evaluator.js.map +1 -1
  39. package/dist/esm/index.d.ts +5 -0
  40. package/dist/esm/index.d.ts.map +1 -1
  41. package/dist/esm/index.js +3 -0
  42. package/dist/esm/index.js.map +1 -1
  43. package/dist/esm/observability/metrics.d.ts +65 -0
  44. package/dist/esm/observability/metrics.d.ts.map +1 -0
  45. package/dist/esm/observability/metrics.js +57 -0
  46. package/dist/esm/observability/metrics.js.map +1 -0
  47. package/dist/esm/observability/noop-provider.d.ts +3 -0
  48. package/dist/esm/observability/noop-provider.d.ts.map +1 -0
  49. package/dist/esm/observability/noop-provider.js +26 -0
  50. package/dist/esm/observability/noop-provider.js.map +1 -0
  51. package/dist/esm/pool/idle-scaling-pool.d.ts +35 -0
  52. package/dist/esm/pool/idle-scaling-pool.d.ts.map +1 -0
  53. package/dist/esm/pool/idle-scaling-pool.js +140 -0
  54. package/dist/esm/pool/idle-scaling-pool.js.map +1 -0
  55. package/dist/esm/pool/isolate-pool.d.ts +9 -1
  56. package/dist/esm/pool/isolate-pool.d.ts.map +1 -1
  57. package/dist/esm/pool/isolate-pool.js.map +1 -1
  58. package/dist/esm/types/evaluator.d.ts +2 -0
  59. package/dist/esm/types/evaluator.d.ts.map +1 -1
  60. package/dist/esm/types/evaluator.js.map +1 -1
  61. package/package.json +5 -5
@@ -0,0 +1,3 @@
1
+ export type ExpressionErrorType = 'timeout' | 'memory_limit' | 'security' | 'syntax' | 'unknown';
2
+ export declare function classifyExpressionError(error: unknown): ExpressionErrorType;
3
+ //# sourceMappingURL=error-classification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-classification.d.ts","sourceRoot":"","sources":["../../../src/evaluator/error-classification.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEjG,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAM3E"}
@@ -0,0 +1,26 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../types"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.classifyExpressionError = classifyExpressionError;
13
+ const types_1 = require("../types");
14
+ function classifyExpressionError(error) {
15
+ if (error instanceof types_1.TimeoutError)
16
+ return 'timeout';
17
+ if (error instanceof types_1.MemoryLimitError)
18
+ return 'memory_limit';
19
+ if (error instanceof types_1.SecurityViolationError)
20
+ return 'security';
21
+ if (error instanceof types_1.SyntaxError)
22
+ return 'syntax';
23
+ return 'unknown';
24
+ }
25
+ });
26
+ //# sourceMappingURL=error-classification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-classification.js","sourceRoot":"","sources":["../../../src/evaluator/error-classification.ts"],"names":[],"mappings":";;;;;;;;;;;IAIA,0DAMC;IAVD,oCAA+F;IAI/F,SAAgB,uBAAuB,CAAC,KAAc;QACrD,IAAI,KAAK,YAAY,oBAAY;YAAE,OAAO,SAAS,CAAC;QACpD,IAAI,KAAK,YAAY,wBAAgB;YAAE,OAAO,cAAc,CAAC;QAC7D,IAAI,KAAK,YAAY,8BAAsB;YAAE,OAAO,UAAU,CAAC;QAC/D,IAAI,KAAK,YAAY,mBAAW;YAAE,OAAO,QAAQ,CAAC;QAClD,OAAO,SAAS,CAAC;IAClB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"expression-evaluator.d.ts","sourceRoot":"","sources":["../../../src/evaluator/expression-evaluator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,eAAe,EAEf,MAAM,UAAU,CAAC;AAMlB,qBAAa,mBAAoB,YAAW,oBAAoB;IAC/D,OAAO,CAAC,MAAM,CAAkB;IAEhC,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,UAAU,CAAC,CAAa;IAIhC,OAAO,CAAC,SAAS,CAA2B;IAE5C,OAAO,CAAC,IAAI,CAAc;IAE1B,OAAO,CAAC,eAAe,CAAwC;IAE/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA+B;gBAEhD,MAAM,EAAE,eAAe;IAsB7B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5C,QAAQ,CACP,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO;IA0BV,OAAO,CAAC,SAAS;IAeX,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IA2BpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B,UAAU,IAAI,OAAO;CAGrB"}
1
+ {"version":3,"file":"expression-evaluator.d.ts","sourceRoot":"","sources":["../../../src/evaluator/expression-evaluator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,eAAe,EAGf,MAAM,UAAU,CAAC;AAyBlB,qBAAa,mBAAoB,YAAW,oBAAoB;IAC/D,OAAO,CAAC,MAAM,CAAkB;IAEhC,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,UAAU,CAAC,CAAa;IAIhC,OAAO,CAAC,SAAS,CAA2B;IAE5C,OAAO,CAAC,IAAI,CAAQ;IAEpB,OAAO,CAAC,eAAe,CAAwC;IAE/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA+B;gBAEhD,MAAM,EAAE,eAAe;IA8B7B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5C,QAAQ,CACP,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO;IAuBV,OAAO,CAAC,SAAS;IAeX,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IA8BpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO9B,UAAU,IAAI,OAAO;CAGrB"}
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@n8n/tournament", "../types/bridge", "@n8n/errors", "../pool/isolate-pool", "./lru-cache"], factory);
7
+ define(["require", "exports", "@n8n/tournament", "../types/bridge", "@n8n/errors", "../pool/idle-scaling-pool", "../pool/isolate-pool", "../observability/metrics", "./error-classification", "./lru-cache"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -13,8 +13,21 @@
13
13
  const tournament_1 = require("@n8n/tournament");
14
14
  const bridge_1 = require("../types/bridge");
15
15
  const errors_1 = require("@n8n/errors");
16
+ const idle_scaling_pool_1 = require("../pool/idle-scaling-pool");
16
17
  const isolate_pool_1 = require("../pool/isolate-pool");
18
+ const metrics_1 = require("../observability/metrics");
19
+ const error_classification_1 = require("./error-classification");
17
20
  const lru_cache_1 = require("./lru-cache");
21
+ function recordOutcome(observability, start, status, error) {
22
+ if (!observability)
23
+ return;
24
+ const durationSeconds = (performance.now() - start) / 1000;
25
+ const errorType = error !== undefined ? (0, error_classification_1.classifyExpressionError)(error) : undefined;
26
+ observability.metrics.histogram(metrics_1.EXPRESSION_METRICS.evaluationDuration.name, durationSeconds, {
27
+ status,
28
+ type: errorType ?? 'none',
29
+ });
30
+ }
18
31
  class ExpressionEvaluator {
19
32
  config;
20
33
  disposed = false;
@@ -29,7 +42,7 @@
29
42
  constructor(config) {
30
43
  this.config = config;
31
44
  this.codeCache = new lru_cache_1.LruCache(config.maxCodeCacheSize, () => {
32
- this.config.observability?.metrics.counter('expression.code_cache.eviction', 1);
45
+ this.config.observability?.metrics.counter(metrics_1.EXPRESSION_METRICS.codeCacheEviction.name, 1);
33
46
  });
34
47
  const logger = config.logger ?? bridge_1.DEFAULT_BRIDGE_CONFIG.logger;
35
48
  this.createBridge = async () => {
@@ -37,10 +50,14 @@
37
50
  await bridge.initialize();
38
51
  return bridge;
39
52
  };
40
- this.pool = new isolate_pool_1.IsolatePool(this.createBridge, config.poolSize ?? 1, (error) => {
53
+ const onReplenishFailed = (error) => {
41
54
  logger.error('[IsolatePool] Failed to replenish bridge', { error });
42
- config.observability?.metrics.counter('expression.pool.replenish_failed', 1);
43
- }, logger);
55
+ config.observability?.metrics.counter(metrics_1.EXPRESSION_METRICS.poolReplenishFailed.name, 1);
56
+ };
57
+ this.pool =
58
+ config.idleTimeoutMs === undefined
59
+ ? new isolate_pool_1.IsolatePool(this.createBridge, config.poolSize ?? 1, onReplenishFailed, logger)
60
+ : new idle_scaling_pool_1.IdleScalingPool(this.createBridge, config.poolSize ?? 1, config.idleTimeoutMs, onReplenishFailed, logger, config.observability);
44
61
  }
45
62
  async initialize() {
46
63
  await this.pool.initialize();
@@ -59,7 +76,7 @@
59
76
  throw error;
60
77
  bridge = await this.createBridge();
61
78
  }
62
- this.config.observability?.metrics.counter('expression.pool.acquired', 1);
79
+ this.config.observability?.metrics.counter(metrics_1.EXPRESSION_METRICS.poolAcquired.name, 1);
63
80
  this.bridgesByCaller.set(caller, bridge);
64
81
  }
65
82
  evaluate(expression, data, caller, options) {
@@ -68,19 +85,17 @@
68
85
  const bridge = this.getBridge(caller);
69
86
  // Transform template expression → sanitized JavaScript (cached)
70
87
  const transformedCode = this.getTransformedCode(expression);
88
+ const { observability } = this.config;
89
+ const start = performance.now();
71
90
  try {
72
91
  const result = bridge.execute(transformedCode, data, {
73
92
  timezone: options?.timezone,
74
93
  });
75
- if (this.config.observability) {
76
- this.config.observability.metrics.counter('expression.evaluation.success', 1);
77
- }
94
+ recordOutcome(observability, start, 'success');
78
95
  return result;
79
96
  }
80
97
  catch (error) {
81
- if (this.config.observability) {
82
- this.config.observability.metrics.counter('expression.evaluation.error', 1);
83
- }
98
+ recordOutcome(observability, start, 'error', error);
84
99
  throw error;
85
100
  }
86
101
  }
@@ -118,10 +133,10 @@
118
133
  getTransformedCode(expression) {
119
134
  const cached = this.codeCache.get(expression);
120
135
  if (cached !== undefined) {
121
- this.config.observability?.metrics.counter('expression.code_cache.hit', 1);
136
+ this.config.observability?.metrics.counter(metrics_1.EXPRESSION_METRICS.codeCacheHit.name, 1);
122
137
  return cached;
123
138
  }
124
- this.config.observability?.metrics.counter('expression.code_cache.miss', 1);
139
+ this.config.observability?.metrics.counter(metrics_1.EXPRESSION_METRICS.codeCacheMiss.name, 1);
125
140
  if (!this.tournament) {
126
141
  // Tournament requires an errorHandler but we only use getExpressionCode()
127
142
  // for AST transformation — we never call tournament.execute(), so this
@@ -135,13 +150,13 @@
135
150
  }
136
151
  const [transformedCode] = this.tournament.getExpressionCode(expression);
137
152
  this.codeCache.set(expression, transformedCode);
138
- this.config.observability?.metrics.gauge('expression.code_cache.size', this.codeCache.size);
153
+ this.config.observability?.metrics.gauge(metrics_1.EXPRESSION_METRICS.codeCacheSize.name, this.codeCache.size);
139
154
  return transformedCode;
140
155
  }
141
156
  async dispose() {
142
157
  this.disposed = true;
143
158
  this.codeCache.clear();
144
- this.config.observability?.metrics.gauge('expression.code_cache.size', 0);
159
+ this.config.observability?.metrics.gauge(metrics_1.EXPRESSION_METRICS.codeCacheSize.name, 0);
145
160
  await this.pool.dispose();
146
161
  }
147
162
  isDisposed() {
@@ -1 +1 @@
1
- {"version":3,"file":"expression-evaluator.js","sourceRoot":"","sources":["../../../src/evaluator/expression-evaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,gDAA6C;IAQ7C,4CAAwD;IACxD,wCAA2C;IAC3C,uDAA0F;IAC1F,2CAAuC;IAEvC,MAAa,mBAAmB;QACvB,MAAM,CAAkB;QAExB,QAAQ,GAAG,KAAK,CAAC;QAEzB,wFAAwF;QAChF,UAAU,CAAc;QAEhC,sEAAsE;QACtE,mFAAmF;QAC3E,SAAS,CAA2B;QAEpC,IAAI,CAAc;QAElB,eAAe,GAAG,IAAI,OAAO,EAAyB,CAAC;QAE9C,YAAY,CAA+B;QAE5D,YAAY,MAAuB;YAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,IAAI,oBAAQ,CAAiB,MAAM,CAAC,gBAAgB,EAAE,GAAG,EAAE;gBAC3E,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,gCAAgC,EAAE,CAAC,CAAC,CAAC;YACjF,CAAC,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,8BAAqB,CAAC,MAAM,CAAC;YAC7D,IAAI,CAAC,YAAY,GAAG,KAAK,IAAI,EAAE;gBAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;gBACrC,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;gBAC1B,OAAO,MAAM,CAAC;YACf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M,CAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CACvC,4BAAkB,CAAC,aAAa,CAAC,IAAI,EACrC,IAAI,CAAC,SAAS,CAAC,IAAI,CACnB,CAAC;YACF,OAAO,eAAe,CAAC;QACxB,CAAC;QAED,KAAK,CAAC,OAAO;YACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC,4BAAkB,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YACnF,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QAED,UAAU;YACT,OAAO,IAAI,CAAC,QAAQ,CAAC;QACtB,CAAC;KACD;IAzKD,kDAyKC"}
@@ -3,6 +3,11 @@ export { IsolatedVmBridge } from './bridge/isolated-vm-bridge';
3
3
  export type { IExpressionEvaluator, EvaluatorConfig, WorkflowData, EvaluateOptions, ExecuteOptions, RuntimeBridge, BridgeConfig, Logger, ObservabilityProvider, MetricsAPI, TracesAPI, Span, LogsAPI, } from './types';
4
4
  export { ExpressionError, MemoryLimitError, TimeoutError, SecurityViolationError, SyntaxError, } from './types';
5
5
  export { IsolateError } from '@n8n/errors';
6
+ export { NoOpProvider } from './observability/noop-provider';
7
+ export { EXPRESSION_METRICS } from './observability/metrics';
8
+ export type { ExpressionMetricDef, ExpressionMetricKey, MetricDef } from './observability/metrics';
9
+ export { classifyExpressionError } from './evaluator/error-classification';
10
+ export type { ExpressionErrorType } from './evaluator/error-classification';
6
11
  export { extend, extendOptional, EXTENSION_OBJECTS } from './extensions/extend';
7
12
  export { ExpressionExtensionError } from './extensions/expression-extension-error';
8
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,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AE,MAAM,yBAAyB,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,YAAY,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAG5E,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC"}
package/dist/cjs/index.js CHANGED
@@ -4,12 +4,12 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./evaluator/expression-evaluator", "./bridge/isolated-vm-bridge", "./types", "@n8n/errors", "./extensions/extend", "./extensions/expression-extension-error"], factory);
7
+ define(["require", "exports", "./evaluator/expression-evaluator", "./bridge/isolated-vm-bridge", "./types", "@n8n/errors", "./observability/noop-provider", "./observability/metrics", "./evaluator/error-classification", "./extensions/extend", "./extensions/expression-extension-error"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ExpressionExtensionError = exports.EXTENSION_OBJECTS = exports.extendOptional = exports.extend = exports.IsolateError = exports.SyntaxError = exports.SecurityViolationError = exports.TimeoutError = exports.MemoryLimitError = exports.ExpressionError = exports.IsolatedVmBridge = exports.ExpressionEvaluator = void 0;
12
+ exports.ExpressionExtensionError = exports.EXTENSION_OBJECTS = exports.extendOptional = exports.extend = exports.classifyExpressionError = exports.EXPRESSION_METRICS = exports.NoOpProvider = exports.IsolateError = exports.SyntaxError = exports.SecurityViolationError = exports.TimeoutError = exports.MemoryLimitError = exports.ExpressionError = exports.IsolatedVmBridge = exports.ExpressionEvaluator = void 0;
13
13
  // Main exports
14
14
  var expression_evaluator_1 = require("./evaluator/expression-evaluator");
15
15
  Object.defineProperty(exports, "ExpressionEvaluator", { enumerable: true, get: function () { return expression_evaluator_1.ExpressionEvaluator; } });
@@ -26,6 +26,12 @@
26
26
  Object.defineProperty(exports, "SyntaxError", { enumerable: true, get: function () { return types_1.SyntaxError; } });
27
27
  var errors_1 = require("@n8n/errors");
28
28
  Object.defineProperty(exports, "IsolateError", { enumerable: true, get: function () { return errors_1.IsolateError; } });
29
+ var noop_provider_1 = require("./observability/noop-provider");
30
+ Object.defineProperty(exports, "NoOpProvider", { enumerable: true, get: function () { return noop_provider_1.NoOpProvider; } });
31
+ var metrics_1 = require("./observability/metrics");
32
+ Object.defineProperty(exports, "EXPRESSION_METRICS", { enumerable: true, get: function () { return metrics_1.EXPRESSION_METRICS; } });
33
+ var error_classification_1 = require("./evaluator/error-classification");
34
+ Object.defineProperty(exports, "classifyExpressionError", { enumerable: true, get: function () { return error_classification_1.classifyExpressionError; } });
29
35
  // Extension runtime exports
30
36
  var extend_1 = require("./extensions/extend");
31
37
  Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return extend_1.extend; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,eAAe;IACf,yEAAuE;IAA9D,2HAAA,mBAAmB,OAAA;IAE5B,uEAAuE;IACvE,6EAA6E;IAC7E,kEAA+D;IAAtD,sHAAA,gBAAgB,OAAA;IAmBzB,cAAc;IACd,iCAMiB;IALhB,wGAAA,eAAe,OAAA;IACf,yGAAA,gBAAgB,OAAA;IAChB,qGAAA,YAAY,OAAA;IACZ,+GAAA,sBAAsB,OAAA;IACtB,oGAAA,WAAW,OAAA;IAEZ,sCAA2C;IAAlC,sGAAA,YAAY,OAAA;IAErB,4BAA4B;IAC5B,8CAAgF;IAAvE,gGAAA,MAAM,OAAA;IAAE,wGAAA,cAAc,OAAA;IAAE,2GAAA,iBAAiB,OAAA;IAClD,sFAAmF;IAA1E,sIAAA,wBAAwB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,eAAe;IACf,yEAAuE;IAA9D,2HAAA,mBAAmB,OAAA;IAE5B,uEAAuE;IACvE,6EAA6E;IAC7E,kEAA+D;IAAtD,sHAAA,gBAAgB,OAAA;IAmBzB,cAAc;IACd,iCAMiB;IALhB,wGAAA,eAAe,OAAA;IACf,yGAAA,gBAAgB,OAAA;IAChB,qGAAA,YAAY,OAAA;IACZ,+GAAA,sBAAsB,OAAA;IACtB,oGAAA,WAAW,OAAA;IAEZ,sCAA2C;IAAlC,sGAAA,YAAY,OAAA;IAErB,+DAA6D;IAApD,6GAAA,YAAY,OAAA;IACrB,mDAA6D;IAApD,6GAAA,kBAAkB,OAAA;IAE3B,yEAA2E;IAAlE,+HAAA,uBAAuB,OAAA;IAGhC,4BAA4B;IAC5B,8CAAgF;IAAvE,gGAAA,MAAM,OAAA;IAAE,wGAAA,cAAc,OAAA;IAAE,2GAAA,iBAAiB,OAAA;IAClD,sFAAmF;IAA1E,sIAAA,wBAAwB,OAAA"}
@@ -0,0 +1,65 @@
1
+ export interface MetricDef {
2
+ name: string;
3
+ kind: 'counter' | 'gauge' | 'histogram';
4
+ labels: readonly string[];
5
+ help: string;
6
+ }
7
+ export declare const EXPRESSION_METRICS: {
8
+ readonly evaluationDuration: {
9
+ readonly name: "expression.evaluation.duration_seconds";
10
+ readonly kind: "histogram";
11
+ readonly labels: readonly ["status", "type"];
12
+ readonly help: "Duration of VM-based expression evaluation in seconds.";
13
+ };
14
+ readonly codeCacheHit: {
15
+ readonly name: "expression.code_cache.hit";
16
+ readonly kind: "counter";
17
+ readonly labels: readonly [];
18
+ readonly help: "Expression code cache hits.";
19
+ };
20
+ readonly codeCacheMiss: {
21
+ readonly name: "expression.code_cache.miss";
22
+ readonly kind: "counter";
23
+ readonly labels: readonly [];
24
+ readonly help: "Expression code cache misses.";
25
+ };
26
+ readonly codeCacheEviction: {
27
+ readonly name: "expression.code_cache.eviction";
28
+ readonly kind: "counter";
29
+ readonly labels: readonly [];
30
+ readonly help: "Expression code cache evictions.";
31
+ };
32
+ readonly codeCacheSize: {
33
+ readonly name: "expression.code_cache.size";
34
+ readonly kind: "gauge";
35
+ readonly labels: readonly [];
36
+ readonly help: "Current expression code cache size.";
37
+ };
38
+ readonly poolAcquired: {
39
+ readonly name: "expression.pool.acquired";
40
+ readonly kind: "counter";
41
+ readonly labels: readonly [];
42
+ readonly help: "Bridges acquired from the expression pool.";
43
+ };
44
+ readonly poolReplenishFailed: {
45
+ readonly name: "expression.pool.replenish_failed";
46
+ readonly kind: "counter";
47
+ readonly labels: readonly [];
48
+ readonly help: "Failed pool bridge replenishments.";
49
+ };
50
+ readonly poolScaledUp: {
51
+ readonly name: "expression.pool.scaled_up";
52
+ readonly kind: "counter";
53
+ readonly labels: readonly [];
54
+ readonly help: "Expression pool scaled up from idle.";
55
+ };
56
+ readonly poolScaledToZero: {
57
+ readonly name: "expression.pool.scaled_to_zero";
58
+ readonly kind: "counter";
59
+ readonly labels: readonly [];
60
+ readonly help: "Expression pool scaled to zero after inactivity.";
61
+ };
62
+ };
63
+ export type ExpressionMetricKey = keyof typeof EXPRESSION_METRICS;
64
+ export type ExpressionMetricDef = (typeof EXPRESSION_METRICS)[ExpressionMetricKey];
65
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/observability/metrics.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;IACxC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDe,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,kBAAkB,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,70 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EXPRESSION_METRICS = void 0;
13
+ exports.EXPRESSION_METRICS = {
14
+ evaluationDuration: {
15
+ name: 'expression.evaluation.duration_seconds',
16
+ kind: 'histogram',
17
+ labels: ['status', 'type'],
18
+ help: 'Duration of VM-based expression evaluation in seconds.',
19
+ },
20
+ codeCacheHit: {
21
+ name: 'expression.code_cache.hit',
22
+ kind: 'counter',
23
+ labels: [],
24
+ help: 'Expression code cache hits.',
25
+ },
26
+ codeCacheMiss: {
27
+ name: 'expression.code_cache.miss',
28
+ kind: 'counter',
29
+ labels: [],
30
+ help: 'Expression code cache misses.',
31
+ },
32
+ codeCacheEviction: {
33
+ name: 'expression.code_cache.eviction',
34
+ kind: 'counter',
35
+ labels: [],
36
+ help: 'Expression code cache evictions.',
37
+ },
38
+ codeCacheSize: {
39
+ name: 'expression.code_cache.size',
40
+ kind: 'gauge',
41
+ labels: [],
42
+ help: 'Current expression code cache size.',
43
+ },
44
+ poolAcquired: {
45
+ name: 'expression.pool.acquired',
46
+ kind: 'counter',
47
+ labels: [],
48
+ help: 'Bridges acquired from the expression pool.',
49
+ },
50
+ poolReplenishFailed: {
51
+ name: 'expression.pool.replenish_failed',
52
+ kind: 'counter',
53
+ labels: [],
54
+ help: 'Failed pool bridge replenishments.',
55
+ },
56
+ poolScaledUp: {
57
+ name: 'expression.pool.scaled_up',
58
+ kind: 'counter',
59
+ labels: [],
60
+ help: 'Expression pool scaled up from idle.',
61
+ },
62
+ poolScaledToZero: {
63
+ name: 'expression.pool.scaled_to_zero',
64
+ kind: 'counter',
65
+ labels: [],
66
+ help: 'Expression pool scaled to zero after inactivity.',
67
+ },
68
+ };
69
+ });
70
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/observability/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;IAOa,QAAA,kBAAkB,GAAG;QACjC,kBAAkB,EAAE;YACnB,IAAI,EAAE,wCAAwC;YAC9C,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC;YAC1B,IAAI,EAAE,wDAAwD;SAC9D;QACD,YAAY,EAAE;YACb,IAAI,EAAE,2BAA2B;YACjC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,6BAA6B;SACnC;QACD,aAAa,EAAE;YACd,IAAI,EAAE,4BAA4B;YAClC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,+BAA+B;SACrC;QACD,iBAAiB,EAAE;YAClB,IAAI,EAAE,gCAAgC;YACtC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,kCAAkC;SACxC;QACD,aAAa,EAAE;YACd,IAAI,EAAE,4BAA4B;YAClC,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,qCAAqC;SAC3C;QACD,YAAY,EAAE;YACb,IAAI,EAAE,0BAA0B;YAChC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,4CAA4C;SAClD;QACD,mBAAmB,EAAE;YACpB,IAAI,EAAE,kCAAkC;YACxC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,oCAAoC;SAC1C;QACD,YAAY,EAAE;YACb,IAAI,EAAE,2BAA2B;YACjC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,sCAAsC;SAC5C;QACD,gBAAgB,EAAE;YACjB,IAAI,EAAE,gCAAgC;YACtC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,kDAAkD;SACxD;KAC4C,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ObservabilityProvider } from '../types';
2
+ export declare const NoOpProvider: ObservabilityProvider;
3
+ //# sourceMappingURL=noop-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-provider.d.ts","sourceRoot":"","sources":["../../../src/observability/noop-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,qBAAqB,EAAmB,MAAM,UAAU,CAAC;AA0B5F,eAAO,MAAM,YAAY,EAAE,qBAI1B,CAAC"}
@@ -0,0 +1,39 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.NoOpProvider = void 0;
13
+ const noopSpan = {
14
+ setStatus() { },
15
+ setAttribute() { },
16
+ recordException() { },
17
+ end() { },
18
+ };
19
+ const noopMetrics = {
20
+ counter() { },
21
+ gauge() { },
22
+ histogram() { },
23
+ };
24
+ const noopTraces = {
25
+ startSpan: () => noopSpan,
26
+ };
27
+ const noopLogs = {
28
+ error() { },
29
+ warn() { },
30
+ info() { },
31
+ debug() { },
32
+ };
33
+ exports.NoOpProvider = {
34
+ metrics: noopMetrics,
35
+ traces: noopTraces,
36
+ logs: noopLogs,
37
+ };
38
+ });
39
+ //# sourceMappingURL=noop-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-provider.js","sourceRoot":"","sources":["../../../src/observability/noop-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;IAEA,MAAM,QAAQ,GAAS;QACtB,SAAS,KAAI,CAAC;QACd,YAAY,KAAI,CAAC;QACjB,eAAe,KAAI,CAAC;QACpB,GAAG,KAAI,CAAC;KACR,CAAC;IAEF,MAAM,WAAW,GAAe;QAC/B,OAAO,KAAI,CAAC;QACZ,KAAK,KAAI,CAAC;QACV,SAAS,KAAI,CAAC;KACd,CAAC;IAEF,MAAM,UAAU,GAAc;QAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ;KACzB,CAAC;IAEF,MAAM,QAAQ,GAAY;QACzB,KAAK,KAAI,CAAC;QACV,IAAI,KAAI,CAAC;QACT,IAAI,KAAI,CAAC;QACT,KAAK,KAAI,CAAC;KACV,CAAC;IAEW,QAAA,YAAY,GAA0B;QAClD,OAAO,EAAE,WAAW;QACpB,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,QAAQ;KACd,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { ObservabilityProvider, RuntimeBridge } from '../types';
2
+ import type { Logger } from '../types/bridge';
3
+ import type { IPool } from './isolate-pool';
4
+ /**
5
+ * Wraps an `IsolatePool`, disposing it after a configured idle period and
6
+ * recreating it on the next acquire. The inner pool either fully exists or
7
+ * does not; callers never observe a partial state.
8
+ */
9
+ export declare class IdleScalingPool implements IPool {
10
+ private readonly createBridge;
11
+ private readonly size;
12
+ private readonly idleTimeoutMs?;
13
+ private readonly onReplenishFailed?;
14
+ private readonly logger?;
15
+ private readonly observability?;
16
+ private innerPool;
17
+ private pendingScaleUp;
18
+ private pendingScaleDown;
19
+ private idleTimer?;
20
+ private disposed;
21
+ private disposePromise?;
22
+ constructor(createBridge: () => Promise<RuntimeBridge>, size: number, idleTimeoutMs?: number | undefined, onReplenishFailed?: ((error: unknown) => void) | undefined, logger?: Logger | undefined, observability?: ObservabilityProvider | undefined);
23
+ initialize(): Promise<void>;
24
+ acquire(): RuntimeBridge;
25
+ release(bridge: RuntimeBridge): Promise<void>;
26
+ dispose(): Promise<void>;
27
+ private doDispose;
28
+ waitForReplenishment(): Promise<void>;
29
+ private drainPendingTransitions;
30
+ private createInnerPool;
31
+ private resetIdleTimer;
32
+ private triggerScaleUp;
33
+ private triggerScaleDown;
34
+ }
35
+ //# sourceMappingURL=idle-scaling-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle-scaling-pool.d.ts","sourceRoot":"","sources":["../../../src/pool/idle-scaling-pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAG5C;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,KAAK;IAS3C,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;IAbhC,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,cAAc,CAAC,CAAgB;gBAGrB,YAAY,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,EAC1C,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,MAAM,YAAA,EACtB,iBAAiB,CAAC,GAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,aAAA,EAC5C,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,aAAa,CAAC,EAAE,qBAAqB,YAAA;IAGjD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC,OAAO,IAAI,aAAa;IAUlB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAIhB,SAAS;IAcjB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;YAK7B,uBAAuB;IAUrC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAyBtB,OAAO,CAAC,gBAAgB;CAkBxB"}
@@ -0,0 +1,154 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../observability/metrics", "./isolate-pool"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.IdleScalingPool = void 0;
13
+ const metrics_1 = require("../observability/metrics");
14
+ const isolate_pool_1 = require("./isolate-pool");
15
+ /**
16
+ * Wraps an `IsolatePool`, disposing it after a configured idle period and
17
+ * recreating it on the next acquire. The inner pool either fully exists or
18
+ * does not; callers never observe a partial state.
19
+ */
20
+ class IdleScalingPool {
21
+ createBridge;
22
+ size;
23
+ idleTimeoutMs;
24
+ onReplenishFailed;
25
+ logger;
26
+ observability;
27
+ innerPool = null;
28
+ pendingScaleUp = null;
29
+ pendingScaleDown = null;
30
+ idleTimer;
31
+ disposed = false;
32
+ disposePromise;
33
+ constructor(createBridge, size, idleTimeoutMs, onReplenishFailed, logger, observability) {
34
+ this.createBridge = createBridge;
35
+ this.size = size;
36
+ this.idleTimeoutMs = idleTimeoutMs;
37
+ this.onReplenishFailed = onReplenishFailed;
38
+ this.logger = logger;
39
+ this.observability = observability;
40
+ }
41
+ async initialize() {
42
+ this.innerPool = this.createInnerPool();
43
+ await this.innerPool.initialize();
44
+ this.resetIdleTimer();
45
+ }
46
+ acquire() {
47
+ if (this.disposed)
48
+ throw new isolate_pool_1.PoolDisposedError();
49
+ if (!this.innerPool) {
50
+ this.triggerScaleUp();
51
+ throw new isolate_pool_1.PoolExhaustedError();
52
+ }
53
+ this.resetIdleTimer();
54
+ return this.innerPool.acquire();
55
+ }
56
+ async release(bridge) {
57
+ if (this.innerPool && !this.disposed) {
58
+ // Pool is live: delegate so the inner pool disposes and replenishes.
59
+ await this.innerPool.release(bridge);
60
+ }
61
+ else if (!bridge.isDisposed()) {
62
+ // Pool is idle, disposed, or the bridge came from cold-start fallback:
63
+ // no pool to delegate to, just dispose to free the V8 isolate.
64
+ await bridge.dispose();
65
+ }
66
+ }
67
+ async dispose() {
68
+ return (this.disposePromise ??= this.doDispose());
69
+ }
70
+ async doDispose() {
71
+ this.disposed = true;
72
+ if (this.idleTimer) {
73
+ clearTimeout(this.idleTimer);
74
+ this.idleTimer = undefined;
75
+ }
76
+ await this.drainPendingTransitions();
77
+ if (this.innerPool) {
78
+ const toDispose = this.innerPool;
79
+ this.innerPool = null;
80
+ await toDispose.dispose();
81
+ }
82
+ }
83
+ async waitForReplenishment() {
84
+ await this.drainPendingTransitions();
85
+ if (this.innerPool)
86
+ await this.innerPool.waitForReplenishment();
87
+ }
88
+ async drainPendingTransitions() {
89
+ // Snapshot both fields before awaiting so a transition starting between reads
90
+ // can't be missed. Waits for transitions in flight now, not ones started later.
91
+ const promises = [];
92
+ if (this.pendingScaleUp)
93
+ promises.push(this.pendingScaleUp.catch(() => { }));
94
+ if (this.pendingScaleDown)
95
+ promises.push(this.pendingScaleDown.catch(() => { }));
96
+ await Promise.all(promises);
97
+ }
98
+ createInnerPool() {
99
+ return new isolate_pool_1.IsolatePool(this.createBridge, this.size, this.onReplenishFailed, this.logger);
100
+ }
101
+ resetIdleTimer() {
102
+ if (this.idleTimeoutMs === undefined)
103
+ return;
104
+ if (this.idleTimer)
105
+ clearTimeout(this.idleTimer);
106
+ this.idleTimer = setTimeout(() => this.triggerScaleDown(), this.idleTimeoutMs);
107
+ this.idleTimer.unref();
108
+ }
109
+ triggerScaleUp() {
110
+ if (this.pendingScaleUp || this.innerPool || this.disposed)
111
+ return;
112
+ this.logger?.info('[IdleScalingPool] Scaling up from idle');
113
+ this.observability?.metrics.counter(metrics_1.EXPRESSION_METRICS.poolScaledUp.name, 1);
114
+ const newInner = this.createInnerPool();
115
+ this.pendingScaleUp = newInner
116
+ .initialize()
117
+ .then(async () => {
118
+ if (this.disposed) {
119
+ await newInner.dispose();
120
+ return;
121
+ }
122
+ this.innerPool = newInner;
123
+ this.resetIdleTimer();
124
+ })
125
+ .catch(async (error) => {
126
+ this.logger?.error('[IdleScalingPool] Scale-up failed', { error });
127
+ await newInner.dispose().catch(() => { });
128
+ })
129
+ .finally(() => {
130
+ this.pendingScaleUp = null;
131
+ });
132
+ }
133
+ triggerScaleDown() {
134
+ if (this.pendingScaleDown || this.pendingScaleUp || !this.innerPool || this.disposed)
135
+ return;
136
+ this.logger?.info('[IdleScalingPool] Scaling to 0 after inactivity', {
137
+ idleTimeoutMs: this.idleTimeoutMs,
138
+ });
139
+ this.observability?.metrics.counter(metrics_1.EXPRESSION_METRICS.poolScaledToZero.name, 1);
140
+ const oldInner = this.innerPool;
141
+ this.innerPool = null;
142
+ this.pendingScaleDown = oldInner
143
+ .dispose()
144
+ .catch((error) => {
145
+ this.logger?.error('[IdleScalingPool] Scale-down dispose failed', { error });
146
+ })
147
+ .finally(() => {
148
+ this.pendingScaleDown = null;
149
+ });
150
+ }
151
+ }
152
+ exports.IdleScalingPool = IdleScalingPool;
153
+ });
154
+ //# sourceMappingURL=idle-scaling-pool.js.map