@lotics/app-sdk 0.130.4 → 0.131.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.
package/dist/index.js CHANGED
@@ -365,16 +365,16 @@ function buildChoiceOutput(questions, answers) {
365
365
  if (!answer || value.length === 0) {
366
366
  return { type: "skipped", question_index: index, question_number: questionNumber, question_text: question.question };
367
367
  }
368
- const optionIndex = answer.custom ? -1 : question.options.findIndex((o) => o.label === value);
369
- if (optionIndex >= 0) {
370
- const option = question.options[optionIndex];
368
+ const optionIndex2 = answer.custom ? -1 : question.options.findIndex((o) => o.label === value);
369
+ if (optionIndex2 >= 0) {
370
+ const option = question.options[optionIndex2];
371
371
  return {
372
372
  type: "option",
373
373
  question_index: index,
374
374
  question_number: questionNumber,
375
375
  question_text: question.question,
376
- option_index: optionIndex,
377
- option_letter: toLetter(optionIndex),
376
+ option_index: optionIndex2,
377
+ option_letter: toLetter(optionIndex2),
378
378
  option_label: option.label,
379
379
  option_description: option.description
380
380
  };
@@ -1017,6 +1017,134 @@ function cellFileIds(cell) {
1017
1017
  return cell.flatMap((entry) => Array.isArray(entry) ? cellFileIds(entry) : storedFileIds([entry]));
1018
1018
  }
1019
1019
 
1020
+ // ../shared/src/schemas/select_walk.ts
1021
+ function selectEnd(field, table, walk) {
1022
+ let current = { field, table };
1023
+ let several;
1024
+ for (let hops = 0; hops <= RESULT_HOPS; hops++) {
1025
+ if (walk.holds(current.field, current.table)) return { ...current, hops, several };
1026
+ const step = walk.through(current.field, current.table);
1027
+ if (step === void 0) return void 0;
1028
+ several ??= step.several ? { link: step.link, table: current.table } : void 0;
1029
+ current = { field: step.shown, table: step.target };
1030
+ }
1031
+ return void 0;
1032
+ }
1033
+
1034
+ // ../shared/src/schemas/select_options.ts
1035
+ function selectOptionsOf(field) {
1036
+ if (field.type === "select") return field.options;
1037
+ if (field.type === "formula") return field.formula.options;
1038
+ return void 0;
1039
+ }
1040
+
1041
+ // ../shared/src/select_cell_alias.ts
1042
+ var byKeyOf = /* @__PURE__ */ new WeakMap();
1043
+ function fieldsByKey(fields) {
1044
+ const held2 = byKeyOf.get(fields);
1045
+ if (held2 !== void 0) return held2;
1046
+ const built = new Map(fields.map((field) => [field.key, field]));
1047
+ byKeyOf.set(fields, built);
1048
+ return built;
1049
+ }
1050
+ var fieldOf = (fields, key) => fieldsByKey(fields).get(key);
1051
+ function selectFieldHolder(tables, fieldKey) {
1052
+ let found;
1053
+ for (const table of tables) {
1054
+ const field = fieldOf(table.fields, fieldKey);
1055
+ if (field !== void 0) found = { table, field };
1056
+ }
1057
+ return found;
1058
+ }
1059
+ var fieldsWalk = (linked) => ({
1060
+ holds: (field) => selectOptionsOf(field) !== void 0,
1061
+ through: (field, table) => {
1062
+ if (field.type !== "lookup") return void 0;
1063
+ const link2 = fieldOf(table.fields, field.source_field_key);
1064
+ const fields = link2?.type === "select_record_link" ? linked(link2.table_id) : void 0;
1065
+ const shown = fields === void 0 ? void 0 : fieldOf(fields, field.lookup_field_key);
1066
+ return link2?.type !== "select_record_link" || fields === void 0 || shown === void 0 ? void 0 : { link: link2.key, several: link2.cardinality !== "one", target: { fields }, shown };
1067
+ }
1068
+ });
1069
+ function selectBehind(field, owner, linked) {
1070
+ const end = selectEnd(field, { fields: owner }, fieldsWalk(linked));
1071
+ return end === void 0 ? void 0 : { field: end.field, fields: end.table.fields };
1072
+ }
1073
+ var indexOf = /* @__PURE__ */ new WeakMap();
1074
+ function optionIndex(options) {
1075
+ const held2 = indexOf.get(options);
1076
+ if (held2 !== void 0) return held2;
1077
+ const keyOf2 = /* @__PURE__ */ new Map();
1078
+ const aliasOf = /* @__PURE__ */ new Map();
1079
+ for (const option of options) {
1080
+ if (option.alias === void 0) continue;
1081
+ aliasOf.set(option.key, option.alias);
1082
+ if (!keyOf2.has(option.alias)) keyOf2.set(option.alias, option.key);
1083
+ }
1084
+ const built = { keys: new Set(options.map((option) => option.key)), aliasOf, keyOf: keyOf2 };
1085
+ indexOf.set(options, built);
1086
+ return built;
1087
+ }
1088
+ function optionKeyIn(options, ref) {
1089
+ const index = optionIndex(options);
1090
+ return index.keys.has(ref) ? ref : index.keyOf.get(ref);
1091
+ }
1092
+ function optionIn(options, ref) {
1093
+ const key = optionKeyIn(options, ref);
1094
+ return key === void 0 ? void 0 : options.find((option) => option.key === key);
1095
+ }
1096
+ function optionAliasIn(options, key) {
1097
+ return optionIndex(options).aliasOf.get(key) ?? key;
1098
+ }
1099
+ function optionAliasOf(field, optionKey) {
1100
+ return optionAliasIn(selectOptionsOf(field) ?? [], optionKey);
1101
+ }
1102
+ function optionKeyOf(field, ref) {
1103
+ return optionKeyIn(selectOptionsOf(field) ?? [], ref);
1104
+ }
1105
+ function renamedDeep(value, rename) {
1106
+ if (typeof value === "string") return rename(value);
1107
+ if (Array.isArray(value)) return value.map((one) => renamedDeep(one, rename));
1108
+ return value;
1109
+ }
1110
+ function optionValue(value, rename) {
1111
+ if (typeof value === "string") return rename(value);
1112
+ if (Array.isArray(value)) return value.map((one) => typeof one === "string" ? rename(one) : one);
1113
+ return value;
1114
+ }
1115
+ function optionAliasing(fields, linked) {
1116
+ const lookedUp = (field) => field.type === "lookup" && linked !== void 0 ? selectBehind(field, fields, linked)?.field : void 0;
1117
+ const option = (fieldKey, optionKey) => {
1118
+ const field = fieldOf(fields, fieldKey);
1119
+ const looked = field === void 0 ? void 0 : lookedUp(field);
1120
+ return looked !== void 0 ? optionAliasOf(looked, optionKey) : field === void 0 ? optionKey : optionAliasOf(field, optionKey);
1121
+ };
1122
+ const cell = (fieldKey, value) => {
1123
+ const field = fieldOf(fields, fieldKey);
1124
+ if (field === void 0 || selectOptionsOf(field) === void 0 && lookedUp(field) === void 0) return value;
1125
+ return field.type === "lookup" ? renamedDeep(value, (one) => option(fieldKey, one)) : optionValue(value, (one) => option(fieldKey, one));
1126
+ };
1127
+ return { option, cell };
1128
+ }
1129
+ function renamedSelectValues(schema, payload, rename) {
1130
+ const walk = (node, value) => {
1131
+ if (node.type === "select" && node.field !== void 0) {
1132
+ const field = node.field;
1133
+ return Array.isArray(value) ? value.map((one) => rename(field, one)) : rename(field, value);
1134
+ }
1135
+ if (node.fields !== void 0 && typeof value === "object" && value !== null && !Array.isArray(value)) {
1136
+ const fields = node.fields;
1137
+ return Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, fields[key] === void 0 ? inner : walk(fields[key], inner)]));
1138
+ }
1139
+ if (node.items !== void 0 && Array.isArray(value)) {
1140
+ const items = node.items;
1141
+ return value.map((item) => walk(items, item));
1142
+ }
1143
+ return value;
1144
+ };
1145
+ return Object.fromEntries(Object.entries(payload).map(([key, value]) => [key, schema[key] === void 0 ? value : walk(schema[key], value)]));
1146
+ }
1147
+
1020
1148
  // ../shared/src/display_values.ts
