@lotics/app-sdk 0.128.7 → 0.130.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 +146 -15
- package/docs/mutations.md +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8841,6 +8841,7 @@ function lexicalAnchor(name, path, ctx, seen) {
|
|
|
8841
8841
|
const write2 = step.type === "let_declare" && step.name === name ? step.initial : step.type === "assign" && step.name === name ? step.value : null;
|
|
8842
8842
|
if (write2 === null) continue;
|
|
8843
8843
|
found = true;
|
|
8844
|
+
if (write2.kind === "lit" && write2.value === null) continue;
|
|
8844
8845
|
const anchor = boundValueAnchor(write2, path, ctx, new Set(seen));
|
|
8845
8846
|
if (!anchor) return null;
|
|
8846
8847
|
if (agreed === null) {
|
|
@@ -10035,6 +10036,109 @@ function stringifyForTemplate(value) {
|
|
|
10035
10036
|
return textOf(value);
|
|
10036
10037
|
}
|
|
10037
10038
|
|
|
10039
|
+
// ../shared/src/schemas/select_walk.ts
|
|
10040
|
+
function selectEnd(field, table, walk) {
|
|
10041
|
+
let current = { field, table };
|
|
10042
|
+
let several;
|
|
10043
|
+
for (let hops = 0; hops <= RESULT_HOPS; hops++) {
|
|
10044
|
+
if (walk.holds(current.field, current.table)) return { ...current, hops, several };
|
|
10045
|
+
const step = walk.through(current.field, current.table);
|
|
10046
|
+
if (step === void 0) return void 0;
|
|
10047
|
+
several ??= step.several ? { link: step.link, table: current.table } : void 0;
|
|
10048
|
+
current = { field: step.shown, table: step.target };
|
|
10049
|
+
}
|
|
10050
|
+
return void 0;
|
|
10051
|
+
}
|
|
10052
|
+
|
|
10053
|
+
// ../shared/src/schemas/select_options.ts
|
|
10054
|
+
function selectOptionsOf(field) {
|
|
10055
|
+
if (field.type === "select") return field.options;
|
|
10056
|
+
if (field.type === "formula") return field.formula.options;
|
|
10057
|
+
return void 0;
|
|
10058
|
+
}
|
|
10059
|
+
|
|
10060
|
+
// ../shared/src/select_cell_alias.ts
|
|
10061
|
+
var byKeyOf = /* @__PURE__ */ new WeakMap();
|
|
10062
|
+
function fieldsByKey(fields) {
|
|
10063
|
+
const held2 = byKeyOf.get(fields);
|
|
10064
|
+
if (held2 !== void 0) return held2;
|
|
10065
|
+
const built = new Map(fields.map((field) => [field.key, field]));
|
|
10066
|
+
byKeyOf.set(fields, built);
|
|
10067
|
+
return built;
|
|
10068
|
+
}
|
|
10069
|
+
var fieldOf = (fields, key) => fieldsByKey(fields).get(key);
|
|
10070
|
+
function selectFieldHolder(tables, fieldKey) {
|
|
10071
|
+
let found;
|
|
10072
|
+
for (const table of tables) {
|
|
10073
|
+
const field = fieldOf(table.fields, fieldKey);
|
|
10074
|
+
if (field !== void 0) found = { table, field };
|
|
10075
|
+
}
|
|
10076
|
+
return found;
|
|
10077
|
+
}
|
|
10078
|
+
var fieldsWalk = (linked) => ({
|
|
10079
|
+
holds: (field) => selectOptionsOf(field) !== void 0,
|
|
10080
|
+
through: (field, table) => {
|
|
10081
|
+
if (field.type !== "lookup") return void 0;
|
|
10082
|
+
const link2 = fieldOf(table.fields, field.source_field_key);
|
|
10083
|
+
const fields = link2?.type === "select_record_link" ? linked(link2.table_id) : void 0;
|
|
10084
|
+
const shown = fields === void 0 ? void 0 : fieldOf(fields, field.lookup_field_key);
|
|
10085
|
+
return link2?.type !== "select_record_link" || fields === void 0 || shown === void 0 ? void 0 : { link: link2.key, several: link2.cardinality !== "one", target: { fields }, shown };
|
|
10086
|
+
}
|
|
10087
|
+
});
|
|
10088
|
+
function selectBehind(field, owner, linked) {
|
|
10089
|
+
const end = selectEnd(field, { fields: owner }, fieldsWalk(linked));
|
|
10090
|
+
return end === void 0 ? void 0 : { field: end.field, fields: end.table.fields };
|
|
10091
|
+
}
|
|
10092
|
+
function optionAliasOf(field, optionKey) {
|
|
10093
|
+
return selectOptionsOf(field)?.find((option) => option.key === optionKey)?.alias ?? optionKey;
|
|
10094
|
+
}
|
|
10095
|
+
function optionKeyOf(field, ref) {
|
|
10096
|
+
const options = selectOptionsOf(field) ?? [];
|
|
10097
|
+
return (options.find((option) => option.key === ref) ?? options.find((option) => option.alias === ref))?.key;
|
|
10098
|
+
}
|
|
10099
|
+
function renamedDeep(value, rename) {
|
|
10100
|
+
if (typeof value === "string") return rename(value);
|
|
10101
|
+
if (Array.isArray(value)) return value.map((one) => renamedDeep(one, rename));
|
|
10102
|
+
return value;
|
|
10103
|
+
}
|
|
10104
|
+
function optionValue(value, rename) {
|
|
10105
|
+
if (typeof value === "string") return rename(value);
|
|
10106
|
+
if (Array.isArray(value)) return value.map((one) => typeof one === "string" ? rename(one) : one);
|
|
10107
|
+
return value;
|
|
10108
|
+
}
|
|
10109
|
+
function optionAliasing(fields, linked) {
|
|
10110
|
+
const lookedUp = (field) => field.type === "lookup" && linked !== void 0 ? selectBehind(field, fields, linked)?.field : void 0;
|
|
10111
|
+
const option = (fieldKey, optionKey) => {
|
|
10112
|
+
const field = fieldOf(fields, fieldKey);
|
|
10113
|
+
const looked = field === void 0 ? void 0 : lookedUp(field);
|
|
10114
|
+
return looked !== void 0 ? optionAliasOf(looked, optionKey) : field === void 0 ? optionKey : optionAliasOf(field, optionKey);
|
|
10115
|
+
};
|
|
10116
|
+
const cell = (fieldKey, value) => {
|
|
10117
|
+
const field = fieldOf(fields, fieldKey);
|
|
10118
|
+
if (field === void 0 || selectOptionsOf(field) === void 0 && lookedUp(field) === void 0) return value;
|
|
10119
|
+
return field.type === "lookup" ? renamedDeep(value, (one) => option(fieldKey, one)) : optionValue(value, (one) => option(fieldKey, one));
|
|
10120
|
+
};
|
|
10121
|
+
return { option, cell };
|
|
10122
|
+
}
|
|
10123
|
+
function renamedSelectValues(schema, payload, rename) {
|
|
10124
|
+
const walk = (node, value) => {
|
|
10125
|
+
if (node.type === "select" && node.field !== void 0) {
|
|
10126
|
+
const field = node.field;
|
|
10127
|
+
return Array.isArray(value) ? value.map((one) => rename(field, one)) : rename(field, value);
|
|
10128
|
+
}
|
|
10129
|
+
if (node.fields !== void 0 && typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
10130
|
+
const fields = node.fields;
|
|
10131
|
+
return Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, fields[key] === void 0 ? inner : walk(fields[key], inner)]));
|
|
10132
|
+
}
|
|
10133
|
+
if (node.items !== void 0 && Array.isArray(value)) {
|
|
10134
|
+
const items = node.items;
|
|
10135
|
+
return value.map((item) => walk(items, item));
|
|
10136
|
+
}
|
|
10137
|
+
return value;
|
|
10138
|
+
};
|
|
10139
|
+
return Object.fromEntries(Object.entries(payload).map(([key, value]) => [key, schema[key] === void 0 ? value : walk(schema[key], value)]));
|
|
10140
|
+
}
|
|
10141
|
+
|
|
10038
10142
|
// ../shared/src/workflow_effect_plan.ts
|
|
10039
10143
|
var WITHHELD = "__withheld";
|
|
10040
10144
|
|
|
@@ -10449,7 +10553,27 @@ function clientRuntime(input) {
|
|
|
10449
10553
|
}
|
|
10450
10554
|
};
|
|
10451
10555
|
}
|
|
10452
|
-
|
|
10556
|
+
function inBodyAliases(input) {
|
|
10557
|
+
const linked = (tableId) => input.tables.get(tableId)?.fields;
|
|
10558
|
+
const holder = (fieldKey) => selectFieldHolder(input.tables.values(), fieldKey)?.field;
|
|
10559
|
+
return {
|
|
10560
|
+
...input,
|
|
10561
|
+
inputs: renamedSelectValues(input.select_inputs ?? {}, input.inputs, (fieldKey, value) => {
|
|
10562
|
+
const field = holder(fieldKey);
|
|
10563
|
+
const key = field === void 0 || typeof value !== "string" ? void 0 : optionKeyOf(field, value);
|
|
10564
|
+
return field === void 0 || key === void 0 ? value : optionAliasOf(field, key);
|
|
10565
|
+
}),
|
|
10566
|
+
known: (recordId) => {
|
|
10567
|
+
const record = input.known(recordId);
|
|
10568
|
+
const table = record === void 0 ? void 0 : input.tables.get(record.table_id);
|
|
10569
|
+
if (record === void 0 || table === void 0) return record;
|
|
10570
|
+
const { cell } = optionAliasing(table.fields, linked);
|
|
10571
|
+
return { ...record, cells: Object.fromEntries(Object.entries(record.cells).map(([key, value]) => [key, cell(key, value)])) };
|
|
10572
|
+
}
|
|
10573
|
+
};
|
|
10574
|
+
}
|
|
10575
|
+
async function predictWorkflowEffects(given) {
|
|
10576
|
+
const input = inBodyAliases(given);
|
|
10453
10577
|
const helpers = {
|
|
10454
10578
|
...createTimezoneAwareFunctions(input.timezone),
|
|
10455
10579
|
// Group membership and whom the caller stands in for are the server's to answer.
|
|
@@ -10476,7 +10600,6 @@ async function predictWorkflowEffects(input) {
|
|
|
10476
10600
|
step_outputs: {},
|
|
10477
10601
|
runtime: clientRuntime(input),
|
|
10478
10602
|
helpers,
|
|
10479
|
-
body_spelling: "key",
|
|
10480
10603
|
record_cache: cache,
|
|
10481
10604
|
fetch_record: fetchRecord,
|
|
10482
10605
|
tables: knownTables(input.tables),
|
|
@@ -10610,7 +10733,7 @@ function loadModel() {
|
|
|
10610
10733
|
});
|
|
10611
10734
|
modelPromise = attempt2;
|
|
10612
10735
|
}
|
|
10613
|
-
function
|
|
10736
|
+
function fieldOf2(tableId, key) {
|
|
10614
10737
|
return loaded?.tables.get(tableId)?.fields.find((field) => field.key === key);
|
|
10615
10738
|
}
|
|
10616
10739
|
var held = /* @__PURE__ */ new Map();
|
|
@@ -10637,7 +10760,7 @@ function noteRows(shape, rows, askedAt) {
|
|
|
10637
10760
|
const cells = new Map(held.get(id)?.cells ?? []);
|
|
10638
10761
|
for (const [column, source] of Object.entries(shape.columns)) {
|
|
10639
10762
|
if (source === null || "via" in source || source.table_id !== tableId || !(column in row2)) continue;
|
|
10640
|
-
const field =
|
|
10763
|
+
const field = fieldOf2(tableId, source.field_key);
|
|
10641
10764
|
if (field === void 0) continue;
|
|
10642
10765
|
const cell = row2[column];
|
|
10643
10766
|
if ((cells.get(source.field_key)?.askedAt ?? 0) <= askedAt) cells.set(source.field_key, { value: storedFromCell(field, cell), askedAt });
|
|
@@ -10677,14 +10800,20 @@ function publish() {
|
|
|
10677
10800
|
version += 1;
|
|
10678
10801
|
for (const listener of listeners) listener();
|
|
10679
10802
|
}
|
|
10803
|
+
function optionKeysFromBody(field, values2) {
|
|
10804
|
+
if (field.type !== "select") return [...values2];
|
|
10805
|
+
const keys2 = values2.map((one) => typeof one === "string" ? optionKeyOf(field, one) : one);
|
|
10806
|
+
return keys2.some((one) => one === void 0) ? void 0 : keys2;
|
|
10807
|
+
}
|
|
10680
10808
|
function storedFromBody(field, value) {
|
|
10681
10809
|
if (field === void 0) return void 0;
|
|
10682
10810
|
switch (field.type) {
|
|
10683
10811
|
case "select":
|
|
10684
10812
|
case "select_member":
|
|
10685
|
-
if (field.multi === true) return Array.isArray(value) ? value : void 0;
|
|
10813
|
+
if (field.multi === true) return Array.isArray(value) ? optionKeysFromBody(field, value) : void 0;
|
|
10686
10814
|
if (value === null) return [];
|
|
10687
|
-
|
|
10815
|
+
if (typeof value === "string") return optionKeysFromBody(field, [value]);
|
|
10816
|
+
return Array.isArray(value) ? optionKeysFromBody(field, value) : void 0;
|
|
10688
10817
|
case "select_record_link": {
|
|
10689
10818
|
const linked = value === null ? [] : Array.isArray(value) ? value : [value];
|
|
10690
10819
|
if (!linked.every((one) => typeof one === "string")) return void 0;
|
|
@@ -10707,7 +10836,7 @@ function stagedOf(effect) {
|
|
|
10707
10836
|
const cells = {};
|
|
10708
10837
|
const unknown = [...effect.unknown];
|
|
10709
10838
|
for (const [key, value] of Object.entries(effect.cells)) {
|
|
10710
|
-
const stored = storedFromBody(
|
|
10839
|
+
const stored = storedFromBody(fieldOf2(effect.table_id, key), value);
|
|
10711
10840
|
if (stored === void 0) unknown.push(key);
|
|
10712
10841
|
else cells[key] = stored;
|
|
10713
10842
|
}
|
|
@@ -10748,14 +10877,16 @@ async function stageWrite(workflow, inputs) {
|
|
|
10748
10877
|
if (failedAtMs === null) reportMisses([{ kind: "model_loading", workflow, count: 1 }]);
|
|
10749
10878
|
return null;
|
|
10750
10879
|
}
|
|
10751
|
-
const
|
|
10752
|
-
|
|
10880
|
+
const described = model.model.workflows[workflow];
|
|
10881
|
+
const plan = described?.plan;
|
|
10882
|
+
if (described === void 0 || plan === void 0 || plan.length === 0) return null;
|
|
10753
10883
|
const minted = [];
|
|
10754
10884
|
let prediction;
|
|
10755
10885
|
try {
|
|
10756
10886
|
prediction = await predictWorkflowEffects({
|
|
10757
10887
|
plan,
|
|
10758
10888
|
inputs,
|
|
10889
|
+
select_inputs: described.inputs ?? {},
|
|
10759
10890
|
tables: model.tables,
|
|
10760
10891
|
known: knownRecord,
|
|
10761
10892
|
timezone: model.context.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
@@ -10873,7 +11004,7 @@ function judgePredictions(shape, rows, askedAt) {
|
|
|
10873
11004
|
const cell = predicted.get(`${target}\0${source.field_key}`);
|
|
10874
11005
|
if (cell === void 0) continue;
|
|
10875
11006
|
const fieldTable = via ? source.target_table_id : tableId;
|
|
10876
|
-
const field =
|
|
11007
|
+
const field = fieldOf2(fieldTable, source.field_key);
|
|
10877
11008
|
const agrees = comparable(field, cell.value) === comparable(field, row2[column]);
|
|
10878
11009
|
judge(cell.entry, `${target}\0${source.field_key}`, agrees ? null : { table_id: fieldTable, field_key: source.field_key, column: via ? "via" : "own", kind: "cell" });
|
|
10879
11010
|
}
|
|
@@ -10914,9 +11045,9 @@ function tablesOf(shape) {
|
|
|
10914
11045
|
tables.add(source.target_table_id);
|
|
10915
11046
|
continue;
|
|
10916
11047
|
}
|
|
10917
|
-
const field =
|
|
11048
|
+
const field = fieldOf2(source.table_id, source.field_key);
|
|
10918
11049
|
if (field?.type === "rollup" || field?.type === "lookup") {
|
|
10919
|
-
const link2 =
|
|
11050
|
+
const link2 = fieldOf2(source.table_id, field.source_field_key);
|
|
10920
11051
|
if (link2?.type === "select_record_link") tables.add(link2.table_id);
|
|
10921
11052
|
}
|
|
10922
11053
|
}
|
|
@@ -10935,7 +11066,7 @@ function writesOver(tables, askedAt) {
|
|
|
10935
11066
|
const mine = entries2.filter((entry) => (entry.settledAt === null || askedAt <= entry.settledAt) && touches(entry, tables));
|
|
10936
11067
|
if (mine.length === 0) return null;
|
|
10937
11068
|
return {
|
|
10938
|
-
field:
|
|
11069
|
+
field: fieldOf2,
|
|
10939
11070
|
table: (tableId) => model.tables.get(tableId),
|
|
10940
11071
|
held: heldCells,
|
|
10941
11072
|
member: (id) => members.get(id),
|
|
@@ -12450,14 +12581,14 @@ function comparesFigure(operator) {
|
|
|
12450
12581
|
function nameOf(field) {
|
|
12451
12582
|
return `"${field.name ?? field.key}"`;
|
|
12452
12583
|
}
|
|
12453
|
-
function conditionUnit(condition2, field,
|
|
12584
|
+
function conditionUnit(condition2, field, fieldOf3) {
|
|
12454
12585
|
if (!comparesFigure(condition2.operator)) return { ok: true, unit: void 0 };
|
|
12455
12586
|
const stated = condition2.unit_option;
|
|
12456
12587
|
const read2 = figureRowSelect(field);
|
|
12457
12588
|
if (read2 === void 0) {
|
|
12458
12589
|
return stated === void 0 ? { ok: true, unit: void 0 } : { ok: false, reason: `${nameOf(field)} is read in one unit for every row, so a condition on it states no unit_option.` };
|
|
12459
12590
|
}
|
|
12460
|
-
const select =
|
|
12591
|
+
const select = fieldOf3(read2.key);
|
|
12461
12592
|
const options = effectiveSelectOptions(select) ?? [];
|
|
12462
12593
|
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(", ")}`;
|
|
12463
12594
|
const reads = `${nameOf(field)} is read in each row's own ${read2.vocabulary} (${select === void 0 ? `"${read2.key}"` : nameOf(select)})`;
|
package/docs/mutations.md
CHANGED
|
@@ -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:
|
|
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:
|
|
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/package.json
CHANGED