@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.
@@ -214,6 +214,9 @@ function compileSort(sort, shape) {
214
214
  for (const s of sort ?? []) {
215
215
  const column = shape.columns.find((c) => c.key === s.column);
216
216
  if (!column) return { ok: false, error: noSuchColumn(s.column) };
217
+ if (column.type === "relation") {
218
+ 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.") };
219
+ }
217
220
  const as = isNumberColumn(column.type) ? "number" : isDateColumn(column.type) ? "date" : "text";
218
221
  out.push({ field: column.key, direction: s.direction === "desc" ? "desc" : "asc", as });
219
222
  }
@@ -6072,6 +6075,11 @@ function relationIdsOf(value) {
6072
6075
  }
6073
6076
  return out;
6074
6077
  }
6078
+ var WORD_TYPES = /* @__PURE__ */ new Set(["text", "long_text", "rich_text", "email", "url", "phone", "markdown"]);
6079
+ function blankToNull(type, value) {
6080
+ if (typeof value === "string" && value.trim() === "" && !WORD_TYPES.has(type)) return null;
6081
+ return value;
6082
+ }
6075
6083
  function createTableDataPort({ client, aliases }) {
6076
6084
  const shapes = /* @__PURE__ */ new Map();
6077
6085
  let warnedNotLive = false;
@@ -6145,7 +6153,7 @@ function createTableDataPort({ client, aliases }) {
6145
6153
  if (!column) return refuse2("invalid_argument", `This table has no column "${key}".`, "Ask columns() for the keys this table has now. Nothing was saved.");
6146
6154
  if (column.readOnly) return refuse2("invalid_argument", `"${column.label}" is worked out by the table, so it cannot be written.`, "Nothing was saved.");
6147
6155
  const kinds = column.type === "relation" ? entityKindsOf(shape.fields.get(key)) : [];
6148
- out[key] = kinds.length ? entityRefsOf2(value, kinds) : column.type === "relation" ? relationIdsOf(value) : value;
6156
+ out[key] = kinds.length ? entityRefsOf2(value, kinds) : column.type === "relation" ? relationIdsOf(value) : blankToNull(column.type, value);
6149
6157
  }
6150
6158
  return { ok: true, data: out };
6151
6159
  }