@sentio/sdk 1.35.1-rc.2 → 1.36.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/lib/aptos-codegen/codegen.d.ts +1 -0
  2. package/lib/aptos-codegen/codegen.js +9 -1
  3. package/lib/aptos-codegen/codegen.js.map +1 -1
  4. package/lib/solana-codegen/codegen.d.ts +1 -0
  5. package/lib/{cli/build.js → solana-codegen/codegen.js} +3 -92
  6. package/lib/solana-codegen/codegen.js.map +1 -0
  7. package/lib/test-abi-code-gen.js +4 -3
  8. package/lib/test-abi-code-gen.js.map +1 -1
  9. package/package.json +3 -11
  10. package/src/aptos-codegen/codegen.ts +8 -0
  11. package/src/{cli/build.ts → solana-codegen/codegen.ts} +1 -113
  12. package/src/test-abi-code-gen.ts +2 -1
  13. package/lib/cli/build.d.ts +0 -4
  14. package/lib/cli/build.js.map +0 -1
  15. package/lib/cli/cli.d.ts +0 -2
  16. package/lib/cli/cli.js +0 -186
  17. package/lib/cli/cli.js.map +0 -1
  18. package/lib/cli/commands/login-server.d.ts +0 -7
  19. package/lib/cli/commands/login-server.js +0 -133
  20. package/lib/cli/commands/login-server.js.map +0 -1
  21. package/lib/cli/commands/run-create.d.ts +0 -1
  22. package/lib/cli/commands/run-create.js +0 -111
  23. package/lib/cli/commands/run-create.js.map +0 -1
  24. package/lib/cli/commands/run-login.d.ts +0 -1
  25. package/lib/cli/commands/run-login.js +0 -136
  26. package/lib/cli/commands/run-login.js.map +0 -1
  27. package/lib/cli/commands/run-version.d.ts +0 -1
  28. package/lib/cli/commands/run-version.js +0 -39
  29. package/lib/cli/commands/run-version.js.map +0 -1
  30. package/lib/cli/config.d.ts +0 -14
  31. package/lib/cli/config.js +0 -64
  32. package/lib/cli/config.js.map +0 -1
  33. package/lib/cli/key.d.ts +0 -2
  34. package/lib/cli/key.js +0 -44
  35. package/lib/cli/key.js.map +0 -1
  36. package/lib/cli/upload.d.ts +0 -2
  37. package/lib/cli/upload.js +0 -189
  38. package/lib/cli/upload.js.map +0 -1
  39. package/lib/cli/utils.d.ts +0 -1
  40. package/lib/cli/utils.js +0 -16
  41. package/lib/cli/utils.js.map +0 -1
  42. package/lib/cli/webpack.config.js +0 -47
  43. package/src/cli/cli.ts +0 -184
  44. package/src/cli/commands/login-server.ts +0 -119
  45. package/src/cli/commands/run-create.ts +0 -115
  46. package/src/cli/commands/run-login.ts +0 -111
  47. package/src/cli/commands/run-version.ts +0 -32
  48. package/src/cli/config.ts +0 -72
  49. package/src/cli/key.ts +0 -43
  50. package/src/cli/upload.ts +0 -214
  51. package/src/cli/utils.ts +0 -10
  52. package/src/cli/webpack.config.js +0 -47
  53. package/templates/aptos/abis/aptos/souffle.json +0 -389
  54. package/templates/aptos/jest.config.js +0 -7
  55. package/templates/aptos/package.json +0 -20
  56. package/templates/aptos/sentio.yaml +0 -1
  57. package/templates/aptos/src/processor.ts +0 -13
  58. package/templates/aptos/tsconfig.json +0 -20
  59. package/templates/evm/abis/evm/x2y2.json +0 -296
  60. package/templates/evm/jest.config.js +0 -7
  61. package/templates/evm/package.json +0 -20
  62. package/templates/evm/sentio.yaml +0 -3
  63. package/templates/evm/src/processor.ts +0 -29
  64. package/templates/evm/tsconfig.json +0 -20
  65. package/templates/raw/jest.config.js +0 -7
  66. package/templates/raw/package.json +0 -20
  67. package/templates/raw/sentio.yaml +0 -3
  68. package/templates/raw/src/processor.ts +0 -0
  69. package/templates/raw/tsconfig.json +0 -20
  70. package/templates/raw/yarn.lock +0 -4095
