@cartesi/cli 1.5.0 → 2.0.0-alpha.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/dist/baseCommand.d.ts +2 -0
- package/dist/baseCommand.d.ts.map +1 -1
- package/dist/baseCommand.js +10 -5
- package/dist/builder/directory.d.ts +3 -0
- package/dist/builder/directory.d.ts.map +1 -0
- package/dist/builder/directory.js +37 -0
- package/dist/builder/docker.d.ts +10 -0
- package/dist/builder/docker.d.ts.map +1 -0
- package/dist/builder/docker.js +112 -0
- package/dist/builder/empty.d.ts +3 -0
- package/dist/builder/empty.d.ts.map +1 -0
- package/dist/builder/empty.js +21 -0
- package/dist/builder/index.d.ts +6 -0
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +5 -0
- package/dist/builder/none.d.ts +3 -0
- package/dist/builder/none.d.ts.map +1 -0
- package/dist/builder/none.js +11 -0
- package/dist/builder/tar.d.ts +3 -0
- package/dist/builder/tar.d.ts.map +1 -0
- package/dist/builder/tar.js +30 -0
- package/dist/commands/build.d.ts +3 -15
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +53 -194
- package/dist/commands/shell.d.ts +2 -1
- package/dist/commands/shell.d.ts.map +1 -1
- package/dist/commands/shell.js +41 -41
- package/dist/config.d.ts +103 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +378 -0
- package/dist/contracts.d.ts +492 -1038
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +223 -498
- package/dist/exec/cartesi-machine.d.ts +9 -0
- package/dist/exec/cartesi-machine.d.ts.map +1 -0
- package/dist/exec/cartesi-machine.js +20 -0
- package/dist/exec/crane.d.ts +15 -0
- package/dist/exec/crane.d.ts.map +1 -0
- package/dist/exec/crane.js +17 -0
- package/dist/exec/genext2fs.d.ts +28 -0
- package/dist/exec/genext2fs.d.ts.map +1 -0
- package/dist/exec/genext2fs.js +44 -0
- package/dist/exec/index.d.ts +5 -0
- package/dist/exec/index.d.ts.map +1 -0
- package/dist/exec/index.js +4 -0
- package/dist/exec/mksquashfs.d.ts +21 -0
- package/dist/exec/mksquashfs.d.ts.map +1 -0
- package/dist/exec/mksquashfs.js +45 -0
- package/dist/exec/util.d.ts +36 -0
- package/dist/exec/util.d.ts.map +1 -0
- package/dist/exec/util.js +78 -0
- package/dist/machine.d.ts +6 -0
- package/dist/machine.d.ts.map +1 -0
- package/dist/machine.js +80 -0
- package/dist/node/docker-compose-anvil.yaml +4 -3
- package/dist/node/docker-compose-bundler.yaml +1 -1
- package/dist/node/docker-compose-paymaster.yaml +1 -1
- package/oclif.manifest.json +32 -95
- package/package.json +7 -7
- package/dist/commands/send/dapp-address.d.ts +0 -9
- package/dist/commands/send/dapp-address.d.ts.map +0 -1
- package/dist/commands/send/dapp-address.js +0 -20
package/dist/config.js
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import bytes from "bytes";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import { extname } from "path";
|
|
4
|
+
import { parse as parseToml } from "smol-toml";
|
|
5
|
+
/**
|
|
6
|
+
* Typed Errors
|
|
7
|
+
*/
|
|
8
|
+
export class InvalidBuilderError extends Error {
|
|
9
|
+
constructor(builder) {
|
|
10
|
+
super(`Invalid builder: ${builder}`);
|
|
11
|
+
this.name = "InvalidBuilder";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class InvalidDriveFormatError extends Error {
|
|
15
|
+
constructor(format) {
|
|
16
|
+
super(`Invalid drive format: ${format}`);
|
|
17
|
+
this.name = "InvalidDriveFormatError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class InvalidEmptyDriveFormatError extends Error {
|
|
21
|
+
constructor(format) {
|
|
22
|
+
super(`Invalid empty drive format: ${format}`);
|
|
23
|
+
this.name = "InvalidEmptyDriveFormatError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class InvalidStringValueError extends Error {
|
|
27
|
+
constructor(value) {
|
|
28
|
+
super(`Invalid string value: ${value}`);
|
|
29
|
+
this.name = "InvalidStringValueError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class InvalidBooleanValueError extends Error {
|
|
33
|
+
constructor(value) {
|
|
34
|
+
super(`Invalid boolean value: ${value}`);
|
|
35
|
+
this.name = "InvalidBooleanValueError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class InvalidNumberValueError extends Error {
|
|
39
|
+
constructor(value) {
|
|
40
|
+
super(`Invalid number value: ${value}`);
|
|
41
|
+
this.name = "InvalidNumberValueError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class InvalidBytesValueError extends Error {
|
|
45
|
+
constructor(value) {
|
|
46
|
+
super(`Invalid bytes value: ${value}`);
|
|
47
|
+
this.name = "InvalidBytesValueError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class RequiredFieldError extends Error {
|
|
51
|
+
constructor(key) {
|
|
52
|
+
super(`Missing required field: ${key}`);
|
|
53
|
+
this.name = "RequiredFieldError";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class InvalidStringArrayError extends Error {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(`Invalid string array`);
|
|
59
|
+
this.name = "InvalidStringArrayError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for drives of a Cartesi Machine. A drive may already exist or be built by a builder
|
|
64
|
+
*/
|
|
65
|
+
const DEFAULT_FORMAT = "ext2";
|
|
66
|
+
const DEFAULT_RAM = "128Mi";
|
|
67
|
+
const DEFAULT_RAM_IMAGE_DOCKER = "/usr/share/cartesi-machine/images/linux.bin";
|
|
68
|
+
const DEFAULT_RAM_IMAGE_LINUX = "/usr/share/cartesi-machine/images/linux.bin";
|
|
69
|
+
const DEFAULT_RAM_IMAGE_MAC = "/opt/homebrew/share/cartesi-machine/images/linux.bin";
|
|
70
|
+
export const DEFAULT_SDK = "cartesi/sdk:0.12.0-alpha.0";
|
|
71
|
+
export const defaultRootDriveConfig = () => ({
|
|
72
|
+
builder: "docker",
|
|
73
|
+
context: ".",
|
|
74
|
+
dockerfile: "Dockerfile", // file on current working directory
|
|
75
|
+
extraSize: 0,
|
|
76
|
+
format: DEFAULT_FORMAT,
|
|
77
|
+
tags: [],
|
|
78
|
+
});
|
|
79
|
+
export const defaultRamImage = () => {
|
|
80
|
+
switch (os.platform()) {
|
|
81
|
+
case "darwin":
|
|
82
|
+
return DEFAULT_RAM_IMAGE_MAC;
|
|
83
|
+
default:
|
|
84
|
+
return DEFAULT_RAM_IMAGE_LINUX;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export const defaultMachineConfig = () => ({
|
|
88
|
+
assertRollingTemplate: undefined,
|
|
89
|
+
bootargs: [],
|
|
90
|
+
entrypoint: undefined,
|
|
91
|
+
finalHash: true,
|
|
92
|
+
interactive: undefined,
|
|
93
|
+
maxMCycle: undefined,
|
|
94
|
+
noRollup: undefined,
|
|
95
|
+
ramLength: DEFAULT_RAM,
|
|
96
|
+
ramImage: defaultRamImage(),
|
|
97
|
+
store: "image",
|
|
98
|
+
user: undefined,
|
|
99
|
+
});
|
|
100
|
+
export const defaultConfig = () => ({
|
|
101
|
+
drives: { root: defaultRootDriveConfig() },
|
|
102
|
+
machine: defaultMachineConfig(),
|
|
103
|
+
sdk: DEFAULT_SDK,
|
|
104
|
+
});
|
|
105
|
+
const parseBoolean = (value, defaultValue) => {
|
|
106
|
+
if (value === undefined) {
|
|
107
|
+
return defaultValue;
|
|
108
|
+
}
|
|
109
|
+
else if (typeof value === "boolean") {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
throw new InvalidBooleanValueError(value);
|
|
113
|
+
};
|
|
114
|
+
const parseOptionalBoolean = (value) => {
|
|
115
|
+
if (value === undefined) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
else if (typeof value === "boolean") {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
throw new InvalidBooleanValueError(value);
|
|
122
|
+
};
|
|
123
|
+
const parseString = (value, defaultValue) => {
|
|
124
|
+
if (value === undefined) {
|
|
125
|
+
return defaultValue;
|
|
126
|
+
}
|
|
127
|
+
else if (typeof value === "string") {
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
throw new InvalidStringValueError(value);
|
|
131
|
+
};
|
|
132
|
+
const parseStringArray = (value) => {
|
|
133
|
+
if (value === undefined) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
else if (typeof value === "string") {
|
|
137
|
+
return [value];
|
|
138
|
+
}
|
|
139
|
+
else if (typeof value === "object" && Array.isArray(value)) {
|
|
140
|
+
return value.map((v) => {
|
|
141
|
+
if (typeof v === "string") {
|
|
142
|
+
return v;
|
|
143
|
+
}
|
|
144
|
+
throw new InvalidStringValueError(v);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
throw new InvalidStringArrayError();
|
|
148
|
+
};
|
|
149
|
+
const parseRequiredString = (value, key) => {
|
|
150
|
+
if (value === undefined) {
|
|
151
|
+
throw new RequiredFieldError(key);
|
|
152
|
+
}
|
|
153
|
+
else if (typeof value === "string") {
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
throw new InvalidStringValueError(value);
|
|
157
|
+
};
|
|
158
|
+
const parseOptionalString = (value) => {
|
|
159
|
+
if (value === undefined) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
else if (typeof value === "string") {
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
throw new InvalidStringValueError(value);
|
|
166
|
+
};
|
|
167
|
+
const parseOptionalStringBoolean = (value) => {
|
|
168
|
+
if (value === undefined) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
else if (typeof value === "string") {
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
else if (typeof value === "boolean") {
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
throw new InvalidStringValueError(value);
|
|
178
|
+
};
|
|
179
|
+
const parseOptionalNumber = (value) => {
|
|
180
|
+
if (value === undefined) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
else if (typeof value === "bigint") {
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
else if (typeof value === "number") {
|
|
187
|
+
return BigInt(value);
|
|
188
|
+
}
|
|
189
|
+
throw new InvalidNumberValueError(value);
|
|
190
|
+
};
|
|
191
|
+
const parseBytes = (value, defaultValue) => {
|
|
192
|
+
if (value === undefined) {
|
|
193
|
+
return defaultValue;
|
|
194
|
+
}
|
|
195
|
+
else if (typeof value === "bigint") {
|
|
196
|
+
return Number(value);
|
|
197
|
+
}
|
|
198
|
+
else if (typeof value === "number" || typeof value === "string") {
|
|
199
|
+
const output = bytes.parse(value);
|
|
200
|
+
if (output !== null) {
|
|
201
|
+
return output;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
throw new InvalidBytesValueError(value);
|
|
205
|
+
};
|
|
206
|
+
const parseBuilder = (value) => {
|
|
207
|
+
if (value === undefined) {
|
|
208
|
+
return "docker";
|
|
209
|
+
}
|
|
210
|
+
else if (typeof value === "string") {
|
|
211
|
+
switch (value) {
|
|
212
|
+
case "directory":
|
|
213
|
+
return "directory";
|
|
214
|
+
case "docker":
|
|
215
|
+
return "docker";
|
|
216
|
+
case "empty":
|
|
217
|
+
return "empty";
|
|
218
|
+
case "none":
|
|
219
|
+
return "none";
|
|
220
|
+
case "tar":
|
|
221
|
+
return "tar";
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
throw new InvalidBuilderError(value);
|
|
225
|
+
};
|
|
226
|
+
const parseFormat = (value) => {
|
|
227
|
+
if (value === undefined) {
|
|
228
|
+
return DEFAULT_FORMAT;
|
|
229
|
+
}
|
|
230
|
+
else if (typeof value === "string") {
|
|
231
|
+
switch (value) {
|
|
232
|
+
case "ext2":
|
|
233
|
+
return "ext2";
|
|
234
|
+
case "sqfs":
|
|
235
|
+
return "sqfs";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
throw new InvalidDriveFormatError(value);
|
|
239
|
+
};
|
|
240
|
+
const parseEmptyFormat = (value) => {
|
|
241
|
+
if (value === undefined) {
|
|
242
|
+
return DEFAULT_FORMAT;
|
|
243
|
+
}
|
|
244
|
+
else if (typeof value === "string") {
|
|
245
|
+
switch (value) {
|
|
246
|
+
case "ext2":
|
|
247
|
+
return "ext2";
|
|
248
|
+
case "raw":
|
|
249
|
+
return "raw";
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
throw new InvalidEmptyDriveFormatError(value);
|
|
253
|
+
};
|
|
254
|
+
const parseMachine = (value) => {
|
|
255
|
+
if (value === undefined) {
|
|
256
|
+
// default machine
|
|
257
|
+
return defaultMachineConfig();
|
|
258
|
+
}
|
|
259
|
+
if (typeof value !== "object") {
|
|
260
|
+
throw new Error(`Invalid machine configuration: ${value}`);
|
|
261
|
+
}
|
|
262
|
+
const toml = value;
|
|
263
|
+
return {
|
|
264
|
+
assertRollingTemplate: parseOptionalBoolean(toml["assert-rolling-template"]),
|
|
265
|
+
bootargs: parseStringArray(toml.bootargs),
|
|
266
|
+
finalHash: parseBoolean(toml["final-hash"], true),
|
|
267
|
+
interactive: undefined,
|
|
268
|
+
maxMCycle: parseOptionalNumber(toml["max-mcycle"]),
|
|
269
|
+
noRollup: parseBoolean(toml["no-rollup"], false),
|
|
270
|
+
ramLength: parseString(toml["ram-length"], DEFAULT_RAM),
|
|
271
|
+
ramImage: parseString(toml["ram-image"], defaultRamImage()),
|
|
272
|
+
store: "image",
|
|
273
|
+
user: parseOptionalString(toml.user),
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
export const getDriveFormat = (filename) => {
|
|
277
|
+
const extension = extname(filename);
|
|
278
|
+
switch (extension) {
|
|
279
|
+
case ".ext2":
|
|
280
|
+
return "ext2";
|
|
281
|
+
case ".sqfs":
|
|
282
|
+
return "sqfs";
|
|
283
|
+
default:
|
|
284
|
+
throw new InvalidDriveFormatError(extension);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const parseDrive = (drive) => {
|
|
288
|
+
const builder = parseBuilder(drive.builder);
|
|
289
|
+
switch (builder) {
|
|
290
|
+
case "directory": {
|
|
291
|
+
const { extraSize, format, mount, directory, shared, user } = drive;
|
|
292
|
+
return {
|
|
293
|
+
builder: "directory",
|
|
294
|
+
extraSize: parseBytes(extraSize, 0),
|
|
295
|
+
format: parseFormat(format),
|
|
296
|
+
mount: parseOptionalStringBoolean(mount),
|
|
297
|
+
directory: parseRequiredString(directory, "directory"),
|
|
298
|
+
shared: parseOptionalBoolean(shared),
|
|
299
|
+
user: parseOptionalString(user),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
case "docker": {
|
|
303
|
+
const { context, dockerfile, extraSize, format, image, mount, shared, tags, target, user, } = drive;
|
|
304
|
+
return {
|
|
305
|
+
builder: "docker",
|
|
306
|
+
image: parseOptionalString(image),
|
|
307
|
+
context: parseString(context, "."),
|
|
308
|
+
dockerfile: parseString(dockerfile, "Dockerfile"),
|
|
309
|
+
extraSize: parseBytes(extraSize, 0),
|
|
310
|
+
format: parseFormat(format),
|
|
311
|
+
mount: parseOptionalStringBoolean(mount),
|
|
312
|
+
shared: parseOptionalBoolean(shared),
|
|
313
|
+
user: parseOptionalString(user),
|
|
314
|
+
tags: parseStringArray(tags),
|
|
315
|
+
target: parseOptionalString(target),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
case "empty": {
|
|
319
|
+
const { format, mount, size, shared, user } = drive;
|
|
320
|
+
return {
|
|
321
|
+
builder: "empty",
|
|
322
|
+
format: parseEmptyFormat(format),
|
|
323
|
+
mount: parseOptionalStringBoolean(mount),
|
|
324
|
+
shared: parseOptionalBoolean(shared),
|
|
325
|
+
size: parseBytes(size, 0),
|
|
326
|
+
user: parseOptionalString(user),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
case "tar": {
|
|
330
|
+
const { extraSize, filename, format, mount, shared, user } = drive;
|
|
331
|
+
return {
|
|
332
|
+
builder: "tar",
|
|
333
|
+
extraSize: parseBytes(extraSize, 0),
|
|
334
|
+
filename: parseRequiredString(filename, "filename"),
|
|
335
|
+
format: parseFormat(format),
|
|
336
|
+
mount: parseOptionalStringBoolean(mount),
|
|
337
|
+
shared: parseOptionalBoolean(shared),
|
|
338
|
+
user: parseOptionalString(user),
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
case "none": {
|
|
342
|
+
const { shared, mount, user } = drive;
|
|
343
|
+
const filename = parseRequiredString(drive.filename, "filename");
|
|
344
|
+
const format = getDriveFormat(filename);
|
|
345
|
+
return {
|
|
346
|
+
builder: "none",
|
|
347
|
+
filename,
|
|
348
|
+
format,
|
|
349
|
+
mount: parseOptionalStringBoolean(mount),
|
|
350
|
+
shared: parseOptionalBoolean(shared),
|
|
351
|
+
user: parseOptionalString(user),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const parseDrives = (config) => {
|
|
357
|
+
// load drives from configuration
|
|
358
|
+
const drives = Object.entries(config ?? {}).reduce((acc, [name, drive]) => {
|
|
359
|
+
acc[name] = parseDrive(drive);
|
|
360
|
+
return acc;
|
|
361
|
+
}, {});
|
|
362
|
+
// check if there is a root drive
|
|
363
|
+
const hasRoot = drives.root !== undefined;
|
|
364
|
+
if (!hasRoot) {
|
|
365
|
+
// there is no root drive, add a default one
|
|
366
|
+
drives.root = defaultRootDriveConfig();
|
|
367
|
+
}
|
|
368
|
+
return drives;
|
|
369
|
+
};
|
|
370
|
+
export const parse = (str) => {
|
|
371
|
+
const toml = parseToml(str);
|
|
372
|
+
const config = {
|
|
373
|
+
drives: parseDrives(toml.drives),
|
|
374
|
+
machine: parseMachine(toml.machine),
|
|
375
|
+
sdk: parseString(toml.sdk, DEFAULT_SDK),
|
|
376
|
+
};
|
|
377
|
+
return config;
|
|
378
|
+
};
|