@sentio/sdk 1.12.5 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { GenericProcessor } from './generic-processor';
3
3
  export { BaseProcessorTemplate } from './base-processor-template';
4
4
  export { Context, ContractView, BoundContractView, SolanaContext } from './context';
5
5
  export { ProcessorServiceImpl } from './service';
6
- export { Counter, Meter, Gauge } from './meter';
6
+ export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter';
7
7
  export { getProvider, setProvider, DummyProvider } from './provider';
8
8
  export { SolanaBaseProcessor } from './solana-processor';
9
9
  export { SuiBaseProcessor } from './sui-processor';
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.SPLTokenProcessor = exports.getContractName = exports.addContractByABI = exports.getContractByABI = exports.addProcessor = exports.getProcessor = exports.EthersError = exports.BigDecimal = exports.ProcessorState = exports.transformEtherError = exports.SuiBindOptions = exports.SolanaBindOptions = exports.BindOptions = exports.ContractNamer = exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.DummyProvider = exports.setProvider = exports.getProvider = exports.Gauge = exports.Meter = exports.Counter = exports.ProcessorServiceImpl = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = void 0;
17
+ exports.SPLTokenProcessor = exports.getContractName = exports.addContractByABI = exports.getContractByABI = exports.addProcessor = exports.getProcessor = exports.EthersError = exports.BigDecimal = exports.ProcessorState = exports.transformEtherError = exports.SuiBindOptions = exports.SolanaBindOptions = exports.BindOptions = exports.ContractNamer = exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.DummyProvider = exports.setProvider = exports.getProvider = exports.MetricDescriptorOption = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.ProcessorServiceImpl = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = void 0;
18
18
  var base_processor_1 = require("./base-processor");
19
19
  Object.defineProperty(exports, "BaseProcessor", { enumerable: true, get: function () { return base_processor_1.BaseProcessor; } });
20
20
  var generic_processor_1 = require("./generic-processor");
@@ -29,9 +29,12 @@ Object.defineProperty(exports, "SolanaContext", { enumerable: true, get: functio
29
29
  var service_1 = require("./service");
30
30
  Object.defineProperty(exports, "ProcessorServiceImpl", { enumerable: true, get: function () { return service_1.ProcessorServiceImpl; } });
31
31
  var meter_1 = require("./meter");
32
- Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return meter_1.Counter; } });
32
+ Object.defineProperty(exports, "CounterBinding", { enumerable: true, get: function () { return meter_1.CounterBinding; } });
33
33
  Object.defineProperty(exports, "Meter", { enumerable: true, get: function () { return meter_1.Meter; } });
34
+ Object.defineProperty(exports, "GaugeBinding", { enumerable: true, get: function () { return meter_1.GaugeBinding; } });
35
+ Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return meter_1.Counter; } });
34
36
  Object.defineProperty(exports, "Gauge", { enumerable: true, get: function () { return meter_1.Gauge; } });
37
+ Object.defineProperty(exports, "MetricDescriptorOption", { enumerable: true, get: function () { return meter_1.MetricDescriptorOption; } });
35
38
  var provider_1 = require("./provider");
36
39
  Object.defineProperty(exports, "getProvider", { enumerable: true, get: function () { return provider_1.getProvider; } });
