@haneullabs/mvr-static 0.1.0 → 0.3.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.
- package/CHANGELOG.md +74 -44
- package/README.md +16 -13
- package/bin/parser.js +2 -1
- package/dist/execute.d.mts +1 -0
- package/dist/execute.mjs +8 -0
- package/dist/execute.mjs.map +1 -0
- package/dist/parsing.mjs +230 -0
- package/dist/parsing.mjs.map +1 -0
- package/package.json +24 -19
- package/src/parsing.ts +5 -5
- package/dist/execute.d.ts +0 -1
- package/dist/execute.js +0 -7
- package/dist/execute.js.map +0 -1
- package/dist/parsing.d.ts +0 -23
- package/dist/parsing.js +0 -257
- package/dist/parsing.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,44 +1,74 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @mysten/mvr-static
|
|
2
|
+
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 99d1e00: Add default export condition
|
|
8
|
+
- Updated dependencies [99d1e00]
|
|
9
|
+
- @mysten/sui@2.3.2
|
|
10
|
+
|
|
11
|
+
## 0.3.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- e00788c: Update to @mysten/sui@2.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [e00788c]
|
|
20
|
+
- Updated dependencies [e00788c]
|
|
21
|
+
- Updated dependencies [e00788c]
|
|
22
|
+
- Updated dependencies [e00788c]
|
|
23
|
+
- Updated dependencies [e00788c]
|
|
24
|
+
- Updated dependencies [e00788c]
|
|
25
|
+
- Updated dependencies [e00788c]
|
|
26
|
+
- Updated dependencies [e00788c]
|
|
27
|
+
- Updated dependencies [e00788c]
|
|
28
|
+
- Updated dependencies [e00788c]
|
|
29
|
+
- Updated dependencies [e00788c]
|
|
30
|
+
- Updated dependencies [e00788c]
|
|
31
|
+
- @mysten/sui@2.0.0
|
|
2
32
|
|
|
3
33
|
## 0.2.12
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
6
36
|
|
|
7
37
|
- Updated dependencies [29e8b92]
|
|
8
|
-
- @
|
|
38
|
+
- @mysten/sui@1.45.2
|
|
9
39
|
|
|
10
40
|
## 0.2.11
|
|
11
41
|
|
|
12
42
|
### Patch Changes
|
|
13
43
|
|
|
14
44
|
- Updated dependencies [e3811f1]
|
|
15
|
-
- @
|
|
45
|
+
- @mysten/sui@1.45.1
|
|
16
46
|
|
|
17
47
|
## 0.2.10
|
|
18
48
|
|
|
19
49
|
### Patch Changes
|
|
20
50
|
|
|
21
51
|
- Updated dependencies [88bdbac]
|
|
22
|
-
- @
|
|
52
|
+
- @mysten/sui@1.45.0
|
|
23
53
|
|
|
24
54
|
## 0.2.9
|
|
25
55
|
|
|
26
56
|
### Patch Changes
|
|
27
57
|
|
|
28
58
|
- Updated dependencies [44d9b4f]
|
|
29
|
-
- @
|
|
59
|
+
- @mysten/sui@1.44.0
|
|
30
60
|
|
|
31
61
|
## 0.2.8
|
|
32
62
|
|
|
33
63
|
### Patch Changes
|
|
34
64
|
|
|
35
|
-
- @
|
|
65
|
+
- @mysten/sui@1.43.2
|
|
36
66
|
|
|
37
67
|
## 0.2.7
|
|
38
68
|
|
|
39
69
|
### Patch Changes
|
|
40
70
|
|
|
41
|
-
- @
|
|
71
|
+
- @mysten/sui@1.43.1
|
|
42
72
|
|
|
43
73
|
## 0.2.6
|
|
44
74
|
|
|
@@ -46,14 +76,14 @@
|
|
|
46
76
|
|
|
47
77
|
- Updated dependencies [f3b19a7]
|
|
48
78
|
- Updated dependencies [bf9f85c]
|
|
49
|
-
- @
|
|
79
|
+
- @mysten/sui@1.43.0
|
|
50
80
|
|
|
51
81
|
## 0.2.5
|
|
52
82
|
|
|
53
83
|
### Patch Changes
|
|
54
84
|
|
|
55
85
|
- Updated dependencies [98c8a27]
|
|
56
|
-
- @
|
|
86
|
+
- @mysten/sui@1.42.0
|
|
57
87
|
|
|
58
88
|
## 0.2.4
|
|
59
89
|
|
|
@@ -61,21 +91,21 @@
|
|
|
61
91
|
|
|
62
92
|
- Updated dependencies [d554cd2]
|
|
63
93
|
- Updated dependencies [04fcfbc]
|
|
64
|
-
- @
|
|
94
|
+
- @mysten/sui@1.41.0
|
|
65
95
|
|
|
66
96
|
## 0.2.3
|
|
67
97
|
|
|
68
98
|
### Patch Changes
|
|
69
99
|
|
|
70
100
|
- Updated dependencies [f5fc0c0]
|
|
71
|
-
- @
|
|
101
|
+
- @mysten/sui@1.40.0
|
|
72
102
|
|
|
73
103
|
## 0.2.2
|
|
74
104
|
|
|
75
105
|
### Patch Changes
|
|
76
106
|
|
|
77
107
|
- Updated dependencies [a9f9035]
|
|
78
|
-
- @
|
|
108
|
+
- @mysten/sui@1.39.1
|
|
79
109
|
|
|
80
110
|
## 0.2.1
|
|
81
111
|
|
|
@@ -83,7 +113,7 @@
|
|
|
83
113
|
|
|
84
114
|
- Updated dependencies [ca92487]
|
|
85
115
|
- Updated dependencies [5ab3c0a]
|
|
86
|
-
- @
|
|
116
|
+
- @mysten/sui@1.39.0
|
|
87
117
|
|
|
88
118
|
## 0.2.0
|
|
89
119
|
|
|
@@ -95,7 +125,7 @@
|
|
|
95
125
|
|
|
96
126
|
- Updated dependencies [3c1741f]
|
|
97
127
|
- Updated dependencies [ea1ac70]
|
|
98
|
-
- @
|
|
128
|
+
- @mysten/sui@1.38.0
|
|
99
129
|
|
|
100
130
|
## 0.1.31
|
|
101
131
|
|
|
@@ -103,62 +133,62 @@
|
|
|
103
133
|
|
|
104
134
|
- Updated dependencies [c689b98]
|
|
105
135
|
- Updated dependencies [5b9ff1a]
|
|
106
|
-
- @
|
|
136
|
+
- @mysten/sui@1.37.6
|
|
107
137
|
|
|
108
138
|
## 0.1.30
|
|
109
139
|
|
|
110
140
|
### Patch Changes
|
|
111
141
|
|
|
112
142
|
- Updated dependencies [3980d04]
|
|
113
|
-
- @
|
|
143
|
+
- @mysten/sui@1.37.5
|
|
114
144
|
|
|
115
145
|
## 0.1.29
|
|
116
146
|
|
|
117
147
|
### Patch Changes
|
|
118
148
|
|
|
119
149
|
- Updated dependencies [6b03e57]
|
|
120
|
-
- @
|
|
150
|
+
- @mysten/sui@1.37.4
|
|
121
151
|
|
|
122
152
|
## 0.1.28
|
|
123
153
|
|
|
124
154
|
### Patch Changes
|
|
125
155
|
|
|
126
156
|
- Updated dependencies [8ff1471]
|
|
127
|
-
- @
|
|
157
|
+
- @mysten/sui@1.37.3
|
|
128
158
|
|
|
129
159
|
## 0.1.27
|
|
130
160
|
|
|
131
161
|
### Patch Changes
|
|
132
162
|
|
|
133
163
|
- Updated dependencies [660377c]
|
|
134
|
-
- @
|
|
164
|
+
- @mysten/sui@1.37.2
|
|
135
165
|
|
|
136
166
|
## 0.1.26
|
|
137
167
|
|
|
138
168
|
### Patch Changes
|
|
139
169
|
|
|
140
|
-
- @
|
|
170
|
+
- @mysten/sui@1.37.1
|
|
141
171
|
|
|
142
172
|
## 0.1.25
|
|
143
173
|
|
|
144
174
|
### Patch Changes
|
|
145
175
|
|
|
146
176
|
- Updated dependencies [72168f0]
|
|
147
|
-
- @
|
|
177
|
+
- @mysten/sui@1.37.0
|
|
148
178
|
|
|
149
179
|
## 0.1.24
|
|
150
180
|
|
|
151
181
|
### Patch Changes
|
|
152
182
|
|
|
153
183
|
- Updated dependencies [44354ab]
|
|
154
|
-
- @
|
|
184
|
+
- @mysten/sui@1.36.2
|
|
155
185
|
|
|
156
186
|
## 0.1.23
|
|
157
187
|
|
|
158
188
|
### Patch Changes
|
|
159
189
|
|
|
160
190
|
- Updated dependencies [c76ddc5]
|
|
161
|
-
- @
|
|
191
|
+
- @mysten/sui@1.36.1
|
|
162
192
|
|
|
163
193
|
## 0.1.22
|
|
164
194
|
|
|
@@ -167,35 +197,35 @@
|
|
|
167
197
|
- Updated dependencies [783bb9e]
|
|
168
198
|
- Updated dependencies [783bb9e]
|
|
169
199
|
- Updated dependencies [5cbbb21]
|
|
170
|
-
- @
|
|
200
|
+
- @mysten/sui@1.36.0
|
|
171
201
|
|
|
172
202
|
## 0.1.21
|
|
173
203
|
|
|
174
204
|
### Patch Changes
|
|
175
205
|
|
|
176
206
|
- Updated dependencies [888afe6]
|
|
177
|
-
- @
|
|
207
|
+
- @mysten/sui@1.35.0
|
|
178
208
|
|
|
179
209
|
## 0.1.20
|
|
180
210
|
|
|
181
211
|
### Patch Changes
|
|
182
212
|
|
|
183
213
|
- Updated dependencies [3fb7a83]
|
|
184
|
-
- @
|
|
214
|
+
- @mysten/sui@1.34.0
|
|
185
215
|
|
|
186
216
|
## 0.1.19
|
|
187
217
|
|
|
188
218
|
### Patch Changes
|
|
189
219
|
|
|
190
220
|
- Updated dependencies [a00522b]
|
|
191
|
-
- @
|
|
221
|
+
- @mysten/sui@1.33.0
|
|
192
222
|
|
|
193
223
|
## 0.1.18
|
|
194
224
|
|
|
195
225
|
### Patch Changes
|
|
196
226
|
|
|
197
227
|
- Updated dependencies [6b7deb8]
|
|
198
|
-
- @
|
|
228
|
+
- @mysten/sui@1.32.0
|
|
199
229
|
|
|
200
230
|
## 0.1.17
|
|
201
231
|
|
|
@@ -204,14 +234,14 @@
|
|
|
204
234
|
- Updated dependencies [1ff4e57]
|
|
205
235
|
- Updated dependencies [550e2e3]
|
|
206
236
|
- Updated dependencies [550e2e3]
|
|
207
|
-
- @
|
|
237
|
+
- @mysten/sui@1.31.0
|
|
208
238
|
|
|
209
239
|
## 0.1.16
|
|
210
240
|
|
|
211
241
|
### Patch Changes
|
|
212
242
|
|
|
213
243
|
- Updated dependencies [5bd6ca3]
|
|
214
|
-
- @
|
|
244
|
+
- @mysten/sui@1.30.5
|
|
215
245
|
|
|
216
246
|
## 0.1.15
|
|
217
247
|
|
|
@@ -219,7 +249,7 @@
|
|
|
219
249
|
|
|
220
250
|
- Updated dependencies [5dce590]
|
|
221
251
|
- Updated dependencies [4a5aef6]
|
|
222
|
-
- @
|
|
252
|
+
- @mysten/sui@1.30.4
|
|
223
253
|
|
|
224
254
|
## 0.1.14
|
|
225
255
|
|
|
@@ -228,21 +258,21 @@
|
|
|
228
258
|
- bb7c03a: Update dependencies
|
|
229
259
|
- Updated dependencies [4457f10]
|
|
230
260
|
- Updated dependencies [bb7c03a]
|
|
231
|
-
- @
|
|
261
|
+
- @mysten/sui@1.30.3
|
|
232
262
|
|
|
233
263
|
## 0.1.13
|
|
234
264
|
|
|
235
265
|
### Patch Changes
|
|
236
266
|
|
|
237
267
|
- Updated dependencies [b265f7e]
|
|
238
|
-
- @
|
|
268
|
+
- @mysten/sui@1.30.2
|
|
239
269
|
|
|
240
270
|
## 0.1.12
|
|
241
271
|
|
|
242
272
|
### Patch Changes
|
|
243
273
|
|
|
244
274
|
- Updated dependencies [ec519fc]
|
|
245
|
-
- @
|
|
275
|
+
- @mysten/sui@1.30.1
|
|
246
276
|
|
|
247
277
|
## 0.1.11
|
|
248
278
|
|
|
@@ -254,13 +284,13 @@
|
|
|
254
284
|
- Updated dependencies [2456052]
|
|
255
285
|
- Updated dependencies [2456052]
|
|
256
286
|
- Updated dependencies [2456052]
|
|
257
|
-
- @
|
|
287
|
+
- @mysten/sui@1.30.0
|
|
258
288
|
|
|
259
289
|
## 0.1.10
|
|
260
290
|
|
|
261
291
|
### Patch Changes
|
|
262
292
|
|
|
263
|
-
- @
|
|
293
|
+
- @mysten/sui@1.29.1
|
|
264
294
|
|
|
265
295
|
## 0.1.9
|
|
266
296
|
|
|
@@ -269,35 +299,35 @@
|
|
|
269
299
|
- Updated dependencies [7d66a32]
|
|
270
300
|
- Updated dependencies [eb91fba]
|
|
271
301
|
- Updated dependencies [19a8045]
|
|
272
|
-
- @
|
|
302
|
+
- @mysten/sui@1.29.0
|
|
273
303
|
|
|
274
304
|
## 0.1.8
|
|
275
305
|
|
|
276
306
|
### Patch Changes
|
|
277
307
|
|
|
278
308
|
- Updated dependencies [9a94aea]
|
|
279
|
-
- @
|
|
309
|
+
- @mysten/sui@1.28.2
|
|
280
310
|
|
|
281
311
|
## 0.1.7
|
|
282
312
|
|
|
283
313
|
### Patch Changes
|
|
284
314
|
|
|
285
315
|
- Updated dependencies [3cd4e53]
|
|
286
|
-
- @
|
|
316
|
+
- @mysten/sui@1.28.1
|
|
287
317
|
|
|
288
318
|
## 0.1.6
|
|
289
319
|
|
|
290
320
|
### Patch Changes
|
|
291
321
|
|
|
292
322
|
- Updated dependencies [2705dc8]
|
|
293
|
-
- @
|
|
323
|
+
- @mysten/sui@1.28.0
|
|
294
324
|
|
|
295
325
|
## 0.1.5
|
|
296
326
|
|
|
297
327
|
### Patch Changes
|
|
298
328
|
|
|
299
329
|
- Updated dependencies [5cea435]
|
|
300
|
-
- @
|
|
330
|
+
- @mysten/sui@1.27.1
|
|
301
331
|
|
|
302
332
|
## 0.1.4
|
|
303
333
|
|
|
@@ -305,7 +335,7 @@
|
|
|
305
335
|
|
|
306
336
|
- Updated dependencies [4d13ef8]
|
|
307
337
|
- Updated dependencies [4d13ef8]
|
|
308
|
-
- @
|
|
338
|
+
- @mysten/sui@1.27.0
|
|
309
339
|
|
|
310
340
|
## 0.1.3
|
|
311
341
|
|
|
@@ -313,14 +343,14 @@
|
|
|
313
343
|
|
|
314
344
|
- 7ba32a4: update dependencies
|
|
315
345
|
- Updated dependencies [7ba32a4]
|
|
316
|
-
- @
|
|
346
|
+
- @mysten/sui@1.26.1
|
|
317
347
|
|
|
318
348
|
## 0.1.2
|
|
319
349
|
|
|
320
350
|
### Patch Changes
|
|
321
351
|
|
|
322
352
|
- Updated dependencies [906dd14]
|
|
323
|
-
- @
|
|
353
|
+
- @mysten/sui@1.26.0
|
|
324
354
|
|
|
325
355
|
## 0.1.1
|
|
326
356
|
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# mvr-static
|
|
2
2
|
|
|
3
3
|
The mvr-static tool is a typescript CLI tool to generate a static file for Move Registry (mvr)
|
|
4
|
-
resolution. This can be used to cache all MVR names for performance & security reasons, and used
|
|
5
|
-
the
|
|
4
|
+
resolution. This can be used to cache all MVR names for performance & security reasons, and used
|
|
5
|
+
with the Haneul client's built-in MVR support.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
@@ -20,9 +20,9 @@ Available options:
|
|
|
20
20
|
- `--output <file-name>`: The output's file name (defaults to `mvr.ts`)
|
|
21
21
|
- `--depth <depth>`: The depth of recursive search for MVR names (defaults to `10`)
|
|
22
22
|
- `--url-mainnet <url>`: The URL to the mainnet MVR (defaults to
|
|
23
|
-
`https://mainnet.mvr.
|
|
23
|
+
`https://mainnet.mvr.haneul-labs.com`)
|
|
24
24
|
- `--url-testnet <url>`: The URL to the testnet MVR (defaults to
|
|
25
|
-
`https://testnet.mvr.
|
|
25
|
+
`https://testnet.mvr.haneul-labs.com`)
|
|
26
26
|
- `--include <dir_patterns>`: The directory patterns to include in the search (defaults to
|
|
27
27
|
`**/*.{js,ts,jsx,tsx,mjs,cjs}`)
|
|
28
28
|
- `--exclude <dir_patterns>`: The directory patterns to exclude in the search (defaults to
|
|
@@ -32,18 +32,21 @@ Available options:
|
|
|
32
32
|
### Use the static file in your project
|
|
33
33
|
|
|
34
34
|
Once you have your static file, you can use it in your project by importing it and passing it to the
|
|
35
|
-
|
|
35
|
+
Haneul client initialization. MVR resolution is now built into the core client.
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
|
-
import {
|
|
39
|
-
|
|
38
|
+
import { SuiGrpcClient } from '@haneullabs/haneul/grpc';
|
|
40
39
|
import { getMvrCache } from './mvr.ts';
|
|
41
40
|
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
// Create a gRPC client with MVR overrides for your network
|
|
42
|
+
const client = new SuiGrpcClient({
|
|
43
|
+
network: 'mainnet',
|
|
44
|
+
baseUrl: 'https://fullnode.mainnet.haneul.io:443',
|
|
45
|
+
mvr: {
|
|
46
|
+
overrides: getMvrCache('mainnet'),
|
|
47
|
+
},
|
|
48
48
|
});
|
|
49
49
|
```
|
|
50
|
+
|
|
51
|
+
The client will now use your pre-resolved MVR names instead of making API calls, which improves
|
|
52
|
+
performance and security.
|
package/bin/parser.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/execute.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.mjs","names":[],"sources":["../src/execute.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { parser } from './parsing.js';\n\nparser();\n"],"mappings":";;;AAIA,QAAQ"}
|
package/dist/parsing.mjs
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { readFile } from "fs/promises";
|
|
3
|
+
import { dirname, extname, isAbsolute, join } from "path";
|
|
4
|
+
import { parseArgs } from "util";
|
|
5
|
+
import { isValidNamedPackage } from "@haneullabs/haneul/utils";
|
|
6
|
+
import { prompt } from "enquirer";
|
|
7
|
+
import { glob } from "glob";
|
|
8
|
+
import { format } from "prettier";
|
|
9
|
+
|
|
10
|
+
//#region src/parsing.ts
|
|
11
|
+
const TYPES_AND_TARGET_MATCHES = /[@a-zA-Z0-9/.-]+::[a-zA-Z0-9_]+::[a-zA-Z0-9_]+/g;
|
|
12
|
+
const MVR_NAME_MATCHES = /[@a-zA-Z0-9/.-]+::/g;
|
|
13
|
+
const DEFAULT_INCLUDE_PATTERNS = ["**/*.{js,ts,jsx,tsx,mjs,cjs}"];
|
|
14
|
+
const DEFAULT_EXCLUDE_PATTERNS = ["node_modules/**", "**/.*"];
|
|
15
|
+
const DEFAULT_FILE_NAME = `mvr.ts`;
|
|
16
|
+
const MAX_BATCH_SIZE = 25;
|
|
17
|
+
const MAINNET_API_URL = "https://mainnet.mvr.haneul-labs.com";
|
|
18
|
+
const TESTNET_API_URL = "https://testnet.mvr.haneul-labs.com";
|
|
19
|
+
const WARNING_MESSAGE = `/**
|
|
20
|
+
* This file is automatically generated by the mvr SDK.
|
|
21
|
+
* You can edit this file, but it will be overwritten on the next run.
|
|
22
|
+
* You should check this file in your version control system.
|
|
23
|
+
*
|
|
24
|
+
* Run this script before building your project to ensure that the mvr.ts file stays up to date.
|
|
25
|
+
*
|
|
26
|
+
* You can use this pre-built cache when initializing your Haneul client by calling
|
|
27
|
+
* \`getMvrCache("mainnet")\` or \`getMvrCache("testnet")\` and passing it as the \`overrides\` option.
|
|
28
|
+
*/
|
|
29
|
+
`;
|
|
30
|
+
const { values: args } = parseArgs({ options: {
|
|
31
|
+
directory: {
|
|
32
|
+
type: "string",
|
|
33
|
+
default: ".",
|
|
34
|
+
short: "d"
|
|
35
|
+
},
|
|
36
|
+
output: {
|
|
37
|
+
type: "string",
|
|
38
|
+
default: DEFAULT_FILE_NAME,
|
|
39
|
+
short: "o"
|
|
40
|
+
},
|
|
41
|
+
depth: {
|
|
42
|
+
type: "string",
|
|
43
|
+
default: "10",
|
|
44
|
+
short: "d"
|
|
45
|
+
},
|
|
46
|
+
"url-mainnet": {
|
|
47
|
+
type: "string",
|
|
48
|
+
default: MAINNET_API_URL
|
|
49
|
+
},
|
|
50
|
+
"url-testnet": {
|
|
51
|
+
type: "string",
|
|
52
|
+
default: TESTNET_API_URL
|
|
53
|
+
},
|
|
54
|
+
include: {
|
|
55
|
+
type: "string",
|
|
56
|
+
multiple: true,
|
|
57
|
+
default: DEFAULT_INCLUDE_PATTERNS,
|
|
58
|
+
short: "i"
|
|
59
|
+
},
|
|
60
|
+
exclude: {
|
|
61
|
+
type: "string",
|
|
62
|
+
multiple: true,
|
|
63
|
+
default: DEFAULT_EXCLUDE_PATTERNS,
|
|
64
|
+
short: "e"
|
|
65
|
+
},
|
|
66
|
+
force: {
|
|
67
|
+
type: "boolean",
|
|
68
|
+
default: false,
|
|
69
|
+
short: "f"
|
|
70
|
+
}
|
|
71
|
+
} });
|
|
72
|
+
async function parser() {
|
|
73
|
+
const path = isAbsolute(args.output) ? args.output : join(process.cwd(), args.output);
|
|
74
|
+
const dir = dirname(path);
|
|
75
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
76
|
+
if (!isSupportedFile(path)) throw new Error(`Unsupported file type: ${path}. Please use a .ts (or equivalent) file name for the output.`);
|
|
77
|
+
if (existsSync(path) && !args.force) {
|
|
78
|
+
const { overwrite } = await prompt({
|
|
79
|
+
type: "confirm",
|
|
80
|
+
name: "overwrite",
|
|
81
|
+
message: `The file ${path} already exists. Do you want to overwrite it?`
|
|
82
|
+
});
|
|
83
|
+
console.log(`Skipping generation of MVR file.`);
|
|
84
|
+
if (!overwrite) return process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
console.log(`Generating ${args.output}...`);
|
|
87
|
+
const { mainnet, testnet } = await crossNetworkResolution(await findNames({}));
|
|
88
|
+
await writeOutputFile(path, mainnet, testnet);
|
|
89
|
+
}
|
|
90
|
+
async function writeOutputFile(outDir, mainnet, testnet) {
|
|
91
|
+
writeFileSync(outDir, await format(`${WARNING_MESSAGE}
|
|
92
|
+
const mainnetResolution = ${JSON.stringify(mainnet, null, 2)}
|
|
93
|
+
const testnetResolution = ${JSON.stringify(testnet, null, 2)}
|
|
94
|
+
|
|
95
|
+
export function getMvrCache(network: 'mainnet' | 'testnet') {
|
|
96
|
+
return network === 'mainnet' ? mainnetResolution : testnetResolution;
|
|
97
|
+
}\n
|
|
98
|
+
`, { parser: "typescript" }), "utf8");
|
|
99
|
+
}
|
|
100
|
+
async function crossNetworkResolution(detectedNames) {
|
|
101
|
+
const packages = Array.from(detectedNames).filter((x) => !x.includes("::"));
|
|
102
|
+
const types = Array.from(detectedNames).filter((x) => x.includes("::"));
|
|
103
|
+
const [mainnetPackages, mainnetTypes, testnetPackages, testnetTypes] = await Promise.all([
|
|
104
|
+
resolvePackages(packages, args["url-mainnet"]),
|
|
105
|
+
resolveTypes(types, args["url-mainnet"]),
|
|
106
|
+
resolvePackages(packages, args["url-testnet"]),
|
|
107
|
+
resolveTypes(types, args["url-testnet"])
|
|
108
|
+
]);
|
|
109
|
+
return {
|
|
110
|
+
mainnet: {
|
|
111
|
+
packages: mainnetPackages,
|
|
112
|
+
types: mainnetTypes
|
|
113
|
+
},
|
|
114
|
+
testnet: {
|
|
115
|
+
packages: testnetPackages,
|
|
116
|
+
types: testnetTypes
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async function resolvePackages(packages, apiUrl) {
|
|
121
|
+
const batches = batch(packages, 50);
|
|
122
|
+
const results = {};
|
|
123
|
+
await Promise.all(batches.map(async (batch$1) => {
|
|
124
|
+
const response = await fetch(`${apiUrl}/v1/resolution/bulk`, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: { "Content-Type": "application/json" },
|
|
127
|
+
body: JSON.stringify({ names: batch$1 })
|
|
128
|
+
});
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
131
|
+
throw new Error(`Failed to resolve packages: ${errorBody?.message}`);
|
|
132
|
+
}
|
|
133
|
+
const data = await response.json();
|
|
134
|
+
if (!data?.resolution) return;
|
|
135
|
+
for (const pkg of Object.keys(data?.resolution)) {
|
|
136
|
+
const pkgData = data.resolution[pkg]?.package_id;
|
|
137
|
+
if (!pkgData) continue;
|
|
138
|
+
results[pkg] = pkgData;
|
|
139
|
+
}
|
|
140
|
+
}));
|
|
141
|
+
return results;
|
|
142
|
+
}
|
|
143
|
+
async function resolveTypes(types, apiUrl) {
|
|
144
|
+
const batches = batch(types, 50);
|
|
145
|
+
const results = {};
|
|
146
|
+
await Promise.all(batches.map(async (batch$1) => {
|
|
147
|
+
const response = await fetch(`${apiUrl}/v1/struct-definition/bulk`, {
|
|
148
|
+
method: "POST",
|
|
149
|
+
headers: { "Content-Type": "application/json" },
|
|
150
|
+
body: JSON.stringify({ types: batch$1 })
|
|
151
|
+
});
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
154
|
+
throw new Error(`Failed to resolve types: ${errorBody?.message}`);
|
|
155
|
+
}
|
|
156
|
+
const data = await response.json();
|
|
157
|
+
if (!data?.resolution) return;
|
|
158
|
+
for (const type of Object.keys(data?.resolution)) {
|
|
159
|
+
const typeData = data.resolution[type]?.type_tag;
|
|
160
|
+
if (!typeData) continue;
|
|
161
|
+
results[type] = typeData;
|
|
162
|
+
}
|
|
163
|
+
}));
|
|
164
|
+
return results;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Finds all the MVR names in the given directory.
|
|
168
|
+
* @param directory - The directory to search for MVR names.
|
|
169
|
+
* @returns A set of all the MVR names found in the directory.
|
|
170
|
+
*/
|
|
171
|
+
async function findNames({ directory = args.directory, include = args.include, exclude = args.exclude, depth = parseInt(args.depth), output = args.output }) {
|
|
172
|
+
const detectedNames = /* @__PURE__ */ new Set();
|
|
173
|
+
const excluded = [...exclude, output];
|
|
174
|
+
const batches = batch(glob.sync(include, {
|
|
175
|
+
ignore: excluded,
|
|
176
|
+
cwd: directory,
|
|
177
|
+
maxDepth: depth,
|
|
178
|
+
absolute: true
|
|
179
|
+
}));
|
|
180
|
+
for (const batch$1 of batches) await processFilesBatch(batch$1, detectedNames);
|
|
181
|
+
return detectedNames;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Finds all the MVR names in the given files.
|
|
185
|
+
*/
|
|
186
|
+
async function processFilesBatch(files, detectedNames) {
|
|
187
|
+
await Promise.all(files.map(async (file) => {
|
|
188
|
+
extractMvrNames(await readFile(file, "utf8")).forEach((name) => detectedNames.add(name));
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Extracts all the MVR names from the given file's data (content).
|
|
193
|
+
*/
|
|
194
|
+
function extractMvrNames(content) {
|
|
195
|
+
const relevantNames = /* @__PURE__ */ new Set();
|
|
196
|
+
[...content.matchAll(TYPES_AND_TARGET_MATCHES)].forEach((match) => {
|
|
197
|
+
const [pkg] = match[0].split("::");
|
|
198
|
+
if (!isValidNamedPackage(pkg)) return;
|
|
199
|
+
relevantNames.add(match[0]);
|
|
200
|
+
});
|
|
201
|
+
[...content.matchAll(MVR_NAME_MATCHES)].forEach((match) => {
|
|
202
|
+
const [pkg] = match[0].split("::");
|
|
203
|
+
if (!isValidNamedPackage(pkg)) return;
|
|
204
|
+
relevantNames.add(pkg);
|
|
205
|
+
});
|
|
206
|
+
return relevantNames;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Batch the given array into smaller arrays of the given size.
|
|
210
|
+
*/
|
|
211
|
+
function batch(array, batchSize = MAX_BATCH_SIZE) {
|
|
212
|
+
const result = [];
|
|
213
|
+
for (let i = 0; i < array.length; i += batchSize) result.push(array.slice(i, i + batchSize));
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
function isSupportedFile(filePath) {
|
|
217
|
+
const ext = extname(filePath).toLowerCase();
|
|
218
|
+
return [
|
|
219
|
+
".js",
|
|
220
|
+
".mjs",
|
|
221
|
+
".cjs",
|
|
222
|
+
".ts",
|
|
223
|
+
".mts",
|
|
224
|
+
".cts"
|
|
225
|
+
].includes(ext);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
//#endregion
|
|
229
|
+
export { parser };
|
|
230
|
+
//# sourceMappingURL=parsing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsing.mjs","names":["batch"],"sources":["../src/parsing.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport { dirname, extname, isAbsolute, join } from 'path';\nimport { parseArgs } from 'util';\nimport type { NamedPackagesOverrides } from '@haneullabs/haneul/client';\nimport { isValidNamedPackage } from '@haneullabs/haneul/utils';\nimport { prompt } from 'enquirer';\nimport { glob } from 'glob';\nimport { format } from 'prettier';\n\nconst TYPES_AND_TARGET_MATCHES = /[@a-zA-Z0-9/.-]+::[a-zA-Z0-9_]+::[a-zA-Z0-9_]+/g;\nconst MVR_NAME_MATCHES = /[@a-zA-Z0-9/.-]+::/g;\n\nconst DEFAULT_INCLUDE_PATTERNS = ['**/*.{js,ts,jsx,tsx,mjs,cjs}'];\nconst DEFAULT_EXCLUDE_PATTERNS = ['node_modules/**', '**/.*'];\nconst DEFAULT_FILE_NAME = `mvr.ts`;\n\nconst MAX_BATCH_SIZE = 25; // files to process per batch.\nconst MAINNET_API_URL = 'https://mainnet.mvr.haneul-labs.com';\nconst TESTNET_API_URL = 'https://testnet.mvr.haneul-labs.com';\n\nconst WARNING_MESSAGE = `/**\n * This file is automatically generated by the mvr SDK.\n * You can edit this file, but it will be overwritten on the next run.\n * You should check this file in your version control system.\n *\n * Run this script before building your project to ensure that the mvr.ts file stays up to date.\n *\n * You can use this pre-built cache when initializing your Haneul client by calling\n * \\`getMvrCache(\"mainnet\")\\` or \\`getMvrCache(\"testnet\")\\` and passing it as the \\`overrides\\` option.\n */\n`;\n\nconst { values: args } = parseArgs({\n\toptions: {\n\t\tdirectory: {\n\t\t\ttype: 'string',\n\t\t\tdefault: '.',\n\t\t\tshort: 'd',\n\t\t},\n\t\toutput: {\n\t\t\ttype: 'string',\n\t\t\tdefault: DEFAULT_FILE_NAME,\n\t\t\tshort: 'o',\n\t\t},\n\t\tdepth: {\n\t\t\ttype: 'string',\n\t\t\tdefault: '10',\n\t\t\tshort: 'd',\n\t\t},\n\t\t'url-mainnet': {\n\t\t\ttype: 'string',\n\t\t\tdefault: MAINNET_API_URL,\n\t\t},\n\t\t'url-testnet': {\n\t\t\ttype: 'string',\n\t\t\tdefault: TESTNET_API_URL,\n\t\t},\n\t\tinclude: {\n\t\t\ttype: 'string',\n\t\t\tmultiple: true,\n\t\t\tdefault: DEFAULT_INCLUDE_PATTERNS,\n\t\t\tshort: 'i',\n\t\t},\n\t\texclude: {\n\t\t\ttype: 'string',\n\t\t\tmultiple: true,\n\t\t\tdefault: DEFAULT_EXCLUDE_PATTERNS,\n\t\t\tshort: 'e',\n\t\t},\n\t\tforce: {\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t\tshort: 'f',\n\t\t},\n\t},\n});\n\nexport async function parser() {\n\tconst path = isAbsolute(args.output) ? args.output : join(process.cwd(), args.output);\n\tconst dir = dirname(path);\n\n\tif (!existsSync(dir)) mkdirSync(dir, { recursive: true });\n\n\tif (!isSupportedFile(path))\n\t\tthrow new Error(\n\t\t\t`Unsupported file type: ${path}. Please use a .ts (or equivalent) file name for the output.`,\n\t\t);\n\n\tif (existsSync(path) && !args.force) {\n\t\tconst { overwrite } = (await prompt({\n\t\t\ttype: 'confirm',\n\t\t\tname: 'overwrite',\n\t\t\tmessage: `The file ${path} already exists. Do you want to overwrite it?`,\n\t\t})) as { overwrite: boolean };\n\n\t\tconsole.log(`Skipping generation of MVR file.`);\n\t\tif (!overwrite) return process.exit(1);\n\t}\n\n\tconsole.log(`Generating ${args.output}...`);\n\n\tconst detectedNames = await findNames({});\n\n\tconst { mainnet, testnet } = await crossNetworkResolution(detectedNames);\n\n\tawait writeOutputFile(path, mainnet, testnet);\n}\n\nasync function writeOutputFile(\n\toutDir: string,\n\tmainnet: NamedPackagesOverrides,\n\ttestnet: NamedPackagesOverrides,\n) {\n\tconst outputFile = `${WARNING_MESSAGE}\nconst mainnetResolution = ${JSON.stringify(mainnet, null, 2)}\nconst testnetResolution = ${JSON.stringify(testnet, null, 2)}\n\nexport function getMvrCache(network: 'mainnet' | 'testnet') {\n\treturn network === 'mainnet' ? mainnetResolution : testnetResolution;\n}\\n\n`;\n\n\twriteFileSync(outDir, await format(outputFile, { parser: 'typescript' }), 'utf8');\n}\n\nexport async function crossNetworkResolution(detectedNames: Set<string>) {\n\tconst packages = Array.from(detectedNames).filter((x) => !x.includes('::'));\n\tconst types = Array.from(detectedNames).filter((x) => x.includes('::'));\n\n\tconst [mainnetPackages, mainnetTypes, testnetPackages, testnetTypes] = await Promise.all([\n\t\tresolvePackages(packages, args['url-mainnet']),\n\t\tresolveTypes(types, args['url-mainnet']),\n\t\tresolvePackages(packages, args['url-testnet']),\n\t\tresolveTypes(types, args['url-testnet']),\n\t]);\n\n\treturn {\n\t\tmainnet: {\n\t\t\tpackages: mainnetPackages,\n\t\t\ttypes: mainnetTypes,\n\t\t},\n\t\ttestnet: {\n\t\t\tpackages: testnetPackages,\n\t\t\ttypes: testnetTypes,\n\t\t},\n\t};\n}\n\nasync function resolvePackages(packages: string[], apiUrl: string) {\n\tconst batches = batch(packages, 50);\n\n\tconst results: Record<string, string> = {};\n\n\tawait Promise.all(\n\t\tbatches.map(async (batch) => {\n\t\t\tconst response = await fetch(`${apiUrl}/v1/resolution/bulk`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tnames: batch,\n\t\t\t\t}),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorBody = await response.json().catch(() => ({}));\n\t\t\t\tthrow new Error(`Failed to resolve packages: ${errorBody?.message}`);\n\t\t\t}\n\n\t\t\tconst data = await response.json();\n\n\t\t\tif (!data?.resolution) return;\n\n\t\t\tfor (const pkg of Object.keys(data?.resolution)) {\n\t\t\t\tconst pkgData = data.resolution[pkg]?.package_id;\n\n\t\t\t\tif (!pkgData) continue;\n\n\t\t\t\tresults[pkg] = pkgData;\n\t\t\t}\n\t\t}),\n\t);\n\n\treturn results;\n}\n\n// TODO: Switch to `/struct-definition/bulk` endpoint when released,\n// as this endpoint will be the right one for \"non-nested\" struct resolution.\n// The current endpoint will fail with \"generic\" parameter lookups (which are not existent)\n// on this parser.\nasync function resolveTypes(types: string[], apiUrl: string) {\n\tconst batches = batch(types, 50);\n\n\tconst results: Record<string, string> = {};\n\n\tawait Promise.all(\n\t\tbatches.map(async (batch) => {\n\t\t\tconst response = await fetch(`${apiUrl}/v1/struct-definition/bulk`, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\ttypes: batch,\n\t\t\t\t}),\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorBody = await response.json().catch(() => ({}));\n\t\t\t\tthrow new Error(`Failed to resolve types: ${errorBody?.message}`);\n\t\t\t}\n\n\t\t\tconst data = await response.json();\n\n\t\t\tif (!data?.resolution) return;\n\n\t\t\tfor (const type of Object.keys(data?.resolution)) {\n\t\t\t\tconst typeData = data.resolution[type]?.type_tag;\n\t\t\t\tif (!typeData) continue;\n\n\t\t\t\tresults[type] = typeData;\n\t\t\t}\n\t\t}),\n\t);\n\n\treturn results;\n}\n\n/**\n * Finds all the MVR names in the given directory.\n * @param directory - The directory to search for MVR names.\n * @returns A set of all the MVR names found in the directory.\n */\nexport async function findNames({\n\tdirectory = args.directory,\n\tinclude = args.include,\n\texclude = args.exclude,\n\tdepth = parseInt(args.depth),\n\toutput = args.output,\n}: {\n\tdirectory?: string;\n\tinclude?: string[];\n\texclude?: string[];\n\tdepth?: number;\n\toutput?: string;\n}) {\n\tconst detectedNames = new Set<string>();\n\tconst excluded = [...exclude, output];\n\n\tconst files = glob.sync(include, {\n\t\tignore: excluded,\n\t\tcwd: directory,\n\t\tmaxDepth: depth,\n\t\tabsolute: true,\n\t});\n\n\t// We batch the files to avoid trying to open too many files at once.\n\tconst batches = batch(files);\n\n\tfor (const batch of batches) {\n\t\tawait processFilesBatch(batch, detectedNames);\n\t}\n\n\treturn detectedNames;\n}\n\n/**\n * Finds all the MVR names in the given files.\n */\nasync function processFilesBatch(files: string[], detectedNames: Set<string>) {\n\tawait Promise.all(\n\t\tfiles.map(async (file) => {\n\t\t\tconst content = await readFile(file, 'utf8');\n\t\t\textractMvrNames(content).forEach((name) => detectedNames.add(name));\n\t\t}),\n\t);\n}\n\n/**\n * Extracts all the MVR names from the given file's data (content).\n */\nfunction extractMvrNames(content: string) {\n\tconst relevantNames = new Set<string>();\n\t// find all \"fully qualified\" matches.\n\tconst fullQualifiedMatches = [...content.matchAll(TYPES_AND_TARGET_MATCHES)];\n\tfullQualifiedMatches.forEach((match) => {\n\t\tconst [pkg] = match[0].split('::');\n\n\t\tif (!isValidNamedPackage(pkg)) return;\n\n\t\trelevantNames.add(match[0]);\n\t});\n\n\t// find all \"plain\" name matches\n\tconst plainNameMatches = [...content.matchAll(MVR_NAME_MATCHES)];\n\tplainNameMatches.forEach((match) => {\n\t\tconst [pkg] = match[0].split('::');\n\t\tif (!isValidNamedPackage(pkg)) return;\n\n\t\trelevantNames.add(pkg);\n\t});\n\n\treturn relevantNames;\n}\n\n/**\n * Batch the given array into smaller arrays of the given size.\n */\nfunction batch<T>(array: T[], batchSize: number = MAX_BATCH_SIZE) {\n\tconst result = [];\n\tfor (let i = 0; i < array.length; i += batchSize) {\n\t\tresult.push(array.slice(i, i + batchSize)); // Create batches\n\t}\n\treturn result;\n}\n\nfunction isSupportedFile(filePath: string) {\n\tconst ext = extname(filePath).toLowerCase();\n\treturn ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].includes(ext);\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,2BAA2B;AACjC,MAAM,mBAAmB;AAEzB,MAAM,2BAA2B,CAAC,+BAA+B;AACjE,MAAM,2BAA2B,CAAC,mBAAmB,QAAQ;AAC7D,MAAM,oBAAoB;AAE1B,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAExB,MAAM,kBAAkB;;;;;;;;;;;AAYxB,MAAM,EAAE,QAAQ,SAAS,UAAU,EAClC,SAAS;CACR,WAAW;EACV,MAAM;EACN,SAAS;EACT,OAAO;EACP;CACD,QAAQ;EACP,MAAM;EACN,SAAS;EACT,OAAO;EACP;CACD,OAAO;EACN,MAAM;EACN,SAAS;EACT,OAAO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,SAAS,UAAU;EACvC,MAAM,CAAC,OAAO,MAAM,GAAG,MAAM,KAAK;AAElC,MAAI,CAAC,oBAAoB,IAAI,CAAE;AAE/B,gBAAc,IAAI,MAAM,GAAG;GAC1B;AAIF,CADyB,CAAC,GAAG,QAAQ,SAAS,iBAAiB,CAAC,CAC/C,SAAS,UAAU;EACnC,MAAM,CAAC,OAAO,MAAM,GAAG,MAAM,KAAK;AAClC,MAAI,CAAC,oBAAoB,IAAI,CAAE;AAE/B,gBAAc,IAAI,IAAI;GACrB;AAEF,QAAO;;;;;AAMR,SAAS,MAAS,OAAY,YAAoB,gBAAgB;CACjE,MAAM,SAAS,EAAE;AACjB,MAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,UACtC,QAAO,KAAK,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC;AAE3C,QAAO;;AAGR,SAAS,gBAAgB,UAAkB;CAC1C,MAAM,MAAM,QAAQ,SAAS,CAAC,aAAa;AAC3C,QAAO;EAAC;EAAO;EAAQ;EAAQ;EAAO;EAAQ;EAAO,CAAC,SAAS,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haneullabs/mvr-static",
|
|
3
|
-
"author": "Haneul Labs <build@
|
|
3
|
+
"author": "Haneul Labs <build@haneul-labs.com>",
|
|
4
4
|
"description": "The static generation tool for Move Registry (mvr)",
|
|
5
|
-
"homepage": "https://sdk.
|
|
6
|
-
"version": "0.1
|
|
5
|
+
"homepage": "https://sdk.haneul-labs.com",
|
|
6
|
+
"version": "0.3.1",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"files": [
|
|
9
9
|
"CHANGELOG.md",
|
|
@@ -12,43 +12,48 @@
|
|
|
12
12
|
"dist",
|
|
13
13
|
"src"
|
|
14
14
|
],
|
|
15
|
-
"type": "
|
|
16
|
-
"main": "./dist/
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
19
25
|
"repository": {
|
|
20
26
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/GeunhwaJeong/
|
|
27
|
+
"url": "git+https://github.com/GeunhwaJeong/ts-sdks.git"
|
|
22
28
|
},
|
|
23
29
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/HaneulLabs/mvr/issues/new"
|
|
25
31
|
},
|
|
26
32
|
"publishConfig": {
|
|
27
33
|
"access": "public"
|
|
28
34
|
},
|
|
29
35
|
"devDependencies": {
|
|
30
36
|
"typescript": "^5.9.3",
|
|
31
|
-
"vitest": "^4.0.
|
|
32
|
-
"@haneullabs/build-scripts": "0.1.0"
|
|
37
|
+
"vitest": "^4.0.17"
|
|
33
38
|
},
|
|
34
39
|
"dependencies": {
|
|
35
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^25.0.8",
|
|
36
41
|
"enquirer": "^2.4.1",
|
|
37
42
|
"glob": "^13.0.0",
|
|
38
|
-
"prettier": "^3.7.
|
|
39
|
-
"@haneullabs/haneul": "
|
|
43
|
+
"prettier": "^3.7.4",
|
|
44
|
+
"@haneullabs/haneul": "^2.4.0"
|
|
40
45
|
},
|
|
41
46
|
"sideEffects": false,
|
|
42
47
|
"bin": "./bin/parser.js",
|
|
43
48
|
"scripts": {
|
|
44
49
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
45
|
-
"build": "tsc --
|
|
50
|
+
"build": "rm -rf dist && tsc --noEmit && tsdown",
|
|
46
51
|
"prettier:check": "prettier -c --ignore-unknown .",
|
|
47
52
|
"prettier:fix": "prettier -w --ignore-unknown .",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"lint": "pnpm run
|
|
51
|
-
"lint:fix": "pnpm run
|
|
53
|
+
"oxlint:check": "oxlint .",
|
|
54
|
+
"oxlint:fix": "oxlint --fix",
|
|
55
|
+
"lint": "pnpm run oxlint:check && pnpm run prettier:check",
|
|
56
|
+
"lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix",
|
|
52
57
|
"test": "vitest run"
|
|
53
58
|
}
|
|
54
59
|
}
|
package/src/parsing.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
|
4
4
|
import { readFile } from 'fs/promises';
|
|
5
5
|
import { dirname, extname, isAbsolute, join } from 'path';
|
|
6
6
|
import { parseArgs } from 'util';
|
|
7
|
-
import type { NamedPackagesOverrides } from '@haneullabs/haneul/
|
|
7
|
+
import type { NamedPackagesOverrides } from '@haneullabs/haneul/client';
|
|
8
8
|
import { isValidNamedPackage } from '@haneullabs/haneul/utils';
|
|
9
9
|
import { prompt } from 'enquirer';
|
|
10
10
|
import { glob } from 'glob';
|
|
@@ -18,8 +18,8 @@ const DEFAULT_EXCLUDE_PATTERNS = ['node_modules/**', '**/.*'];
|
|
|
18
18
|
const DEFAULT_FILE_NAME = `mvr.ts`;
|
|
19
19
|
|
|
20
20
|
const MAX_BATCH_SIZE = 25; // files to process per batch.
|
|
21
|
-
const MAINNET_API_URL = 'https://mainnet.mvr.
|
|
22
|
-
const TESTNET_API_URL = 'https://testnet.mvr.
|
|
21
|
+
const MAINNET_API_URL = 'https://mainnet.mvr.haneul-labs.com';
|
|
22
|
+
const TESTNET_API_URL = 'https://testnet.mvr.haneul-labs.com';
|
|
23
23
|
|
|
24
24
|
const WARNING_MESSAGE = `/**
|
|
25
25
|
* This file is automatically generated by the mvr SDK.
|
|
@@ -28,8 +28,8 @@ const WARNING_MESSAGE = `/**
|
|
|
28
28
|
*
|
|
29
29
|
* Run this script before building your project to ensure that the mvr.ts file stays up to date.
|
|
30
30
|
*
|
|
31
|
-
* You can use this pre-built cache when initializing your
|
|
32
|
-
* \`getMvrCache("mainnet")\` or \`getMvrCache("testnet")\`
|
|
31
|
+
* You can use this pre-built cache when initializing your Haneul client by calling
|
|
32
|
+
* \`getMvrCache("mainnet")\` or \`getMvrCache("testnet")\` and passing it as the \`overrides\` option.
|
|
33
33
|
*/
|
|
34
34
|
`;
|
|
35
35
|
|
package/dist/execute.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/execute.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// Copyright (c) Mysten Labs, Inc.
|
|
4
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
const parsing_js_1 = require("./parsing.js");
|
|
6
|
-
(0, parsing_js_1.parser)();
|
|
7
|
-
//# sourceMappingURL=execute.js.map
|
package/dist/execute.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":";;AAAA,kCAAkC;AAClC,sCAAsC;AACtC,6CAAsC;AAEtC,IAAA,mBAAM,GAAE,CAAC"}
|
package/dist/parsing.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare function parser(): Promise<undefined>;
|
|
2
|
-
export declare function crossNetworkResolution(detectedNames: Set<string>): Promise<{
|
|
3
|
-
mainnet: {
|
|
4
|
-
packages: Record<string, string>;
|
|
5
|
-
types: Record<string, string>;
|
|
6
|
-
};
|
|
7
|
-
testnet: {
|
|
8
|
-
packages: Record<string, string>;
|
|
9
|
-
types: Record<string, string>;
|
|
10
|
-
};
|
|
11
|
-
}>;
|
|
12
|
-
/**
|
|
13
|
-
* Finds all the MVR names in the given directory.
|
|
14
|
-
* @param directory - The directory to search for MVR names.
|
|
15
|
-
* @returns A set of all the MVR names found in the directory.
|
|
16
|
-
*/
|
|
17
|
-
export declare function findNames({ directory, include, exclude, depth, output, }: {
|
|
18
|
-
directory?: string;
|
|
19
|
-
include?: string[];
|
|
20
|
-
exclude?: string[];
|
|
21
|
-
depth?: number;
|
|
22
|
-
output?: string;
|
|
23
|
-
}): Promise<Set<string>>;
|
package/dist/parsing.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parser = parser;
|
|
4
|
-
exports.crossNetworkResolution = crossNetworkResolution;
|
|
5
|
-
exports.findNames = findNames;
|
|
6
|
-
// Copyright (c) Mysten Labs, Inc.
|
|
7
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const promises_1 = require("fs/promises");
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const util_1 = require("util");
|
|
12
|
-
const utils_1 = require("@haneullabs/haneul/utils");
|
|
13
|
-
const enquirer_1 = require("enquirer");
|
|
14
|
-
const glob_1 = require("glob");
|
|
15
|
-
const prettier_1 = require("prettier");
|
|
16
|
-
const TYPES_AND_TARGET_MATCHES = /[@a-zA-Z0-9/.-]+::[a-zA-Z0-9_]+::[a-zA-Z0-9_]+/g;
|
|
17
|
-
const MVR_NAME_MATCHES = /[@a-zA-Z0-9/.-]+::/g;
|
|
18
|
-
const DEFAULT_INCLUDE_PATTERNS = ['**/*.{js,ts,jsx,tsx,mjs,cjs}'];
|
|
19
|
-
const DEFAULT_EXCLUDE_PATTERNS = ['node_modules/**', '**/.*'];
|
|
20
|
-
const DEFAULT_FILE_NAME = `mvr.ts`;
|
|
21
|
-
const MAX_BATCH_SIZE = 25; // files to process per batch.
|
|
22
|
-
const MAINNET_API_URL = 'https://mainnet.mvr.haneullabs.com';
|
|
23
|
-
const TESTNET_API_URL = 'https://testnet.mvr.haneullabs.com';
|
|
24
|
-
const WARNING_MESSAGE = `/**
|
|
25
|
-
* This file is automatically generated by the mvr SDK.
|
|
26
|
-
* You can edit this file, but it will be overwritten on the next run.
|
|
27
|
-
* You should check this file in your version control system.
|
|
28
|
-
*
|
|
29
|
-
* Run this script before building your project to ensure that the mvr.ts file stays up to date.
|
|
30
|
-
*
|
|
31
|
-
* You can use this pre-built cache when initializing your "NamedPackagesPlugin" by calling
|
|
32
|
-
* \`getMvrCache("mainnet")\` or \`getMvrCache("testnet")\`
|
|
33
|
-
*/
|
|
34
|
-
`;
|
|
35
|
-
const { values: args } = (0, util_1.parseArgs)({
|
|
36
|
-
options: {
|
|
37
|
-
directory: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
default: '.',
|
|
40
|
-
short: 'd',
|
|
41
|
-
},
|
|
42
|
-
output: {
|
|
43
|
-
type: 'string',
|
|
44
|
-
default: DEFAULT_FILE_NAME,
|
|
45
|
-
short: 'o',
|
|
46
|
-
},
|
|
47
|
-
depth: {
|
|
48
|
-
type: 'string',
|
|
49
|
-
default: '10',
|
|
50
|
-
short: 'd',
|
|
51
|
-
},
|
|
52
|
-
'url-mainnet': {
|
|
53
|
-
type: 'string',
|
|
54
|
-
default: MAINNET_API_URL,
|
|
55
|
-
},
|
|
56
|
-
'url-testnet': {
|
|
57
|
-
type: 'string',
|
|
58
|
-
default: TESTNET_API_URL,
|
|
59
|
-
},
|
|
60
|
-
include: {
|
|
61
|
-
type: 'string',
|
|
62
|
-
multiple: true,
|
|
63
|
-
default: DEFAULT_INCLUDE_PATTERNS,
|
|
64
|
-
short: 'i',
|
|
65
|
-
},
|
|
66
|
-
exclude: {
|
|
67
|
-
type: 'string',
|
|
68
|
-
multiple: true,
|
|
69
|
-
default: DEFAULT_EXCLUDE_PATTERNS,
|
|
70
|
-
short: 'e',
|
|
71
|
-
},
|
|
72
|
-
force: {
|
|
73
|
-
type: 'boolean',
|
|
74
|
-
default: false,
|
|
75
|
-
short: 'f',
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
async function parser() {
|
|
80
|
-
const path = (0, path_1.isAbsolute)(args.output) ? args.output : (0, path_1.join)(process.cwd(), args.output);
|
|
81
|
-
const dir = (0, path_1.dirname)(path);
|
|
82
|
-
if (!(0, fs_1.existsSync)(dir))
|
|
83
|
-
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
84
|
-
if (!isSupportedFile(path))
|
|
85
|
-
throw new Error(`Unsupported file type: ${path}. Please use a .ts (or equivalent) file name for the output.`);
|
|
86
|
-
if ((0, fs_1.existsSync)(path) && !args.force) {
|
|
87
|
-
const { overwrite } = (await (0, enquirer_1.prompt)({
|
|
88
|
-
type: 'confirm',
|
|
89
|
-
name: 'overwrite',
|
|
90
|
-
message: `The file ${path} already exists. Do you want to overwrite it?`,
|
|
91
|
-
}));
|
|
92
|
-
console.log(`Skipping generation of MVR file.`);
|
|
93
|
-
if (!overwrite)
|
|
94
|
-
return process.exit(1);
|
|
95
|
-
}
|
|
96
|
-
console.log(`Generating ${args.output}...`);
|
|
97
|
-
const detectedNames = await findNames({});
|
|
98
|
-
const { mainnet, testnet } = await crossNetworkResolution(detectedNames);
|
|
99
|
-
await writeOutputFile(path, mainnet, testnet);
|
|
100
|
-
}
|
|
101
|
-
async function writeOutputFile(outDir, mainnet, testnet) {
|
|
102
|
-
const outputFile = `${WARNING_MESSAGE}
|
|
103
|
-
const mainnetResolution = ${JSON.stringify(mainnet, null, 2)}
|
|
104
|
-
const testnetResolution = ${JSON.stringify(testnet, null, 2)}
|
|
105
|
-
|
|
106
|
-
export function getMvrCache(network: 'mainnet' | 'testnet') {
|
|
107
|
-
return network === 'mainnet' ? mainnetResolution : testnetResolution;
|
|
108
|
-
}\n
|
|
109
|
-
`;
|
|
110
|
-
(0, fs_1.writeFileSync)(outDir, await (0, prettier_1.format)(outputFile, { parser: 'typescript' }), 'utf8');
|
|
111
|
-
}
|
|
112
|
-
async function crossNetworkResolution(detectedNames) {
|
|
113
|
-
const packages = Array.from(detectedNames).filter((x) => !x.includes('::'));
|
|
114
|
-
const types = Array.from(detectedNames).filter((x) => x.includes('::'));
|
|
115
|
-
const [mainnetPackages, mainnetTypes, testnetPackages, testnetTypes] = await Promise.all([
|
|
116
|
-
resolvePackages(packages, args['url-mainnet']),
|
|
117
|
-
resolveTypes(types, args['url-mainnet']),
|
|
118
|
-
resolvePackages(packages, args['url-testnet']),
|
|
119
|
-
resolveTypes(types, args['url-testnet']),
|
|
120
|
-
]);
|
|
121
|
-
return {
|
|
122
|
-
mainnet: {
|
|
123
|
-
packages: mainnetPackages,
|
|
124
|
-
types: mainnetTypes,
|
|
125
|
-
},
|
|
126
|
-
testnet: {
|
|
127
|
-
packages: testnetPackages,
|
|
128
|
-
types: testnetTypes,
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
async function resolvePackages(packages, apiUrl) {
|
|
133
|
-
const batches = batch(packages, 50);
|
|
134
|
-
const results = {};
|
|
135
|
-
await Promise.all(batches.map(async (batch) => {
|
|
136
|
-
const response = await fetch(`${apiUrl}/v1/resolution/bulk`, {
|
|
137
|
-
method: 'POST',
|
|
138
|
-
headers: { 'Content-Type': 'application/json' },
|
|
139
|
-
body: JSON.stringify({
|
|
140
|
-
names: batch,
|
|
141
|
-
}),
|
|
142
|
-
});
|
|
143
|
-
if (!response.ok) {
|
|
144
|
-
const errorBody = await response.json().catch(() => ({}));
|
|
145
|
-
throw new Error(`Failed to resolve packages: ${errorBody?.message}`);
|
|
146
|
-
}
|
|
147
|
-
const data = await response.json();
|
|
148
|
-
if (!data?.resolution)
|
|
149
|
-
return;
|
|
150
|
-
for (const pkg of Object.keys(data?.resolution)) {
|
|
151
|
-
const pkgData = data.resolution[pkg]?.package_id;
|
|
152
|
-
if (!pkgData)
|
|
153
|
-
continue;
|
|
154
|
-
results[pkg] = pkgData;
|
|
155
|
-
}
|
|
156
|
-
}));
|
|
157
|
-
return results;
|
|
158
|
-
}
|
|
159
|
-
// TODO: Switch to `/struct-definition/bulk` endpoint when released,
|
|
160
|
-
// as this endpoint will be the right one for "non-nested" struct resolution.
|
|
161
|
-
// The current endpoint will fail with "generic" parameter lookups (which are not existent)
|
|
162
|
-
// on this parser.
|
|
163
|
-
async function resolveTypes(types, apiUrl) {
|
|
164
|
-
const batches = batch(types, 50);
|
|
165
|
-
const results = {};
|
|
166
|
-
await Promise.all(batches.map(async (batch) => {
|
|
167
|
-
const response = await fetch(`${apiUrl}/v1/struct-definition/bulk`, {
|
|
168
|
-
method: 'POST',
|
|
169
|
-
headers: { 'Content-Type': 'application/json' },
|
|
170
|
-
body: JSON.stringify({
|
|
171
|
-
types: batch,
|
|
172
|
-
}),
|
|
173
|
-
});
|
|
174
|
-
if (!response.ok) {
|
|
175
|
-
const errorBody = await response.json().catch(() => ({}));
|
|
176
|
-
throw new Error(`Failed to resolve types: ${errorBody?.message}`);
|
|
177
|
-
}
|
|
178
|
-
const data = await response.json();
|
|
179
|
-
if (!data?.resolution)
|
|
180
|
-
return;
|
|
181
|
-
for (const type of Object.keys(data?.resolution)) {
|
|
182
|
-
const typeData = data.resolution[type]?.type_tag;
|
|
183
|
-
if (!typeData)
|
|
184
|
-
continue;
|
|
185
|
-
results[type] = typeData;
|
|
186
|
-
}
|
|
187
|
-
}));
|
|
188
|
-
return results;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Finds all the MVR names in the given directory.
|
|
192
|
-
* @param directory - The directory to search for MVR names.
|
|
193
|
-
* @returns A set of all the MVR names found in the directory.
|
|
194
|
-
*/
|
|
195
|
-
async function findNames({ directory = args.directory, include = args.include, exclude = args.exclude, depth = parseInt(args.depth), output = args.output, }) {
|
|
196
|
-
const detectedNames = new Set();
|
|
197
|
-
const excluded = [...exclude, output];
|
|
198
|
-
const files = glob_1.glob.sync(include, {
|
|
199
|
-
ignore: excluded,
|
|
200
|
-
cwd: directory,
|
|
201
|
-
maxDepth: depth,
|
|
202
|
-
absolute: true,
|
|
203
|
-
});
|
|
204
|
-
// We batch the files to avoid trying to open too many files at once.
|
|
205
|
-
const batches = batch(files);
|
|
206
|
-
for (const batch of batches) {
|
|
207
|
-
await processFilesBatch(batch, detectedNames);
|
|
208
|
-
}
|
|
209
|
-
return detectedNames;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Finds all the MVR names in the given files.
|
|
213
|
-
*/
|
|
214
|
-
async function processFilesBatch(files, detectedNames) {
|
|
215
|
-
await Promise.all(files.map(async (file) => {
|
|
216
|
-
const content = await (0, promises_1.readFile)(file, 'utf8');
|
|
217
|
-
extractMvrNames(content).forEach((name) => detectedNames.add(name));
|
|
218
|
-
}));
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Extracts all the MVR names from the given file's data (content).
|
|
222
|
-
*/
|
|
223
|
-
function extractMvrNames(content) {
|
|
224
|
-
const relevantNames = new Set();
|
|
225
|
-
// find all "fully qualified" matches.
|
|
226
|
-
const fullQualifiedMatches = [...content.matchAll(TYPES_AND_TARGET_MATCHES)];
|
|
227
|
-
fullQualifiedMatches.forEach((match) => {
|
|
228
|
-
const [pkg] = match[0].split('::');
|
|
229
|
-
if (!(0, utils_1.isValidNamedPackage)(pkg))
|
|
230
|
-
return;
|
|
231
|
-
relevantNames.add(match[0]);
|
|
232
|
-
});
|
|
233
|
-
// find all "plain" name matches
|
|
234
|
-
const plainNameMatches = [...content.matchAll(MVR_NAME_MATCHES)];
|
|
235
|
-
plainNameMatches.forEach((match) => {
|
|
236
|
-
const [pkg] = match[0].split('::');
|
|
237
|
-
if (!(0, utils_1.isValidNamedPackage)(pkg))
|
|
238
|
-
return;
|
|
239
|
-
relevantNames.add(pkg);
|
|
240
|
-
});
|
|
241
|
-
return relevantNames;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Batch the given array into smaller arrays of the given size.
|
|
245
|
-
*/
|
|
246
|
-
function batch(array, batchSize = MAX_BATCH_SIZE) {
|
|
247
|
-
const result = [];
|
|
248
|
-
for (let i = 0; i < array.length; i += batchSize) {
|
|
249
|
-
result.push(array.slice(i, i + batchSize)); // Create batches
|
|
250
|
-
}
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
function isSupportedFile(filePath) {
|
|
254
|
-
const ext = (0, path_1.extname)(filePath).toLowerCase();
|
|
255
|
-
return ['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].includes(ext);
|
|
256
|
-
}
|
|
257
|
-
//# sourceMappingURL=parsing.js.map
|
package/dist/parsing.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.js","sourceRoot":"","sources":["../src/parsing.ts"],"names":[],"mappings":";;AAgFA,wBA6BC;AAmBD,wDAqBC;AAoFD,8BA+BC;AAxQD,kCAAkC;AAClC,sCAAsC;AACtC,2BAA0D;AAC1D,0CAAuC;AACvC,+BAA0D;AAC1D,+BAAiC;AAEjC,oDAA+D;AAC/D,uCAAkC;AAClC,+BAA4B;AAC5B,uCAAkC;AAElC,MAAM,wBAAwB,GAAG,iDAAiD,CAAC;AACnF,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAE/C,MAAM,wBAAwB,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAClE,MAAM,wBAAwB,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AAC9D,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC,MAAM,cAAc,GAAG,EAAE,CAAC,CAAC,8BAA8B;AACzD,MAAM,eAAe,GAAG,oCAAoC,CAAC;AAC7D,MAAM,eAAe,GAAG,oCAAoC,CAAC;AAE7D,MAAM,eAAe,GAAG;;;;;;;;;;CAUvB,CAAC;AAEF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAA,gBAAS,EAAC;IAClC,OAAO,EAAE;QACR,SAAS,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,GAAG;YACZ,KAAK,EAAE,GAAG;SACV;QACD,MAAM,EAAE;YACP,IAAI,EAAE,QAAQ;Y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