@mark1russell7/vex 0.3.0 → 0.4.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/build/index.js CHANGED
@@ -113,12 +113,22 @@ const rec = (fields) => ({
113
113
  tag: "rec",
114
114
  fields
115
115
  });
116
- /** This function evaluates `body` once for each target of `axis`. The result is a list. */
117
- const each = (axis, body) => ({
118
- tag: "each",
119
- axis,
120
- body
121
- });
116
+ /**
117
+ * This function evaluates `body` once for each target of `axis`. The result is a list. With `at`, the axis finds its
118
+ * targets from the key of that address, not from the focus.
119
+ */
120
+ function each(axis, body, at) {
121
+ return at === void 0 || at.length === 0 ? {
122
+ tag: "each",
123
+ axis,
124
+ body
125
+ } : {
126
+ tag: "each",
127
+ axis,
128
+ body,
129
+ at
130
+ };
131
+ }
122
132
  /** This function makes an expression of an extension kind. */
123
133
  const ext = (kind, data) => ({
124
134
  tag: "ext",
@@ -216,7 +226,7 @@ function isExpr(u) {
216
226
  case "let": return isExprRecord(u["bind"]) && isExpr(u["body"]);
217
227
  case "var": return typeof u["name"] === "string";
218
228
  case "rec": return isExprRecord(u["fields"]);
219
- case "each": return isAxis(u["axis"]) && isExpr(u["body"]);
229
+ case "each": return isAxis(u["axis"]) && isExpr(u["body"]) && (u["at"] === void 0 || Array.isArray(u["at"]) && u["at"].every(isMove));
220
230
  case "ext": return typeof u["kind"] === "string" && "data" in u;
221
231
  default: return false;
222
232
  }
@@ -399,6 +409,15 @@ function applyMove(s, at, m) {
399
409
  return ok(at.focus === a ? b ?? at.focus : a ?? at.focus);
400
410
  }
401
411
  case "offset": {
412
+ const parentOf = s.parentOf?.bind(s);
413
+ const childrenOf = s.childrenOf?.bind(s);
414
+ if (parentOf !== void 0 && childrenOf !== void 0 && m.d.length === 1) {
415
+ const p = parentOf(at.focus);
416
+ const group = p === void 0 ? s.keys.filter((k) => parentOf(k) === void 0) : childrenOf(p);
417
+ const i = group.indexOf(at.focus);
418
+ const k = i < 0 ? void 0 : group[i + (m.d[0] ?? 0)];
419
+ return k === void 0 ? refError("out-of-bounds", `the offset [${m.d.join(",")}] from "${at.focus}" is outside its siblings`) : ok(k);
420
+ }
402
421
  const c = s.coords(at.focus);
403
422
  if (c === void 0 || c.length !== m.d.length) return refError("no-offset", `an offset of length ${m.d.length} is not valid in a ${s.kind} space`);
404
423
  /* v8 ignore next -- @preserve */
@@ -839,10 +858,26 @@ var Compiler = class {
839
858
  }
840
859
  #each(e, info) {
841
860
  const { path } = info;
861
+ const at = e.at ?? [];
842
862
  const targets = this.#targets(e.axis, path, { next: 1 });
843
863
  const body = this.node(e.body, [...path, 0]);
844
864
  return (f, c) => {
845
- const ts = targets(f, c);
865
+ let from = f;
866
+ if (at.length > 0) {
867
+ const where = resolveAddr(c.space, f.pos, at);
868
+ if (!where.ok) return this.#emit(c, info, f, fail({
869
+ ...where.error,
870
+ path
871
+ }));
872
+ from = {
873
+ pos: {
874
+ origin: f.pos.origin,
875
+ focus: where.value
876
+ },
877
+ env: f.env
878
+ };
879
+ }
880
+ const ts = targets(from, c);
846
881
  if (!ts.ok) return this.#emit(c, info, f, ts);
847
882
  const items = ts.value.map(({ key, test }) => {
848
883
  if (test !== void 0 && !test.ok) return {
@@ -1015,7 +1050,8 @@ var Compiler = class {
1015
1050
  return r;
1016
1051
  }
1017
1052
  #listOp(op, list, rest, f, path) {
1018
- const strict = (op === "reduce" ? rest[1] : rest[0])?.strict === true;
1053
+ const optsArg = op === "reduce" ? rest[1] : rest[0];
1054
+ const strict = optsArg?.strict === true;
1019
1055
  const firstError = list.items.find((it) => !it.result.ok)?.result;
1020
1056
  if (strict && firstError !== void 0 && !firstError.ok) return fail(firstError.error);
1021
1057
  const okValues = list.items.flatMap((it) => it.result.ok ? [it.result.value] : []);
@@ -1059,18 +1095,26 @@ var Compiler = class {
1059
1095
  if (op === "all") return ok(b.value.every((x) => x));
1060
1096
  return ok(!b.value.some((x) => x));
1061
1097
  }
1062
- case "reduce": return this.#reduce(rest[0], okValues, f, path);
1098
+ case "reduce": return this.#reduce(rest[0], okValues, f, path, optsArg);
1063
1099
  }
1064
1100
  }
1065
- /** This method folds the values with a domain op, from the left. An empty list gives the identity of the op. */
1066
- #reduce(opName, values, f, path) {
1101
+ /**
1102
+ * This method folds the values with a domain op, from the left. An empty list gives the identity of the op, if one
1103
+ * domain has an identity for the op (LIST.EMPTY). The option `domain` names that domain when more domains have one.
1104
+ */
1105
+ #reduce(opName, values, f, path, opts) {
1067
1106
  if (typeof opName !== "string") return this.#err("kind-mismatch", `"reduce" needs an op name, but got a ${describeType(opName)}`, f, path, { op: "reduce" });
1068
1107
  if (values.length === 0) {
1069
- for (const d of this.#domains) {
1070
- const id = d.ops[opName]?.identity;
1071
- if (id !== void 0 && Object.hasOwn(d.ops, opName)) return this.#invoke(id, opName, f, path);
1108
+ const named = opts?.domain;
1109
+ const candidates = this.#domains.filter((d) => Object.hasOwn(d.ops, opName) && d.ops[opName].identity !== void 0 && (named === void 0 || d.name === named));
1110
+ if (named !== void 0 && !this.#domains.some((d) => d.name === named)) return this.#err("unknown-op", `"reduce" names the domain ${JSON.stringify(named)}, but the program has no such domain`, f, path, { op: opName });
1111
+ const [only, second] = candidates;
1112
+ if (only === void 0) return this.#err("empty", `"reduce" with "${opName}" has no values and the op has no identity`, f, path, { op: opName });
1113
+ if (second !== void 0) {
1114
+ const names = candidates.map((d) => d.name).join(", ");
1115
+ return this.#err("empty", `"reduce" with "${opName}" has no values, and more domains have an identity for it (${names}). Name one with { domain }`, f, path, { op: opName });
1072
1116
  }
1073
- return this.#err("empty", `"reduce" with "${opName}" has no values and the op has no identity`, f, path, { op: opName });
1117
+ return this.#invoke(only.ops[opName].identity, opName, f, path);
1074
1118
  }
1075
1119
  let acc = values[0];
1076
1120
  for (let i = 1; i < values.length; i++) {
@@ -1127,10 +1171,21 @@ function labelOf(e) {
1127
1171
  case "let": return `let ${Object.keys(e.bind).join(", ")}`;
1128
1172
  case "var": return e.name;
1129
1173
  case "rec": return `{ ${Object.keys(e.fields).join(", ")} }`;
1130
- case "each": return `each ${e.axis.t}`;
1174
+ case "each": return e.at === void 0 ? `each ${e.axis.t}` : `each ${e.axis.t} from ${e.at.map(moveText).join(".")}`;
1131
1175
  case "ext": return e.kind;
1132
1176
  }
1133
1177
  }
1178
+ /** This function gives a short text for a move, for the label of an axis with an address. */
1179
+ function moveText(m) {
1180
+ switch (m.t) {
1181
+ case "key": return `key(${m.key})`;
1182
+ case "index": return `index(${m.i})`;
1183
+ case "offset": return `offset(${m.d.join(", ")})`;
1184
+ case "other":
1185
+ case "origin":
1186
+ case "parent": return m.t;
1187
+ }
1188
+ }
1134
1189
  /** This function gives a short text for a value. */
1135
1190
  function previewValue(u) {
1136
1191
  if (typeof u === "number") return String(u);
@@ -1176,86 +1231,198 @@ const sizeOf = (e) => 1 + children(e).reduce((s, c) => s + sizeOf(c), 0);
1176
1231
  */
1177
1232
  function deps(e) {
1178
1233
  const out = [];
1179
- const walk = (x, axes) => {
1234
+ const walk = (x, axes, axisAt) => {
1180
1235
  if (x.tag === "ref") {
1181
1236
  out.push({
1182
1237
  at: x.at ?? [],
1183
1238
  path: x.path,
1184
- axes
1239
+ axes,
1240
+ axisAt
1185
1241
  });
1186
1242
  return;
1187
1243
  }
1188
1244
  if (x.tag === "each") {
1189
1245
  const inner = [...axes, x.axis.t];
1190
- children(x).forEach((c) => walk(c, inner));
1246
+ const innerAt = [...axisAt, x.at ?? []];
1247
+ children(x).forEach((c) => walk(c, inner, innerAt));
1191
1248
  return;
1192
1249
  }
1193
- children(x).forEach((c) => walk(c, axes));
1250
+ children(x).forEach((c) => walk(c, axes, axisAt));
1194
1251
  };
1195
- walk(e, []);
1252
+ walk(e, [], []);
1196
1253
  return out;
1197
1254
  }
1198
1255
  //#endregion
1199
1256
  //#region src/json.ts
1200
- const isPlainJson = (u) => {
1201
- if (u === null || typeof u === "string" || typeof u === "boolean") return true;
1202
- if (typeof u === "number") return Number.isFinite(u);
1203
- if (Array.isArray(u)) return u.every(isPlainJson);
1204
- if (typeof u === "object") {
1205
- const proto = Object.getPrototypeOf(u);
1206
- return (proto === Object.prototype || proto === null) && Object.values(u).every(isPlainJson);
1257
+ const isRecord = (u) => typeof u === "object" && u !== null && !Array.isArray(u);
1258
+ const isPlainRecord = (u) => {
1259
+ if (!isRecord(u)) return false;
1260
+ const proto = Object.getPrototypeOf(u);
1261
+ return proto === Object.prototype || proto === null;
1262
+ };
1263
+ /** This function gives the JSON form of a value, or the reason why the value has no JSON form. */
1264
+ function encodeValue(u, domains) {
1265
+ if (u === null || typeof u === "string" || typeof u === "boolean") return ok(u);
1266
+ if (typeof u === "number") {
1267
+ if (Object.is(u, -0)) return ok({
1268
+ $vex: "number",
1269
+ value: "-0"
1270
+ });
1271
+ return Number.isFinite(u) ? ok(u) : ok({
1272
+ $vex: "number",
1273
+ value: Number.isNaN(u) ? "NaN" : u > 0 ? "Infinity" : "-Infinity"
1274
+ });
1207
1275
  }
1208
- return false;
1276
+ if (Array.isArray(u)) {
1277
+ const out = [];
1278
+ for (const x of u) {
1279
+ const r = encodeValue(x, domains);
1280
+ if (!r.ok) return r;
1281
+ out.push(r.value);
1282
+ }
1283
+ return ok(out);
1284
+ }
1285
+ if (isPlainRecord(u)) {
1286
+ const out = {};
1287
+ for (const [k, x] of Object.entries(u)) {
1288
+ const r = encodeValue(x, domains);
1289
+ if (!r.ok) return r;
1290
+ out[k] = r.value;
1291
+ }
1292
+ return ok(Object.hasOwn(u, "$vex") ? {
1293
+ $vex: "escape",
1294
+ value: out
1295
+ } : out);
1296
+ }
1297
+ const d = domains.find((dom) => dom.encode !== void 0 && dom.is(u));
1298
+ if (d?.encode !== void 0) return ok({
1299
+ $vex: "domain",
1300
+ domain: d.name,
1301
+ value: d.encode(u)
1302
+ });
1303
+ return fail(vexError("bad-expression", "a literal value is not JSON data and no domain encodes it"));
1304
+ }
1305
+ const NUMBERS = {
1306
+ "-0": -0,
1307
+ NaN: NaN,
1308
+ Infinity: Number.POSITIVE_INFINITY,
1309
+ "-Infinity": Number.NEGATIVE_INFINITY
1209
1310
  };
1311
+ /** This function reads a value from its JSON form. */
1312
+ function decodeValue(u, domains) {
1313
+ if (Array.isArray(u)) {
1314
+ const out = [];
1315
+ for (const x of u) {
1316
+ const r = decodeValue(x, domains);
1317
+ if (!r.ok) return r;
1318
+ out.push(r.value);
1319
+ }
1320
+ return ok(out);
1321
+ }
1322
+ if (!isRecord(u)) return ok(u);
1323
+ const fields = (record) => {
1324
+ const out = {};
1325
+ for (const [k, x] of Object.entries(record)) {
1326
+ const r = decodeValue(x, domains);
1327
+ if (!r.ok) return r;
1328
+ out[k] = r.value;
1329
+ }
1330
+ return ok(out);
1331
+ };
1332
+ const kind = u["$vex"];
1333
+ if (kind === "escape" && isRecord(u["value"])) return fields(u["value"]);
1334
+ if (kind === "number" && typeof u["value"] === "string" && Object.hasOwn(NUMBERS, u["value"])) return ok(NUMBERS[u["value"]]);
1335
+ if (kind === "domain" && typeof u["domain"] === "string") {
1336
+ const name = u["domain"];
1337
+ const d = domains.find((dom) => dom.name === name);
1338
+ if (d?.decode === void 0) return fail(vexError("bad-expression", `no domain "${name}" decodes a literal`));
1339
+ return ok(d.decode(u["value"]));
1340
+ }
1341
+ return fields(u);
1342
+ }
1343
+ /** This function applies `f` to each literal value of a JSON tree of an expression. */
1344
+ function mapValues(u, f) {
1345
+ if (!isRecord(u)) return ok(u);
1346
+ const out = { ...u };
1347
+ const child = (key) => {
1348
+ const r = mapValues(u[key], f);
1349
+ if (r.ok) out[key] = r.value;
1350
+ return r.ok ? void 0 : r;
1351
+ };
1352
+ const each = (key) => {
1353
+ const list = u[key];
1354
+ if (Array.isArray(list)) {
1355
+ const items = [];
1356
+ for (const x of list) {
1357
+ const r = mapValues(x, f);
1358
+ if (!r.ok) return r;
1359
+ items.push(r.value);
1360
+ }
1361
+ out[key] = items;
1362
+ } else if (isRecord(list)) {
1363
+ const rec = {};
1364
+ for (const [k, x] of Object.entries(list)) {
1365
+ const r = mapValues(x, f);
1366
+ if (!r.ok) return r;
1367
+ rec[k] = r.value;
1368
+ }
1369
+ out[key] = rec;
1370
+ }
1371
+ };
1372
+ const axis = (a) => {
1373
+ if (!isRecord(a) || a["t"] !== "where") return ok(a);
1374
+ const inner = axis(a["axis"]);
1375
+ if (!inner.ok) return inner;
1376
+ const test = mapValues(a["test"], f);
1377
+ return test.ok ? ok({
1378
+ ...a,
1379
+ axis: inner.value,
1380
+ test: test.value
1381
+ }) : test;
1382
+ };
1383
+ switch (u["tag"]) {
1384
+ case "lit": {
1385
+ if (!Object.hasOwn(u, "value")) return ok(out);
1386
+ const r = f(u["value"]);
1387
+ if (!r.ok) return r;
1388
+ out["value"] = r.value;
1389
+ return ok(out);
1390
+ }
1391
+ case "app": return each("args") ?? ok(out);
1392
+ case "let": return each("bind") ?? child("body") ?? ok(out);
1393
+ case "rec": return each("fields") ?? ok(out);
1394
+ case "each": {
1395
+ const a = axis(u["axis"]);
1396
+ if (!a.ok) return a;
1397
+ out["axis"] = a.value;
1398
+ return child("body") ?? ok(out);
1399
+ }
1400
+ default: return ok(out);
1401
+ }
1402
+ }
1210
1403
  /**
1211
- * This function gives the JSON text of an expression. A literal that is a domain value needs a domain with
1212
- * `encode`. A literal that is not JSON data and has no such domain gives the error `#VALUE!`.
1404
+ * This function gives the JSON text of an expression. A literal value that is a domain value needs a domain with
1405
+ * `encode`. A literal value that is not JSON data and has no such domain gives the error `#VALUE!`.
1213
1406
  */
1214
1407
  function serialize(e, domains = []) {
1215
- const failure = [];
1216
- const replacer = function(k, value) {
1217
- const holder = this;
1218
- if (k !== "value" || holder["tag"] !== "lit") return value;
1219
- if (isPlainJson(value)) return value;
1220
- const d = domains.find((dom) => dom.encode !== void 0 && dom.is(value));
1221
- if (d?.encode !== void 0) return {
1222
- $vex: "domain",
1223
- domain: d.name,
1224
- value: d.encode(value)
1225
- };
1226
- failure.push({ message: `a literal value is not JSON data and no domain encodes it` });
1227
- return null;
1228
- };
1229
- let text;
1230
1408
  try {
1231
- text = JSON.stringify(e, replacer);
1409
+ const tree = mapValues(e, (v) => encodeValue(v, domains));
1410
+ return tree.ok ? ok(JSON.stringify(tree.value)) : fail(tree.error);
1232
1411
  } catch (thrown) {
1233
1412
  return fail(vexError("threw", "the expression has no JSON form", { thrown }));
1234
1413
  }
1235
- const first = failure[0];
1236
- return first === void 0 ? ok(text) : fail(vexError("bad-expression", first.message));
1237
1414
  }
1238
- const isEncoded = (u) => u?.$vex === "domain" && typeof u.domain === "string";
1239
1415
  /** This function reads an expression from JSON text. It checks the whole tree. */
1240
1416
  function parse(text, domains = []) {
1241
1417
  let raw;
1242
- const failure = [];
1243
1418
  try {
1244
- raw = JSON.parse(text, (_k, value) => {
1245
- if (!isEncoded(value)) return value;
1246
- const d = domains.find((dom) => dom.name === value.domain);
1247
- if (d?.decode === void 0) {
1248
- failure.push(`no domain "${value.domain}" decodes a literal`);
1249
- return value;
1250
- }
1251
- return d.decode(value.value);
1252
- });
1419
+ raw = JSON.parse(text);
1253
1420
  } catch (thrown) {
1254
1421
  return fail(vexError("bad-expression", "the text is not JSON", { thrown }));
1255
1422
  }
1256
- const first = failure[0];
1257
- if (first !== void 0) return fail(vexError("bad-expression", first));
1258
- return isExpr(raw) ? ok(raw) : fail(vexError("bad-expression", "the JSON is not a valid Vex expression"));
1423
+ const tree = mapValues(raw, (v) => decodeValue(v, domains));
1424
+ if (!tree.ok) return fail(tree.error);
1425
+ return isExpr(tree.value) ? ok(tree.value) : fail(vexError("bad-expression", "the JSON is not a valid Vex expression"));
1259
1426
  }
1260
1427
  //#endregion
1261
1428
  //#region src/traversal.ts
@@ -1366,6 +1533,8 @@ var SheetRun = class {
1366
1533
  #columns;
1367
1534
  #opts;
1368
1535
  #done = /* @__PURE__ */ new Map();
1536
+ #warmed = /* @__PURE__ */ new Map();
1537
+ #index;
1369
1538
  #visits = /* @__PURE__ */ new Map();
1370
1539
  #stack = [];
1371
1540
  #top = {
@@ -1397,8 +1566,27 @@ var SheetRun = class {
1397
1566
  });
1398
1567
  return this.cell(data.column, where.value);
1399
1568
  };
1400
- /** This method gives the result of one cell: the column `column` at the key `key`. */
1569
+ /**
1570
+ * This method gives the result of one cell: the column `column` at the key `key`. A read from a host first evaluates
1571
+ * the column at the keys before `key`, in key order. Thus a recurrence over the keys reads finished cells, and a
1572
+ * first read at the last key does not go deep into the call stack.
1573
+ */
1401
1574
  cell(column, key) {
1575
+ if (this.#top.index < 0) this.#warmTo(column, key);
1576
+ return this.#cell(column, key);
1577
+ }
1578
+ /** This method evaluates the column `column` at each key before `key` that it did not evaluate before, in key order. */
1579
+ #warmTo(column, key) {
1580
+ if (!this.#columns.has(column)) return;
1581
+ const keys = this.#opts.space.keys;
1582
+ this.#index ??= new Map(keys.map((k, i) => [k, i]));
1583
+ const end = this.#index.get(key) ?? 0;
1584
+ const start = this.#warmed.get(column) ?? 0;
1585
+ for (let i = start; i < end; i++) this.#cell(column, keys[i] ?? key);
1586
+ if (end > start) this.#warmed.set(column, end);
1587
+ }
1588
+ /** This method evaluates one cell, without the warm-up of `cell`. */
1589
+ #cell(column, key) {
1402
1590
  const id = `${column}\u0000${key}`;
1403
1591
  const done = this.#done.get(id);
1404
1592
  if (done !== void 0) return done;
@@ -1466,10 +1654,7 @@ var SheetRun = class {
1466
1654
  * for example a running total, then reads finished cells and does not go deep into the call stack.
1467
1655
  */
1468
1656
  warm(column, key) {
1469
- for (const k of this.#opts.space.keys) {
1470
- if (k === key) return;
1471
- this.cell(column, k);
1472
- }
1657
+ this.#warmTo(column, key);
1473
1658
  }
1474
1659
  };
1475
1660
  //#endregion
@@ -1526,14 +1711,7 @@ var ChainImpl = class ChainImpl {
1526
1711
  } });
1527
1712
  }
1528
1713
  #opts(k) {
1529
- const { env } = this.#s;
1530
- return {
1531
- space: env.space,
1532
- origin: k,
1533
- domains: env.domains,
1534
- ...env.options.fns === void 0 ? {} : { fns: env.options.fns },
1535
- ...env.options.extensions === void 0 ? {} : { extensions: env.options.extensions }
1536
- };
1714
+ return evalOptions(this.#s, k);
1537
1715
  }
1538
1716
  result(k) {
1539
1717
  return evaluate(this.#s.expr, this.#opts(k));
@@ -1590,6 +1768,12 @@ var ChainImpl = class ChainImpl {
1590
1768
  expr: app(name, this.#s.expr, ...args.map((a) => toExpr(a, this.#s.addr)))
1591
1769
  });
1592
1770
  }
1771
+ if(then, otherwise) {
1772
+ return new ChainImpl({
1773
+ ...this.#s,
1774
+ expr: app("if", this.#s.expr, toExpr(then, this.#s.addr), toExpr(otherwise, this.#s.addr))
1775
+ });
1776
+ }
1593
1777
  ifError(fallback) {
1594
1778
  return new ChainImpl({
1595
1779
  ...this.#s,
@@ -1649,7 +1833,7 @@ var ChainImpl = class ChainImpl {
1649
1833
  };
1650
1834
  return new ListChainImpl({
1651
1835
  ...this.#s,
1652
- expr: let_({ [name]: this.#s.expr }, each(axis, inner.program))
1836
+ expr: let_({ [name]: this.#s.expr }, each(axis, inner.program, this.#s.addr))
1653
1837
  });
1654
1838
  }
1655
1839
  others(body, opts) {
@@ -1677,6 +1861,17 @@ var ChainImpl = class ChainImpl {
1677
1861
  return this.#axis({ t: "siblings" }, body, opts);
1678
1862
  }
1679
1863
  };
1864
+ /** This function gives the options of an evaluation of a chain or a list chain at the origin `k`. */
1865
+ function evalOptions(s, k) {
1866
+ const { env } = s;
1867
+ return {
1868
+ space: env.space,
1869
+ origin: k,
1870
+ domains: env.domains,
1871
+ ...env.options.fns === void 0 ? {} : { fns: env.options.fns },
1872
+ ...env.options.extensions === void 0 ? {} : { extensions: env.options.extensions }
1873
+ };
1874
+ }
1680
1875
  var ListChainImpl = class {
1681
1876
  kind = "vex.list-chain";
1682
1877
  #s;
@@ -1687,7 +1882,11 @@ var ListChainImpl = class {
1687
1882
  return this.#s.expr;
1688
1883
  }
1689
1884
  #op(op, extra, opts) {
1690
- const args = opts?.strict === true ? [...extra, lit({ strict: true })] : extra;
1885
+ const options = {
1886
+ ...opts?.strict === true ? { strict: true } : {},
1887
+ ...opts?.domain === void 0 ? {} : { domain: opts.domain }
1888
+ };
1889
+ const args = Object.keys(options).length > 0 ? [...extra, lit(options)] : extra;
1691
1890
  return new ChainImpl({
1692
1891
  ...this.#s,
1693
1892
  expr: app(op, this.#s.expr, ...args)
@@ -1720,12 +1919,27 @@ var ListChainImpl = class {
1720
1919
  values(opts) {
1721
1920
  return this.#op("values", [], opts);
1722
1921
  }
1922
+ keys(opts) {
1923
+ return this.#op("keys", [], opts);
1924
+ }
1925
+ errors() {
1926
+ return this.#op("errors", []);
1927
+ }
1723
1928
  first(opts) {
1724
1929
  return this.#op("first", [], opts);
1725
1930
  }
1726
1931
  reduce(op, opts) {
1727
1932
  return this.#op("reduce", [lit(op)], opts);
1728
1933
  }
1934
+ result(k) {
1935
+ return evaluate(this.#s.expr, evalOptions(this.#s, k));
1936
+ }
1937
+ at(k) {
1938
+ return toOptional(this.result(k));
1939
+ }
1940
+ explain(k) {
1941
+ return explain(this.#s.expr, evalOptions(this.#s, k));
1942
+ }
1729
1943
  };
1730
1944
  var RootImpl = class {
1731
1945
  #env;