@stndrds/cli 1.0.0-alpha.209 → 1.0.0-alpha.211
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/dist/bin.mjs +42 -12
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -87,6 +87,9 @@ function getGlobalOptions(cmd) {
|
|
|
87
87
|
function getFormat(cmd) {
|
|
88
88
|
return getGlobalOptions(cmd).format;
|
|
89
89
|
}
|
|
90
|
+
function parseCsvList(value) {
|
|
91
|
+
return value.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
|
|
92
|
+
}
|
|
90
93
|
function getClientFromCommand(cmd) {
|
|
91
94
|
const root = getGlobalOptions(cmd);
|
|
92
95
|
if (!(root.apiUrl && root.apiKey)) {
|
|
@@ -178,6 +181,25 @@ function formatOutput(data, format) {
|
|
|
178
181
|
`);
|
|
179
182
|
}
|
|
180
183
|
|
|
184
|
+
// src/commands/autofill.ts
|
|
185
|
+
function registerAutofillCommand(program) {
|
|
186
|
+
const autofill = program.command("autofill").description("AI attribute autofill (backfill empty record fields)");
|
|
187
|
+
autofill.command("backfill").description("Dry-run estimate (default) or enqueue an autofill backfill job").requiredOption("--objects <ids>", "comma-separated object IDs to backfill").option("--max-records <n>", "cap the number of records processed").option("--confirm", "enqueue the job instead of returning a dry-run estimate").action(
|
|
188
|
+
async (opts, cmd) => {
|
|
189
|
+
const objectIds = parseCsvList(opts.objects);
|
|
190
|
+
if (objectIds.length === 0) {
|
|
191
|
+
throw new Error("--objects requires at least one object ID");
|
|
192
|
+
}
|
|
193
|
+
const client = getClientFromCommand(cmd);
|
|
194
|
+
const body = { objectIds };
|
|
195
|
+
if (opts.maxRecords) body.maxRecords = Number(opts.maxRecords);
|
|
196
|
+
if (opts.confirm) body.confirm = true;
|
|
197
|
+
const result = await client.post("/autofill/backfill", body);
|
|
198
|
+
formatOutput(result, getFormat(cmd));
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
181
203
|
// src/commands/documents.ts
|
|
182
204
|
function registerDocumentsCommand(program) {
|
|
183
205
|
const documents = program.command("documents").description("Manage documents");
|
|
@@ -279,15 +301,23 @@ function parseSortFlag(sort) {
|
|
|
279
301
|
const [attribute, direction = "asc"] = sort.split(":");
|
|
280
302
|
return [{ attribute, direction }];
|
|
281
303
|
}
|
|
304
|
+
function buildQueryBody(opts) {
|
|
305
|
+
const body = {};
|
|
306
|
+
if (opts.limit) body.limit = Number(opts.limit);
|
|
307
|
+
if (opts.offset) body.offset = Number(opts.offset);
|
|
308
|
+
if (opts.sort) body.sorts = parseSortFlag(opts.sort);
|
|
309
|
+
if (opts.filter) body.filters = JSON.parse(opts.filter);
|
|
310
|
+
if (opts.fields !== void 0) body.fields = parseCsvList(opts.fields);
|
|
311
|
+
return body;
|
|
312
|
+
}
|
|
282
313
|
function registerRecordsCommand(program) {
|
|
283
314
|
const records = program.command("records").description("Manage records (CRUD + search)");
|
|
284
|
-
records.command("list").description("List records for an object").argument("<object>", "object name (e.g. contacts)").option("--limit <n>", "max records to return").option("--offset <n>", "number of records to skip").option("--sort <sort>", 'sort rule as "attribute:direction"').option("--filter <json>", "filter state as JSON string").
|
|
315
|
+
records.command("list").description("List records for an object").argument("<object>", "object name (e.g. contacts)").option("--limit <n>", "max records to return").option("--offset <n>", "number of records to skip").option("--sort <sort>", 'sort rule as "attribute:direction"').option("--filter <json>", "filter state as JSON string").option(
|
|
316
|
+
"--fields <names>",
|
|
317
|
+
"comma-separated reference attributes to hydrate (empty for none, omit for all)"
|
|
318
|
+
).action(async (objectName, opts, cmd) => {
|
|
285
319
|
const client = getClientFromCommand(cmd);
|
|
286
|
-
const body =
|
|
287
|
-
if (opts.limit) body.limit = Number(opts.limit);
|
|
288
|
-
if (opts.offset) body.offset = Number(opts.offset);
|
|
289
|
-
if (opts.sort) body.sorts = parseSortFlag(opts.sort);
|
|
290
|
-
if (opts.filter) body.filters = JSON.parse(opts.filter);
|
|
320
|
+
const body = buildQueryBody(opts);
|
|
291
321
|
const result = await client.post(`/records/${objectName}/list`, body);
|
|
292
322
|
formatOutput(result, getFormat(cmd));
|
|
293
323
|
});
|
|
@@ -314,13 +344,12 @@ function registerRecordsCommand(program) {
|
|
|
314
344
|
process.stdout.write(`Record ${id} deleted.
|
|
315
345
|
`);
|
|
316
346
|
});
|
|
317
|
-
records.command("search").description("Full-text search records").argument("<object>", "object name").requiredOption("--query <q>", "search query string").option("--limit <n>", "max records to return").option("--offset <n>", "number of records to skip").option("--sort <sort>", 'sort rule as "attribute:direction"').option("--filter <json>", "filter state as JSON string").
|
|
347
|
+
records.command("search").description("Full-text search records").argument("<object>", "object name").requiredOption("--query <q>", "search query string").option("--limit <n>", "max records to return").option("--offset <n>", "number of records to skip").option("--sort <sort>", 'sort rule as "attribute:direction"').option("--filter <json>", "filter state as JSON string").option(
|
|
348
|
+
"--fields <names>",
|
|
349
|
+
"comma-separated reference attributes to hydrate (empty for none, omit for all)"
|
|
350
|
+
).action(async (objectName, opts, cmd) => {
|
|
318
351
|
const client = getClientFromCommand(cmd);
|
|
319
|
-
const body = { q: opts.query };
|
|
320
|
-
if (opts.limit) body.limit = Number(opts.limit);
|
|
321
|
-
if (opts.offset) body.offset = Number(opts.offset);
|
|
322
|
-
if (opts.sort) body.sorts = parseSortFlag(opts.sort);
|
|
323
|
-
if (opts.filter) body.filters = JSON.parse(opts.filter);
|
|
352
|
+
const body = { q: opts.query, ...buildQueryBody(opts) };
|
|
324
353
|
const result = await client.post(`/records/${objectName}/search`, body);
|
|
325
354
|
formatOutput(result, getFormat(cmd));
|
|
326
355
|
});
|
|
@@ -731,6 +760,7 @@ function createProgram() {
|
|
|
731
760
|
registerDocumentsCommand(program);
|
|
732
761
|
registerKeysCommand(program);
|
|
733
762
|
registerAuthCommand(program);
|
|
763
|
+
registerAutofillCommand(program);
|
|
734
764
|
program.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
735
765
|
const raw = program.opts();
|
|
736
766
|
const resolved = await resolveCliConfig({
|