@stndrds/cli 1.0.0-alpha.255 → 1.0.0-alpha.258

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 (2) hide show
  1. package/dist/bin.mjs +27 -11
  2. package/package.json +1 -1
package/dist/bin.mjs CHANGED
@@ -279,6 +279,23 @@ function registerConnectorsCommand(program) {
279
279
  }
280
280
 
281
281
  // src/commands/documents.ts
282
+ var BYTE_UNITS = ["B", "KB", "MB", "GB", "TB"];
283
+ function formatFileSize(bytes) {
284
+ if (bytes <= 0) return "0 B";
285
+ const k = 1e3;
286
+ const unitIndex = Math.min(BYTE_UNITS.length - 1, Math.floor(Math.log(bytes) / Math.log(k)));
287
+ const value = Number.parseFloat((bytes / k ** unitIndex).toFixed(1));
288
+ return `${value} ${BYTE_UNITS[unitIndex]}`;
289
+ }
290
+ function toFileRow(file) {
291
+ return {
292
+ id: file.id,
293
+ position: file.position,
294
+ type: file.mimeType,
295
+ size: formatFileSize(file.size),
296
+ ocrStatus: file.ocrStatus
297
+ };
298
+ }
282
299
  function registerDocumentsCommand(program) {
283
300
  const documents = program.command("documents").description("Manage documents");
284
301
  documents.command("list").description("List documents").option("--limit <n>", "max documents to return").option("--offset <n>", "number of documents to skip").action(async (opts, cmd) => {
@@ -320,23 +337,22 @@ function registerDocumentsCommand(program) {
320
337
  const result = await client.get(`/documents/${id}/preview`);
321
338
  formatOutput(result, getFormat(cmd));
322
339
  });
323
- documents.command("slots").description("List slots for a document").argument("<id>", "document ID").action(async (id, _opts, cmd) => {
340
+ documents.command("files").description("List files in a document's pack (position-ordered)").argument("<id>", "document ID").action(async (id, _opts, cmd) => {
324
341
  const client = getClientFromCommand(cmd);
325
- const result = await client.get(`/documents/${id}/slots`);
326
- formatOutput(result, getFormat(cmd));
342
+ const files = await client.get(`/documents/${id}/files`);
343
+ const sorted = [...files].sort((a, b) => a.position - b.position);
344
+ const format = getFormat(cmd);
345
+ formatOutput(format === "table" ? sorted.map(toFileRow) : sorted, format);
327
346
  });
328
- documents.command("add-slot").description("Add a file slot to a document").argument("<id>", "document ID").requiredOption("--slot-name <name>", "slot name").requiredOption("--file-id <fileId>", "file ID").action(async (id, opts, cmd) => {
347
+ documents.command("add-file").description("Append a file to a document's pack").argument("<id>", "document ID").requiredOption("--file-id <fileId>", "file ID").action(async (id, opts, cmd) => {
329
348
  const client = getClientFromCommand(cmd);
330
- const result = await client.post(`/documents/${id}/slots`, {
331
- slotName: opts.slotName,
332
- fileId: opts.fileId
333
- });
349
+ const result = await client.post(`/documents/${id}/files`, { fileId: opts.fileId });
334
350
  formatOutput(result, getFormat(cmd));
335
351
  });
336
- documents.command("remove-slot").description("Remove a slot from a document").argument("<id>", "document ID").argument("<slotId>", "slot ID").action(async (id, slotId, _opts, cmd) => {
352
+ documents.command("remove-file").description("Remove a file from a document's pack").argument("<id>", "document ID").argument("<fileId>", "file ID").action(async (id, fileId, _opts, cmd) => {
337
353
  const client = getClientFromCommand(cmd);
338
- await client.delete(`/documents/${id}/slots/${slotId}`);
339
- process.stdout.write(`Slot ${slotId} removed.
354
+ await client.delete(`/documents/${id}/files/${fileId}`);
355
+ process.stdout.write(`File ${fileId} removed.
340
356
  `);
341
357
  });
342
358
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stndrds/cli",
3
- "version": "1.0.0-alpha.255",
3
+ "version": "1.0.0-alpha.258",
4
4
  "description": "CLI tool to interact with Standards API",
5
5
  "type": "module",
6
6
  "bin": {