@lotics/app-sdk 0.129.0 → 0.130.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 +17 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9482,32 +9482,14 @@ function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField
|
|
|
9482
9482
|
if (coerce.mode === "display" && terminalField) {
|
|
9483
9483
|
return coerceFieldDisplay(current, terminalField, terminalOwner, ctx);
|
|
9484
9484
|
}
|
|
9485
|
-
if (coerce.mode === "alias") return coerceOptionAliases(current, coerce.of, ctx);
|
|
9486
9485
|
return current;
|
|
9487
9486
|
}
|
|
9488
9487
|
function coercionOf(read2) {
|
|
9489
|
-
|
|
9490
|
-
if (read2.of === void 0) throw new WorkflowEvalError("A read coerced to its alias names no select.", { kind: "alias_without_field" });
|
|
9491
|
-
return { mode: "alias", of: read2.of };
|
|
9488
|
+
return { mode: read2.coerce ?? "raw" };
|
|
9492
9489
|
}
|
|
9493
|
-
function
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
if (Array.isArray(v)) return v.map(resolve);
|
|
9497
|
-
return typeof v === "string" ? aliasOf.get(v) ?? v : v;
|
|
9498
|
-
};
|
|
9499
|
-
return resolve(value);
|
|
9500
|
-
}
|
|
9501
|
-
function coerceOptionAliases(value, of, ctx) {
|
|
9502
|
-
const options = optionsBehind(of, heldTable(of.table_id, ctx), ctx, 0);
|
|
9503
|
-
return options instanceof Promise ? options.then((held2) => aliasesOf(value, of, held2, ctx)) : aliasesOf(value, of, options, ctx);
|
|
9504
|
-
}
|
|
9505
|
-
function optionsBehind(of, held2, ctx, hops, unheld = "refuse") {
|
|
9506
|
-
if (held2 instanceof Promise) return held2.then((table) => optionsBehind(of, table, ctx, hops, unheld));
|
|
9507
|
-
if (held2 === null) {
|
|
9508
|
-
if (unheld === "unknown") return void 0;
|
|
9509
|
-
throw new WorkflowEvalError(`Reading "${of.field_key}" as its alias reads table ${of.table_id}, which this run does not hold.`, { kind: "unknown_table", extra: { table_id: of.table_id } });
|
|
9510
|
-
}
|
|
9490
|
+
function optionsBehind(of, held2, ctx, hops) {
|
|
9491
|
+
if (held2 instanceof Promise) return held2.then((table) => optionsBehind(of, table, ctx, hops));
|
|
9492
|
+
if (held2 === null) return void 0;
|
|
9511
9493
|
const field = findField(held2, of.field_key);
|
|
9512
9494
|
if (field?.type === "select") return field.options;
|
|
9513
9495
|
if (field?.type === "formula") return field.formula.options;
|
|
@@ -9515,17 +9497,7 @@ function optionsBehind(of, held2, ctx, hops, unheld = "refuse") {
|
|
|
9515
9497
|
const through = findField(held2, field.source_field_key);
|
|
9516
9498
|
if (through?.type !== "select_record_link") return void 0;
|
|
9517
9499
|
const next = { table_id: through.table_id, field_key: field.lookup_field_key };
|
|
9518
|
-
return optionsBehind(next, heldTable(next.table_id, ctx), ctx, hops + 1
|
|
9519
|
-
}
|
|
9520
|
-
function aliasesOf(value, of, options, ctx) {
|
|
9521
|
-
if (options === void 0) {
|
|
9522
|
-
throw new WorkflowEvalError(`Reading "${of.field_key}" of table ${of.table_id} as its alias reads a field that holds no options.`, { kind: "no_options", extra: { table_id: of.table_id, field_key: of.field_key } });
|
|
9523
|
-
}
|
|
9524
|
-
if (!Array.isArray(value)) return optionAliases(value, { options });
|
|
9525
|
-
assertCheap(ctx.evaluation_budget, value);
|
|
9526
|
-
const aliased = optionAliases(value, { options });
|
|
9527
|
-
charge(ctx, builtSize(aliased));
|
|
9528
|
-
return aliased;
|
|
9500
|
+
return optionsBehind(next, heldTable(next.table_id, ctx), ctx, hops + 1);
|
|
9529
9501
|
}
|
|
9530
9502
|
async function walkPending(read2, at2, walked) {
|
|
9531
9503
|
const { path, coerce, ctx, anchor, carried, field, terminal_field: terminalField, owners } = read2;
|
|
@@ -9577,7 +9549,7 @@ async function coerceFieldDisplay(value, field, owner, ctx) {
|
|
|
9577
9549
|
return coerceMemberDisplay(value, ctx);
|
|
9578
9550
|
case "lookup":
|
|
9579
9551
|
if (field.lookup_field_type !== "select") return value;
|
|
9580
|
-
const behind = owner === null ? void 0 : await optionsBehind({ table_id: owner.id, field_key: field.key }, owner, ctx, 0
|
|
9552
|
+
const behind = owner === null ? void 0 : await optionsBehind({ table_id: owner.id, field_key: field.key }, owner, ctx, 0);
|
|
9581
9553
|
const options = behind ?? field.lookup_field_options;
|
|
9582
9554
|
return options ? coerceOptionKeysDeep(value, options, ctx) : value;
|
|
9583
9555
|
default:
|
|
@@ -10553,8 +10525,7 @@ function clientRuntime(input) {
|
|
|
10553
10525
|
}
|
|
10554
10526
|
};
|
|
10555
10527
|
}
|
|
10556
|
-
function
|
|
10557
|
-
if (input.spelling === "key") return input;
|
|
10528
|
+
function inBodyAliases(input) {
|
|
10558
10529
|
const linked = (tableId) => input.tables.get(tableId)?.fields;
|
|
10559
10530
|
const holder = (fieldKey) => selectFieldHolder(input.tables.values(), fieldKey)?.field;
|
|
10560
10531
|
return {
|
|
@@ -10574,7 +10545,7 @@ function inBodySpelling(input) {
|
|
|
10574
10545
|
};
|
|
10575
10546
|
}
|
|
10576
10547
|
async function predictWorkflowEffects(given) {
|
|
10577
|
-
const input =
|
|
10548
|
+
const input = inBodyAliases(given);
|
|
10578
10549
|
const helpers = {
|
|
10579
10550
|
...createTimezoneAwareFunctions(input.timezone),
|
|
10580
10551
|
// Group membership and whom the caller stands in for are the server's to answer.
|
|
@@ -10601,7 +10572,6 @@ async function predictWorkflowEffects(given) {
|
|
|
10601
10572
|
step_outputs: {},
|
|
10602
10573
|
runtime: clientRuntime(input),
|
|
10603
10574
|
helpers,
|
|
10604
|
-
body_spelling: input.spelling,
|
|
10605
10575
|
record_cache: cache,
|
|
10606
10576
|
fetch_record: fetchRecord,
|
|
10607
10577
|
tables: knownTables(input.tables),
|
|
@@ -10802,20 +10772,20 @@ function publish() {
|
|
|
10802
10772
|
version += 1;
|
|
10803
10773
|
for (const listener of listeners) listener();
|
|
10804
10774
|
}
|
|
10805
|
-
function optionKeysFromBody(field,
|
|
10806
|
-
if (
|
|
10775
|
+
function optionKeysFromBody(field, values2) {
|
|
10776
|
+
if (field.type !== "select") return [...values2];
|
|
10807
10777
|
const keys2 = values2.map((one) => typeof one === "string" ? optionKeyOf(field, one) : one);
|
|
10808
10778
|
return keys2.some((one) => one === void 0) ? void 0 : keys2;
|
|
10809
10779
|
}
|
|
10810
|
-
function storedFromBody(field,
|
|
10780
|
+
function storedFromBody(field, value) {
|
|
10811
10781
|
if (field === void 0) return void 0;
|
|
10812
10782
|
switch (field.type) {
|
|
10813
10783
|
case "select":
|
|
10814
10784
|
case "select_member":
|
|
10815
|
-
if (field.multi === true) return Array.isArray(value) ? optionKeysFromBody(field,
|
|
10785
|
+
if (field.multi === true) return Array.isArray(value) ? optionKeysFromBody(field, value) : void 0;
|
|
10816
10786
|
if (value === null) return [];
|
|
10817
|
-
if (typeof value === "string") return optionKeysFromBody(field,
|
|
10818
|
-
return Array.isArray(value) ? optionKeysFromBody(field,
|
|
10787
|
+
if (typeof value === "string") return optionKeysFromBody(field, [value]);
|
|
10788
|
+
return Array.isArray(value) ? optionKeysFromBody(field, value) : void 0;
|
|
10819
10789
|
case "select_record_link": {
|
|
10820
10790
|
const linked = value === null ? [] : Array.isArray(value) ? value : [value];
|
|
10821
10791
|
if (!linked.every((one) => typeof one === "string")) return void 0;
|
|
@@ -10832,13 +10802,13 @@ function storedFromBody(field, spelling, value) {
|
|
|
10832
10802
|
return value;
|
|
10833
10803
|
}
|
|
10834
10804
|
}
|
|
10835
|
-
function stagedOf(effect
|
|
10805
|
+
function stagedOf(effect) {
|
|
10836
10806
|
if (effect.kind === "unknown") return null;
|
|
10837
10807
|
if (effect.kind === "remove") return effect;
|
|
10838
10808
|
const cells = {};
|
|
10839
10809
|
const unknown = [...effect.unknown];
|
|
10840
10810
|
for (const [key, value] of Object.entries(effect.cells)) {
|
|
10841
|
-
const stored = storedFromBody(fieldOf2(effect.table_id, key),
|
|
10811
|
+
const stored = storedFromBody(fieldOf2(effect.table_id, key), value);
|
|
10842
10812
|
if (stored === void 0) unknown.push(key);
|
|
10843
10813
|
else cells[key] = stored;
|
|
10844
10814
|
}
|
|
@@ -10882,14 +10852,12 @@ async function stageWrite(workflow, inputs) {
|
|
|
10882
10852
|
const described = model.model.workflows[workflow];
|
|
10883
10853
|
const plan = described?.plan;
|
|
10884
10854
|
if (described === void 0 || plan === void 0 || plan.length === 0) return null;
|
|
10885
|
-
const spelling = described.option_spelling ?? "key";
|
|
10886
10855
|
const minted = [];
|
|
10887
10856
|
let prediction;
|
|
10888
10857
|
try {
|
|
10889
10858
|
prediction = await predictWorkflowEffects({
|
|
10890
10859
|
plan,
|
|
10891
10860
|
inputs,
|
|
10892
|
-
spelling,
|
|
10893
10861
|
select_inputs: described.inputs ?? {},
|
|
10894
10862
|
tables: model.tables,
|
|
10895
10863
|
known: knownRecord,
|
|
@@ -10914,7 +10882,7 @@ async function stageWrite(workflow, inputs) {
|
|
|
10914
10882
|
reportMisses([{ kind: "refused", workflow, count: 1 }]);
|
|
10915
10883
|
return null;
|
|
10916
10884
|
}
|
|
10917
|
-
const staged = prediction.effects.flatMap((effect) => stagedOf(effect
|
|
10885
|
+
const staged = prediction.effects.flatMap((effect) => stagedOf(effect) ?? []);
|
|
10918
10886
|
const unknown = new Set(prediction.effects.flatMap((effect) => effect.kind === "unknown" ? [effect.table_id] : []));
|
|
10919
10887
|
if (staged.length === 0 && unknown.size === 0) {
|
|
10920
10888
|
reportMisses([{ kind: "nothing_written", workflow, count: 1 }]);
|
package/package.json
CHANGED