@sentio/sdk 4.1.0-rc.1 → 4.1.0-rc.3
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/core/base-context.d.ts.map +1 -1
- package/dist/core/base-context.js +0 -3
- package/dist/core/base-context.js.map +1 -1
- package/dist/core/event-logger.d.ts.map +1 -1
- package/dist/core/event-logger.js +3 -16
- package/dist/core/event-logger.js.map +1 -1
- package/dist/core/meter.d.ts.map +1 -1
- package/dist/core/meter.js +1 -18
- package/dist/core/meter.js.map +1 -1
- package/dist/core/normalization.d.ts +0 -3
- package/dist/core/normalization.d.ts.map +1 -1
- package/dist/core/normalization.js +0 -61
- package/dist/core/normalization.js.map +1 -1
- package/dist/solana/builtin/types.d.ts +20 -20
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/metric-utils.d.ts +6 -1
- package/dist/testing/metric-utils.d.ts.map +1 -1
- package/dist/testing/metric-utils.js +111 -11
- package/dist/testing/metric-utils.js.map +1 -1
- package/dist/testing/test-processor-server.d.ts +0 -309
- package/dist/testing/test-processor-server.d.ts.map +1 -1
- package/dist/testing/test-processor-server.js +8 -0
- package/dist/testing/test-processor-server.js.map +1 -1
- package/dist/{tsdown.config.ts → tsdown.config.js} +8 -1
- package/dist/utils/price.d.ts +9 -5
- package/dist/utils/price.d.ts.map +1 -1
- package/dist/utils/price.js +20 -27
- package/dist/utils/price.js.map +1 -1
- package/package.json +6 -6
- package/src/core/base-context.ts +0 -3
- package/src/core/event-logger.ts +2 -18
- package/src/core/meter.ts +1 -18
- package/src/core/normalization.ts +0 -65
- package/src/testing/index.ts +10 -1
- package/src/testing/metric-utils.ts +126 -12
- package/src/testing/test-processor-server.ts +8 -0
- package/src/{tsdown.config.ts → tsdown.config.js} +8 -1
- package/src/utils/price.ts +22 -29
package/dist/utils/price.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CoinIDSchema } from '@sentio/protos';
|
|
2
2
|
import { create } from '@bufbuild/protobuf';
|
|
3
|
+
import { timestampDate, timestampFromDate } from '@bufbuild/protobuf/wkt';
|
|
3
4
|
import { Endpoints, processMetrics } from '@sentio/runtime';
|
|
4
5
|
import { LRUCache } from 'lru-cache';
|
|
5
|
-
import {
|
|
6
|
+
import { createSentioClient, PriceService } from '@sentio/api';
|
|
7
|
+
import { Code, ConnectError } from '@connectrpc/connect';
|
|
6
8
|
import path from 'path';
|
|
7
9
|
import fs from 'fs';
|
|
8
10
|
import os from 'os';
|
|
@@ -21,11 +23,10 @@ export function getPriceClient(basePath = Endpoints.INSTANCE.priceFeedAPI) {
|
|
|
21
23
|
if (basePath.endsWith('/')) {
|
|
22
24
|
basePath = basePath.slice(0, -1);
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
return createSentioClient(PriceService, {
|
|
25
27
|
baseUrl: basePath || 'https://api.sentio.xyz',
|
|
26
|
-
|
|
28
|
+
apiKey: getApiKey()
|
|
27
29
|
});
|
|
28
|
-
return PriceService;
|
|
29
30
|
}
|
|
30
31
|
const priceMap = new LRUCache({
|
|
31
32
|
max: 100000,
|
|
@@ -56,18 +57,17 @@ export async function getPriceByTypeOrSymbolInternal(priceClient, date, coinId,
|
|
|
56
57
|
}
|
|
57
58
|
processMetrics.process_pricecall_count.add(1);
|
|
58
59
|
const response = priceClient.getPrice({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
timestamp: timestampFromDate(date),
|
|
61
|
+
coinId: {
|
|
62
|
+
id: symbol
|
|
63
|
+
? { case: 'symbol', value: symbol }
|
|
64
|
+
: { case: 'address', value: { address: address?.address ?? '', chain: address?.chain ?? '' } }
|
|
64
65
|
}
|
|
65
66
|
});
|
|
66
67
|
price = response
|
|
67
68
|
.then((res) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const responseDate = new Date(data.timestamp);
|
|
69
|
+
if (res.timestamp) {
|
|
70
|
+
const responseDate = timestampDate(res.timestamp);
|
|
71
71
|
const responseDateString = dateString(responseDate);
|
|
72
72
|
if (responseDateString === todayDateString) {
|
|
73
73
|
priceMap.delete(key);
|
|
@@ -86,13 +86,13 @@ export async function getPriceByTypeOrSymbolInternal(priceClient, date, coinId,
|
|
|
86
86
|
else {
|
|
87
87
|
priceMap.delete(key);
|
|
88
88
|
}
|
|
89
|
-
return
|
|
89
|
+
return res.price;
|
|
90
90
|
})
|
|
91
91
|
.catch((e) => {
|
|
92
92
|
setTimeout(() => {
|
|
93
93
|
priceMap.delete(key);
|
|
94
94
|
}, 1000);
|
|
95
|
-
if (e.
|
|
95
|
+
if (e instanceof ConnectError && e.code === Code.NotFound) {
|
|
96
96
|
console.error('price not found for ', JSON.stringify(coinId), ' at ', dateStr);
|
|
97
97
|
return undefined;
|
|
98
98
|
}
|
|
@@ -133,25 +133,18 @@ function dateString(date) {
|
|
|
133
133
|
return [date.getHours(), date.getUTCDate(), date.getUTCMonth() + 1, date.getUTCFullYear()].join('-');
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
|
-
* get coins that has price, return results
|
|
136
|
+
* get coins that has price, return results as a list of `{ symbol, coin }`
|
|
137
|
+
* pairs where `coin` is the address-keyed CoinID for that symbol on the chain
|
|
137
138
|
* @param chainId
|
|
138
139
|
*/
|
|
139
140
|
export async function getCoinsThatHasPrice(chainId) {
|
|
140
141
|
if (!priceClient) {
|
|
141
142
|
priceClient = getPriceClient();
|
|
142
143
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
limit: 1000
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
if (!data?.coinAddressesInChain) {
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
return Object.entries(data.coinAddressesInChain).map(([symbol, coin]) => {
|
|
153
|
-
coin.symbol = symbol;
|
|
154
|
-
return coin;
|
|
144
|
+
const res = await priceClient.listCoins({
|
|
145
|
+
chain: chainId,
|
|
146
|
+
limit: 1000
|
|
155
147
|
});
|
|
148
|
+
return Object.entries(res.coinAddressesInChain).map(([symbol, coin]) => ({ symbol, coin }));
|
|
156
149
|
}
|
|
157
150
|
//# sourceMappingURL=price.js.map
|
package/dist/utils/price.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/utils/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAe,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,SAAS,SAAS;IAChB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,EAAE,CA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IG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAgB;IACzD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,WAAW,GAAG,cAAc,EAAE,CAAA;IAChC,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC;QACtC,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,IAAI;KACZ,CAAC,CAAA;IAEF,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAC7F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/sdk",
|
|
3
|
-
"version": "4.1.0-rc.
|
|
3
|
+
"version": "4.1.0-rc.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"@anchor-lang/core": "^1.0.2",
|
|
66
66
|
"@aptos-labs/ts-sdk": "~7.1.0",
|
|
67
67
|
"@bufbuild/protobuf": "^2.12.0",
|
|
68
|
-
"@connectrpc/connect": "^2.
|
|
68
|
+
"@connectrpc/connect": "^2.1.2",
|
|
69
69
|
"@iota/iota-sdk": "~1.14.0",
|
|
70
70
|
"@mysten/sui": "~2.20.0",
|
|
71
71
|
"@prettier/sync": "^0.6.0",
|
|
72
72
|
"@protobuf-ts/grpcweb-transport": "^2.11.1",
|
|
73
|
-
"@sentio/api": "
|
|
73
|
+
"@sentio/api": "~2.0.3",
|
|
74
74
|
"@sentio/bigdecimal": "9.1.1-patch.3",
|
|
75
75
|
"@sentio/chain": "~3.4.29",
|
|
76
76
|
"@sentio/ethers-v6": "^1.0.29",
|
|
@@ -97,8 +97,8 @@
|
|
|
97
97
|
"typechain": "^8.3.2",
|
|
98
98
|
"utility-types": "^3.11.0",
|
|
99
99
|
"yaml": "^2.3.4",
|
|
100
|
-
"@sentio/protos": "4.1.0-rc.
|
|
101
|
-
"@sentio/runtime": "^4.1.0-rc.
|
|
100
|
+
"@sentio/protos": "4.1.0-rc.3",
|
|
101
|
+
"@sentio/runtime": "^4.1.0-rc.3"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"tsdown": "^0.22.3"
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"build:bundle": "pnpm gen && pnpm bundle",
|
|
118
118
|
"bundle": "tsdown --config src/bundle.config.ts",
|
|
119
119
|
"bundle:dts": "tsc --emitDeclarationOnly --declaration",
|
|
120
|
-
"compile": "tsc && cp src/tsdown.config.
|
|
120
|
+
"compile": "tsc && cp src/tsdown.config.js dist",
|
|
121
121
|
"gen": "pnpm gen:eth && pnpm gen:aptos && pnpm gen:sui && pnpm gen:iota && pnpm gen:solana && pnpm gen:fuel && pnpm gen:store",
|
|
122
122
|
"gen:aptos": "cp node_modules/@typemove/aptos/src/abis/*.json src/aptos/abis && tsx src/aptos/codegen/run.ts src/aptos/abis src/aptos/builtin && pnpm gen:aptos_test",
|
|
123
123
|
"gen:aptos_test": "tsx src/aptos/codegen/run.ts src/aptos/tests/abis src/aptos/tests/types",
|
package/src/core/base-context.ts
CHANGED
|
@@ -24,10 +24,7 @@ export abstract class BaseContext {
|
|
|
24
24
|
private active: boolean
|
|
25
25
|
|
|
26
26
|
private _res: Required<ProcessResult, 'states'> = create(ProcessResultSchema, {
|
|
27
|
-
counters: [],
|
|
28
|
-
events: [],
|
|
29
27
|
exports: [],
|
|
30
|
-
gauges: [],
|
|
31
28
|
states: {
|
|
32
29
|
configUpdated: false
|
|
33
30
|
},
|
package/src/core/event-logger.ts
CHANGED
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
type EventLogConfig_Field,
|
|
10
10
|
EventLogConfig_FieldSchema,
|
|
11
11
|
EventLogConfig_StructFieldTypeSchema,
|
|
12
|
-
type EventTrackingResult,
|
|
13
|
-
EventTrackingResultSchema,
|
|
14
12
|
LogLevel,
|
|
15
13
|
type RichStruct,
|
|
16
14
|
RichStructSchema,
|
|
@@ -19,7 +17,7 @@ import {
|
|
|
19
17
|
TimeseriesResult_TimeseriesType
|
|
20
18
|
} from '@sentio/protos'
|
|
21
19
|
import { create } from '@bufbuild/protobuf'
|
|
22
|
-
import {
|
|
20
|
+
import { normalizeToRichStruct } from './normalization.js'
|
|
23
21
|
import { MapStateStorage, processMetrics } from '@sentio/runtime'
|
|
24
22
|
import { BN } from 'fuels'
|
|
25
23
|
import { BigDecimal } from '@sentio/bigdecimal'
|
|
@@ -173,20 +171,6 @@ function emit<T>(ctx: BaseContext, eventName: string, event: Event<T>) {
|
|
|
173
171
|
}
|
|
174
172
|
})
|
|
175
173
|
|
|
176
|
-
// legacy v2 events, deprecating
|
|
177
|
-
const eventRes: EventTrackingResult = create(EventTrackingResultSchema, {
|
|
178
|
-
metadata: ctx.getMetaData(eventName, {}),
|
|
179
|
-
severity: severity || LogLevel.INFO,
|
|
180
|
-
message: message || '',
|
|
181
|
-
distinctEntityId: distinctId || '',
|
|
182
|
-
attributes: {
|
|
183
|
-
...normalizeLabels(ctx.baseLabels), // TODO avoid dup label in metadata
|
|
184
|
-
...normalizeAttribute(payload)
|
|
185
|
-
},
|
|
186
|
-
runtimeInfo: undefined,
|
|
187
|
-
attributes2: normalizeToRichStruct(ctx.baseLabels, payload)
|
|
188
|
-
})
|
|
189
|
-
|
|
190
174
|
const res: TimeseriesResult = create(TimeseriesResultSchema, {
|
|
191
175
|
metadata: ctx.getMetaData(eventName, {}),
|
|
192
176
|
type: TimeseriesResult_TimeseriesType.EVENT,
|
|
@@ -195,5 +179,5 @@ function emit<T>(ctx: BaseContext, eventName: string, event: Event<T>) {
|
|
|
195
179
|
})
|
|
196
180
|
|
|
197
181
|
processMetrics.process_eventemit_count.add(1)
|
|
198
|
-
ctx.update({ timeseriesResult: [res]
|
|
182
|
+
ctx.update({ timeseriesResult: [res] })
|
|
199
183
|
}
|
package/src/core/meter.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseContext } from './base-context.js'
|
|
2
|
-
import { Numberish,
|
|
2
|
+
import { Numberish, toTimeSeriesData } from './numberish.js'
|
|
3
3
|
import { NamedResultDescriptor } from './metadata.js'
|
|
4
4
|
import {
|
|
5
5
|
AggregationConfigSchema,
|
|
@@ -112,15 +112,6 @@ export class Counter extends Metric {
|
|
|
112
112
|
private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {
|
|
113
113
|
processMetrics.process_metricrecord_count.add(1)
|
|
114
114
|
ctx.update({
|
|
115
|
-
// legacy support, deprecating
|
|
116
|
-
counters: [
|
|
117
|
-
{
|
|
118
|
-
metadata: ctx.getMetaData(this.name, labels),
|
|
119
|
-
metricValue: toMetricValue(value),
|
|
120
|
-
add: add,
|
|
121
|
-
runtimeInfo: undefined
|
|
122
|
-
}
|
|
123
|
-
],
|
|
124
115
|
timeseriesResult: [
|
|
125
116
|
{
|
|
126
117
|
metadata: ctx.getMetaData(this.name, labels),
|
|
@@ -170,14 +161,6 @@ export class Gauge extends Metric {
|
|
|
170
161
|
record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {
|
|
171
162
|
processMetrics.process_metricrecord_count.add(1)
|
|
172
163
|
ctx.update({
|
|
173
|
-
// legacy support, deprecating
|
|
174
|
-
gauges: [
|
|
175
|
-
{
|
|
176
|
-
metadata: ctx.getMetaData(this.config.name, labels),
|
|
177
|
-
metricValue: toMetricValue(value),
|
|
178
|
-
runtimeInfo: undefined
|
|
179
|
-
}
|
|
180
|
-
],
|
|
181
164
|
timeseriesResult: [
|
|
182
165
|
{
|
|
183
166
|
metadata: ctx.getMetaData(this.name, labels),
|
|
@@ -17,9 +17,6 @@ import {
|
|
|
17
17
|
import { create } from '@bufbuild/protobuf'
|
|
18
18
|
import { toBigInteger, toBigDecimal } from './numberish.js'
|
|
19
19
|
|
|
20
|
-
export const SENTIO_BIGINT_STRING_SUFFIX = ':sto_bi'
|
|
21
|
-
export const SENTIO_BIGDECIMAL_STRING_SUFFIX = ':sto_bd'
|
|
22
|
-
|
|
23
20
|
function normalizeName(name: string): string {
|
|
24
21
|
return name.slice(0, 128).replace(/[^_a-zA-Z0-9]/g, '_')
|
|
25
22
|
}
|
|
@@ -56,68 +53,6 @@ export function normalizeLabels(labels: Labels): Labels {
|
|
|
56
53
|
return normLabels
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
function normalizeObject(obj: any, length: number, path?: string): any {
|
|
60
|
-
let ret: any
|
|
61
|
-
|
|
62
|
-
const typeString = typeof obj
|
|
63
|
-
switch (typeString) {
|
|
64
|
-
case 'string':
|
|
65
|
-
return obj.slice(0, length)
|
|
66
|
-
case 'bigint':
|
|
67
|
-
return obj.toString() + SENTIO_BIGINT_STRING_SUFFIX
|
|
68
|
-
// return Number(obj)
|
|
69
|
-
case 'number':
|
|
70
|
-
return obj
|
|
71
|
-
case 'function':
|
|
72
|
-
return null
|
|
73
|
-
case 'symbol':
|
|
74
|
-
return null
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(obj)) {
|
|
77
|
-
console.warn(
|
|
78
|
-
`Array type inside log/event payload is not currently supported and will be ignored. Path: ${path ?? ''}`
|
|
79
|
-
)
|
|
80
|
-
return null
|
|
81
|
-
// ret = []
|
|
82
|
-
// for (const val of obj) {
|
|
83
|
-
// ret.push(normalizeObject(val, length))
|
|
84
|
-
// }
|
|
85
|
-
} else if (obj === Object(obj)) {
|
|
86
|
-
if (obj instanceof Date) {
|
|
87
|
-
return obj.toISOString()
|
|
88
|
-
}
|
|
89
|
-
if (obj instanceof BigDecimal) {
|
|
90
|
-
if (obj.isNaN() || !obj.isFinite()) {
|
|
91
|
-
console.error("can't submit NaN or Infinity value, will store as 0")
|
|
92
|
-
return 0
|
|
93
|
-
}
|
|
94
|
-
return obj.toString() + SENTIO_BIGDECIMAL_STRING_SUFFIX
|
|
95
|
-
// return obj.toNumber()
|
|
96
|
-
}
|
|
97
|
-
if (BN.isBN(obj)) {
|
|
98
|
-
return obj.toString(10) + SENTIO_BIGINT_STRING_SUFFIX
|
|
99
|
-
}
|
|
100
|
-
if (obj instanceof Promise) {
|
|
101
|
-
console.error('Cannot submit promise')
|
|
102
|
-
return null
|
|
103
|
-
}
|
|
104
|
-
ret = {}
|
|
105
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
106
|
-
const normValue = normalizeObject(value, length, `${path ?? ''}.${key}`)
|
|
107
|
-
if (normValue != null) {
|
|
108
|
-
ret[key] = normValue
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
ret = obj
|
|
113
|
-
}
|
|
114
|
-
return ret
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function normalizeAttribute(record: Record<string, any>): any {
|
|
118
|
-
return normalizeObject(record, 1000)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
56
|
function normalizeToRichValue(value: any): RichValue {
|
|
122
57
|
if (value == null) {
|
|
123
58
|
return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
|
package/src/testing/index.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export { TestProcessorServer } from './test-processor-server.js'
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
MetricValueToNumber,
|
|
4
|
+
firstCounterValue,
|
|
5
|
+
firstGaugeValue,
|
|
6
|
+
countersOf,
|
|
7
|
+
gaugesOf,
|
|
8
|
+
eventsOf,
|
|
9
|
+
eventField,
|
|
10
|
+
eventFieldValue
|
|
11
|
+
} from './metric-utils.js'
|
|
3
12
|
|
|
4
13
|
export { loadTestProvidersFromEnv } from './test-provider.js' // TODO make the interface more standard and then export
|
|
5
14
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { MetricValue, ProcessResult } from '@sentio/protos'
|
|
1
|
+
import type { MetricValue, ProcessResult, RichStruct, RichValue, TimeseriesResult } from '@sentio/protos'
|
|
2
|
+
import { TimeseriesResult_TimeseriesType } from '@sentio/protos'
|
|
2
3
|
import { Numberish, BigDecimal } from '../core/index.js'
|
|
3
4
|
import { bytesToBigInt } from '../utils/conversion.js'
|
|
4
5
|
|
|
@@ -24,26 +25,139 @@ export function MetricValueToNumber(v: MetricValue | undefined): Numberish | und
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
// The legacy gauges/counters/events fields were dropped in v4; metrics and events
|
|
29
|
+
// now travel exclusively as TimeseriesResult entries tagged by type. These helpers
|
|
30
|
+
// recover the per-type views (and values) that tests used to read off the legacy
|
|
31
|
+
// fields. The metric value lives at data.fields.value (see core/numberish.ts
|
|
32
|
+
// toTimeSeriesData); event payload fields are flattened into data.fields.
|
|
33
|
+
function RichValueToNumber(v: RichValue | undefined): Numberish | undefined {
|
|
34
|
+
if (v === undefined) {
|
|
29
35
|
return undefined
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
37
|
+
switch (v.value.case) {
|
|
38
|
+
case 'floatValue':
|
|
39
|
+
return v.value.value
|
|
40
|
+
case 'bigintValue': {
|
|
41
|
+
let intValue = bytesToBigInt(v.value.value.data)
|
|
42
|
+
if (v.value.value.negative) {
|
|
43
|
+
intValue = -intValue
|
|
44
|
+
}
|
|
45
|
+
return intValue
|
|
34
46
|
}
|
|
47
|
+
case 'bigdecimalValue': {
|
|
48
|
+
const bd = v.value.value
|
|
49
|
+
if (bd.value === undefined) {
|
|
50
|
+
return undefined
|
|
51
|
+
}
|
|
52
|
+
let intValue = bytesToBigInt(bd.value.data)
|
|
53
|
+
if (bd.value.negative) {
|
|
54
|
+
intValue = -intValue
|
|
55
|
+
}
|
|
56
|
+
return new BigDecimal(`${intValue}e${bd.exp}`)
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return undefined
|
|
35
60
|
}
|
|
36
|
-
return undefined
|
|
37
61
|
}
|
|
38
62
|
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
function timeseriesOf(result: ProcessResult | undefined, type: TimeseriesResult_TimeseriesType): TimeseriesResult[] {
|
|
64
|
+
return result?.timeseriesResult.filter((t) => t.type === type) ?? []
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function countersOf(result: ProcessResult | undefined): TimeseriesResult[] {
|
|
68
|
+
return timeseriesOf(result, TimeseriesResult_TimeseriesType.COUNTER)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function gaugesOf(result: ProcessResult | undefined): TimeseriesResult[] {
|
|
72
|
+
return timeseriesOf(result, TimeseriesResult_TimeseriesType.GAUGE)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function eventsOf(result: ProcessResult | undefined): TimeseriesResult[] {
|
|
76
|
+
return timeseriesOf(result, TimeseriesResult_TimeseriesType.EVENT)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Read a string field off a TimeseriesResult's data struct (e.g. an event's
|
|
80
|
+
// `message` or a flattened payload attribute). Returns undefined if absent or
|
|
81
|
+
// not a string.
|
|
82
|
+
export function eventField(ts: TimeseriesResult | undefined, key: string): string | undefined {
|
|
83
|
+
const v = ts?.data?.fields?.[key]?.value
|
|
84
|
+
return v?.case === 'stringValue' ? v.value : undefined
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Convert a RichValue back to a plain JS value (inverse of core/normalization.ts
|
|
88
|
+
// normalizeToRichValue), so event payload fields — including nested structs — can
|
|
89
|
+
// be asserted with deep equality.
|
|
90
|
+
function richValueToJs(v: RichValue | undefined): unknown {
|
|
91
|
+
if (v === undefined) {
|
|
41
92
|
return undefined
|
|
42
93
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return
|
|
94
|
+
switch (v.value.case) {
|
|
95
|
+
case 'nullValue':
|
|
96
|
+
return null
|
|
97
|
+
case 'stringValue':
|
|
98
|
+
case 'boolValue':
|
|
99
|
+
case 'floatValue':
|
|
100
|
+
return v.value.value
|
|
101
|
+
case 'bigintValue': {
|
|
102
|
+
let n = bytesToBigInt(v.value.value.data)
|
|
103
|
+
if (v.value.value.negative) {
|
|
104
|
+
n = -n
|
|
105
|
+
}
|
|
106
|
+
return n
|
|
107
|
+
}
|
|
108
|
+
case 'bigdecimalValue': {
|
|
109
|
+
const bd = v.value.value
|
|
110
|
+
if (bd.value === undefined) {
|
|
111
|
+
return undefined
|
|
112
|
+
}
|
|
113
|
+
let n = bytesToBigInt(bd.value.data)
|
|
114
|
+
if (bd.value.negative) {
|
|
115
|
+
n = -n
|
|
116
|
+
}
|
|
117
|
+
return new BigDecimal(`${n}e${bd.exp}`)
|
|
118
|
+
}
|
|
119
|
+
case 'structValue':
|
|
120
|
+
return richStructToJs(v.value.value)
|
|
121
|
+
case 'listValue':
|
|
122
|
+
return v.value.value.values.map(richValueToJs)
|
|
123
|
+
default:
|
|
124
|
+
return undefined
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function richStructToJs(s: RichStruct | undefined): Record<string, unknown> {
|
|
129
|
+
const out: Record<string, unknown> = {}
|
|
130
|
+
if (s) {
|
|
131
|
+
for (const [k, v] of Object.entries(s.fields)) {
|
|
132
|
+
out[k] = richValueToJs(v)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return out
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Read an arbitrary event payload field off a TimeseriesResult's data struct as a
|
|
139
|
+
// plain JS value (strings, bigints, nested objects, ...).
|
|
140
|
+
export function eventFieldValue(ts: TimeseriesResult | undefined, key: string): unknown {
|
|
141
|
+
return richValueToJs(ts?.data?.fields?.[key])
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function firstTimeseriesValue(
|
|
145
|
+
result: ProcessResult | undefined,
|
|
146
|
+
type: TimeseriesResult_TimeseriesType,
|
|
147
|
+
name: string
|
|
148
|
+
): Numberish | undefined {
|
|
149
|
+
for (const ts of timeseriesOf(result, type)) {
|
|
150
|
+
if (ts.metadata?.name === name) {
|
|
151
|
+
return RichValueToNumber(ts.data?.fields?.value)
|
|
46
152
|
}
|
|
47
153
|
}
|
|
48
154
|
return undefined
|
|
49
155
|
}
|
|
156
|
+
|
|
157
|
+
export function firstCounterValue(result: ProcessResult | undefined, name: string): Numberish | undefined {
|
|
158
|
+
return firstTimeseriesValue(result, TimeseriesResult_TimeseriesType.COUNTER, name)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function firstGaugeValue(result: ProcessResult | undefined, name: string): Numberish | undefined {
|
|
162
|
+
return firstTimeseriesValue(result, TimeseriesResult_TimeseriesType.GAUGE, name)
|
|
163
|
+
}
|
|
@@ -162,6 +162,10 @@ export class TestProcessorServer {
|
|
|
162
162
|
const subject = this.storeContext.subject
|
|
163
163
|
|
|
164
164
|
return new Promise((resolve, reject) => {
|
|
165
|
+
// The V3 service streams timeseries separately as `tsRequest` batches and clears
|
|
166
|
+
// `timeseriesResult` from the final `result` message. Collect the batches here and fold
|
|
167
|
+
// them back in so test helpers can read metrics/events off `result.timeseriesResult`.
|
|
168
|
+
const collectedTimeseries: TimeseriesResult[] = []
|
|
165
169
|
const subscription = subject.subscribe({
|
|
166
170
|
next: (response) => {
|
|
167
171
|
if (response.processId !== processId) {
|
|
@@ -173,6 +177,9 @@ export class TestProcessorServer {
|
|
|
173
177
|
response.value.value.remove ?? false
|
|
174
178
|
)
|
|
175
179
|
}
|
|
180
|
+
if (response.value?.case === 'tsRequest') {
|
|
181
|
+
collectedTimeseries.push(...((response.value.value.data ?? []) as TimeseriesResult[]))
|
|
182
|
+
}
|
|
176
183
|
if (response.value?.case === 'result') {
|
|
177
184
|
subscription.unsubscribe()
|
|
178
185
|
// The service always emits a fully-formed ProcessResult message here; use it directly.
|
|
@@ -186,6 +193,7 @@ export class TestProcessorServer {
|
|
|
186
193
|
if (result.states?.error) {
|
|
187
194
|
reject(new Error(result.states.error))
|
|
188
195
|
} else {
|
|
196
|
+
result.timeseriesResult = collectedTimeseries
|
|
189
197
|
resolve(result)
|
|
190
198
|
}
|
|
191
199
|
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// NOTE: This config is intentionally plain JavaScript (not TypeScript). It is
|
|
2
|
+
// copied verbatim to @sentio/sdk/dist and loaded by `sentio build` from the
|
|
3
|
+
// user's node_modules. Node refuses to strip types from .ts files under
|
|
4
|
+
// node_modules ("Stripping types is currently unsupported for files under
|
|
5
|
+
// node_modules"), so a .ts config fails to load there. A .js config has no types
|
|
6
|
+
// to strip and loads natively on every Node version and package manager. Keep it
|
|
7
|
+
// .js — do not rename to .ts.
|
|
1
8
|
import { defineConfig } from 'tsdown'
|
|
2
9
|
|
|
3
10
|
let env
|
|
@@ -17,7 +24,7 @@ function sentioRegistrationGuard() {
|
|
|
17
24
|
// Set the flag only (no code change) so the module is force-kept without
|
|
18
25
|
// counting as a transform (avoids a spurious broken-sourcemap warning).
|
|
19
26
|
handler() {
|
|
20
|
-
return { moduleSideEffects: 'no-treeshake'
|
|
27
|
+
return { moduleSideEffects: 'no-treeshake' }
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
}
|