zinkee 0.1.59 → 0.1.60

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/index.js CHANGED
@@ -252,7 +252,7 @@ ${list}`
252
252
  };
253
253
  }
254
254
  async function showExamples(commandName, json, stdout, filters = {}) {
255
- const { getCommandExamples } = await import("./examples-EAGYSHFN.js");
255
+ const { getCommandExamples } = await import("./examples-ELI5SKQH.js");
256
256
  const examples = getCommandExamples(commandName, filters);
257
257
  if (examples.length === 0) {
258
258
  throw new CliError("invalid_cli_usage", `No examples registered for "${commandName}".`);
@@ -2721,7 +2721,9 @@ var supportedComparators = /* @__PURE__ */ new Set([
2721
2721
  "lt",
2722
2722
  "lte",
2723
2723
  "contains",
2724
+ "not_contains",
2724
2725
  "in",
2726
+ "between",
2725
2727
  "is_empty",
2726
2728
  "is_not_empty"
2727
2729
  ]);
@@ -2763,8 +2765,13 @@ function normalizeValue(comparator, rawValue) {
2763
2765
  }
2764
2766
  return null;
2765
2767
  }
2766
- if (comparator === "in") {
2768
+ if (comparator === "in" || comparator === "between") {
2767
2769
  const values = rawValue.split(",").map((value) => value.trim()).filter(Boolean);
2770
+ if (comparator === "between" && values.length !== 2) {
2771
+ throw new Error(
2772
+ `Comparator "between" requires exactly two comma-separated values (from,to), got "${rawValue}".`
2773
+ );
2774
+ }
2768
2775
  if (values.length === 0) {
2769
2776
  throw new Error(`Comparator "${comparator}" requires at least one value.`);
2770
2777
  }
@@ -2775,10 +2782,10 @@ function normalizeValue(comparator, rawValue) {
2775
2782
  }
2776
2783
  return rawValue;
2777
2784
  }
2778
- function parseExpression(input) {
2785
+ function parseExpression(input, comparators = supportedComparators) {
2779
2786
  const trimmed = input.trim();
2780
2787
  const [field, comparatorCandidate, rawValue] = trimmed.includes(":") && !trimmed.includes(" ") ? parseColonExpression(trimmed) : parseSpaceExpression(trimmed);
2781
- if (!supportedComparators.has(comparatorCandidate)) {
2788
+ if (!comparators.has(comparatorCandidate)) {
2782
2789
  throw new Error(
2783
2790
  `Unsupported comparator "${comparatorCandidate}" in expression "${input}".`
2784
2791
  );
@@ -2813,6 +2820,9 @@ var COMPARATOR_TO_DISPLAY_OPERATOR = {
2813
2820
  is_empty: "IS_EMPTY",
2814
2821
  is_not_empty: "IS_NOT_EMPTY"
2815
2822
  };
2823
+ var DISPLAY_FILTER_COMPARATORS = new Set(
2824
+ Object.keys(COMPARATOR_TO_DISPLAY_OPERATOR)
2825
+ );
2816
2826
  function toDisplayFilter(parsed) {
2817
2827
  const values = parsed.value === null ? [] : Array.isArray(parsed.value) ? [...parsed.value] : [parsed.value];
2818
2828
  return {
@@ -2823,7 +2833,7 @@ function toDisplayFilter(parsed) {
2823
2833
  }
2824
2834
  function parseFilterExpression(input) {
2825
2835
  try {
2826
- return parseExpression(input);
2836
+ return parseExpression(input, DISPLAY_FILTER_COMPARATORS);
2827
2837
  } catch (error) {
2828
2838
  const message = error instanceof Error ? error.message : "Invalid filter expression.";
2829
2839
  throw new InvalidArgumentError2(message);
@@ -4744,6 +4754,29 @@ import { readFileSync as readFileSync5 } from "fs";
4744
4754
  import { InvalidArgumentError as InvalidArgumentError3 } from "commander";
4745
4755
 
4746
4756
  // src/api/records.ts
4757
+ function isQueryExpression(entry) {
4758
+ return typeof entry === "object" && entry !== null && "comparator" in entry && !("op" in entry);
4759
+ }
4760
+ function toWhereNode(entry) {
4761
+ if (!isQueryExpression(entry)) {
4762
+ return entry;
4763
+ }
4764
+ return {
4765
+ field: entry.field,
4766
+ op: entry.comparator,
4767
+ value: entry.value
4768
+ };
4769
+ }
4770
+ function toSort(entry) {
4771
+ if (typeof entry !== "string") {
4772
+ return entry;
4773
+ }
4774
+ const [field = "", direction = "asc"] = entry.split(":");
4775
+ return {
4776
+ field,
4777
+ direction: direction.toUpperCase()
4778
+ };
4779
+ }
4747
4780
  function jsonOptions6(body, method) {
4748
4781
  return {
4749
4782
  method,
@@ -4807,19 +4840,11 @@ var RecordsApi = class {
4807
4840
  { method: "DELETE" }
4808
4841
  );
4809
4842
  }
4843
+ // Only the CLI forms (comparator expressions, "field:dir" sort strings, limit/offset)
4844
+ // are converted; native payloads from --raw/--where-json reach the API untouched.
4810
4845
  normalizeQueryInput(query) {
4811
- const where = query.where?.map((expression) => ({
4812
- field: expression.field,
4813
- op: expression.comparator,
4814
- value: expression.value
4815
- }));
4816
- const sort = query.sort?.map((entry) => {
4817
- const [field, direction = "asc"] = entry.split(":");
4818
- return {
4819
- field,
4820
- direction: direction.toUpperCase()
4821
- };
4822
- });
4846
+ const where = Array.isArray(query.where) ? query.where.map(toWhereNode) : query.where;
4847
+ const sort = Array.isArray(query.sort) ? query.sort.map(toSort) : query.sort;
4823
4848
  return {
4824
4849
  ...query,
4825
4850
  select: query.select,
@@ -4828,7 +4853,7 @@ var RecordsApi = class {
4828
4853
  page: query.limit !== void 0 || query.offset !== void 0 ? {
4829
4854
  offset: query.offset,
4830
4855
  limit: query.limit
4831
- } : void 0,
4856
+ } : query.page,
4832
4857
  limit: void 0,
4833
4858
  offset: void 0
4834
4859
  };
@@ -5041,13 +5066,45 @@ function toQueryExpressions(expressions) {
5041
5066
  value: expression.value
5042
5067
  }));
5043
5068
  }
5069
+ function parseWhereJson(input) {
5070
+ let parsed;
5071
+ try {
5072
+ parsed = JSON.parse(input);
5073
+ } catch (error) {
5074
+ const message = error instanceof Error ? error.message : "Invalid JSON.";
5075
+ throw new CliError(
5076
+ "invalid_cli_usage",
5077
+ `Failed to parse JSON from --where-json: ${message}`
5078
+ );
5079
+ }
5080
+ if (!Array.isArray(parsed) && !isJsonObject(parsed)) {
5081
+ throw new CliError(
5082
+ "invalid_cli_usage",
5083
+ 'Expected --where-json to contain a JSON array of conditions or a JSON object (a condition or an {"and"|"or": [...]} group).'
5084
+ );
5085
+ }
5086
+ return parsed;
5087
+ }
5088
+ function resolveWhere(options) {
5089
+ const where = toQueryExpressions(options.where);
5090
+ if (options.whereJson !== void 0) {
5091
+ if (where) {
5092
+ throw new CliError(
5093
+ "invalid_cli_usage",
5094
+ 'Provide either "--where" or "--where-json", not both.'
5095
+ );
5096
+ }
5097
+ return parseWhereJson(options.whereJson);
5098
+ }
5099
+ return where;
5100
+ }
5044
5101
  function buildRecordQueryInput(options, allowRaw) {
5045
5102
  const input = allowRaw ? readRawObject(options.raw, options.rawFile) : {};
5046
5103
  if (options.select && options.select.length > 0) {
5047
5104
  input.select = [...options.select];
5048
5105
  }
5049
- const where = toQueryExpressions(options.where);
5050
- if (where && where.length > 0) {
5106
+ const where = resolveWhere(options);
5107
+ if (where !== void 0) {
5051
5108
  input.where = where;
5052
5109
  }
5053
5110
  if (options.search !== void 0) {
@@ -5206,16 +5263,22 @@ function registerRecordsCommands(program, options = {}) {
5206
5263
  }
5207
5264
  emitTable(stdout, recordsData);
5208
5265
  });
5209
- records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector).option("--select <fields>", "field selection (comma-separated, repeatable)", collectSelectValues, []).option("--where <expression>", "where expression", collectWhereExpressions, []).option(
5266
+ records.command("query").description("Query records for a schema").argument("<schema>", "schema uuid or slug", parseUuidOrSlugSelector).option("--select <fields>", "field selection (comma-separated, repeatable)", collectSelectValues, []).option(
5267
+ "--where <expression>",
5268
+ 'condition "<field> <op> [value]" (repeatable, combined with AND)',
5269
+ collectWhereExpressions,
5270
+ []
5271
+ ).option(
5272
+ "--where-json <json>",
5273
+ 'native where as JSON: an array of conditions (AND) or one condition/{"and"|"or": [...]} group (not combinable with --where)'
5274
+ ).option(
5210
5275
  "--search <term>",
5211
5276
  "free-text search term (matched across the schema's searchable fields)"
5212
5277
  ).option("--sort <field:direction>", "sort field(s)", collectSortValues, []).option("--limit <number>", "limit results", parseNonNegativeInteger).option("--offset <number>", "offset results", parseNonNegativeInteger).option("--raw <json>", "raw JSON object payload").option("--raw-file <path>", "path to a raw JSON object payload").action(async function action(schema, commandOptions) {
5213
5278
  const { api, schemasApi, json } = createRecordsApi(this, filePath);
5279
+ const query = buildRecordQueryInput(commandOptions, true);
5214
5280
  const resolvedSchema = await resolveSchemaSelector(schemasApi, schema);
5215
- const data = await api.queryRecords(
5216
- resolvedSchema,
5217
- buildRecordQueryInput(commandOptions, true)
5218
- );
5281
+ const data = await api.queryRecords(resolvedSchema, query);
5219
5282
  const recordsData = getQueryRecords(data);
5220
5283
  if (json) {
5221
5284
  emitJson(