package/src/cli/upload.ts DELETED
@@ -1,214 +0,0 @@
1
- import { execSync } from 'child_process'
2
- import { createHash } from 'crypto'
3
- import fs from 'fs'
4
- import readline from 'readline'
5
- import { SentioProjectConfig } from './config'
6
- import { ReadKey } from './key'
7
- import path from 'path'
8
- import chalk from 'chalk'
9
- import { buildProcessor } from './build'
10
- import fetch from 'node-fetch'
11
- import { getCliVersion } from './utils'
12
- import { URL } from 'url'
13
-
14
- async function createProject(options: SentioProjectConfig, apiKey: string) {
15
- const url = new URL('/api/v1/projects', options.host)
16
- const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]
17
- return fetch(url, {
18
- method: 'POST',
19
- headers: {
20
- 'api-key': apiKey,
21
- },
22
- body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),
23
- })
24
- }
25
-
26
- export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {
27
- if (options.build) {
28
- await buildProcessor(false)
29
- }
30
-
31
- console.log(chalk.blue('Prepare to upload'))
32
-
33
- const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')
34
-
35
- const apiKey = apiKeyOverride || ReadKey(options.host)
36
-
37
- const isProd = options.host === 'https://app.sentio.xyz'
38
- if (!apiKey) {
39
- const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host
40
- console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))
41
- process.exit(1)
42
- }
43
-
44
- if (!fs.existsSync(PROCESSOR_FILE)) {
45
- console.error(chalk.red('File not existed ', PROCESSOR_FILE, "don't use --nobuild"))
46
- process.exit(1)
47
- }
48
-
49
- const stat = fs.statSync(PROCESSOR_FILE)
50
- console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)
51
- const content = fs.readFileSync(PROCESSOR_FILE)
52
- const hash = createHash('sha256')
53
- hash.update(content)
54
- const digest = hash.digest('hex')
55
-
56
- let triedCount = 0
57
- const upload = async () => {
58
- let commitSha = ''
59
- let gitUrl = ''
60
- const sha256 = digest
61
- try {
62
- commitSha = execSync('git rev-parse HEAD').toString().trim()
63
- } catch (e) {
64
- chalk.yellow(e)
65
- }
66
- try {
67
- gitUrl = execSync('git remote get-url origin').toString().trim()
68
- } catch (e) {
69
- // skip errors
70
- }
71
- console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))
72
-
73
- // get gcs upload url
74
- const initUploadResRaw = await initUpload(options.host, apiKey, options.project, getCliVersion())
75
- if (!initUploadResRaw.ok) {
76
- console.error(chalk.red('Failed to get upload url'))
77
- console.error(chalk.red((await initUploadResRaw.json()).message))
78
-
79
- if (initUploadResRaw.status === 404) {
80
- // create project if not exist
81
- const rl = readline.createInterface({
82
- input: process.stdin,
83
- output: process.stdout,
84
- })
85
- const prompt = async () => {
86
- const answer: string = await new Promise((resolve) =>
87
- rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)
88
- )
89
- if (['y', 'yes'].includes(answer.toLowerCase())) {
90
- rl.close()
91
- const res = await createProject(options, apiKey)
92
- if (!res.ok) {
93
- console.error(chalk.red('Create Project Failed'))
94
- console.error(chalk.red((await res.json()).message))
95
- return
96
- }
97
- console.log(chalk.green('Project created'))
98
- await upload()
99
- } else if (['n', 'no'].includes(answer.toLowerCase())) {
100
- rl.close()
101
- } else {
102
- await prompt()
103
- }
104
- }
105
- await prompt()
106
- }
107
- return
108
- }
109
- const initUploadRes = await initUploadResRaw.json()
110
- const uploadUrl = initUploadRes['url'] as string
111
-
112
- // do actual uploading
113
- const file = fs.createReadStream(PROCESSOR_FILE)
114
- const uploadResRaw = await fetch(uploadUrl, {
115
- method: 'PUT',
116
- headers: {
117
- 'Content-Type': 'application/octet-stream',
118
- },
119
- body: file,
120
- })
121
- if (!uploadResRaw.ok) {
122
- console.error(chalk.red('Failed to upload'))
123
- console.error(chalk.red(await uploadResRaw.text()))
124
- return
125
- }
126
-
127
- // finish uploading
128
- const finishUploadResRaw = await finishUpload(
129
- options.host,
130
- apiKey,
131
- options.project,
132
- getCliVersion(),
133
- sha256,
134
- commitSha,
135
- gitUrl,
136
- options.debug
137
- )
138
- if (!finishUploadResRaw.ok) {
139
- console.error(chalk.red('Failed to finish uploading'))
140
- console.error(chalk.red(await finishUploadResRaw.text()))
141
- return
142
- }
143
-
144
- console.log(chalk.green('Upload success: '))
145
- console.log('\t', chalk.blue('sha256:'), digest)
146
- if (commitSha) {
147
- console.log('\t', chalk.blue('Git commit SHA:'), commitSha)
148
- }
149
- const { projectFullSlug } = await finishUploadResRaw.json()
150
- console.log('\t', chalk.blue('Check status:'), `${options.host}/${projectFullSlug}/datasource`)
151
- }
152
-
153
- let error: Error
154
- const tryUploading = async () => {
155
- if (triedCount++ >= 5) {
156
- console.error(error)
157
- return
158
- }
159
- try {
160
- await upload()
161
- } catch (e) {
162
- if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {
163
- error = e
164
- await new Promise((resolve) => setTimeout(resolve, 1000))
165
- await tryUploading()
166
- } else {
167
- console.error(e)
168
- }
169
- }
170
- }
171
-
172
- await tryUploading()
173
- }
174
-
175
- async function initUpload(host: string, apiKey: string, projectSlug: string, sdkVersion: string) {
176
- const initUploadUrl = new URL(`/api/v1/processors/init_upload`, host)
177
- return fetch(initUploadUrl, {
178
- method: 'POST',
179
- headers: {
180
- 'api-key': apiKey,
181
- },
182
- body: JSON.stringify({
183
- project_slug: projectSlug,
184
- sdk_version: sdkVersion,
185
- }),
186
- })
187
- }
188
-
189
- async function finishUpload(
190
- host: string,
191
- apiKey: string,
192
- projectSlug: string,
193
- sdkVersion: string,
194
- sha256: string,
195
- commitSha: string,
196
- gitUrl: string,
197
- debug: boolean
198
- ) {
199
- const finishUploadUrl = new URL(`/api/v1/processors/finish_upload`, host)
200
- return fetch(finishUploadUrl, {
201
- method: 'POST',
202
- headers: {
203
- 'api-key': apiKey,
204
- },
205
- body: JSON.stringify({
206
- project_slug: projectSlug,
207
- sdk_version: sdkVersion,
208
- sha256: sha256,
209
- commit_sha: commitSha,
210
- git_url: gitUrl,
211
- debug: debug,
212
- }),
213
- })
214
- }
package/src/cli/utils.ts DELETED
@@ -1,10 +0,0 @@
1
- import fs from 'fs-extra'
2
- import path from 'path'
3
-
4
- export function getCliVersion() {
5
- const packageJsonPath = path.resolve(__dirname, '../../package.json')
6
- const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf-8')
7
- const packageJson = JSON.parse(packageJsonContent)
8
-
9
- return packageJson.version
10
- }
@@ -1,47 +0,0 @@
1
- /* eslint-disable */
2
- const path = require('path')
3
-
4
- module.exports = {
5
- entry: {
6
- lib: './src/processor.ts',
7
- },
8
- devtool: 'inline-source-map',
9
- module: {
10
- rules: [
11
- {
12
- test: /\.tsx?$/,
13
- use: 'ts-loader',
14
- exclude: /node_modules/,
15
- },
16
- ],
17
- },
18
- resolve: {
19
- extensions: ['.ts', '.js'],
20
- },
21
- output: {
22
- filename: '[name].js',
23
- path: path.resolve(process.cwd(), 'dist'),
24
- },
25
- target: 'node',
26
- mode: 'production',
27
- externals: [
28
- {
29
- protobufjs: 'commonjs2 protobufjs',
30
- aptos: 'commonjs2 aptos-sdk',
31
- ethers: 'commonjs2 ethers',
32
- bs58: 'commonjs2 bs58',
33
- "bignumber.js": 'commonjs2 bignumber.js',
34
- 'bn.js': 'commonjs2 bn.js',
35
- 'csv-parse': 'commonjs2 csv-parse',
36
- },
37
- function ({ context, request }, callback) {
38
- if (/^@(ethersproject|solana|project-serum|nice-grpc).*$/.test(request)) {
39
- return callback(null, 'commonjs ' + request)
40
- }
41
- if (request.startsWith("@sentio/sdk")) {
42
- return callback(null, 'commonjs2 ' + request)
43
- }
44
- callback()
45
- },
46
- ],
47
- }