@sentio/sdk 1.23.1 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/lib/aptos/aptos-processor.d.ts +0 -2
  2. package/lib/aptos/aptos-processor.js +9 -55
  3. package/lib/aptos/aptos-processor.js.map +1 -1
  4. package/lib/aptos/context.d.ts +1 -1
  5. package/lib/aptos/context.js +1 -0
  6. package/lib/aptos/context.js.map +1 -1
  7. package/lib/aptos/index.d.ts +3 -2
  8. package/lib/aptos/index.js +5 -1
  9. package/lib/aptos/index.js.map +1 -1
  10. package/lib/aptos/network.d.ts +3 -1
  11. package/lib/aptos/network.js +8 -3
  12. package/lib/aptos/network.js.map +1 -1
  13. package/lib/aptos/types.d.ts +13 -2
  14. package/lib/aptos/types.js +64 -2
  15. package/lib/aptos/types.js.map +1 -1
  16. package/lib/aptos-codegen/codegen.js +1 -2
  17. package/lib/aptos-codegen/codegen.js.map +1 -1
  18. package/lib/cli/cli.js +5 -5
  19. package/lib/cli/cli.js.map +1 -1
  20. package/lib/cli/commands/run-create.js +31 -11
  21. package/lib/cli/commands/run-create.js.map +1 -1
  22. package/lib/cli/commands/run-login.js +1 -1
  23. package/lib/cli/commands/run-login.js.map +1 -1
  24. package/lib/cli/config.d.ts +0 -1
  25. package/lib/cli/config.js.map +1 -1
  26. package/lib/core/base-processor.js +6 -25
  27. package/lib/core/base-processor.js.map +1 -1
  28. package/lib/core/context.d.ts +7 -5
  29. package/lib/core/context.js +15 -0
  30. package/lib/core/context.js.map +1 -1
  31. package/lib/core/event-tracker.d.ts +22 -0
  32. package/lib/core/event-tracker.js +53 -0
  33. package/lib/core/event-tracker.js.map +1 -0
  34. package/lib/core/index.d.ts +1 -0
  35. package/lib/core/index.js +4 -1
  36. package/lib/core/index.js.map +1 -1
  37. package/lib/core/solana-processor.js +1 -5
  38. package/lib/core/solana-processor.js.map +1 -1
  39. package/lib/core/sui-processor.js +1 -5
  40. package/lib/core/sui-processor.js.map +1 -1
  41. package/lib/gen/processor/protos/processor.d.ts +72 -0
  42. package/lib/gen/processor/protos/processor.js +481 -2
  43. package/lib/gen/processor/protos/processor.js.map +1 -1
  44. package/lib/processor-state.d.ts +4 -0
  45. package/lib/processor-state.js +2 -0
  46. package/lib/processor-state.js.map +1 -1
  47. package/lib/service.d.ts +2 -0
  48. package/lib/service.js +24 -1
  49. package/lib/service.js.map +1 -1
  50. package/lib/tests/erc20.js +3 -0
  51. package/lib/tests/erc20.js.map +1 -1
  52. package/lib/tests/souffl3.js +5 -7
  53. package/lib/tests/souffl3.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/aptos/aptos-processor.ts +10 -65
  56. package/src/aptos/context.ts +2 -1
  57. package/src/aptos/index.ts +3 -2
  58. package/src/aptos/network.ts +6 -1
  59. package/src/aptos/types.ts +84 -2
  60. package/src/aptos-codegen/codegen.ts +2 -3
  61. package/src/cli/cli.ts +5 -5
  62. package/src/cli/commands/run-create.ts +33 -11
  63. package/src/cli/commands/run-login.ts +1 -1
  64. package/src/cli/config.ts +1 -1
  65. package/src/core/base-processor.ts +5 -25
  66. package/src/core/context.ts +29 -5
  67. package/src/core/event-tracker.ts +66 -0
  68. package/src/core/index.ts +1 -0
  69. package/src/core/solana-processor.ts +1 -5
  70. package/src/core/sui-processor.ts +1 -5
  71. package/src/gen/processor/protos/processor.ts +600 -1
  72. package/src/processor-state.ts +6 -0
  73. package/src/service.ts +28 -1
  74. package/src/tests/erc20.ts +4 -0
  75. package/src/tests/souffl3.ts +5 -7
  76. package/{template → templates/aptos}/.gitignore +0 -0
  77. package/templates/aptos/abis/aptos/souffle.json +389 -0
  78. package/{template → templates/aptos}/jest.config.js +0 -0
  79. package/templates/aptos/package.json +20 -0
  80. package/templates/aptos/sentio.yaml +1 -0
  81. package/templates/aptos/src/processor.test.ts +14 -0
  82. package/templates/aptos/src/processor.ts +13 -0
  83. package/{template → templates/aptos}/tsconfig.json +0 -0
  84. package/templates/evm/.gitignore +107 -0
  85. package/{template → templates/evm}/abis/evm/x2y2.json +0 -0
  86. package/templates/evm/jest.config.js +7 -0
  87. package/{template → templates/evm}/package.json +1 -1
  88. package/{template → templates/evm}/sentio.yaml +0 -0
  89. package/{template → templates/evm}/src/processor.test.ts +0 -0
  90. package/{template → templates/evm}/src/processor.ts +0 -0
  91. package/templates/evm/tsconfig.json +20 -0
  92. package/templates/raw/.gitignore +107 -0
  93. package/templates/raw/jest.config.js +7 -0
  94. package/templates/raw/package.json +20 -0
  95. package/templates/raw/sentio.yaml +3 -0
  96. package/templates/raw/src/processor.test.ts +14 -0
  97. package/templates/raw/src/processor.ts +0 -0
  98. package/templates/raw/tsconfig.json +20 -0
  99. package/templates/raw/yarn.lock +4095 -0
