@dench.com/cli 3.11.18 → 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.
Files changed (3) hide show
  1. package/crm.ts +19 -2
  2. package/dench.ts +46 -10
  3. package/package.json +1 -1
package/crm.ts CHANGED
@@ -3966,12 +3966,20 @@ async function runExportCommand(ctx: CrmCliContext): Promise<void> {
3966
3966
  `crm export: duplicate entry ids detected (${all.length} rows, ${uniqueIds} unique). Export aborted.`,
3967
3967
  );
3968
3968
  }
3969
+ // When each row was added and last changed, so "added this week" can be
3970
+ // answered from the export alone.
3971
+ const isoTime = (value: unknown) =>
3972
+ typeof value === "number" && Number.isFinite(value)
3973
+ ? new Date(value).toISOString()
3974
+ : "";
3969
3975
  if (format === "csv") {
3970
3976
  const fields = Object.keys(all[0]?.fields ?? {});
3971
- const header = ["_id", ...fields].join(",");
3977
+ const header = ["_id", "_createdAt", "_updatedAt", ...fields].join(",");
3972
3978
  const lines = all.map((entry) => {
3973
3979
  const cells = [
3974
3980
  entry.id,
3981
+ isoTime(entry.createdAt),
3982
+ isoTime(entry.updatedAt),
3975
3983
  ...fields.map((f) => csvEscape(entry.fields[f])),
3976
3984
  ];
3977
3985
  return cells.join(",");
@@ -3980,7 +3988,16 @@ async function runExportCommand(ctx: CrmCliContext): Promise<void> {
3980
3988
  } else {
3981
3989
  for (const entry of all) {
3982
3990
  process.stdout.write(
3983
- `${JSON.stringify({ _id: entry.id, ...entry.fields })}\n`,
3991
+ `${JSON.stringify({
3992
+ _id: entry.id,
3993
+ ...(isoTime(entry.createdAt)
3994
+ ? { _createdAt: isoTime(entry.createdAt) }
3995
+ : {}),
3996
+ ...(isoTime(entry.updatedAt)
3997
+ ? { _updatedAt: isoTime(entry.updatedAt) }
3998
+ : {}),
3999
+ ...entry.fields,
4000
+ })}\n`,
3984
4001
  );
3985
4002
  }
3986
4003
  }
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 content = Buffer.concat(chunks).toString("utf8");
3806
-
3807
- const result = (await runtime.client.action(
3808
- api.functions.files.editFileFromUI,
3809
- {
3810
- path: target,
3811
- content,
3812
- apiKey,
3813
- } as never,
3814
- )) as { path: string; contentHash: string };
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 !== ".") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "3.11.18",
3
+ "version": "3.11.20-staging.580",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {