@sentio/sdk 1.31.1 → 1.31.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/lib/binds.d.ts CHANGED
@@ -2,6 +2,10 @@ import { BindOptions } from './core/bind-options';
2
2
  import { BaseProcessor, ContractView } from './core';
3
3
  import { Networkish } from '@ethersproject/networks';
4
4
  import { BaseContract } from 'ethers';
5
+ import { MapStateStorage } from './state/state-storage';
6
+ export declare class ProcessorState extends MapStateStorage<BaseProcessor<any, any>> {
7
+ static INSTANCE: ProcessorState;
8
+ }
5
9
  export declare function getProcessor(opts: BindOptions): BaseProcessor<any, any> | undefined;
6
10
  export declare function addProcessor(opts: BindOptions, processor: BaseProcessor<any, any>): void;
7
11
  export declare function getContractByABI(abiName: string, address: string, network: Networkish): ContractView<BaseContract> | undefined;
package/lib/binds.js CHANGED
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addContractByABI = exports.getContractByABI = exports.addProcessor = exports.getProcessor = void 0;
3
+ exports.addContractByABI = exports.getContractByABI = exports.addProcessor = exports.getProcessor = exports.ProcessorState = void 0;
4
4
  const bind_options_1 = require("./core/bind-options");
5
5
  const providers_1 = require("@ethersproject/providers");
