@cartesi/cli 2.0.0-alpha.21 → 2.0.0-alpha.22

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 (131) hide show
  1. package/dist/index.js +685 -50
  2. package/dist/index.js.map +785 -0
  3. package/package.json +80 -84
  4. package/LICENSE +0 -202
  5. package/dist/base.d.ts +0 -28
  6. package/dist/base.d.ts.map +0 -1
  7. package/dist/base.js +0 -109
  8. package/dist/builder/directory.d.ts +0 -3
  9. package/dist/builder/directory.d.ts.map +0 -1
  10. package/dist/builder/directory.js +0 -39
  11. package/dist/builder/docker.d.ts +0 -10
  12. package/dist/builder/docker.d.ts.map +0 -1
  13. package/dist/builder/docker.js +0 -114
  14. package/dist/builder/empty.d.ts +0 -3
  15. package/dist/builder/empty.d.ts.map +0 -1
  16. package/dist/builder/empty.js +0 -21
  17. package/dist/builder/index.d.ts +0 -6
  18. package/dist/builder/index.d.ts.map +0 -1
  19. package/dist/builder/index.js +0 -5
  20. package/dist/builder/none.d.ts +0 -3
  21. package/dist/builder/none.d.ts.map +0 -1
  22. package/dist/builder/none.js +0 -11
  23. package/dist/builder/tar.d.ts +0 -3
  24. package/dist/builder/tar.d.ts.map +0 -1
  25. package/dist/builder/tar.js +0 -30
  26. package/dist/commands/address-book.d.ts +0 -6
  27. package/dist/commands/address-book.d.ts.map +0 -1
  28. package/dist/commands/address-book.js +0 -44
  29. package/dist/commands/build.d.ts +0 -8
  30. package/dist/commands/build.d.ts.map +0 -1
  31. package/dist/commands/build.js +0 -97
  32. package/dist/commands/clean.d.ts +0 -3
  33. package/dist/commands/clean.d.ts.map +0 -1
  34. package/dist/commands/clean.js +0 -10
  35. package/dist/commands/create.d.ts +0 -7
  36. package/dist/commands/create.d.ts.map +0 -1
  37. package/dist/commands/create.js +0 -37
  38. package/dist/commands/deploy/build.d.ts +0 -3
  39. package/dist/commands/deploy/build.d.ts.map +0 -1
  40. package/dist/commands/deploy/build.js +0 -9
  41. package/dist/commands/deploy.d.ts +0 -3
  42. package/dist/commands/deploy.d.ts.map +0 -1
  43. package/dist/commands/deploy.js +0 -12
  44. package/dist/commands/deposit/erc1155.d.ts +0 -18
  45. package/dist/commands/deposit/erc1155.d.ts.map +0 -1
  46. package/dist/commands/deposit/erc1155.js +0 -254
  47. package/dist/commands/deposit/erc20.d.ts +0 -10
  48. package/dist/commands/deposit/erc20.d.ts.map +0 -1
  49. package/dist/commands/deposit/erc20.js +0 -125
  50. package/dist/commands/deposit/erc721.d.ts +0 -10
  51. package/dist/commands/deposit/erc721.d.ts.map +0 -1
  52. package/dist/commands/deposit/erc721.js +0 -143
  53. package/dist/commands/deposit/ether.d.ts +0 -10
  54. package/dist/commands/deposit/ether.d.ts.map +0 -1
  55. package/dist/commands/deposit/ether.js +0 -65
  56. package/dist/commands/deposit.d.ts +0 -9
  57. package/dist/commands/deposit.d.ts.map +0 -1
  58. package/dist/commands/deposit.js +0 -37
  59. package/dist/commands/doctor.d.ts +0 -3
  60. package/dist/commands/doctor.d.ts.map +0 -1
  61. package/dist/commands/doctor.js +0 -105
  62. package/dist/commands/hash.d.ts +0 -5
  63. package/dist/commands/hash.d.ts.map +0 -1
  64. package/dist/commands/hash.js +0 -22
  65. package/dist/commands/logs.d.ts +0 -9
  66. package/dist/commands/logs.d.ts.map +0 -1
  67. package/dist/commands/logs.js +0 -34
  68. package/dist/commands/run.d.ts +0 -15
  69. package/dist/commands/run.d.ts.map +0 -1
  70. package/dist/commands/run.js +0 -202
  71. package/dist/commands/send.d.ts +0 -10
  72. package/dist/commands/send.d.ts.map +0 -1
  73. package/dist/commands/send.js +0 -130
  74. package/dist/commands/shell.d.ts +0 -7
  75. package/dist/commands/shell.d.ts.map +0 -1
  76. package/dist/commands/shell.js +0 -48
  77. package/dist/commands/status.d.ts +0 -6
  78. package/dist/commands/status.d.ts.map +0 -1
  79. package/dist/commands/status.js +0 -50
  80. package/dist/compose/default.env +0 -36
  81. package/dist/compose/docker-compose-anvil.yaml +0 -39
  82. package/dist/compose/docker-compose-bundler.yaml +0 -71
  83. package/dist/compose/docker-compose-database.yaml +0 -12
  84. package/dist/compose/docker-compose-explorer.yaml +0 -96
  85. package/dist/compose/docker-compose-node-cpus.yaml +0 -6
  86. package/dist/compose/docker-compose-node-memory.yaml +0 -6
  87. package/dist/compose/docker-compose-node.yaml +0 -50
  88. package/dist/compose/docker-compose-passkey-server.yaml +0 -37
  89. package/dist/compose/docker-compose-paymaster.yaml +0 -40
  90. package/dist/compose/docker-compose-proxy.yaml +0 -24
  91. package/dist/config.d.ts +0 -124
  92. package/dist/config.d.ts.map +0 -1
  93. package/dist/config.js +0 -418
  94. package/dist/contracts.d.ts +0 -4376
  95. package/dist/contracts.d.ts.map +0 -1
  96. package/dist/contracts.js +0 -1839
  97. package/dist/exec/cartesi-machine.d.ts +0 -9
  98. package/dist/exec/cartesi-machine.d.ts.map +0 -1
  99. package/dist/exec/cartesi-machine.js +0 -18
  100. package/dist/exec/genext2fs.d.ts +0 -31
  101. package/dist/exec/genext2fs.d.ts.map +0 -1
  102. package/dist/exec/genext2fs.js +0 -44
  103. package/dist/exec/index.d.ts +0 -4
  104. package/dist/exec/index.d.ts.map +0 -1
  105. package/dist/exec/index.js +0 -3
  106. package/dist/exec/mksquashfs.d.ts +0 -21
  107. package/dist/exec/mksquashfs.d.ts.map +0 -1
  108. package/dist/exec/mksquashfs.js +0 -47
  109. package/dist/exec/rollups.d.ts +0 -105
  110. package/dist/exec/rollups.d.ts.map +0 -1
  111. package/dist/exec/rollups.js +0 -375
  112. package/dist/exec/util.d.ts +0 -21
  113. package/dist/exec/util.d.ts.map +0 -1
  114. package/dist/exec/util.js +0 -31
  115. package/dist/index.d.ts +0 -3
  116. package/dist/index.d.ts.map +0 -1
  117. package/dist/machine.d.ts +0 -12
  118. package/dist/machine.d.ts.map +0 -1
  119. package/dist/machine.js +0 -90
  120. package/dist/prompts.d.ts +0 -73
  121. package/dist/prompts.d.ts.map +0 -1
  122. package/dist/prompts.js +0 -192
  123. package/dist/template.d.ts +0 -3
  124. package/dist/template.d.ts.map +0 -1
  125. package/dist/template.js +0 -16
  126. package/dist/types/docker.d.ts +0 -22
  127. package/dist/types/docker.d.ts.map +0 -1
  128. package/dist/types/docker.js +0 -1
  129. package/dist/wallet.d.ts +0 -9225
  130. package/dist/wallet.d.ts.map +0 -1
  131. package/dist/wallet.js +0 -41