1021
1149
  function getFieldDisplayValue(field, value) {
1022
1150
  if (field.type === "boolean") {
@@ -1036,15 +1164,15 @@ function getFieldDisplayValue(field, value) {
1036
1164
  return "";
1037
1165
  }
1038
1166
  if (field.multi) {
1039
- return selectValues.map((key) => field.options.find((opt2) => opt2.key === key)?.name ?? key).join(", ");
1167
+ return selectValues.map((ref) => optionIn(field.options, ref)?.name ?? ref).join(", ");
1040
1168
  }
1041
- const option = field.options.find((opt2) => opt2.key === selectValues[0]);
1169
+ const option = selectValues[0] === void 0 ? void 0 : optionIn(field.options, selectValues[0]);
1042
1170
  return option?.name ?? selectValues[0] ?? "";
1043
1171
  }
1044
1172
  case "formula": {
1045
1173
  if (field.formula.options !== void 0) {
1046
1174
  const [key] = Array.isArray(value) ? value : [];
1047
- return key === void 0 ? "" : field.formula.options.find((option) => option.key === key)?.name ?? key;
1175
+ return key === void 0 ? "" : optionIn(field.formula.options, key)?.name ?? key;
1048
1176
  }
1049
1177
  const formulaVal = getFormulaValue(value);
1050
1178
  return formulaVal !== null ? String(formulaVal) : "";
@@ -1065,6 +1193,10 @@ function getFieldDisplayValue(field, value) {
1065
1193
  const count = cellFileIds(value).length;
1066
1194
  return count === 0 ? "" : `${count} file(s)`;
1067
1195
  }
1196
+ if (field.lookup_field_type === "select") {
1197
+ const options = field.lookup_field_options ?? [];
1198
+ return flattenLookupValues(value).map((one) => typeof one === "string" ? optionIn(options, one)?.name ?? one : lookupElementToString(one)).filter(Boolean).join(", ");
1199
+ }
1068
1200
  return value.map(lookupElementToString).filter(Boolean).join(", ");
1069
1201
  }
1070
1202
  case "autonumber":
@@ -1898,7 +2030,7 @@ __export(expression_array_exports, {
1898
2030
  flatten: () => flatten,
1899
2031
  groupBy: () => groupBy,
1900
2032
  includes: () => includes,
1901
- indexOf: () => indexOf,
2033
+ indexOf: () => indexOf2,
1902
2034
  intersection: () => intersection,
1903
2035
  intersectionBy: () => intersectionBy,
1904
2036
  last: () => last,
@@ -2655,7 +2787,7 @@ function flat(arr, depth = 1) {
2655
2787
  }
2656
2788
  return arr.flat(depth);
2657
2789
  }
2658
- function indexOf(collection, search, fromIndex) {
2790
+ function indexOf2(collection, search, fromIndex) {
2659
2791
  if (collection == null) return -1;
2660
2792
  if (fromIndex != null && typeof fromIndex !== "number") throw new ExpressionArgumentError("indexOf: fromIndex must be a number");
2661
2793
  if (Array.isArray(collection)) return collection.indexOf(search, fromIndex);
@@ -7786,8 +7918,20 @@ var formulaOnlyFunctions = {
7786
7918
  const declared = names ?? {};
7787
7919
  for (const key of held2) if (typeof key !== "string" || !Object.hasOwn(declared, key)) throw new UndeclaredOptionError(field);
7788
7920
  return Object.entries(declared).filter(([key]) => held2.has(key)).map(([, name]) => name).join(", ");
7789
- }
7921
+ },
7922
+ // A lookup through a link holding several rows reaches a formula as its one value while it holds one row, so a
7923
+ // list helper reads a single value as a list of it.
7924
+ join: (list2, separator) => join(asList(list2), separator),
7925
+ sum: (list2) => sum(asList(list2)),
7926
+ mean: (list2) => mean(asList(list2)),
7927
+ first: (list2) => first(asList(list2)),
7928
+ last: (list2) => last(asList(list2)),
7929
+ unique: (list2) => unique(asList(list2)),
7930
+ compact: (list2) => compact(asList(list2))
7790
7931
  };
7932
+ function asList(value) {
7933
+ return value === null || value === void 0 || Array.isArray(value) ? value : [value];
7934
+ }
7791
7935
  var MAX_HELD_TIMEZONES = 512;
7792
7936
  var functionsByTimezone = /* @__PURE__ */ new Map();
7793
7937
  function timezoneAwareFunctions(defaultTimezone) {
@@ -10008,109 +10152,6 @@ function stringifyForTemplate(value) {
10008
10152
  return textOf(value);
10009
10153
  }
10010
10154
 
10011
- // ../shared/src/schemas/select_walk.ts
10012
- function selectEnd(field, table, walk) {
10013
- let current = { field, table };
10014
- let several;
10015
- for (let hops = 0; hops <= RESULT_HOPS; hops++) {
10016
- if (walk.holds(current.field, current.table)) return { ...current, hops, several };
10017
- const step = walk.through(current.field, current.table);
10018
- if (step === void 0) return void 0;
10019
- several ??= step.several ? { link: step.link, table: current.table } : void 0;
10020
- current = { field: step.shown, table: step.target };
10021
- }
10022
- return void 0;
10023
- }
10024
-
10025
- // ../shared/src/schemas/select_options.ts
10026
- function selectOptionsOf(field) {
10027
- if (field.type === "select") return field.options;
10028
- if (field.type === "formula") return field.formula.options;
10029
- return void 0;
10030
- }
10031
-
10032
- // ../shared/src/select_cell_alias.ts
10033
- var byKeyOf = /* @__PURE__ */ new WeakMap();
10034
- function fieldsByKey(fields) {
10035
- const held2 = byKeyOf.get(fields);
10036
- if (held2 !== void 0) return held2;
10037
- const built = new Map(fields.map((field) => [field.key, field]));
10038
- byKeyOf.set(fields, built);
10039
- return built;
10040
- }
10041
- var fieldOf = (fields, key) => fieldsByKey(fields).get(key);
10042
- function selectFieldHolder(tables, fieldKey) {
10043
- let found;
10044
- for (const table of tables) {
10045
- const field = fieldOf(table.fields, fieldKey);
10046
- if (field !== void 0) found = { table, field };
10047
- }
10048
- return found;
10049
- }
10050
- var fieldsWalk = (linked) => ({
10051
- holds: (field) => selectOptionsOf(field) !== void 0,
10052
- through: (field, table) => {
10053
- if (field.type !== "lookup") return void 0;
10054
- const link2 = fieldOf(table.fields, field.source_field_key);
10055
- const fields = link2?.type === "select_record_link" ? linked(link2.table_id) : void 0;
10056
- const shown = fields === void 0 ? void 0 : fieldOf(fields, field.lookup_field_key);
10057
- return link2?.type !== "select_record_link" || fields === void 0 || shown === void 0 ? void 0 : { link: link2.key, several: link2.cardinality !== "one", target: { fields }, shown };
10058
- }
10059
- });
10060
- function selectBehind(field, owner, linked) {
10061
- const end = selectEnd(field, { fields: owner }, fieldsWalk(linked));
10062
- return end === void 0 ? void 0 : { field: end.field, fields: end.table.fields };
10063
- }
10064
- function optionAliasOf(field, optionKey) {
10065
- return selectOptionsOf(field)?.find((option) => option.key === optionKey)?.alias ?? optionKey;
10066
- }
10067
- function optionKeyOf(field, ref) {
10068
- const options = selectOptionsOf(field) ?? [];
10069
- return (options.find((option) => option.key === ref) ?? options.find((option) => option.alias === ref))?.key;
10070
- }
10071
- function renamedDeep(value, rename) {
10072
- if (typeof value === "string") return rename(value);
10073
- if (Array.isArray(value)) return value.map((one) => renamedDeep(one, rename));
10074
- return value;
10075
- }
10076
- function optionValue(value, rename) {
10077
- if (typeof value === "string") return rename(value);
10078
- if (Array.isArray(value)) return value.map((one) => typeof one === "string" ? rename(one) : one);
10079
- return value;
10080
- }
10081
- function optionAliasing(fields, linked) {
10082
- const lookedUp = (field) => field.type === "lookup" && linked !== void 0 ? selectBehind(field, fields, linked)?.field : void 0;
10083
- const option = (fieldKey, optionKey) => {
10084
- const field = fieldOf(fields, fieldKey);
10085
- const looked = field === void 0 ? void 0 : lookedUp(field);
10086
- return looked !== void 0 ? optionAliasOf(looked, optionKey) : field === void 0 ? optionKey : optionAliasOf(field, optionKey);
10087
- };
10088
- const cell = (fieldKey, value) => {
10089
- const field = fieldOf(fields, fieldKey);
10090
- if (field === void 0 || selectOptionsOf(field) === void 0 && lookedUp(field) === void 0) return value;
10091
- return field.type === "lookup" ? renamedDeep(value, (one) => option(fieldKey, one)) : optionValue(value, (one) => option(fieldKey, one));
10092
- };
10093
- return { option, cell };
10094
- }
10095
- function renamedSelectValues(schema, payload, rename) {
10096
- const walk = (node, value) => {
10097
- if (node.type === "select" && node.field !== void 0) {
10098
- const field = node.field;
10099
- return Array.isArray(value) ? value.map((one) => rename(field, one)) : rename(field, value);
10100
- }
10101
- if (node.fields !== void 0 && typeof value === "object" && value !== null && !Array.isArray(value)) {
10102
- const fields = node.fields;
10103
- return Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, fields[key] === void 0 ? inner : walk(fields[key], inner)]));
10104
- }
10105
- if (node.items !== void 0 && Array.isArray(value)) {
10106
- const items = node.items;
10107
- return value.map((item) => walk(items, item));
10108
- }
10109
- return value;
10110
- };
10111
- return Object.fromEntries(Object.entries(payload).map(([key, value]) => [key, schema[key] === void 0 ? value : walk(schema[key], value)]));
10112
- }
10113
-
10114
10155
  // ../shared/src/workflow_effect_plan.ts
10115
10156
  var WITHHELD = "__withheld";
10116
10157
 
@@ -10215,14 +10256,14 @@ function asIds(ids) {
10215
10256
  if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string")) return null;
10216
10257
  return ids;
10217
10258
  }
