@dench.com/cli 3.11.19-staging.578 → 3.11.20-staging.580
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/dench.ts +46 -10
- package/package.json +1 -1
package/dench.ts
CHANGED
|
@@ -3802,16 +3802,20 @@ async function runFilesWrite() {
|
|
|
3802
3802
|
for await (const chunk of process.stdin as AsyncIterable<Buffer>) {
|
|
3803
3803
|
chunks.push(chunk);
|
|
3804
3804
|
}
|
|
3805
|
-
const
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3805
|
+
const raw = Buffer.concat(chunks);
|
|
3806
|
+
const content = raw.toString("utf8");
|
|
3807
|
+
|
|
3808
|
+
// The inline edit takes up to 400,000 characters. A bigger file (a large
|
|
3809
|
+
// CSV export) goes up as bytes, the way `dench stage` saves one, instead
|
|
3810
|
+
// of failing.
|
|
3811
|
+
const result =
|
|
3812
|
+
content.length > FILES_WRITE_INLINE_MAX_CHARS
|
|
3813
|
+
? await uploadWrittenFile(runtime, apiKey, target, new Uint8Array(raw))
|
|
3814
|
+
: ((await runtime.client.action(api.functions.files.editFileFromUI, {
|
|
3815
|
+
path: target,
|
|
3816
|
+
content,
|
|
3817
|
+
apiKey,
|
|
3818
|
+
} as never)) as { path: string; contentHash: string });
|
|
3815
3819
|
|
|
3816
3820
|
if (json) {
|
|
3817
3821
|
print({ ok: true, ...result, bytes: Buffer.byteLength(content, "utf8") });
|
|
@@ -3822,6 +3826,38 @@ async function runFilesWrite() {
|
|
|
3822
3826
|
);
|
|
3823
3827
|
}
|
|
3824
3828
|
|
|
3829
|
+
/** `editFileFromUI` refuses content longer than this many characters. */
|
|
3830
|
+
const FILES_WRITE_INLINE_MAX_CHARS = 400_000;
|
|
3831
|
+
|
|
3832
|
+
/** Saves a large write through storage, with the parent folders the tree
|
|
3833
|
+
* needs to show it (as `dench stage` records them). */
|
|
3834
|
+
async function uploadWrittenFile(
|
|
3835
|
+
runtime: Runtime,
|
|
3836
|
+
apiKey: string,
|
|
3837
|
+
path: string,
|
|
3838
|
+
bytes: Uint8Array,
|
|
3839
|
+
): Promise<{ path: string; contentHash: string }> {
|
|
3840
|
+
for (
|
|
3841
|
+
let parent = parentOfPath(path);
|
|
3842
|
+
parent && parent !== "/";
|
|
3843
|
+
parent = parentOfPath(parent)
|
|
3844
|
+
) {
|
|
3845
|
+
try {
|
|
3846
|
+
await runtime.client.mutation(api.functions.files.recordDirCreate, {
|
|
3847
|
+
path: parent,
|
|
3848
|
+
apiKey,
|
|
3849
|
+
} as never);
|
|
3850
|
+
} catch {
|
|
3851
|
+
// Best-effort, as in `dench stage`: the file itself is what matters.
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
const { contentHash } = await uploadConvexFileBytes(runtime, apiKey, {
|
|
3855
|
+
path,
|
|
3856
|
+
bytes,
|
|
3857
|
+
});
|
|
3858
|
+
return { path, contentHash };
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3825
3861
|
async function writeLocalFileBytes(localPath: string, bytes: Uint8Array) {
|
|
3826
3862
|
const parent = dirname(localPath);
|
|
3827
3863
|
if (parent && parent !== ".") {
|