@donezone/cli 0.1.40 → 0.1.41
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/index.js +86 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25983,6 +25983,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
25983
25983
|
import { existsSync as existsSync2 } from "node:fs";
|
|
25984
25984
|
import * as fs from "node:fs/promises";
|
|
25985
25985
|
import path from "node:path";
|
|
25986
|
+
import { TextDecoder as TextDecoder2 } from "node:util";
|
|
25986
25987
|
|
|
25987
25988
|
// ../../node_modules/commander/esm.mjs
|
|
25988
25989
|
var import__ = __toESM(require_commander(), 1);
|
|
@@ -27488,6 +27489,21 @@ class DoneLocalChain {
|
|
|
27488
27489
|
const result = this.runContract(record, "execute", env, info, msg);
|
|
27489
27490
|
return { address, result };
|
|
27490
27491
|
}
|
|
27492
|
+
dumpStorage(address) {
|
|
27493
|
+
const record = this.contracts.get(address);
|
|
27494
|
+
if (!record) {
|
|
27495
|
+
throw new Error(`contract ${address} not found`);
|
|
27496
|
+
}
|
|
27497
|
+
const storage = record.backend.storage;
|
|
27498
|
+
if (!(storage instanceof import_backend.BasicKVIterStorage)) {
|
|
27499
|
+
return [];
|
|
27500
|
+
}
|
|
27501
|
+
const entries = [];
|
|
27502
|
+
storage.dict.forEach((value, key) => {
|
|
27503
|
+
entries.push({ key, value: value ?? "" });
|
|
27504
|
+
});
|
|
27505
|
+
return entries.sort((a, b) => a.key.localeCompare(b.key));
|
|
27506
|
+
}
|
|
27491
27507
|
query(address, msg, options = {}) {
|
|
27492
27508
|
const record = this.contracts.get(address);
|
|
27493
27509
|
if (!record) {
|
|
@@ -42932,6 +42948,48 @@ async function writeJson(file2, data) {
|
|
|
42932
42948
|
const json = JSON.stringify(data, null, 2);
|
|
42933
42949
|
await fs.writeFile(file2, `${json}\n`, "utf8");
|
|
42934
42950
|
}
|
|
42951
|
+
function describeStorageEntry(entry) {
|
|
42952
|
+
const valueBase64 = entry.value ?? "";
|
|
42953
|
+
const keyText = decodeUtf8FromBase64(entry.key);
|
|
42954
|
+
const valueText = decodeUtf8FromBase64(valueBase64);
|
|
42955
|
+
const snapshot = {
|
|
42956
|
+
key: {
|
|
42957
|
+
base64: entry.key,
|
|
42958
|
+
utf8: keyText
|
|
42959
|
+
},
|
|
42960
|
+
value: {
|
|
42961
|
+
base64: valueBase64,
|
|
42962
|
+
utf8: valueText
|
|
42963
|
+
}
|
|
42964
|
+
};
|
|
42965
|
+
const parsed = tryParseJsonLike(valueText);
|
|
42966
|
+
if (parsed !== undefined) {
|
|
42967
|
+
snapshot.value.json = parsed;
|
|
42968
|
+
}
|
|
42969
|
+
return snapshot;
|
|
42970
|
+
}
|
|
42971
|
+
function decodeUtf8FromBase64(base64) {
|
|
42972
|
+
if (!base64)
|
|
42973
|
+
return;
|
|
42974
|
+
try {
|
|
42975
|
+
const bytes2 = Buffer.from(base64, "base64");
|
|
42976
|
+
if (bytes2.length === 0) {
|
|
42977
|
+
return "";
|
|
42978
|
+
}
|
|
42979
|
+
return utf8Decoder2.decode(bytes2);
|
|
42980
|
+
} catch {
|
|
42981
|
+
return;
|
|
42982
|
+
}
|
|
42983
|
+
}
|
|
42984
|
+
function tryParseJsonLike(text) {
|
|
42985
|
+
if (!text)
|
|
42986
|
+
return;
|
|
42987
|
+
try {
|
|
42988
|
+
return JSON.parse(text);
|
|
42989
|
+
} catch {
|
|
42990
|
+
return;
|
|
42991
|
+
}
|
|
42992
|
+
}
|
|
42935
42993
|
async function runCommand(command, args, options = {}) {
|
|
42936
42994
|
await new Promise((resolve3, reject) => {
|
|
42937
42995
|
const child = spawn(command, args, {
|
|
@@ -43093,6 +43151,7 @@ program2.parseAsync().catch((error) => {
|
|
|
43093
43151
|
console.error(error instanceof Error ? error.message : String(error));
|
|
43094
43152
|
process.exit(1);
|
|
43095
43153
|
});
|
|
43154
|
+
var utf8Decoder2 = new TextDecoder2;
|
|
43096
43155
|
var DEV_LOG_PREFIX = import_picocolors.default.bold(import_picocolors.default.cyan("[done dev]"));
|
|
43097
43156
|
var DEV_WARN_PREFIX = import_picocolors.default.bold(import_picocolors.default.yellow("[done dev]"));
|
|
43098
43157
|
var DEV_ERROR_PREFIX = import_picocolors.default.bold(import_picocolors.default.red("[done dev]"));
|
|
@@ -43197,7 +43256,7 @@ class DoneDevOrchestrator {
|
|
|
43197
43256
|
if (contracts.length === 0) {
|
|
43198
43257
|
throw new Error("No contracts defined in done.json. Run `bunx done init <name>` first.");
|
|
43199
43258
|
}
|
|
43200
|
-
return contracts.map((contract) => {
|
|
43259
|
+
return contracts.map((contract, index) => {
|
|
43201
43260
|
if (!contract.entry) {
|
|
43202
43261
|
throw new Error(`Contract '${contract.name}' is missing an entry path.`);
|
|
43203
43262
|
}
|
|
@@ -43207,8 +43266,10 @@ class DoneDevOrchestrator {
|
|
|
43207
43266
|
const entryPath = path.resolve(manifestDir, contract.entry);
|
|
43208
43267
|
const outFilePath = path.resolve(manifestDir, contract.outFile);
|
|
43209
43268
|
const watchGlobs = (contract.watch && contract.watch.length > 0 ? contract.watch : [contract.entry]).map((pattern) => path.resolve(manifestDir, pattern));
|
|
43269
|
+
const slug = toSlug(contract.name) || `contract-${index + 1}`;
|
|
43210
43270
|
return {
|
|
43211
43271
|
name: contract.name,
|
|
43272
|
+
slug,
|
|
43212
43273
|
envKey: toEnvVarKey(contract.name),
|
|
43213
43274
|
entryPath,
|
|
43214
43275
|
outFilePath,
|
|
@@ -43254,6 +43315,7 @@ class DoneDevOrchestrator {
|
|
|
43254
43315
|
contract.address = deployment.address;
|
|
43255
43316
|
this.chain.advanceBlock();
|
|
43256
43317
|
this.logInfo(`${import_picocolors.default.green("\u2022")} ${contract.name} deployed at ${deployment.address}`);
|
|
43318
|
+
await this.dumpContractStorage(contract);
|
|
43257
43319
|
}
|
|
43258
43320
|
}
|
|
43259
43321
|
async startHttpServer() {
|
|
@@ -43323,6 +43385,29 @@ class DoneDevOrchestrator {
|
|
|
43323
43385
|
this.chain.advanceBlock();
|
|
43324
43386
|
await this.writeEnvFile({ DONE_DEV_UPDATED_AT: new Date().toISOString() });
|
|
43325
43387
|
this.logInfo(`${import_picocolors.default.green("\u21BB")} updated ${contract.name} (height ${this.chain.height})`);
|
|
43388
|
+
await this.dumpContractStorage(contract);
|
|
43389
|
+
}
|
|
43390
|
+
async dumpContractStorage(contract) {
|
|
43391
|
+
if (!this.chain || !contract.address)
|
|
43392
|
+
return;
|
|
43393
|
+
let entries;
|
|
43394
|
+
try {
|
|
43395
|
+
entries = this.chain.dumpStorage(contract.address);
|
|
43396
|
+
} catch (error) {
|
|
43397
|
+
this.logWarn(`Unable to snapshot storage for ${contract.name}: ${error.message}`);
|
|
43398
|
+
return;
|
|
43399
|
+
}
|
|
43400
|
+
const snapshot = {
|
|
43401
|
+
contract: contract.name,
|
|
43402
|
+
address: contract.address,
|
|
43403
|
+
height: this.chain.height,
|
|
43404
|
+
updatedAt: new Date().toISOString(),
|
|
43405
|
+
entries: entries.map(describeStorageEntry)
|
|
43406
|
+
};
|
|
43407
|
+
const storageDir = path.join(this.options.workspace.root, ".done", "storage");
|
|
43408
|
+
await fs.mkdir(storageDir, { recursive: true });
|
|
43409
|
+
const filePath = path.join(storageDir, `${contract.slug}.json`);
|
|
43410
|
+
await writeJson(filePath, snapshot);
|
|
43326
43411
|
}
|
|
43327
43412
|
async launchFrontend() {
|
|
43328
43413
|
const frontend = this.options.devConfig.frontend;
|