6
+ const state_storage_1 = require("./state/state-storage");
7
+ class ProcessorState extends state_storage_1.MapStateStorage {
8
+ static INSTANCE = new ProcessorState();
9
+ }
10
+ exports.ProcessorState = ProcessorState;
11
+ // from abiName_address_chainId => contract wrapper
12
+ const contracts = new Map();
6
13
  function getKey(abiName, address, network) {
7
14
  const chainId = (0, providers_1.getNetwork)(network).chainId.toString();
8
15
  return [abiName, address.toLowerCase(), chainId].join('_');
@@ -10,23 +17,22 @@ function getKey(abiName, address, network) {
10
17
  // Dedup processor that bind multiple times
11
18
  function getProcessor(opts) {
12
19
  const sig = (0, bind_options_1.getOptionsSignature)(opts);
13
- return global.PROCESSOR_STATE.processorMap.get(sig);
20
+ return ProcessorState.INSTANCE.getValue(sig);
14
21
  }
15
22
  exports.getProcessor = getProcessor;
16
23
  function addProcessor(opts, processor) {
17
24
  const sig = (0, bind_options_1.getOptionsSignature)(opts);
18
- global.PROCESSOR_STATE.processors.push(processor);
19
- global.PROCESSOR_STATE.processorMap.set(sig, processor);
25
+ ProcessorState.INSTANCE.getOrSetValue(sig, processor);
20
26
  }
21
27
  exports.addProcessor = addProcessor;
22
28
  function getContractByABI(abiName, address, network) {
23
29
  const key = getKey(abiName, address, network);
24
- return global.PROCESSOR_STATE.contracts.get(key);
30
+ return contracts.get(key);
25
31
  }
26
32
  exports.getContractByABI = getContractByABI;
27
33
  function addContractByABI(abiName, address, network, contract) {
28
34
  const key = getKey(abiName, address, network);
29
- return global.PROCESSOR_STATE.contracts.set(key, contract);
35
+ return contracts.set(key, contract);
30
36
  }
31
37
  exports.addContractByABI = addContractByABI;
32
38
  //# sourceMappingURL=binds.js.map
package/lib/binds.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"binds.js","sourceRoot":"","sources":["../src/binds.ts"],"names":[],"mappings":";;;AAAA,sDAAsE;AAGtE,wDAAqD;AAGrD,SAAS,MAAM,CAAC,OAAe,EAAE,OAAe,EAAE,OAAmB;IACnE,MAAM,OAAO,GAAG,IAAA,sBAAU,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;IACtD,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC5D,CAAC;AAED,2CAA2C;AAC3C,SAAgB,YAAY,CAAC,IAAiB;IAC5C,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,CAAA;IACrC,OAAO,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACrD,CAAC;AAHD,oCAGC;AAED,SAAgB,YAAY,CAAC,IAAiB,EAAE,SAAkC;IAChF,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,CAAA;IAErC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACjD,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AACzD,CAAC;AALD,oCAKC;AAED,SAAgB,gBAAgB,CAAC,OAAe,EAAE,OAAe,EAAE,OAAmB;IACpF,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,OAAO,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAClD,CAAC;AAHD,4CAGC;AAED,SAAgB,gBAAgB,CAC9B,OAAe,EACf,OAAe,EACf,OAAmB,EACnB,QAAoC;IAEpC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,OAAO,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AAC5D,CAAC;AARD,4CAQC","sourcesContent":["import { BindOptions, getOptionsSignature } from './core/bind-options'\nimport { BaseProcessor, ContractView } from './core'\nimport { Networkish } from '@ethersproject/networks'\nimport { getNetwork } from '@ethersproject/providers'\nimport { BaseContract } from 'ethers'\n\nfunction getKey(abiName: string, address: string, network: Networkish) {\n const chainId = getNetwork(network).chainId.toString()\n return [abiName, address.toLowerCase(), chainId].join('_')\n}\n\n// Dedup processor that bind multiple times\nexport function getProcessor(opts: BindOptions) {\n const sig = getOptionsSignature(opts)\n return global.PROCESSOR_STATE.processorMap.get(sig)\n}\n\nexport function addProcessor(opts: BindOptions, processor: BaseProcessor<any, any>) {\n const sig = getOptionsSignature(opts)\n\n global.PROCESSOR_STATE.processors.push(processor)\n global.PROCESSOR_STATE.processorMap.set(sig, processor)\n}\n\nexport function getContractByABI(abiName: string, address: string, network: Networkish) {\n const key = getKey(abiName, address, network)\n return global.PROCESSOR_STATE.contracts.get(key)\n}\n\nexport function addContractByABI(\n abiName: string,\n address: string,\n network: Networkish,\n contract: ContractView<BaseContract>\n) {\n const key = getKey(abiName, address, network)\n return global.PROCESSOR_STATE.contracts.set(key, contract)\n}\n"]}
1
+ {"version":3,"file":"binds.js","sourceRoot":"","sources":["../src/binds.ts"],"names":[],"mappings":";;;AAAA,sDAAsE;AAGtE,wDAAqD;AAErD,yDAAuD;AAEvD,MAAa,cAAe,SAAQ,+BAAwC;IAC1E,MAAM,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAA;;AADxC,wCAEC;AAED,mDAAmD;AACnD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAsC,CAAA;AAE/D,SAAS,MAAM,CAAC,OAAe,EAAE,OAAe,EAAE,OAAmB;IACnE,MAAM,OAAO,GAAG,IAAA,sBAAU,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;IACtD,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC5D,CAAC;AAED,2CAA2C;AAC3C,SAAgB,YAAY,CAAC,IAAiB;IAC5C,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,CAAA;IACrC,OAAO,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAC9C,CAAC;AAHD,oCAGC;AAED,SAAgB,YAAY,CAAC,IAAiB,EAAE,SAAkC;IAChF,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,IAAI,CAAC,CAAA;IAErC,cAAc,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;AACvD,CAAC;AAJD,oCAIC;AAED,SAAgB,gBAAgB,CAAC,OAAe,EAAE,OAAe,EAAE,OAAmB;IACpF,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAC3B,CAAC;AAHD,4CAGC;AAED,SAAgB,gBAAgB,CAC9B,OAAe,EACf,OAAe,EACf,OAAmB,EACnB,QAAoC;IAEpC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7C,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACrC,CAAC;AARD,4CAQC","sourcesContent":["import { BindOptions, getOptionsSignature } from './core/bind-options'\nimport { BaseProcessor, ContractView } from './core'\nimport { Networkish } from '@ethersproject/networks'\nimport { getNetwork } from '@ethersproject/providers'\nimport { BaseContract } from 'ethers'\nimport { MapStateStorage } from './state/state-storage'\n\nexport class ProcessorState extends MapStateStorage<BaseProcessor<any, any>> {\n static INSTANCE = new ProcessorState()\n}\n\n// from abiName_address_chainId => contract wrapper\nconst contracts = new Map<string, ContractView<BaseContract>>()\n\nfunction getKey(abiName: string, address: string, network: Networkish) {\n const chainId = getNetwork(network).chainId.toString()\n return [abiName, address.toLowerCase(), chainId].join('_')\n}\n\n// Dedup processor that bind multiple times\nexport function getProcessor(opts: BindOptions) {\n const sig = getOptionsSignature(opts)\n return ProcessorState.INSTANCE.getValue(sig)\n}\n\nexport function addProcessor(opts: BindOptions, processor: BaseProcessor<any, any>) {\n const sig = getOptionsSignature(opts)\n\n ProcessorState.INSTANCE.getOrSetValue(sig, processor)\n}\n\nexport function getContractByABI(abiName: string, address: string, network: Networkish) {\n const key = getKey(abiName, address, network)\n return contracts.get(key)\n}\n\nexport function addContractByABI(\n abiName: string,\n address: string,\n network: Networkish,\n contract: ContractView<BaseContract>\n) {\n const key = getKey(abiName, address, network)\n return contracts.set(key, contract)\n}\n"]}
@@ -118,7 +118,7 @@ function sha256(str) {
118
118
  async function checkKey(host, apiKey) {
119
119
  const checkApiKeyUrl = new url_1.URL('/api/v1/processors/check_key', host);
120
120
  return (0, node_fetch_1.default)(checkApiKeyUrl, {
121
- method: 'HEAD',
121
+ method: 'GET',
122
122
  headers: {
123
123
  'api-key': apiKey,
124
124
  },
@@ -1 +1 @@
1
- {"version":3,"file":"run-login.js","sourceRoot":"","sources":["../../../src/cli/commands/run-login.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,sCAA2D;AAC3D,iDAA4C;AAC5C,2CAA8B;AAC9B,+CAAgC;AAChC,kDAAyB;AACzB,gCAAiC;AACjC,4DAA8B;AAE9B,MAAM,IAAI,GAAG,KAAK,CAAA;AAElB,SAAgB,QAAQ,CAAC,IAAc;IACrC,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,yBAAyB;SACvC;KACF,CAAA;IACD,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAE5D,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;YAC7B;gBACE,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,cAAc;aACxB;YACD;gBACE,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,iBAAiB;aAC9B;SACF,CAAC,CAAA;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;KACnB;SAAM,IAAI,OAAO,CAAC,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ACjD,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,OAAO;SAChB,CAAC,CAAA;QACF,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;QAClC,OAAO,CAAC,GAAG,CAAC,oCAAoC,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QAEtE,IAAA,0BAAW,EAAC;YACV,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,OAAO,CAAC,IAAI;YACxB,YAAY,EAAE,QAAQ;SACvB,CAAC,CAAA;KACH;AACH,CAAC;AAtED,4BAsEC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACzF,CAAC;AAED,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAA;AACzD,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,MAAc;IAClD,MAAM,cAAc,GAAG,IAAI,SAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAA;IACpE,OAAO,IAAA,oBAAK,EAAC,cAAc,EAAE;QAC3B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { getAuthConfig, getFinalizedHost } from '../config'\nimport { startServer } from './login-server'\nimport url, { URL } from 'url'\nimport * as crypto from 'crypto'\nimport chalk from 'chalk'\nimport { WriteKey } from '../key'\nimport fetch from 'node-fetch'\n\nconst port = 20000\n\nexport function runLogin(argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Your API key',\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Login to Sentio',\n content: 'sentio login',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else if (options['api-key']) {\n const host = getFinalizedHost(options.host)\n console.log(chalk.blue('login to ' + host))\n const apiKey = options['api-key']\n checkKey(host, apiKey).then((res) => {\n if (res.status == 200) {\n WriteKey(host, apiKey)\n console.log(chalk.green('login success'))\n } else {\n console.error(chalk.red('login failed, code:', res.status, res.statusText))\n }\n })\n } else {\n // https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce\n const verifier = base64URLEncode(crypto.randomBytes(32))\n const challenge = base64URLEncode(sha256(verifier))\n\n const conf = getAuthConfig(options.host)\n const authURL = new URL(conf.domain + `/authorize?`)\n const params = new url.URLSearchParams({\n response_type: 'code',\n code_challenge: challenge,\n code_challenge_method: 'S256',\n client_id: conf.clientId,\n redirect_uri: `http://localhost:${port}/callback`,\n audience: conf.audience,\n prompt: 'login',\n })\n authURL.search = params.toString()\n console.log('Continue your authorization here: ' + authURL.toString())\n\n startServer({\n serverPort: port,\n sentioHost: options.host,\n codeVerifier: verifier,\n })\n }\n}\n\nfunction base64URLEncode(str: Buffer) {\n return str.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '')\n}\n\nfunction sha256(str: string) {\n return crypto.createHash('sha256').update(str).digest()\n}\n\nasync function checkKey(host: string, apiKey: string) {\n const checkApiKeyUrl = new URL('/api/v1/processors/check_key', host)\n return fetch(checkApiKeyUrl, {\n method: 'HEAD',\n headers: {\n 'api-key': apiKey,\n },\n })\n}\n"]}
1
+ {"version":3,"file":"run-login.js","sourceRoot":"","sources":["../../../src/cli/commands/run-login.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,sCAA2D;AAC3D,iDAA4C;AAC5C,2CAA8B;AAC9B,+CAAgC;AAChC,kDAAyB;AACzB,gCAAiC;AACjC,4DAA8B;AAE9B,MAAM,IAAI,GAAG,KAAK,CAAA;AAElB,SAAgB,QAAQ,CAAC,IAAc;IACrC,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,yBAAyB;SACvC;KACF,CAAA;IACD,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAE5D,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;YAC7B;gBACE,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,cAAc;aACxB;YACD;gBACE,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,iBAAiB;aAC9B;SACF,CAAC,CAAA;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;KACnB;SAAM,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,IAAI,GAAG,IAAA,yBAAgB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC3C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAA;QAC3C,MAAM,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AQ,EAAE,CAAC,CAAA;QAEtE,IAAA,0BAAW,EAAC;YACV,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,OAAO,CAAC,IAAI;YACxB,YAAY,EAAE,QAAQ;SACvB,CAAC,CAAA;KACH;AACH,CAAC;AAtED,4BAsEC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,OAAO,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACzF,CAAC;AAED,SAAS,MAAM,CAAC,GAAW;IACzB,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAA;AACzD,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,MAAc;IAClD,MAAM,cAAc,GAAG,IAAI,SAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAA;IACpE,OAAO,IAAA,oBAAK,EAAC,cAAc,EAAE;QAC3B,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { getAuthConfig, getFinalizedHost } from '../config'\nimport { startServer } from './login-server'\nimport url, { URL } from 'url'\nimport * as crypto from 'crypto'\nimport chalk from 'chalk'\nimport { WriteKey } from '../key'\nimport fetch from 'node-fetch'\n\nconst port = 20000\n\nexport function runLogin(argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Your API key',\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Login to Sentio',\n content: 'sentio login',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else if (options['api-key']) {\n const host = getFinalizedHost(options.host)\n console.log(chalk.blue('login to ' + host))\n const apiKey = options['api-key']\n checkKey(host, apiKey).then((res) => {\n if (res.status == 200) {\n WriteKey(host, apiKey)\n console.log(chalk.green('login success'))\n } else {\n console.error(chalk.red('login failed, code:', res.status, res.statusText))\n }\n })\n } else {\n // https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce\n const verifier = base64URLEncode(crypto.randomBytes(32))\n const challenge = base64URLEncode(sha256(verifier))\n\n const conf = getAuthConfig(options.host)\n const authURL = new URL(conf.domain + `/authorize?`)\n const params = new url.URLSearchParams({\n response_type: 'code',\n code_challenge: challenge,\n code_challenge_method: 'S256',\n client_id: conf.clientId,\n redirect_uri: `http://localhost:${port}/callback`,\n audience: conf.audience,\n prompt: 'login',\n })\n authURL.search = params.toString()\n console.log('Continue your authorization here: ' + authURL.toString())\n\n startServer({\n serverPort: port,\n sentioHost: options.host,\n codeVerifier: verifier,\n })\n }\n}\n\nfunction base64URLEncode(str: Buffer) {\n return str.toString('base64').replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '')\n}\n\nfunction sha256(str: string) {\n return crypto.createHash('sha256').update(str).digest()\n}\n\nasync function checkKey(host: string, apiKey: string) {\n const checkApiKeyUrl = new URL('/api/v1/processors/check_key', host)\n return fetch(checkApiKeyUrl, {\n method: 'GET',\n headers: {\n 'api-key': apiKey,\n },\n })\n}\n"]}
package/lib/cli/upload.js CHANGED
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.uploadFile = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const crypto_1 = require("crypto");
9
- const form_data_1 = __importDefault(require("form-data"));
10
9
  const fs_1 = __importDefault(require("fs"));
11
10
  const readline_1 = __importDefault(require("readline"));
12
11
  const key_1 = require("./key");
@@ -15,8 +14,9 @@ const chalk_1 = __importDefault(require("chalk"));
15
14
  const build_1 = require("./build");
16
15
  const node_fetch_1 = __importDefault(require("node-fetch"));
17
16
  const utils_1 = require("./utils");
17
+ const url_1 = require("url");
18
18
  async function createProject(options, apiKey) {
19
- const url = new URL('/api/v1/projects', options.host);
19
+ const url = new url_1.URL('/api/v1/projects', options.host);
20
20
  const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project];
21
21
  return (0, node_fetch_1.default)(url, {
22
22
  method: 'POST',
@@ -32,7 +32,6 @@ async function uploadFile(options, apiKeyOverride) {
32
32
  }
33
33
  console.log(chalk_1.default.blue('Prepare to upload'));
34
34
  const PROCESSOR_FILE = path_1.default.join(process.cwd(), 'dist/lib.js');
35
- const url = new URL('/api/v1/processors', options.host);
36
35
  const apiKey = apiKeyOverride || (0, key_1.ReadKey)(options.host);
37
36
  const isProd = options.host === 'https://app.sentio.xyz';
38
37
  if (!apiKey) {
@@ -52,47 +51,29 @@ async function uploadFile(options, apiKeyOverride) {
52
51
  const digest = hash.digest('hex');
53
52
  let triedCount = 0;
54
53
  const upload = async () => {
55
- const data = new form_data_1.default();
56
- data.append('attachment', fs_1.default.createReadStream(PROCESSOR_FILE));
57
- data.append('sha256', digest);
58
54
  let commitSha = '';
55
+ let gitUrl = '';
56
+ const sha256 = digest;
59
57
  try {
60
58
  commitSha = (0, child_process_1.execSync)('git rev-parse HEAD').toString().trim();
61
- data.append('commitSha', commitSha);
62
59
  }
63
60
  catch (e) {
64
61
  chalk_1.default.yellow(e);
65
62
  }
66
63
  try {
67
- const gitUrl = (0, child_process_1.execSync)('git remote get-url origin').toString().trim();
68
- data.append('gitUrl', gitUrl);
64
+ gitUrl = (0, child_process_1.execSync)('git remote get-url origin').toString().trim();
69
65
  }
70
66
  catch (e) {
71
67
  // skip errors
72
68
  }
73
69
  console.log(chalk_1.default.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'));
74
- const res = await (0, node_fetch_1.default)(url, {
75
- method: 'POST',
76
- headers: {
77
- 'api-key': apiKey,
78
- project: options.project,
79
- version: (0, utils_1.getCliVersion)(),
80
- },
81
- body: data,
82
- });
83
- if (res.ok) {
84
- console.log(chalk_1.default.green('Upload success: '));
85
- console.log('\t', chalk_1.default.blue('sha256:'), digest);
86
- if (commitSha) {
87
- console.log('\t', chalk_1.default.blue('Git commit SHA:'), commitSha);
88
- }
89
- const { ProjectSlug } = await res.json();
90
- console.log('\t', chalk_1.default.blue('Check status:'), `${options.host}/${ProjectSlug}/datasource`);
91
- }
92
- else {
93
- console.error(chalk_1.default.red('Upload Failed'));
94
- console.error(chalk_1.default.red(await res.text()));
95
- if (res.status === 404) {
70
+ // get gcs upload url
71
+ const initUploadResRaw = await initUpload(options.host, apiKey, options.project, (0, utils_1.getCliVersion)());
72
+ if (!initUploadResRaw.ok) {
73
+ console.error(chalk_1.default.red('Failed to get upload url'));
74
+ console.error(chalk_1.default.red(await initUploadResRaw.text()));
75
+ if (initUploadResRaw.status === 404) {
76
+ // create project if not exist
96
77
  const rl = readline_1.default.createInterface({
97
78
  input: process.stdin,
98
79
  output: process.stdout,
@@ -119,7 +100,38 @@ async function uploadFile(options, apiKeyOverride) {
119
100
  };
120
101
  await prompt();
121
102
  }
103
+ return;
104
+ }
105
+ const initUploadRes = await initUploadResRaw.json();
106
+ const uploadUrl = initUploadRes['url'];
107
+ // do actual uploading
108
+ const file = fs_1.default.createReadStream(PROCESSOR_FILE);
109
+ const uploadResRaw = await (0, node_fetch_1.default)(uploadUrl, {
110
+ method: 'PUT',
111
+ headers: {
112
+ 'Content-Type': 'application/octet-stream',
113
+ },
114
+ body: file,
115
+ });
116
+ if (!uploadResRaw.ok) {
117
+ console.error(chalk_1.default.red('Failed to upload'));
118
+ console.error(chalk_1.default.red(await uploadResRaw.text()));
119
+ return;
120
+ }
121
+ // finish uploading
122
+ const finishUploadResRaw = await finishUpload(options.host, apiKey, options.project, (0, utils_1.getCliVersion)(), sha256, commitSha, gitUrl);
123
+ if (!finishUploadResRaw.ok) {
124
+ console.error(chalk_1.default.red('Failed to finish uploading'));
125
+ console.error(chalk_1.default.red(await finishUploadResRaw.text()));
126
+ return;
122
127
  }
128
+ console.log(chalk_1.default.green('Upload success: '));
129
+ console.log('\t', chalk_1.default.blue('sha256:'), digest);
130
+ if (commitSha) {
131
+ console.log('\t', chalk_1.default.blue('Git commit SHA:'), commitSha);
132
+ }
133
+ const { ProjectFullSlug } = await finishUploadResRaw.json();
134
+ console.log('\t', chalk_1.default.blue('Check status:'), `${options.host}/${ProjectFullSlug}/datasource`);
123
135
  };
124
136
  let error;
125
137
  const tryUploading = async () => {
@@ -144,4 +156,31 @@ async function uploadFile(options, apiKeyOverride) {
144
156
  await tryUploading();
145
157
  }
146
158
  exports.uploadFile = uploadFile;
159
+ async function initUpload(host, apiKey, projectSlug, sdkVersion) {
160
+ const initUploadUrl = new url_1.URL(`/api/v1/processors/${projectSlug}/init_upload`, host);
161
+ return (0, node_fetch_1.default)(initUploadUrl, {
162
+ method: 'POST',
163
+ headers: {
164
+ 'api-key': apiKey,
165
+ },
166
+ body: JSON.stringify({
167
+ sdk_version: sdkVersion,
168
+ }),
169
+ });
170
+ }
171
+ async function finishUpload(host, apiKey, projectSlug, sdkVersion, sha256, commitSha, gitUrl) {
172
+ const finishUploadUrl = new url_1.URL(`/api/v1/processors/${projectSlug}/finish_upload`, host);
173
+ return (0, node_fetch_1.default)(finishUploadUrl, {
174
+ method: 'POST',
175
+ headers: {
176
+ 'api-key': apiKey,
177
+ },
178
+ body: JSON.stringify({
179
+ sdk_version: sdkVersion,
180
+ sha256: sha256,
181
+ commit_sha: commitSha,
182
+ git_url: gitUrl,
183
+ }),
184
+ });
185
+ }
147
186
  //# sourceMappingURL=upload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/cli/upload.ts"],"names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jB;SACF;IACH,CAAC,CAAA;IAED,MAAM,YAAY,EAAE,CAAA;AACtB,CAAC;AA5HD,gCA4HC","sourcesContent":["import { execSync } from 'child_process'\nimport { createHash } from 'crypto'\nimport FormData from 'form-data'\nimport fs from 'fs'\nimport readline from 'readline'\nimport { SentioProjectConfig } from './config'\nimport { ReadKey } from './key'\nimport path from 'path'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport fetch from 'node-fetch'\nimport { getCliVersion } from './utils'\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]\n return fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false)\n }\n\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const url = new URL('/api/v1/processors', options.host)\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n let triedCount = 0\n const upload = async () => {\n const data = new FormData()\n data.append('attachment', fs.createReadStream(PROCESSOR_FILE))\n data.append('sha256', digest)\n\n let commitSha = ''\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n data.append('commitSha', commitSha)\n } catch (e) {\n chalk.yellow(e)\n }\n try {\n const gitUrl = execSync('git remote get-url origin').toString().trim()\n data.append('gitUrl', gitUrl)\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n project: options.project,\n version: getCliVersion(),\n },\n body: data,\n })\n\n if (res.ok) {\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n const { ProjectSlug } = await res.json()\n console.log('\\t', chalk.blue('Check status:'), `${options.host}/${ProjectSlug}/datasource`)\n } else {\n console.error(chalk.red('Upload Failed'))\n console.error(chalk.red(await res.text()))\n\n if (res.status === 404) {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red((await res.json()).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n }\n }\n\n let error: Error\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n console.error(error)\n return\n }\n try {\n await upload()\n } catch (e) {\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n error = e\n await new Promise((resolve) => setTimeout(resolve, 1000))\n await tryUploading()\n } else {\n console.error(e)\n }\n }\n }\n\n await tryUploading()\n}\n"]}
1
+ {"version":3,"file":"upload.js","sourceRoot":"","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AM,eAAe,GAAG,IAAI,SAAG,CAAC,sBAAsB,WAAW,gBAAgB,EAAE,IAAI,CAAC,CAAA;IACxF,OAAO,IAAA,oBAAK,EAAC,eAAe,EAAE;QAC5B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,WAAW,EAAE,UAAU;YACvB,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,MAAM;SAChB,CAAC;KACH,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { execSync } from 'child_process'\nimport { createHash } from 'crypto'\nimport fs from 'fs'\nimport readline from 'readline'\nimport { SentioProjectConfig } from './config'\nimport { ReadKey } from './key'\nimport path from 'path'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport fetch from 'node-fetch'\nimport { getCliVersion } from './utils'\nimport { URL } from 'url'\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]\n return fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false)\n }\n\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n let triedCount = 0\n const upload = async () => {\n let commitSha = ''\n let gitUrl = ''\n const sha256 = digest\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n } catch (e) {\n chalk.yellow(e)\n }\n try {\n gitUrl = execSync('git remote get-url origin').toString().trim()\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n\n // get gcs upload url\n const initUploadResRaw = await initUpload(options.host, apiKey, options.project, getCliVersion())\n if (!initUploadResRaw.ok) {\n console.error(chalk.red('Failed to get upload url'))\n console.error(chalk.red(await initUploadResRaw.text()))\n\n if (initUploadResRaw.status === 404) {\n // create project if not exist\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red((await res.json()).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n return\n }\n const initUploadRes = await initUploadResRaw.json()\n const uploadUrl = initUploadRes['url'] as string\n\n // do actual uploading\n const file = fs.createReadStream(PROCESSOR_FILE)\n const uploadResRaw = await fetch(uploadUrl, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/octet-stream',\n },\n body: file,\n })\n if (!uploadResRaw.ok) {\n console.error(chalk.red('Failed to upload'))\n console.error(chalk.red(await uploadResRaw.text()))\n return\n }\n\n // finish uploading\n const finishUploadResRaw = await finishUpload(\n options.host,\n apiKey,\n options.project,\n getCliVersion(),\n sha256,\n commitSha,\n gitUrl\n )\n if (!finishUploadResRaw.ok) {\n console.error(chalk.red('Failed to finish uploading'))\n console.error(chalk.red(await finishUploadResRaw.text()))\n return\n }\n\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n const { ProjectFullSlug } = await finishUploadResRaw.json()\n console.log('\\t', chalk.blue('Check status:'), `${options.host}/${ProjectFullSlug}/datasource`)\n }\n\n let error: Error\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n console.error(error)\n return\n }\n try {\n await upload()\n } catch (e) {\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n error = e\n await new Promise((resolve) => setTimeout(resolve, 1000))\n await tryUploading()\n } else {\n console.error(e)\n }\n }\n }\n\n await tryUploading()\n}\n\nasync function initUpload(host: string, apiKey: string, projectSlug: string, sdkVersion: string) {\n const initUploadUrl = new URL(`/api/v1/processors/${projectSlug}/init_upload`, host)\n return fetch(initUploadUrl, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n sdk_version: sdkVersion,\n }),\n })\n}\n\nasync function finishUpload(\n host: string,\n apiKey: string,\n projectSlug: string,\n sdkVersion: string,\n sha256: string,\n commitSha: string,\n gitUrl: string\n) {\n const finishUploadUrl = new URL(`/api/v1/processors/${projectSlug}/finish_upload`, host)\n return fetch(finishUploadUrl, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n sdk_version: sdkVersion,\n sha256: sha256,\n commit_sha: commitSha,\n git_url: gitUrl,\n }),\n })\n}\n"]}
package/lib/core/meter.js CHANGED
@@ -55,11 +55,11 @@ class Metric extends metadata_1.NamedResultDescriptor {
55
55
  this.type = type;
56
56
  this.descriptor = gen_1.MetricConfig.fromPartial({ name: this.name, ...option });
57
57
  const aggregationConfig = this.descriptor.aggregationConfig;
58
- if (aggregationConfig && aggregationConfig.intervalInMinutes && aggregationConfig.intervalInMinutes.length) {
58
+ if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {
59
59
  if (aggregationConfig.intervalInMinutes.length > 1) {
60
60
  console.error('current only support one intervalInMinutes, only first interval will be used for', name);
61
61
  }
62
- if (aggregationConfig.intervalInMinutes[0] > 0 && !aggregationConfig.types) {
62
+ if (aggregationConfig.intervalInMinutes[0] > 0 && aggregationConfig.types.length === 0) {
63
63
  aggregationConfig.types = [gen_1.AggregationType.SUM, gen_1.AggregationType.COUNT];
64
64
  }
65
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,yCAA0D;AAC1D,gCAAyE;AACzE,0DAAwD;AAExD,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,CAA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{ BaseContext } from './base-context'\nimport { Numberish, toMetricValue } from './numberish'\nimport { Labels, NamedResultDescriptor } from './metadata'\nimport { AggregationConfig, AggregationType, MetricConfig } from '../gen'\nimport { MapStateStorage } from '../state/state-storage'\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\nexport class MetricOptions {\n unit?: string\n description?: string\n sparse?: boolean\n aggregationConfig?: Partial<AggregationConfig>\n}\n\nexport class CounterOptions {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\nenum MetricType {\n Counter = 0,\n Gauge = 1,\n}\n\nexport class Metric extends NamedResultDescriptor {\n type: MetricType\n descriptor: MetricConfig\n constructor(type: MetricType, name: string, option?: MetricOptions) {\n super(name)\n this.type = type\n this.descriptor = MetricConfig.fromPartial({ name: this.name, ...option })\n const aggregationConfig = this.descriptor.aggregationConfig\n if (aggregationConfig && aggregationConfig.intervalInMinutes && aggregationConfig.intervalInMinutes.length) {\n if (aggregationConfig.intervalInMinutes.length > 1) {\n console.error('current only support one intervalInMinutes, only first interval will be used for', name)\n }\n if (aggregationConfig.intervalInMinutes[0] > 0 && !aggregationConfig.types) {\n aggregationConfig.types = [AggregationType.SUM, AggregationType.COUNT]\n }\n }\n }\n}\n\nexport class MetricState extends MapStateStorage<Metric> {\n static INSTANCE = new MetricState()\n\n getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {\n const metricMap = this.getOrRegister()\n let metric = metricMap.get(name)\n if (metric && metric.type !== type) {\n throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.type}`)\n }\n\n if (!metric) {\n if (type === MetricType.Counter) {\n metric = new Counter(name, option)\n } else {\n metric = new Gauge(name, option)\n }\n }\n metricMap.set(name, metric)\n return metric\n }\n}\n\nexport class Counter extends Metric {\n static register(name: string, option?: CounterOptions): Counter {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.Counter, name, option) as Counter\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.Counter, name, option)\n }\n\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.res.counters.push({\n metadata: ctx.getMetaData(this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\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 static register(name: string, option?: MetricOptions): Gauge {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.Gauge, name, option) as Gauge\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.Counter, name, option)\n }\n\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx.res.gauges.push({\n metadata: ctx.getMetaData(this.descriptor.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\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"]}
1
+ {"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,yCAA0D;AAC1D,gCAAyE;AACzE,0DAAwD;AAExD,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,MAAa,aAAa;IACxB,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,MAAM,CAAU;IAChB,iBAAiB,CAA6B;CAC/C;AALD,sCAKC;AAED,MAAa,c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C,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YAClB,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;YACvD,WAAW,EAAE,IAAA,yBAAa,EAAC,KAAK,CAAC;YACjC,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;IACJ,CAAC;CACF;AAhBD,sBAgBC;AAED,MAAa,YAAY;IACN,KAAK,CAAO;IACZ,GAAG,CAAa;IAEjC,YAAY,IAAY,EAAE,GAAgB;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,MAAM,CAAC,KAAgB,EAAE,SAAiB,EAAE;QAC1C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;CACF;AAZD,oCAYC;AAED,MAAa,KAAK;IACC,GAAG,CAAa;IAEjC,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF;AAdD,sBAcC","sourcesContent":["import { BaseContext } from './base-context'\nimport { Numberish, toMetricValue } from './numberish'\nimport { Labels, NamedResultDescriptor } from './metadata'\nimport { AggregationConfig, AggregationType, MetricConfig } from '../gen'\nimport { MapStateStorage } from '../state/state-storage'\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\nexport class MetricOptions {\n unit?: string\n description?: string\n sparse?: boolean\n aggregationConfig?: Partial<AggregationConfig>\n}\n\nexport class CounterOptions {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\nenum MetricType {\n Counter = 0,\n Gauge = 1,\n}\n\nexport class Metric extends NamedResultDescriptor {\n type: MetricType\n descriptor: MetricConfig\n constructor(type: MetricType, name: string, option?: MetricOptions) {\n super(name)\n this.type = type\n this.descriptor = MetricConfig.fromPartial({ name: this.name, ...option })\n const aggregationConfig = this.descriptor.aggregationConfig\n if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {\n if (aggregationConfig.intervalInMinutes.length > 1) {\n console.error('current only support one intervalInMinutes, only first interval will be used for', name)\n }\n if (aggregationConfig.intervalInMinutes[0] > 0 && aggregationConfig.types.length === 0) {\n aggregationConfig.types = [AggregationType.SUM, AggregationType.COUNT]\n }\n }\n }\n}\n\nexport class MetricState extends MapStateStorage<Metric> {\n static INSTANCE = new MetricState()\n\n getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {\n const metricMap = this.getOrRegister()\n let metric = metricMap.get(name)\n if (metric && metric.type !== type) {\n throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.type}`)\n }\n\n if (!metric) {\n if (type === MetricType.Counter) {\n metric = new Counter(name, option)\n } else {\n metric = new Gauge(name, option)\n }\n }\n metricMap.set(name, metric)\n return metric\n }\n}\n\nexport class Counter extends Metric {\n static register(name: string, option?: CounterOptions): Counter {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.Counter, name, option) as Counter\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.Counter, name, option)\n }\n\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.res.counters.push({\n metadata: ctx.getMetaData(this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\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 static register(name: string, option?: MetricOptions): Gauge {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.Gauge, name, option) as Gauge\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.Counter, name, option)\n }\n\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx.res.gauges.push({\n metadata: ctx.getMetaData(this.descriptor.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\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"]}
@@ -3,11 +3,15 @@ import { SolanaContext } from './context';
3
3
  import Long from 'long';
4
4
  import { Instruction } from '@project-serum/anchor';
5
5
  import { SolanaBindOptions } from './bind-options';
6
+ import { ListStateStorage } from '../state/state-storage';
6
7
  declare type IndexConfigure = {
7
8
  startSlot: Long;
8
9
  endSlot?: Long;
9
10
  };
10
11
  export declare type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void;
12
+ export declare class SolanaProcessorState extends ListStateStorage<SolanaBaseProcessor> {
13
+ static INSTANCE: SolanaProcessorState;
14
+ }
11
15
  export declare class SolanaBaseProcessor {
12
16
  instructionHandlerMap: Map<string, SolanaInstructionHandler>;
13
17
  address: string;
@@ -3,9 +3,14 @@ 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.SolanaBaseProcessor = void 0;
6
+ exports.SolanaBaseProcessor = exports.SolanaProcessorState = void 0;
7
7
  const context_1 = require("./context");
8
8
  const long_1 = __importDefault(require("long"));
9
+ const state_storage_1 = require("../state/state-storage");
10
+ class SolanaProcessorState extends state_storage_1.ListStateStorage {
11
+ static INSTANCE = new SolanaProcessorState();
12
+ }
13
+ exports.SolanaProcessorState = SolanaProcessorState;
9
14
  class SolanaBaseProcessor {
10
15
  instructionHandlerMap = new Map();
11
16
  address;
@@ -19,7 +24,7 @@ class SolanaBaseProcessor {
19
24
  if (options) {
20
25
  this.bind(options);
21
26
  }
22
- global.PROCESSOR_STATE.solanaProcessors.push(this);
27
+ SolanaProcessorState.INSTANCE.addValue(this);
23
28
  }
24
29
  bind(options) {
25
30
  this.address = options.address;
@@ -1 +1 @@
1
- {"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../../src/core/solana-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAyC;AACzC,gDAAuB;AAWvB,MAAa,mBAAmB;IACvB,qBAAqB,GAA0C,IAAI,GAAG,EAAE,CAAA;IAC/E,OAAO,CAAQ;IACf,QAAQ,CAAQ;I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AC,OAAO,GAAG,QAAQ,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA3FD,kDA2FC","sourcesContent":["import { ProcessResult } from '../gen'\nimport { SolanaContext } from './context'\nimport Long from 'long'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './bind-options'\n\ntype IndexConfigure = {\n startSlot: Long\n endSlot?: Long\n}\n\nexport type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void\n\nexport class SolanaBaseProcessor {\n public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()\n address: string\n endpoint: string\n contractName: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: new Long(0) }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.solanaProcessors.push(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n innerInstruction(flag: boolean) {\n this.processInnerInstruction = flag\n return this\n }\n\n public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHandlerMap.set(instructionName, handler)\n\n return this\n }\n\n public getParsedInstruction(ins: string | { type: string; info: any }): Instruction | null {\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n return this.fromParsedInstruction ? this.fromParsedInstruction(ins as { type: string; info: any }) : null\n }\n if (this.decodeInstruction != null) {\n return this.decodeInstruction(ins as string)\n }\n }\n return null\n }\n\n public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {\n return this.instructionHandlerMap.get(parsedInstruction.name)\n }\n\n public handleInstruction(\n parsedInstruction: Instruction,\n accounts: string[],\n handler: SolanaInstructionHandler,\n slot: Long\n ): ProcessResult {\n const ctx = new SolanaContext(this.contractName, this.address, slot)\n handler(parsedInstruction, ctx, accounts)\n return ctx.getProcessResult()\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSlot = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSlot = endBlock\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../../src/core/solana-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAyC;AACzC,gDAAuB;AAGvB,0DAAyD;AASzD,MAAa,oBAAqB,SAAQ,gCAAqC;IAC7E,MAAM,CAAC,QAAQ,GAAyB,IAAI,oBAAoB,EAAE,CAAA;;AADpE,oDAEC;AAED,MAAa,mBAAmB;IACvB,qBAAqB,GAA0C,IAAI,GAAG,EAAE,CAAA;IAC/E,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,YAAY,CAAQ;IACpB,uBAAuB,CAAS;IAChC,MAAM,GAAmB,EAAE,SAAS,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACnD,iBAAiB,CAAgD;IACjE,qBAAqB,CAAkE;IAEvF,YAAY,OAA0B;QACpC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,CAAC,OAA0B;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAA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C;IAEM,iBAAiB,CACtB,iBAA8B,EAC9B,QAAkB,EAClB,OAAiC,EACjC,IAAU;QAEV,MAAM,GAAG,GAAG,IAAI,uBAAa,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACpE,OAAO,CAAC,iBAAiB,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAA;QACzC,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAA;IAC9B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA3FD,kDA2FC","sourcesContent":["import { ProcessResult } from '../gen'\nimport { SolanaContext } from './context'\nimport Long from 'long'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './bind-options'\nimport { ListStateStorage } from '../state/state-storage'\n\ntype IndexConfigure = {\n startSlot: Long\n endSlot?: Long\n}\n\nexport type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void\n\nexport class SolanaProcessorState extends ListStateStorage<SolanaBaseProcessor> {\n static INSTANCE: SolanaProcessorState = new SolanaProcessorState()\n}\n\nexport class SolanaBaseProcessor {\n public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()\n address: string\n endpoint: string\n contractName: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: new Long(0) }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n SolanaProcessorState.INSTANCE.addValue(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n innerInstruction(flag: boolean) {\n this.processInnerInstruction = flag\n return this\n }\n\n public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHandlerMap.set(instructionName, handler)\n\n return this\n }\n\n public getParsedInstruction(ins: string | { type: string; info: any }): Instruction | null {\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n return this.fromParsedInstruction ? this.fromParsedInstruction(ins as { type: string; info: any }) : null\n }\n if (this.decodeInstruction != null) {\n return this.decodeInstruction(ins as string)\n }\n }\n return null\n }\n\n public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {\n return this.instructionHandlerMap.get(parsedInstruction.name)\n }\n\n public handleInstruction(\n parsedInstruction: Instruction,\n accounts: string[],\n handler: SolanaInstructionHandler,\n slot: Long\n ): ProcessResult {\n const ctx = new SolanaContext(this.contractName, this.address, slot)\n handler(parsedInstruction, ctx, accounts)\n return ctx.getProcessResult()\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSlot = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSlot = endBlock\n return this\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { SuiContext } from './context';
2
2
  import { ProcessResult } from '../gen';
3
3
  import Long from 'long';
4
+ import { ListStateStorage } from '../state/state-storage';
4
5
  declare type IndexConfigure = {
5
6
  startSeqNumber: Long;
6
7
  endSeqNumber?: Long;
@@ -9,6 +10,9 @@ export declare class SuiBindOptions {
9
10
  address: string;
10
11
  startBlock?: Long | number;
11
12
  }
13
+ export declare class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
14
+ static INSTANCE: SuiProcessorState;
15
+ }
12
16
  export declare class SuiBaseProcessor {
13
17
  transactionHanlder: (transaction: any, ctx: SuiContext) => void;
14
18
  address: string;
@@ -3,9 +3,10 @@ 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.SuiBaseProcessor = exports.SuiBindOptions = void 0;
6
+ exports.SuiBaseProcessor = exports.SuiProcessorState = exports.SuiBindOptions = void 0;
7
7
  const context_1 = require("./context");
8
8
  const long_1 = __importDefault(require("long"));
9
+ const state_storage_1 = require("../state/state-storage");
9
10
  class SuiBindOptions {
10
11
  address;
11
12
  // network?: Networkish = 1
@@ -13,6 +14,10 @@ class SuiBindOptions {
13
14
  startBlock;
14
15
  }
15
16
  exports.SuiBindOptions = SuiBindOptions;
17
+ class SuiProcessorState extends state_storage_1.ListStateStorage {
18
+ static INSTANCE = new SuiProcessorState();
19
+ }
20
+ exports.SuiProcessorState = SuiProcessorState;
16
21
  class SuiBaseProcessor {
17
22
  transactionHanlder;
18
23
  address;
@@ -22,7 +27,7 @@ class SuiBaseProcessor {
22
27
  if (options.startBlock) {
23
28
  this.startSlot(options.startBlock);
24
29
  }
25
- global.PROCESSOR_STATE.suiProcessors.push(this);
30
+ SuiProcessorState.INSTANCE.addValue(this);
26
31
  }
27
32
  onTransaction(handler) {
28
33
  this.transactionHanlder = handler;
@@ -1 +1 @@
1
- {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAsC;AAEtC,gDAAuB;AAOvB,MAAa,cAAc;IACzB,OAAO,CAAQ;IACf,2BAA2B;IAC3B,gBAAgB;IAChB,UAAU,CAAgB;CAE3B;AAND,wCAMC;AAED,MAAa,gBAAgB;IACpB,kBAAkB,CAA6C;IACtE,OAAO,CAAQ;IACf,MAAM,GAAmB,EAAE,cAAc,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IAExD,YAAY,IAAY,EAAE,OAAuB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;SACnC;QACD,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjD,CAAC;IAEM,aAAa,CAAC,OAAoD;QACvE,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,iBAAiB,CAAC,GAAQ,EAAE,IAAU;QAC3C,MAAM,GAAG,GAAG,IAAI,oBAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QAE9C,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;SAClC;QACD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC/B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,SAAS,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1CD,4CA0CC","sourcesContent":["import { SuiContext } from './context'\nimport { ProcessResult } from '../gen'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport class SuiBindOptions {\n address: string\n // network?: Networkish = 1\n // name?: string\n startBlock?: Long | number\n // endBlock?: Long | number\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n\n constructor(name: string, options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n global.PROCESSOR_STATE.suiProcessors.push(this)\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n this.transactionHanlder = handler\n return this\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return ctx.getProcessResult()\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAsC;AAEtC,gDAA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b,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1CD,4CA0CC","sourcesContent":["import { SuiContext } from './context'\nimport { ProcessResult } from '../gen'\nimport Long from 'long'\nimport { ListStateStorage } from '../state/state-storage'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport class SuiBindOptions {\n address: string\n // network?: Networkish = 1\n // name?: string\n startBlock?: Long | number\n // endBlock?: Long | number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n\n constructor(name: string, options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n this.transactionHanlder = handler\n return this\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return ctx.getProcessResult()\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
package/lib/service.js CHANGED
@@ -14,6 +14,9 @@ const exporter_1 = require("./core/exporter");
14
14
  const event_tracker_1 = require("./core/event-tracker");
15
15
  const aptos_processor_1 = require("./aptos/aptos-processor");
16
16
  const account_processor_1 = require("./core/account-processor");
17
+ const sui_processor_1 = require("./core/sui-processor");
18
+ const solana_processor_1 = require("./core/solana-processor");
19
+ const binds_1 = require("./binds");
17
20
  BigInt.prototype.toJSON = function () {
18
21
  return this.toString();
19
22
  };
@@ -90,7 +93,7 @@ class ProcessorServiceImpl {
90
93
  });
91
94
  }
92
95
  // Part 1.a, prepare EVM processors
93
- for (const processor of global.PROCESSOR_STATE.processors) {
96
+ for (const processor of binds_1.ProcessorState.INSTANCE.getValues()) {
94
97
  // If server favor incremental update this need to change
95
98
  // Start basic config for contract
96
99
  const chainId = processor.getChainId();
@@ -212,7 +215,7 @@ class ProcessorServiceImpl {
212
215
  this.accountConfigs.push(accountConfig);
213
216
  }
214
217
  // Part 2, prepare solana constractors
215
- for (const solanaProcessor of global.PROCESSOR_STATE.solanaProcessors) {
218
+ for (const solanaProcessor of solana_processor_1.SolanaProcessorState.INSTANCE.getValues()) {
216
219
  const contractConfig = {
217
220
  processorType: USER_PROCESSOR,
218
221
  contract: {
@@ -238,7 +241,7 @@ class ProcessorServiceImpl {
238
241
  this.contractConfigs.push(contractConfig);
239
242
  }
240
243
  // Part 3, prepare sui constractors
241
- for (const suiProcessor of global.PROCESSOR_STATE.suiProcessors) {
244
+ for (const suiProcessor of sui_processor_1.SuiProcessorState.INSTANCE.getValues()) {
242
245
  const contractConfig = {
243
246
  processorType: USER_PROCESSOR,
244
247
  contract: {
@@ -449,11 +452,11 @@ class ProcessorServiceImpl {
449
452
  throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service not started.');
450
453
  }
451
454
  const result = gen_1.ProcessResult.fromPartial({});
452
- if (request.chainId.toLowerCase().startsWith('sui') && global.PROCESSOR_STATE.suiProcessors) {
455
+ if (request.chainId.toLowerCase().startsWith('sui') && sui_processor_1.SuiProcessorState.INSTANCE.getValues()) {
453
456
  const processorPromises = [];
454
457
  for (const txn of request.transactions) {
455
458
  processorPromises.push(new Promise((resolve, _) => {
456
- for (const processor of global.PROCESSOR_STATE.suiProcessors) {
459
+ for (const processor of sui_processor_1.SuiProcessorState.INSTANCE.getValues()) {
457
460
  const res = processor.handleTransaction(JSON.parse(new util_1.TextDecoder().decode(txn.raw)), txn.slot ?? long_1.default.fromNumber(0));
458
461
  if (res) {
459
462
  res.gauges.forEach((g) => result.gauges.push(g));
@@ -478,14 +481,14 @@ class ProcessorServiceImpl {
478
481
  }
479
482
  const result = gen_1.ProcessResult.fromPartial({});
480
483
  // Only have instruction handlers for solana processors
481
- if (global.PROCESSOR_STATE.solanaProcessors) {
484
+ if (solana_processor_1.SolanaProcessorState.INSTANCE.getValues()) {
482
485
  const processorPromises = [];
483
486
  for (const instruction of request.instructions) {
484
487
  if (!instruction) {
485
488
  throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'instruction cannot be null');
486
489
  }
487
490
  processorPromises.push(new Promise((resolve, _) => {
488
- for (const processor of global.PROCESSOR_STATE.solanaProcessors) {
491
+ for (const processor of solana_processor_1.SolanaProcessorState.INSTANCE.getValues()) {
489
492
  if (processor.address === instruction.programAccountId) {
490
493
  let parsedInstruction = null;
491
494
  if (instruction.parsed) {