37
40
  Object.defineProperty(exports, "setProvider", { enumerable: true, get: function () { return provider_1.setProvider; } });
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,qCAAmF;AAA1E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AAChE,qCAAgD;AAAvC,+GAAA,oBAAoB,OAAA;AAC7B,iCAA+C;AAAtC,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,8FAAA,KAAK,OAAA;AAC9B,uCAAoE;AAA3D,uGAAA,WAAW,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,yGAAA,aAAa,OAAA;AAChD,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,iDAAkD;AAAzC,iHAAA,gBAAgB,OAAA;AACzB,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,+CAA+E;AAAtE,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAAE,8GAAA,cAAc,OAAA;AACvD,iCAA6C;AAApC,4GAAA,mBAAmB,OAAA;AAC5B,qDAAkD;AAAzC,iHAAA,cAAc,OAAA;AACvB,6CAAsD;AAA7C,0GAAA,SAAS,OAAc;AAChC,iCAAqC;AAA5B,oGAAA,WAAW,OAAA;AAGpB,iCAAyG;AAAhG,qGAAA,YAAY,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAExF,mEAAgD;AAEhD,4CAAoD;AAA3C,4GAAA,iBAAiB,OAAA","sourcesContent":["export { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { Context, ContractView, BoundContractView, SolanaContext } from './context'\nexport { ProcessorServiceImpl } from './service'\nexport { Counter, Meter, Gauge } from './meter'\nexport { getProvider, setProvider, DummyProvider } from './provider'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { SuiBaseProcessor } from './sui-processor'\nexport { ContractNamer } from './contract-namer'\nexport { BindOptions, SolanaBindOptions, SuiBindOptions } from './bind-options'\nexport { transformEtherError } from './error'\nexport { ProcessorState } from './processor-state'\nexport { BigNumber as BigDecimal } from 'bignumber.js'\nexport { EthersError } from './error'\nexport type { TypedCallTrace } from './trace'\n\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'\n\nexport * from './gen/processor/protos/processor'\n\nexport { SPLTokenProcessor } from './solana/builtin'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,qCAAmF;AAA1E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AAChE,qCAAgD;AAAvC,+GAAA,oBAAoB,OAAA;AAC7B,iCAAqG;AAA5F,uGAAA,cAAc,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,+GAAA,sBAAsB,OAAA;AACpF,uCAAoE;AAA3D,uGAAA,WAAW,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,yGAAA,aAAa,OAAA;AAChD,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,iDAAkD;AAAzC,iHAAA,gBAAgB,OAAA;AACzB,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,+CAA+E;AAAtE,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAAE,8GAAA,cAAc,OAAA;AACvD,iCAA6C;AAApC,4GAAA,mBAAmB,OAAA;AAC5B,qDAAkD;AAAzC,iHAAA,cAAc,OAAA;AACvB,6CAAsD;AAA7C,0GAAA,SAAS,OAAc;AAChC,iCAAqC;AAA5B,oGAAA,WAAW,OAAA;AAGpB,iCAAyG;AAAhG,qGAAA,YAAY,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAExF,mEAAgD;AAEhD,4CAAoD;AAA3C,4GAAA,iBAAiB,OAAA","sourcesContent":["export { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { Context, ContractView, BoundContractView, SolanaContext } from './context'\nexport { ProcessorServiceImpl } from './service'\nexport { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter'\nexport { getProvider, setProvider, DummyProvider } from './provider'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { SuiBaseProcessor } from './sui-processor'\nexport { ContractNamer } from './contract-namer'\nexport { BindOptions, SolanaBindOptions, SuiBindOptions } from './bind-options'\nexport { transformEtherError } from './error'\nexport { ProcessorState } from './processor-state'\nexport { BigNumber as BigDecimal } from 'bignumber.js'\nexport { EthersError } from './error'\nexport type { TypedCallTrace } from './trace'\n\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'\n\nexport * from './gen/processor/protos/processor'\n\nexport { SPLTokenProcessor } from './solana/builtin'\n"]}
package/lib/meter.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { MetricDescriptor } from './gen/processor/protos/processor';
1
2
  import { BaseContext } from './context';
2
3
  import { Numberish } from './numberish';
3
4
  export declare function normalizeName(name: string): string;
@@ -7,16 +8,33 @@ export declare function normalizeLabels(labels: Labels): Labels;
7
8
  export declare type Labels = {
8
9
  [key: string]: string;
9
10
  };
10
- export declare class Counter {
11
+ export declare class MetricDescriptorOption {
12
+ unit?: string;
13
+ description?: string;
14
+ sparse?: boolean;
15
+ }
16
+ export declare class Metric {
17
+ descriptor: MetricDescriptor;
18
+ usage: number;
19
+ constructor(name: string, option?: MetricDescriptorOption);
20
+ }
21
+ export declare class Counter extends Metric {
22
+ add(ctx: BaseContext, value: Numberish, labels?: Labels): void;
23
+ sub(ctx: BaseContext, value: Numberish, labels?: Labels): void;
24
+ private record;
25
+ }
26
+ export declare class CounterBinding {
11
27
  private readonly ctx;
12
- private readonly name;
28
+ private readonly counter;
13
29
  constructor(name: string, ctx: BaseContext);
14
30
  add(value: Numberish, labels?: Labels): void;
15
31
  sub(value: Numberish, labels?: Labels): void;
16
- private record;
17
32
  }
18
- export declare class Gauge {
19
- private readonly name;
33
+ export declare class Gauge extends Metric {
34
+ record(ctx: BaseContext, value: Numberish, labels?: Labels): void;
35
+ }
36
+ export declare class GaugeBinding {
37
+ private readonly gauge;
20
38
  private readonly ctx;
21
39
  constructor(name: string, ctx: BaseContext);
22
40
  record(value: Numberish, labels?: Labels): void;
@@ -24,6 +42,6 @@ export declare class Gauge {
24
42
  export declare class Meter {
25
43
  private readonly ctx;
26
44
  constructor(ctx: BaseContext);
27
- Counter(name: string): Counter;
28
- Gauge(name: string): Gauge;
45
+ Counter(name: string): CounterBinding;
46
+ Gauge(name: string): GaugeBinding;
29
47
  }
package/lib/meter.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Meter = exports.Gauge = exports.Counter = exports.normalizeLabels = exports.normalizeValue = exports.normalizeKey = exports.normalizeName = void 0;
6
+ exports.Meter = exports.GaugeBinding = exports.Gauge = exports.CounterBinding = exports.Counter = exports.Metric = exports.MetricDescriptorOption = exports.normalizeLabels = exports.normalizeValue = exports.normalizeKey = exports.normalizeName = void 0;
7
+ const processor_1 = require("./gen/processor/protos/processor");
7
8
  const context_1 = require("./context");
8
9
  const numberish_1 = require("./numberish");
9
10
  const long_1 = __importDefault(require("long"));
@@ -31,8 +32,13 @@ function normalizeLabels(labels) {
31
32
  return normLabels;
32
33
  }
33
34
  exports.normalizeLabels = normalizeLabels;
34
- function GetRecordMetaData(ctx, name, labels) {
35
- name = normalizeName(name);
35
+ function GetRecordMetaData(ctx, metric, labels) {
36
+ let descriptor = metric.descriptor;
37
+ if (metric.usage > 0) {
38
+ // Other setting don't need to be write multiple times
39
+ descriptor = processor_1.MetricDescriptor.fromPartial({ name: descriptor.name });
40
+ }
41
+ descriptor.name = normalizeName(descriptor.name);
36
42
  if (ctx instanceof context_1.Context) {
37
43
  if (ctx.log) {
38
44
  return {
@@ -41,7 +47,8 @@ function GetRecordMetaData(ctx, name, labels) {
41
47
  transactionIndex: ctx.log.transactionIndex,
42
48
  logIndex: ctx.log.logIndex,
43
49
  chainId: ctx.chainId.toString(),
44
- name: name,
50
+ name: descriptor.name,
51
+ descriptor: descriptor,
45
52
  labels: normalizeLabels(labels),
46
53
  };
47
54
  }
@@ -52,7 +59,8 @@ function GetRecordMetaData(ctx, name, labels) {
52
59
  transactionIndex: -1,
53
60
  logIndex: -1,
54
61
  chainId: ctx.chainId.toString(),
55
- name: name,
62
+ name: descriptor.name,
63
+ descriptor: descriptor,
56
64
  labels: normalizeLabels(labels),
57
65
  };
58
66
  }
@@ -63,7 +71,8 @@ function GetRecordMetaData(ctx, name, labels) {
63
71
  transactionIndex: ctx.trace.transactionPosition,
64
72
  logIndex: -1,
65
73
  chainId: ctx.chainId.toString(),
66
- name: name,
74
+ name: descriptor.name,
75
+ descriptor: descriptor,
67
76
  labels: normalizeLabels(labels),
68
77
  };
69
78
  }
@@ -75,7 +84,8 @@ function GetRecordMetaData(ctx, name, labels) {
75
84
  transactionIndex: 0,
76
85
  logIndex: 0,
77
86
  chainId: 'SOL_mainnet',
78
- name: name,
87
+ name: descriptor.name,
88
+ descriptor: descriptor,
79
89
  labels: normalizeLabels(labels),
80
90
  };
81
91
  }
@@ -86,75 +96,104 @@ function GetRecordMetaData(ctx, name, labels) {
86
96
  transactionIndex: 0,
87
97
  logIndex: 0,
88
98
  chainId: 'SUI_devnet',
89
- name: name,
99
+ name: descriptor.name,
100
+ descriptor: descriptor,
90
101
  labels: normalizeLabels(labels),
91
102
  };
92
103
  }
93
104
  throw new Error("This can't happen");
94
105
  }
95
- class Counter {
96
- ctx;
97
- name;
98
- constructor(name, ctx) {
99
- this.name = name;
100
- this.ctx = ctx;
106
+ class MetricDescriptorOption {
107
+ unit;
108
+ description;
109
+ sparse;
110
+ }
111
+ exports.MetricDescriptorOption = MetricDescriptorOption;
112
+ class Metric {
113
+ descriptor = processor_1.MetricDescriptor.fromPartial({});
114
+ usage = 0;
115
+ constructor(name, option) {
116
+ this.descriptor.name = name;
117
+ if (option) {
118
+ if (option.unit) {
119
+ this.descriptor.unit = option.unit;
120
+ }
121
+ if (option.description) {
122
+ this.descriptor.description = option.description;
123
+ }
124
+ if (option.sparse) {
125
+ this.descriptor.sparse = option.sparse;
126
+ }
127
+ }
101
128
  }
102
- add(value, labels = {}) {
103
- this.record(value, labels, true);
129
+ }
130
+ exports.Metric = Metric;
131
+ class Counter extends Metric {
132
+ add(ctx, value, labels = {}) {
133
+ this.record(ctx, value, labels, true);
104
134
  }
105
- sub(value, labels = {}) {
106
- this.record(value, labels, false);
135
+ sub(ctx, value, labels = {}) {
136
+ this.record(ctx, value, labels, false);
107
137
  }
108
- record(value, labels, add) {
109
- this.ctx.counters.push({
110
- metadata: GetRecordMetaData(this.ctx, this.name, labels),
138
+ record(ctx, value, labels, add) {
139
+ ctx.counters.push({
140
+ metadata: GetRecordMetaData(ctx, this, labels),
111
141
  metricValue: (0, numberish_1.toMetricValue)(value),
112
142
  add: add,
113
143
  runtimeInfo: undefined,
114
144
  });
145
+ this.usage++;
115
146
  }
116
147
  }
117
148
  exports.Counter = Counter;
118
- class Gauge {
119
- name;
149
+ class CounterBinding {
120
150
  ctx;
151
+ counter;
121
152
  constructor(name, ctx) {
122
- this.name = name;
153
+ this.counter = new Counter(name);
123
154
  this.ctx = ctx;
124
155
  }
125
- record(value, labels = {}) {
126
- this.ctx.gauges.push({
127
- metadata: GetRecordMetaData(this.ctx, this.name, labels),
156
+ add(value, labels = {}) {
157
+ this.counter.add(this.ctx, value, labels);
158
+ }
159
+ sub(value, labels = {}) {
160
+ this.counter.sub(this.ctx, value, labels);
161
+ }
162
+ }
163
+ exports.CounterBinding = CounterBinding;
164
+ class Gauge extends Metric {
165
+ record(ctx, value, labels = {}) {
166
+ ctx.gauges.push({
167
+ metadata: GetRecordMetaData(ctx, this, labels),
128
168
  metricValue: (0, numberish_1.toMetricValue)(value),
129
169
  runtimeInfo: undefined,
130
170
  });
171
+ this.usage++;
131
172
  }
132
173
  }
133
174
  exports.Gauge = Gauge;
175
+ class GaugeBinding {
176
+ gauge;
177
+ ctx;
178
+ constructor(name, ctx) {
179
+ this.gauge = new Gauge(name);
180
+ this.ctx = ctx;
181
+ }
182
+ record(value, labels = {}) {
183
+ this.gauge.record(this.ctx, value, labels);
184
+ }
185
+ }
186
+ exports.GaugeBinding = GaugeBinding;
134
187
  class Meter {
135
188
  ctx;
136
- // TODO is map necessary since we are sending request remotely?
137
- // counterMap = new Map<string, Counter>()
138
- // gaugeMap = new Map<string, Gauge>()
139
189
  constructor(ctx) {
140
190
  this.ctx = ctx;
141
191
  }
142
192
  Counter(name) {
143
- // let counter = this.counterMap.get(name)
144
- // if (!counter) {
145
- // counter = new Counter(name, this.ctx)
146
- // }
147
- // return counter
148
- return new Counter(name, this.ctx);
193
+ return new CounterBinding(name, this.ctx);
149
194
  }
150
195
  Gauge(name) {
151
- // let gauge = this.gaugeMap.get(name)
152
- //
153
- // if (!gauge) {
154
- // gauge = new Gauge(name, this.ctx)
155
- // }
156
- // return gauge
157
- return new Gauge(name, this.ctx);
196
+ return new GaugeBinding(name, this.ctx);
158
197
  }
159
198
  }
160
199
  exports.Meter = Meter;
package/lib/meter.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"meter.js","sourceRoot":"","sources":["../src/meter.ts"],"names":[],"mappings":";;;;;;AACA,uCAA2E;AAC3E,2CAAsD;AACtD,gDAAuB;AAEvB,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAC/C,CAAC;AAHD,sCAGC;AAED,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,OAAO,SAAS,CAAA;KACjB;IACD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AALD,oCAKC;AAED,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC3B,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe,CAAC,MAAc;IAC5C,MAAM,UAAU,GAAW,EAAE,CAAA;IAC7B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;QACxB,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;KAC5D;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAND,0CAMC;AAED,SAAS,iBAAiB,CAAC,GAAgB,EAAE,IAAY,EAAE,MAAc;IACvE,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;IAE1B,IAAI,GAAG,YAAY,iBAAO,EAAE;QAC1B,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,OAAO;gBACL,eAAe,EAAE,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO;gBACjD,WAAW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K,CAAC;YACjC,GAAG,EAAE,GAAG;YACR,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;IACJ,CAAC;CACF;AAzBD,0BAyBC;AAED,MAAa,KAAK;IACC,IAAI,CAAQ;IACZ,GAAG,CAAa;IAEjC,YAAY,IAAY,EAAE,GAAgB;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,MAAM,CAAC,KAAgB,EAAE,SAAiB,EAAE;QAC1C,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YACnB,QAAQ,EAAE,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;YACxD,WAAW,EAAE,IAAA,yBAAa,EAAC,KAAK,CAAC;YACjC,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;IACJ,CAAC;CACF;AAhBD,sBAgBC;AAED,MAAa,KAAK;IACC,GAAG,CAAa;IAEjC,+DAA+D;IAC/D,0CAA0C;IAC1C,sCAAsC;IAEtC,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,0CAA0C;QAE1C,kBAAkB;QAClB,6CAA6C;QAC7C,IAAI;QACJ,iBAAiB;QAEjB,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,sCAAsC;QACtC,EAAE;QACF,gBAAgB;QAChB,wCAAwC;QACxC,IAAI;QACJ,eAAe;QACf,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;CACF;AA/BD,sBA+BC","sourcesContent":["import { RecordMetaData } from './gen/processor/protos/processor'\nimport { BaseContext, Context, SolanaContext, SuiContext } from './context'\nimport { toMetricValue, Numberish } from './numberish'\nimport Long from 'long'\n\nexport function normalizeName(name: string): string {\n const regex = new RegExp('![_.a-zA-Z0-9]')\n return name.slice(0, 100).replace(regex, '_')\n}\n\nexport function normalizeKey(name: string): string {\n if (name === 'labels') {\n return 'labels_'\n }\n return normalizeName(name)\n}\n\nexport function normalizeValue(name: string): string {\n return name.slice(0, 100)\n}\n\nexport function normalizeLabels(labels: Labels): Labels {\n const normLabels: Labels = {}\n for (const key in labels) {\n normLabels[normalizeKey(key)] = normalizeValue(labels[key])\n }\n return normLabels\n}\n\nfunction GetRecordMetaData(ctx: BaseContext, name: string, labels: Labels): RecordMetaData {\n name = normalizeName(name)\n\n if (ctx instanceof Context) {\n if (ctx.log) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.log.blockNumber, true), // TODO need number type to be long\n transactionIndex: ctx.log.transactionIndex,\n logIndex: ctx.log.logIndex,\n chainId: ctx.chainId.toString(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n if (ctx.block) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.block.number, true),\n transactionIndex: -1,\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n if (ctx.trace) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.trace.blockNumber, true),\n transactionIndex: ctx.trace.transactionPosition, // TODO make sure if this is the right value to set\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n } else if (ctx instanceof SolanaContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: Long.ZERO, // TODO need number type to be long\n transactionIndex: 0,\n logIndex: 0,\n chainId: 'SOL_mainnet', // TODO set in context\n name: name,\n labels: normalizeLabels(labels),\n }\n } else if (ctx instanceof SuiContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: Long.ZERO, // TODO need number type to be long\n transactionIndex: 0,\n logIndex: 0,\n chainId: 'SUI_devnet', // TODO set in context\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"This can't happen\")\n}\n\nexport type Labels = { [key: string]: string }\n\nexport class Counter {\n private readonly ctx: BaseContext\n private readonly name: string\n\n constructor(name: string, ctx: BaseContext) {\n this.name = name\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.record(value, labels, true)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.record(value, labels, false)\n }\n\n private record(value: Numberish, labels: Labels, add: boolean) {\n this.ctx.counters.push({\n metadata: GetRecordMetaData(this.ctx, this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class Gauge {\n private readonly name: string\n private readonly ctx: BaseContext\n\n constructor(name: string, ctx: BaseContext) {\n this.name = name\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.ctx.gauges.push({\n metadata: GetRecordMetaData(this.ctx, this.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class Meter {\n private readonly ctx: BaseContext\n\n // TODO is map necessary since we are sending request remotely?\n // counterMap = new Map<string, Counter>()\n // gaugeMap = new Map<string, Gauge>()\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): Counter {\n // let counter = this.counterMap.get(name)\n\n // if (!counter) {\n // counter = new Counter(name, this.ctx)\n // }\n // return counter\n\n return new Counter(name, this.ctx)\n }\n\n Gauge(name: string): Gauge {\n // let gauge = this.gaugeMap.get(name)\n //\n // if (!gauge) {\n // gauge = new Gauge(name, this.ctx)\n // }\n // return gauge\n return new Gauge(name, this.ctx)\n }\n}\n"]}
1
+ {"version":3,"file":"meter.js","sourceRoot":"","sources":["../src/meter.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAmF;AACnF,uCAA2E;AAC3E,2CAAsD;AACtD,gDAAuB;AAEvB,SAAgB,aAA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,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF;AAdD,sBAcC","sourcesContent":["import { MetricDescriptor, RecordMetaData } from './gen/processor/protos/processor'\nimport { BaseContext, Context, SolanaContext, SuiContext } from './context'\nimport { toMetricValue, Numberish } from './numberish'\nimport Long from 'long'\n\nexport function normalizeName(name: string): string {\n const regex = new RegExp('![_.a-zA-Z0-9]')\n return name.slice(0, 100).replace(regex, '_')\n}\n\nexport function normalizeKey(name: string): string {\n if (name === 'labels') {\n return 'labels_'\n }\n return normalizeName(name)\n}\n\nexport function normalizeValue(name: string): string {\n return name.slice(0, 100)\n}\n\nexport function normalizeLabels(labels: Labels): Labels {\n const normLabels: Labels = {}\n for (const key in labels) {\n normLabels[normalizeKey(key)] = normalizeValue(labels[key])\n }\n return normLabels\n}\n\nfunction GetRecordMetaData(ctx: BaseContext, metric: Metric, labels: Labels): RecordMetaData {\n let descriptor = metric.descriptor\n if (metric.usage > 0) {\n // Other setting don't need to be write multiple times\n descriptor = MetricDescriptor.fromPartial({ name: descriptor.name })\n }\n\n descriptor.name = normalizeName(descriptor.name)\n\n if (ctx instanceof Context) {\n if (ctx.log) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.log.blockNumber, true), // TODO need number type to be long\n transactionIndex: ctx.log.transactionIndex,\n logIndex: ctx.log.logIndex,\n chainId: ctx.chainId.toString(),\n name: descriptor.name,\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (ctx.block) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.block.number, true),\n transactionIndex: -1,\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n name: descriptor.name,\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (ctx.trace) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.trace.blockNumber, true),\n transactionIndex: ctx.trace.transactionPosition, // TODO make sure if this is the right value to set\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n name: descriptor.name,\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n } else if (ctx instanceof SolanaContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: Long.ZERO, // TODO need number type to be long\n transactionIndex: 0,\n logIndex: 0,\n chainId: 'SOL_mainnet', // TODO set in context\n name: descriptor.name,\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n } else if (ctx instanceof SuiContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: Long.ZERO, // TODO need number type to be long\n transactionIndex: 0,\n logIndex: 0,\n chainId: 'SUI_devnet', // TODO set in context\n name: descriptor.name,\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"This can't happen\")\n}\n\nexport type Labels = { [key: string]: string }\n\nexport class MetricDescriptorOption {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\nexport class Metric {\n descriptor: MetricDescriptor = MetricDescriptor.fromPartial({})\n usage = 0\n\n constructor(name: string, option?: MetricDescriptorOption) {\n this.descriptor.name = name\n if (option) {\n if (option.unit) {\n this.descriptor.unit = option.unit\n }\n if (option.description) {\n this.descriptor.description = option.description\n }\n if (option.sparse) {\n this.descriptor.sparse = option.sparse\n }\n }\n }\n}\n\nexport class Counter extends Metric {\n add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, true)\n }\n\n sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, false)\n }\n\n private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {\n ctx.counters.push({\n metadata: GetRecordMetaData(ctx, this, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n this.usage++\n }\n}\n\nexport class CounterBinding {\n private readonly ctx: BaseContext\n private readonly counter: Counter\n\n constructor(name: string, ctx: BaseContext) {\n this.counter = new Counter(name)\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.counter.add(this.ctx, value, labels)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.counter.sub(this.ctx, value, labels)\n }\n}\n\nexport class Gauge extends Metric {\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx.gauges.push({\n metadata: GetRecordMetaData(ctx, this, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n this.usage++\n }\n}\n\nexport class GaugeBinding {\n private readonly gauge: Gauge\n private readonly ctx: BaseContext\n\n constructor(name: string, ctx: BaseContext) {\n this.gauge = new Gauge(name)\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.gauge.record(this.ctx, value, labels)\n }\n}\n\nexport class Meter {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): CounterBinding {\n return new CounterBinding(name, this.ctx)\n }\n\n Gauge(name: string): GaugeBinding {\n return new GaugeBinding(name, this.ctx)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.12.5",
4
+ "version": "1.13.0",
5
5
  "scripts": {
6
6
  "compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
7
7
  "compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli",
package/src/cli/upload.ts CHANGED
@@ -52,6 +52,12 @@ export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: s
52
52
  } catch (e) {
53
53
  chalk.yellow(e)
54
54
  }
55
+ try {
56
+ const gitUrl = execSync('git remote get-url origin').toString().trim()
57
+ data.append('gitUrl', gitUrl)
58
+ } catch (e) {
59
+ // skip errors
60
+ }
55
61
 
56
62
  url.pathname = '/api/v1/processors'
57
63
 
@@ -263,6 +263,13 @@ export interface ProcessResult {
263
263
  logs: LogResult[];
264
264
  }
265
265
 
266
+ export interface MetricDescriptor {
267
+ name: string;
268
+ unit: string;
269
+ description: string;
270
+ sparse: boolean;
271
+ }
272
+
266
273
  export interface RecordMetaData {
267
274
  contractAddress: string;
268
275
  blockNumber: Long;
@@ -270,6 +277,7 @@ export interface RecordMetaData {
270
277
  logIndex: number;
271
278
  chainId: string;
272
279
  name: string;
280
+ descriptor: MetricDescriptor | undefined;
273
281
  labels: { [key: string]: string };
274
282
  }
275
283
 
@@ -2661,6 +2669,86 @@ export const ProcessResult = {
2661
2669
  },
2662
2670
  };
2663
2671
 
2672
+ function createBaseMetricDescriptor(): MetricDescriptor {
2673
+ return { name: "", unit: "", description: "", sparse: false };
2674
+ }
2675
+
2676
+ export const MetricDescriptor = {
2677
+ encode(
2678
+ message: MetricDescriptor,
2679
+ writer: _m0.Writer = _m0.Writer.create()
2680
+ ): _m0.Writer {
2681
+ if (message.name !== "") {
2682
+ writer.uint32(10).string(message.name);
2683
+ }
2684
+ if (message.unit !== "") {
2685
+ writer.uint32(18).string(message.unit);
2686
+ }
2687
+ if (message.description !== "") {
2688
+ writer.uint32(26).string(message.description);
2689
+ }
2690
+ if (message.sparse === true) {
2691
+ writer.uint32(32).bool(message.sparse);
2692
+ }
2693
+ return writer;
2694
+ },
2695
+
2696
+ decode(input: _m0.Reader | Uint8Array, length?: number): MetricDescriptor {
2697
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
2698
+ let end = length === undefined ? reader.len : reader.pos + length;
2699
+ const message = createBaseMetricDescriptor();
2700
+ while (reader.pos < end) {
2701
+ const tag = reader.uint32();
2702
+ switch (tag >>> 3) {
2703
+ case 1:
2704
+ message.name = reader.string();
2705
+ break;
2706
+ case 2:
2707
+ message.unit = reader.string();
2708
+ break;
2709
+ case 3:
2710
+ message.description = reader.string();
2711
+ break;
2712
+ case 4:
2713
+ message.sparse = reader.bool();
2714
+ break;
2715
+ default:
2716
+ reader.skipType(tag & 7);
2717
+ break;
2718
+ }
2719
+ }
2720
+ return message;
2721
+ },
2722
+
2723
+ fromJSON(object: any): MetricDescriptor {
2724
+ return {
2725
+ name: isSet(object.name) ? String(object.name) : "",
2726
+ unit: isSet(object.unit) ? String(object.unit) : "",
2727
+ description: isSet(object.description) ? String(object.description) : "",
2728
+ sparse: isSet(object.sparse) ? Boolean(object.sparse) : false,
2729
+ };
2730
+ },
2731
+
2732
+ toJSON(message: MetricDescriptor): unknown {
2733
+ const obj: any = {};
2734
+ message.name !== undefined && (obj.name = message.name);
2735
+ message.unit !== undefined && (obj.unit = message.unit);
2736
+ message.description !== undefined &&
2737
+ (obj.description = message.description);
2738
+ message.sparse !== undefined && (obj.sparse = message.sparse);
2739
+ return obj;
2740
+ },
2741
+
2742
+ fromPartial(object: DeepPartial<MetricDescriptor>): MetricDescriptor {
2743
+ const message = createBaseMetricDescriptor();
2744
+ message.name = object.name ?? "";
2745
+ message.unit = object.unit ?? "";
2746
+ message.description = object.description ?? "";
2747
+ message.sparse = object.sparse ?? false;
2748
+ return message;
2749
+ },
2750
+ };
2751
+
2664
2752
  function createBaseRecordMetaData(): RecordMetaData {
2665
2753
  return {
2666
2754
  contractAddress: "",
@@ -2669,6 +2757,7 @@ function createBaseRecordMetaData(): RecordMetaData {
2669
2757
  logIndex: 0,
2670
2758
  chainId: "",
2671
2759
  name: "",
2760
+ descriptor: undefined,
2672
2761
  labels: {},
2673
2762
  };
2674
2763
  }
@@ -2696,6 +2785,12 @@ export const RecordMetaData = {
2696
2785
  if (message.name !== "") {
2697
2786
  writer.uint32(50).string(message.name);
2698
2787
  }
2788
+ if (message.descriptor !== undefined) {
2789
+ MetricDescriptor.encode(
2790
+ message.descriptor,
2791
+ writer.uint32(66).fork()
2792
+ ).ldelim();
2793
+ }
2699
2794
  Object.entries(message.labels).forEach(([key, value]) => {
2700
2795
  RecordMetaData_LabelsEntry.encode(
2701
2796
  { key: key as any, value },
@@ -2730,6 +2825,9 @@ export const RecordMetaData = {
2730
2825
  case 6:
2731
2826
  message.name = reader.string();
2732
2827
  break;
2828
+ case 8:
2829
+ message.descriptor = MetricDescriptor.decode(reader, reader.uint32());
2830
+ break;
2733
2831
  case 7:
2734
2832
  const entry7 = RecordMetaData_LabelsEntry.decode(
2735
2833
  reader,
@@ -2761,6 +2859,9 @@ export const RecordMetaData = {
2761
2859
  logIndex: isSet(object.logIndex) ? Number(object.logIndex) : 0,
2762
2860
  chainId: isSet(object.chainId) ? String(object.chainId) : "",
2763
2861
  name: isSet(object.name) ? String(object.name) : "",
2862
+ descriptor: isSet(object.descriptor)
2863
+ ? MetricDescriptor.fromJSON(object.descriptor)
2864
+ : undefined,
2764
2865
  labels: isObject(object.labels)
2765
2866
  ? Object.entries(object.labels).reduce<{ [key: string]: string }>(
2766
2867
  (acc, [key, value]) => {
@@ -2785,6 +2886,10 @@ export const RecordMetaData = {
2785
2886
  (obj.logIndex = Math.round(message.logIndex));
2786
2887
  message.chainId !== undefined && (obj.chainId = message.chainId);
2787
2888
  message.name !== undefined && (obj.name = message.name);
2889
+ message.descriptor !== undefined &&
2890
+ (obj.descriptor = message.descriptor
2891
+ ? MetricDescriptor.toJSON(message.descriptor)
2892
+ : undefined);
2788
2893
  obj.labels = {};
2789
2894
  if (message.labels) {
2790
2895
  Object.entries(message.labels).forEach(([k, v]) => {
@@ -2805,6 +2910,10 @@ export const RecordMetaData = {
2805
2910
  message.logIndex = object.logIndex ?? 0;
2806
2911
  message.chainId = object.chainId ?? "";
2807
2912
  message.name = object.name ?? "";
2913
+ message.descriptor =
2914
+ object.descriptor !== undefined && object.descriptor !== null
2915
+ ? MetricDescriptor.fromPartial(object.descriptor)
2916
+ : undefined;
2808
2917
  message.labels = Object.entries(object.labels ?? {}).reduce<{
2809
2918
  [key: string]: string;
2810
2919
  }>((acc, [key, value]) => {
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ export { GenericProcessor } from './generic-processor'
3
3
  export { BaseProcessorTemplate } from './base-processor-template'
4
4
  export { Context, ContractView, BoundContractView, SolanaContext } from './context'
5
5
  export { ProcessorServiceImpl } from './service'
6
- export { Counter, Meter, Gauge } from './meter'
6
+ export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter'
7
7
  export { getProvider, setProvider, DummyProvider } from './provider'
8
8
  export { SolanaBaseProcessor } from './solana-processor'
9
9
  export { SuiBaseProcessor } from './sui-processor'