@forge/runtime 5.6.0 → 5.6.1-next.1
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/CHANGELOG.md +14 -0
- package/out/app-manifest.js +13 -15
- package/out/context.js +6 -3
- package/out/feature-flag.js +4 -3
- package/out/limits/tracker.js +2 -2
- package/out/metrics/metrics.d.ts +2 -21
- package/out/metrics/metrics.d.ts.map +1 -1
- package/out/metrics/metrics.js +8 -12
- package/out/sandbox/inspector.js +41 -35
- package/out/sandbox/invocation-request.js +20 -15
- package/package.json +2 -2
- package/out/metrics/in-memory-counter-metric.d.ts +0 -16
- package/out/metrics/in-memory-counter-metric.d.ts.map +0 -1
- package/out/metrics/in-memory-counter-metric.js +0 -32
- package/out/metrics/in-memory-event-metric.d.ts +0 -12
- package/out/metrics/in-memory-event-metric.d.ts.map +0 -1
- package/out/metrics/in-memory-event-metric.js +0 -20
- package/out/metrics/in-memory-gauge-metric.d.ts +0 -13
- package/out/metrics/in-memory-gauge-metric.d.ts.map +0 -1
- package/out/metrics/in-memory-gauge-metric.js +0 -23
- package/out/metrics/in-memory-metrics.d.ts +0 -27
- package/out/metrics/in-memory-metrics.d.ts.map +0 -1
- package/out/metrics/in-memory-metrics.js +0 -81
- package/out/metrics/in-memory-timed-metric.d.ts +0 -18
- package/out/metrics/in-memory-timed-metric.d.ts.map +0 -1
- package/out/metrics/in-memory-timed-metric.js +0 -50
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @forge/runtime
|
|
2
2
|
|
|
3
|
+
## 5.6.1-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- eb06eca: Break more dependencies between SDK and runtime
|
|
8
|
+
|
|
9
|
+
## 5.6.1-next.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- f8a4714: Use InMemoryMetrics from the Node monorepo
|
|
14
|
+
- Updated dependencies [f8a4714]
|
|
15
|
+
- @forge/util@1.4.3-next.0
|
|
16
|
+
|
|
3
17
|
## 5.6.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/out/app-manifest.js
CHANGED
|
@@ -45,6 +45,14 @@ const AppManifestRequiredFields = t.type({
|
|
|
45
45
|
});
|
|
46
46
|
const AppManifestType = t.intersection([AppManifestRequiredFields, AppManifestOptionalFields]);
|
|
47
47
|
class AppManifest {
|
|
48
|
+
static FILE_NAME = 'manifest.yml';
|
|
49
|
+
static async fromFile(filePath) {
|
|
50
|
+
const fullPath = path_1.default.join(filePath, AppManifest.FILE_NAME);
|
|
51
|
+
const manifestContents = (0, fs_1.readFileSync)(fullPath, 'utf-8');
|
|
52
|
+
const manifest = yaml_1.default.parse(manifestContents);
|
|
53
|
+
return new AppManifest(manifest);
|
|
54
|
+
}
|
|
55
|
+
manifest;
|
|
48
56
|
constructor(manifest) {
|
|
49
57
|
if (!AppManifestType.is(manifest)) {
|
|
50
58
|
throw new Error('invalid manifest');
|
|
@@ -53,33 +61,23 @@ class AppManifest {
|
|
|
53
61
|
this.manifest = manifest;
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
|
-
static async fromFile(filePath) {
|
|
57
|
-
const fullPath = path_1.default.join(filePath, AppManifest.FILE_NAME);
|
|
58
|
-
const manifestContents = (0, fs_1.readFileSync)(fullPath, 'utf-8');
|
|
59
|
-
const manifest = yaml_1.default.parse(manifestContents);
|
|
60
|
-
return new AppManifest(manifest);
|
|
61
|
-
}
|
|
62
64
|
getHostForRemote(remote) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return found === null || found === void 0 ? void 0 : found.baseUrl;
|
|
65
|
+
const found = this.manifest.remotes?.find(({ key }) => key === remote);
|
|
66
|
+
return found?.baseUrl;
|
|
66
67
|
}
|
|
67
68
|
getDefaultRemoteForProvider(provider) {
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const remotes = providerConfig === null || providerConfig === void 0 ? void 0 : providerConfig.remotes;
|
|
69
|
+
const providerConfig = this.getExternalAuthProviderConfig(provider);
|
|
70
|
+
const remotes = providerConfig?.remotes;
|
|
71
71
|
if (remotes && remotes.length > 0) {
|
|
72
72
|
return remotes[0];
|
|
73
73
|
}
|
|
74
74
|
return undefined;
|
|
75
75
|
}
|
|
76
76
|
getExternalAuthProviderConfig(provider) {
|
|
77
|
-
|
|
78
|
-
return (_a = this.manifest.providers) === null || _a === void 0 ? void 0 : _a.auth.find((v) => v.key === provider);
|
|
77
|
+
return this.manifest.providers?.auth.find((v) => v.key === provider);
|
|
79
78
|
}
|
|
80
79
|
getEgressAllowlist() {
|
|
81
80
|
return this.manifest.egress || [];
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
exports.AppManifest = AppManifest;
|
|
85
|
-
AppManifest.FILE_NAME = 'manifest.yml';
|
package/out/context.js
CHANGED
|
@@ -31,18 +31,21 @@ function createPrincipal(cfg) {
|
|
|
31
31
|
}
|
|
32
32
|
exports.createPrincipal = createPrincipal;
|
|
33
33
|
function createLicenseContext(cfg) {
|
|
34
|
-
var _a;
|
|
35
34
|
const { license } = cfg.meta;
|
|
36
35
|
if (license) {
|
|
37
36
|
return {
|
|
38
37
|
license: {
|
|
39
|
-
isActive:
|
|
38
|
+
isActive: license.isActive ?? false
|
|
40
39
|
}
|
|
41
40
|
};
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
exports.createLicenseContext = createLicenseContext;
|
|
45
44
|
function setupRequestContext(cfg) {
|
|
46
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
principal: createPrincipal(cfg),
|
|
47
|
+
...createLicenseContext(cfg),
|
|
48
|
+
...createInstallationContext(cfg)
|
|
49
|
+
};
|
|
47
50
|
}
|
|
48
51
|
exports.setupRequestContext = setupRequestContext;
|
package/out/feature-flag.js
CHANGED
|
@@ -10,12 +10,13 @@ exports.XEN_RUNTIME_ENABLE_NETWORK_LIMITS = 'xen-runtime-enable-network-limits';
|
|
|
10
10
|
exports.XEN_RUNTIME_SHOULD_BLOCK_EXTERNAL_FETCH = 'xen-runtime-should-block-external-fetch';
|
|
11
11
|
exports.XEN_RUNTIME_SHOULD_REPORT_METRICS = 'xen-runtime-should-report-metrics';
|
|
12
12
|
class FeatureFlags {
|
|
13
|
-
|
|
14
|
-
this.flags = flags;
|
|
15
|
-
}
|
|
13
|
+
flags;
|
|
16
14
|
static fromRequestMetaData(metaData) {
|
|
17
15
|
return new FeatureFlags(metaData.featureFlags || []);
|
|
18
16
|
}
|
|
17
|
+
constructor(flags) {
|
|
18
|
+
this.flags = flags;
|
|
19
|
+
}
|
|
19
20
|
isFeatureFlagEnabled(flag) {
|
|
20
21
|
return this.flags.includes(flag);
|
|
21
22
|
}
|
package/out/limits/tracker.js
CHANGED
|
@@ -6,9 +6,9 @@ exports.Limit = {
|
|
|
6
6
|
FetchRequestLimit: 'forge-fetch-request-count'
|
|
7
7
|
};
|
|
8
8
|
class PerInvocationLimitsTracker {
|
|
9
|
+
limits = {};
|
|
10
|
+
limitCount = {};
|
|
9
11
|
constructor(limits) {
|
|
10
|
-
this.limits = {};
|
|
11
|
-
this.limitCount = {};
|
|
12
12
|
this.limits = limits || {};
|
|
13
13
|
}
|
|
14
14
|
incrementCount(limitKey, by = 1) {
|
package/out/metrics/metrics.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Metrics, Tags } from '@forge/util/packages/metrics-interface';
|
|
2
2
|
import { BaseInvocationRequest } from '../sandbox/invocation-request';
|
|
3
|
-
import { InMemoryMetrics } from './in-memory-metrics';
|
|
4
|
-
export { InMemoryMetrics };
|
|
5
3
|
export declare enum MetricType {
|
|
6
4
|
TimerMetric = "timer",
|
|
7
5
|
CounterMetric = "counter",
|
|
8
|
-
GaugeMetric = "gauge"
|
|
9
|
-
EventMetric = "event"
|
|
6
|
+
GaugeMetric = "gauge"
|
|
10
7
|
}
|
|
11
8
|
export interface Metric {
|
|
12
9
|
name: string;
|
|
@@ -14,22 +11,6 @@ export interface Metric {
|
|
|
14
11
|
value: number | string;
|
|
15
12
|
tags: Tags;
|
|
16
13
|
}
|
|
17
|
-
export interface DefaultMetricsRecord {
|
|
18
|
-
getName(): string;
|
|
19
|
-
getTags(): Tags;
|
|
20
|
-
}
|
|
21
|
-
export interface TimedMetricsRecord extends DefaultMetricsRecord, Timing {
|
|
22
|
-
getTime(): number;
|
|
23
|
-
}
|
|
24
|
-
export interface CounterMetricsRecord extends DefaultMetricsRecord, Counter {
|
|
25
|
-
getCount(): number;
|
|
26
|
-
}
|
|
27
|
-
export interface GaugeMetricsRecord extends DefaultMetricsRecord, Gauge {
|
|
28
|
-
getValue(): number;
|
|
29
|
-
}
|
|
30
|
-
export interface EventMetricsRecord extends DefaultMetricsRecord {
|
|
31
|
-
getDescription(): string;
|
|
32
|
-
}
|
|
33
14
|
export declare class MetricsCollector {
|
|
34
15
|
private readonly _metrics;
|
|
35
16
|
constructor(_metrics: Metrics);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/metrics/metrics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/metrics/metrics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAa,MAAM,wCAAwC,CAAC;AAElF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,oBAAY,UAAU;IACpB,WAAW,UAAU;IACrB,aAAa,YAAY;IACzB,WAAW,UAAU;CACtB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,EAAE,IAAI,CAAC;CACZ;AAYD,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,OAAO;IAEvC,OAAO,IAAI,OAAO;IAIlB,cAAc,IAAI,MAAM,EAAE;IAIjC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,MAAM,GAAG,SAAqB,GAAG,MAAM,EAAE;IAuCrE,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,CAAA;KAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CASpH;AAED,eAAO,MAAM,sBAAsB,yBACX,qBAAqB,KAC1C;IAAE,SAAS,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CASjD,CAAC"}
|
package/out/metrics/metrics.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMetricsCollector = exports.MetricsCollector = exports.MetricType =
|
|
3
|
+
exports.createMetricsCollector = exports.MetricsCollector = exports.MetricType = void 0;
|
|
4
|
+
const in_memory_metrics_1 = require("@forge/util/packages/in-memory-metrics");
|
|
4
5
|
const metrics_interface_1 = require("@forge/util/packages/metrics-interface");
|
|
5
6
|
const feature_flag_1 = require("../feature-flag");
|
|
6
|
-
const in_memory_metrics_1 = require("./in-memory-metrics");
|
|
7
|
-
Object.defineProperty(exports, "InMemoryMetrics", { enumerable: true, get: function () { return in_memory_metrics_1.InMemoryMetrics; } });
|
|
8
7
|
var MetricType;
|
|
9
8
|
(function (MetricType) {
|
|
10
9
|
MetricType["TimerMetric"] = "timer";
|
|
11
10
|
MetricType["CounterMetric"] = "counter";
|
|
12
11
|
MetricType["GaugeMetric"] = "gauge";
|
|
13
|
-
MetricType["EventMetric"] = "event";
|
|
14
12
|
})(MetricType = exports.MetricType || (exports.MetricType = {}));
|
|
13
|
+
function isInMemoryMetrics(metrics) {
|
|
14
|
+
return metrics.constructor.name === in_memory_metrics_1.InMemoryMetrics.name;
|
|
15
|
+
}
|
|
15
16
|
class MetricsCollector {
|
|
17
|
+
_metrics;
|
|
16
18
|
constructor(_metrics) {
|
|
17
19
|
this._metrics = _metrics;
|
|
18
20
|
}
|
|
@@ -23,7 +25,7 @@ class MetricsCollector {
|
|
|
23
25
|
return MetricsCollector.collect(this._metrics);
|
|
24
26
|
}
|
|
25
27
|
static collect(metrics, prefix = undefined) {
|
|
26
|
-
if (!(metrics
|
|
28
|
+
if (!isInMemoryMetrics(metrics)) {
|
|
27
29
|
return [];
|
|
28
30
|
}
|
|
29
31
|
const addPrefix = (p, value) => {
|
|
@@ -50,13 +52,7 @@ class MetricsCollector {
|
|
|
50
52
|
type: MetricType.TimerMetric,
|
|
51
53
|
value: v.getTime()
|
|
52
54
|
}));
|
|
53
|
-
|
|
54
|
-
name: addPrefix(prefix, v.getName()),
|
|
55
|
-
tags: v.getTags(),
|
|
56
|
-
type: MetricType.EventMetric,
|
|
57
|
-
value: v.getDescription()
|
|
58
|
-
}));
|
|
59
|
-
allMetrics.push(...timers, ...counters, ...gauges, ...events);
|
|
55
|
+
allMetrics.push(...timers, ...counters, ...gauges);
|
|
60
56
|
return allMetrics;
|
|
61
57
|
}
|
|
62
58
|
async wrapInMetrics(options, callback) {
|
package/out/sandbox/inspector.js
CHANGED
|
@@ -62,37 +62,24 @@ function processArgForLogConsole(arg) {
|
|
|
62
62
|
}
|
|
63
63
|
const className = type === 'object' ? arg.constructor.name : undefined;
|
|
64
64
|
const subtype = inspectorSubtypeEntries.find((a) => a[1](arg));
|
|
65
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
type,
|
|
67
|
+
...(className ? { className } : undefined),
|
|
68
|
+
...(subtype ? { subtype: subtype[0] } : undefined),
|
|
69
|
+
value: arg,
|
|
70
|
+
description: (0, util_1.inspect)(arg)
|
|
71
|
+
};
|
|
66
72
|
}
|
|
67
73
|
class ChromeInspector {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
wss.clients.forEach((ws) => ws.send(message));
|
|
79
|
-
};
|
|
80
|
-
this.stopSession = () => {
|
|
81
|
-
const wss = this.wss;
|
|
82
|
-
if (!wss) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (CLOSE_CONNECTION_ON_SESSION_STOP) {
|
|
86
|
-
wss.clients.forEach((ws) => ws.close());
|
|
87
|
-
}
|
|
88
|
-
const callbacks = this.callbacks;
|
|
89
|
-
if (!callbacks) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this.callbacks = undefined;
|
|
93
|
-
callbacks.onSessionStop();
|
|
94
|
-
};
|
|
95
|
-
}
|
|
74
|
+
static DENY_CODE = 1011;
|
|
75
|
+
static DENY_REASON = 'Only one frontend is allowed';
|
|
76
|
+
static FORCE_RESET_FRONTEND_STATE_EVENTS = [
|
|
77
|
+
'{"method":"Runtime.executionContextsCleared"}',
|
|
78
|
+
'{"method":"Inspector.targetReloadedAfterCrash"}'
|
|
79
|
+
];
|
|
80
|
+
wss;
|
|
81
|
+
callbacks;
|
|
82
|
+
frontendMsgsForNewSandbox = [];
|
|
96
83
|
startServer(port = 0) {
|
|
97
84
|
const wss = new ws_1.default.Server({ port });
|
|
98
85
|
wss.on('connection', (ws) => {
|
|
@@ -203,6 +190,31 @@ class ChromeInspector {
|
|
|
203
190
|
throw Error('Unable to find port for inspector server');
|
|
204
191
|
}
|
|
205
192
|
}
|
|
193
|
+
sendMessageToFrontend = (message) => {
|
|
194
|
+
const wss = this.wss;
|
|
195
|
+
if (!wss) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (VERBOSE_LOG) {
|
|
199
|
+
log('Message to frontend:\n' + message);
|
|
200
|
+
}
|
|
201
|
+
wss.clients.forEach((ws) => ws.send(message));
|
|
202
|
+
};
|
|
203
|
+
stopSession = () => {
|
|
204
|
+
const wss = this.wss;
|
|
205
|
+
if (!wss) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (CLOSE_CONNECTION_ON_SESSION_STOP) {
|
|
209
|
+
wss.clients.forEach((ws) => ws.close());
|
|
210
|
+
}
|
|
211
|
+
const callbacks = this.callbacks;
|
|
212
|
+
if (!callbacks) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.callbacks = undefined;
|
|
216
|
+
callbacks.onSessionStop();
|
|
217
|
+
};
|
|
206
218
|
forceResetFrontendState() {
|
|
207
219
|
for (const evt of ChromeInspector.FORCE_RESET_FRONTEND_STATE_EVENTS) {
|
|
208
220
|
this.sendMessageToFrontend(evt);
|
|
@@ -231,12 +243,6 @@ class ChromeInspector {
|
|
|
231
243
|
}
|
|
232
244
|
}
|
|
233
245
|
exports.ChromeInspector = ChromeInspector;
|
|
234
|
-
ChromeInspector.DENY_CODE = 1011;
|
|
235
|
-
ChromeInspector.DENY_REASON = 'Only one frontend is allowed';
|
|
236
|
-
ChromeInspector.FORCE_RESET_FRONTEND_STATE_EVENTS = [
|
|
237
|
-
'{"method":"Runtime.executionContextsCleared"}',
|
|
238
|
-
'{"method":"Inspector.targetReloadedAfterCrash"}'
|
|
239
|
-
];
|
|
240
246
|
exports.notImplementedInspector = {
|
|
241
247
|
startServer: () => {
|
|
242
248
|
throw new Error('Not implemented');
|
|
@@ -6,10 +6,13 @@ const feature_flag_1 = require("../feature-flag");
|
|
|
6
6
|
const ari_1 = require("@forge/util/packages/ari");
|
|
7
7
|
const __1 = require("..");
|
|
8
8
|
class XenInvocationRequestImpl {
|
|
9
|
+
request;
|
|
10
|
+
invocationId;
|
|
11
|
+
featureFlags;
|
|
12
|
+
serviceTokens = [];
|
|
9
13
|
constructor(request, invocationId) {
|
|
10
14
|
this.request = request;
|
|
11
15
|
this.invocationId = invocationId;
|
|
12
|
-
this.serviceTokens = [];
|
|
13
16
|
this.serviceTokens = this.buildServiceTokens(request._meta.tokens);
|
|
14
17
|
}
|
|
15
18
|
buildServiceTokens(tokens) {
|
|
@@ -77,11 +80,10 @@ class XenInvocationRequestImpl {
|
|
|
77
80
|
return this.request._meta.appToken;
|
|
78
81
|
}
|
|
79
82
|
getProxy() {
|
|
80
|
-
var _a;
|
|
81
83
|
if (!this.isFeatureFlagEnabled(feature_flag_1.XEN_RUNTIME_ENABLE_EGRESS_PROXY)) {
|
|
82
84
|
return undefined;
|
|
83
85
|
}
|
|
84
|
-
return
|
|
86
|
+
return this.request._meta?.proxy;
|
|
85
87
|
}
|
|
86
88
|
getAllTokens() {
|
|
87
89
|
return this.serviceTokens;
|
|
@@ -115,12 +117,9 @@ function xenInvocationRequestFactory(invocation) {
|
|
|
115
117
|
}
|
|
116
118
|
exports.xenInvocationRequestFactory = xenInvocationRequestFactory;
|
|
117
119
|
class InvocationRequest {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.manifest = manifest;
|
|
122
|
-
this.thirdPartyAuthTokenReferences = this.getThirdPartyTokenReferences();
|
|
123
|
-
}
|
|
120
|
+
sandboxConfig;
|
|
121
|
+
xenInvocationRequest;
|
|
122
|
+
manifest;
|
|
124
123
|
static async setup(sandboxConfig, xenInvocationRequest) {
|
|
125
124
|
const manifest = await app_manifest_1.AppManifest.fromFile(sandboxConfig.appPath);
|
|
126
125
|
return this.setupSync(sandboxConfig, xenInvocationRequest, manifest);
|
|
@@ -128,6 +127,13 @@ class InvocationRequest {
|
|
|
128
127
|
static setupSync(sandboxConfig, xenInvocationRequest, manifest) {
|
|
129
128
|
return new InvocationRequest(sandboxConfig, xenInvocationRequest, manifest);
|
|
130
129
|
}
|
|
130
|
+
thirdPartyAuthTokenReferences;
|
|
131
|
+
constructor(sandboxConfig, xenInvocationRequest, manifest) {
|
|
132
|
+
this.sandboxConfig = sandboxConfig;
|
|
133
|
+
this.xenInvocationRequest = xenInvocationRequest;
|
|
134
|
+
this.manifest = manifest;
|
|
135
|
+
this.thirdPartyAuthTokenReferences = this.getThirdPartyTokenReferences();
|
|
136
|
+
}
|
|
131
137
|
getAppAri() {
|
|
132
138
|
return this.manifest.manifest.app.id;
|
|
133
139
|
}
|
|
@@ -225,16 +231,16 @@ class InvocationRequest {
|
|
|
225
231
|
return serviceTokens ? serviceTokens[0] : undefined;
|
|
226
232
|
}
|
|
227
233
|
getAtlassianServiceToken() {
|
|
228
|
-
var _a;
|
|
229
234
|
const atlassianTokens = this.getAllTokens(this.getAtlassianTokenServiceKey());
|
|
230
|
-
return
|
|
235
|
+
return this.pickTokenToUse(atlassianTokens)?.token;
|
|
231
236
|
}
|
|
232
237
|
getAppTokenKey() {
|
|
233
238
|
return '__atlassian-app-token';
|
|
234
239
|
}
|
|
235
240
|
getThirdPartyTokenReferenceList(serviceKey) {
|
|
236
|
-
|
|
237
|
-
|
|
241
|
+
return (this.thirdPartyAuthTokenReferences
|
|
242
|
+
?.filter((ref) => ref.serviceKey === serviceKey)
|
|
243
|
+
.map((service) => service.reference) || []);
|
|
238
244
|
}
|
|
239
245
|
getThirdPartyTokenReferences() {
|
|
240
246
|
return this.getThirdPartyTokens().map(({ service, token }, index) => {
|
|
@@ -250,8 +256,7 @@ class InvocationRequest {
|
|
|
250
256
|
return this.getAllTokens().filter(({ service }) => service !== this.getAtlassianTokenServiceKey());
|
|
251
257
|
}
|
|
252
258
|
getThirdPartyToken(serviceKey) {
|
|
253
|
-
|
|
254
|
-
return (_b = (_a = this.thirdPartyAuthTokenReferences) === null || _a === void 0 ? void 0 : _a.find((ref) => ref.reference === serviceKey || ref.serviceKey === serviceKey)) === null || _b === void 0 ? void 0 : _b.token;
|
|
259
|
+
return this.thirdPartyAuthTokenReferences?.find((ref) => ref.reference === serviceKey || ref.serviceKey === serviceKey)?.token;
|
|
255
260
|
}
|
|
256
261
|
getAppVersion() {
|
|
257
262
|
return this.xenInvocationRequest.getAppVersion();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/runtime",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.1-next.1",
|
|
4
4
|
"description": "A Node.js runtime for Atlassian app functions",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"typescript": "4.8.4"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@forge/util": "1.4.
|
|
29
|
+
"@forge/util": "1.4.3-next.0",
|
|
30
30
|
"fp-ts": "^2.16.2",
|
|
31
31
|
"io-ts": "^2.2.21",
|
|
32
32
|
"io-ts-reporters": "^2.0.1",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Tags } from '@forge/util/packages/metrics-interface';
|
|
2
|
-
import { CounterMetricsRecord } from './metrics';
|
|
3
|
-
export declare class InMemoryCounterMetric implements CounterMetricsRecord {
|
|
4
|
-
private readonly name;
|
|
5
|
-
private readonly additionalInfo?;
|
|
6
|
-
private count;
|
|
7
|
-
constructor(name: string, additionalInfo?: Tags | undefined);
|
|
8
|
-
getTags(): Tags;
|
|
9
|
-
getCount(): number;
|
|
10
|
-
getName(): string;
|
|
11
|
-
incr(): void;
|
|
12
|
-
decr(): void;
|
|
13
|
-
decrBy(val: number): void;
|
|
14
|
-
incrBy(val: number): void;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=in-memory-counter-metric.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-counter-metric.d.ts","sourceRoot":"","sources":["../../src/metrics/in-memory-counter-metric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,qBAAa,qBAAsB,YAAW,oBAAoB;IAI9D,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAJlC,OAAO,CAAC,KAAK,CAAK;gBAGC,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,kBAAM;IAGxC,OAAO,IAAI,IAAI;IAIf,QAAQ,IAAI,MAAM;IAIlB,OAAO,IAAI,MAAM;IAIjB,IAAI,IAAI,IAAI;IAIZ,IAAI,IAAI,IAAI;IAIZ,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIzB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAG1B"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryCounterMetric = void 0;
|
|
4
|
-
class InMemoryCounterMetric {
|
|
5
|
-
constructor(name, additionalInfo) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
this.additionalInfo = additionalInfo;
|
|
8
|
-
this.count = 0;
|
|
9
|
-
}
|
|
10
|
-
getTags() {
|
|
11
|
-
return this.additionalInfo || {};
|
|
12
|
-
}
|
|
13
|
-
getCount() {
|
|
14
|
-
return this.count;
|
|
15
|
-
}
|
|
16
|
-
getName() {
|
|
17
|
-
return this.name;
|
|
18
|
-
}
|
|
19
|
-
incr() {
|
|
20
|
-
this.count++;
|
|
21
|
-
}
|
|
22
|
-
decr() {
|
|
23
|
-
this.count--;
|
|
24
|
-
}
|
|
25
|
-
decrBy(val) {
|
|
26
|
-
this.count -= val;
|
|
27
|
-
}
|
|
28
|
-
incrBy(val) {
|
|
29
|
-
this.count += val;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.InMemoryCounterMetric = InMemoryCounterMetric;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { EventMetricsRecord } from './metrics';
|
|
2
|
-
import { Tags } from '@forge/util/packages/metrics-interface';
|
|
3
|
-
export declare class InMemoryEventMetric implements EventMetricsRecord {
|
|
4
|
-
private readonly name;
|
|
5
|
-
private readonly description;
|
|
6
|
-
private readonly additionalInfo?;
|
|
7
|
-
constructor(name: string, description: any, additionalInfo?: Tags | undefined);
|
|
8
|
-
getDescription(): string;
|
|
9
|
-
getName(): string;
|
|
10
|
-
getTags(): Tags;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=in-memory-event-metric.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-event-metric.d.ts","sourceRoot":"","sources":["../../src/metrics/in-memory-event-metric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAE9D,qBAAa,mBAAoB,YAAW,kBAAkB;IAE1D,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAFf,IAAI,EAAE,MAAM,EACZ,WAAW,KAAA,EACX,cAAc,CAAC,kBAAM;IAGxC,cAAc,IAAI,MAAM;IAIxB,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryEventMetric = void 0;
|
|
4
|
-
class InMemoryEventMetric {
|
|
5
|
-
constructor(name, description, additionalInfo) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
this.description = description;
|
|
8
|
-
this.additionalInfo = additionalInfo;
|
|
9
|
-
}
|
|
10
|
-
getDescription() {
|
|
11
|
-
return this.description;
|
|
12
|
-
}
|
|
13
|
-
getName() {
|
|
14
|
-
return this.name;
|
|
15
|
-
}
|
|
16
|
-
getTags() {
|
|
17
|
-
return this.additionalInfo || {};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.InMemoryEventMetric = InMemoryEventMetric;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { GaugeMetricsRecord } from './metrics';
|
|
2
|
-
import { Tags } from '@forge/util/packages/metrics-interface';
|
|
3
|
-
export declare class InMemoryGaugeMetric implements GaugeMetricsRecord {
|
|
4
|
-
private readonly name;
|
|
5
|
-
private readonly additionalInfo?;
|
|
6
|
-
private value;
|
|
7
|
-
constructor(name: string, additionalInfo?: Tags | undefined);
|
|
8
|
-
getName(): string;
|
|
9
|
-
getTags(): Tags;
|
|
10
|
-
getValue(): number;
|
|
11
|
-
set(val: number): void;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=in-memory-gauge-metric.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-gauge-metric.d.ts","sourceRoot":"","sources":["../../src/metrics/in-memory-gauge-metric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAE9D,qBAAa,mBAAoB,YAAW,kBAAkB;IAI1D,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;IAJlC,OAAO,CAAC,KAAK,CAAK;gBAGC,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,kBAAM;IAGxC,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,IAAI;IAIf,QAAQ,IAAI,MAAM;IAIlB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAGvB"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryGaugeMetric = void 0;
|
|
4
|
-
class InMemoryGaugeMetric {
|
|
5
|
-
constructor(name, additionalInfo) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
this.additionalInfo = additionalInfo;
|
|
8
|
-
this.value = 0;
|
|
9
|
-
}
|
|
10
|
-
getName() {
|
|
11
|
-
return this.name;
|
|
12
|
-
}
|
|
13
|
-
getTags() {
|
|
14
|
-
return this.additionalInfo || {};
|
|
15
|
-
}
|
|
16
|
-
getValue() {
|
|
17
|
-
return this.value;
|
|
18
|
-
}
|
|
19
|
-
set(val) {
|
|
20
|
-
this.value = val;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.InMemoryGaugeMetric = InMemoryGaugeMetric;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Counter, Gauge, Metrics, Tags, Timing } from '../../../forge-util/packages/metrics-interface';
|
|
2
|
-
import { CounterMetricsRecord, EventMetricsRecord, GaugeMetricsRecord, TimedMetricsRecord } from './metrics';
|
|
3
|
-
export declare class InMemoryMetrics implements Metrics {
|
|
4
|
-
private readonly _timers;
|
|
5
|
-
private readonly _counters;
|
|
6
|
-
private readonly _gauges;
|
|
7
|
-
private readonly _children;
|
|
8
|
-
private readonly _events;
|
|
9
|
-
private readonly _tags;
|
|
10
|
-
private readonly _name;
|
|
11
|
-
constructor(tags?: Tags, name?: string);
|
|
12
|
-
getName(): string;
|
|
13
|
-
getTimers(): TimedMetricsRecord[];
|
|
14
|
-
getCounters(): Map<string, CounterMetricsRecord>;
|
|
15
|
-
getEvents(): EventMetricsRecord[];
|
|
16
|
-
getGauges(): Map<string, GaugeMetricsRecord>;
|
|
17
|
-
getChildren(): Map<string, InMemoryMetrics>;
|
|
18
|
-
private getHashedMetricName;
|
|
19
|
-
child(name: string, tags?: Tags): Metrics;
|
|
20
|
-
counter(name: string, tags?: Tags): Counter;
|
|
21
|
-
event(title: string, description?: string): void;
|
|
22
|
-
gauge(name: string, tags?: Tags): Gauge;
|
|
23
|
-
timing(name: string, tags?: Tags): Timing;
|
|
24
|
-
set(name: string, tags?: Tags | undefined): never;
|
|
25
|
-
histogram(name: string, buckets: number[], tags?: Tags | undefined): never;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=in-memory-metrics.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-metrics.d.ts","sourceRoot":"","sources":["../../src/metrics/in-memory-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,gDAAgD,CAAC;AAKvG,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAM7G,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoC;IAC9D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAC1D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA+B;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,IAAI,GAAE,IAAS,EAAE,IAAI,SAAK;IAU/B,OAAO;IAIP,SAAS,IAAI,kBAAkB,EAAE;IAIjC,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAIhD,SAAS,IAAI,kBAAkB,EAAE;IAIjC,SAAS,IAAI,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAI5C,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC;IAIlD,OAAO,CAAC,mBAAmB;IAK3B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,IAAS,GAAG,OAAO;IAW7C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,IAAS,GAAG,OAAO;IAS/C,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAIhD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,IAAS,GAAG,KAAK;IAS3C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM;IAMzC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,GAAG,KAAK;IAIjD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,GAAG,KAAK;CAG3E"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryMetrics = void 0;
|
|
4
|
-
const in_memory_counter_metric_1 = require("./in-memory-counter-metric");
|
|
5
|
-
const in_memory_event_metric_1 = require("./in-memory-event-metric");
|
|
6
|
-
const in_memory_gauge_metric_1 = require("./in-memory-gauge-metric");
|
|
7
|
-
const in_memory_timed_metric_1 = require("./in-memory-timed-metric");
|
|
8
|
-
class InMemoryMetrics {
|
|
9
|
-
constructor(tags = {}, name = '') {
|
|
10
|
-
this._timers = [];
|
|
11
|
-
this._counters = new Map();
|
|
12
|
-
this._gauges = new Map();
|
|
13
|
-
this._children = new Map();
|
|
14
|
-
this._events = [];
|
|
15
|
-
this._tags = tags;
|
|
16
|
-
this._name = name;
|
|
17
|
-
}
|
|
18
|
-
getName() {
|
|
19
|
-
return this._name;
|
|
20
|
-
}
|
|
21
|
-
getTimers() {
|
|
22
|
-
return this._timers;
|
|
23
|
-
}
|
|
24
|
-
getCounters() {
|
|
25
|
-
return this._counters;
|
|
26
|
-
}
|
|
27
|
-
getEvents() {
|
|
28
|
-
return this._events;
|
|
29
|
-
}
|
|
30
|
-
getGauges() {
|
|
31
|
-
return this._gauges;
|
|
32
|
-
}
|
|
33
|
-
getChildren() {
|
|
34
|
-
return this._children;
|
|
35
|
-
}
|
|
36
|
-
getHashedMetricName(name, tags) {
|
|
37
|
-
const sortedTags = Object.entries(Object.assign(Object.assign({}, this._tags), tags)).sort();
|
|
38
|
-
return `${name}_${JSON.stringify(sortedTags)}`;
|
|
39
|
-
}
|
|
40
|
-
child(name, tags = {}) {
|
|
41
|
-
const hashedMetricName = this.getHashedMetricName(name, tags);
|
|
42
|
-
if (!this._children.has(hashedMetricName)) {
|
|
43
|
-
const child = new InMemoryMetrics({}, name);
|
|
44
|
-
Object.assign(child._tags, this._tags);
|
|
45
|
-
Object.assign(child._tags, tags);
|
|
46
|
-
this._children.set(hashedMetricName, child);
|
|
47
|
-
}
|
|
48
|
-
return this._children.get(hashedMetricName);
|
|
49
|
-
}
|
|
50
|
-
counter(name, tags = {}) {
|
|
51
|
-
const hashedMetricName = this.getHashedMetricName(name, tags);
|
|
52
|
-
if (!this._counters.has(hashedMetricName)) {
|
|
53
|
-
const counter = new in_memory_counter_metric_1.InMemoryCounterMetric(name, Object.assign(Object.assign({}, this._tags), tags));
|
|
54
|
-
this._counters.set(hashedMetricName, counter);
|
|
55
|
-
}
|
|
56
|
-
return this._counters.get(hashedMetricName);
|
|
57
|
-
}
|
|
58
|
-
event(title, description) {
|
|
59
|
-
this._events.push(new in_memory_event_metric_1.InMemoryEventMetric(title, description));
|
|
60
|
-
}
|
|
61
|
-
gauge(name, tags = {}) {
|
|
62
|
-
const hashedMetricName = this.getHashedMetricName(name, tags);
|
|
63
|
-
if (!this._gauges.has(hashedMetricName)) {
|
|
64
|
-
const gauge = new in_memory_gauge_metric_1.InMemoryGaugeMetric(name, Object.assign(Object.assign({}, this._tags), tags));
|
|
65
|
-
this._gauges.set(hashedMetricName, gauge);
|
|
66
|
-
}
|
|
67
|
-
return this._gauges.get(hashedMetricName);
|
|
68
|
-
}
|
|
69
|
-
timing(name, tags) {
|
|
70
|
-
const timer = new in_memory_timed_metric_1.InMemoryTimedMetric(name, Object.assign(Object.assign({}, this._tags), tags));
|
|
71
|
-
this._timers.push(timer);
|
|
72
|
-
return timer;
|
|
73
|
-
}
|
|
74
|
-
set(name, tags) {
|
|
75
|
-
throw new Error('Sets are not implemented.');
|
|
76
|
-
}
|
|
77
|
-
histogram(name, buckets, tags) {
|
|
78
|
-
throw new Error('Histograms are not implemented.');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.InMemoryMetrics = InMemoryMetrics;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Tags, Timing } from '@forge/util/packages/metrics-interface';
|
|
2
|
-
import { TimedMetricsRecord } from './metrics';
|
|
3
|
-
export declare class InMemoryTimedMetric implements TimedMetricsRecord {
|
|
4
|
-
private readonly name;
|
|
5
|
-
private additionalInfo?;
|
|
6
|
-
private latency;
|
|
7
|
-
private started;
|
|
8
|
-
private startedAt;
|
|
9
|
-
constructor(name: string, additionalInfo?: Tags | undefined);
|
|
10
|
-
getTime(): number;
|
|
11
|
-
getName(): string;
|
|
12
|
-
getTags(): Tags;
|
|
13
|
-
private format;
|
|
14
|
-
private stopTimer;
|
|
15
|
-
measure(): Timing.Stop;
|
|
16
|
-
set(val: number, extraTags?: Tags): void;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=in-memory-timed-metric.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-timed-metric.d.ts","sourceRoot":"","sources":["../../src/metrics/in-memory-timed-metric.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAiB,MAAM,wCAAwC,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAI/C,qBAAa,mBAAoB,YAAW,kBAAkB;IAM1D,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,cAAc,CAAC;IANzB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAa;gBAGX,IAAI,EAAE,MAAM,EACrB,cAAc,CAAC,kBAAM;IAGxB,OAAO,IAAI,MAAM;IAOjB,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,IAAI;IAItB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,SAAS;IAMV,OAAO,IAAI,MAAM,CAAC,IAAI;IAWtB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI;CAShD"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryTimedMetric = void 0;
|
|
4
|
-
const MILLISEC_TO_NANOSEC = 1000000;
|
|
5
|
-
class InMemoryTimedMetric {
|
|
6
|
-
constructor(name, additionalInfo) {
|
|
7
|
-
this.name = name;
|
|
8
|
-
this.additionalInfo = additionalInfo;
|
|
9
|
-
this.latency = 0;
|
|
10
|
-
this.started = false;
|
|
11
|
-
this.startedAt = BigInt(0);
|
|
12
|
-
}
|
|
13
|
-
getTime() {
|
|
14
|
-
if (this.started) {
|
|
15
|
-
this.stopTimer();
|
|
16
|
-
}
|
|
17
|
-
return this.format(this.latency);
|
|
18
|
-
}
|
|
19
|
-
getName() {
|
|
20
|
-
return this.name;
|
|
21
|
-
}
|
|
22
|
-
getTags() {
|
|
23
|
-
return this.additionalInfo || {};
|
|
24
|
-
}
|
|
25
|
-
format(input, opts) {
|
|
26
|
-
return parseFloat(input.toFixed((opts === null || opts === void 0 ? void 0 : opts.precision) || 2));
|
|
27
|
-
}
|
|
28
|
-
stopTimer(extraTags) {
|
|
29
|
-
const latency = process.hrtime.bigint() - this.startedAt;
|
|
30
|
-
this.started = false;
|
|
31
|
-
this.set(Number(latency) / MILLISEC_TO_NANOSEC, extraTags);
|
|
32
|
-
}
|
|
33
|
-
measure() {
|
|
34
|
-
this.startedAt = process.hrtime.bigint();
|
|
35
|
-
this.started = true;
|
|
36
|
-
return {
|
|
37
|
-
stop: (extraTags, opts) => {
|
|
38
|
-
this.stopTimer(extraTags);
|
|
39
|
-
return this.format(this.latency, opts);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
set(val, extraTags) {
|
|
44
|
-
this.latency = val;
|
|
45
|
-
if (extraTags) {
|
|
46
|
-
this.additionalInfo = Object.assign(Object.assign({}, this.additionalInfo), extraTags);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.InMemoryTimedMetric = InMemoryTimedMetric;
|