@dench.com/cli 2.9.9-staging.275 → 3.0.1-staging.284
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/crm.ts +61 -1
- package/dench.ts +15 -2
- package/lib/api-schemas.ts +55 -0
- package/package.json +1 -1
package/crm.ts
CHANGED
|
@@ -1804,6 +1804,20 @@ async function runViewsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
1804
1804
|
const entries = Array.isArray(materialized.entries)
|
|
1805
1805
|
? materialized.entries
|
|
1806
1806
|
: [];
|
|
1807
|
+
// The bare-array output hides `truncated`; say so on stderr so a
|
|
1808
|
+
// clipped view is never mistaken for the full dataset (stdout stays
|
|
1809
|
+
// clean JSON).
|
|
1810
|
+
if (materialized.truncated === true) {
|
|
1811
|
+
const total = materialized.totalCount;
|
|
1812
|
+
const returned =
|
|
1813
|
+
typeof total === "number" && total > entries.length
|
|
1814
|
+
? `${entries.length} of ${total} matching rows returned`
|
|
1815
|
+
: `${entries.length} rows returned; more may match`;
|
|
1816
|
+
process.stderr.write(
|
|
1817
|
+
`warning: view "${readViewName(view) ?? viewName}" on ${objectName} hit the server read budget; ${returned}. ` +
|
|
1818
|
+
`Use 'dench crm query ${objectName} --where …' or 'dench crm export' for the full set.\n`,
|
|
1819
|
+
);
|
|
1820
|
+
}
|
|
1807
1821
|
if (!withMeta) {
|
|
1808
1822
|
out(ctx, entries);
|
|
1809
1823
|
return;
|
|
@@ -2577,6 +2591,52 @@ async function runEntriesCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
2577
2591
|
}
|
|
2578
2592
|
}
|
|
2579
2593
|
|
|
2594
|
+
const SNAPSHOT_RETRY_DELAYS_MS = [300, 900, 2_700];
|
|
2595
|
+
|
|
2596
|
+
/**
|
|
2597
|
+
* A Convex application error (`ConvexError`) carries `data`; a transport
|
|
2598
|
+
* or server blip (fetch failure, 5xx, overloaded) is a plain Error without
|
|
2599
|
+
* it. Only the latter is worth retrying — "Entry not found" will not fix
|
|
2600
|
+
* itself.
|
|
2601
|
+
*/
|
|
2602
|
+
export function isTransientRpcError(error: unknown): boolean {
|
|
2603
|
+
if (!error || typeof error !== "object") return false;
|
|
2604
|
+
if ((error as { data?: unknown }).data !== undefined) return false;
|
|
2605
|
+
return error instanceof Error;
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
/**
|
|
2609
|
+
* One read per target row means a bulk-delete snapshot of N rows is N
|
|
2610
|
+
* sequential round-trips; a single dropped connection used to abort the
|
|
2611
|
+
* whole command ("could not snapshot"). Retry transient failures with a
|
|
2612
|
+
* short backoff before giving up.
|
|
2613
|
+
*/
|
|
2614
|
+
async function queryWithTransientRetry(
|
|
2615
|
+
ctx: CrmCliContext,
|
|
2616
|
+
fn: Parameters<ConvexHttpClient["query"]>[0],
|
|
2617
|
+
args: Record<string, unknown>,
|
|
2618
|
+
): Promise<unknown> {
|
|
2619
|
+
for (let attempt = 0; ; attempt++) {
|
|
2620
|
+
try {
|
|
2621
|
+
return await ctx.convex.query(fn, {
|
|
2622
|
+
...args,
|
|
2623
|
+
...(ctx.sessionToken ? { sessionToken: ctx.sessionToken } : {}),
|
|
2624
|
+
} as never);
|
|
2625
|
+
} catch (error) {
|
|
2626
|
+
const delay = SNAPSHOT_RETRY_DELAYS_MS[attempt];
|
|
2627
|
+
if (delay === undefined || !isTransientRpcError(error)) {
|
|
2628
|
+
throw normalizeRpcError(error);
|
|
2629
|
+
}
|
|
2630
|
+
process.stderr.write(
|
|
2631
|
+
`warning: transient error reading entry for the bulk-delete snapshot ` +
|
|
2632
|
+
`(${error instanceof Error ? error.message : String(error)}); ` +
|
|
2633
|
+
`retrying in ${delay}ms (${attempt + 1}/${SNAPSHOT_RETRY_DELAYS_MS.length}).\n`,
|
|
2634
|
+
);
|
|
2635
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2580
2640
|
/**
|
|
2581
2641
|
* Fetch every target row and write it to a JSONL snapshot under the OS
|
|
2582
2642
|
* temp dir ($TMPDIR or /tmp). This is an automatic undo file, not an
|
|
@@ -2591,7 +2651,7 @@ async function snapshotEntriesBeforeBulkDelete(
|
|
|
2591
2651
|
const lines: string[] = [];
|
|
2592
2652
|
try {
|
|
2593
2653
|
for (const entryId of entryIds) {
|
|
2594
|
-
const entry = await
|
|
2654
|
+
const entry = await queryWithTransientRetry(ctx, api.entries.get, {
|
|
2595
2655
|
objectName,
|
|
2596
2656
|
entryId: entryId as any,
|
|
2597
2657
|
});
|
package/dench.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env tsx
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
4
5
|
import {
|
|
5
6
|
chmod,
|
|
6
7
|
mkdir,
|
|
@@ -3833,7 +3834,20 @@ async function runFilesWrite() {
|
|
|
3833
3834
|
});
|
|
3834
3835
|
}
|
|
3835
3836
|
const target = normalizeFilesPath(targetRaw);
|
|
3836
|
-
|
|
3837
|
+
if (process.stdin.isTTY) {
|
|
3838
|
+
throw new CliError("dench files write reads the new contents from stdin", {
|
|
3839
|
+
code: "files_write_stdin_tty",
|
|
3840
|
+
nextActions: [
|
|
3841
|
+
"Pipe the file in: `dench files write <path> < local.md`.",
|
|
3842
|
+
"Or use `dench stage <local-path> <workspace-path>` to copy a local file.",
|
|
3843
|
+
],
|
|
3844
|
+
});
|
|
3845
|
+
}
|
|
3846
|
+
const chunks: Buffer[] = [];
|
|
3847
|
+
for await (const chunk of process.stdin as AsyncIterable<Buffer>) {
|
|
3848
|
+
chunks.push(chunk);
|
|
3849
|
+
}
|
|
3850
|
+
const content = Buffer.concat(chunks).toString("utf8");
|
|
3837
3851
|
|
|
3838
3852
|
const result = (await runtime.client.action(
|
|
3839
3853
|
api.functions.files.editFileFromUI,
|
|
@@ -4290,7 +4304,6 @@ function sha256HexSync(bytes: Uint8Array): string {
|
|
|
4290
4304
|
// Used by the dench files commands so we can compute the hash
|
|
4291
4305
|
// alongside the upload synchronously. Bun + Node both ship
|
|
4292
4306
|
// node:crypto, so this is free.
|
|
4293
|
-
const { createHash } = require("node:crypto") as typeof import("node:crypto");
|
|
4294
4307
|
return createHash("sha256").update(bytes).digest("hex");
|
|
4295
4308
|
}
|
|
4296
4309
|
|
package/lib/api-schemas.ts
CHANGED
|
@@ -3414,6 +3414,28 @@ export const requestSchemas: Record<string, ZodTypeAny> = {
|
|
|
3414
3414
|
prefix: z.string().optional().describe("Directory path, defaults to /."),
|
|
3415
3415
|
slug: z.string().optional(),
|
|
3416
3416
|
}),
|
|
3417
|
+
"files.content": z.object({
|
|
3418
|
+
path: z
|
|
3419
|
+
.string()
|
|
3420
|
+
.describe(
|
|
3421
|
+
"Workspace file path, e.g. /reports/q2.md. A leading /workspace/ mount prefix is stripped.",
|
|
3422
|
+
),
|
|
3423
|
+
slug: z.string().optional(),
|
|
3424
|
+
}),
|
|
3425
|
+
"files.write": z.object({
|
|
3426
|
+
path: z
|
|
3427
|
+
.string()
|
|
3428
|
+
.describe(
|
|
3429
|
+
"Workspace file path, e.g. /reports/q2.md. A leading /workspace/ mount prefix is stripped.",
|
|
3430
|
+
),
|
|
3431
|
+
content: z.string().describe("Full replacement text (UTF-8, <= 400 KB)."),
|
|
3432
|
+
expectedPreviousHash: z
|
|
3433
|
+
.string()
|
|
3434
|
+
.optional()
|
|
3435
|
+
.describe(
|
|
3436
|
+
"contentHash from the last read; the write is rejected with version_mismatch if the file changed since.",
|
|
3437
|
+
),
|
|
3438
|
+
}),
|
|
3417
3439
|
"files.downloadUrl": z.object({ path: z.string() }),
|
|
3418
3440
|
"files.delete": z.object({ path: z.string() }),
|
|
3419
3441
|
"files.mkdir": z.object({ path: z.string() }),
|
|
@@ -4545,6 +4567,28 @@ export const responseSchemas: Record<string, ZodTypeAny> = {
|
|
|
4545
4567
|
|
|
4546
4568
|
// Files
|
|
4547
4569
|
"files.list": z.array(fileTreeRow),
|
|
4570
|
+
"files.content": z
|
|
4571
|
+
.object({
|
|
4572
|
+
path: z.string(),
|
|
4573
|
+
isDir: z.boolean(),
|
|
4574
|
+
virtual: z.boolean(),
|
|
4575
|
+
size: z.number().nullable(),
|
|
4576
|
+
mtime: z.number().nullable().optional(),
|
|
4577
|
+
content: z
|
|
4578
|
+
.string()
|
|
4579
|
+
.nullable()
|
|
4580
|
+
.describe("Inline text, or null for binary / uncached files."),
|
|
4581
|
+
encoding: z.string().nullable(),
|
|
4582
|
+
contentHash: z.string().nullable().optional(),
|
|
4583
|
+
downloadable: z.boolean(),
|
|
4584
|
+
})
|
|
4585
|
+
.passthrough()
|
|
4586
|
+
.nullable()
|
|
4587
|
+
.describe("The file, or null when nothing exists at the path."),
|
|
4588
|
+
"files.write": z.object({
|
|
4589
|
+
path: z.string().describe("Normalized workspace path that was written."),
|
|
4590
|
+
contentHash: z.string(),
|
|
4591
|
+
}),
|
|
4548
4592
|
"files.downloadUrl": z
|
|
4549
4593
|
.string()
|
|
4550
4594
|
.nullable()
|
|
@@ -6266,6 +6310,17 @@ export const responseExamples: Record<string, unknown> = {
|
|
|
6266
6310
|
lastModifiedBy: "api-v1",
|
|
6267
6311
|
},
|
|
6268
6312
|
],
|
|
6313
|
+
"files.content": {
|
|
6314
|
+
path: "/README.md",
|
|
6315
|
+
isDir: false,
|
|
6316
|
+
virtual: false,
|
|
6317
|
+
size: 2048,
|
|
6318
|
+
content: "# Acme workspace\n",
|
|
6319
|
+
encoding: "utf-8",
|
|
6320
|
+
contentHash: "9f86d081884c7d65",
|
|
6321
|
+
downloadable: true,
|
|
6322
|
+
},
|
|
6323
|
+
"files.write": { path: "/reports/q2.md", contentHash: "9f86d081884c7d65" },
|
|
6269
6324
|
"files.downloadUrl":
|
|
6270
6325
|
"https://happy-animal-123.convex.cloud/api/storage/abc123?download=README.md",
|
|
6271
6326
|
"files.delete": { path: "/README.md" },
|