@ai-matrx/records 0.83.2 → 0.84.1

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.
@@ -170,6 +170,9 @@ function compileSort(sort, shape) {
170
170
  for (const s of sort ?? []) {
171
171
  const column = shape.columns.find((c) => c.key === s.column);
172
172
  if (!column) return { ok: false, error: noSuchColumn(s.column) };
173
+ if (column.type === "relation") {
174
+ return { ok: false, error: refusal(`"${column.label}" is a link, so the store cannot sort by it.`, "Sort the rows on the page by each link's label. Nothing was read.") };
175
+ }
173
176
  const as = isNumberColumn(column.type) ? "number" : isDateColumn(column.type) ? "date" : "text";
174
177
  out.push({ field: column.key, direction: s.direction === "desc" ? "desc" : "asc", as });
175
178
  }
@@ -6028,6 +6031,11 @@ function relationIdsOf(value) {
6028
6031
  }
6029
6032
  return out;
6030
6033
  }
6034
+ var WORD_TYPES = /* @__PURE__ */ new Set(["text", "long_text", "rich_text", "email", "url", "phone", "markdown"]);
6035
+ function blankToNull(type, value) {
6036
+ if (typeof value === "string" && value.trim() === "" && !WORD_TYPES.has(type)) return null;
6037
+ return value;
6038
+ }
6031
6039
  function createTableDataPort({ client, aliases }) {
6032
6040
  const shapes = /* @__PURE__ */ new Map();
6033
6041
  let warnedNotLive = false;
@@ -6101,7 +6109,7 @@ function createTableDataPort({ client, aliases }) {
6101
6109
  if (!column) return refuse2("invalid_argument", `This table has no column "${key}".`, "Ask columns() for the keys this table has now. Nothing was saved.");
6102
6110
  if (column.readOnly) return refuse2("invalid_argument", `"${column.label}" is worked out by the table, so it cannot be written.`, "Nothing was saved.");
6103
6111
  const kinds = column.type === "relation" ? entityKindsOf(shape.fields.get(key)) : [];
6104
- out[key] = kinds.length ? entityRefsOf2(value, kinds) : column.type === "relation" ? relationIdsOf(value) : value;
6112
+ out[key] = kinds.length ? entityRefsOf2(value, kinds) : column.type === "relation" ? relationIdsOf(value) : blankToNull(column.type, value);
6105
6113
  }
6106
6114
  return { ok: true, data: out };
6107
6115
  }