@lotics/app-sdk 0.134.2 → 0.134.3

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 CHANGED
@@ -56,7 +56,7 @@ import {
56
56
  subtractDecimal,
57
57
  sumDecimal,
58
58
  urlParam
59
- } from "./chunk-FE5YWUAG.js";
59
+ } from "./chunk-55CRJ3GB.js";
60
60
 
61
61
  // src/mount.tsx
62
62
  import { createRoot } from "react-dom/client";
@@ -876,6 +876,12 @@ var ExpressionArgumentError = class extends Error {
876
876
  this.name = "ExpressionArgumentError";
877
877
  }
878
878
  };
879
+ var ExpressionValueError = class extends ExpressionArgumentError {
880
+ constructor(message2) {
881
+ super(message2);
882
+ this.name = "ExpressionValueError";
883
+ }
884
+ };
879
885
  var ExpressionLimitError = class extends Error {
880
886
  constructor(message2) {
881
887
  super(message2);
@@ -2536,7 +2542,7 @@ function first(arr) {
2536
2542
  }
2537
2543
  function requireFirst(arr, message2) {
2538
2544
  if (arr == null) {
2539
- throw new ExpressionArgumentError(message2 ?? "requireFirst: array is null or undefined");
2545
+ throw new ExpressionValueError(message2 ?? "requireFirst: array is null or undefined");
2540
2546
  }
2541
2547
  if (!Array.isArray(arr)) {
2542
2548
  throw new ExpressionArgumentError("requireFirst: expected array, got " + typeof arr);
@@ -3295,19 +3301,19 @@ function signed(format2, n) {
3295
3301
  }
3296
3302
 
3297
3303
  // ../shared/src/format_money.ts
3298
- function numberFormatter(locale, maximumFractionDigits) {
3299
- const key = `${locale}\0${maximumFractionDigits}`;
3304
+ function numberFormatter(locale, maximumFractionDigits, minimumFractionDigits = 0) {
3305
+ const key = `${locale}\0${minimumFractionDigits}\0${maximumFractionDigits}`;
3300
3306
  let format2 = numberFormatters.get(key);
3301
3307
  if (format2 === void 0) {
3302
- format2 = new Intl.NumberFormat(locale, { maximumFractionDigits });
3308
+ format2 = new Intl.NumberFormat(locale, { minimumFractionDigits, maximumFractionDigits });
3303
3309
  numberFormatters.set(key, format2);
3304
3310
  }
3305
3311
  return format2;
3306
3312
  }
3307
3313
  var numberFormatters = /* @__PURE__ */ new Map();
3308
3314
  function formatNumber(value, options = {}) {
3309
- const { locale = "vi-VN", maxFractionDigits = 2 } = options;
3310
- return signed((magnitude) => numberFormatter(locale, maxFractionDigits).format(magnitude), value);
3315
+ const { locale = "vi-VN", minFractionDigits, maxFractionDigits = 2 } = options;
3316
+ return signed((magnitude) => numberFormatter(locale, Math.max(maxFractionDigits, minFractionDigits ?? 0), minFractionDigits).format(magnitude), value);
3311
3317
  }
3312
3318
 
3313
3319
  // ../shared/src/expression_string.ts
@@ -3365,7 +3371,7 @@ function repeat(str, count) {
3365
3371
  throw new ExpressionArgumentError("repeat: expected string, got " + typeof str);
3366
3372
  }
3367
3373
  if (typeof count !== "number" || !Number.isInteger(count) || count < 0) {
3368
- throw new ExpressionArgumentError("repeat: count must be a whole number, 0 or more");
3374
+ throw new ExpressionValueError("repeat: count must be a whole number, 0 or more");
3369
3375
  }
3370
3376
  assertStringLength("repeat", str.length * count);
3371
3377
  return str.repeat(count);
@@ -3564,7 +3570,7 @@ function uuidFrom(text2) {
3564
3570
  if (typeof text2 !== "string") {
3565
3571
  throw new ExpressionArgumentError(`uuidFrom: expected text, got ${text2 == null ? "nothing" : typeof text2}`);
3566
3572
  }
3567
- if (text2 === "") throw new ExpressionArgumentError("uuidFrom: expected text, got an empty text");
3573
+ if (text2 === "") throw new ExpressionValueError("uuidFrom: expected text, got an empty text");
3568
3574
  return uuidV5(text2, UUID_FROM_NAMESPACE);
3569
3575
  }
3570
3576
  var VI_DIGITS = [
@@ -3657,7 +3663,7 @@ function numberToWords(value, language = "vi") {
3657
3663
  throw new ExpressionArgumentError("numberToWords: expected number, got " + typeof value);
3658
3664
  }
3659
3665
  if (!isFinite(n)) {
3660
- throw new ExpressionArgumentError("numberToWords: value must be a finite number");
3666
+ throw new ExpressionValueError("numberToWords: value must be a finite number");
3661
3667
  }
3662
3668
  if (language !== "vi" && language !== "en") {
3663
3669
  throw new ExpressionArgumentError(`numberToWords: language must be "vi" or "en", got ${typeof language}`);
@@ -3688,7 +3694,7 @@ function enNumberToWords(n, negative) {
3688
3694
  for (let rem = n; rem > 0; rem = Math.floor(rem / 1e3), group++) {
3689
3695
  const value = rem % 1e3;
3690
3696
  if (value === 0) continue;
3691
- if (group >= EN_SCALES.length) throw new ExpressionArgumentError("numberToWords: value is too large to read in English");
3697
+ if (group >= EN_SCALES.length) throw new ExpressionValueError("numberToWords: value is too large to read in English");
3692
3698
  parts.unshift(EN_SCALES[group] ? `${enReadGroup(value)} ${EN_SCALES[group]}` : enReadGroup(value));
3693
3699
  }
3694
3700
  const result = parts.join(" ");
@@ -3774,7 +3780,7 @@ function distanceMeters(lat1, lon1, lat2, lon2) {
3774
3780
  function mean(arr) {
3775
3781
  if (arr == null) return null;
3776
3782
  if (!Array.isArray(arr)) {
3777
- throw new Error("mean: expected array, got " + typeof arr);
3783
+ throw new ExpressionArgumentError("mean: expected array, got " + typeof arr);
3778
3784
  }
3779
3785
  const present = arr.filter((item) => item != null);
3780
3786
  if (present.length === 0) {
@@ -3788,7 +3794,7 @@ function mean(arr) {
3788
3794
  }
3789
3795
  function min(...values2) {
3790
3796
  if (values2.length === 0) {
3791
- throw new Error("min: expected at least one argument");
3797
+ throw new ExpressionArgumentError("min: expected at least one argument");
3792
3798
  }
3793
3799
  if (values2.length === 1 && Array.isArray(values2[0])) {
3794
3800
  const arr = values2[0];
@@ -3816,7 +3822,7 @@ function min(...values2) {
3816
3822
  }
3817
3823
  function max(...values2) {
3818
3824
  if (values2.length === 0) {
3819
- throw new Error("max: expected at least one argument");
3825
+ throw new ExpressionArgumentError("max: expected at least one argument");
3820
3826
  }
3821
3827
  if (values2.length === 1 && Array.isArray(values2[0])) {
3822
3828
  const arr = values2[0];
@@ -3845,17 +3851,17 @@ function max(...values2) {
3845
3851
  function round(value, precision) {
3846
3852
  if (value == null) return null;
3847
3853
  if (typeof value !== "number") {
3848
- throw new Error("round: expected number, got " + typeof value);
3854
+ throw new ExpressionArgumentError("round: expected number, got " + typeof value);
3849
3855
  }
3850
3856
  if (precision != null && typeof precision !== "number") {
3851
- throw new Error("round: precision must be a number");
3857
+ throw new ExpressionArgumentError("round: precision must be a number");
3852
3858
  }
3853
3859
  return roundDecimal(value, precision ?? 0);
3854
3860
  }
3855
3861
  function sum(arr) {
3856
3862
  if (arr == null) return 0;
3857
3863
  if (!Array.isArray(arr)) {
3858
- throw new Error("sum: expected array, got " + typeof arr);
3864
+ throw new ExpressionArgumentError("sum: expected array, got " + typeof arr);
3859
3865
  }
3860
3866
  const present = arr.filter((item) => item != null);
3861
3867
  if (!present.every((item) => typeof item === "number")) {
@@ -3866,34 +3872,34 @@ function sum(arr) {
3866
3872
  function abs(n) {
3867
3873
  if (n == null) return null;
3868
3874
  if (typeof n !== "number") {
3869
- throw new Error("abs: expected number, got " + typeof n);
3875
+ throw new ExpressionArgumentError("abs: expected number, got " + typeof n);
3870
3876
  }
3871
3877
  return Math.abs(n);
3872
3878
  }
3873
3879
  function ceil(n) {
3874
3880
  if (n == null) return null;
3875
3881
  if (typeof n !== "number") {
3876
- throw new Error("ceil: expected number, got " + typeof n);
3882
+ throw new ExpressionArgumentError("ceil: expected number, got " + typeof n);
3877
3883
  }
3878
3884
  return Math.ceil(n);
3879
3885
  }
3880
3886
  function floor(n) {
3881
3887
  if (n == null) return null;
3882
3888
  if (typeof n !== "number") {
3883
- throw new Error("floor: expected number, got " + typeof n);
3889
+ throw new ExpressionArgumentError("floor: expected number, got " + typeof n);
3884
3890
  }
3885
3891
  return Math.floor(n);
3886
3892
  }
3887
3893
  function clamp(n, min3, max3) {
3888
3894
  if (n == null) return null;
3889
3895
  if (typeof n !== "number") {
3890
- throw new Error("clamp: expected number, got " + typeof n);
3896
+ throw new ExpressionArgumentError("clamp: expected number, got " + typeof n);
3891
3897
  }
3892
3898
  if (typeof min3 !== "number") {
3893
- throw new Error("clamp: min must be a number");
3899
+ throw new ExpressionArgumentError("clamp: min must be a number");
3894
3900
  }
3895
3901
  if (typeof max3 !== "number") {
3896
- throw new Error("clamp: max must be a number");
3902
+ throw new ExpressionArgumentError("clamp: max must be a number");
3897
3903
  }
3898
3904
  if (min3 > max3) {
3899
3905
  throw new Error("clamp: min must be less than or equal to max");
@@ -3905,16 +3911,16 @@ function clamp(n, min3, max3) {
3905
3911
  function percentage(part, total, decimals) {
3906
3912
  if (part == null || total == null) return null;
3907
3913
  if (typeof part !== "number") {
3908
- throw new Error("percentage: part must be a number");
3914
+ throw new ExpressionArgumentError("percentage: part must be a number");
3909
3915
  }
3910
3916
  if (typeof total !== "number") {
3911
- throw new Error("percentage: total must be a number");
3917
+ throw new ExpressionArgumentError("percentage: total must be a number");
3912
3918
  }
3913
3919
  if (total === 0) {
3914
3920
  throw new Error("percentage: total cannot be zero");
3915
3921
  }
3916
3922
  if (decimals != null && typeof decimals !== "number") {
3917
- throw new Error("percentage: decimals must be a number");
3923
+ throw new ExpressionArgumentError("percentage: decimals must be a number");
3918
3924
  }
3919
3925
  const percent = divideDecimal(multiplyDecimal(part, 100), total);
3920
3926
  return decimals != null ? roundDecimal(percent, decimals) : percent;
@@ -3922,17 +3928,17 @@ function percentage(part, total, decimals) {
3922
3928
  function pow(base, exponent) {
3923
3929
  if (base == null || exponent == null) return null;
3924
3930
  if (typeof base !== "number") {
3925
- throw new Error("pow: base must be a number");
3931
+ throw new ExpressionArgumentError("pow: base must be a number");
3926
3932
  }
3927
3933
  if (typeof exponent !== "number") {
3928
- throw new Error("pow: exponent must be a number");
3934
+ throw new ExpressionArgumentError("pow: exponent must be a number");
3929
3935
  }
3930
3936
  return powerDecimal(base, exponent);
3931
3937
  }
3932
3938
  function sqrt(n) {
3933
3939
  if (n == null) return null;
3934
3940
  if (typeof n !== "number") {
3935
- throw new Error("sqrt: expected number, got " + typeof n);
3941
+ throw new ExpressionArgumentError("sqrt: expected number, got " + typeof n);
3936
3942
  }
3937
3943
  if (n < 0) {
3938
3944
  throw new Error("sqrt: cannot calculate square root of negative number");
@@ -3942,10 +3948,10 @@ function sqrt(n) {
3942
3948
  function mod(n, divisor) {
3943
3949
  if (n == null || divisor == null) return null;
3944
3950
  if (typeof n !== "number") {
3945
- throw new Error("mod: expected number, got " + typeof n);
3951
+ throw new ExpressionArgumentError("mod: expected number, got " + typeof n);
3946
3952
  }
3947
3953
  if (typeof divisor !== "number") {
3948
- throw new Error("mod: divisor must be a number");
3954
+ throw new ExpressionArgumentError("mod: divisor must be a number");
3949
3955
  }
3950
3956
  if (divisor === 0) {
3951
3957
  throw new Error("mod: divisor cannot be zero");
@@ -3953,7 +3959,7 @@ function mod(n, divisor) {
3953
3959
  return moduloDecimal(n, divisor);
3954
3960
  }
3955
3961
  function degrees(name, value) {
3956
- if (typeof value !== "number") throw new Error(`distance: ${name} must be a number, got ${typeof value}`);
3962
+ if (typeof value !== "number") throw new ExpressionArgumentError(`distance: ${name} must be a number, got ${typeof value}`);
3957
3963
  return value;
3958
3964
  }
3959
3965
  function distance(lat1, lon1, lat2, lon2) {
@@ -3987,36 +3993,36 @@ function getNestedValue(obj, path) {
3987
3993
  function keys(obj) {
3988
3994
  if (obj == null) return [];
3989
3995
  if (typeof obj !== "object") {
3990
- throw new Error("keys: expected object, got " + typeof obj);
3996
+ throw new ExpressionArgumentError("keys: expected object, got " + typeof obj);
3991
3997
  }
3992
3998
  if (Array.isArray(obj)) {
3993
- throw new Error("keys: expected object, got array");
3999
+ throw new ExpressionArgumentError("keys: expected object, got array");
3994
4000
  }
3995
4001
  return Object.keys(obj);
3996
4002
  }
3997
4003
  function values(obj) {
3998
4004
  if (obj == null) return [];
3999
4005
  if (typeof obj !== "object") {
4000
- throw new Error("values: expected object, got " + typeof obj);
4006
+ throw new ExpressionArgumentError("values: expected object, got " + typeof obj);
4001
4007
  }
4002
4008
  if (Array.isArray(obj)) {
4003
- throw new Error("values: expected object, got array");
4009
+ throw new ExpressionArgumentError("values: expected object, got array");
4004
4010
  }
4005
4011
  return Object.values(obj);
4006
4012
  }
4007
4013
  function entries(obj) {
4008
4014
  if (obj == null) return [];
4009
4015
  if (typeof obj !== "object") {
4010
- throw new Error("entries: expected object, got " + typeof obj);
4016
+ throw new ExpressionArgumentError("entries: expected object, got " + typeof obj);
4011
4017
  }
4012
4018
  if (Array.isArray(obj)) {
4013
- throw new Error("entries: expected object, got array");
4019
+ throw new ExpressionArgumentError("entries: expected object, got array");
4014
4020
  }
4015
4021
  return Object.entries(obj);
4016
4022
  }
4017
4023
  function get(obj, path, defaultValue) {
4018
4024
  if (typeof path !== "string") {
4019
- throw new Error("get: path must be a string");
4025
+ throw new ExpressionArgumentError("get: path must be a string");
4020
4026
  }
4021
4027
  const value = getNestedValue(obj, path);
4022
4028
  return value !== void 0 ? value : defaultValue;
@@ -4024,13 +4030,13 @@ function get(obj, path, defaultValue) {
4024
4030
  function pick(obj, fields) {
4025
4031
  if (obj == null) return {};
4026
4032
  if (typeof obj !== "object") {
4027
- throw new Error("pick: expected object, got " + typeof obj);
4033
+ throw new ExpressionArgumentError("pick: expected object, got " + typeof obj);
4028
4034
  }
4029
4035
  if (Array.isArray(obj)) {
4030
- throw new Error("pick: expected object, got array");
4036
+ throw new ExpressionArgumentError("pick: expected object, got array");
4031
4037
  }
4032
4038
  if (!Array.isArray(fields)) {
4033
- throw new Error("pick: fields must be an array");
4039
+ throw new ExpressionArgumentError("pick: fields must be an array");
4034
4040
  }
4035
4041
  const result = {};
4036
4042
  const objRecord = obj;
@@ -4043,13 +4049,13 @@ function pick(obj, fields) {
4043
4049
  function omit(obj, fields) {
4044
4050
  if (obj == null) return {};
4045
4051
  if (typeof obj !== "object") {
4046
- throw new Error("omit: expected object, got " + typeof obj);
4052
+ throw new ExpressionArgumentError("omit: expected object, got " + typeof obj);
4047
4053
  }
4048
4054
  if (Array.isArray(obj)) {
4049
- throw new Error("omit: expected object, got array");
4055
+ throw new ExpressionArgumentError("omit: expected object, got array");
4050
4056
  }
4051
4057
  if (!Array.isArray(fields)) {
4052
- throw new Error("omit: fields must be an array");
4058
+ throw new ExpressionArgumentError("omit: fields must be an array");
4053
4059
  }
4054
4060
  const result = {};
4055
4061
  const objRecord = obj;
@@ -4063,7 +4069,7 @@ function merge(obj1, obj2) {
4063
4069
  if (obj1 == null && obj2 == null) return {};
4064
4070
  if (obj1 == null) {
4065
4071
  if (typeof obj2 !== "object" || Array.isArray(obj2)) {
4066
- throw new Error(
4072
+ throw new ExpressionArgumentError(
4067
4073
  "merge: expected object, got " + (Array.isArray(obj2) ? "array" : typeof obj2)
4068
4074
  );
4069
4075
  }
@@ -4071,23 +4077,23 @@ function merge(obj1, obj2) {
4071
4077
  }
4072
4078
  if (obj2 == null) {
4073
4079
  if (typeof obj1 !== "object" || Array.isArray(obj1)) {
4074
- throw new Error(
4080
+ throw new ExpressionArgumentError(
4075
4081
  "merge: expected object, got " + (Array.isArray(obj1) ? "array" : typeof obj1)
4076
4082
  );
4077
4083
  }
4078
4084
  return { ...obj1 };
4079
4085
  }
4080
4086
  if (typeof obj1 !== "object") {
4081
- throw new Error("merge: expected object, got " + typeof obj1);
4087
+ throw new ExpressionArgumentError("merge: expected object, got " + typeof obj1);
4082
4088
  }
4083
4089
  if (typeof obj2 !== "object") {
4084
- throw new Error("merge: expected object, got " + typeof obj2);
4090
+ throw new ExpressionArgumentError("merge: expected object, got " + typeof obj2);
4085
4091
  }
4086
4092
  if (Array.isArray(obj1)) {
4087
- throw new Error("merge: expected object, got array for obj1");
4093
+ throw new ExpressionArgumentError("merge: expected object, got array for obj1");
4088
4094
  }
4089
4095
  if (Array.isArray(obj2)) {
4090
- throw new Error("merge: expected object, got array for obj2");
4096
+ throw new ExpressionArgumentError("merge: expected object, got array for obj2");
4091
4097
  }
4092
4098
  return {
4093
4099
  ...obj1,
@@ -4097,10 +4103,10 @@ function merge(obj1, obj2) {
4097
4103
  function nonNullKeys(obj) {
4098
4104
  if (obj == null) return [];
4099
4105
  if (typeof obj !== "object") {
4100
- throw new Error("nonNullKeys: expected object, got " + typeof obj);
4106
+ throw new ExpressionArgumentError("nonNullKeys: expected object, got " + typeof obj);
4101
4107
  }
4102
4108
  if (Array.isArray(obj)) {
4103
- throw new Error("nonNullKeys: expected object, got array");
4109
+ throw new ExpressionArgumentError("nonNullKeys: expected object, got array");
4104
4110
  }
4105
4111
  const result = [];
4106
4112
  for (const [key, value] of Object.entries(obj)) {
@@ -4181,7 +4187,7 @@ function toNumber(val) {
4181
4187
  }
4182
4188
  return parsed;
4183
4189
  }
4184
- throw new Error("toNumber: expected number or string, got " + typeof val);
4190
+ throw new ExpressionArgumentError("toNumber: expected number or string, got " + typeof val);
4185
4191
  }
4186
4192
  function toFigure(val) {
4187
4193
  if (typeof val === "number") return Number.isFinite(val) ? val : null;
@@ -4213,7 +4219,7 @@ function isEmpty(val) {
4213
4219
  function parseJson(value) {
4214
4220
  if (value == null) return null;
4215
4221
  if (typeof value !== "string") {
4216
- throw new Error("parseJson: expected a JSON string, got " + typeof value);
4222
+ throw new ExpressionArgumentError("parseJson: expected a JSON string, got " + typeof value);
4217
4223
  }
4218
4224
  try {
4219
4225
  return JSON.parse(value);
@@ -7145,7 +7151,7 @@ function validateOptionalTimezone(value, funcName) {
7145
7151
  function normalizeDateWithValidation(date2, timezone, funcName) {
7146
7152
  const normalized = normalizeDate(date2, timezone);
7147
7153
  if (isNaN(normalized.getTime())) {
7148
- throw new ExpressionArgumentError(`${funcName}: invalid date`);
7154
+ throw new ExpressionValueError(`${funcName}: invalid date`);
7149
7155
  }
7150
7156
  return normalized;
7151
7157
  }
@@ -7207,14 +7213,14 @@ function getDateExpressionFunctions(defaultTimezone, language) {
7207
7213
  if (typeof date2 === "string" && !hasTimezone(date2)) {
7208
7214
  const testDate = new Date(date2);
7209
7215
  if (isNaN(testDate.getTime())) {
7210
- throw new ExpressionArgumentError("formatDate: invalid date");
7216
+ throw new ExpressionValueError("formatDate: invalid date");
7211
7217
  }
7212
7218
  const iso = parseISO(date2);
7213
7219
  return format(isNaN(iso.getTime()) ? testDate : iso, formatStr);
7214
7220
  }
7215
7221
  const dateObj = date2 instanceof Date ? date2 : new Date(date2);
7216
7222
  if (isNaN(dateObj.getTime())) {
7217
- throw new ExpressionArgumentError("formatDate: invalid date");
7223
+ throw new ExpressionValueError("formatDate: invalid date");
7218
7224
  }
7219
7225
  if (tz) {
7220
7226
  const zonedDate = new TZDate(dateObj, tz);
@@ -7652,7 +7658,7 @@ function objectFromEntries(...args) {
7652
7658
  if (!Array.isArray(pair)) throw new ExpressionArgumentError("Object.fromEntries: every entry must be a [key, value] pair");
7653
7659
  const key = pair[0];
7654
7660
  const text2 = typeof key === "string" ? key : Array.isArray(key) ? textOf(key) : typeof key === "number" ? numberText(key) : String(key);
7655
- if (isReservedObjectKey(text2)) throw new ExpressionArgumentError(`Object.fromEntries: a key cannot be "${text2}"`);
7661
+ if (isReservedObjectKey(text2)) throw new ExpressionValueError(`Object.fromEntries: a key cannot be "${text2}"`);
7656
7662
  defineOwn(result, text2, pair[1] ?? null);
7657
7663
  }
7658
7664
  return result;
@@ -12165,6 +12171,7 @@ var BASE_OPERATIONS = ["empty", "filled", "percent_empty", "percent_filled", "un
12165
12171
  var NUMBER_AGGREGATE_OPERATIONS = [...BASE_OPERATIONS, "sum", "avg", "median", "min", "max", "range"];
12166
12172
  var DATE_AGGREGATE_OPERATIONS = [...BASE_OPERATIONS, "earliest", "latest", "date_range"];
12167
12173
  var SELECT_AGGREGATE_OPERATIONS = [...BASE_OPERATIONS, "selected"];
12174
+ var DERIVED_AGGREGATE_OPERATIONS = ["missing"];
12168
12175
  var BOOLEAN_AGGREGATE_OPERATIONS = ["checked", "unchecked", "percent_checked", "percent_unchecked"];
12169
12176
  var FORMULA_AGGREGATE_OPERATIONS = [...NUMBER_AGGREGATE_OPERATIONS, "earliest", "latest", "date_range", ...BOOLEAN_AGGREGATE_OPERATIONS];
12170
12177
  var ROLLUP_AGGREGATE_OPERATIONS = [...NUMBER_AGGREGATE_OPERATIONS, "earliest", "latest", "date_range"];
@@ -12190,12 +12197,16 @@ var AGGREGATE_OPERATIONS = [
12190
12197
  "percent_checked",
12191
12198
  "percent_unchecked",
12192
12199
  "selected",
12200
+ "missing",
12193
12201
  "string_agg"
12194
12202
  ];
12195
12203
  function isAggregateOperation(value) {
12196
12204
  return AGGREGATE_OPERATIONS.some((operation) => operation === value);
12197
12205
  }
12198
- var ACCUMULATING_OPERATIONS = /* @__PURE__ */ new Set(["sum", "count", "empty", "filled", "unique", "checked", "unchecked", "selected"]);
12206
+ function isDerivedAggregateOperation(operation) {
12207
+ return DERIVED_AGGREGATE_OPERATIONS.some((one) => one === operation);
12208
+ }
12209
+ var ACCUMULATING_OPERATIONS = /* @__PURE__ */ new Set(["sum", "count", "empty", "filled", "unique", "checked", "unchecked", "selected", "missing"]);
12199
12210
  function accumulates(operation) {
12200
12211
  return ACCUMULATING_OPERATIONS.has(operation);
12201
12212
  }
@@ -12728,11 +12739,14 @@ var OPERATION_FIELD_TYPES = {
12728
12739
  // absent, unlike every other row: a formula cell holds one scalar, so no
12729
12740
  // effective type ever resolves to this operation through one, and listing it
12730
12741
  // would put a case in `aggregateFormulaField` that nothing can reach.
12731
- selected: ["select", "select_member", "select_record_link", "files"]
12742
+ selected: ["select", "select_member", "select_record_link", "files"],
12743
+ // Derived (`DERIVED_AGGREGATE_OPERATIONS`): the one key a linked row holds, which a single select states.
12744
+ missing: ["select"]
12732
12745
  };
12733
12746
  var FIELD_TYPE_OPERATIONS = /* @__PURE__ */ new Map();
12734
12747
  for (const [operation, fieldTypes] of Object.entries(OPERATION_FIELD_TYPES)) {
12735
12748
  for (const ft of fieldTypes) {
12749
+ if (isDerivedAggregateOperation(operation)) continue;
12736
12750
  let ops = FIELD_TYPE_OPERATIONS.get(ft);
12737
12751
  if (!ops) {
12738
12752
  ops = [];
@@ -12973,13 +12987,13 @@ var MEASURED_UNITS = [
12973
12987
  { code: "kg", dimension: "mass", factor: 1e3, label: { vi: "kg", en: "kg" }, scales: true, spellings: ["kgs", "kilogram", "kilograms", "kilo", "k\xFD"] },
12974
12988
  { code: "t", dimension: "mass", factor: 1e6, label: { vi: "t\u1EA5n", en: "t" }, scales: true, spellings: ["ton", "tons", "tonne", "tonnes", "mt"] },
12975
12989
  { code: "l", dimension: "volume", factor: 1, label: { vi: "l\xEDt", en: "L" }, scales: true, spellings: ["liter", "liters", "litre", "litres"] },
12976
- { code: "m3", dimension: "volume", factor: 1e3, label: { vi: "m\xB3", en: "m\xB3" }, scales: true, spellings: ["kh\u1ED1i", "cubic meter", "cubic metre"] },
12990
+ { code: "m3", dimension: "volume", factor: 1e3, label: { vi: "m\xB3", en: "m\xB3" }, scales: true, spellings: ["kh\u1ED1i", "cubic meter", "cubic metre"], symbol: "m\xB3" },
12977
12991
  { code: "cbm", dimension: "volume", factor: 1e3, label: { vi: "CBM", en: "CBM" }, scales: false, spellings: [] },
12978
12992
  { code: "mm", dimension: "length", factor: 1, label: { vi: "mm", en: "mm" }, scales: true, spellings: ["millimeter", "millimetre", "milimet"] },
12979
12993
  { code: "cm", dimension: "length", factor: 10, label: { vi: "cm", en: "cm" }, scales: true, spellings: ["centimeter", "centimetre", "centimet"] },
12980
12994
  { code: "m", dimension: "length", factor: 1e3, label: { vi: "m", en: "m" }, scales: true, spellings: ["meter", "meters", "metre", "metres", "m\xE9t"] },
12981
12995
  { code: "km", dimension: "length", factor: 1e6, label: { vi: "km", en: "km" }, scales: true, spellings: ["kilometer", "kilometers", "kilometre", "kilometres", "kilomet", "c\xE2y s\u1ED1"] },
12982
- { code: "m2", dimension: "area", factor: 1, label: { vi: "m\xB2", en: "m\xB2" }, scales: true, spellings: ["sqm", "m\xE9t vu\xF4ng"] },
12996
+ { code: "m2", dimension: "area", factor: 1, label: { vi: "m\xB2", en: "m\xB2" }, scales: true, spellings: ["sqm", "m\xE9t vu\xF4ng"], symbol: "m\xB2" },
12983
12997
  { code: "min", dimension: "duration", factor: 1, label: { vi: "ph\xFAt", en: "min" }, scales: true, spellings: ["minute", "minutes", "mins"] },
12984
12998
  { code: "h", dimension: "duration", factor: 60, label: { vi: "gi\u1EDD", en: "h" }, scales: true, spellings: ["hour", "hours", "hr", "hrs", "ti\u1EBFng"] },
12985
12999
  { code: "day", dimension: "duration", factor: 1440, label: { vi: "ng\xE0y", en: "d" }, scales: false, spellings: ["days"] }
@@ -12997,7 +13011,7 @@ var SPELLED = new Map(
12997
13011
  )
12998
13012
  );
12999
13013
  function measuredUnit(unit) {
13000
- return unit == null ? void 0 : MEASURED_UNITS.find((one) => one.code === unit);
13014
+ return unit == null ? void 0 : MEASURED_UNITS.find((one) => one.code === unit || "symbol" in one && one.symbol === unit);
13001
13015
  }
13002
13016
  function convert(value, from, to) {
13003
13017
  return from.code === to.code ? value : divideDecimal(multiplyDecimal(value, from.factor), to.factor);
@@ -13018,8 +13032,12 @@ var SCALES = new Map(
13018
13032
 
13019
13033
  // ../shared/src/notation.ts
13020
13034
  var PERCENT = "percent";
13035
+ var MAX_DECIMALS = 6;
13036
+ function decimalsOf(notation) {
13037
+ return notation.decimals == null ? {} : { decimals: notation.decimals };
13038
+ }
13021
13039
  var DECIMAL = { style: "decimal" };
13022
- var NOTATION_DESCRIPTION = `How the figure reads: { "style": "decimal" }; money, { "style": "currency", "currency": an ISO 4217 code (USD, VND) }; or a quantity, { "style": "unit", "unit": "${PERCENT}" (10 reads "10%"), or ${UNIT_WORDS} }. A currency or unit read on each row from a single select of that row is { "per_row": that select }.`;
13040
+ var NOTATION_DESCRIPTION = `How the figure reads: { "style": "decimal" }; money, { "style": "currency", "currency": an ISO 4217 code (USD, VND) }; or a quantity, { "style": "unit", "unit": "${PERCENT}" (10 reads "10%"), or ${UNIT_WORDS} }. A currency or unit read on each row from a single select of that row is { "per_row": that select }. A decimal or a quantity states its places as "decimals" (0 to ${MAX_DECIMALS}): 1 reads 6 as "6,0".`;
13023
13041
  function notationOfKeys(keys2) {
13024
13042
  if (keys2.format === "currency") {
13025
13043
  return { style: "currency", currency: keys2.currency_field ? { per_row: keys2.currency_field } : keys2.currency || DEFAULT_CURRENCY };
@@ -13036,16 +13054,19 @@ function keysStated(keys2) {
13036
13054
  function sameValue(a, b) {
13037
13055
  return typeof a === "string" || typeof b === "string" ? a === b : a.per_row === b.per_row;
13038
13056
  }
13039
- function sameNotation(a, b) {
13057
+ function sameStyle(a, b) {
13040
13058
  if (a === void 0 || b === void 0) return a === b;
13041
13059
  if (a.style === "currency" && b.style === "currency") return sameValue(a.currency, b.currency);
13042
13060
  if (a.style === "unit" && b.style === "unit") return sameValue(a.unit, b.unit);
13043
13061
  return a.style === "decimal" && b.style === "decimal";
13044
13062
  }
13063
+ function sameNotation(a, b) {
13064
+ return sameStyle(a, b) && (a === void 0 || b === void 0 || decimalsOf(a).decimals === decimalsOf(b).decimals);
13065
+ }
13045
13066
  function storedNotation(notation, keys2) {
13046
13067
  if (notation == null) return notationOfKeys(keys2);
13047
13068
  if (!keysStated(keys2)) return notation;
13048
- const derived = notationOfKeys(keys2);
13069
+ const derived = { ...notationOfKeys(keys2), ...decimalsOf(notation) };
13049
13070
  return sameNotation(notation, derived) ? notation : derived;
13050
13071
  }
13051
13072
  function fieldNotation(field) {
@@ -13812,6 +13833,110 @@ function pickedFirst(a, b) {
13812
13833
  return a.id < b.id ? 1 : a.id > b.id ? -1 : 0;
13813
13834
  }
13814
13835
 
13836
+ // ../shared/src/expected_held.ts
13837
+ var nameOf2 = (option) => option.alias ?? option.key;
13838
+ function expectedKeys(options, of) {
13839
+ const named = of === void 0 ? void 0 : new Set(of.map(nameOf2));
13840
+ return options.filter((option) => named === void 0 || named.has(nameOf2(option))).map((option) => option.key);
13841
+ }
13842
+ function heldOptionOf(cell) {
13843
+ if (!Array.isArray(cell)) return void 0;
13844
+ const [first2] = cell;
13845
+ return typeof first2 === "string" ? first2 : void 0;
13846
+ }
13847
+ function missingKeys(expected, held2) {
13848
+ return expected.filter((key) => !held2.has(key));
13849
+ }
13850
+
13851
+ // ../shared/src/record_refs.ts
13852
+ var FIELD_NAME = /^[^.\s]+$/;
13853
+ function isRecordRef(value) {
13854
+ return typeof value === "object" && value !== null && !Array.isArray(value) && "record" in value;
13855
+ }
13856
+ var RecordRefError = class extends Error {
13857
+ constructor(message2) {
13858
+ super(message2);
13859
+ this.name = "RecordRefError";
13860
+ }
13861
+ };
13862
+ function recordRefName(ref) {
13863
+ if (typeof ref.record !== "string" || !FIELD_NAME.test(ref.record)) {
13864
+ return { refused: `\`record\` names a field of the row, "<field>" \u2014 a field of a linked row is read through a lookup of it on this row, never a path` };
13865
+ }
13866
+ return { field: ref.record };
13867
+ }
13868
+ function holdsRecordRef(filter2) {
13869
+ if (typeof filter2 !== "object" || filter2 === null) return false;
13870
+ const node = filter2;
13871
+ if (isRecordRef(node.value)) return true;
13872
+ return Array.isArray(node.children) && node.children.some(holdsRecordRef);
13873
+ }
13874
+ var TEXT_LISTS = /* @__PURE__ */ new Set(["is_any_of", "is_none_of", "contains_any_of"]);
13875
+ var MEMBERSHIP = new Set(LINK_MEMBERSHIP);
13876
+ var kindOf = (field) => resolveFilterType(field);
13877
+ function optionKeysOf(target, holder, keys2) {
13878
+ const byAlias = new Map(target.options.map((option) => [option.alias, option.key]));
13879
+ return keys2.flatMap((key) => {
13880
+ const alias = holder.options.find((option) => option.key === key)?.alias;
13881
+ const mapped = alias === void 0 ? void 0 : byAlias.get(alias);
13882
+ return mapped === void 0 ? [] : [mapped];
13883
+ });
13884
+ }
13885
+ function valueOfCell(target, holder, operator, cell) {
13886
+ const kind = kindOf(target);
13887
+ switch (kind) {
13888
+ case "text":
13889
+ if (typeof cell !== "string" || cell === "") return null;
13890
+ return TEXT_LISTS.has(operator) ? [cell] : cell;
13891
+ case "number":
13892
+ return typeof cell === "number" ? cell : null;
13893
+ case "boolean":
13894
+ return typeof cell === "boolean" ? cell : null;
13895
+ case "date": {
13896
+ if (typeof cell !== "string") return null;
13897
+ const [date2 = "", time] = cell.split("T");
13898
+ return date2.length === 10 ? { type: "exact", date: date2, time: time ?? null } : null;
13899
+ }
13900
+ case "select":
13901
+ case "select_member": {
13902
+ const held2 = Array.isArray(cell) ? cell.filter((one) => typeof one === "string") : [];
13903
+ const keys2 = target.type === "select" && holder.type === "select" ? optionKeysOf(target, holder, held2) : held2;
13904
+ return keys2.length === 0 ? null : keys2;
13905
+ }
13906
+ default: {
13907
+ const ids = extractRecordLinkIds(cell);
13908
+ return ids.length === 0 ? null : ids;
13909
+ }
13910
+ }
13911
+ }
13912
+ function bindRecordRefs(filter2, target, source) {
13913
+ const bind = (node) => {
13914
+ if (node.node_type === "group") {
13915
+ const children = node.children.map(bind);
13916
+ if (node.logic === "and") return children.some((child) => child === null) ? null : { ...node, children: children.filter((child) => child !== null) };
13917
+ const kept = children.filter((child) => child !== null);
13918
+ return kept.length === 0 && children.length > 0 ? null : { ...node, children: kept };
13919
+ }
13920
+ if (node.node_type === "traversal") {
13921
+ if (isRecordRef(node.condition.value)) throw new RecordRefError(`a condition on the row a link reaches cannot name a field of this row (${node.path.join(".")})`);
13922
+ return node;
13923
+ }
13924
+ if (!isRecordRef(node.value)) return node;
13925
+ return bindCondition(node, node.value);
13926
+ };
13927
+ const bindCondition = (node, ref) => {
13928
+ const named = recordRefName(ref);
13929
+ if ("refused" in named) throw new RecordRefError(named.refused);
13930
+ const field = node.field_key === void 0 ? void 0 : target.get(node.field_key);
13931
+ const held2 = source(named.field);
13932
+ if (field === void 0) throw new RecordRefError(`a condition names field "${String(node.field_key)}", which the table does not hold`);
13933
+ if (held2 === void 0) throw new RecordRefError(`"${named.field}" is no field of the row`);
13934
+ const value = valueOfCell(field, held2.field, node.operator, held2.cell);
13935
+ return value === null ? null : { ...node, value };
13936
+ };
13937
+ return bind(filter2);
13938
+ }
13939
+
13815
13940
  // ../shared/src/query_column_types.ts
13816
13941
  var QUERY_COLUMN_TYPES = [
13817
13942
  "text",
@@ -14222,6 +14347,10 @@ function computeFormulaFieldsWithContext(row2, fields, context, linkedTableRecor
14222
14347
  const computes = (key) => context.computedAggregates === void 0 || context.computedAggregates.has(key);
14223
14348
  for (const { field, sourceField } of context.rollupFields) {
14224
14349
  if (!computes(field.key) || !mayRecompute(sourceField.key)) continue;
14350
+ if (field.aggregate_option.operation === "missing") {
14351
+ result[field.key] = missingRollupValue(field, row2, fields, linkedTableRecords.get(sourceField.table_id), linkedTableFields.get(sourceField.table_id));
14352
+ continue;
14353
+ }
14225
14354
  if (linkedTableRecords.has(sourceField.table_id) && linkedTableFields.has(sourceField.table_id)) {
14226
14355
  const linkedRecords = linkedTableRecords.get(sourceField.table_id);
14227
14356
  const linkedTableFieldsArray = linkedTableFields.get(sourceField.table_id) ?? [];
@@ -14235,8 +14364,13 @@ function computeFormulaFieldsWithContext(row2, fields, context, linkedTableRecor
14235
14364
  result[field.key] = null;
14236
14365
  continue;
14237
14366
  }
14367
+ const filter2 = boundRollupFilter(field.filter, linkedTableFieldsArray, fields, row2);
14368
+ if (filter2 === null) {
14369
+ result[field.key] = rollupOverNothing(field.aggregate_option?.operation);
14370
+ continue;
14371
+ }
14238
14372
  const traversal = planFilterTraversal(
14239
- field.filter,
14373
+ filter2,
14240
14374
  sourceField.table_id,
14241
14375
  linkedTableFieldsArray,
14242
14376
  linkedTableRecords,
@@ -14256,7 +14390,7 @@ function computeFormulaFieldsWithContext(row2, fields, context, linkedTableRecor
14256
14390
  linkedFieldType?.type || "text",
14257
14391
  linkedRecords,
14258
14392
  field.aggregate_option,
14259
- field.filter,
14393
+ filter2,
14260
14394
  linkedTableFieldsArray,
14261
14395
  linkedFieldType ? {
14262
14396
  definition: `Rollup "${field.name}" (${field.key})`,
@@ -14521,27 +14655,33 @@ function readsAreAllEmpty(prepared, data) {
14521
14655
  }
14522
14656
  function evaluateFormulaWithJS(parsed, data, dates, everyReferenceEmpty) {
14523
14657
  try {
14524
- if (parsed.kind === "unparsable") throw parsed.error;
14525
- const scope = { ...timezoneAwareFunctions(dates.timezone, dates.language), ...formulaOnlyFunctions, data: data.data, names: data.names, [LOWERED_PLACES]: data.places ?? {} };
14526
- if (everyReferenceEmpty) {
14527
- const taken = (condition2) => {
14528
- const answer = condition2.evaluate(scope);
14529
- return typeof answer === "boolean" ? answer : void 0;
14530
- };
14531
- if (!readsFieldsOnlyThroughEmptinessPredicates(parsed.expression, taken)) return null;
14532
- }
14533
- const result = parsed.expression?.evaluate(scope);
14534
- if (result === null || result === void 0) {
14535
- return null;
14536
- }
14537
- if (typeof result === "number" || typeof result === "string" || typeof result === "boolean") {
14538
- return result;
14539
- }
14540
- return `${FORMULA_ERROR_PREFIX}Unexpected result type`;
14658
+ return runFormula(parsed, data, dates, everyReferenceEmpty);
14541
14659
  } catch (error) {
14542
- if (error instanceof UndeclaredOptionError) return `${FORMULA_ERROR_PREFIX}${error.message}`;
14543
- return `${FORMULA_ERROR_PREFIX}Formula evaluation error: ${error instanceof Error ? error.message : String(error)}`;
14660
+ return errorCell(error);
14661
+ }
14662
+ }
14663
+ function errorCell(error) {
14664
+ if (error instanceof UndeclaredOptionError) return `${FORMULA_ERROR_PREFIX}${error.message}`;
14665
+ return `${FORMULA_ERROR_PREFIX}Formula evaluation error: ${error instanceof Error ? error.message : String(error)}`;
14666
+ }
14667
+ function runFormula(parsed, data, dates, everyReferenceEmpty) {
14668
+ if (parsed.kind === "unparsable") throw parsed.error;
14669
+ const scope = { ...timezoneAwareFunctions(dates.timezone, dates.language), ...formulaOnlyFunctions, data: data.data, names: data.names, [LOWERED_PLACES]: data.places ?? {} };
14670
+ if (everyReferenceEmpty) {
14671
+ const taken = (condition2) => {
14672
+ const answer = condition2.evaluate(scope);
14673
+ return typeof answer === "boolean" ? answer : void 0;
14674
+ };
14675
+ if (!readsFieldsOnlyThroughEmptinessPredicates(parsed.expression, taken)) return null;
14676
+ }
14677
+ const result = parsed.expression?.evaluate(scope);
14678
+ if (result === null || result === void 0) {
14679
+ return null;
14680
+ }
14681
+ if (typeof result === "number" || typeof result === "string" || typeof result === "boolean") {
14682
+ return result;
14544
14683
  }
14684
+ return `${FORMULA_ERROR_PREFIX}Unexpected result type`;
14545
14685
  }
14546
14686
  function isRollupField(field) {
14547
14687
  return field.type === "rollup";
@@ -14607,9 +14747,44 @@ function linkedRowsNamed(table, ids) {
14607
14747
  const found = [...new Set(ids)].flatMap((id) => table.positions.get(id) ?? []);
14608
14748
  return found.sort((a, b) => a - b).map((at2) => table.rows[at2]);
14609
14749
  }
14750
+ var MissingRollupUnreadError = class extends Error {
14751
+ constructor(message2) {
14752
+ super(message2);
14753
+ this.name = "MissingRollupUnreadError";
14754
+ }
14755
+ };
14756
+ function missingRollupValue(field, row2, ownFields, linked, linkedFields) {
14757
+ const keyKey = field.aggregate_option.field_key ?? "";
14758
+ const keyField = linkedFields?.find((one) => one.key === keyKey);
14759
+ if (keyField?.type !== "select") {
14760
+ throw new MissingRollupUnreadError(`The missing roll-up "${field.key}" reads the single select "${keyKey}" of the table its link "${field.source_field_key}" points at, and this pass holds no such field of it`);
14761
+ }
14762
+ const linkCell = row2[field.source_field_key];
14763
+ const ids = Array.isArray(linkCell) ? extractRecordLinkIds(linkCell) : [];
14764
+ if (ids.length > 0 && linked === void 0) {
14765
+ throw new MissingRollupUnreadError(`The missing roll-up "${field.key}" counts the rows its link "${field.source_field_key}" names, and this pass did not load them`);
14766
+ }
14767
+ const of = field.of_field_key === void 0 ? void 0 : ownFields.find((one) => one.key === field.of_field_key);
14768
+ if (field.of_field_key !== void 0 && of?.type !== "select") {
14769
+ throw new MissingRollupUnreadError(`The missing roll-up "${field.key}" reads the multi-select "${field.of_field_key}" of its own table, and this pass holds no such field`);
14770
+ }
14771
+ const ofCell = of === void 0 ? void 0 : row2[of.key];
14772
+ const named = new Set(Array.isArray(ofCell) ? ofCell : []);
14773
+ const expected = expectedKeys(keyField.options, of?.type === "select" ? of.options.filter((option) => named.has(option.key)) : void 0);
14774
+ const holding = new Set(linked === void 0 ? [] : linkedRowsNamed(linked, ids).flatMap((one) => heldOptionOf(one.data[keyKey]) ?? []));
14775
+ return missingKeys(expected, holding).length;
14776
+ }
14610
14777
  function rollupOverNothing(operation) {
14611
14778
  return operation !== void 0 && accumulates(operation) ? 0 : null;
14612
14779
  }
14780
+ function boundRollupFilter(filter2, linkedFields, ownFields, row2) {
14781
+ if (filter2 === void 0 || !holdsRecordRef(filter2)) return filter2;
14782
+ const target = new Map(linkedFields.map((one) => [one.key, one]));
14783
+ return bindRecordRefs(filter2, target, (name) => {
14784
+ const field = ownFields.find((one) => one.key === name);
14785
+ return field === void 0 ? void 0 : { field, cell: row2[name] };
14786
+ });
14787
+ }
14613
14788
  function calculateRollupValue(value, fieldType, allLinkedTableRecords, aggregateOption, filter2, linkedTableFields, subject, traversalContext, fileFacts) {
14614
14789
  const operation = aggregateOption?.operation;
14615
14790
  const overNothing = rollupOverNothing(operation);
@@ -15152,7 +15327,7 @@ function overlayTotals(over, totals, admits, closed, rows) {
15152
15327
  }
15153
15328
  function totalsAsked(shape, aggregate) {
15154
15329
  const table = shape.rows?.table_id;
15155
- if (table === void 0 || aggregate.day !== void 0 || aggregate.avg !== void 0) return null;
15330
+ if (table === void 0 || aggregate.day !== void 0 || aggregate.avg !== void 0 || aggregate.max !== void 0 || aggregate.min !== void 0) return null;
15156
15331
  const by = (aggregate.by ?? []).map((column) => ({ output: column, field_key: fieldKeyOf(shape, column, table), tiers: aggregate.bands?.[column] }));
15157
15332
  const sum2 = aggregate.sum === void 0 ? void 0 : fieldKeyOf(shape, aggregate.sum, table);
15158
15333
  if (by.some((one) => one.field_key === void 0) || aggregate.sum !== void 0 && sum2 === void 0) return null;