@lotics/app-sdk 0.130.3 → 0.131.0
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 +182 -133
- package/dist/overlay.d.ts +1 -1
- package/dist/queries.d.ts +5 -1
- package/dist/router.js +1 -1
- package/dist/row.d.ts +1 -1
- package/dist/shared_types.d.ts +8 -6
- package/docs/ai.md +1 -1
- package/docs/data_fetching.md +6 -5
- package/docs/members_and_options.md +11 -8
- package/docs/mutations.md +3 -3
- package/docs/queries.md +9 -13
- package/docs/recipes.md +2 -2
- package/docs/workflows.md +18 -18
- package/package.json +1 -1
- /package/dist/{chunk-GYTOFOC2.js → chunk-V4APGE4F.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
subtractDecimal,
|
|
52
52
|
sumDecimal,
|
|
53
53
|
urlParam
|
|
54
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-V4APGE4F.js";
|
|
55
55
|
|
|
56
56
|
// src/mount.tsx
|
|
57
57
|
import { createRoot } from "react-dom/client";
|
|
@@ -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
|
|
369
|
-
if (
|
|
370
|
-
const option = question.options[
|
|
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:
|
|
377
|
-
option_letter: toLetter(
|
|
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((
|
|
1167
|
+
return selectValues.map((ref) => optionIn(field.options, ref)?.name ?? ref).join(", ");
|
|
1040
1168
|
}
|
|
1041
|
-
const option = field.options
|
|
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
|
|
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: () =>
|
|
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
|
|
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);
|
|
@@ -10008,109 +10140,6 @@ function stringifyForTemplate(value) {
|
|
|
10008
10140
|
return textOf(value);
|
|
10009
10141
|
}
|
|
10010
10142
|
|
|
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
10143
|
// ../shared/src/workflow_effect_plan.ts
|
|
10115
10144
|
var WITHHELD = "__withheld";
|
|
10116
10145
|
|
|
@@ -11393,6 +11422,14 @@ function opt(v) {
|
|
|
11393
11422
|
}
|
|
11394
11423
|
return null;
|
|
11395
11424
|
}
|
|
11425
|
+
function optAlias(v) {
|
|
11426
|
+
if (Array.isArray(v)) return v.length ? optAlias(v[0]) : null;
|
|
11427
|
+
if (v && typeof v === "object") {
|
|
11428
|
+
const alias = v.alias;
|
|
11429
|
+
if (typeof alias === "string" && alias !== "") return alias;
|
|
11430
|
+
}
|
|
11431
|
+
return opt(v);
|
|
11432
|
+
}
|
|
11396
11433
|
function text(v) {
|
|
11397
11434
|
if (typeof v === "string") return v;
|
|
11398
11435
|
if (typeof v === "number" && Number.isFinite(v)) return String(v);
|
|
@@ -11452,13 +11489,13 @@ function readLinks(v) {
|
|
|
11452
11489
|
}
|
|
11453
11490
|
return out;
|
|
11454
11491
|
}
|
|
11455
|
-
var row = { opt, text, num, bool, date, datetime, link };
|
|
11492
|
+
var row = { opt, optAlias, text, num, bool, date, datetime, link };
|
|
11456
11493
|
function readSelect(value) {
|
|
11457
11494
|
if (!Array.isArray(value)) return [];
|
|
11458
11495
|
const out = [];
|
|
11459
11496
|
for (const entry of value.flat(Infinity)) {
|
|
11460
11497
|
if (typeof entry === "string") {
|
|
11461
|
-
if (entry !== "") out.push({ key: entry, label: entry });
|
|
11498
|
+
if (entry !== "") out.push({ key: entry, alias: entry, label: entry });
|
|
11462
11499
|
continue;
|
|
11463
11500
|
}
|
|
11464
11501
|
if (!entry || typeof entry !== "object") continue;
|
|
@@ -11466,7 +11503,8 @@ function readSelect(value) {
|
|
|
11466
11503
|
const key = obj.key;
|
|
11467
11504
|
if (typeof key !== "string" || key === "") continue;
|
|
11468
11505
|
const label = typeof obj.label === "string" ? obj.label : key;
|
|
11469
|
-
|
|
11506
|
+
const alias = typeof obj.alias === "string" && obj.alias !== "" ? obj.alias : key;
|
|
11507
|
+
out.push({ key, alias, label });
|
|
11470
11508
|
}
|
|
11471
11509
|
return out;
|
|
11472
11510
|
}
|
|
@@ -11564,8 +11602,8 @@ function countsOf(rows, by) {
|
|
|
11564
11602
|
const cell = one[by];
|
|
11565
11603
|
const held2 = Array.isArray(cell) ? cell : cell == null ? [] : [cell];
|
|
11566
11604
|
for (const value of held2) {
|
|
11567
|
-
const
|
|
11568
|
-
if (
|
|
11605
|
+
const alias = row.optAlias(value);
|
|
11606
|
+
if (alias !== null) counts[alias] = (counts[alias] ?? 0) + 1;
|
|
11569
11607
|
}
|
|
11570
11608
|
}
|
|
11571
11609
|
return counts;
|
|
@@ -12547,6 +12585,9 @@ function firstOptionKey(cell) {
|
|
|
12547
12585
|
}
|
|
12548
12586
|
return void 0;
|
|
12549
12587
|
}
|
|
12588
|
+
function isZeroBound(value) {
|
|
12589
|
+
return typeof value === "number" && value === 0;
|
|
12590
|
+
}
|
|
12550
12591
|
function comparesFigure(operator) {
|
|
12551
12592
|
return operator !== "is_empty" && operator !== "is_not_empty";
|
|
12552
12593
|
}
|
|
@@ -12565,24 +12606,24 @@ function conditionUnit(condition2, field, fieldOf3) {
|
|
|
12565
12606
|
const held2 = options.length === 0 ? `${select === void 0 ? `"${read2.key}"` : nameOf(select)} holds no ${read2.vocabulary} yet` : `one of ${options.map((option2) => `${option2.name} (${option2.key})`).join(", ")}`;
|
|
12566
12607
|
const reads = `${nameOf(field)} is read in each row's own ${read2.vocabulary} (${select === void 0 ? `"${read2.key}"` : nameOf(select)})`;
|
|
12567
12608
|
if (stated === void 0) {
|
|
12568
|
-
const unstated = condition2.value === null || condition2.value === void 0 || condition2.value === "";
|
|
12609
|
+
const unstated = condition2.value === null || condition2.value === void 0 || condition2.value === "" || isZeroBound(condition2.value);
|
|
12569
12610
|
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}.` };
|
|
12570
12611
|
}
|
|
12571
|
-
const option = typeof stated === "string" ? options
|
|
12612
|
+
const option = typeof stated === "string" ? optionIn(options, stated) : void 0;
|
|
12572
12613
|
if (option === void 0) {
|
|
12573
12614
|
return { ok: false, reason: `${reads}; unit_option ${JSON.stringify(stated)} is none of them: ${held2}.` };
|
|
12574
12615
|
}
|
|
12575
12616
|
const target = read2.vocabulary === "unit" ? measuredUnit(option.name) : void 0;
|
|
12576
|
-
if (target === void 0) return { ok: true, unit: { select: read2, options: [{ key: option.key, factor: 1 }], factor: 1 } };
|
|
12617
|
+
if (target === void 0) return { ok: true, unit: { select: read2, options: [{ key: option.key, alias: option.alias, factor: 1 }], factor: 1 } };
|
|
12577
12618
|
const kin = options.flatMap((candidate) => {
|
|
12578
12619
|
const measured = measuredUnit(candidate.name);
|
|
12579
|
-
return measured?.dimension === target.dimension ? [{ key: candidate.key, factor: measured.factor }] : [];
|
|
12620
|
+
return measured?.dimension === target.dimension ? [{ key: candidate.key, alias: candidate.alias, factor: measured.factor }] : [];
|
|
12580
12621
|
});
|
|
12581
12622
|
return { ok: true, unit: { select: read2, options: kin, factor: target.factor } };
|
|
12582
12623
|
}
|
|
12583
12624
|
function rowUnitFactor(unit, data) {
|
|
12584
12625
|
const key = firstOptionKey(data[unit.select.key]);
|
|
12585
|
-
return key === void 0 ? void 0 : unit.options
|
|
12626
|
+
return key === void 0 ? void 0 : optionIn(unit.options, key)?.factor;
|
|
12586
12627
|
}
|
|
12587
12628
|
|
|
12588
12629
|
// ../shared/src/filter.ts
|
|
@@ -13085,7 +13126,9 @@ function matchCell(cell, field, filterCondition, looseCondition, memberContext,
|
|
|
13085
13126
|
}
|
|
13086
13127
|
} else if (filterCondition.type === "select") {
|
|
13087
13128
|
const value = columnValue;
|
|
13088
|
-
const
|
|
13129
|
+
const options = effectiveSelectOptions(field);
|
|
13130
|
+
const keyOf2 = (ref) => options === null ? ref : optionKeyIn(options, ref) ?? ref;
|
|
13131
|
+
const recordValues = (value ?? []).map(keyOf2);
|
|
13089
13132
|
const isRecordEmpty = !value || recordValues.length === 0;
|
|
13090
13133
|
if (filterCondition.operator === "is_empty") {
|
|
13091
13134
|
matches = isRecordEmpty;
|
|
@@ -13095,7 +13138,7 @@ function matchCell(cell, field, filterCondition, looseCondition, memberContext,
|
|
|
13095
13138
|
if (filterCondition.value === null) {
|
|
13096
13139
|
return null;
|
|
13097
13140
|
}
|
|
13098
|
-
const filterValues = filterCondition.value;
|
|
13141
|
+
const filterValues = filterCondition.value.map(keyOf2);
|
|
13099
13142
|
const hasEmptyInFilter = filterValues.includes("");
|
|
13100
13143
|
if (filterCondition.operator === "has_any_of") {
|
|
13101
13144
|
matches = hasEmptyInFilter && isRecordEmpty || filterValues.some((filterVal) => filterVal !== "" && recordValues.includes(filterVal));
|
|
@@ -13408,7 +13451,7 @@ function fieldValueInfo(field) {
|
|
|
13408
13451
|
return {
|
|
13409
13452
|
type: field.lookup_field_type ?? "text",
|
|
13410
13453
|
...field.lookup_field_type === "number" ? { notation: fieldNotation(field) } : { format: field.lookup_field_format },
|
|
13411
|
-
options: field.lookup_field_options,
|
|
13454
|
+
options: field.lookup_field_options === void 0 ? void 0 : carriedOptions(field.lookup_field_options),
|
|
13412
13455
|
autonumber: field.lookup_field_autonumber,
|
|
13413
13456
|
several: field.lookup_field_several
|
|
13414
13457
|
};
|
|
@@ -14260,7 +14303,7 @@ function drawn(over, field, stored) {
|
|
|
14260
14303
|
const keys2 = Array.isArray(stored) ? stored : [];
|
|
14261
14304
|
return keys2.map((key) => {
|
|
14262
14305
|
const option = field.options.find((one) => one.key === key);
|
|
14263
|
-
return { key, label: option === void 0 ? String(key) : option.name };
|
|
14306
|
+
return { key, alias: optionAliasIn(field.options, String(key)), label: option === void 0 ? String(key) : option.name };
|
|
14264
14307
|
});
|
|
14265
14308
|
}
|
|
14266
14309
|
case "select_member": {
|
|
@@ -14459,10 +14502,15 @@ function storedCellOf(cell) {
|
|
|
14459
14502
|
if (!Array.isArray(cell)) return cell;
|
|
14460
14503
|
return cell.map((one) => one !== null && typeof one === "object" ? Reflect.get(one, "key") ?? Reflect.get(one, "id") ?? one : one);
|
|
14461
14504
|
}
|
|
14462
|
-
function groupsOf(totals, side) {
|
|
14505
|
+
function groupsOf(over, totals, side) {
|
|
14463
14506
|
if (!totals.by.every(({ field_key }) => side.cells.has(field_key) && !side.unknown.has(field_key))) return null;
|
|
14464
14507
|
const [only] = totals.by;
|
|
14465
|
-
if (totals.each && only !== void 0)
|
|
14508
|
+
if (totals.each && only !== void 0) {
|
|
14509
|
+
const field = over.field(totals.table_id, only.field_key);
|
|
14510
|
+
const keys2 = Object.keys(countsOf([{ cell: side.cells.get(only.field_key) }], "cell"));
|
|
14511
|
+
const options = effectiveSelectOptions(field);
|
|
14512
|
+
return options === null ? keys2 : keys2.map((key) => optionAliasIn(options, key));
|
|
14513
|
+
}
|
|
14466
14514
|
return [
|
|
14467
14515
|
JSON.stringify(
|
|
14468
14516
|
totals.by.map(({ field_key, tiers }) => {
|
|
@@ -14486,8 +14534,8 @@ function overlayTotals(over, totals, admits, closed, rows) {
|
|
|
14486
14534
|
pending = true;
|
|
14487
14535
|
continue;
|
|
14488
14536
|
}
|
|
14489
|
-
const from = before.in ? groupsOf(totals, before) : [];
|
|
14490
|
-
const to = after.in ? groupsOf(totals, after) : [];
|
|
14537
|
+
const from = before.in ? groupsOf(over, totals, before) : [];
|
|
14538
|
+
const to = after.in ? groupsOf(over, totals, after) : [];
|
|
14491
14539
|
if (from === null || to === null) {
|
|
14492
14540
|
pending = true;
|
|
14493
14541
|
continue;
|
|
@@ -14895,7 +14943,8 @@ function useFieldOptions(alias, opts) {
|
|
|
14895
14943
|
for (const [column, def] of Object.entries(answer.data?.fields ?? {})) {
|
|
14896
14944
|
const options = def.options ?? [];
|
|
14897
14945
|
const index = new Map(options.map((option) => [option.key, option]));
|
|
14898
|
-
|
|
14946
|
+
const aliasIndex = new Map(options.map((option) => [option.alias, option]));
|
|
14947
|
+
out[column] = { label: def.label, options, byKey: (key) => index.get(key), byAlias: (alias2) => aliasIndex.get(alias2) };
|
|
14899
14948
|
}
|
|
14900
14949
|
return out;
|
|
14901
14950
|
}, [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
|
|
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
|
|
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/router.js
CHANGED
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. */
|