package/lib/cli/cli.js CHANGED
@@ -37,7 +37,7 @@ else {
37
37
  // For all the commands that need read project configs
38
38
  // TODO move them to their own modules
39
39
  // Process configs
40
- let processorConfig = { host: '', project: '', source: '', build: true };
40
+ let processorConfig = { host: '', project: '', build: true };
41
41
  // Fist step, read from project yaml file
42
42
  try {
43
43
  console.log(chalk_1.default.blue('Loading Process config'));
@@ -64,9 +64,9 @@ else {
64
64
  if (!processorConfig.host) {
65
65
  processorConfig.host = 'prod';
66
66
  }
67
- if (!processorConfig.source) {
68
- processorConfig.source = 'src/processor.ts';
69
- }
67
+ // if (!processorConfig.source) {
68
+ // processorConfig.source = 'src/processor.ts'
69
+ // }
70
70
  // if (!processorConfig.targets) {
71
71
  // console.warn('targets is not defined, use EVM as the default target')
72
72
  // processorConfig.targets = []
@@ -159,7 +159,7 @@ function usage() {
159
159
  {
160
160
  header: 'Usage',
161
161
  content: [
162
- 'sentio $command --help\t\tshow detail usage of specific command',
162
+ 'sentio <command> --help\t\tshow detail usage of specific command',
163
163
  'sentio login --api-key=xx\t\tsave credential to local',
164
164
  'sentio create\t\t\t\tcreate a template project',
165
165
  'sentio upload\t\t\t\tbuild and upload processor to sentio',
@@ -1 +1 @@
1
- {"version":3,"file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K,CAAC,CAAA;YACnD,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;YAE5B,IAAI,WAAW,GAAG,SAAS,CAAA;YAC3B,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;gBACtB,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;aACjC;YACD,IAAA,mBAAU,EAAC,eAAe,EAAE,WAAW,CAAC,CAAA;SACzC;KACF;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;QAC1C,IAAA,sBAAc,EAAC,KAAK,CAAC,CAAA;KACtB;SAAM,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;QACxC,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAA;KACrB;SAAM;QACL,KAAK,EAAE,CAAA;KACR;CACF;AAED,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;QAC7B;YACE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,8CAA8C;SACxD;QACD;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,iEAAiE;gBACjE,uDAAuD;gBACvD,gDAAgD;gBAChD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;gBAC5C,2CAA2C;aAC5C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'\nimport { uploadFile } from './upload'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport { runLogin } from './commands/run-login'\nimport { runCreate } from './commands/run-create'\nimport { runVersion } from './commands/run-version'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (!mainOptions.command) {\n usage()\n}\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(argv)\n} else {\n // For all the commands that need read project configs\n // TODO move them to their own modules\n\n // Process configs\n let processorConfig: SentioProjectConfig = { host: '', project: '', source: '', build: true }\n // Fist step, read from project yaml file\n try {\n console.log(chalk.blue('Loading Process config'))\n // TODO correctly located sentio.yaml\n const pwd = process.cwd()\n const packageJson = path.join(pwd, 'package.json')\n if (!fs.existsSync(packageJson)) {\n console.error('package.json not found, please run this command in the root of your project')\n process.exit(1)\n }\n\n const yamlPath = path.join(pwd, 'sentio.yaml')\n if (!fs.existsSync(yamlPath)) {\n console.error('sentio.yaml not found, please create one according to: TODO docs')\n process.exit(1)\n }\n\n processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig\n if (!processorConfig.project === undefined) {\n console.error('Config yaml must have contain a valid project identifier')\n process.exit(1)\n }\n if (processorConfig.build === undefined) {\n processorConfig.build = true\n }\n if (!processorConfig.host) {\n processorConfig.host = 'prod'\n }\n\n if (!processorConfig.source) {\n processorConfig.source = 'src/processor.ts'\n }\n // if (!processorConfig.targets) {\n // console.warn('targets is not defined, use EVM as the default target')\n // processorConfig.targets = []\n // }\n // if (processorConfig.targets.length === 0) {\n // // By default evm\n // processorConfig.targets.push({ chain: EVM })\n // }\n } catch (e) {\n console.error(e)\n process.exit(1)\n }\n\n if (mainOptions.command === 'upload') {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Manually provide API key rather than use saved credential',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'owner',\n description: '(Optional) Override Project owner',\n type: String,\n },\n {\n name: 'nobuild',\n description: '(Optional) Skip build & pack file before uploading, default false',\n type: Boolean,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'sentio upload',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n if (options.host) {\n processorConfig.host = options.host\n }\n if (options.nobuild) {\n processorConfig.build = false\n }\n finalizeHost(processorConfig)\n FinalizeProjectName(processorConfig, options.owner)\n console.log(processorConfig)\n\n let apiOverride = undefined\n if (options['api-key']) {\n apiOverride = options['api-key']\n }\n uploadFile(processorConfig, apiOverride)\n }\n } else if (mainOptions.command === 'build') {\n buildProcessor(false)\n } else if (mainOptions.command === 'gen') {\n buildProcessor(true)\n } else {\n usage()\n }\n}\n\nfunction usage() {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Manage your project files to Sentio.',\n },\n {\n header: 'Usage',\n content: [\n 'sentio $command --help\\t\\tshow detail usage of specific command',\n 'sentio login --api-key=xx\\t\\tsave credential to local',\n 'sentio create\\t\\t\\t\\tcreate a template project',\n 'sentio upload\\t\\t\\t\\tbuild and upload processor to sentio',\n 'sentio gen\\t\\t\\t\\tgenerate abi',\n 'sentio build\\t\\t\\t\\tgenerate abi and build',\n 'sentio version\\t\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,4EAAiD;AACjD,4CAAmB;AACnB,gDAAuB;AAEvB,sDAA0B;AAC1B,qCAAiF;AACjF,qCAAqC;AACrC,kDAAyB;AACzB,mCAAwC;AACxC,oDAA+C;AAC/C,sDAAiD;AACjD,wDAAmD;AAEnD,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,S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,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,EAAE;QACxC,IAAA,sBAAc,EAAC,IAAI,CAAC,CAAA;KACrB;SAAM;QACL,KAAK,EAAE,CAAA;KACR;CACF;AAED,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;QAC7B;YACE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,8CAA8C;SACxD;QACD;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,kEAAkE;gBAClE,uDAAuD;gBACvD,gDAAgD;gBAChD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;gBAC5C,2CAA2C;aAC5C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'\nimport { uploadFile } from './upload'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport { runLogin } from './commands/run-login'\nimport { runCreate } from './commands/run-create'\nimport { runVersion } from './commands/run-version'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (!mainOptions.command) {\n usage()\n}\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(argv)\n} else {\n // For all the commands that need read project configs\n // TODO move them to their own modules\n\n // Process configs\n let processorConfig: SentioProjectConfig = { host: '', project: '', build: true }\n // Fist step, read from project yaml file\n try {\n console.log(chalk.blue('Loading Process config'))\n // TODO correctly located sentio.yaml\n const pwd = process.cwd()\n const packageJson = path.join(pwd, 'package.json')\n if (!fs.existsSync(packageJson)) {\n console.error('package.json not found, please run this command in the root of your project')\n process.exit(1)\n }\n\n const yamlPath = path.join(pwd, 'sentio.yaml')\n if (!fs.existsSync(yamlPath)) {\n console.error('sentio.yaml not found, please create one according to: TODO docs')\n process.exit(1)\n }\n\n processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig\n if (!processorConfig.project === undefined) {\n console.error('Config yaml must have contain a valid project identifier')\n process.exit(1)\n }\n if (processorConfig.build === undefined) {\n processorConfig.build = true\n }\n if (!processorConfig.host) {\n processorConfig.host = 'prod'\n }\n\n // if (!processorConfig.source) {\n // processorConfig.source = 'src/processor.ts'\n // }\n // if (!processorConfig.targets) {\n // console.warn('targets is not defined, use EVM as the default target')\n // processorConfig.targets = []\n // }\n // if (processorConfig.targets.length === 0) {\n // // By default evm\n // processorConfig.targets.push({ chain: EVM })\n // }\n } catch (e) {\n console.error(e)\n process.exit(1)\n }\n\n if (mainOptions.command === 'upload') {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Manually provide API key rather than use saved credential',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'owner',\n description: '(Optional) Override Project owner',\n type: String,\n },\n {\n name: 'nobuild',\n description: '(Optional) Skip build & pack file before uploading, default false',\n type: Boolean,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'sentio upload',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n if (options.host) {\n processorConfig.host = options.host\n }\n if (options.nobuild) {\n processorConfig.build = false\n }\n finalizeHost(processorConfig)\n FinalizeProjectName(processorConfig, options.owner)\n console.log(processorConfig)\n\n let apiOverride = undefined\n if (options['api-key']) {\n apiOverride = options['api-key']\n }\n uploadFile(processorConfig, apiOverride)\n }\n } else if (mainOptions.command === 'build') {\n buildProcessor(false)\n } else if (mainOptions.command === 'gen') {\n buildProcessor(true)\n } else {\n usage()\n }\n}\n\nfunction usage() {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Manage your project files to Sentio.',\n },\n {\n header: 'Usage',\n content: [\n 'sentio <command> --help\\t\\tshow detail usage of specific command',\n 'sentio login --api-key=xx\\t\\tsave credential to local',\n 'sentio create\\t\\t\\t\\tcreate a template project',\n 'sentio upload\\t\\t\\t\\tbuild and upload processor to sentio',\n 'sentio gen\\t\\t\\t\\tgenerate abi',\n 'sentio build\\t\\t\\t\\tgenerate abi and build',\n 'sentio version\\t\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
@@ -31,23 +31,43 @@ function runCreate(argv) {
31
31
  description: '(Optional) The root direct new project will be created, default current working dir',
32
32
  type: String,
33
33
  },
34
+ {
35
+ name: 'chain-type',
36
+ alias: 'c',
37
+ description: 'The type of project you want to create, can be evm, aptos, raw (if you want to start from scratch and support multiple types of chains)',
38
+ type: String,
39
+ defaultValue: 'evm',
40
+ },
34
41
  ];
35
42
  const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
43
+ const usage = (0, command_line_usage_1.default)([
44
+ {
45
+ header: 'Create a template project',
46
+ content: 'sentio create <name>',
47
+ },
48
+ {
49
+ header: 'Options',
50
+ optionList: optionDefinitions,
51
+ },
52
+ ]);
36
53
  if (options.help || !options.name) {
37
- const usage = (0, command_line_usage_1.default)([
38
- {
39
- header: 'Create a template project',
40
- content: 'sentio create $NAME',
41
- },
42
- {
43
- header: 'Options',
44
- optionList: optionDefinitions,
45
- },
46
- ]);
47
54
  console.log(usage);
48
55
  }
49
56
  else {
50
- const templateFolder = path_1.default.resolve(__dirname, '../../../template');
57
+ const chainType = options['chain-type'].toLowerCase();
58
+ switch (chainType) {
59
+ case 'evm':
60
+ break;
61
+ case 'aptos':
62
+ break;
63
+ case 'raw':
64
+ break;
65
+ default:
66
+ console.error(chalk_1.default.red('non supported chain-type for template creation, use --help for more information.'));
67
+ console.log(usage);
68
+ process.exit(1);
69
+ }
70
+ const templateFolder = path_1.default.resolve(__dirname, '../../../templates', chainType);
51
71
  const projectName = options.name || 'default';
52
72
  const rootDir = options.directory || process.cwd();
53
73
  const dstFolder = path_1.default.resolve(rootDir, projectName);
@@ -1 +1 @@
1
- {"version":3,"file":"run-create.js","sourceRoot":"","sources":["../../../src/cli/commands/run-create.ts"],"names":[],"mappings":";;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,gDAAuB;AACvB,wDAAyB;AACzB,kDAAyB;AACzB,oCAAwC;AAExC,SAAgB,SAAS,CAAC,IAAc;IACtC,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,KAAK,EAAE,GAAG;YACV,aAAa,EAAE,IAAI;YACnB,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,cAAc;SAC5B;QACD;YACE,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,qFAAqF;YAClG,IAAI,EAAE,MAAM;SACb;KACF,CAAA;IAED,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5D,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjC,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;YAC7B;gBACE,MAAM,EAAE,2BAA2B;gBACnC,OAAO,EAAE,qBAAqB;aAC/B;YACD;gBACE,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,iBAAiB;aAC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AW,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;YAElF,MAAM,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;YAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAA;YAExE,IAAI,UAAU,GAAG,IAAA,qBAAa,GAAE,CAAA;YAChC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAC/B,UAAU,GAAG,GAAG,GAAG,UAAU,CAAA;aAC9B;YAED,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,UAAU,CAAA;YACpD,WAAW,CAAC,IAAI,GAAG,WAAW,CAAA;YAE9B,yCAAyC;YACzC,WAAW,CAAC,OAAO,CAAC,WAAW,GAAG,YAAY,CAAA;YAE9C,kBAAE,CAAC,aAAa,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;SACxE;QACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,+BAA+B,GAAG,WAAW,GAAG,GAAG,CAAC,CAAC,CAAA;KAC9E;AACH,CAAC;AArFD,8BAqFC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport chalk from 'chalk'\nimport { getCliVersion } from '../utils'\n\nexport function runCreate(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: 'name',\n alias: 'n',\n defaultOption: true,\n type: String,\n description: 'Project name',\n },\n {\n name: 'directory',\n alias: 'd',\n description: '(Optional) The root direct new project will be created, default current working dir',\n type: String,\n },\n ]\n\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help || !options.name) {\n const usage = commandLineUsage([\n {\n header: 'Create a template project',\n content: 'sentio create $NAME',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n const templateFolder = path.resolve(__dirname, '../../../template')\n const projectName = options.name || 'default'\n\n const rootDir = options.directory || process.cwd()\n const dstFolder = path.resolve(rootDir, projectName)\n if (fs.existsSync(dstFolder)) {\n console.error(chalk.red(\"can't create project '\" + projectName + \"', directory already existed\"))\n process.exit(1)\n }\n\n fs.copySync(templateFolder, dstFolder, {\n filter: (src, _) => {\n // TODO read from .gitignore to be more reliable\n if (\n src.endsWith('types') ||\n src.endsWith('dist') ||\n src.endsWith('node_modules') ||\n src.endsWith('.lock') ||\n src.endsWith('dist')\n ) {\n return false\n }\n return true\n },\n overwrite: false,\n })\n if (options.name) {\n const sentioYamlPath = path.resolve(dstFolder, 'sentio.yaml')\n fs.writeFileSync(sentioYamlPath, 'project: ' + projectName + '\\n', { flag: 'w+' })\n\n const packageJsonPath = path.resolve(dstFolder, 'package.json')\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))\n\n let cliVersion = getCliVersion()\n if (!cliVersion.startsWith('^')) {\n cliVersion = '^' + cliVersion\n }\n\n packageJson.dependencies['@sentio/sdk'] = cliVersion\n packageJson.name = projectName\n\n // Don't add directly to avoid deps issue\n packageJson.scripts.postinstall = 'sentio gen'\n\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))\n }\n console.log(chalk.green(\"successfully create project '\" + projectName + \"'\"))\n }\n}\n"]}
1
+ {"version":3,"file":"run-create.js","sourceRoot":"","sources":["../../../src/cli/commands/run-create.ts"],"names":[],"mappings":";;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,gDAAuB;AACvB,wDAAyB;AACzB,kDAAyB;AACzB,oCAAwC;AAExC,SAAgB,SAAS,CAAC,IAAc;IACtC,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YAC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ElF,MAAM,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;YAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAA;YAExE,IAAI,UAAU,GAAG,IAAA,qBAAa,GAAE,CAAA;YAChC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAC/B,UAAU,GAAG,GAAG,GAAG,UAAU,CAAA;aAC9B;YAED,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,UAAU,CAAA;YACpD,WAAW,CAAC,IAAI,GAAG,WAAW,CAAA;YAE9B,yCAAyC;YACzC,WAAW,CAAC,OAAO,CAAC,WAAW,GAAG,YAAY,CAAA;YAE9C,kBAAE,CAAC,aAAa,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;SACxE;QACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,+BAA+B,GAAG,WAAW,GAAG,GAAG,CAAC,CAAC,CAAA;KAC9E;AACH,CAAC;AA3GD,8BA2GC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport path from 'path'\nimport fs from 'fs-extra'\nimport chalk from 'chalk'\nimport { getCliVersion } from '../utils'\n\nexport function runCreate(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: 'name',\n alias: 'n',\n defaultOption: true,\n type: String,\n description: 'Project name',\n },\n {\n name: 'directory',\n alias: 'd',\n description: '(Optional) The root direct new project will be created, default current working dir',\n type: String,\n },\n {\n name: 'chain-type',\n alias: 'c',\n description:\n 'The type of project you want to create, can be evm, aptos, raw (if you want to start from scratch and support multiple types of chains)',\n type: String,\n defaultValue: 'evm',\n },\n ]\n\n const options = commandLineArgs(optionDefinitions, { argv })\n const usage = commandLineUsage([\n {\n header: 'Create a template project',\n content: 'sentio create <name>',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n\n if (options.help || !options.name) {\n console.log(usage)\n } else {\n const chainType: string = options['chain-type'].toLowerCase()\n switch (chainType) {\n case 'evm':\n break\n case 'aptos':\n break\n case 'raw':\n break\n default:\n console.error(chalk.red('non supported chain-type for template creation, use --help for more information.'))\n console.log(usage)\n process.exit(1)\n }\n const templateFolder = path.resolve(__dirname, '../../../templates', chainType)\n const projectName = options.name || 'default'\n\n const rootDir = options.directory || process.cwd()\n const dstFolder = path.resolve(rootDir, projectName)\n if (fs.existsSync(dstFolder)) {\n console.error(chalk.red(\"can't create project '\" + projectName + \"', directory already existed\"))\n process.exit(1)\n }\n\n fs.copySync(templateFolder, dstFolder, {\n filter: (src, _) => {\n // TODO read from .gitignore to be more reliable\n if (\n src.endsWith('types') ||\n src.endsWith('dist') ||\n src.endsWith('node_modules') ||\n src.endsWith('.lock') ||\n src.endsWith('dist')\n ) {\n return false\n }\n return true\n },\n overwrite: false,\n })\n if (options.name) {\n const sentioYamlPath = path.resolve(dstFolder, 'sentio.yaml')\n fs.writeFileSync(sentioYamlPath, 'project: ' + projectName + '\\n', { flag: 'w+' })\n\n const packageJsonPath = path.resolve(dstFolder, 'package.json')\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))\n\n let cliVersion = getCliVersion()\n if (!cliVersion.startsWith('^')) {\n cliVersion = '^' + cliVersion\n }\n\n packageJson.dependencies['@sentio/sdk'] = cliVersion\n packageJson.name = projectName\n\n // Don't add directly to avoid deps issue\n packageJson.scripts.postinstall = 'sentio gen'\n\n fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))\n }\n console.log(chalk.green(\"successfully create project '\" + projectName + \"'\"))\n }\n}\n"]}
@@ -35,7 +35,7 @@ function runLogin(argv) {
35
35
  const usage = (0, command_line_usage_1.default)([
36
36
  {
37
37
  header: 'Login to Sentio',
38
- content: 'sentio login --api-key=$key',
38
+ content: 'sentio login --api-key=<key>',
39
39
  },
40
40
  {
41
41
  header: 'Options',
@@ -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,sCAA4C;AAC5C,kDAAyB;AACzB,kDAAyB;AACzB,gDAAuB;AACvB,gCAAiC;AAEjC,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,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,yBAAyB;SACvC;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,MAAM;SACb;KACF,CAAA;IACD,MAAM,OAAO,GAAG,IAAA,2BAAe,EAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IAE5D,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QACvC,MAAM,KAAK,GAAG,IAAA,4BAAgB,EAAC;YAC7B;gBACE,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,6BAA6B;aACvC;YACD;gBACE,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,iBAAiB;aAC9B;SACF,CAAC,CAAA;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;KACnB;SAAM;QACL,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,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAA;QACzB,MAAM,UAAU,GAAG;YACjB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,IAAI,EAAE,8BAA8B;YACpC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC;aAC9B;SACF,CAAA;QACD,MAAM,CAAC,GAAG,GAAG,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,eAAK,CAAC,CAAC,CAAC,cAAI,CAAA;QACjD,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;YACxC,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,EAAE;gBACzB,IAAA,cAAQ,EAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;gBAClC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;aAC1C;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAA;aACnF;QACH,CAAC,CAAC,CAAA;QAEF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACxB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC,CAAC,CAAA;QACF,GAAG,CAAC,GAAG,EAAE,CAAA;KACV;AACH,CAAC;AA7DD,4BA6DC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { getFinalizedHost } from '../config'\nimport chalk from 'chalk'\nimport https from 'https'\nimport http from 'http'\nimport { WriteKey } from '../key'\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: 'api-key',\n type: String,\n description: '(Required) Your API key',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n\n if (options.help || !options['api-key']) {\n const usage = commandLineUsage([\n {\n header: 'Login to Sentio',\n content: 'sentio login --api-key=$key',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n const host = getFinalizedHost(options.host)\n console.log(chalk.blue('login to ' + host))\n const url = new URL(host)\n const reqOptions = {\n hostname: url.hostname,\n port: url.port,\n path: '/api/v1/processors/check_key',\n method: 'HEAD',\n headers: {\n 'api-key': options['api-key'],\n },\n }\n const h = url.protocol == 'https:' ? https : http\n const req = h.request(reqOptions, (res) => {\n if (res.statusCode == 200) {\n WriteKey(host, options['api-key'])\n console.log(chalk.green('login success'))\n } else {\n console.error(chalk.red('login failed, code:', res.statusCode, res.statusMessage))\n }\n })\n\n req.on('error', (error) => {\n console.error(error)\n })\n req.end()\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,sCAA4C;AAC5C,kDAAyB;AACzB,kDAAyB;AACzB,gDAAuB;AACvB,gCAAiC;AAEjC,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,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,yBAAyB;SACvC;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,IAAI,EAAE,MAAM;SAC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AC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;aAC1C;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAA;aACnF;QACH,CAAC,CAAC,CAAA;QAEF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACxB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC,CAAC,CAAA;QACF,GAAG,CAAC,GAAG,EAAE,CAAA;KACV;AACH,CAAC;AA7DD,4BA6DC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { getFinalizedHost } from '../config'\nimport chalk from 'chalk'\nimport https from 'https'\nimport http from 'http'\nimport { WriteKey } from '../key'\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: 'api-key',\n type: String,\n description: '(Required) Your API key',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n\n if (options.help || !options['api-key']) {\n const usage = commandLineUsage([\n {\n header: 'Login to Sentio',\n content: 'sentio login --api-key=<key>',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n const host = getFinalizedHost(options.host)\n console.log(chalk.blue('login to ' + host))\n const url = new URL(host)\n const reqOptions = {\n hostname: url.hostname,\n port: url.port,\n path: '/api/v1/processors/check_key',\n method: 'HEAD',\n headers: {\n 'api-key': options['api-key'],\n },\n }\n const h = url.protocol == 'https:' ? https : http\n const req = h.request(reqOptions, (res) => {\n if (res.statusCode == 200) {\n WriteKey(host, options['api-key'])\n console.log(chalk.green('login success'))\n } else {\n console.error(chalk.red('login failed, code:', res.statusCode, res.statusMessage))\n }\n })\n\n req.on('error', (error) => {\n console.error(error)\n })\n req.end()\n }\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  export interface SentioProjectConfig {
2
2
  project: string;
3
3
  host: string;
4
- source: string;
5
4
  build: boolean;
6
5
  }
7
6
  export declare function getFinalizedHost(host: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":";;;AAQA,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,QAAQ,IAAI,EAAE;QACZ,KAAK,SAAS,CAAC;QACf,KAAK,EAAE,CAAC;QACR,KAAK,MAAM;YACT,OAAO,wBAAwB,CAAA;QACjC,KAAK,MAAM;YACT,OAAO,yBAAyB,CAAA;QAClC,KAAK,SAAS;YACZ,OAAO,4BAA4B,CAAA;QACrC,KAAK,OAAO;YACV,OAAO,wBAAwB,CAAA;KAClC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAdD,4CAcC;AAED,SAAgB,YAAY,CAAC,MAA2B;IACtD,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC7C,CAAC;AAFD,oCAEC;AAED,SAAgB,mBAAmB,CAAC,MAA2B,EAAE,KAAyB;IACxF,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;SACpC;QACD,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KACzC;AACH,CAAC;AARD,kDAQC;AAED,4BAA4B;AAC5B,kBAAkB;AAClB,qBAAqB;AACrB,IAAI;AACJ,EAAE;AACF,wCAAwC;AACxC,2BAA2B;AAC3B,iCAAiC","sourcesContent":["export interface SentioProjectConfig {\n project: string\n host: string\n source: string\n build: boolean\n // targets: Target[]\n}\n\nexport function getFinalizedHost(host: string): string {\n switch (host) {\n case undefined:\n case '':\n case 'prod':\n return 'https://app.sentio.xyz'\n case 'test':\n return 'https://test.sentio.xyz'\n case 'staging':\n return 'https://staging.sentio.xyz'\n case 'local':\n return 'http://localhost:10000'\n }\n return host\n}\n\nexport function finalizeHost(config: SentioProjectConfig) {\n config.host = getFinalizedHost(config.host)\n}\n\nexport function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {\n if (owner) {\n let name = config.project\n if (name.includes('/')) {\n name = config.project.split('/')[1]\n }\n config.project = [owner, name].join('/')\n }\n}\n\n// export interface Target {\n// chain: string\n// abisDir?: string\n// }\n//\n// // Supported target chain, lower case\n// export const EVM = 'evm'\n// export const SOLANA = 'solana'\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":";;;AAQA,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,QAAQ,IAAI,EAAE;QACZ,KAAK,SAAS,CAAC;QACf,KAAK,EAAE,CAAC;QACR,KAAK,MAAM;YACT,OAAO,wBAAwB,CAAA;QACjC,KAAK,MAAM;YACT,OAAO,yBAAyB,CAAA;QAClC,KAAK,SAAS;YACZ,OAAO,4BAA4B,CAAA;QACrC,KAAK,OAAO;YACV,OAAO,wBAAwB,CAAA;KAClC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAdD,4CAcC;AAED,SAAgB,YAAY,CAAC,MAA2B;IACtD,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC7C,CAAC;AAFD,oCAEC;AAED,SAAgB,mBAAmB,CAAC,MAA2B,EAAE,KAAyB;IACxF,IAAI,KAAK,EAAE;QACT,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;SACpC;QACD,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KACzC;AACH,CAAC;AARD,kDAQC;AAED,4BAA4B;AAC5B,kBAAkB;AAClB,qBAAqB;AACrB,IAAI;AACJ,EAAE;AACF,wCAAwC;AACxC,2BAA2B;AAC3B,iCAAiC","sourcesContent":["export interface SentioProjectConfig {\n project: string\n host: string\n // source: string\n build: boolean\n // targets: Target[]\n}\n\nexport function getFinalizedHost(host: string): string {\n switch (host) {\n case undefined:\n case '':\n case 'prod':\n return 'https://app.sentio.xyz'\n case 'test':\n return 'https://test.sentio.xyz'\n case 'staging':\n return 'https://staging.sentio.xyz'\n case 'local':\n return 'http://localhost:10000'\n }\n return host\n}\n\nexport function finalizeHost(config: SentioProjectConfig) {\n config.host = getFinalizedHost(config.host)\n}\n\nexport function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {\n if (owner) {\n let name = config.project\n if (name.includes('/')) {\n name = config.project.split('/')[1]\n }\n config.project = [owner, name].join('/')\n }\n}\n\n// export interface Target {\n// chain: string\n// abisDir?: string\n// }\n//\n// // Supported target chain, lower case\n// export const EVM = 'evm'\n// export const SOLANA = 'solana'\n"]}
@@ -7,6 +7,7 @@ exports.BaseProcessor = exports.TraceHandler = exports.EventsHandler = void 0;
7
7
  const providers_1 = require("@ethersproject/providers");
8
8
  const long_1 = __importDefault(require("long"));
9
9
  const context_1 = require("./context");
10
+ const gen_1 = require("../gen");
10
11
  class EventsHandler {
11
12
  filters;
12
13
  handler;
@@ -76,17 +77,9 @@ class BaseProcessor {
76
77
  event.eventSignature = parsed.signature;
77
78
  // TODO fix this bug
78
79
  await handler(event, ctx);
79
- return {
80
- gauges: ctx.gauges,
81
- counters: ctx.counters,
82
- logs: ctx.logs,
83
- };
80
+ return ctx.getProcessResult();
84
81
  }
85
- return {
86
- gauges: [],
87
- counters: [],
88
- logs: [],
89
- };
82
+ return gen_1.ProcessResult.fromPartial({});
90
83
  },
91
84
  });
92
85
  return this;
@@ -98,11 +91,7 @@ class BaseProcessor {
98
91
  this.blockHandlers.push(async function (block) {
99
92
  const ctx = new context_1.ContractContext(contractName, contractView, chainId, block, undefined);
100
93
  await handler(block, ctx);
101
- return {
102
- gauges: ctx.gauges,
103
- counters: ctx.counters,
104
- logs: ctx.logs,
105
- };
94
+ return ctx.getProcessResult();
106
95
  });
107
96
  return this;
108
97
  }
@@ -126,21 +115,13 @@ class BaseProcessor {
126
115
  const contractInterface = contractView.rawContract.interface;
127
116
  const fragment = contractInterface.getFunction(signature);
128
117
  if (!trace.action.input) {
129
- return {
130
- gauges: [],
131
- counters: [],
132
- logs: [],
133
- };
118
+ return gen_1.ProcessResult.fromPartial({});
134
119
  }
135
120
  const traceData = '0x' + trace.action.input.slice(10);
136
121
  trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData);
137
122
  const ctx = new context_1.ContractContext(contractName, contractView, chainId, undefined, undefined, trace);
138
123
  await handler(trace, ctx);
139
- return {
140
- gauges: ctx.gauges,
141
- counters: ctx.counters,
142
- logs: ctx.logs,
143
- };
124
+ return ctx.getProcessResult();
144
125
  },
145
126
  });
146
127
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAA4E;AAM5E,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAoB,EAAE,CAAA;I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QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAA;QACnD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;QAErC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,SAAS;YACT,OAAO,EAAE,KAAK,WAAW,KAAY;gBACnC,MAAM,iBAAiB,GAAG,YAAY,CAAC,WAAW,CAAC,SAAS,CAAA;gBAC5D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;gBACzD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE;oBACvB,OAAO;wBACL,MAAM,EAAE,EAAE;wBACV,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;qBACT,CAAA;iBACF;gBACD,MAAM,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;gBACrD,KAAK,CAAC,IAAI,GAAG,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;gBAE3E,MAAM,GAAG,GAAG,IAAI,yBAAe,CAC7B,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,CACN,CAAA;gBACD,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;gBACzB,OAAO;oBACL,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;oBACtB,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAA;YACH,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1KD,sCA0KC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log\n )\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined\n )\n await handler(block, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return {\n gauges: [],\n counters: [],\n logs: [],\n }\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n undefined,\n trace\n )\n await handler(trace, ctx)\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n },\n })\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAA4E;AAC5E,gCAAsC;AAKtC,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAsB,aAAa;IAIjC,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAoB,EAAE,CAAA;IACnC,aAAa,GAAmB,EAAE,CAAA;IAElC,MAAM,CAAqB;IAE3B,YAAY,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,UAAU,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC;SACxB,CAAA;QACD,IAAI,MAAM,CAAC,UAAU,EAAE;YACrB,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE;gBACzC,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,cAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;aAC5D;iBAAM;gBACL,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;aAC3C;SACF;QACD,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,c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cesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log\n )\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push(async function (block: Block) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined\n )\n await handler(block, ctx)\n return ctx.getProcessResult()\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return ProcessResult.fromPartial({})\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n undefined,\n trace\n )\n await handler(trace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData } from '../gen';
1
+ import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData, EventTrackingResult, ProcessResult } from '../gen';
2
2
  import { BaseContract, EventFilter } from 'ethers';
3
3
  import { Block, Log } from '@ethersproject/abstract-provider';
4
4
  import { Meter } from './meter';
@@ -10,10 +10,12 @@ export declare abstract class BaseContext {
10
10
  gauges: GaugeResult[];
11
11
  counters: CounterResult[];
12
12
  logs: LogResult[];
13
+ events: EventTrackingResult[];
13
14
  meter: Meter;
14
15
  logger: Logger;
15
16
  protected constructor();
16
- abstract getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
17
+ getProcessResult(): ProcessResult;
18
+ abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
17
19
  }
18
20
  export declare abstract class EthContext extends BaseContext {
19
21
  chainId: number;
@@ -29,7 +31,7 @@ export declare class ContractContext<TContract extends BaseContract, TContractBo
29
31
  contract: TContractBoundView;
30
32
  contractName: string;
31
33
  constructor(contractName: string, view: TContractBoundView, chainId: number, block?: Block, log?: Log, trace?: Trace);
32
- getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
34
+ getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
33
35
  }
34
36
  export declare class ContractView<TContract extends BaseContract> {
35
37
  filters: {
@@ -55,12 +57,12 @@ export declare class SolanaContext extends BaseContext {
55
57
  programName: string;
56
58
  blockNumber: Long;
57
59
  constructor(programName: string, address: string, slot: Long);
58
- getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
60
+ getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
59
61
  }
60
62
  export declare class SuiContext extends BaseContext {
61
63
  address: string;
62
64
  moduleName: string;
63
65
  blockNumber: Long;
64
66
  constructor(address: string, slot: Long);
65
- getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData;
67
+ getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData;
66
68
  }
@@ -12,12 +12,22 @@ class BaseContext {
12
12
  gauges = [];
13
13
  counters = [];
14
14
  logs = [];
15
+ events = [];
15
16
  meter;
16
17
  logger;
17
18
  constructor() {
18
19
  this.meter = new meter_1.Meter(this);
19
20
  this.logger = new logger_1.Logger(this);
20
21
  }
22
+ getProcessResult() {
23
+ const res = {
24
+ gauges: this.gauges,
25
+ counters: this.counters,
26
+ logs: this.logs,
27
+ events: this.events,
28
+ };
29
+ return res;
30
+ }
21
31
  }
22
32
  exports.BaseContext = BaseContext;
23
33
  class EthContext extends BaseContext {
@@ -69,6 +79,7 @@ class ContractContext extends EthContext {
69
79
  logIndex: this.log.logIndex,
70
80
  chainId: this.chainId.toString(),
71
81
  dataDescriptor: descriptor,
82
+ name: descriptor.name,
72
83
  labels: (0, meter_1.normalizeLabels)(labels),
73
84
  };
74
85
  }
@@ -82,6 +93,7 @@ class ContractContext extends EthContext {
82
93
  logIndex: -1,
83
94
  chainId: this.chainId.toString(),
84
95
  dataDescriptor: descriptor,
96
+ name: descriptor.name,
85
97
  labels: (0, meter_1.normalizeLabels)(labels),
86
98
  };
87
99
  }
@@ -95,6 +107,7 @@ class ContractContext extends EthContext {
95
107
  logIndex: -1,
96
108
  chainId: this.chainId.toString(),
97
109
  dataDescriptor: descriptor,
110
+ name: descriptor.name,
98
111
  labels: (0, meter_1.normalizeLabels)(labels),
99
112
  };
100
113
  }
@@ -155,6 +168,7 @@ class SolanaContext extends BaseContext {
155
168
  logIndex: 0,
156
169
  chainId: chain_1.SOL_MAINMET_ID,
157
170
  dataDescriptor: descriptor,
171
+ name: descriptor.name,
158
172
  labels: (0, meter_1.normalizeLabels)(labels),
159
173
  };
160
174
  }
@@ -179,6 +193,7 @@ class SuiContext extends BaseContext {
179
193
  logIndex: 0,
180
194
  chainId: chain_1.SUI_DEVNET_ID,
181
195
  dataDescriptor: descriptor,
196
+ name: descriptor.name,
182
197
  labels: (0, meter_1.normalizeLabels)(labels),
183
198
  };
184
199
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":";;;;;;AAGA,mCAAgD;AAChD,gDAAuB;AAEvB,qCAAiC;AAEjC,0CAA8D;AAE9D,MAAsB,WAAW;IAC/B,MAAM,GAAkB,EAAE,CAAA;IAC1B,QAAQ,GAAoB,EAAE,CAAA;IAC9B,IAAI,GAAgB,EAAE,CAAA;IACtB,KAAK,CAAO;IACZ,MAAM,CAAQ;IAEd;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CAGF;AAbD,kCAaC;AAED,MAAsB,UAAW,SAAQ,WAAW;IAClD,OAAO,CAAQ;IACf,OAAO,CAAQ;IACf,GAAG,CAAM;IACT,KAAK,CAAQ;IACb,KAAK,CAAQ;IACb,WAAW,CAAM;IACjB,eAAe,CAAS;IAExB,YAAsB,OAAe,EAAE,OAAe,EAAE,KAAa,EAAE,GAAS,EAAE,KAAa;QAC7F,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,WAAW,GAAG,cAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;YACzD,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC,eAAe,CAAA;SAC3C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,SAAQ,WAAW;IACzC,OAAO,CAAQ;IACf,UAAU,CAAQ;IAClB,WAAW,CAAM;IAEjB,YAAY,OAAe,EAAE,IAAU;QACrC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;IACzB,CAAC;IAED,WAAW,CAAC,UAAsC,EAAE,MAAc;QAChE,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,qBAAa;YACtB,cAAc,EAAE,UAAU;YAC1B,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AAxBD,gCAwBC","sourcesContent":["import { CounterResult, GaugeResult, LogResult, DataDescriptor, RecordMetaData } from '../gen'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { Meter, normalizeLabels } from './meter'\nimport Long from 'long'\nimport { Trace } from './trace'\nimport { Logger } from './logger'\nimport { Labels } from './metadata'\nimport { SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'\n\nexport abstract class BaseContext {\n gauges: GaugeResult[] = []\n counters: CounterResult[] = []\n logs: LogResult[] = []\n meter: Meter\n logger: Logger\n\n protected constructor() {\n this.meter = new Meter(this)\n this.logger = new Logger(this)\n }\n\n abstract getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData\n}\n\nexport abstract class EthContext extends BaseContext {\n chainId: number\n address: string\n log?: Log\n block?: Block\n trace?: Trace\n blockNumber: Long\n transactionHash?: string\n\n protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {\n super()\n this.chainId = chainId\n this.log = log\n this.block = block\n this.trace = trace\n this.address = address\n if (log) {\n this.blockNumber = Long.fromNumber(log.blockNumber, true)\n this.transactionHash = log.transactionHash\n } else if (block) {\n this.blockNumber = Long.fromNumber(block.number, true)\n } else if (trace) {\n this.blockNumber = Long.fromNumber(trace.blockNumber, true)\n this.transactionHash = trace.transactionHash\n }\n }\n}\n\nexport class ContractContext<\n TContract extends BaseContract,\n TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>\n> extends EthContext {\n contract: TContractBoundView\n contractName: string\n\n constructor(\n contractName: string,\n view: TContractBoundView,\n chainId: number,\n block?: Block,\n log?: Log,\n trace?: Trace\n ) {\n super(chainId, view.rawContract.address, block, log, trace)\n view.context = this\n this.contractName = contractName\n this.contract = view\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n if (this.log) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.log.transactionIndex,\n transactionHash: this.transactionHash || '',\n logIndex: this.log.logIndex,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (this.block) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: -1,\n transactionHash: '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (this.trace) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.trace.transactionPosition,\n transactionHash: this.transactionHash || '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"Invaid ctx argument can't happen\")\n }\n}\n\nexport class ContractView<TContract extends BaseContract> {\n filters: { [name: string]: (...args: Array<any>) => EventFilter }\n protected contract: TContract\n\n constructor(contract: TContract) {\n this.contract = contract\n this.filters = contract.filters\n }\n\n get rawContract() {\n return this.contract\n }\n\n get provider() {\n return this.contract.provider\n }\n}\n\nexport class BoundContractView<TContract extends BaseContract, TContractView extends ContractView<TContract>> {\n protected view: TContractView\n // context will be set right after context creation (in context's constructor)\n context: ContractContext<TContract, BoundContractView<TContract, TContractView>>\n\n constructor(view: TContractView) {\n this.view = view\n }\n\n get rawContract() {\n return this.view.rawContract\n }\n\n get provider() {\n return this.view.provider\n }\n\n get filters() {\n return this.view.filters\n }\n}\n\nexport class SolanaContext extends BaseContext {\n address: string\n programName: string\n blockNumber: Long\n\n constructor(programName: string, address: string, slot: Long) {\n super()\n this.programName = programName\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.programName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO add\n logIndex: 0,\n chainId: SOL_MAINMET_ID, // TODO set in context\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class SuiContext extends BaseContext {\n address: string\n moduleName: string\n blockNumber: Long\n\n constructor(address: string, slot: Long) {\n super()\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor | undefined, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO\n logIndex: 0,\n chainId: SUI_DEVNET_ID, // TODO set in context\n dataDescriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":";;;;;;AAWA,mCAAgD;AAChD,gDAAuB;AAEvB,qCAAiC;AAEjC,0CAA8D;AAE9D,MAAsB,WAAW;IAC/B,MAAM,GAAkB,EAAE,CAAA;IAC1B,QAAQ,GAAoB,EAAE,CAAA;IAC9B,IAAI,GAAgB,EAAE,CAAA;IACtB,MAAM,GAA0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UAAW,SAAQ,WAAW;IACzC,OAAO,CAAQ;IACf,UAAU,CAAQ;IAClB,WAAW,CAAM;IAEjB,YAAY,OAAe,EAAE,IAAU;QACrC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;IACzB,CAAC;IAED,WAAW,CAAC,UAA0B,EAAE,MAAc;QACpD,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,qBAAa;YACtB,cAAc,EAAE,UAAU;YAC1B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF;AAzBD,gCAyBC","sourcesContent":["import {\n CounterResult,\n GaugeResult,\n LogResult,\n DataDescriptor,\n RecordMetaData,\n EventTrackingResult,\n ProcessResult,\n} from '../gen'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { Meter, normalizeLabels } from './meter'\nimport Long from 'long'\nimport { Trace } from './trace'\nimport { Logger } from './logger'\nimport { Labels } from './metadata'\nimport { SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'\n\nexport abstract class BaseContext {\n gauges: GaugeResult[] = []\n counters: CounterResult[] = []\n logs: LogResult[] = []\n events: EventTrackingResult[] = []\n meter: Meter\n logger: Logger\n\n protected constructor() {\n this.meter = new Meter(this)\n this.logger = new Logger(this)\n }\n\n getProcessResult(): ProcessResult {\n const res: ProcessResult = {\n gauges: this.gauges,\n counters: this.counters,\n logs: this.logs,\n events: this.events,\n }\n return res\n }\n\n abstract getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData\n}\n\nexport abstract class EthContext extends BaseContext {\n chainId: number\n address: string\n log?: Log\n block?: Block\n trace?: Trace\n blockNumber: Long\n transactionHash?: string\n\n protected constructor(chainId: number, address: string, block?: Block, log?: Log, trace?: Trace) {\n super()\n this.chainId = chainId\n this.log = log\n this.block = block\n this.trace = trace\n this.address = address\n if (log) {\n this.blockNumber = Long.fromNumber(log.blockNumber, true)\n this.transactionHash = log.transactionHash\n } else if (block) {\n this.blockNumber = Long.fromNumber(block.number, true)\n } else if (trace) {\n this.blockNumber = Long.fromNumber(trace.blockNumber, true)\n this.transactionHash = trace.transactionHash\n }\n }\n}\n\nexport class ContractContext<\n TContract extends BaseContract,\n TContractBoundView extends BoundContractView<TContract, ContractView<TContract>>\n> extends EthContext {\n contract: TContractBoundView\n contractName: string\n\n constructor(\n contractName: string,\n view: TContractBoundView,\n chainId: number,\n block?: Block,\n log?: Log,\n trace?: Trace\n ) {\n super(chainId, view.rawContract.address, block, log, trace)\n view.context = this\n this.contractName = contractName\n this.contract = view\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n if (this.log) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.log.transactionIndex,\n transactionHash: this.transactionHash || '',\n logIndex: this.log.logIndex,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n if (this.block) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: -1,\n transactionHash: '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n if (this.trace) {\n return {\n address: this.contract.rawContract.address,\n contractName: this.contractName,\n blockNumber: this.blockNumber,\n transactionIndex: this.trace.transactionPosition,\n transactionHash: this.transactionHash || '',\n logIndex: -1,\n chainId: this.chainId.toString(),\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"Invaid ctx argument can't happen\")\n }\n}\n\nexport class ContractView<TContract extends BaseContract> {\n filters: { [name: string]: (...args: Array<any>) => EventFilter }\n protected contract: TContract\n\n constructor(contract: TContract) {\n this.contract = contract\n this.filters = contract.filters\n }\n\n get rawContract() {\n return this.contract\n }\n\n get provider() {\n return this.contract.provider\n }\n}\n\nexport class BoundContractView<TContract extends BaseContract, TContractView extends ContractView<TContract>> {\n protected view: TContractView\n // context will be set right after context creation (in context's constructor)\n context: ContractContext<TContract, BoundContractView<TContract, TContractView>>\n\n constructor(view: TContractView) {\n this.view = view\n }\n\n get rawContract() {\n return this.view.rawContract\n }\n\n get provider() {\n return this.view.provider\n }\n\n get filters() {\n return this.view.filters\n }\n}\n\nexport class SolanaContext extends BaseContext {\n address: string\n programName: string\n blockNumber: Long\n\n constructor(programName: string, address: string, slot: Long) {\n super()\n this.programName = programName\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.programName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO add\n logIndex: 0,\n chainId: SOL_MAINMET_ID, // TODO set in context\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class SuiContext extends BaseContext {\n address: string\n moduleName: string\n blockNumber: Long\n\n constructor(address: string, slot: Long) {\n super()\n this.address = address\n this.blockNumber = slot\n }\n\n getMetaData(descriptor: DataDescriptor, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO\n logIndex: 0,\n chainId: SUI_DEVNET_ID, // TODO set in context\n dataDescriptor: descriptor,\n name: descriptor.name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { BaseContext } from './context';
2
+ export interface Event {
3
+ distinctId: string;
4
+ payload?: Record<string, string>;
5
+ }
6
+ export interface TrackerOptions {
7
+ totalByDay?: boolean;
8
+ unique?: boolean;
9
+ distinctByDays?: number[];
10
+ }
11
+ export declare class EventTracker {
12
+ static DEFAULT_OPTIONS: TrackerOptions;
13
+ static register(eventName: string, options?: TrackerOptions): EventTracker;
14
+ eventName: string;
15
+ options: TrackerOptions;
16
+ protected constructor(eventName: string, options: TrackerOptions);
17
+ trackEvent(ctx: BaseContext, event: Event): void;
18
+ }
19
+ export declare class AccountEventTracker extends EventTracker {
20
+ static DEFAULT_OPTIONS: TrackerOptions;
21
+ static register(eventName?: string, options?: TrackerOptions): AccountEventTracker;
22
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccountEventTracker = exports.EventTracker = void 0;
4
+ const sdk_1 = require("@sentio/sdk");
5
+ // Track Event with an identity associate with it
6
+ class EventTracker {
7
+ static DEFAULT_OPTIONS = {
8
+ totalByDay: true,
9
+ unique: true,
10
+ };
11
+ static register(eventName, options) {
12
+ const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options });
13
+ global.PROCESSOR_STATE.eventTrackers.push(tracker);
14
+ return tracker;
15
+ }
16
+ eventName;
17
+ options;
18
+ constructor(eventName, options) {
19
+ this.eventName = eventName;
20
+ this.options = options;
21
+ }
22
+ trackEvent(ctx, event) {
23
+ const res = {
24
+ metadata: ctx.getMetaData(sdk_1.DataDescriptor.fromPartial({ name: this.eventName }), {}),
25
+ distinctEntityId: event.distinctId,
26
+ attributes: JSON.stringify({}),
27
+ runtimeInfo: undefined,
28
+ };
29
+ ctx.events.push(res);
30
+ }
31
+ }
32
+ exports.EventTracker = EventTracker;
33
+ class AccountEventTracker extends EventTracker {
34
+ static DEFAULT_OPTIONS = {
35
+ totalByDay: true,
36
+ unique: true,
37
+ distinctByDays: [1, 7, 30],
38
+ };
39
+ static register(eventName, options) {
40
+ if (eventName) {
41
+ ;
42
+ ['user', eventName].join('.');
43
+ }
44
+ else {
45
+ eventName = 'user';
46
+ }
47
+ const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options });
48
+ global.PROCESSOR_STATE.eventTrackers.push(tracker);
49
+ return tracker;
50
+ }
51
+ }
52
+ exports.AccountEventTracker = AccountEventTracker;
53
+ //# sourceMappingURL=event-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-tracker.js","sourceRoot":"","sources":["../../src/core/event-tracker.ts"],"names":[],"mappings":";;;AACA,qCAAiE;AAgBjE,iDAAiD;AACjD,MAAa,YAAY;IACvB,MAAM,CAAC,eAAe,GAAmB;QACvC,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;KACb,CAAA;IAED,MAAM,CAAC,QAAQ,CAAC,SAAiB,EAAE,OAAwB;QACzD,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,GAAG,YAAY,CAAC,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAC5F,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClD,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,SAAS,CAAQ;IACjB,OAAO,CAAgB;IACvB,YAAsB,SAAiB,EAAE,OAAuB;QAC9D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,UAAU,CAAC,GAAgB,EAAE,KAAY;QACvC,MAAM,GAAG,GAAwB;YAC/B,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,oBAAc,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;YACnF,gBAAgB,EAAE,KAAK,CAAC,UAAU;YAClC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,WAAW,EAAE,SAAS;SACvB,CAAA;QACD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;;AA3BH,oCA4BC;AAED,MAAa,mBAAoB,SAAQ,YAAY;IACnD,MAAM,CAAC,eAAe,GAAmB;QACvC,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;KAC3B,CAAA;IAED,MAAM,CAAC,QAAQ,CAAC,SAAkB,EAAE,OAAwB;QAC1D,IAAI,SAAS,EAAE;YACb,CAAC;YAAA,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;SAC/B;aAAM;YACL,SAAS,GAAG,MAAM,CAAA;SACnB;QACD,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,SAAS,EAAE,EAAE,GAAG,mBAAmB,CAAC,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAC1G,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAClD,OAAO,OAAO,CAAA;IAChB,CAAC;;AAhBH,kDAiBC","sourcesContent":["import { BaseContext } from './context'\nimport { DataDescriptor, EventTrackingResult } from '@sentio/sdk'\n\nexport interface Event {\n // The unique identifier of main identity associate with an event\n // .e.g user id / toekn address / account address / contract address id\n //\n distinctId: string\n payload?: Record<string, string>\n}\n\nexport interface TrackerOptions {\n totalByDay?: boolean\n unique?: boolean\n distinctByDays?: number[]\n}\n\n// Track Event with an identity associate with it\nexport class EventTracker {\n static DEFAULT_OPTIONS: TrackerOptions = {\n totalByDay: true,\n unique: true,\n }\n\n static register(eventName: string, options?: TrackerOptions) {\n const tracker = new EventTracker(eventName, { ...EventTracker.DEFAULT_OPTIONS, ...options })\n global.PROCESSOR_STATE.eventTrackers.push(tracker)\n return tracker\n }\n\n eventName: string\n options: TrackerOptions\n protected constructor(eventName: string, options: TrackerOptions) {\n this.eventName = eventName\n this.options = options\n }\n\n trackEvent(ctx: BaseContext, event: Event) {\n const res: EventTrackingResult = {\n metadata: ctx.getMetaData(DataDescriptor.fromPartial({ name: this.eventName }), {}),\n distinctEntityId: event.distinctId,\n attributes: JSON.stringify({}),\n runtimeInfo: undefined,\n }\n ctx.events.push(res)\n }\n}\n\nexport class AccountEventTracker extends EventTracker {\n static DEFAULT_OPTIONS: TrackerOptions = {\n totalByDay: true,\n unique: true,\n distinctByDays: [1, 7, 30],\n }\n\n static register(eventName?: string, options?: TrackerOptions) {\n if (eventName) {\n ;['user', eventName].join('.')\n } else {\n eventName = 'user'\n }\n const tracker = new AccountEventTracker(eventName, { ...AccountEventTracker.DEFAULT_OPTIONS, ...options })\n global.PROCESSOR_STATE.eventTrackers.push(tracker)\n return tracker\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  export { BigDecimal } from './big-decimal';
2
2
  export { ContractContext, ContractView, BoundContractView, SolanaContext } from './context';
3
3
  export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOptions } from './meter';
4
+ export { EventTracker, AccountEventTracker } from './event-tracker';
4
5
  export { type Numberish, toBigInteger, toMetricValue } from './numberish';
5
6
  export { BindOptions, SolanaBindOptions } from './bind-options';
6
7
  export { BaseProcessor } from './base-processor';
package/lib/core/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SuiBindOptions = exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.SolanaBindOptions = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.MetricDescriptorOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
3
+ exports.SuiBindOptions = exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.SolanaBindOptions = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.AccountEventTracker = exports.EventTracker = exports.MetricDescriptorOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
4
4
  var big_decimal_1 = require("./big-decimal");
5
5
  Object.defineProperty(exports, "BigDecimal", { enumerable: true, get: function () { return big_decimal_1.BigDecimal; } });
6
6
  var context_1 = require("./context");
@@ -15,6 +15,9 @@ Object.defineProperty(exports, "GaugeBinding", { enumerable: true, get: function
15
15
  Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return meter_1.Counter; } });
16
16
  Object.defineProperty(exports, "Gauge", { enumerable: true, get: function () { return meter_1.Gauge; } });
17
17
  Object.defineProperty(exports, "MetricDescriptorOptions", { enumerable: true, get: function () { return meter_1.MetricDescriptorOptions; } });
18
+ var event_tracker_1 = require("./event-tracker");
19
+ Object.defineProperty(exports, "EventTracker", { enumerable: true, get: function () { return event_tracker_1.EventTracker; } });
20
+ Object.defineProperty(exports, "AccountEventTracker", { enumerable: true, get: function () { return event_tracker_1.AccountEventTracker; } });
18
21
  var numberish_1 = require("./numberish");
19
22
  Object.defineProperty(exports, "toBigInteger", { enumerable: true, get: function () { return numberish_1.toBigInteger; } });
20
23
  Object.defineProperty(exports, "toMetricValue", { enumerable: true, get: function () { return numberish_1.toMetricValue; } });