mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-10-28 07:41:23 +00:00
feat: PostgREST-style document filtering and ordering
GET /collections/:id/documents accepts filter (field.op.value terms; eq neq gt gte lt lte like in is; dotted paths index into document data) and order (field.asc|desc). Whitelisted field/operator parsing with parameterized values; plain lists keep the sqlc path. CLI gains `documents list --collection --filter --order`; OpenAPI + generated client updated. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
f9e7002048
commit
8892c6dc43
11 files changed
+489
-8
No files matched your search
@@ -2,6 +2,7 @@ import { cac } from "cac";
|
||||
|
||||
import { cmdLogin, cmdLogout, cmdWhoami } from "./commands/auth.js";
|
||||
import { cmdAuditList } from "./commands/audit.js";
|
||||
import { cmdDocumentsList } from "./commands/documents.js";
|
||||
import { cmdBucketsCreate, cmdBucketsList } from "./commands/buckets.js";
|
||||
import { cmdContext, cmdUse } from "./commands/context.js";
|
||||
import { cmdInject } from "./commands/inject.js";
|
||||
@@ -156,6 +157,16 @@ cli
|
||||
.option("--yes", "Skip the confirmation prompt")
|
||||
.action(cmdJobsRemove);
|
||||
|
||||
cli
|
||||
.command("documents:list", "List documents in a collection (PostgREST-style --filter/--order)")
|
||||
.option("--collection <slug|id>", "Collection slug or id (required)")
|
||||
.option("--project <id>", "Project override")
|
||||
.option("--filter <expr>", "field.op.value terms, comma-separated (eq neq gt gte lt lte like in is)")
|
||||
.option("--order <expr>", "field.asc|field.desc list")
|
||||
.option("--limit <n>", "Page size (default 50)")
|
||||
.option("--offset <n>", "Page offset")
|
||||
.action(cmdDocumentsList);
|
||||
|
||||
cli
|
||||
.command("audit:list", "List audit events for the current project")
|
||||
.option("--project <id>", "Project override")
|
||||
@@ -289,6 +300,7 @@ const GROUPS = new Set([
|
||||
"projects",
|
||||
"buckets",
|
||||
"objects",
|
||||
"documents",
|
||||
"keys",
|
||||
"jobs",
|
||||
"audit",
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { CollectionsService } from "@primora/api-client";
|
||||
|
||||
import { loadConfig } from "../config.js";
|
||||
import { CliError, configureClient, requireAuth, requireProject } from "../http.js";
|
||||
import { formatDate, isJson, printJson, printTable } from "../out.js";
|
||||
|
||||
interface DocumentsListOptions {
|
||||
project?: string;
|
||||
collection?: string;
|
||||
filter?: string;
|
||||
order?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
json?: boolean;
|
||||
}
|
||||
|
||||
// Accepts a collection id or slug.
|
||||
async function collectionIdFor(projectId: string, ref: string): Promise<string> {
|
||||
const { items } = await CollectionsService.listCollections({ projectId });
|
||||
const match = items.find((c) => c.id === ref || c.slug === ref || c.name === ref);
|
||||
if (!match) {
|
||||
throw new CliError(
|
||||
`Collection "${ref}" not found.`,
|
||||
`Known: ${items.map((c) => c.slug).join(", ") || "(none)"}`,
|
||||
);
|
||||
}
|
||||
return match.id;
|
||||
}
|
||||
|
||||
export async function cmdDocumentsList(options: DocumentsListOptions): Promise<void> {
|
||||
if (!options.collection) {
|
||||
throw new CliError("Missing --collection <slug|id>.");
|
||||
}
|
||||
const cfg = loadConfig();
|
||||
requireAuth(cfg);
|
||||
configureClient(cfg);
|
||||
|
||||
const projectId = requireProject(cfg, options.project);
|
||||
const collectionId = await collectionIdFor(projectId, options.collection);
|
||||
const res = await CollectionsService.listDocuments({
|
||||
collectionId,
|
||||
limit: options.limit,
|
||||
offset: options.offset,
|
||||
filter: options.filter,
|
||||
order: options.order,
|
||||
});
|
||||
if (isJson(options)) {
|
||||
printJson(res);
|
||||
return;
|
||||
}
|
||||
if (!res.items.length) {
|
||||
console.log("No documents.");
|
||||
return;
|
||||
}
|
||||
printTable(
|
||||
["ID", "DATA", "UPDATED"],
|
||||
res.items.map((d) => [
|
||||
d.id.slice(0, 8),
|
||||
JSON.stringify(d.data).slice(0, 80),
|
||||
formatDate(d.updated_at),
|
||||
]),
|
||||
);
|
||||
console.log(`${res.items.length} of ${res.total}`);
|
||||
}
|
||||
Reference in new issue
Block a user