@nivaro/react 0.3.131 → 0.3.133

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.
@@ -1,90 +1,90 @@
1
- import { choiceLabel as F, titleCase as y } from "./utils.js";
2
- import { formulaInputs as P } from "./write-formula.js";
3
- const R = /* @__PURE__ */ new Set(["integer", "bigInteger", "float", "decimal", "number"]);
4
- function v(e, n = {}) {
5
- var t, s, c;
6
- const o = (t = n.fields) == null ? void 0 : t[e];
7
- if (o != null && o.trim()) return o.trim();
1
+ import { choiceLabel as W, titleCase as y } from "./utils.js";
2
+ import { formulaInputs as R } from "./write-formula.js";
3
+ const J = /* @__PURE__ */ new Set(["integer", "bigInteger", "float", "decimal", "number"]);
4
+ function O(e, n = {}) {
5
+ var t, s, i;
6
+ const r = (t = n.fields) == null ? void 0 : t[e];
7
+ if (r != null && r.trim()) return r.trim();
8
8
  if (e.includes(".")) {
9
- const r = e.split(".");
10
- return [((c = (s = n.fields) == null ? void 0 : s[r[0]]) == null ? void 0 : c.trim()) || y(r[0]), ...r.slice(1).map((u) => y(u))].join("’s ");
9
+ const o = e.split(".");
10
+ return [((i = (s = n.fields) == null ? void 0 : s[o[0]]) == null ? void 0 : i.trim()) || y(o[0]), ...o.slice(1).map((u) => y(u))].join("’s ");
11
11
  }
12
12
  return y(e);
13
13
  }
14
- function N(e, n = {}) {
14
+ function k(e, n = {}) {
15
15
  var t;
16
- const o = (t = n.collections) == null ? void 0 : t[e];
17
- return o != null && o.trim() ? o.trim() : y(e);
16
+ const r = (t = n.collections) == null ? void 0 : t[e];
17
+ return r != null && r.trim() ? r.trim() : y(e);
18
18
  }
19
- function w(e, n, o) {
20
- var s, c;
21
- const t = (c = (s = o.relatedFields) == null ? void 0 : s[e]) == null ? void 0 : c[n];
19
+ function w(e, n, r) {
20
+ var s, i;
21
+ const t = (i = (s = r.relatedFields) == null ? void 0 : s[e]) == null ? void 0 : i[n];
22
22
  return t != null && t.trim() ? t.trim() : y(n);
23
23
  }
24
- const b = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0;
25
- function z(e, n) {
24
+ const A = (e) => e == null || e === "" || Array.isArray(e) && e.length === 0;
25
+ function M(e, n) {
26
26
  return n === "money" ? `${e < 0 ? "-" : ""}$${Math.abs(e).toLocaleString("en-US", { maximumFractionDigits: 2 })}` : n === "percent" ? `${e.toLocaleString("en-US", { maximumFractionDigits: 2 })}%` : e.toLocaleString("en-US", { maximumFractionDigits: 6 });
27
27
  }
28
- function S(e, n, o = {}) {
29
- var u, l, h, f, a, d, m;
30
- if (b(n)) return "empty";
31
- const t = String(n), s = (l = (u = o.choices) == null ? void 0 : u[e]) == null ? void 0 : l[t];
32
- if (s != null) return F(s);
33
- const c = (f = (h = o.records) == null ? void 0 : h[e]) == null ? void 0 : f[t];
34
- if (c != null) return c;
35
- if (typeof n == "boolean" || ((a = o.types) == null ? void 0 : a[e]) === "boolean") {
28
+ function v(e, n, r = {}) {
29
+ var u, c, h, a, f, m, d;
30
+ if (A(n)) return "empty";
31
+ const t = String(n), s = (c = (u = r.choices) == null ? void 0 : u[e]) == null ? void 0 : c[t];
32
+ if (s != null) return W(s);
33
+ const i = (a = (h = r.records) == null ? void 0 : h[e]) == null ? void 0 : a[t];
34
+ if (i != null) return i;
35
+ if (typeof n == "boolean" || ((f = r.types) == null ? void 0 : f[e]) === "boolean") {
36
36
  if (n === !0 || t === "true" || t === "1") return "Yes";
37
37
  if (n === !1 || t === "false" || t === "0") return "No";
38
38
  }
39
- const r = (d = o.formats) == null ? void 0 : d[e];
40
- return (typeof n == "number" || /^\s*-?\d+(\.\d+)?\s*$/.test(t)) && (r || R.has(((m = o.types) == null ? void 0 : m[e]) ?? "")) ? z(Number(t), r) : typeof n == "object" ? JSON.stringify(n) : F(t);
39
+ const o = (m = r.formats) == null ? void 0 : m[e];
40
+ return (typeof n == "number" || /^\s*-?\d+(\.\d+)?\s*$/.test(t)) && (o || J.has(((d = r.types) == null ? void 0 : d[e]) ?? "")) ? M(Number(t), o) : typeof n == "object" ? JSON.stringify(n) : W(t);
41
41
  }
42
42
  function _(e) {
43
43
  return e.length <= 1 ? e[0] ?? "" : `${e.slice(0, -1).join(", ")} or ${e[e.length - 1]}`;
44
44
  }
45
- function T(e) {
45
+ function N(e) {
46
46
  return e.length <= 1 ? e[0] ?? "" : `${e.slice(0, -1).join(", ")} and ${e[e.length - 1]}`;
47
47
  }
48
- function B(e) {
49
- if (Array.isArray(e)) return e.map((o) => String(o));
48
+ function T(e) {
49
+ if (Array.isArray(e)) return e.map((r) => String(r));
50
50
  if (e == null) return null;
51
51
  const n = String(e).trim();
52
52
  if (!n) return null;
53
53
  if (n.startsWith("["))
54
54
  try {
55
- const o = JSON.parse(n);
56
- return Array.isArray(o) ? o.map((t) => String(t)) : null;
55
+ const r = JSON.parse(n);
56
+ return Array.isArray(r) ? r.map((t) => String(t)) : null;
57
57
  } catch {
58
58
  return null;
59
59
  }
60
- return n.split(",").map((o) => o.trim()).filter(Boolean);
60
+ return n.split(",").map((r) => r.trim()).filter(Boolean);
61
61
  }
62
- const C = (e) => e && e[0].toUpperCase() + e.slice(1);
63
- function A(e, n, o, t = {}) {
62
+ const I = (e) => e && e[0].toUpperCase() + e.slice(1);
63
+ function b(e, n, r, t = {}) {
64
64
  if (!e) return null;
65
- const s = v(e, t), c = n ?? "eq";
66
- switch (c) {
65
+ const s = O(e, t), i = n ?? "eq";
66
+ switch (i) {
67
67
  case "null":
68
68
  return `${s} is empty`;
69
69
  case "nnull":
70
70
  return `${s} is set`;
71
71
  case "eq":
72
- return b(o) ? `${s} is empty` : `${s} is ${S(e, o, t)}`;
72
+ return A(r) ? `${s} is empty` : `${s} is ${v(e, r, t)}`;
73
73
  case "neq":
74
- return b(o) ? `${s} is set` : `${s} is not ${S(e, o, t)} (or is empty)`;
74
+ return A(r) ? `${s} is set` : `${s} is not ${v(e, r, t)} (or is empty)`;
75
75
  case "gt":
76
76
  case "gte":
77
77
  case "lt":
78
78
  case "lte": {
79
- if (b(o)) return null;
80
- const r = { gt: "is over", gte: "is at least", lt: "is under", lte: "is at most" }[c];
81
- return `${s} ${r} ${S(e, o, t)}`;
79
+ if (A(r)) return null;
80
+ const o = { gt: "is over", gte: "is at least", lt: "is under", lte: "is at most" }[i];
81
+ return `${s} ${o} ${v(e, r, t)}`;
82
82
  }
83
83
  case "contains":
84
- return b(o) ? null : `${s} contains “${String(o)}”`;
84
+ return A(r) ? null : `${s} contains “${String(r)}”`;
85
85
  case "in": {
86
- const r = B(o);
87
- return r != null && r.length ? `${s} is ${_(r.map((i) => S(e, i, t)))}` : null;
86
+ const o = T(r);
87
+ return o != null && o.length ? `${s} is ${_(o.map((l) => v(e, l, t)))}` : null;
88
88
  }
89
89
  default:
90
90
  return null;
@@ -92,16 +92,16 @@ function A(e, n, o, t = {}) {
92
92
  }
93
93
  function U(e, n = {}) {
94
94
  if (!Array.isArray(e) || e.length === 0) return null;
95
- const o = [];
95
+ const r = [];
96
96
  for (const t of e) {
97
97
  if (!t || typeof t != "object" || !t.field) continue;
98
- const s = A(t.field, t.op, t.value, n);
98
+ const s = b(t.field, t.op, t.value, n);
99
99
  if (!s) return null;
100
- o.push(s);
100
+ r.push(s);
101
101
  }
102
- return o.length ? o.join(" and ") : null;
102
+ return r.length ? r.join(" and ") : null;
103
103
  }
104
- const I = {
104
+ const P = {
105
105
  _eq: "eq",
106
106
  _neq: "neq",
107
107
  _gt: "gt",
@@ -111,44 +111,44 @@ const I = {
111
111
  _in: "in",
112
112
  _contains: "contains"
113
113
  };
114
- function O(e, n = {}, o = "") {
114
+ function q(e, n = {}, r = "") {
115
115
  if (!e || typeof e != "object" || Array.isArray(e)) return null;
116
116
  const t = [];
117
- for (const [s, c] of Object.entries(e)) {
117
+ for (const [s, i] of Object.entries(e)) {
118
118
  if (s === "_and" || s === "_or") {
119
- if (!Array.isArray(c) || c.length === 0) return null;
120
- const l = c.map((h) => O(h, n, o));
121
- if (l.some((h) => !h)) return null;
119
+ if (!Array.isArray(i) || i.length === 0) return null;
120
+ const c = i.map((h) => q(h, n, r));
121
+ if (c.some((h) => !h)) return null;
122
122
  t.push(
123
- s === "_and" ? l.join(" and ") : `either ${_(l)}`
123
+ s === "_and" ? c.join(" and ") : `either ${_(c)}`
124
124
  );
125
125
  continue;
126
126
  }
127
127
  if (s.startsWith("_")) return null;
128
- const r = o ? `${o}.${s}` : s;
129
- if (c === null || typeof c != "object" || Array.isArray(c)) {
130
- const l = A(r, Array.isArray(c) ? "in" : "eq", c, n);
131
- if (!l) return null;
132
- t.push(l);
128
+ const o = r ? `${r}.${s}` : s;
129
+ if (i === null || typeof i != "object" || Array.isArray(i)) {
130
+ const c = b(o, Array.isArray(i) ? "in" : "eq", i, n);
131
+ if (!c) return null;
132
+ t.push(c);
133
133
  continue;
134
134
  }
135
- const i = Object.entries(c);
136
- if (i.length === 0) return null;
137
- if (!i.every(([l]) => l.startsWith("_"))) {
138
- const l = O(c, n, r);
139
- if (!l) return null;
140
- t.push(l);
135
+ const l = Object.entries(i);
136
+ if (l.length === 0) return null;
137
+ if (!l.every(([c]) => c.startsWith("_"))) {
138
+ const c = q(i, n, o);
139
+ if (!c) return null;
140
+ t.push(c);
141
141
  continue;
142
142
  }
143
- for (const [l, h] of i) {
144
- let f;
145
- if (l === "_null" ? f = A(r, h === !1 ? "nnull" : "null", null, n) : l === "_nnull" ? f = A(r, h === !1 ? "null" : "nnull", null, n) : I[l] ? f = A(r, I[l], h, n) : f = null, !f) return null;
146
- t.push(f);
143
+ for (const [c, h] of l) {
144
+ let a;
145
+ if (c === "_null" ? a = b(o, h === !1 ? "nnull" : "null", null, n) : c === "_nnull" ? a = b(o, h === !1 ? "null" : "nnull", null, n) : P[c] ? a = b(o, P[c], h, n) : a = null, !a) return null;
146
+ t.push(a);
147
147
  }
148
148
  }
149
149
  return t.length ? t.join(" and ") : null;
150
150
  }
151
- function k(e) {
151
+ function S(e) {
152
152
  if (!e) return null;
153
153
  if (typeof e == "object" && !Array.isArray(e)) return e;
154
154
  if (typeof e != "string") return null;
@@ -159,16 +159,16 @@ function k(e) {
159
159
  return null;
160
160
  }
161
161
  }
162
- function H(e, n, o = {}) {
163
- var d, m;
164
- const t = (d = e.parent_field) == null ? void 0 : d.trim(), s = (m = e.filter_column) == null ? void 0 : m.trim();
162
+ function Q(e, n, r = {}) {
163
+ var m, d;
164
+ const t = (m = e.parent_field) == null ? void 0 : m.trim(), s = (d = e.filter_column) == null ? void 0 : d.trim();
165
165
  if (!t || !s || !n.field) return null;
166
- const c = v(n.field, o), r = v(t, o), i = n.relatedCollection ?? null, u = i ? N(i, o) : "records", l = i ? s.split(".").map((p, $) => $ === 0 ? w(i, p, o) : y(p)).join("’s ") : y(s), f = e.value_map && Object.keys(e.value_map).length > 0 ? `whose ${l} is mapped from this record’s ${r}` : e.filter_is_m2m ? `whose ${l} is one of this record’s ${r}` : `whose ${l} is this record’s ${r}`, a = [`${c} only offers ${u} ${f}.`];
167
- return e.clear_on_parent_change !== !1 && a.push(`Changing ${r} clears ${c}.`), e.clear_on_unavailable && a.push(`A ${c} that no longer fits is cleared.`), a.push(
168
- e.show_all_if_no_parent === !1 ? `${c} stays locked until ${r} is picked.` : `With no ${r} picked, it offers every one.`
169
- ), e.upstream && a.push(`Picking a ${c} fills ${r} from it.`), a;
166
+ const i = O(n.field, r), o = O(t, r), l = n.relatedCollection ?? null, u = l ? k(l, r) : "records", c = l ? s.split(".").map((p, $) => $ === 0 ? w(l, p, r) : y(p)).join("’s ") : y(s), a = e.value_map && Object.keys(e.value_map).length > 0 ? `whose ${c} is mapped from this record’s ${o}` : e.filter_is_m2m ? `whose ${c} is one of this record’s ${o}` : `whose ${c} is this record’s ${o}`, f = [`${i} only offers ${u} ${a}.`];
167
+ return e.clear_on_parent_change !== !1 && f.push(`Changing ${o} clears ${i}.`), e.clear_on_unavailable && f.push(`A ${i} that no longer fits is cleared.`), f.push(
168
+ e.show_all_if_no_parent === !1 ? `${i} stays locked until ${o} is picked.` : `With no ${o} picked, it offers every one.`
169
+ ), e.upstream && f.push(`Picking a ${i} fills ${o} from it.`), f;
170
170
  }
171
- function D(e) {
171
+ function z(e) {
172
172
  return [e.first_name, e.last_name].filter(Boolean).join(" ").trim() || e.email || "someone";
173
173
  }
174
174
  function j(e) {
@@ -181,35 +181,80 @@ function j(e) {
181
181
  return null;
182
182
  }
183
183
  }
184
- const M = /* @__PURE__ */ new Set(["eq", "neq", "gt", "gte", "lt", "lte", "in"]);
185
- function K(e, n, o = {}) {
184
+ const D = /* @__PURE__ */ new Set(["eq", "neq", "gt", "gte", "lt", "lte", "in"]);
185
+ function X(e, n, r = {}) {
186
186
  const t = j(e.filters);
187
187
  if (!t) return null;
188
188
  const s = [
189
- ...(e.users ?? []).map(D),
190
- ...(e.teams ?? []).map((l) => l.name ? `the ${l.name} team` : "a team")
191
- ], c = s.length ? s.length > 4 ? `${s.slice(0, 3).join(", ")} and ${s.length - 3} others` : T(s) : "nobody", r = s.length === 1 && !(e.teams ?? []).length ? "owns" : "own", i = n.stateLabel ? `${n.stateLabel}` : "this step";
192
- if (e.is_default) return `When no other group matches, ${c} ${r} ${i}.`;
193
- if (t.length === 0 || t.some((l) => !M.has(l.op ?? "eq"))) return null;
189
+ ...(e.users ?? []).map(z),
190
+ ...(e.teams ?? []).map((c) => c.name ? `the ${c.name} team` : "a team")
191
+ ], i = s.length ? s.length > 4 ? `${s.slice(0, 3).join(", ")} and ${s.length - 3} others` : N(s) : "nobody", o = s.length === 1 && !(e.teams ?? []).length ? "owns" : "own", l = n.stateLabel ? `${n.stateLabel}` : "this step";
192
+ if (e.is_default) return `When no other group matches, ${i} ${o} ${l}.`;
193
+ if (t.length === 0 || t.some((c) => !D.has(c.op ?? "eq"))) return null;
194
194
  const u = U(
195
- t.map((l) => ({ field: l.field, op: l.op ?? "eq", value: l.value })),
196
- o
195
+ t.map((c) => ({ field: c.field, op: c.op ?? "eq", value: c.value })),
196
+ r
197
197
  );
198
- return u ? `When ${u}, ${c} ${r} ${i}.` : null;
198
+ return u ? `When ${u}, ${i} ${o} ${l}.` : null;
199
+ }
200
+ function Z(e, n = {}) {
201
+ const r = e.op ?? "eq";
202
+ if (e.field === "$state") {
203
+ const s = (T(e.value) ?? []).flatMap((i) => i.split(",")).map((i) => i.trim()).filter(Boolean).map((i) => {
204
+ var o;
205
+ return ((o = n.states) == null ? void 0 : o[i]) ?? i;
206
+ });
207
+ return s.length ? r === "eq" ? `the record is at ${s[0]}` : r === "neq" ? `the record is not at ${s[0]}` : r === "in" ? `the record is at ${_(s)}` : null : null;
208
+ }
209
+ if (e.field === "$addendum_active") {
210
+ if (!["true", "false"].includes(String(e.value)) || r !== "eq" && r !== "neq") return null;
211
+ const t = String(e.value) === "true";
212
+ return (r === "neq" ? !t : t) ? "an addendum is going through approval" : "no addendum is going through approval";
213
+ }
214
+ if (r === "related_none" || r === "related_some") {
215
+ const t = k(e.field.split(":")[0] ?? e.field, n);
216
+ return r === "related_none" ? `it has no linked ${t}` : `it has linked ${t}`;
217
+ }
218
+ return b(e.field, r, e.value, n);
219
+ }
220
+ function G(e, n = {}) {
221
+ if (!e) return [];
222
+ const r = (s) => {
223
+ const i = s.map((o) => Z(o, n));
224
+ return i.some((o) => !o) ? null : N(i);
225
+ };
226
+ if (Array.isArray(e)) {
227
+ if (!e.length) return [];
228
+ const s = r(e);
229
+ return s ? [`Anyone can make it while ${s}.`] : null;
230
+ }
231
+ const t = [];
232
+ for (const [s, i] of Object.entries(e)) {
233
+ const o = `On ${k(s, n)}`;
234
+ if (!Array.isArray(i)) return null;
235
+ if (!i.length) {
236
+ t.push(`${o}, anyone can make it.`);
237
+ continue;
238
+ }
239
+ const l = r(i);
240
+ if (!l) return null;
241
+ t.push(`${o}, anyone can make it while ${l}.`);
242
+ }
243
+ return t;
199
244
  }
200
- function Q(e, n = {}) {
201
- var a, d, m;
202
- const o = ((a = e.to_states) != null && a.length ? e.to_states : e.to_state ? [e.to_state] : []).map(
245
+ function L(e, n = {}) {
246
+ var f, m, d;
247
+ const r = ((f = e.to_states) != null && f.length ? e.to_states : e.to_state ? [e.to_state] : []).map(
203
248
  (p) => {
204
249
  var $;
205
250
  return (($ = n.states) == null ? void 0 : $[p]) ?? p;
206
251
  }
207
252
  );
208
- if (!o.length) return null;
209
- const t = e.from_state ? ((d = n.states) == null ? void 0 : d[e.from_state]) ?? e.from_state : null, s = j(e.required_roles), c = j(e.condition_rules), r = j(e.requirements);
210
- if (!s || !c || !r) return null;
211
- const i = c.length ? U(c, n) : null;
212
- if (c.length && !i) return null;
253
+ if (!r.length) return null;
254
+ const t = e.from_state ? ((m = n.states) == null ? void 0 : m[e.from_state]) ?? e.from_state : null, s = j(e.required_roles), i = j(e.condition_rules), o = j(e.requirements);
255
+ if (!s || !i || !o) return null;
256
+ const l = i.length ? U(i, n) : null;
257
+ if (i.length && !l) return null;
213
258
  let u;
214
259
  if (s.length) {
215
260
  const p = s.map(($) => {
@@ -219,25 +264,30 @@ function Q(e, n = {}) {
219
264
  u = p.length === s.length ? _(p) : `people in ${s.length === 1 ? "one chosen role" : `one of ${s.length} chosen roles`}`;
220
265
  } else u = "anyone who can edit the record";
221
266
  e.require_owner && (u = e.allow_creator ? `the step’s owner or the record’s creator${s.length ? ` (in ${u})` : ""}` : `the step’s owner${s.length ? ` (in ${u})` : ""}`);
222
- const l = e.to_previous ? `back to the step it came from (${_(o)} when that is not known)` : `to ${_(o)}`, h = `move it ${t ? `from ${t} ` : "from any step "}${l}`, f = [];
223
- e.auto_trigger ? f.push(
224
- C(`${i ? `when ${i}, ` : ""}it moves by itself ${t ? `from ${t} ` : ""}${l}.`)
225
- ) : f.push(C(`${i ? `when ${i}, ` : ""}${u} can ${h}.`));
226
- for (const p of r) {
227
- if ((p == null ? void 0 : p.type) !== "child_fields" || !p.collection || !((m = p.fields) != null && m.length)) return null;
267
+ const c = e.to_previous ? `back to the step it came from (${_(r)} when that is not known)` : `to ${_(r)}`, h = `move it ${t ? `from ${t} ` : "from any step "}${c}`, a = [];
268
+ e.auto_trigger ? a.push(
269
+ I(`${l ? `when ${l}, ` : ""}it moves by itself ${t ? `from ${t} ` : ""}${c}.`)
270
+ ) : a.push(I(`${l ? `when ${l}, ` : ""}${u} can ${h}.`));
271
+ for (const p of o) {
272
+ if ((p == null ? void 0 : p.type) !== "child_fields" || !p.collection || !((d = p.fields) != null && d.length)) return null;
228
273
  const $ = p.fields.map(
229
274
  (g) => {
230
- var W;
231
- return ((W = p.labels) == null ? void 0 : W[g]) ?? w(p.collection, g, n);
275
+ var C;
276
+ return ((C = p.labels) == null ? void 0 : C[g]) ?? w(p.collection, g, n);
232
277
  }
233
278
  );
234
- f.push(
235
- `Before it moves, every ${N(p.collection, n)} line needs ${T($)}.`
279
+ a.push(
280
+ `Before it moves, every ${k(p.collection, n)} line needs ${N($)}.`
236
281
  );
237
282
  }
238
- return e.comment_mode === "required" && f.push("A comment is required."), f;
283
+ if (e.require_owner && !e.auto_trigger) {
284
+ const p = G(e.open_when ?? null, n);
285
+ if (!p) return null;
286
+ a.push(...p);
287
+ }
288
+ return e.comment_mode === "required" && a.push("A comment is required."), a;
239
289
  }
240
- const q = {
290
+ const F = {
241
291
  sum: "Sum of",
242
292
  count: "Number of",
243
293
  avg: "Average of",
@@ -247,121 +297,121 @@ const q = {
247
297
  distinct_count: "Number of different",
248
298
  weighted_avg: "Weighted average of"
249
299
  };
250
- function E(e, n) {
251
- return e.replace(/\{\{\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\}\}/g, (o, t) => n(t)).replace(/\bitem\.([A-Za-z_][A-Za-z0-9_]*)/g, (o, t) => n(t)).replace(/\s*\*\s*/g, " × ").replace(/\s*\/\s*/g, " ÷ ").replace(/\s+/g, " ").trim();
300
+ function B(e, n) {
301
+ return e.replace(/\{\{\s*([A-Za-z_][A-Za-z0-9_.]*)\s*\}\}/g, (r, t) => n(t)).replace(/\bitem\.([A-Za-z_][A-Za-z0-9_]*)/g, (r, t) => n(t)).replace(/\s*\*\s*/g, " × ").replace(/\s*\/\s*/g, " ÷ ").replace(/\s+/g, " ").trim();
252
302
  }
253
- function Z(e, n) {
254
- var f, a;
255
- const o = typeof e.related_collection == "string" ? e.related_collection : null, t = typeof e.aggregate == "string" ? e.aggregate : null;
256
- if (!o || !t || !q[t]) return null;
257
- const s = N(o, n), c = (d) => w(o, d, n), r = [];
258
- let i;
303
+ function Y(e, n) {
304
+ var a, f;
305
+ const r = typeof e.related_collection == "string" ? e.related_collection : null, t = typeof e.aggregate == "string" ? e.aggregate : null;
306
+ if (!r || !t || !F[t]) return null;
307
+ const s = k(r, n), i = (m) => w(r, m, n), o = [];
308
+ let l;
259
309
  if (t === "count")
260
- i = `${s} records`;
310
+ l = `${s} records`;
261
311
  else {
262
- const d = typeof e.value_formula == "string" ? e.value_formula.trim() : "", m = typeof e.value_field == "string" ? e.value_field : "";
263
- if (d)
264
- i = `(${E(d, c)})`, r.push(...P(d).map(c));
265
- else if (m)
266
- i = c(m), r.push(i);
312
+ const m = typeof e.value_formula == "string" ? e.value_formula.trim() : "", d = typeof e.value_field == "string" ? e.value_field : "";
313
+ if (m)
314
+ l = `(${B(m, i)})`, o.push(...R(m).map(i));
315
+ else if (d)
316
+ l = i(d), o.push(l);
267
317
  else return null;
268
318
  if (t === "weighted_avg") {
269
319
  const p = typeof e.weight_field == "string" ? e.weight_field : "";
270
320
  if (!p) return null;
271
- i = `${i} weighted by ${c(p)}`, r.push(c(p));
321
+ l = `${l} weighted by ${i(p)}`, o.push(i(p));
272
322
  }
273
- i = `${i} on ${s}`;
323
+ l = `${l} on ${s}`;
274
324
  }
275
- const u = t === "distinct_count" ? `${q[t]} ${i}` : `${q[t]} ${i}`;
276
- let l = "";
325
+ const u = t === "distinct_count" ? `${F[t]} ${l}` : `${F[t]} ${l}`;
326
+ let c = "";
277
327
  if (e.filter && typeof e.filter == "object" && Object.keys(e.filter).length > 0) {
278
- const d = {
279
- fields: ((f = n.relatedFields) == null ? void 0 : f[o]) ?? {},
280
- choices: ((a = n.relatedChoices) == null ? void 0 : a[o]) ?? {},
328
+ const m = {
329
+ fields: ((a = n.relatedFields) == null ? void 0 : a[r]) ?? {},
330
+ choices: ((f = n.relatedChoices) == null ? void 0 : f[r]) ?? {},
281
331
  collections: n.collections,
282
332
  relatedFields: n.relatedFields
283
- }, m = O(e.filter, d);
284
- if (!m) return null;
285
- l = ` where ${m}`;
333
+ }, d = q(e.filter, m);
334
+ if (!d) return null;
335
+ c = ` where ${d}`;
286
336
  }
287
337
  const h = e.recursive ? ", counting every level below" : "";
288
- return { text: `${u}${l}${h}`, inputs: r };
338
+ return { text: `${u}${c}${h}`, inputs: o };
289
339
  }
290
- function X(e, n = {}, o = []) {
291
- var c;
292
- const t = (r) => v(r, n), s = e.computed_store === !0 || e.computed_store === 1;
340
+ function x(e, n = {}, r = []) {
341
+ var i;
342
+ const t = (o) => O(o, n), s = e.computed_store === !0 || e.computed_store === 1;
293
343
  switch (e.computed_type) {
294
344
  case "rollup": {
295
- const r = k(e.computed_formula);
296
- if (!r) return null;
297
- const u = (Array.isArray(r.sources) ? r.sources : [r]).map((a) => Z(a, n));
298
- if (!u.length || u.some((a) => !a)) return null;
299
- const l = u, h = [];
300
- l.length > 1 && h.push("The figures above are added together.");
301
- const f = r.parent_filter;
302
- if (f && typeof f == "object" && Object.keys(f).length > 0) {
303
- const a = O(f, n);
304
- if (!a) return null;
305
- h.push(`Only for records where ${a}; on other records it is typed in by hand.`);
345
+ const o = S(e.computed_formula);
346
+ if (!o) return null;
347
+ const u = (Array.isArray(o.sources) ? o.sources : [o]).map((f) => Y(f, n));
348
+ if (!u.length || u.some((f) => !f)) return null;
349
+ const c = u, h = [];
350
+ c.length > 1 && h.push("The figures above are added together.");
351
+ const a = o.parent_filter;
352
+ if (a && typeof a == "object" && Object.keys(a).length > 0) {
353
+ const f = q(a, n);
354
+ if (!f) return null;
355
+ h.push(`Only for records where ${f}; on other records it is typed in by hand.`);
306
356
  }
307
357
  return e.computed_store != null && h.push(
308
358
  s ? "Saved on the record and recalculated when one of those records changes." : "Worked out each time the record is read."
309
359
  ), {
310
- sentence: `${l.map((a) => a.text).join(", plus ")}.`,
360
+ sentence: `${c.map((f) => f.text).join(", plus ")}.`,
311
361
  notes: h,
312
- inputs: [...new Set(l.flatMap((a) => a.inputs))]
362
+ inputs: [...new Set(c.flatMap((f) => f.inputs))]
313
363
  };
314
364
  }
315
365
  case "lookup": {
316
- const r = k(e.computed_formula), i = typeof (r == null ? void 0 : r.fk_field) == "string" ? r.fk_field : null, u = typeof (r == null ? void 0 : r.source_field) == "string" ? r.source_field : null;
317
- if (!i || !u) return null;
318
- const l = (c = n.links) == null ? void 0 : c[i], h = l ? w(l, u, n) : y(u);
366
+ const o = S(e.computed_formula), l = typeof (o == null ? void 0 : o.fk_field) == "string" ? o.fk_field : null, u = typeof (o == null ? void 0 : o.source_field) == "string" ? o.source_field : null;
367
+ if (!l || !u) return null;
368
+ const c = (i = n.links) == null ? void 0 : i[l], h = c ? w(c, u, n) : y(u);
319
369
  return {
320
- sentence: `Copied from the ${t(i)}’s ${h} when ${t(i)} is set.`,
370
+ sentence: `Copied from the ${t(l)}’s ${h} when ${t(l)} is set.`,
321
371
  notes: [
322
- `It keeps the value it copied, even if the ${t(i)} changes later; clearing ${t(i)} clears it.`
372
+ `It keeps the value it copied, even if the ${t(l)} changes later; clearing ${t(l)} clears it.`
323
373
  ],
324
- inputs: [t(i)]
374
+ inputs: [t(l)]
325
375
  };
326
376
  }
327
377
  case "read":
328
378
  case "write": {
329
- const r = String(e.computed_formula ?? "").trim();
330
- if (!r) return null;
331
- const i = P(r).map(t);
379
+ const o = String(e.computed_formula ?? "").trim();
380
+ if (!o) return null;
381
+ const l = R(o).map(t);
332
382
  return {
333
- sentence: `Worked out as ${E(r, t)}.`,
383
+ sentence: `Worked out as ${B(o, t)}.`,
334
384
  notes: [
335
- e.computed_type === "read" ? "Worked out each time the record is read; it is never saved." : `Saved on the record; worked out again when ${i.length ? _(i) : "an input"} changes.`
385
+ e.computed_type === "read" ? "Worked out each time the record is read; it is never saved." : `Saved on the record; worked out again when ${l.length ? _(l) : "an input"} changes.`
336
386
  ],
337
- inputs: i
387
+ inputs: l
338
388
  };
339
389
  }
340
390
  }
341
- for (const { field: r, config: i } of o) {
342
- const u = k(i), l = k(u == null ? void 0 : u.field_map), h = typeof (u == null ? void 0 : u.source_collection) == "string" ? u.source_collection : null;
343
- if (!l || !h) continue;
344
- const f = l[e.field];
345
- if (typeof f != "string" || !f.trim()) continue;
346
- const a = typeof (u == null ? void 0 : u.source_fk_field) == "string" ? u.source_fk_field : r, d = f.split("||").map((g) => g.trim()).filter(Boolean), m = d.map(
347
- (g) => g === "id" ? `the picked ${t(a)} itself` : w(h, g, n)
348
- ), p = m.length === 1 ? d[0] === "id" ? m[0] : `the ${t(a)}’s ${m[0]}` : `the ${t(a)}’s ${m[0]} (or ${_(m.slice(1))} when that is empty)`, $ = (u == null ? void 0 : u.on_write) === !1 ? "picked on the form" : "set, on the form or through the API";
391
+ for (const { field: o, config: l } of r) {
392
+ const u = S(l), c = S(u == null ? void 0 : u.field_map), h = typeof (u == null ? void 0 : u.source_collection) == "string" ? u.source_collection : null;
393
+ if (!c || !h) continue;
394
+ const a = c[e.field];
395
+ if (typeof a != "string" || !a.trim()) continue;
396
+ const f = typeof (u == null ? void 0 : u.source_fk_field) == "string" ? u.source_fk_field : o, m = a.split("||").map((g) => g.trim()).filter(Boolean), d = m.map(
397
+ (g) => g === "id" ? `the picked ${t(f)} itself` : w(h, g, n)
398
+ ), p = d.length === 1 ? m[0] === "id" ? d[0] : `the ${t(f)}’s ${d[0]}` : `the ${t(f)}’s ${d[0]} (or ${_(d.slice(1))} when that is empty)`, $ = (u == null ? void 0 : u.on_write) === !1 ? "picked on the form" : "set, on the form or through the API";
349
399
  return {
350
- sentence: `Filled from ${p} when ${t(a)} is ${$}.`,
400
+ sentence: `Filled from ${p} when ${t(f)} is ${$}.`,
351
401
  notes: ["You can change it afterwards; a value someone typed is never overwritten."],
352
- inputs: [t(a)]
402
+ inputs: [t(f)]
353
403
  };
354
404
  }
355
405
  return null;
356
406
  }
357
- const J = (e, n, o = `${n}s`) => `${e.toLocaleString("en-US")} ${e === 1 ? n : o}`;
358
- function G(e) {
407
+ const E = (e, n, r = `${n}s`) => `${e.toLocaleString("en-US")} ${e === 1 ? n : r}`;
408
+ function V(e) {
359
409
  if (e.length === 0) return "";
360
- const n = e.slice(0, 3).map((t) => `“${t}”`), o = e.length - n.length;
361
- return `${J(e.length, "form")} (${n.join(", ")}${o > 0 ? ` and ${o} more` : ""})`;
410
+ const n = e.slice(0, 3).map((t) => `“${t}”`), r = e.length - n.length;
411
+ return `${E(e.length, "form")} (${n.join(", ")}${r > 0 ? ` and ${r} more` : ""})`;
362
412
  }
363
- function L(e, n = [], o, t = {}) {
364
- var c;
413
+ function ee(e, n = [], r, t = {}) {
414
+ var i;
365
415
  const s = {
366
416
  ...t,
367
417
  fields: { ...t.fields ?? {} },
@@ -369,50 +419,52 @@ function L(e, n = [], o, t = {}) {
369
419
  choices: { ...t.choices ?? {} },
370
420
  links: { ...t.links ?? {} }
371
421
  };
372
- for (const r of e) {
373
- (c = r.label) != null && c.trim() && (s.fields[r.field] = r.label.trim()), r.type && (s.types[r.field] = r.type);
374
- let i = r.options;
375
- if (typeof i == "string")
422
+ for (const o of e) {
423
+ (i = o.label) != null && i.trim() && (s.fields[o.field] = o.label.trim()), o.type && (s.types[o.field] = o.type);
424
+ let l = o.options;
425
+ if (typeof l == "string")
376
426
  try {
377
- i = JSON.parse(i);
427
+ l = JSON.parse(l);
378
428
  } catch {
379
- i = null;
429
+ l = null;
380
430
  }
381
- const u = Array.isArray(i) ? i : i && typeof i == "object" ? i.choices : null;
431
+ const u = Array.isArray(l) ? l : l && typeof l == "object" ? l.choices : null;
382
432
  if (!Array.isArray(u)) continue;
383
- const l = {};
433
+ const c = {};
384
434
  for (const h of u) {
385
435
  if (!h || typeof h != "object") continue;
386
- const { value: f, text: a } = h;
387
- f != null && (l[String(f)] = F(a == null ? String(f) : String(a)));
436
+ const { value: a, text: f } = h;
437
+ a != null && (c[String(a)] = W(f == null ? String(a) : String(f)));
388
438
  }
389
- Object.keys(l).length && (s.choices[r.field] = l);
439
+ Object.keys(c).length && (s.choices[o.field] = c);
390
440
  }
391
- for (const r of n)
392
- (!o || r.many_collection === o) && r.many_field && r.one_collection && !r.junction_field && (s.links[r.many_field] = r.one_collection);
441
+ for (const o of n)
442
+ (!r || o.many_collection === r) && o.many_field && o.one_collection && !o.junction_field && (s.links[o.many_field] = o.one_collection);
393
443
  return s;
394
444
  }
395
- function x(e) {
445
+ function te(e) {
396
446
  var t;
397
447
  const n = [];
398
- e.forms.length && n.push(`It is on ${G(e.forms)}`);
399
- const o = ((t = e.records) == null ? void 0 : t.with_value) ?? 0;
400
- return e.records && o > 0 && n.push(`${J(o, "record")} ${o === 1 ? "has" : "have"} a ${e.fieldLabel}`), n.length ? `${n.join(" and ")}.` : null;
448
+ e.forms.length && n.push(`It is on ${V(e.forms)}`);
449
+ const r = ((t = e.records) == null ? void 0 : t.with_value) ?? 0;
450
+ return e.records && r > 0 && n.push(`${E(r, "record")} ${r === 1 ? "has" : "have"} a ${e.fieldLabel}`), n.length ? `${n.join(" and ")}.` : null;
401
451
  }
402
452
  export {
403
- T as andList,
404
- N as collectionLabelOf,
405
- H as describeCascadeFilter,
406
- A as describeCondition,
453
+ N as andList,
454
+ k as collectionLabelOf,
455
+ Q as describeCascadeFilter,
456
+ b as describeCondition,
407
457
  U as describeConditionList,
408
- x as describeFieldReach,
409
- X as describeFieldSource,
410
- O as describeFilterObject,
411
- K as describeOwnerGroup,
412
- Q as describeTransition,
413
- v as fieldLabelOf,
414
- E as formulaInWords,
458
+ te as describeFieldReach,
459
+ x as describeFieldSource,
460
+ q as describeFilterObject,
461
+ G as describeOpenWhen,
462
+ Z as describeOpenWhenRule,
463
+ X as describeOwnerGroup,
464
+ L as describeTransition,
465
+ O as fieldLabelOf,
466
+ B as formulaInWords,
415
467
  _ as orList,
416
- L as sentenceLabelsFromFields,
417
- S as valueTextOf
468
+ ee as sentenceLabelsFromFields,
469
+ v as valueTextOf
418
470
  };