10218
- function asList(cell) {
10259
+ function asList2(cell) {
10219
10260
  if (Array.isArray(cell)) return cell;
10220
10261
  return cell === null || cell === void 0 ? [] : [cell];
10221
10262
  }
10222
10263
  function adjusted(current, items, op) {
10223
10264
  const keyOf2 = (item) => item !== null && typeof item === "object" && "id" in item ? item.id : item;
10224
- const held2 = asList(current);
10225
- const given = asList(items);
10265
+ const held2 = asList2(current);
10266
+ const given = asList2(items);
10226
10267
  if (op === "add_to") {
10227
10268
  const have = new Set(held2.map(keyOf2));
10228
10269
  return [...held2, ...given.filter((item) => !have.has(keyOf2(item)))];
@@ -10231,8 +10272,8 @@ function adjusted(current, items, op) {
10231
10272
  return held2.filter((item) => !gone.has(keyOf2(item)));
10232
10273
  }
10233
10274
  function withoutMade(current, templates) {
10234
- const gone = new Set(asList(templates));
10235
- return asList(current).filter((item) => !(item !== null && typeof item === "object" && "document_template_id" in item && gone.has(item.document_template_id)));
10275
+ const gone = new Set(asList2(templates));
10276
+ return asList2(current).filter((item) => !(item !== null && typeof item === "object" && "document_template_id" in item && gone.has(item.document_template_id)));
10236
10277
  }
10237
10278
  function note(walk, effect) {
10238
10279
  if (walk.unsure && effect.kind !== "unknown") {
@@ -11393,6 +11434,14 @@ function opt(v) {
11393
11434
  }
11394
11435
  return null;
11395
11436
  }
11437
+ function optAlias(v) {
11438
+ if (Array.isArray(v)) return v.length ? optAlias(v[0]) : null;
11439
+ if (v && typeof v === "object") {
11440
+ const alias = v.alias;
11441
+ if (typeof alias === "string" && alias !== "") return alias;
11442
+ }
11443
+ return opt(v);
11444
+ }
11396
11445
  function text(v) {
11397
11446
  if (typeof v === "string") return v;
11398
11447
  if (typeof v === "number" && Number.isFinite(v)) return String(v);
@@ -11452,13 +11501,13 @@ function readLinks(v) {
11452
11501
  }
11453
11502
  return out;
11454
11503
  }
11455
- var row = { opt, text, num, bool, date, datetime, link };
11504
+ var row = { opt, optAlias, text, num, bool, date, datetime, link };
11456
11505
  function readSelect(value) {
11457
11506
  if (!Array.isArray(value)) return [];
11458
11507
  const out = [];
11459
11508
  for (const entry of value.flat(Infinity)) {
11460
11509
  if (typeof entry === "string") {
11461
- if (entry !== "") out.push({ key: entry, label: entry });
11510
+ if (entry !== "") out.push({ key: entry, alias: entry, label: entry });
11462
11511
  continue;
11463
11512
  }
11464
11513
  if (!entry || typeof entry !== "object") continue;
@@ -11466,7 +11515,8 @@ function readSelect(value) {
11466
11515
  const key = obj.key;
11467
11516
  if (typeof key !== "string" || key === "") continue;
11468
11517
  const label = typeof obj.label === "string" ? obj.label : key;
11469
- out.push({ key, label });
11518
+ const alias = typeof obj.alias === "string" && obj.alias !== "" ? obj.alias : key;
11519
+ out.push({ key, alias, label });
11470
11520
  }
11471
11521
  return out;
11472
11522
  }
@@ -11564,8 +11614,8 @@ function countsOf(rows, by) {
11564
11614
  const cell = one[by];
11565
11615
  const held2 = Array.isArray(cell) ? cell : cell == null ? [] : [cell];
11566
11616
  for (const value of held2) {
11567
- const key = row.opt(value);
11568
- if (key !== null) counts[key] = (counts[key] ?? 0) + 1;
11617
+ const alias = row.optAlias(value);
11618
+ if (alias !== null) counts[alias] = (counts[alias] ?? 0) + 1;
11569
11619
  }
11570
11620
  }
11571
11621
  return counts;
@@ -12571,21 +12621,21 @@ function conditionUnit(condition2, field, fieldOf3) {
12571
12621
  const unstated = condition2.value === null || condition2.value === void 0 || condition2.value === "" || isZeroBound(condition2.value);
12572
12622
  return unstated ? { ok: true, unit: void 0 } : { ok: false, reason: `${reads}, so '${condition2.operator}' states the ${read2.vocabulary} its value is in as unit_option: ${held2}.` };
12573
12623
  }
12574
- const option = typeof stated === "string" ? options.find((candidate) => candidate.key === stated) : void 0;
12624
+ const option = typeof stated === "string" ? optionIn(options, stated) : void 0;
12575
12625
  if (option === void 0) {
12576
12626
  return { ok: false, reason: `${reads}; unit_option ${JSON.stringify(stated)} is none of them: ${held2}.` };
12577
12627
  }
12578
12628
  const target = read2.vocabulary === "unit" ? measuredUnit(option.name) : void 0;
12579
- if (target === void 0) return { ok: true, unit: { select: read2, options: [{ key: option.key, factor: 1 }], factor: 1 } };
12629
+ if (target === void 0) return { ok: true, unit: { select: read2, options: [{ key: option.key, alias: option.alias, factor: 1 }], factor: 1 } };
12580
12630
  const kin = options.flatMap((candidate) => {
12581
12631
  const measured = measuredUnit(candidate.name);
12582
- return measured?.dimension === target.dimension ? [{ key: candidate.key, factor: measured.factor }] : [];
12632
+ return measured?.dimension === target.dimension ? [{ key: candidate.key, alias: candidate.alias, factor: measured.factor }] : [];
12583
12633
  });
12584
12634
  return { ok: true, unit: { select: read2, options: kin, factor: target.factor } };
12585
12635
  }
12586
12636
  function rowUnitFactor(unit, data) {
12587
12637
  const key = firstOptionKey(data[unit.select.key]);
12588
- return key === void 0 ? void 0 : unit.options.find((option) => option.key === key)?.factor;
12638
+ return key === void 0 ? void 0 : optionIn(unit.options, key)?.factor;
12589
12639
  }
12590
12640
 
12591
12641
  // ../shared/src/filter.ts
@@ -13088,7 +13138,9 @@ function matchCell(cell, field, filterCondition, looseCondition, memberContext,
13088
13138
  }
13089
13139
  } else if (filterCondition.type === "select") {
13090
13140
  const value = columnValue;
13091
- const recordValues = value ?? [];
13141
+ const options = effectiveSelectOptions(field);
13142
+ const keyOf2 = (ref) => options === null ? ref : optionKeyIn(options, ref) ?? ref;
13143
+ const recordValues = (value ?? []).map(keyOf2);
13092
13144
  const isRecordEmpty = !value || recordValues.length === 0;
13093
13145
  if (filterCondition.operator === "is_empty") {
13094
13146
  matches = isRecordEmpty;
@@ -13098,7 +13150,7 @@ function matchCell(cell, field, filterCondition, looseCondition, memberContext,
13098
13150
  if (filterCondition.value === null) {
13099
13151
  return null;
13100
13152
  }
13101
- const filterValues = filterCondition.value;
13153
+ const filterValues = filterCondition.value.map(keyOf2);
13102
13154
  const hasEmptyInFilter = filterValues.includes("");
13103
13155
  if (filterCondition.operator === "has_any_of") {
13104
13156
  matches = hasEmptyInFilter && isRecordEmpty || filterValues.some((filterVal) => filterVal !== "" && recordValues.includes(filterVal));
@@ -13411,7 +13463,7 @@ function fieldValueInfo(field) {
13411
13463
  return {
13412
13464
  type: field.lookup_field_type ?? "text",
13413
13465
  ...field.lookup_field_type === "number" ? { notation: fieldNotation(field) } : { format: field.lookup_field_format },
13414
- options: field.lookup_field_options,
13466
+ options: field.lookup_field_options === void 0 ? void 0 : carriedOptions(field.lookup_field_options),
13415
13467
  autonumber: field.lookup_field_autonumber,
13416
13468
  several: field.lookup_field_several
13417
13469
  };
@@ -14263,7 +14315,7 @@ function drawn(over, field, stored) {
14263
14315
  const keys2 = Array.isArray(stored) ? stored : [];
14264
14316
  return keys2.map((key) => {
14265
14317
  const option = field.options.find((one) => one.key === key);
14266
- return { key, label: option === void 0 ? String(key) : option.name };
14318
+ return { key, alias: optionAliasIn(field.options, String(key)), label: option === void 0 ? String(key) : option.name };
14267
14319
  });
14268
14320
  }
14269
14321
  case "select_member": {
@@ -14462,10 +14514,15 @@ function storedCellOf(cell) {
14462
14514
  if (!Array.isArray(cell)) return cell;
14463
14515
  return cell.map((one) => one !== null && typeof one === "object" ? Reflect.get(one, "key") ?? Reflect.get(one, "id") ?? one : one);
14464
14516
  }
14465
- function groupsOf(totals, side) {
14517
+ function groupsOf(over, totals, side) {
14466
14518
  if (!totals.by.every(({ field_key }) => side.cells.has(field_key) && !side.unknown.has(field_key))) return null;
14467
14519
  const [only] = totals.by;
14468
- if (totals.each && only !== void 0) return Object.keys(countsOf([{ cell: side.cells.get(only.field_key) }], "cell"));
14520
+ if (totals.each && only !== void 0) {
14521
+ const field = over.field(totals.table_id, only.field_key);
14522
+ const keys2 = Object.keys(countsOf([{ cell: side.cells.get(only.field_key) }], "cell"));
14523
+ const options = effectiveSelectOptions(field);
14524
+ return options === null ? keys2 : keys2.map((key) => optionAliasIn(options, key));
14525
+ }
14469
14526
  return [
14470
14527
  JSON.stringify(
14471
14528
  totals.by.map(({ field_key, tiers }) => {
@@ -14489,8 +14546,8 @@ function overlayTotals(over, totals, admits, closed, rows) {
14489
14546
  pending = true;
14490
14547
  continue;
14491
14548
  }
14492
- const from = before.in ? groupsOf(totals, before) : [];
14493
- const to = after.in ? groupsOf(totals, after) : [];
14549
+ const from = before.in ? groupsOf(over, totals, before) : [];
14550
+ const to = after.in ? groupsOf(over, totals, after) : [];
14494
14551
  if (from === null || to === null) {
14495
14552
  pending = true;
14496
14553
  continue;
@@ -14898,7 +14955,8 @@ function useFieldOptions(alias, opts) {
14898
14955
  for (const [column, def] of Object.entries(answer.data?.fields ?? {})) {
14899
14956
  const options = def.options ?? [];
14900
14957
  const index = new Map(options.map((option) => [option.key, option]));
14901
- out[column] = { label: def.label, options, byKey: (key) => index.get(key) };
14958
+ const aliasIndex = new Map(options.map((option) => [option.alias, option]));
14959
+ out[column] = { label: def.label, options, byKey: (key) => index.get(key), byAlias: (alias2) => aliasIndex.get(alias2) };
14902
14960
  }
14903
14961
  return out;
14904
14962
  }, [answer.data]);
package/dist/overlay.d.ts CHANGED
@@ -22,6 +22,6 @@ export declare function overlayRead(alias: string, params: Readonly<Record<strin
22
22
  export declare function overlayGroups(alias: string, params: Readonly<Record<string, unknown>>, narrowing: TableRecordFilters | undefined, aggregate: QueryAggregate, askedAt: number, rows: readonly Row[]): Overlaid;
23
23
  /** The count of a read's rows with each staged write counted in or out. */
24
24
  export declare function overlayCount(alias: string, params: Readonly<Record<string, unknown>>, narrowing: TableRecordFilters | undefined, askedAt: number, total: number): Overlaid<number>;
25
- /** A count per value of `by`, keyed as a row carries it, with each staged write counted in or out. */
25
+ /** A count per value of `by`, keyed by the option's alias, with each staged write counted in or out. */
26
26
  export declare function overlayCounts(alias: string, params: Readonly<Record<string, unknown>>, narrowing: TableRecordFilters | undefined, by: string, askedAt: number, counts: Readonly<Record<string, number>>): Overlaid<Readonly<Record<string, number>>>;
27
27
  export {};
package/dist/queries.d.ts CHANGED
@@ -65,7 +65,7 @@ export interface QueryState<R> {
65
65
  truncated: boolean;
66
66
  /** The whole set's count, where `total` is asked; `undefined` until it answers. */
67
67
  total: number | undefined;
68
- /** Rows per value of `total.by`, keyed as a row carries it (an option's `opt_…`), a value no row holds absent;
68
+ /** Rows per value of `total.by`, keyed by the option's alias (`row.optAlias`), a value no row holds absent;
69
69
  * or per name of `total.where`. */
70
70
  counts: Readonly<Record<string, number>> | undefined;
71
71
  /** Only the first read of a key with nothing to show; a re-read and a new key keep the rows on screen. */
@@ -168,6 +168,8 @@ export interface FieldOptions {
168
168
  options: ResolvedOption[];
169
169
  /** `undefined` for an option removed after the cell was written. */
170
170
  byKey: (key: string) => ResolvedOption | undefined;
171
+ /** The option an alias names. */
172
+ byAlias: (alias: string) => ResolvedOption | undefined;
171
173
  }
172
174
  /** The units or currencies a number column is read in, row by row: the options of the select on its row naming each row's. */
173
175
  export interface FigureUnits {
@@ -204,6 +206,8 @@ export interface FieldOptionsOptions {
204
206
  * const { fields, units } = useFieldOptions("records");
205
207
  * // populate a picker:
206
208
  * (fields.status?.options ?? []).map((o) => <option key={o.key} value={o.key}>{o.label}</option>)
209
+ * // a stored value is the option whose alias it names; never a key or label typed into code:
210
+ * readSelect(r.status)[0]?.alias === "won"
207
211
  * // color a stored value:
208
212
  * fields.status?.byKey(readSelect(r.status)[0]?.key ?? "")?.color
209
213
  * // a range on a figure each row reads in its own unit names one:
package/dist/row.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Pure, never-throwing decoders of `useQuery` cells: a select is a
3
- * `{ key, label }[]`, a date/datetime a timezone-less `YYYY-MM-DD[THH:mm…]`
3
+ * `{ key, alias, label }[]`, a date/datetime a timezone-less `YYYY-MM-DD[THH:mm…]`
4
4
  * wall-clock string, a number or boolean itself.
5
5
  */
6
6
  /** The column a predicted row carries, so no surface opens a row the server has not answered for. */
@@ -272,11 +272,13 @@ export interface ResolvedMember {
272
272
  /** The server resolves each `select` cell to `ResolvedOption[]` before the app sees it. */
273
273
  export interface ResolvedOption {
274
274
  key: string;
275
+ /** The option's fixed name in code, the same on a cloned table: compare by this, never by `key` or `label`. The key where the option states none or was deleted after the cell was written. */
276
+ alias: string;
275
277
  /** The key, for an option deleted after the cell was written. */
276
278
  label: string;
277
279
  /**
278
280
  * A palette token (`"blue"`), from `useFieldOptions` only — a cell carries
279
- * key and label.
281
+ * key, alias and label.
280
282
  */
281
283
  color?: string;
282
284
  /** A brand or icon mark, from `useFieldOptions` only. */
@@ -286,7 +288,7 @@ export interface ResolvedOption {
286
288
  export type SpecLayout = CardsSpec | TableSpec | { kind: "calendar"; date: string; end: string | null; } | { kind: "lanes"; field: string; group: string | null; start: string; end: string | null; loads: { value: string; against: string; }[]; per: "day" | "week"; read: { query: string; param: string; listed: string[]; } | null; order: string | null; move: string | null; } | { kind: "plan"; at: string; across: string; up: string; fill: string | null; mark: { field: string; option: string; } | null; size: { field: string; options: Record<string, { across: number; along: number; up: number; }>; } | null; place: { entity: string; read: { query: string; param: string | null; listed: string[]; }; kind: string; kinds: { bay: string; area: string | null; landmark: string | null; }; sheet: string | null; scale: string | null; x: string; y: string; width: string | null; depth: string | null; across: string; up: string; reach_from: string | null; stacked: string | null; reaches: { first: string; last: string; both: string; } | null; size: { across: string; along: string; up: string; } | null; }; load: { query: string; param: string | null; } | null; } | { kind: "roster"; entity: string; via: string; day: string | null; end: string | null; expect: string | null; of: string | null; cadence: { on: { days: ("fri" | "mon" | "sat" | "sun" | "thu" | "tue" | "wed")[]; } | { field: string; }; from: string | null; until: string | null; planned: string | null; } | null; read: { query: string; param: string; listed: string[]; }; covers: number | null; create: string[] | null; } | { start: string; end: string; milestones: string[]; planned: { start: string | null; end: string | null; } | null; progress: string | null; after: string | null; kind: "gantt"; };
287
289
  /** A comparison as a compiled app states it: every key, `null` where it bounds nothing. */
288
290
  export type StatedBounds<V> = { gt: V | null; gte: V | null; lt: V | null; lte: V | null; };
289
- export type TableField = { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "number"; notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; rating?: { max: number; } | null | undefined; format: "currency" | "number" | "percentage"; currency?: string | null | undefined; unit?: string | null | undefined; unit_field?: string | null | undefined; currency_field?: string | null | undefined; default_value?: number | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "text"; unique?: boolean | undefined; format?: "link" | "markdown" | "text" | "time" | undefined; default_value?: string | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "date"; format?: "date" | "date_range" | "datetime" | "datetime_range" | "month" | undefined; timezone?: string | undefined; derive_from?: "created_at" | "updated_at" | undefined; default_value?: string | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "boolean"; default_value?: boolean | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "select"; options: { key: string; alias?: string | undefined; name: string; color?: "amber" | "blue" | "cyan" | "emerald" | "fuchsia" | "gray" | "green" | "indigo" | "lime" | "neutral" | "orange" | "pink" | "purple" | "red" | "rose" | "sky" | "slate" | "stone" | "teal" | "violet" | "yellow" | "zinc" | undefined; mark?: { kind: string; name: string; } | undefined; short?: string | undefined; }[]; multi?: boolean | undefined; default_value?: string[] | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "select_member"; multi?: boolean | undefined; default_value?: string[] | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "select_record_link"; table_id: string; paired_field_key?: string | undefined; cardinality?: "many" | "one" | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "rollup"; source_field_key: string; aggregate_option: { operation: "checked" | "percent_checked" | "percent_unchecked" | "unchecked"; field_key: string; } | { operation: "empty" | "filled" | "percent_empty" | "percent_filled" | "selected"; field_key: string; } | { operation: "empty" | "filled" | "percent_empty" | "percent_filled" | "percent_unique" | "unique"; field_key: string; } | { operation: "empty" | "filled" | "percent_empty" | "percent_filled" | "percent_unique" | "selected" | "unique"; field_key: string; } | { operation: "date_range" | "earliest" | "empty" | "filled" | "latest" | "percent_empty" | "percent_filled" | "percent_unique" | "unique"; field_key: string; } | { operation: "avg" | "empty" | "filled" | "max" | "median" | "min" | "percent_empty" | "percent_filled" | "percent_unique" | "range" | "sum" | "unique"; field_key: string; } | { operation: "avg" | "date_range" | "earliest" | "empty" | "filled" | "latest" | "max" | "median" | "min" | "percent_empty" | "percent_filled" | "percent_unique" | "range" | "sum" | "unique"; field_key: string; } | { operation: "avg" | "checked" | "date_range" | "earliest" | "empty" | "filled" | "latest" | "max" | "median" | "min" | "percent_checked" | "percent_empty" | "percent_filled" | "percent_unchecked" | "percent_unique" | "range" | "sum" | "unchecked" | "unique"; field_key: string; } | { operation: "count"; field_key?: string | undefined; }; filter?: TableRecordFiltersGroupNode | undefined; aggregate_field_type?: "autonumber" | "boolean" | "button" | "date" | "files" | "formula" | "lookup" | "number" | "rollup" | "select" | "select_member" | "select_record_link" | "text" | undefined; aggregate_field_notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; aggregate_field_format?: string | undefined; aggregate_field_currency?: string | undefined; aggregate_field_unit?: string | undefined; aggregate_field_unit_field?: string | undefined; aggregate_field_currency_field?: string | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "lookup"; source_field_key: string; lookup_field_key: string; lookup_field_type?: "autonumber" | "boolean" | "button" | "date" | "files" | "formula" | "lookup" | "number" | "rollup" | "select" | "select_member" | "select_record_link" | "text" | undefined; lookup_field_notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; lookup_field_format?: string | undefined; lookup_field_currency?: string | undefined; lookup_field_unit?: string | undefined; lookup_field_options?: { key: string; name: string; color?: string | undefined; mark?: { kind: string; name: string; } | undefined; }[] | undefined; lookup_field_autonumber?: boolean | undefined; lookup_field_several?: true | undefined; order_by?: { field_key: string; direction: "asc" | "desc"; } | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "files"; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "formula"; formula: { expression: string; notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; link?: true | undefined; format?: "currency" | "link" | "number" | "percentage" | undefined; currency?: string | undefined; unit?: string | undefined; unit_field?: string | undefined; currency_field?: string | undefined; options?: { key: string; alias?: string | undefined; name: string; color?: "amber" | "blue" | "cyan" | "emerald" | "fuchsia" | "gray" | "green" | "indigo" | "lime" | "neutral" | "orange" | "pink" | "purple" | "red" | "rose" | "sky" | "slate" | "stone" | "teal" | "violet" | "yellow" | "zinc" | undefined; mark?: { kind: string; name: string; } | undefined; short?: string | undefined; }[] | undefined; output_type?: "boolean" | "date" | "datetime" | "number" | "select" | "text" | undefined; volatile?: boolean | undefined; }; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "button"; text: string; workflow_id?: string | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "autonumber"; prefix?: string | undefined; padding?: number | undefined; template?: string | undefined; };
291
+ export type TableField = { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "number"; notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; rating?: { max: number; } | null | undefined; format: "currency" | "number" | "percentage"; currency?: string | null | undefined; unit?: string | null | undefined; unit_field?: string | null | undefined; currency_field?: string | null | undefined; default_value?: number | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "text"; unique?: boolean | undefined; format?: "link" | "markdown" | "text" | "time" | undefined; default_value?: string | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "date"; format?: "date" | "date_range" | "datetime" | "datetime_range" | "month" | undefined; timezone?: string | undefined; derive_from?: "created_at" | "updated_at" | undefined; default_value?: string | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "boolean"; default_value?: boolean | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "select"; options: { key: string; alias?: string | undefined; name: string; color?: "amber" | "blue" | "cyan" | "emerald" | "fuchsia" | "gray" | "green" | "indigo" | "lime" | "neutral" | "orange" | "pink" | "purple" | "red" | "rose" | "sky" | "slate" | "stone" | "teal" | "violet" | "yellow" | "zinc" | undefined; mark?: { kind: string; name: string; } | undefined; short?: string | undefined; }[]; multi?: boolean | undefined; default_value?: string[] | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "select_member"; multi?: boolean | undefined; default_value?: string[] | null | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "select_record_link"; table_id: string; paired_field_key?: string | undefined; cardinality?: "many" | "one" | undefined; default_from?: { link_field_key: string; through?: string[] | undefined; field_key: string; options?: Record<string, string> | undefined; } | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "rollup"; source_field_key: string; aggregate_option: { operation: "checked" | "percent_checked" | "percent_unchecked" | "unchecked"; field_key: string; } | { operation: "empty" | "filled" | "percent_empty" | "percent_filled" | "selected"; field_key: string; } | { operation: "empty" | "filled" | "percent_empty" | "percent_filled" | "percent_unique" | "unique"; field_key: string; } | { operation: "empty" | "filled" | "percent_empty" | "percent_filled" | "percent_unique" | "selected" | "unique"; field_key: string; } | { operation: "date_range" | "earliest" | "empty" | "filled" | "latest" | "percent_empty" | "percent_filled" | "percent_unique" | "unique"; field_key: string; } | { operation: "avg" | "empty" | "filled" | "max" | "median" | "min" | "percent_empty" | "percent_filled" | "percent_unique" | "range" | "sum" | "unique"; field_key: string; } | { operation: "avg" | "date_range" | "earliest" | "empty" | "filled" | "latest" | "max" | "median" | "min" | "percent_empty" | "percent_filled" | "percent_unique" | "range" | "sum" | "unique"; field_key: string; } | { operation: "avg" | "checked" | "date_range" | "earliest" | "empty" | "filled" | "latest" | "max" | "median" | "min" | "percent_checked" | "percent_empty" | "percent_filled" | "percent_unchecked" | "percent_unique" | "range" | "sum" | "unchecked" | "unique"; field_key: string; } | { operation: "count"; field_key?: string | undefined; }; filter?: TableRecordFiltersGroupNode | undefined; aggregate_field_type?: "autonumber" | "boolean" | "button" | "date" | "files" | "formula" | "lookup" | "number" | "rollup" | "select" | "select_member" | "select_record_link" | "text" | undefined; aggregate_field_notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; aggregate_field_format?: string | undefined; aggregate_field_currency?: string | undefined; aggregate_field_unit?: string | undefined; aggregate_field_unit_field?: string | undefined; aggregate_field_currency_field?: string | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "lookup"; source_field_key: string; lookup_field_key: string; lookup_field_type?: "autonumber" | "boolean" | "button" | "date" | "files" | "formula" | "lookup" | "number" | "rollup" | "select" | "select_member" | "select_record_link" | "text" | undefined; lookup_field_notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; lookup_field_format?: string | undefined; lookup_field_currency?: string | undefined; lookup_field_unit?: string | undefined; lookup_field_options?: { key: string; alias?: string | undefined; name: string; color?: string | undefined; mark?: { kind: string; name: string; } | undefined; }[] | undefined; lookup_field_autonumber?: boolean | undefined; lookup_field_several?: true | undefined; order_by?: { field_key: string; direction: "asc" | "desc"; } | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "files"; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "formula"; formula: { expression: string; notation?: { style: "decimal"; } | { style: "currency"; currency: string | { per_row: string; }; } | { style: "unit"; unit: string | { per_row: string; }; } | undefined; link?: true | undefined; format?: "currency" | "link" | "number" | "percentage" | undefined; currency?: string | undefined; unit?: string | undefined; unit_field?: string | undefined; currency_field?: string | undefined; options?: { key: string; alias?: string | undefined; name: string; color?: "amber" | "blue" | "cyan" | "emerald" | "fuchsia" | "gray" | "green" | "indigo" | "lime" | "neutral" | "orange" | "pink" | "purple" | "red" | "rose" | "sky" | "slate" | "stone" | "teal" | "violet" | "yellow" | "zinc" | undefined; mark?: { kind: string; name: string; } | undefined; short?: string | undefined; }[] | undefined; output_type?: "boolean" | "date" | "datetime" | "number" | "select" | "text" | undefined; volatile?: boolean | undefined; }; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "button"; text: string; workflow_id?: string | null | undefined; } | { key: string; alias?: string | undefined; name: string; description: string; confirm_before_update?: boolean | undefined; required?: boolean | undefined; type: "autonumber"; prefix?: string | undefined; padding?: number | undefined; template?: string | undefined; };
290
292
  export type TableRecordFilters = TableRecordFiltersConditionNode | TableRecordFiltersGroupNode | TableRecordFiltersTraversalNode;
291
293
  export type TableRecordFiltersConditionNode = { node_type: "condition"; field_key?: string; type?: string; operator: string; value?: unknown; unit_option?: string; ignore_accents?: boolean; };
292
294
  export type TableRecordFiltersGroupNode = { node_type: "group"; logic: "and" | "or"; children: (TableRecordFiltersConditionNode | TableRecordFiltersTraversalNode | TableRecordFiltersGroupNode)[]; };
@@ -321,8 +323,8 @@ export declare const readLinks: (v: unknown) => ResolvedLink[];
321
323
  export declare const readMembers: (value: unknown) => ResolvedMember[];
322
324
  /**
323
325
  * `[]` for an empty or malformed cell; a bare string (options unresolved
324
- * server-side) becomes `{ key, label: key }`; malformed entries are dropped. A
326
+ * server-side) becomes `{ key, alias: key, label: key }`; malformed entries are dropped. A
325
327
  * lookup's cell, one list per linked row, reads as one list.
326
328
  */
327
329
  export declare const readSelect: (value: unknown) => ResolvedOption[];
328
- export declare const row: { opt: (v: unknown) => string | null; text: (v: unknown) => string; num: (v: unknown) => number | null; bool: (v: unknown) => boolean | null; date: (v: unknown) => Date | null; datetime: (v: unknown) => Date | null; link: (v: unknown) => ResolvedLink | null; };
330
+ export declare const row: { opt: (v: unknown) => string | null; optAlias: (v: unknown) => string | null; text: (v: unknown) => string; num: (v: unknown) => number | null; bool: (v: unknown) => boolean | null; date: (v: unknown) => Date | null; datetime: (v: unknown) => Date | null; link: (v: unknown) => ResolvedLink | null; };
package/docs/ai.md CHANGED
@@ -325,7 +325,7 @@ and calls it correctly. Every alias you declare appears, with every input:
325
325
  ```
326
326
  workflows (run_app_workflow):
327
327
  - updateOrder(reference?: text, shipped_on?: date, owner?: member,
328
- status?: select(In progress=opt_a1b2c3|Complete=opt_d4e5f6),
328
+ status?: select(In progress=in_progress|Complete=complete),
329
329
  attachments?: file[], customer_id?: record_link(Customers)) — …
330
330
  ```
331
331
 
@@ -56,12 +56,12 @@ Do not reach for it N times over one source. Each declared query re-executes its
56
56
  tree, so four facets mounted as four counts are four full scans landing in one burst against the
57
57
  server's concurrency gate. When the counts differ only by the value of one column the query
58
58
  projects — a strip of stages, a facet per option — pass it as `by`: **one scan returns every
59
- value's count as `counts`, beside `total`**. A row holding several values is counted under each; a
59
+ value's count as `counts` (keyed by the option's `alias`), beside `total`**. A row holding several values is counted under each; a
60
60
  row holding none is in `total` only.
61
61
 
62
62
  ```tsx
63
63
  const { total, counts } = useQuery("orders", { q }, { rows: false, total: { by: "stage" } });
64
- // counts?.["opt_shipped"] — the rows in that stage over the whole set, however few are loaded
64
+ // counts?.shipped — keyed by the option's alias; the rows in that stage over the whole set, however few are loaded
65
65
  ```
66
66
 
67
67
  Several counts of one set — a tab each, a share each — are **one read with `total: { where }`**: each
@@ -378,7 +378,7 @@ Wire shapes per output column type:
378
378
  | `boolean` | `boolean` |
379
379
  | `date` | `"YYYY-MM-DD"` — a calendar day, no time component (a reduced-precision date field may also carry `"YYYY-MM"` or `"YYYY"`; see below) |
380
380
  | `datetime` | `"YYYY-MM-DDTHH:mm"` — workspace wall-clock, minute precision |
381
- | `select` | `Array<{ key, label }>` — one entry per selected option |
381
+ | `select` | `Array<{ key, alias, label }>` — one entry per selected option; code compares by `alias` |
382
382
  | `select_member` | `Array<{ id, name, email?, image?, groups? }>` — the last three only for authenticated viewers of the app's own org; `image` presigned |
383
383
  | `select_record_link` | `Array<{ id, display }>` — target record id + the row's name: the field its table names rows by |
384
384
  | `files` | `Array<{ id, filename, mime_type, url, thumbnail_url?, size?, created_at?, document_template_id? }>` — presigned |
@@ -401,15 +401,16 @@ the server's answer is the only check — the rule the filter keys follow too.
401
401
 
402
402
  | Reader | In → out | Semantics |
403
403
  |---|---|---|
404
- | `row.opt(cell)` | select cell → `string \| null` | first option **key** (accepts the legacy bare-string / `{ id }` shapes); `null` when empty |
404
+ | `row.opt(cell)` | select cell → `string \| null` | first option **key** (accepts the legacy bare-string / `{ id }` shapes); `null` when empty. To compare or key by option, use `row.optAlias` |
405
405
  | `row.text(cell)` | any → `string` | strings pass through, finite numbers stringify, everything else → `""` |
406
406
  | `row.num(cell)` | any → `number \| null` | finite numbers pass, parseable strings parse, everything else (empty cell, NaN/Infinity, unparseable string) → `null` |
407
407
  | `row.bool(cell)` | any → `boolean \| null` | `true`/`false` (the strings decode too); everything else → `null` — an unanswered checkbox is not a "no" |
408
408
  | `row.date(cell)` | date/datetime cell → `Date \| null` | the stored **calendar day** at LOCAL midnight — time stripped; a reduced-precision value decodes to its **period start** |
409
409
  | `row.datetime(cell)` | date/datetime cell → `Date \| null` | local `Date` **keeping the stored wall-clock** (minute precision; seconds are dropped); missing time = midnight; a reduced-precision value decodes to its **period start** |
410
+ | `row.optAlias(cell)` | select cell → `string \| null` | the FIRST option's `alias` (the key where the cell states none): the one to compare and key by |
410
411
  | `row.link(cell)` | link cell → `{ id, display } \| null` | the FIRST linked record |
411
412
  | `readLinks(cell)` | link cell → `{ id, display }[]` | ALL linked records (`[]` when empty), a LOOKUP of a link field included |
412
- | `readSelect(cell)` | select cell → `ResolvedOption[]` | all selected options as `{ key, label }` (`[]` when empty) |
413
+ | `readSelect(cell)` | select cell → `ResolvedOption[]` | all selected options as `{ key, alias, label }` (`[]` when empty) |
413
414
  | `readMembers(cell)` | member cell → `ResolvedMember[]` | `{ id, name, email?, image?, groups? }[]` (`[]` when empty) |
414
415
  | `readFiles(cell)` | files cell → `AppFile[]` | attached files with presigned URLs (`[]` when empty), a LOOKUP of a files field included |
415
416
  | `readLocked(rowObj)` | the whole **row** → `boolean` | the record's lock state from `__source_locked` |
@@ -10,8 +10,8 @@ Every select and member value reaches the app in one of two shapes, and most scr
10
10
 
11
11
  | You need | Reach for | What it carries |
12
12
  | --- | --- | --- |
13
- | Render a stored select value | `readSelect(cell)` | The options the record actually holds — `{ key, label }`, **no color** |
14
- | Populate a select picker, or color a stored value | `useFieldOptions(alias)` | Each select column's **complete** option list — `{ key, label, color }` — plus a `byKey` index |
13
+ | Render a stored select value | `readSelect(cell)` | The options the record actually holds — `{ key, alias, label }`, **no color** |
14
+ | Populate a select picker, or color a stored value | `useFieldOptions(alias)` | Each select column's **complete** option list — `{ key, alias, label, color }` — plus `byKey` and `byAlias` indexes |
15
15
  | Filter a number each row reads in its own unit | `useFieldOptions(alias).units` | The units or currencies a range on it compares in — `{ vocabulary, options }` |
16
16
  | Render a stored member value | `readMembers(cell)` | The members the record actually holds |
17
17
  | Populate a member picker (assign UIs) | `useMembers(opts?)` | The org roster — every member, not only the referenced ones |
@@ -24,7 +24,9 @@ member appears without an app change.
24
24
  ## Select option cells (`readSelect`)
25
25
 
26
26
  A `select` column's storage shape is a bare array of option keys. The server rewrites every
27
- projected `select` cell to `Array<{ key, label }>` before the row reaches the app:
27
+ projected `select` cell to `Array<{ key, alias, label }>` before the row reaches the app:
28
+
29
+ - **`alias`** is the option's fixed name in code. Compare by it: a `key` is a random id that differs on a cloned table, and a `label` changes when the option is renamed. A key no option answers (an option deleted after the cell was written) carries itself as its alias.
28
30
 
29
31
  - **`label`** comes from the column's source field's option config. An option deleted after the
30
32
  cell was written resolves with `label` equal to the key — the stale state is visible, not hidden.
@@ -37,7 +39,7 @@ Decode with **`readSelect(cell)`** (`dist/select.d.ts`) → `ResolvedOption[]`:
37
39
 
38
40
  - Returns `[]` for `null`/`undefined`/empty cells and for any unexpected shape — iterate without
39
41
  null-checks.
40
- - A bare-string entry (an unresolvable column's key) becomes `{ key, label: key }`, so single-value
42
+ - A bare-string entry (an unresolvable column's key) becomes `{ key, alias: key, label: key }`, so single-value
41
43
  reads still work.
42
44
  - Malformed entries are dropped, never returned partially.
43
45
 
@@ -54,10 +56,10 @@ up table edits with no app change.
54
56
 
55
57
  ```tsx
56
58
  const { fields } = useFieldOptions("orders"); // same alias you query
57
- // populate a picker: the option KEY is the value a workflow input takes
59
+ // populate a picker: the option ALIAS is the value a workflow input takes
58
60
  <select value={status} onChange={(e) => setStatus(e.target.value)}>
59
61
  {(fields.status?.options ?? []).map((o) => (
60
- <option key={o.key} value={o.key}>{o.label}</option>
62
+ <option key={o.key} value={o.alias}>{o.label}</option>
61
63
  ))}
62
64
  </select>
63
65
  ```
@@ -71,8 +73,9 @@ a compile error, and every key is optional. Each `FieldOptions`:
71
73
  | Property | Meaning |
72
74
  | --- | --- |
73
75
  | `label` | The source field's display name — a ready picker/section label |
74
- | `options` | Every option of the field — `{ key, label, color, mark? }` (the option's own brand or glyph, where the field marks every option) — in field-config order, **including options not present in any current row** |
76
+ | `options` | Every option of the field — `{ key, alias, label, color, mark? }` (the option's own brand or glyph, where the field marks every option) — in field-config order, **including options not present in any current row** |
75
77
  | `byKey(key)` | Resolve one option by key; `undefined` for an unknown key (option removed after the cell was written) |
78
+ | `byAlias(alias)` | Resolve one option by alias; `undefined` for an alias no option states |
76
79
 
77
80
  - `color` is a named palette token (e.g. `"blue"`, `"emerald"`), mapped to a color by the app;
78
81
  draw a missing or unrecognized token neutral.
@@ -118,7 +121,7 @@ const shown = opt ? (fields.status?.byKey(opt.key) ?? opt) : null; // carries `c
118
121
  ```
119
122
 
120
123
  `byKey` hit → the configured color. `byKey` miss (option removed post-write) → fall back to the
121
- cell's own `{ key, label }`, which renders as a neutral badge. Never hand-map option key → color.
124
+ cell's own `{ key, alias, label }`, which renders as a neutral badge. Never hand-map option key → color.
122
125
 
123
126
  ## Member cells (`readMembers`)
124
127
 
package/docs/mutations.md CHANGED
@@ -231,7 +231,7 @@ Every declaration takes optional `description` and `required` (default **true**)
231
231
  | `date` | — | `"YYYY-MM-DD"`, or a TZ-bearing ISO datetime (projected to the workspace day) | `string` |
232
232
  | `datetime` | — | `"YYYY-MM-DDTHH:mm"` naive workspace wall-clock (what the platform DatePicker emits), or TZ-bearing ISO | `string` |
233
233
  | `email` | — | a valid email | `string` |
234
- | `select` | exactly one of `options: [{label, value}]` (min 1) **or** `field: "fld_…"`; `multi?` | an option key (array when `multi`) | union of the option `value`s (inline) or the field's current option keys (`field`); `ReadonlyArray<…>` when `multi` |
234
+ | `select` | exactly one of `options: [{label, value}]` (min 1) **or** `field: "fld_…"`; `multi?` | an option alias (array when `multi`; a key is still accepted) | union of the option `value`s (inline) or the field's current option aliases (`field`); `ReadonlyArray<…>` when `multi` |
235
235
  | `record_link` | `table_id` (required), `multi?` | a record id — must exist **in the declared table** | `string` / `ReadonlyArray<string>` |
236
236
  | `member` | `group?`, `multi?` | a member id — with `group`, must belong to that group | `string` / `ReadonlyArray<string>` |
237
237
  | `file` | `multi?` | a file id from an upload — must live in the app's workspace | `string` / `ReadonlyArray<string>` |
@@ -417,7 +417,7 @@ Why a full-form snapshot save is a bug, not a style choice — three independent
417
417
  // load: snapshot the editable fields from the row
418
418
  const initial = useMemo(() => ({
419
419
  title: row.text(r.title),
420
- status: readSelect(r.status)[0]?.key ?? "",
420
+ status: row.optAlias(r.status) ?? "",
421
421
  }), [r]);
422
422
 
423
423
  // save: send only the diff
@@ -518,7 +518,7 @@ hands the app its **write model** (`GET /v1/apps/{app_id}/write_model`, read onc
518
518
  bound workflow's record writes and the steps they depend on, where each query's columns and rows
519
519
  come from, and the fields they name. `useWorkflow` walks the workflow's own steps against the rows
520
520
  the app has already read, with the evaluator the engine runs, and stages what it will write over
521
- every read before the request answers — a workflow's select options compare as that workflow names them, while the app's reads keep their keys:
521
+ every read before the request answers — a workflow's select options are named by alias, as the app's reads name them:
522
522
 
523
523
  - **Cells.** A written cell redraws in every column that reads it: an option as its label, a member
524
524
  as the face a read or `useMembers` drew, a link as its label — and a column reading the linked row beside it
package/docs/queries.md CHANGED
@@ -23,7 +23,7 @@ several through `nodes`, each call a new version of the app:
23
23
  "kind": "from_table",
24
24
  "table_id": "tbl_orders",
25
25
  "filter": { "node_type": "condition", "field_key": "status",
26
- "operator": "has_any_of", "value": ["opt_open"] }
26
+ "operator": "has_any_of", "value": ["open"] }
27
27
  },
28
28
  "columns": ["order_code", "customer", "total", "created"]
29
29
  }
@@ -116,7 +116,7 @@ reading a column this query does not project is a `tsc` error.
116
116
 
117
117
  **`source_fields_by_table_id` is always `{}`** — the key is part of the shape, the map is not
118
118
  filled. **The complete option sets, with colors, are `useFieldOptions`**; a cell's own
119
- `{ key, label }` comes down on the cell ([members_and_options.md](./members_and_options.md)).
119
+ `{ key, alias, label }` comes down on the cell ([members_and_options.md](./members_and_options.md)).
120
120
 
121
121
  Delivery-layer enrichment (applied to the response, per request):
122
122
 
@@ -130,16 +130,12 @@ Delivery-layer enrichment (applied to the response, per request):
130
130
  `{ id, name, email?, image?, groups? }[]`, the same shape `useMembers` returns. The last three
131
131
  are org-internal and share one gate: present only for authenticated members of the app's own org,
132
132
  and `image` arrives presigned.
133
- - **`select` cells** — bare option-key arrays become `{ key, label }[]` (colors ride in
133
+ - **`select` cells** — bare option-key arrays become `{ key, alias, label }[]` (colors ride in
134
134
  `useFieldOptions`, not the cell — see [members_and_options.md](./members_and_options.md)).
135
135
  **Enrichment needs the column's source addressing**, which a passthrough projection carries, a
136
136
  union carries when its arms agree (or per-row, when the compiler emits it), and a **link
137
- extraction** carries as of the target field it reads. The one shape that has none is a select
138
- reached through a **lookup FIELD**: the column addresses the lookup, whose own type is `lookup`,
139
- not `select` — so the cell stays bare `opt_*` keys AND `useFieldOptions` omits the column
140
- entirely, and reading `.label` off it renders the option KEY. Resolve the keys
141
- (`readSelect(cell).map((o) => o.key)`) against any alias that projects the underlying field
142
- DIRECTLY.
137
+ extraction** carries as of the target field it reads. A select reached through a **lookup
138
+ field** enriches the same way, its alias read from the select it looks up.
143
139
  - **`number` columns** arrive as JS numbers (Postgres `numeric` strings are coerced; a
144
140
  decimal with more digits than a double holds rounds to the double). **`date`/`datetime`** columns
145
141
  arrive as canonical wall-clock strings (`YYYY-MM-DD` / `YYYY-MM-DDTHH:mm`).
@@ -416,7 +412,7 @@ on a link column costs a linked-record read per row. An `unpivot` reads its sour
416
412
 
417
413
  An extracted column **is** addressed to the field it reads on the target table, so the delivery
418
414
  layer treats it like any other field-backed column: an extracted `select` enriches to
419
- `{key,label}` and appears in `useFieldOptions`, and an extracted date resolves relative-date
415
+ `{key,alias,label}` and appears in `useFieldOptions`, and an extracted date resolves relative-date
420
416
  filters in the source field's timezone. It is still never **writable** — a read through a link is
421
417
  not a write path, and `writable_target` rejects it. `link_agg` has the same parent and `source` rules,
422
418
  carries no field addressing (an aggregate of many cells is no one field's value), and its `operation`
@@ -481,10 +477,10 @@ derived surfaces share one implementation.
481
477
  | Field type | Column type | Source-layer operators | Derived-layer differences | Sort / group / aggregate notes |
482
478
  | --- | --- | --- | --- | --- |
483
479
  | text | `text` | `equals`, `not_equals`, `contains`, `does_not_contain`, `starts_with`, `ends_with`, `is_empty`, `is_not_empty`, `is_any_of`, `is_none_of`, `contains_any_of` | same set | Sort is lexicographic in the database's default collation — no locale control — over the trimmed, case-folded text, a column the query derives included; the value read stays as written. Text comparisons normalize both sides (trim + case-insensitive). The LIKE family (`contains`, `does_not_contain`, `starts_with`, `ends_with`, and `contains_any_of`, whose value is a list and which holds when ANY listed word is in the cell) keeps **accents** (`contains "cá"` matches `"Cá hồi"`, not `"Cà chua"`) unless the condition states `"ignore_accents": true`, which folds them, so `contains "ha noi"` matches `"Hà Nội"`; the identity operators (`equals`, `not_equals`, `is_any_of`, `is_none_of`) do **not** — they compare a stored value, and `mã` is not `ma`. |
484
- | number | `number` | `equals`, `not_equals`, `greater_than`, `less_than`, `greater_than_or_equal_to`, `less_than_or_equal_to`, `is_empty`, `is_not_empty` | same set — except a figure read in each row's own unit or currency (a `notation` whose currency or unit is `per_row`, or a rollup totalling in its row's), which a comparison matches only at the source layer: a condition on a column passing it straight through moves there, anywhere else it is refused | Full numeric aggregate set (§8). A comparison on a figure read per row states `unit_option`, the key of the option of that select its value is in — `{ "field_key": "amount", "operator": "greater_than", "value": 100, "unit_option": "opt_usd" }` — and matches only rows holding that option; rows in a measured unit of the same dimension compare converted (`≥ 1` in `t` matches `1500` in `kg`), a counted unit or a currency never. One stating none is refused. |
480
+ | number | `number` | `equals`, `not_equals`, `greater_than`, `less_than`, `greater_than_or_equal_to`, `less_than_or_equal_to`, `is_empty`, `is_not_empty` | same set — except a figure read in each row's own unit or currency (a `notation` whose currency or unit is `per_row`, or a rollup totalling in its row's), which a comparison matches only at the source layer: a condition on a column passing it straight through moves there, anywhere else it is refused | Full numeric aggregate set (§8). A comparison on a figure read per row states `unit_option`, the alias (or key) of the option of that select its value is in — `{ "field_key": "amount", "operator": "greater_than", "value": 100, "unit_option": "usd" }` — and matches only rows holding that option; rows in a measured unit of the same dimension compare converted (`≥ 1` in `t` matches `1500` in `kg`), a counted unit or a currency never. One stating none is refused. |
485
481
  | date / datetime | `date` / `datetime` (datetime when the field's format includes time) | `on`, `before`, `after`, `on_or_before`, `on_or_after`, `between`, `time_of_day`, `is_empty`, `is_not_empty` — values are `DateTimePoint`s (below) | same set | Day-level filters on datetime values expand to the full-day window; a `date` column compares on the day alone, so a time in the filter value is ignored. A reduced-precision value (`"2026-05"`) is its period start, and a value with no time is at `00:00` for `time_of_day`. Sortable; bucketable in `group.by` (§8); `earliest`/`latest`/`min`/`max`/`date_range` aggregate. |
486
482
  | boolean | `boolean` | `equals` (value `true`/`false`; `false` matches NULL/missing) | same | `checked`/`unchecked`/`percent_*` aggregate (`unchecked` counts false **or** empty). |
487
- | select (single & multi) | `select` | `has_any_of`, `has_none_of`, `has_all_of`, `is_empty`, `is_not_empty` — values are **option keys** (`opt_*`), never labels | the **runtime** `filter` (§9) also takes option **names**, resolving each to its key — an unknown one is refused rather than matching nothing, and the value stays an array either way; a select column the query DERIVES instead of projecting from a field or a select literal carries no option set, so addressing one there is refused | Cells are arrays even for single-selects. Sorting a select column orders by its options' order (a multi-select by its first option), an empty cell last, on every page, keyset included; through a `union` whose arms project different selects, each row by its own select's order (§2 `union`); a select the query derives carries no options and orders by raw JSON. `unnest` fans option keys. |
483
+ | select (single & multi) | `select` | `has_any_of`, `has_none_of`, `has_all_of`, `is_empty`, `is_not_empty` — values are **option aliases** (`open`) or keys (`opt_*`), never labels; a count per value is keyed by alias | the **runtime** `filter` (§9) also takes option **names**, resolving each to its key — an unknown one is refused rather than matching nothing, and the value stays an array either way; a select column the query DERIVES instead of projecting from a field or a select literal carries no option set, so addressing one there is refused | Cells are arrays even for single-selects. Sorting a select column orders by its options' order (a multi-select by its first option), an empty cell last, on every page, keyset included; through a `union` whose arms project different selects, each row by its own select's order (§2 `union`); a select the query derives carries no options and orders by raw JSON. `unnest` fans option keys. |
488
484
  | select_member | `select_member` | select ops + `is_current_member`, `is_not_current_member` (field-scoped, no value; `is_not_current_member` matches every cell not holding the requester, an empty one included) | same — `is_current_member` **works at the runtime layer** too | Sorting orders by the first member's name as a reader is shown it (the one the organization gave, else their profile's; a member it does not name reads as empty text), folded like text, then by member id; an empty cell last, on every page, keyset included. `unnest` fans member ids. Anonymous public request: current-member binds the app owner (§1). |
489
485
  | select_record_link | `select_record_link` | membership by linked-record **id**: `has_any_of`, `has_none_of`, `has_all_of`; text over the cached **display** (deprecated — filter by id, and a linked record's field through a lookup): `contains`, `not_contains`, `starts_with`, `ends_with`; `is_empty`, `is_not_empty` | same — id-membership works at the runtime layer (converged `[{id}]` containment) | Sorting orders by the first linked record's display, folded like text, then by its id; an empty cell last, on every page, keyset included. `unnest` fans link ids (+ display). |
490
486
  | files | `files` | `has_filename`, `has_mime_type` (substring), `has_file_count` (exact count), `is_empty`, `is_not_empty` | same | Presign-enriched at delivery (§1); `unnest` fans file ids. Only presence-counting aggregates. |
@@ -532,7 +528,7 @@ tree shape — `TableRecordFilters`:
532
528
 
533
529
  ```jsonc
534
530
  // condition — one predicate
535
- { "node_type": "condition", "field_key": "status", "operator": "has_any_of", "value": ["opt_open"] }
531
+ { "node_type": "condition", "field_key": "status", "operator": "has_any_of", "value": ["open"] }
536
532
  // group — AND/OR of children (conditions, traversals, nested groups)
537
533
  { "node_type": "group", "logic": "and", "children": [ … ] }
538
534
  // traversal — a predicate on a record reachable through link hops
package/docs/recipes.md CHANGED
@@ -112,8 +112,8 @@ Full pattern, including the date-param trick for range filters: [queries](./quer
112
112
  A query cell is `unknown` with a per-type serialized shape, and the readers own it: `row.opt` /
113
113
  `row.text` / `row.num` / `row.bool` / `row.date` / `row.datetime`, `readSelect`, `readMembers`,
114
114
  `row.link` / `readLinks` ([data fetching](./data_fetching.md#the-readers)). A hand-rolled `firstOpt` /
115
- `linkDisplay` re-implements that contract: a select cell is `[{key,label}]`, so a reader that grabs
116
- the wrong half is *plausible and wrong* rather than broken.
115
+ `linkDisplay` re-implements that contract: a select cell is `[{key,alias,label}]`, so a reader that grabs
116
+ the wrong half is *plausible and wrong* rather than broken. Compare and key an option by its `alias` (`row.optAlias`, `counts`, a workflow's outputs): a `key` differs on a cloned table and a `label` changes on a rename.
117
117
 
118
118
  ## Set the icon and colour
119
119
 
package/docs/workflows.md CHANGED
@@ -19,14 +19,14 @@ engine, no `eval`, no sandbox. Four consequences shape everything below:
19
19
  - **One canonical form per concept.** Several JS spellings are accepted and *lowered* to one
20
20
  stored form. The stored tree renders back to source when it is read (`get_workflow`), so a
21
21
  read body shows the canonical spelling, not the sugar you typed (see *Round-tripping* below).
22
- - **Opaque keys, never display names.** Fields are `fld_*`, select options are `opt_*`, tables
22
+ - **Opaque keys, never display names.** Fields are `fld_*`, select options are named by their alias, tables
23
23
  are `tbl_*`, groups are `grp_*`. A display name is rejected at save with an error pointing at
24
24
  the right key. The generated types carry the human-readable name in a JSDoc comment; the
25
25
  *value* is always the key.
26
26
 
27
27
  ```js
28
- // A field read by its opaque key, compared against one of that field's option keys:
29
- if (order.data["fld_status"] == "opt_open") { … }
28
+ // A field read by its opaque key, compared against one of that field's option aliases:
29
+ if (order.data["fld_status"] == "open") { … }
30
30
  ```
31
31
 
32
32
  ## Where a body lives
@@ -88,11 +88,11 @@ because it is grammar rather than a helper — the path continues through it.
88
88
 
89
89
  **A record reads in its declared shape, however it reached you.** Every row a records tool
90
90
  returns, the trigger record and its diff, and every row `linked(...)` fetches arrive shaped as the
91
- generated types declare them: a single select as its option key or `null`, one member as its id
91
+ generated types declare them: a single select as its option alias or `null`, one member as its id
92
92
  or `null`, a link as its ids. So a row read through a `let`, a ternary, a callback parameter, a
93
93
  helper result, a table id held in a variable, or a value that waited through a pause reads the
94
94
  same as one read straight off the call. (A record *tool* run from the CLI or chat serves what is
95
- stored — a single select as `["opt_x"]` — so take a field's shape from the generated types, never
95
+ stored — a single select as `["opt_x"]`, a key — so take a field's shape from the generated types, never
96
96
  from a transcript.)
97
97
 
98
98
  **A link field reads as an array of ids, in every spelling.** `order.data["fld_link"]` is
@@ -512,7 +512,7 @@ Everything else does not — a lambda anywhere else is rejected.
512
512
  - A body may read the reserved roots, the names in scope, enclosing `for-of` items, and an
513
513
  enclosing lambda's parameters. A parameter spelled like an outer name shadows it inside the body.
514
514
  - A callback's item reads in its declared shape (see *Path access*), so a callback over rows
515
- reads `r.data["fld_status"]` as the option key whatever the rows came from.
515
+ reads `r.data["fld_status"]` as the option alias whatever the rows came from.
516
516
  - `reduce` is callback-only and its **initial value is required** (it is what gives the
517
517
  accumulator a type).
518
518
  - Most of these also accept a **path-string** form instead of a callback, resolved with `get`
@@ -615,8 +615,8 @@ Value shapes, which the generated types enforce exactly:
615
615
 
616
616
  | Field | Read | Write |
617
617
  |---|---|---|
618
- | single `select` | one `opt_*` key, or `null` | the key: `fld_status: "opt_open"` |
619
- | multi `select` | array of `opt_*` keys | array: `fld_tags: ["opt_urgent"]` |
618
+ | single `select` | one option alias, or `null` | the alias: `fld_status: "open"` (a key is still accepted) |
619
+ | multi `select` | array of option aliases | array: `fld_tags: ["urgent"]` |
620
620
  | single `select_member` | one member id, or `null` | the id |
621
621
  | multi `select_member` | array of member ids | array |
622
622
  | `select_record_link` | array of ids — `linked(...)` fetches the rows | array of ids: `fld_customer: [customer.id]`, or a link read fed straight back |
@@ -685,12 +685,12 @@ The catch is where you build that array, and it is not obvious. **Write the lite
685
685
  call**, so it is typed by the `records` parameter:
686
686
 
687
687
  ```js
688
- // ONE trip. The array literal is contextually typed by `records`, so "opt_bVPEMB"
688
+ // ONE trip. The array literal is contextually typed by `records`, so "vao_bai"
689
689
  // stays the literal the table's write type wants.
690
690
  await create_records({
691
691
  records: concat(
692
- coRaVao ? [{ fld_khoan: "opt_bVPEMB", fld_tien: giaRaVao, fld_chuyen: [i.chuyen_id] }] : [],
693
- coVeSinh ? [{ fld_khoan: "opt_nx0KAL", fld_tien: giaVeSinh, fld_chuyen: [i.chuyen_id] }] : [],
692
+ coRaVao ? [{ fld_khoan: "vao_bai", fld_tien: giaRaVao, fld_chuyen: [i.chuyen_id] }] : [],
693
+ coVeSinh ? [{ fld_khoan: "ve_sinh", fld_tien: giaVeSinh, fld_chuyen: [i.chuyen_id] }] : [],
694
694
  ),
695
695
  table_id: "tbl_…",
696
696
  });
@@ -702,14 +702,14 @@ from the fix:
702
702
  ```js
703
703
  let rows = [];
704
704
  for (const g of gia.records) {
705
- rows = concat(rows, [{ fld_khoan: "opt_bVPEMB", … }]); // widens to `string`
705
+ rows = concat(rows, [{ fld_khoan: "vao_bai", … }]); // widens to `string`
706
706
  }
707
707
  await create_records({ records: rows, … });
708
708
  // TS2322: Type '{ fld_khoan: string; … }[]' is not assignable to 'readonly …RecordWrite[]'.
709
- // Type 'string' is not assignable to '"opt_bVPEMB" | "opt_nx0KAL" | … | null'.
709
+ // Type 'string' is not assignable to '"vao_bai" | "ve_sinh" | … | null'.
710
710
  ```
711
711
 
712
- `concat` widens a select's option key to `string` the moment it leaves the literal, and an
712
+ `concat` widens a select's option alias to `string` the moment it leaves the literal, and an
713
713
  annotation is not in the subset. Let the call site supply the type: keep the loop for FINDING
714
714
  values and put the writing after it.
715
715
 
@@ -761,17 +761,17 @@ The rules that are easy to get wrong because the failing code looks correct.
761
761
  iteration 0 and silently skip every remaining iteration and its mutations. Move the wait out,
762
762
  or split the loop into separately triggered runs.
763
763
  - **String contexts coerce to display text.** A read inside a template or a string-typed argument
764
- renders the *label*; everywhere else it is the raw key. So
764
+ renders the *label*; everywhere else it is the raw alias. So
765
765
  `` `Status: ${record["fld_status"]}` `` prints "Done" while
766
- `record["fld_status"] == "opt_done"` compares keys — both correct, and neither substitutes for
766
+ `record["fld_status"] == "done"` compares aliases — both correct, and neither substitutes for
767
767
  the other. It holds on every route a record arrives by — a `let`, a callback parameter, a row
768
768
  from a variable `table_id`.
769
769
  - **Multi-select `==` quietly desugars.** On a multi-select field,
770
- `record["fld_tags"] == "opt_urgent"` rewrites to `includes(…)` at save. Either spelling is
770
+ `record["fld_tags"] == "urgent"` rewrites to `includes(…)` at save. Either spelling is
771
771
  fine — but a `switch` on a multi-select discriminant is **rejected**, because its value is an
772
772
  array and no string `case` could ever match. Use `if (includes(…))` branches. `switch` cases
773
773
  must be string literals, each in its own `{ }` block; there is no fallthrough, and a case on a
774
- single-select discriminant is option-key-validated.
774
+ single-select discriminant is option-validated.
775
775
  - **`let` survives a wait, so its values must survive JSON.** The binding stack is snapshotted at
776
776
  the pause and hydrated on resume — no Dates, functions, or Maps in a `let` initializer.
777
777
  - **An empty accumulator can't infer its element type.** `let xs = []` then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.130.4",
3
+ "version": "0.131.1",
4
4
  "description": "The SDK a Lotics custom-code app reads and writes through — typed hooks over the host bridge, cell readers, mount() and AppRouter",
5
5
  "type": "module",
6
6
  "exports": {