package/dist/config.js DELETED
@@ -1,418 +0,0 @@
1
- import bytes from "bytes";
2
- import { extname } from "node:path";
3
- import { parse as parseToml } from "smol-toml";
4
- /**
5
- * Typed Errors
6
- */
7
- export class InvalidBuilderError extends Error {
8
- constructor(builder) {
9
- super(`Invalid builder: ${builder}`);
10
- this.name = "InvalidBuilder";
11
- }
12
- }
13
- export class InvalidDriveFormatError extends Error {
14
- constructor(format) {
15
- super(`Invalid drive format: ${format}`);
16
- this.name = "InvalidDriveFormatError";
17
- }
18
- }
19
- export class InvalidEmptyDriveFormatError extends Error {
20
- constructor(format) {
21
- super(`Invalid empty drive format: ${format}`);
22
- this.name = "InvalidEmptyDriveFormatError";
23
- }
24
- }
25
- export class InvalidStringValueError extends Error {
26
- constructor(value) {
27
- super(`Invalid string value: ${value}`);
28
- this.name = "InvalidStringValueError";
29
- }
30
- }
31
- export class InvalidBooleanValueError extends Error {
32
- constructor(value) {
33
- super(`Invalid boolean value: ${value}`);
34
- this.name = "InvalidBooleanValueError";
35
- }
36
- }
37
- export class InvalidNumberValueError extends Error {
38
- constructor(value) {
39
- super(`Invalid number value: ${value}`);
40
- this.name = "InvalidNumberValueError";
41
- }
42
- }
43
- export class InvalidBytesValueError extends Error {
44
- constructor(value) {
45
- super(`Invalid bytes value: ${value}`);
46
- this.name = "InvalidBytesValueError";
47
- }
48
- }
49
- export class RequiredFieldError extends Error {
50
- constructor(key) {
51
- super(`Missing required field: ${key}`);
52
- this.name = "RequiredFieldError";
53
- }
54
- }
55
- export class InvalidStringArrayError extends Error {
56
- constructor() {
57
- super("Invalid string array");
58
- this.name = "InvalidStringArrayError";
59
- }
60
- }
61
- /**
62
- * Configuration for drives of a Cartesi Machine. A drive may already exist or be built by a builder
63
- */
64
- const DEFAULT_FORMAT = "ext2";
65
- const DEFAULT_RAM = "128Mi";
66
- export const DEFAULT_SDK_VERSION = "0.12.0-alpha.25";
67
- export const DEFAULT_SDK_IMAGE = "cartesi/sdk";
68
- export const PREFERRED_PORT = 6751;
69
- export const defaultRootDriveConfig = () => ({
70
- builder: "docker",
71
- buildArgs: [],
72
- context: ".",
73
- dockerfile: "Dockerfile", // file on current working directory
74
- extraSize: 0,
75
- format: DEFAULT_FORMAT,
76
- tags: [],
77
- });
78
- export const defaultMachineConfig = () => ({
79
- assertRollingTemplate: undefined,
80
- bootargs: [],
81
- entrypoint: undefined,
82
- maxMCycle: undefined,
83
- noRollup: undefined,
84
- ramLength: DEFAULT_RAM,
85
- useDockerEnv: true,
86
- useDockerWorkdir: true,
87
- user: undefined,
88
- });
89
- export const defaultConfig = () => ({
90
- drives: { root: defaultRootDriveConfig() },
91
- machine: defaultMachineConfig(),
92
- sdk: `${DEFAULT_SDK_IMAGE}:${DEFAULT_SDK_VERSION}`,
93
- });
94
- const parseBoolean = (value, defaultValue) => {
95
- if (value === undefined) {
96
- return defaultValue;
97
- }
98
- if (typeof value === "boolean") {
99
- return value;
100
- }
101
- throw new InvalidBooleanValueError(value);
102
- };
103
- const parseOptionalBoolean = (value) => {
104
- if (value === undefined) {
105
- return undefined;
106
- }
107
- if (typeof value === "boolean") {
108
- return value;
109
- }
110
- throw new InvalidBooleanValueError(value);
111
- };
112
- const parseString = (value, defaultValue) => {
113
- if (value === undefined) {
114
- return defaultValue;
115
- }
116
- if (typeof value === "string") {
117
- return value;
118
- }
119
- throw new InvalidStringValueError(value);
120
- };
121
- const parseStringArray = (value) => {
122
- if (value === undefined) {
123
- return [];
124
- }
125
- if (typeof value === "string") {
126
- return [value];
127
- }
128
- if (typeof value === "object" && Array.isArray(value)) {
129
- return value.map((v) => {
130
- if (typeof v === "string") {
131
- return v;
132
- }
133
- throw new InvalidStringValueError(v);
134
- });
135
- }
136
- throw new InvalidStringArrayError();
137
- };
138
- const parseRequiredString = (value, key) => {
139
- if (value === undefined) {
140
- throw new RequiredFieldError(key);
141
- }
142
- if (typeof value === "string") {
143
- return value;
144
- }
145
- throw new InvalidStringValueError(value);
146
- };
147
- const parseOptionalString = (value) => {
148
- if (value === undefined) {
149
- return undefined;
150
- }
151
- if (typeof value === "string") {
152
- return value;
153
- }
154
- throw new InvalidStringValueError(value);
155
- };
156
- const parseOptionalStringBoolean = (value) => {
157
- if (value === undefined) {
158
- return undefined;
159
- }
160
- if (typeof value === "string") {
161
- return value;
162
- }
163
- if (typeof value === "boolean") {
164
- return value;
165
- }
166
- throw new InvalidStringValueError(value);
167
- };
168
- const parseOptionalNumber = (value) => {
169
- if (value === undefined) {
170
- return undefined;
171
- }
172
- if (typeof value === "bigint") {
173
- return value;
174
- }
175
- if (typeof value === "number") {
176
- return BigInt(value);
177
- }
178
- throw new InvalidNumberValueError(value);
179
- };
180
- const parseBytes = (value, defaultValue) => {
181
- if (value === undefined) {
182
- return defaultValue;
183
- }
184
- if (typeof value === "bigint") {
185
- return Number(value);
186
- }
187
- if (typeof value === "number" || typeof value === "string") {
188
- const output = bytes.parse(value);
189
- if (output !== null) {
190
- return output;
191
- }
192
- }
193
- throw new InvalidBytesValueError(value);
194
- };
195
- const parseBuilder = (value) => {
196
- if (value === undefined) {
197
- return "docker";
198
- }
199
- if (typeof value === "string") {
200
- switch (value) {
201
- case "directory":
202
- return "directory";
203
- case "docker":
204
- return "docker";
205
- case "empty":
206
- return "empty";
207
- case "none":
208
- return "none";
209
- case "tar":
210
- return "tar";
211
- }
212
- }
213
- throw new InvalidBuilderError(value);
214
- };
215
- const parseFormat = (value) => {
216
- if (value === undefined) {
217
- return DEFAULT_FORMAT;
218
- }
219
- if (typeof value === "string") {
220
- switch (value) {
221
- case "ext2":
222
- return "ext2";
223
- case "sqfs":
224
- return "sqfs";
225
- }
226
- }
227
- throw new InvalidDriveFormatError(value);
228
- };
229
- const parseEmptyFormat = (value) => {
230
- if (value === undefined) {
231
- return DEFAULT_FORMAT;
232
- }
233
- if (typeof value === "string") {
234
- switch (value) {
235
- case "ext2":
236
- return "ext2";
237
- case "raw":
238
- return "raw";
239
- }
240
- }
241
- throw new InvalidEmptyDriveFormatError(value);
242
- };
243
- const parseMachine = (value) => {
244
- if (value === undefined) {
245
- // default machine
246
- return defaultMachineConfig();
247
- }
248
- if (typeof value !== "object") {
249
- throw new Error(`Invalid machine configuration: ${value}`);
250
- }
251
- const toml = value;
252
- return {
253
- assertRollingTemplate: parseOptionalBoolean(toml.assert_rolling_template),
254
- bootargs: parseStringArray(toml.boot_args),
255
- entrypoint: parseOptionalString(toml.entrypoint),
256
- maxMCycle: parseOptionalNumber(toml.max_mcycle),
257
- noRollup: parseBoolean(toml.no_rollup, false),
258
- ramLength: parseString(toml.ram_length, DEFAULT_RAM),
259
- ramImage: parseOptionalString(toml.ram_image),
260
- useDockerEnv: parseBoolean(toml.use_docker_env, true),
261
- useDockerWorkdir: parseBoolean(toml.use_docker_workdir, true),
262
- user: parseOptionalString(toml.user),
263
- };
264
- };
265
- export const getDriveFormat = (filename) => {
266
- const extension = extname(filename);
267
- switch (extension) {
268
- case ".ext2":
269
- return "ext2";
270
- case ".sqfs":
271
- return "sqfs";
272
- default:
273
- throw new InvalidDriveFormatError(extension);
274
- }
275
- };
276
- const parseDrive = (drive) => {
277
- const builder = parseBuilder(drive.builder);
278
- switch (builder) {
279
- case "directory": {
280
- const { extra_size, format, mount, directory, shared, user } = drive;
281
- return {
282
- builder: "directory",
283
- extraSize: parseBytes(extra_size, 0),
284
- format: parseFormat(format),
285
- mount: parseOptionalStringBoolean(mount),
286
- directory: parseRequiredString(directory, "directory"),
287
- shared: parseOptionalBoolean(shared),
288
- user: parseOptionalString(user),
289
- };
290
- }
291
- case "docker": {
292
- const { build_args, context, dockerfile, extra_size, format, image, mount, shared, tags, target, user, } = drive;
293
- return {
294
- builder: "docker",
295
- buildArgs: parseStringArray(build_args),
296
- image: parseOptionalString(image),
297
- context: parseString(context, "."),
298
- dockerfile: parseString(dockerfile, "Dockerfile"),
299
- extraSize: parseBytes(extra_size, 0),
300
- format: parseFormat(format),
301
- mount: parseOptionalStringBoolean(mount),
302
- shared: parseOptionalBoolean(shared),
303
- user: parseOptionalString(user),
304
- tags: parseStringArray(tags),
305
- target: parseOptionalString(target),
306
- };
307
- }
308
- case "empty": {
309
- const { format, mount, size, shared, user } = drive;
310
- return {
311
- builder: "empty",
312
- format: parseEmptyFormat(format),
313
- mount: parseOptionalStringBoolean(mount),
314
- shared: parseOptionalBoolean(shared),
315
- size: parseBytes(size, 0),
316
- user: parseOptionalString(user),
317
- };
318
- }
319
- case "tar": {
320
- const { extra_size, filename, format, mount, shared, user } = drive;
321
- return {
322
- builder: "tar",
323
- extraSize: parseBytes(extra_size, 0),
324
- filename: parseRequiredString(filename, "filename"),
325
- format: parseFormat(format),
326
- mount: parseOptionalStringBoolean(mount),
327
- shared: parseOptionalBoolean(shared),
328
- user: parseOptionalString(user),
329
- };
330
- }
331
- case "none": {
332
- const { shared, mount, user } = drive;
333
- const filename = parseRequiredString(drive.filename, "filename");
334
- const format = getDriveFormat(filename);
335
- return {
336
- builder: "none",
337
- filename,
338
- format,
339
- mount: parseOptionalStringBoolean(mount),
340
- shared: parseOptionalBoolean(shared),
341
- user: parseOptionalString(user),
342
- };
343
- }
344
- }
345
- };
346
- const parseDrives = (config) => {
347
- // load drives from configuration
348
- const drives = Object.entries(config ?? {}).reduce((acc, [name, drive]) => {
349
- acc[name] = parseDrive(drive);
350
- return acc;
351
- }, {});
352
- // check if there is a root drive
353
- const hasRoot = drives.root !== undefined;
354
- if (!hasRoot) {
355
- // there is no root drive, add a default one
356
- drives.root = defaultRootDriveConfig();
357
- }
358
- return drives;
359
- };
360
- export const parse = (str) => {
361
- let toml = {};
362
- for (const s of str) {
363
- toml = mergeTomlTables(toml, parseToml(s));
364
- }
365
- const config = {
366
- drives: parseDrives(toml.drives),
367
- machine: parseMachine(toml.machine),
368
- sdk: parseString(toml.sdk, `${DEFAULT_SDK_IMAGE}:${DEFAULT_SDK_VERSION}`),
369
- };
370
- return config;
371
- };
372
- /**
373
- * Checks if a value is a plain object (TOML table)
374
- */
375
- function isTomlTable(value) {
376
- return (typeof value === "object" &&
377
- value !== null &&
378
- !Array.isArray(value) &&
379
- !("toISOString" in value)); // Check for TomlDate (has toISOString method)
380
- }
381
- /**
382
- * Recursively merges two TOML table objects
383
- * Values from 'other' take precedence over 'base'
384
- *
385
- * @param base - The base TOML table
386
- * @param other - The TOML table to merge into base (takes precedence)
387
- * @returns A new merged TOML table
388
- */
389
- export function mergeTomlTables(base, other) {
390
- const result = { ...base };
391
- for (const [key, otherValue] of Object.entries(other)) {
392
- const baseValue = result[key];
393
- // If both values are tables, merge them recursively
394
- if (isTomlTable(baseValue) && isTomlTable(otherValue)) {
395
- result[key] = mergeTomlTables(baseValue, otherValue);
396
- }
397
- else {
398
- // For all other cases, other value takes precedence
399
- result[key] = otherValue;
400
- }
401
- }
402
- return result;
403
- }
404
- /**
405
- * Merges two TOML values of any type
406
- *
407
- * @param base - The base TOML value
408
- * @param other - The TOML value to merge into base (takes precedence)
409
- * @returns The merged TOML value
410
- */
411
- export function mergeTomlValues(base, other) {
412
- // If both are tables, merge recursively
413
- if (isTomlTable(base) && isTomlTable(other)) {
414
- return mergeTomlTables(base, other);
415
- }
416
- // For arrays, replaces entirely
417
- return other;
418
- }