@elaraai/east-ui-components 0.0.1-beta.17 → 0.0.1-beta.18

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.cjs CHANGED
@@ -543,7 +543,7 @@ var q = {
543
543
  }, Q = ["fa-classic", "fa-duotone", "fa-sharp", "fa-sharp-duotone", "fa-thumbprint", "fa-whiteboard", "fa-notdog", "fa-notdog-duo", "fa-chisel", "fa-etch", "fa-jelly", "fa-jelly-fill", "fa-jelly-duo", "fa-slab", "fa-slab-press", "fa-utility", "fa-utility-duo", "fa-utility-fill"];
544
544
  var i = "classic", t = "duotone", d = "sharp", l = "sharp-duotone", f = "chisel", n = "etch", h = "jelly", o = "jelly-duo", u = "jelly-fill", g = "notdog", s$1 = "notdog-duo", y$1 = "slab", m = "slab-press", e = "thumbprint", p = "utility", a$1 = "utility-duo", w = "utility-fill", x$1 = "whiteboard", b = "Classic", c$1 = "Duotone", I = "Sharp", F = "Sharp Duotone", v = "Chisel", S = "Etch", A = "Jelly", P$1 = "Jelly Duo", j = "Jelly Fill", B = "Notdog", N = "Notdog Duo", k$1 = "Slab", D = "Slab Press", T = "Thumbprint", C = "Utility", W = "Utility Duo", K = "Utility Fill", R = "Whiteboard", rt = [i, t, d, l, f, n, h, o, u, g, s$1, y$1, m, e, p, a$1, w, x$1];
545
545
  _dt = {}, _defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_dt, i, b), t, c$1), d, I), l, F), f, v), n, S), h, A), o, P$1), u, j), g, B), _defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_defineProperty$V(_dt, s$1, N), y$1, k$1), m, D), e, T), p, C), a$1, W), w, K), x$1, R);
546
- var gt = {
546
+ var gt$1 = {
547
547
  classic: {
548
548
  900: "fas",
549
549
  400: "far",
@@ -1158,7 +1158,7 @@ familyProxy(_LONG_STYLE_TO_PREFIX);
1158
1158
  var ICON_SELECTION_SYNTAX_PATTERN = E;
1159
1159
  var LAYERS_TEXT_CLASSNAME = "fa-layers-text";
1160
1160
  var FONT_FAMILY_PATTERN = _;
1161
- var _FONT_WEIGHT_TO_PREFIX = _objectSpread2({}, gt);
1161
+ var _FONT_WEIGHT_TO_PREFIX = _objectSpread2({}, gt$1);
1162
1162
  familyProxy(_FONT_WEIGHT_TO_PREFIX);
1163
1163
  var ATTRIBUTES_WATCHED_FOR_MUTATION = ["class", "data-prefix", "data-icon", "data-fa-transform", "data-fa-mask"];
1164
1164
  var DUOTONE_CLASSES = H;
@@ -20849,10 +20849,10 @@ function requireIsPrimitive() {
20849
20849
  })(isPrimitive);
20850
20850
  return isPrimitive;
20851
20851
  }
20852
- var eq = {};
20852
+ var eq$1 = {};
20853
20853
  var hasRequiredEq;
20854
20854
  function requireEq() {
20855
- if (hasRequiredEq) return eq;
20855
+ if (hasRequiredEq) return eq$1;
20856
20856
  hasRequiredEq = 1;
20857
20857
  (function(exports$1) {
20858
20858
  Object.defineProperty(exports$1, Symbol.toStringTag, { value: "Module" });
@@ -20860,8 +20860,8 @@ function requireEq() {
20860
20860
  return value === other || Number.isNaN(value) && Number.isNaN(other);
20861
20861
  }
20862
20862
  exports$1.eq = eq2;
20863
- })(eq);
20864
- return eq;
20863
+ })(eq$1);
20864
+ return eq$1;
20865
20865
  }
20866
20866
  var hasRequiredIsMatchWith;
20867
20867
  function requireIsMatchWith() {
@@ -34007,15 +34007,15 @@ var selectSmallestDistanceBetweenValues = createSelector(selectAllAppliedValues,
34007
34007
  if (sortedValues.length < 2) {
34008
34008
  return Infinity;
34009
34009
  }
34010
- var diff = sortedValues[sortedValues.length - 1] - sortedValues[0];
34011
- if (diff === 0) {
34010
+ var diff2 = sortedValues[sortedValues.length - 1] - sortedValues[0];
34011
+ if (diff2 === 0) {
34012
34012
  return Infinity;
34013
34013
  }
34014
34014
  for (var i2 = 0; i2 < sortedValues.length - 1; i2++) {
34015
34015
  var distance = sortedValues[i2 + 1] - sortedValues[i2];
34016
34016
  smallestDistanceBetweenValues = Math.min(smallestDistanceBetweenValues, distance);
34017
34017
  }
34018
- return smallestDistanceBetweenValues / diff;
34018
+ return smallestDistanceBetweenValues / diff2;
34019
34019
  });
34020
34020
  var selectCalculatedPadding = createSelector(selectSmallestDistanceBetweenValues, selectChartLayout, selectBarCategoryGap, selectChartOffsetInternal, (_1, _2, _3, padding) => padding, (smallestDistanceInPercent, layout, barCategoryGap, offset, padding) => {
34021
34021
  if (!isWellBehavedNumber(smallestDistanceInPercent)) {
@@ -53716,10 +53716,10 @@ const arrIncludesSome = (row, columnId, filterValue) => {
53716
53716
  });
53717
53717
  };
53718
53718
  arrIncludesSome.autoRemove = (val) => testFalsey(val) || !(val != null && val.length);
53719
- const equals = (row, columnId, filterValue) => {
53719
+ const equals$1 = (row, columnId, filterValue) => {
53720
53720
  return row.getValue(columnId) === filterValue;
53721
53721
  };
53722
- equals.autoRemove = (val) => testFalsey(val);
53722
+ equals$1.autoRemove = (val) => testFalsey(val);
53723
53723
  const weakEquals = (row, columnId, filterValue) => {
53724
53724
  return row.getValue(columnId) == filterValue;
53725
53725
  };
@@ -53750,7 +53750,7 @@ const filterFns = {
53750
53750
  arrIncludes,
53751
53751
  arrIncludesAll,
53752
53752
  arrIncludesSome,
53753
- equals,
53753
+ equals: equals$1,
53754
53754
  weakEquals,
53755
53755
  inNumberRange
53756
53756
  };
@@ -71247,6 +71247,28 @@ const Builtins = {
71247
71247
  inputs: ["T", "T"],
71248
71248
  output: BooleanType
71249
71249
  },
71250
+ // Patch operations - P is the computed PatchType passed from expression building
71251
+ // We use two type parameters because the patch type structure varies based on T
71252
+ Diff: {
71253
+ type_parameters: ["T", "P"],
71254
+ inputs: ["T", "T"],
71255
+ output: "P"
71256
+ },
71257
+ ApplyPatch: {
71258
+ type_parameters: ["T", "P"],
71259
+ inputs: ["T", "P"],
71260
+ output: "T"
71261
+ },
71262
+ ComposePatch: {
71263
+ type_parameters: ["T", "P"],
71264
+ inputs: ["P", "P"],
71265
+ output: "P"
71266
+ },
71267
+ InvertPatch: {
71268
+ type_parameters: ["T", "P"],
71269
+ inputs: ["P"],
71270
+ output: "P"
71271
+ },
71250
71272
  BooleanNot: {
71251
71273
  type_parameters: [],
71252
71274
  inputs: [BooleanType],
@@ -72723,6 +72745,17 @@ function valueOrExprToAstTyped(value, type, visited, location = get_location(2))
72723
72745
  class BooleanExpr extends Expr {
72724
72746
  constructor(ast, createExpr) {
72725
72747
  super(BooleanType, ast, createExpr);
72748
+ // ============================================================================
72749
+ // Aliases for comparison operations
72750
+ // ============================================================================
72751
+ /** Alias for {@link equals} */
72752
+ __publicField(this, "eq", this.equals);
72753
+ /** Alias for {@link equals} */
72754
+ __publicField(this, "equal", this.equals);
72755
+ /** Alias for {@link notEquals} */
72756
+ __publicField(this, "ne", this.notEquals);
72757
+ /** Alias for {@link notEquals} */
72758
+ __publicField(this, "notEqual", this.notEquals);
72726
72759
  }
72727
72760
  /**
72728
72761
  * Performs logical NOT operation (!x).
@@ -72993,6 +73026,58 @@ class BooleanExpr extends Expr {
72993
73026
  class IntegerExpr extends Expr {
72994
73027
  constructor(ast, createExpr) {
72995
73028
  super(IntegerType, ast, createExpr);
73029
+ // ============================================================================
73030
+ // Aliases for comparison operations
73031
+ // ============================================================================
73032
+ /** Alias for {@link equals} */
73033
+ __publicField(this, "eq", this.equals);
73034
+ /** Alias for {@link equals} */
73035
+ __publicField(this, "equal", this.equals);
73036
+ /** Alias for {@link notEquals} */
73037
+ __publicField(this, "ne", this.notEquals);
73038
+ /** Alias for {@link notEquals} */
73039
+ __publicField(this, "notEqual", this.notEquals);
73040
+ /** Alias for {@link greaterThan} */
73041
+ __publicField(this, "gt", this.greaterThan);
73042
+ /** Alias for {@link greaterThan} */
73043
+ __publicField(this, "greater", this.greaterThan);
73044
+ /** Alias for {@link lessThan} */
73045
+ __publicField(this, "lt", this.lessThan);
73046
+ /** Alias for {@link lessThan} */
73047
+ __publicField(this, "less", this.lessThan);
73048
+ /** Alias for {@link greaterThanOrEqual} */
73049
+ __publicField(this, "gte", this.greaterThanOrEqual);
73050
+ /** Alias for {@link greaterThanOrEqual} */
73051
+ __publicField(this, "ge", this.greaterThanOrEqual);
73052
+ /** Alias for {@link greaterThanOrEqual} */
73053
+ __publicField(this, "greaterEqual", this.greaterThanOrEqual);
73054
+ /** Alias for {@link lessThanOrEqual} */
73055
+ __publicField(this, "lte", this.lessThanOrEqual);
73056
+ /** Alias for {@link lessThanOrEqual} */
73057
+ __publicField(this, "le", this.lessThanOrEqual);
73058
+ /** Alias for {@link lessThanOrEqual} */
73059
+ __publicField(this, "lessEqual", this.lessThanOrEqual);
73060
+ // ============================================================================
73061
+ // Aliases for arithmetic operations
73062
+ // ============================================================================
73063
+ /** Alias for {@link add} */
73064
+ __publicField(this, "plus", this.add);
73065
+ /** Alias for {@link subtract} */
73066
+ __publicField(this, "sub", this.subtract);
73067
+ /** Alias for {@link subtract} */
73068
+ __publicField(this, "minus", this.subtract);
73069
+ /** Alias for {@link multiply} */
73070
+ __publicField(this, "mul", this.multiply);
73071
+ /** Alias for {@link multiply} */
73072
+ __publicField(this, "times", this.multiply);
73073
+ /** Alias for {@link divide} */
73074
+ __publicField(this, "div", this.divide);
73075
+ /** Alias for {@link remainder} */
73076
+ __publicField(this, "mod", this.remainder);
73077
+ /** Alias for {@link remainder} */
73078
+ __publicField(this, "rem", this.remainder);
73079
+ /** Alias for {@link remainder} */
73080
+ __publicField(this, "modulo", this.remainder);
72996
73081
  }
72997
73082
  /**
72998
73083
  * Negates an integer value (-x).
@@ -73384,6 +73469,58 @@ class IntegerExpr extends Expr {
73384
73469
  class FloatExpr extends Expr {
73385
73470
  constructor(ast, createExpr) {
73386
73471
  super(FloatType, ast, createExpr);
73472
+ // ============================================================================
73473
+ // Aliases for comparison operations
73474
+ // ============================================================================
73475
+ /** Alias for {@link equals} */
73476
+ __publicField(this, "eq", this.equals);
73477
+ /** Alias for {@link equals} */
73478
+ __publicField(this, "equal", this.equals);
73479
+ /** Alias for {@link notEquals} */
73480
+ __publicField(this, "ne", this.notEquals);
73481
+ /** Alias for {@link notEquals} */
73482
+ __publicField(this, "notEqual", this.notEquals);
73483
+ /** Alias for {@link greaterThan} */
73484
+ __publicField(this, "gt", this.greaterThan);
73485
+ /** Alias for {@link greaterThan} */
73486
+ __publicField(this, "greater", this.greaterThan);
73487
+ /** Alias for {@link lessThan} */
73488
+ __publicField(this, "lt", this.lessThan);
73489
+ /** Alias for {@link lessThan} */
73490
+ __publicField(this, "less", this.lessThan);
73491
+ /** Alias for {@link greaterThanOrEqual} */
73492
+ __publicField(this, "gte", this.greaterThanOrEqual);
73493
+ /** Alias for {@link greaterThanOrEqual} */
73494
+ __publicField(this, "ge", this.greaterThanOrEqual);
73495
+ /** Alias for {@link greaterThanOrEqual} */
73496
+ __publicField(this, "greaterEqual", this.greaterThanOrEqual);
73497
+ /** Alias for {@link lessThanOrEqual} */
73498
+ __publicField(this, "lte", this.lessThanOrEqual);
73499
+ /** Alias for {@link lessThanOrEqual} */
73500
+ __publicField(this, "le", this.lessThanOrEqual);
73501
+ /** Alias for {@link lessThanOrEqual} */
73502
+ __publicField(this, "lessEqual", this.lessThanOrEqual);
73503
+ // ============================================================================
73504
+ // Aliases for arithmetic operations
73505
+ // ============================================================================
73506
+ /** Alias for {@link add} */
73507
+ __publicField(this, "plus", this.add);
73508
+ /** Alias for {@link subtract} */
73509
+ __publicField(this, "sub", this.subtract);
73510
+ /** Alias for {@link subtract} */
73511
+ __publicField(this, "minus", this.subtract);
73512
+ /** Alias for {@link multiply} */
73513
+ __publicField(this, "mul", this.multiply);
73514
+ /** Alias for {@link multiply} */
73515
+ __publicField(this, "times", this.multiply);
73516
+ /** Alias for {@link divide} */
73517
+ __publicField(this, "div", this.divide);
73518
+ /** Alias for {@link remainder} */
73519
+ __publicField(this, "mod", this.remainder);
73520
+ /** Alias for {@link remainder} */
73521
+ __publicField(this, "rem", this.remainder);
73522
+ /** Alias for {@link remainder} */
73523
+ __publicField(this, "modulo", this.remainder);
73387
73524
  }
73388
73525
  /**
73389
73526
  * Negates a floating-point number (-x).
@@ -74169,6 +74306,37 @@ if ((typeof document === "undefined" ? require("url").pathToFileURL(__filename).
74169
74306
  class StringExpr extends Expr {
74170
74307
  constructor(ast, createExpr) {
74171
74308
  super(StringType, ast, createExpr);
74309
+ // ============================================================================
74310
+ // Aliases for comparison operations
74311
+ // ============================================================================
74312
+ /** Alias for {@link equals} */
74313
+ __publicField(this, "eq", this.equals);
74314
+ /** Alias for {@link equals} */
74315
+ __publicField(this, "equal", this.equals);
74316
+ /** Alias for {@link notEquals} */
74317
+ __publicField(this, "ne", this.notEquals);
74318
+ /** Alias for {@link notEquals} */
74319
+ __publicField(this, "notEqual", this.notEquals);
74320
+ /** Alias for {@link greaterThan} */
74321
+ __publicField(this, "gt", this.greaterThan);
74322
+ /** Alias for {@link greaterThan} */
74323
+ __publicField(this, "greater", this.greaterThan);
74324
+ /** Alias for {@link lessThan} */
74325
+ __publicField(this, "lt", this.lessThan);
74326
+ /** Alias for {@link lessThan} */
74327
+ __publicField(this, "less", this.lessThan);
74328
+ /** Alias for {@link greaterThanOrEqual} */
74329
+ __publicField(this, "gte", this.greaterThanOrEqual);
74330
+ /** Alias for {@link greaterThanOrEqual} */
74331
+ __publicField(this, "ge", this.greaterThanOrEqual);
74332
+ /** Alias for {@link greaterThanOrEqual} */
74333
+ __publicField(this, "greaterEqual", this.greaterThanOrEqual);
74334
+ /** Alias for {@link lessThanOrEqual} */
74335
+ __publicField(this, "lte", this.lessThanOrEqual);
74336
+ /** Alias for {@link lessThanOrEqual} */
74337
+ __publicField(this, "le", this.lessThanOrEqual);
74338
+ /** Alias for {@link lessThanOrEqual} */
74339
+ __publicField(this, "lessEqual", this.lessThanOrEqual);
74172
74340
  }
74173
74341
  /**
74174
74342
  * Parses a value of the given type from the string using East's canonical text format.
@@ -75006,6 +75174,37 @@ function tokenizeDateTimeFormat(format2) {
75006
75174
  class DateTimeExpr extends Expr {
75007
75175
  constructor(ast, createExpr) {
75008
75176
  super(DateTimeType, ast, createExpr);
75177
+ // ============================================================================
75178
+ // Aliases for comparison operations
75179
+ // ============================================================================
75180
+ /** Alias for {@link equals} */
75181
+ __publicField(this, "eq", this.equals);
75182
+ /** Alias for {@link equals} */
75183
+ __publicField(this, "equal", this.equals);
75184
+ /** Alias for {@link notEquals} */
75185
+ __publicField(this, "ne", this.notEquals);
75186
+ /** Alias for {@link notEquals} */
75187
+ __publicField(this, "notEqual", this.notEquals);
75188
+ /** Alias for {@link greaterThan} */
75189
+ __publicField(this, "gt", this.greaterThan);
75190
+ /** Alias for {@link greaterThan} */
75191
+ __publicField(this, "greater", this.greaterThan);
75192
+ /** Alias for {@link lessThan} */
75193
+ __publicField(this, "lt", this.lessThan);
75194
+ /** Alias for {@link lessThan} */
75195
+ __publicField(this, "less", this.lessThan);
75196
+ /** Alias for {@link greaterThanOrEqual} */
75197
+ __publicField(this, "gte", this.greaterThanOrEqual);
75198
+ /** Alias for {@link greaterThanOrEqual} */
75199
+ __publicField(this, "ge", this.greaterThanOrEqual);
75200
+ /** Alias for {@link greaterThanOrEqual} */
75201
+ __publicField(this, "greaterEqual", this.greaterThanOrEqual);
75202
+ /** Alias for {@link lessThanOrEqual} */
75203
+ __publicField(this, "lte", this.lessThanOrEqual);
75204
+ /** Alias for {@link lessThanOrEqual} */
75205
+ __publicField(this, "le", this.lessThanOrEqual);
75206
+ /** Alias for {@link lessThanOrEqual} */
75207
+ __publicField(this, "lessEqual", this.lessThanOrEqual);
75009
75208
  }
75010
75209
  /**
75011
75210
  * Extracts the year component from the DateTime.
@@ -77253,6 +77452,17 @@ function encodeCsvFor(structType, config2) {
77253
77452
  class BlobExpr extends Expr {
77254
77453
  constructor(ast, createExpr) {
77255
77454
  super(ast.type, ast, createExpr);
77455
+ // ============================================================================
77456
+ // Aliases for comparison operations
77457
+ // ============================================================================
77458
+ /** Alias for {@link equals} */
77459
+ __publicField(this, "eq", this.equals);
77460
+ /** Alias for {@link equals} */
77461
+ __publicField(this, "equal", this.equals);
77462
+ /** Alias for {@link notEquals} */
77463
+ __publicField(this, "ne", this.notEquals);
77464
+ /** Alias for {@link notEquals} */
77465
+ __publicField(this, "notEqual", this.notEquals);
77256
77466
  }
77257
77467
  /**
77258
77468
  * Returns the size of the blob in bytes.
@@ -77497,6 +77707,17 @@ class ArrayExpr extends Expr {
77497
77707
  constructor(value_type, ast, createExpr) {
77498
77708
  super(ast.type, ast, createExpr);
77499
77709
  __publicField(this, "value_type");
77710
+ // ============================================================================
77711
+ // Aliases for comparison operations
77712
+ // ============================================================================
77713
+ /** Alias for {@link equals} */
77714
+ __publicField(this, "eq", this.equals);
77715
+ /** Alias for {@link equals} */
77716
+ __publicField(this, "equal", this.equals);
77717
+ /** Alias for {@link notEquals} */
77718
+ __publicField(this, "ne", this.notEquals);
77719
+ /** Alias for {@link notEquals} */
77720
+ __publicField(this, "notEqual", this.notEquals);
77500
77721
  this.value_type = value_type;
77501
77722
  }
77502
77723
  /**
@@ -79342,6 +79563,17 @@ class SetExpr extends Expr {
79342
79563
  constructor(key_type, ast, createExpr) {
79343
79564
  super(ast.type, ast, createExpr);
79344
79565
  __publicField(this, "key_type");
79566
+ // ============================================================================
79567
+ // Aliases for comparison operations
79568
+ // ============================================================================
79569
+ /** Alias for {@link equals} */
79570
+ __publicField(this, "eq", this.equals);
79571
+ /** Alias for {@link equals} */
79572
+ __publicField(this, "equal", this.equals);
79573
+ /** Alias for {@link notEquals} */
79574
+ __publicField(this, "ne", this.notEquals);
79575
+ /** Alias for {@link notEquals} */
79576
+ __publicField(this, "notEqual", this.notEquals);
79345
79577
  this.key_type = key_type;
79346
79578
  }
79347
79579
  /**
@@ -80454,6 +80686,17 @@ class DictExpr extends Expr {
80454
80686
  super(ast.type, ast, createExpr);
80455
80687
  __publicField(this, "key_type");
80456
80688
  __publicField(this, "value_type");
80689
+ // ============================================================================
80690
+ // Aliases for comparison operations
80691
+ // ============================================================================
80692
+ /** Alias for {@link equals} */
80693
+ __publicField(this, "eq", this.equals);
80694
+ /** Alias for {@link equals} */
80695
+ __publicField(this, "equal", this.equals);
80696
+ /** Alias for {@link notEquals} */
80697
+ __publicField(this, "ne", this.notEquals);
80698
+ /** Alias for {@link notEquals} */
80699
+ __publicField(this, "notEqual", this.notEquals);
80457
80700
  this.key_type = key_type;
80458
80701
  this.value_type = value_type;
80459
80702
  }
@@ -81929,6 +82172,17 @@ class VariantExpr extends Expr {
81929
82172
  constructor(cases, ast, factory) {
81930
82173
  super(ast.type, ast, factory);
81931
82174
  __publicField(this, "cases");
82175
+ // ============================================================================
82176
+ // Aliases for comparison operations
82177
+ // ============================================================================
82178
+ /** Alias for {@link equals} */
82179
+ __publicField(this, "eq", this.equals);
82180
+ /** Alias for {@link equals} */
82181
+ __publicField(this, "equal", this.equals);
82182
+ /** Alias for {@link notEquals} */
82183
+ __publicField(this, "ne", this.notEquals);
82184
+ /** Alias for {@link notEquals} */
82185
+ __publicField(this, "notEqual", this.notEquals);
81932
82186
  this.cases = cases;
81933
82187
  }
81934
82188
  /**
@@ -82267,7 +82521,7 @@ function ast_to_ir(ast, ctx = { local_ctx: /* @__PURE__ */ new Map(), parent_ctx
82267
82521
  throw new Error(`Builtin ${builtin_name} with type parameters [${ast.type_parameters.map((tp) => printType(tp)).join(", ")}] argument ${i2} of type ${printType(arg.type)} is not compatible with expected type ${printType(expectedType)} at ${printLocation(ast.location)}`);
82268
82522
  }
82269
82523
  arg_ir = variant("As", {
82270
- type: toEastTypeValue(arg.type),
82524
+ type: toEastTypeValue(expectedType),
82271
82525
  value: arg_ir,
82272
82526
  location: toLocationValue(ast.location)
82273
82527
  });
@@ -82999,6 +83253,318 @@ function ast_to_ir(ast, ctx = { local_ctx: /* @__PURE__ */ new Map(), parent_ctx
82999
83253
  throw e3;
83000
83254
  }
83001
83255
  }
83256
+ class ConflictError extends Error {
83257
+ constructor(message) {
83258
+ super(message);
83259
+ this.name = "ConflictError";
83260
+ }
83261
+ }
83262
+ function computeLCS(before, after, equal2) {
83263
+ const m2 = before.length;
83264
+ const n2 = after.length;
83265
+ const dp = Array.from({ length: m2 + 1 }, () => Array(n2 + 1).fill(0));
83266
+ for (let i3 = 1; i3 <= m2; i3++) {
83267
+ for (let j3 = 1; j3 <= n2; j3++) {
83268
+ if (equal2(before[i3 - 1], after[j3 - 1])) {
83269
+ dp[i3][j3] = dp[i3 - 1][j3 - 1] + 1;
83270
+ } else {
83271
+ dp[i3][j3] = Math.max(dp[i3 - 1][j3], dp[i3][j3 - 1]);
83272
+ }
83273
+ }
83274
+ }
83275
+ const beforeIndices = [];
83276
+ const afterIndices = [];
83277
+ let i2 = m2;
83278
+ let j2 = n2;
83279
+ while (i2 > 0 && j2 > 0) {
83280
+ if (equal2(before[i2 - 1], after[j2 - 1])) {
83281
+ beforeIndices.unshift(i2 - 1);
83282
+ afterIndices.unshift(j2 - 1);
83283
+ i2--;
83284
+ j2--;
83285
+ } else if (dp[i2 - 1][j2] > dp[i2][j2 - 1]) {
83286
+ i2--;
83287
+ } else {
83288
+ j2--;
83289
+ }
83290
+ }
83291
+ return { beforeIndices, afterIndices };
83292
+ }
83293
+ function diffFor(type, ctx = { diff: [], types: [], equal: [] }) {
83294
+ const t2 = isVariant(type) ? type : toEastTypeValue(type);
83295
+ if (t2.type === "Never") {
83296
+ return (_before, _after) => {
83297
+ throw new Error("Cannot diff values of type Never");
83298
+ };
83299
+ } else if (t2.type === "Null" || t2.type === "Boolean" || t2.type === "Integer" || t2.type === "Float" || t2.type === "String" || t2.type === "DateTime" || t2.type === "Blob") {
83300
+ const equal2 = equalFor(t2);
83301
+ return (before, after) => {
83302
+ if (equal2(before, after)) {
83303
+ return variant("unchanged", null);
83304
+ }
83305
+ return variant("replace", { before, after });
83306
+ };
83307
+ } else if (t2.type === "Array") {
83308
+ let elementEqual;
83309
+ let is2;
83310
+ const ret = (before, after) => {
83311
+ if (is2(before, after)) {
83312
+ return variant("unchanged", null);
83313
+ }
83314
+ const { beforeIndices, afterIndices } = computeLCS(before, after, elementEqual);
83315
+ const operations = [];
83316
+ let beforePtr = 0;
83317
+ let afterPtr = 0;
83318
+ let lcsPtr = 0;
83319
+ let deleteCount = 0;
83320
+ let insertCount = 0;
83321
+ while (beforePtr < before.length || afterPtr < after.length) {
83322
+ const nextBeforeLCS = lcsPtr < beforeIndices.length ? beforeIndices[lcsPtr] : before.length;
83323
+ const nextAfterLCS = lcsPtr < afterIndices.length ? afterIndices[lcsPtr] : after.length;
83324
+ while (beforePtr < nextBeforeLCS) {
83325
+ const actualPosition = beforePtr - deleteCount + insertCount;
83326
+ operations.push({
83327
+ key: BigInt(actualPosition),
83328
+ offset: 0n,
83329
+ operation: variant("delete", before[beforePtr])
83330
+ });
83331
+ deleteCount++;
83332
+ beforePtr++;
83333
+ }
83334
+ while (afterPtr < nextAfterLCS) {
83335
+ operations.push({
83336
+ key: BigInt(afterPtr),
83337
+ offset: 0n,
83338
+ operation: variant("insert", after[afterPtr])
83339
+ });
83340
+ insertCount++;
83341
+ afterPtr++;
83342
+ }
83343
+ if (lcsPtr < beforeIndices.length) {
83344
+ beforePtr++;
83345
+ afterPtr++;
83346
+ lcsPtr++;
83347
+ }
83348
+ }
83349
+ if (operations.length === 0) {
83350
+ return variant("unchanged", null);
83351
+ }
83352
+ return variant("patch", operations);
83353
+ };
83354
+ const arrayEqual = equalFor(t2, ctx.equal);
83355
+ ctx.diff.push(ret);
83356
+ ctx.types.push(t2);
83357
+ ctx.equal.push(arrayEqual);
83358
+ is2 = isFor(t2, ctx.equal);
83359
+ elementEqual = equalFor(t2.value, ctx.equal);
83360
+ ctx.diff.pop();
83361
+ ctx.types.pop();
83362
+ ctx.equal.pop();
83363
+ return ret;
83364
+ } else if (t2.type === "Set") {
83365
+ const is2 = isFor(t2);
83366
+ const keyCompare = compareFor(t2.value);
83367
+ return (before, after) => {
83368
+ if (is2(before, after)) {
83369
+ return variant("unchanged", null);
83370
+ }
83371
+ const operations = new SortedMap(void 0, keyCompare);
83372
+ for (const key of before) {
83373
+ if (!after.has(key)) {
83374
+ operations.set(key, variant("delete", null));
83375
+ }
83376
+ }
83377
+ for (const key of after) {
83378
+ if (!before.has(key)) {
83379
+ operations.set(key, variant("insert", null));
83380
+ }
83381
+ }
83382
+ if (operations.size === 0) {
83383
+ return variant("unchanged", null);
83384
+ }
83385
+ let deleteCount = 0;
83386
+ let insertCount = 0;
83387
+ for (const op of operations.values()) {
83388
+ if (op.type === "delete")
83389
+ deleteCount++;
83390
+ if (op.type === "insert")
83391
+ insertCount++;
83392
+ }
83393
+ if (deleteCount === before.size && insertCount === after.size && before.size > 0) {
83394
+ return variant("replace", { before, after });
83395
+ }
83396
+ return variant("patch", operations);
83397
+ };
83398
+ } else if (t2.type === "Dict") {
83399
+ let valueDiff;
83400
+ let valueEqual;
83401
+ let is2;
83402
+ const keyCompare = compareFor(t2.value.key);
83403
+ const ret = (before, after) => {
83404
+ if (is2(before, after)) {
83405
+ return variant("unchanged", null);
83406
+ }
83407
+ const operations = new SortedMap(void 0, keyCompare);
83408
+ for (const [key, beforeValue] of before) {
83409
+ if (!after.has(key)) {
83410
+ operations.set(key, variant("delete", beforeValue));
83411
+ } else {
83412
+ const afterValue = after.get(key);
83413
+ if (!valueEqual(beforeValue, afterValue)) {
83414
+ const patch = valueDiff(beforeValue, afterValue);
83415
+ operations.set(key, variant("update", patch));
83416
+ }
83417
+ }
83418
+ }
83419
+ for (const [key, afterValue] of after) {
83420
+ if (!before.has(key)) {
83421
+ operations.set(key, variant("insert", afterValue));
83422
+ }
83423
+ }
83424
+ if (operations.size === 0) {
83425
+ return variant("unchanged", null);
83426
+ }
83427
+ let insertCount = 0;
83428
+ let deleteCount = 0;
83429
+ for (const op of operations.values()) {
83430
+ if (op.type === "insert")
83431
+ insertCount++;
83432
+ if (op.type === "delete")
83433
+ deleteCount++;
83434
+ }
83435
+ if (insertCount === after.size && deleteCount === before.size && before.size > 0) {
83436
+ return variant("replace", { before, after });
83437
+ }
83438
+ return variant("patch", operations);
83439
+ };
83440
+ const dictEqual = equalFor(t2, ctx.equal);
83441
+ ctx.diff.push(ret);
83442
+ ctx.types.push(t2);
83443
+ ctx.equal.push(dictEqual);
83444
+ is2 = isFor(t2, ctx.equal);
83445
+ valueDiff = diffFor(t2.value.value, ctx);
83446
+ valueEqual = equalFor(t2.value.value, ctx.equal);
83447
+ ctx.diff.pop();
83448
+ ctx.types.pop();
83449
+ ctx.equal.pop();
83450
+ return ret;
83451
+ } else if (t2.type === "Struct") {
83452
+ const fieldDiffs = {};
83453
+ const fieldEquals = {};
83454
+ const ret = (before, after) => {
83455
+ if (before === after) {
83456
+ return variant("unchanged", null);
83457
+ }
83458
+ const patchFields = {};
83459
+ let allUnchanged = true;
83460
+ for (const { name } of t2.value) {
83461
+ const beforeValue = before[name];
83462
+ const afterValue = after[name];
83463
+ if (fieldEquals[name](beforeValue, afterValue)) {
83464
+ patchFields[name] = variant("unchanged", null);
83465
+ } else {
83466
+ patchFields[name] = fieldDiffs[name](beforeValue, afterValue);
83467
+ allUnchanged = false;
83468
+ }
83469
+ }
83470
+ if (allUnchanged) {
83471
+ return variant("unchanged", null);
83472
+ }
83473
+ return variant("patch", patchFields);
83474
+ };
83475
+ const structEqual = equalFor(t2, ctx.equal);
83476
+ ctx.diff.push(ret);
83477
+ ctx.types.push(t2);
83478
+ ctx.equal.push(structEqual);
83479
+ for (const { name, type: fieldType } of t2.value) {
83480
+ fieldDiffs[name] = diffFor(fieldType, ctx);
83481
+ fieldEquals[name] = equalFor(fieldType, ctx.equal);
83482
+ }
83483
+ ctx.diff.pop();
83484
+ ctx.types.pop();
83485
+ ctx.equal.pop();
83486
+ return ret;
83487
+ } else if (t2.type === "Variant") {
83488
+ const caseDiffs = {};
83489
+ const caseEquals = {};
83490
+ const ret = (before, after) => {
83491
+ if (before === after) {
83492
+ return variant("unchanged", null);
83493
+ }
83494
+ if (before.type !== after.type) {
83495
+ return variant("replace", { before, after });
83496
+ }
83497
+ const caseName = before.type;
83498
+ if (caseEquals[caseName](before.value, after.value)) {
83499
+ return variant("unchanged", null);
83500
+ }
83501
+ const casePatch = caseDiffs[caseName](before.value, after.value);
83502
+ if (casePatch.type === "unchanged") {
83503
+ return variant("unchanged", null);
83504
+ }
83505
+ return variant("patch", variant(caseName, casePatch));
83506
+ };
83507
+ const variantEqual = equalFor(t2, ctx.equal);
83508
+ ctx.diff.push(ret);
83509
+ ctx.types.push(t2);
83510
+ ctx.equal.push(variantEqual);
83511
+ for (const { name, type: caseType } of t2.value) {
83512
+ caseDiffs[name] = diffFor(caseType, ctx);
83513
+ caseEquals[name] = equalFor(caseType, ctx.equal);
83514
+ }
83515
+ ctx.diff.pop();
83516
+ ctx.types.pop();
83517
+ ctx.equal.pop();
83518
+ return ret;
83519
+ } else if (t2.type === "Ref") {
83520
+ let innerDiff;
83521
+ let innerEqual;
83522
+ let is2;
83523
+ const ret = (before, after) => {
83524
+ if (is2(before, after)) {
83525
+ return variant("unchanged", null);
83526
+ }
83527
+ if (innerEqual(before.value, after.value)) {
83528
+ return variant("unchanged", null);
83529
+ }
83530
+ const innerPatch = innerDiff(before.value, after.value);
83531
+ if (innerPatch.type === "unchanged") {
83532
+ return variant("unchanged", null);
83533
+ }
83534
+ return variant("patch", innerPatch);
83535
+ };
83536
+ const refEqual = equalFor(t2, ctx.equal);
83537
+ ctx.diff.push(ret);
83538
+ ctx.types.push(t2);
83539
+ ctx.equal.push(refEqual);
83540
+ is2 = isFor(t2, ctx.equal);
83541
+ innerDiff = diffFor(t2.value, ctx);
83542
+ innerEqual = equalFor(t2.value, ctx.equal);
83543
+ ctx.diff.pop();
83544
+ ctx.types.pop();
83545
+ ctx.equal.pop();
83546
+ return ret;
83547
+ } else if (t2.type === "Recursive") {
83548
+ const resolvedType = ctx.types[ctx.types.length - Number(t2.value)];
83549
+ if (resolvedType === void 0) {
83550
+ throw new Error(`Internal error: Recursive type context not found in diffFor`);
83551
+ }
83552
+ const equal2 = ctx.equal[ctx.equal.length - Number(t2.value)];
83553
+ if (equal2 === void 0) {
83554
+ throw new Error(`Internal error: Recursive equal context not found in diffFor`);
83555
+ }
83556
+ return (before, after) => {
83557
+ if (equal2(before, after)) {
83558
+ return variant("unchanged", null);
83559
+ }
83560
+ return variant("replace", { before, after });
83561
+ };
83562
+ } else if (t2.type === "Function" || t2.type === "AsyncFunction") {
83563
+ return (_before, _after) => variant("unchanged", null);
83564
+ } else {
83565
+ throw new Error(`Unhandled type in diffFor: ${t2.type}`);
83566
+ }
83567
+ }
83002
83568
  class ParseError extends Error {
83003
83569
  constructor(message, position, path = "") {
83004
83570
  super(message);
@@ -84065,6 +84631,1007 @@ const createVariantParser = (cases, frozen, typeCtx) => {
84065
84631
  typeCtx.pop();
84066
84632
  return ret;
84067
84633
  };
84634
+ function applyFor(type, ctx = { apply: [], types: [], equal: [], print: [] }) {
84635
+ const t2 = isVariant(type) ? type : toEastTypeValue(type);
84636
+ if (t2.type === "Never") {
84637
+ return (_base, _patch) => {
84638
+ throw new Error("Cannot apply patch to values of type Never");
84639
+ };
84640
+ } else if (t2.type === "Null" || t2.type === "Boolean" || t2.type === "Integer" || t2.type === "Float" || t2.type === "String" || t2.type === "DateTime" || t2.type === "Blob") {
84641
+ const equal2 = equalFor(t2);
84642
+ const print2 = printFor(t2);
84643
+ return (base, patch) => {
84644
+ if (patch.type === "unchanged") {
84645
+ return base;
84646
+ } else if (patch.type === "replace") {
84647
+ if (!equal2(base, patch.value.before)) {
84648
+ throw new ConflictError(`Cannot apply replace - expected ${print2(patch.value.before)}, found ${print2(base)}`);
84649
+ }
84650
+ return patch.value.after;
84651
+ } else {
84652
+ throw new Error(`Invalid patch type for primitive: ${patch.type}`);
84653
+ }
84654
+ };
84655
+ } else if (t2.type === "Array") {
84656
+ let elementApply;
84657
+ let elementEqual;
84658
+ let elementPrint;
84659
+ let arrayEqual;
84660
+ const ret = (base, patch) => {
84661
+ if (patch.type === "unchanged") {
84662
+ return base;
84663
+ } else if (patch.type === "replace") {
84664
+ if (!arrayEqual(base, patch.value.before)) {
84665
+ throw new ConflictError("Cannot apply replace - base array does not match expected");
84666
+ }
84667
+ return [...patch.value.after];
84668
+ } else if (patch.type === "patch") {
84669
+ const result = [...base];
84670
+ const operations = patch.value;
84671
+ for (const op of operations) {
84672
+ const key = Number(op.key);
84673
+ const offset = Number(op.offset);
84674
+ const oldKey = key + offset;
84675
+ if (op.operation.type === "delete") {
84676
+ if (oldKey < 0 || oldKey >= result.length) {
84677
+ throw new ConflictError(`Cannot delete at index ${oldKey} - array length is ${result.length}`);
84678
+ }
84679
+ if (!elementEqual(result[oldKey], op.operation.value)) {
84680
+ throw new ConflictError(`Cannot delete at index ${oldKey} - expected ${elementPrint(op.operation.value)}, found ${elementPrint(result[oldKey])}`);
84681
+ }
84682
+ result.splice(oldKey, 1);
84683
+ } else if (op.operation.type === "insert") {
84684
+ if (key < 0 || key > result.length) {
84685
+ throw new ConflictError(`Cannot insert at index ${key} - array length is ${result.length}`);
84686
+ }
84687
+ result.splice(key, 0, op.operation.value);
84688
+ } else if (op.operation.type === "update") {
84689
+ if (oldKey < 0 || oldKey >= result.length) {
84690
+ throw new ConflictError(`Cannot update at index ${oldKey} - array length is ${result.length}`);
84691
+ }
84692
+ result[oldKey] = elementApply(result[oldKey], op.operation.value);
84693
+ }
84694
+ }
84695
+ return result;
84696
+ } else {
84697
+ throw new Error(`Invalid patch type for array: ${patch.type}`);
84698
+ }
84699
+ };
84700
+ const arrayPrint = printFor(t2, ctx.print);
84701
+ arrayEqual = equalFor(t2, ctx.equal);
84702
+ ctx.apply.push(ret);
84703
+ ctx.types.push(t2);
84704
+ ctx.equal.push(arrayEqual);
84705
+ ctx.print.push(arrayPrint);
84706
+ elementApply = applyFor(t2.value, ctx);
84707
+ elementEqual = equalFor(t2.value, ctx.equal);
84708
+ elementPrint = printFor(t2.value, ctx.print);
84709
+ ctx.apply.pop();
84710
+ ctx.types.pop();
84711
+ ctx.equal.pop();
84712
+ ctx.print.pop();
84713
+ return ret;
84714
+ } else if (t2.type === "Set") {
84715
+ const keyPrint = printFor(t2.value);
84716
+ const setEqual = equalFor(t2, ctx.equal);
84717
+ const keyCompare = compareFor(t2.value);
84718
+ return (base, patch) => {
84719
+ if (patch.type === "unchanged") {
84720
+ return base;
84721
+ } else if (patch.type === "replace") {
84722
+ if (!setEqual(base, patch.value.before)) {
84723
+ throw new ConflictError("Cannot apply replace - base set does not match expected");
84724
+ }
84725
+ return new SortedSet(patch.value.after, keyCompare);
84726
+ } else if (patch.type === "patch") {
84727
+ const result = new SortedSet(base, keyCompare);
84728
+ const operations = patch.value;
84729
+ for (const [key, op] of operations) {
84730
+ if (op.type === "delete") {
84731
+ if (!result.has(key)) {
84732
+ throw new ConflictError(`Cannot delete key ${keyPrint(key)} - key does not exist`);
84733
+ }
84734
+ result.delete(key);
84735
+ } else if (op.type === "insert") {
84736
+ if (result.has(key)) {
84737
+ throw new ConflictError(`Cannot insert key ${keyPrint(key)} - key already exists`);
84738
+ }
84739
+ result.add(key);
84740
+ }
84741
+ }
84742
+ return result;
84743
+ } else {
84744
+ throw new Error(`Invalid patch type for set: ${patch.type}`);
84745
+ }
84746
+ };
84747
+ } else if (t2.type === "Dict") {
84748
+ let valueApply;
84749
+ let valueEqual;
84750
+ let dictEqual;
84751
+ let keyPrint;
84752
+ let valuePrint;
84753
+ const keyCompare = compareFor(t2.value.key);
84754
+ const ret = (base, patch) => {
84755
+ if (patch.type === "unchanged") {
84756
+ return base;
84757
+ } else if (patch.type === "replace") {
84758
+ if (!dictEqual(base, patch.value.before)) {
84759
+ throw new ConflictError("Cannot apply replace - base dict does not match expected");
84760
+ }
84761
+ return new SortedMap(patch.value.after, keyCompare);
84762
+ } else if (patch.type === "patch") {
84763
+ const result = new SortedMap(base, keyCompare);
84764
+ const operations = patch.value;
84765
+ for (const [key, op] of operations) {
84766
+ if (op.type === "delete") {
84767
+ if (!result.has(key)) {
84768
+ throw new ConflictError(`Cannot delete key ${keyPrint(key)} - key does not exist`);
84769
+ }
84770
+ if (!valueEqual(result.get(key), op.value)) {
84771
+ throw new ConflictError(`Cannot delete key ${keyPrint(key)} - expected value ${valuePrint(op.value)}, found ${valuePrint(result.get(key))}`);
84772
+ }
84773
+ result.delete(key);
84774
+ } else if (op.type === "insert") {
84775
+ if (result.has(key)) {
84776
+ throw new ConflictError(`Cannot insert key ${keyPrint(key)} - key already exists with value ${valuePrint(result.get(key))}`);
84777
+ }
84778
+ result.set(key, op.value);
84779
+ } else if (op.type === "update") {
84780
+ if (!result.has(key)) {
84781
+ throw new ConflictError(`Cannot update key ${keyPrint(key)} - key does not exist`);
84782
+ }
84783
+ result.set(key, valueApply(result.get(key), op.value));
84784
+ }
84785
+ }
84786
+ return result;
84787
+ } else {
84788
+ throw new Error(`Invalid patch type for dict: ${patch.type}`);
84789
+ }
84790
+ };
84791
+ const dictPrint = printFor(t2, ctx.print);
84792
+ dictEqual = equalFor(t2, ctx.equal);
84793
+ ctx.apply.push(ret);
84794
+ ctx.types.push(t2);
84795
+ ctx.equal.push(dictEqual);
84796
+ ctx.print.push(dictPrint);
84797
+ valueApply = applyFor(t2.value.value, ctx);
84798
+ valueEqual = equalFor(t2.value.value, ctx.equal);
84799
+ keyPrint = printFor(t2.value.key);
84800
+ valuePrint = printFor(t2.value.value, ctx.print);
84801
+ ctx.apply.pop();
84802
+ ctx.types.pop();
84803
+ ctx.equal.pop();
84804
+ ctx.print.pop();
84805
+ return ret;
84806
+ } else if (t2.type === "Struct") {
84807
+ const fieldApplies = {};
84808
+ let equal2;
84809
+ const ret = (base, patch) => {
84810
+ if (patch.type === "unchanged") {
84811
+ return base;
84812
+ } else if (patch.type === "replace") {
84813
+ if (!equal2(base, patch.value.before)) {
84814
+ throw new ConflictError("Cannot apply replace - base struct does not match expected");
84815
+ }
84816
+ return { ...patch.value.after };
84817
+ } else if (patch.type === "patch") {
84818
+ const result = {};
84819
+ for (const { name } of t2.value) {
84820
+ const fieldPatch = patch.value[name];
84821
+ result[name] = fieldApplies[name](base[name], fieldPatch);
84822
+ }
84823
+ return result;
84824
+ } else {
84825
+ throw new Error(`Invalid patch type for struct: ${patch.type}`);
84826
+ }
84827
+ };
84828
+ const structPrint = printFor(t2, ctx.print);
84829
+ equal2 = equalFor(t2, ctx.equal);
84830
+ ctx.apply.push(ret);
84831
+ ctx.types.push(t2);
84832
+ ctx.equal.push(equal2);
84833
+ ctx.print.push(structPrint);
84834
+ for (const { name, type: fieldType } of t2.value) {
84835
+ fieldApplies[name] = applyFor(fieldType, ctx);
84836
+ }
84837
+ ctx.apply.pop();
84838
+ ctx.types.pop();
84839
+ ctx.equal.pop();
84840
+ ctx.print.pop();
84841
+ return ret;
84842
+ } else if (t2.type === "Variant") {
84843
+ const caseApplies = {};
84844
+ let equal2;
84845
+ const ret = (base, patch) => {
84846
+ if (patch.type === "unchanged") {
84847
+ return base;
84848
+ } else if (patch.type === "replace") {
84849
+ if (!equal2(base, patch.value.before)) {
84850
+ throw new ConflictError("Cannot apply replace - base variant does not match expected");
84851
+ }
84852
+ return patch.value.after;
84853
+ } else if (patch.type === "patch") {
84854
+ const caseName = patch.value.type;
84855
+ if (base.type !== caseName) {
84856
+ throw new ConflictError(`Cannot apply patch for case ${caseName} to variant with case ${base.type}`);
84857
+ }
84858
+ const casePatch = patch.value.value;
84859
+ const newValue = caseApplies[caseName](base.value, casePatch);
84860
+ return variant(caseName, newValue);
84861
+ } else {
84862
+ throw new Error(`Invalid patch type for variant: ${patch.type}`);
84863
+ }
84864
+ };
84865
+ const variantPrint = printFor(t2, ctx.print);
84866
+ equal2 = equalFor(t2, ctx.equal);
84867
+ ctx.apply.push(ret);
84868
+ ctx.types.push(t2);
84869
+ ctx.equal.push(equal2);
84870
+ ctx.print.push(variantPrint);
84871
+ for (const { name, type: caseType } of t2.value) {
84872
+ caseApplies[name] = applyFor(caseType, ctx);
84873
+ }
84874
+ ctx.apply.pop();
84875
+ ctx.types.pop();
84876
+ ctx.equal.pop();
84877
+ ctx.print.pop();
84878
+ return ret;
84879
+ } else if (t2.type === "Ref") {
84880
+ let innerApply;
84881
+ let equal2;
84882
+ const ret = (base, patch) => {
84883
+ if (patch.type === "unchanged") {
84884
+ return base;
84885
+ } else if (patch.type === "replace") {
84886
+ if (!equal2(base, patch.value.before)) {
84887
+ throw new ConflictError("Cannot apply replace - base ref does not match expected");
84888
+ }
84889
+ return { value: patch.value.after.value };
84890
+ } else if (patch.type === "patch") {
84891
+ const newValue = innerApply(base.value, patch.value);
84892
+ return { value: newValue };
84893
+ } else {
84894
+ throw new Error(`Invalid patch type for ref: ${patch.type}`);
84895
+ }
84896
+ };
84897
+ const refPrint = printFor(t2, ctx.print);
84898
+ equal2 = equalFor(t2, ctx.equal);
84899
+ ctx.apply.push(ret);
84900
+ ctx.types.push(t2);
84901
+ ctx.equal.push(equal2);
84902
+ ctx.print.push(refPrint);
84903
+ innerApply = applyFor(t2.value, ctx);
84904
+ ctx.apply.pop();
84905
+ ctx.types.pop();
84906
+ ctx.equal.pop();
84907
+ ctx.print.pop();
84908
+ return ret;
84909
+ } else if (t2.type === "Recursive") {
84910
+ return (base, patch) => {
84911
+ if (patch.type === "unchanged") {
84912
+ return base;
84913
+ } else if (patch.type === "replace") {
84914
+ return patch.value.after;
84915
+ } else {
84916
+ throw new Error(`Invalid patch type for recursive type: ${patch.type}`);
84917
+ }
84918
+ };
84919
+ } else if (t2.type === "Function" || t2.type === "AsyncFunction") {
84920
+ return (base, patch) => {
84921
+ if (patch.type === "unchanged") {
84922
+ return base;
84923
+ } else if (patch.type === "replace") {
84924
+ return patch.value.after;
84925
+ } else {
84926
+ throw new Error(`Invalid patch type for function: ${patch.type}`);
84927
+ }
84928
+ };
84929
+ } else {
84930
+ throw new Error(`Unhandled type in applyFor: ${t2.type}`);
84931
+ }
84932
+ }
84933
+ function invertFor(type, ctx = { invert: [], types: [], equal: [] }) {
84934
+ const t2 = isVariant(type) ? type : toEastTypeValue(type);
84935
+ if (t2.type === "Never") {
84936
+ return (_patch) => {
84937
+ throw new Error("Cannot invert patches for type Never");
84938
+ };
84939
+ } else if (t2.type === "Null" || t2.type === "Boolean" || t2.type === "Integer" || t2.type === "Float" || t2.type === "String" || t2.type === "DateTime" || t2.type === "Blob") {
84940
+ return (patch) => {
84941
+ if (patch.type === "unchanged") {
84942
+ return patch;
84943
+ } else if (patch.type === "replace") {
84944
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
84945
+ } else {
84946
+ throw new Error(`Invalid patch type for primitive inversion: ${patch.type}`);
84947
+ }
84948
+ };
84949
+ } else if (t2.type === "Array") {
84950
+ let elementInvert;
84951
+ const ret = (patch) => {
84952
+ if (patch.type === "unchanged") {
84953
+ return patch;
84954
+ } else if (patch.type === "replace") {
84955
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
84956
+ } else if (patch.type === "patch") {
84957
+ const operations = patch.value;
84958
+ const inverted = [];
84959
+ for (let i2 = operations.length - 1; i2 >= 0; i2--) {
84960
+ const op = operations[i2];
84961
+ if (op.operation.type === "delete") {
84962
+ inverted.push({
84963
+ key: op.key,
84964
+ offset: 0n,
84965
+ operation: variant("insert", op.operation.value)
84966
+ });
84967
+ } else if (op.operation.type === "insert") {
84968
+ inverted.push({
84969
+ key: op.key,
84970
+ offset: 0n,
84971
+ operation: variant("delete", op.operation.value)
84972
+ });
84973
+ } else if (op.operation.type === "update") {
84974
+ inverted.push({
84975
+ key: op.key,
84976
+ offset: 0n,
84977
+ operation: variant("update", elementInvert(op.operation.value))
84978
+ });
84979
+ }
84980
+ }
84981
+ return variant("patch", inverted);
84982
+ } else {
84983
+ throw new Error(`Invalid patch type for array inversion: ${patch.type}`);
84984
+ }
84985
+ };
84986
+ const arrayEqual = equalFor(t2, ctx.equal);
84987
+ ctx.invert.push(ret);
84988
+ ctx.types.push(t2);
84989
+ ctx.equal.push(arrayEqual);
84990
+ elementInvert = invertFor(t2.value, ctx);
84991
+ ctx.invert.pop();
84992
+ ctx.types.pop();
84993
+ ctx.equal.pop();
84994
+ return ret;
84995
+ } else if (t2.type === "Set") {
84996
+ const keyCompare = compareFor(t2.value);
84997
+ return (patch) => {
84998
+ if (patch.type === "unchanged") {
84999
+ return patch;
85000
+ } else if (patch.type === "replace") {
85001
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
85002
+ } else if (patch.type === "patch") {
85003
+ const operations = patch.value;
85004
+ const inverted = new SortedMap(void 0, keyCompare);
85005
+ for (const [key, op] of operations) {
85006
+ if (op.type === "delete") {
85007
+ inverted.set(key, variant("insert", null));
85008
+ } else if (op.type === "insert") {
85009
+ inverted.set(key, variant("delete", null));
85010
+ }
85011
+ }
85012
+ return variant("patch", inverted);
85013
+ } else {
85014
+ throw new Error(`Invalid patch type for set inversion: ${patch.type}`);
85015
+ }
85016
+ };
85017
+ } else if (t2.type === "Dict") {
85018
+ let valueInvert;
85019
+ const keyCompare = compareFor(t2.value.key);
85020
+ const ret = (patch) => {
85021
+ if (patch.type === "unchanged") {
85022
+ return patch;
85023
+ } else if (patch.type === "replace") {
85024
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
85025
+ } else if (patch.type === "patch") {
85026
+ const operations = patch.value;
85027
+ const inverted = new SortedMap(void 0, keyCompare);
85028
+ for (const [key, op] of operations) {
85029
+ if (op.type === "delete") {
85030
+ inverted.set(key, variant("insert", op.value));
85031
+ } else if (op.type === "insert") {
85032
+ inverted.set(key, variant("delete", op.value));
85033
+ } else if (op.type === "update") {
85034
+ inverted.set(key, variant("update", valueInvert(op.value)));
85035
+ }
85036
+ }
85037
+ return variant("patch", inverted);
85038
+ } else {
85039
+ throw new Error(`Invalid patch type for dict inversion: ${patch.type}`);
85040
+ }
85041
+ };
85042
+ const dictEqual = equalFor(t2, ctx.equal);
85043
+ ctx.invert.push(ret);
85044
+ ctx.types.push(t2);
85045
+ ctx.equal.push(dictEqual);
85046
+ valueInvert = invertFor(t2.value.value, ctx);
85047
+ ctx.invert.pop();
85048
+ ctx.types.pop();
85049
+ ctx.equal.pop();
85050
+ return ret;
85051
+ } else if (t2.type === "Struct") {
85052
+ const fieldInverts = {};
85053
+ const ret = (patch) => {
85054
+ if (patch.type === "unchanged") {
85055
+ return patch;
85056
+ } else if (patch.type === "replace") {
85057
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
85058
+ } else if (patch.type === "patch") {
85059
+ const result = {};
85060
+ let allUnchanged = true;
85061
+ for (const { name } of t2.value) {
85062
+ const inverted = fieldInverts[name](patch.value[name]);
85063
+ result[name] = inverted;
85064
+ if (inverted.type !== "unchanged") {
85065
+ allUnchanged = false;
85066
+ }
85067
+ }
85068
+ if (allUnchanged) {
85069
+ return variant("unchanged", null);
85070
+ }
85071
+ return variant("patch", result);
85072
+ } else {
85073
+ throw new Error(`Invalid patch type for struct inversion: ${patch.type}`);
85074
+ }
85075
+ };
85076
+ const structEqual = equalFor(t2, ctx.equal);
85077
+ ctx.invert.push(ret);
85078
+ ctx.types.push(t2);
85079
+ ctx.equal.push(structEqual);
85080
+ for (const { name, type: fieldType } of t2.value) {
85081
+ fieldInverts[name] = invertFor(fieldType, ctx);
85082
+ }
85083
+ ctx.invert.pop();
85084
+ ctx.types.pop();
85085
+ ctx.equal.pop();
85086
+ return ret;
85087
+ } else if (t2.type === "Variant") {
85088
+ const caseInverts = {};
85089
+ const ret = (patch) => {
85090
+ if (patch.type === "unchanged") {
85091
+ return patch;
85092
+ } else if (patch.type === "replace") {
85093
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
85094
+ } else if (patch.type === "patch") {
85095
+ const caseName = patch.value.type;
85096
+ const inverted = caseInverts[caseName](patch.value.value);
85097
+ if (inverted.type === "unchanged") {
85098
+ return variant("unchanged", null);
85099
+ }
85100
+ return variant("patch", variant(caseName, inverted));
85101
+ } else {
85102
+ throw new Error(`Invalid patch type for variant inversion: ${patch.type}`);
85103
+ }
85104
+ };
85105
+ const variantEqual = equalFor(t2, ctx.equal);
85106
+ ctx.invert.push(ret);
85107
+ ctx.types.push(t2);
85108
+ ctx.equal.push(variantEqual);
85109
+ for (const { name, type: caseType } of t2.value) {
85110
+ caseInverts[name] = invertFor(caseType, ctx);
85111
+ }
85112
+ ctx.invert.pop();
85113
+ ctx.types.pop();
85114
+ ctx.equal.pop();
85115
+ return ret;
85116
+ } else if (t2.type === "Ref") {
85117
+ let innerInvert;
85118
+ const ret = (patch) => {
85119
+ if (patch.type === "unchanged") {
85120
+ return patch;
85121
+ } else if (patch.type === "replace") {
85122
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
85123
+ } else if (patch.type === "patch") {
85124
+ const inverted = innerInvert(patch.value);
85125
+ if (inverted.type === "unchanged") {
85126
+ return variant("unchanged", null);
85127
+ }
85128
+ return variant("patch", inverted);
85129
+ } else {
85130
+ throw new Error(`Invalid patch type for ref inversion: ${patch.type}`);
85131
+ }
85132
+ };
85133
+ const refEqual = equalFor(t2, ctx.equal);
85134
+ ctx.invert.push(ret);
85135
+ ctx.types.push(t2);
85136
+ ctx.equal.push(refEqual);
85137
+ innerInvert = invertFor(t2.value, ctx);
85138
+ ctx.invert.pop();
85139
+ ctx.types.pop();
85140
+ ctx.equal.pop();
85141
+ return ret;
85142
+ } else if (t2.type === "Recursive") {
85143
+ return (patch) => {
85144
+ if (patch.type === "unchanged") {
85145
+ return patch;
85146
+ } else if (patch.type === "replace") {
85147
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
85148
+ } else {
85149
+ throw new Error(`Invalid patch type for recursive type inversion: ${patch.type}`);
85150
+ }
85151
+ };
85152
+ } else if (t2.type === "Function" || t2.type === "AsyncFunction") {
85153
+ return (patch) => {
85154
+ if (patch.type === "unchanged") {
85155
+ return patch;
85156
+ } else if (patch.type === "replace") {
85157
+ return variant("replace", { before: patch.value.after, after: patch.value.before });
85158
+ } else {
85159
+ throw new Error(`Invalid patch type for function inversion: ${patch.type}`);
85160
+ }
85161
+ };
85162
+ } else {
85163
+ throw new Error(`Unhandled type in invertFor: ${t2.type}`);
85164
+ }
85165
+ }
85166
+ function composeFor(type, ctx = { compose: [], apply: [], invert: [], types: [], equal: [], print: [] }) {
85167
+ const t2 = isVariant(type) ? type : toEastTypeValue(type);
85168
+ if (t2.type === "Never") {
85169
+ return (_first, _second) => {
85170
+ throw new Error("Cannot compose patches for type Never");
85171
+ };
85172
+ } else if (t2.type === "Null" || t2.type === "Boolean" || t2.type === "Integer" || t2.type === "Float" || t2.type === "String" || t2.type === "DateTime" || t2.type === "Blob") {
85173
+ return (first, second2) => {
85174
+ if (first.type === "unchanged") {
85175
+ return second2;
85176
+ } else if (second2.type === "unchanged") {
85177
+ return first;
85178
+ } else if (first.type === "replace" && second2.type === "replace") {
85179
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85180
+ } else {
85181
+ throw new Error("Invalid patch composition for primitive");
85182
+ }
85183
+ };
85184
+ } else if (t2.type === "Array") {
85185
+ let applyRet;
85186
+ let invertRet;
85187
+ const composeRet = (first, second2) => {
85188
+ if (first.type === "unchanged") {
85189
+ return second2;
85190
+ } else if (second2.type === "unchanged") {
85191
+ return first;
85192
+ } else if (first.type === "replace" && second2.type === "replace") {
85193
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85194
+ } else if (first.type === "replace" && second2.type === "patch") {
85195
+ const afterSecond = applyRet(first.value.after, second2);
85196
+ return variant("replace", { before: first.value.before, after: afterSecond });
85197
+ } else if (first.type === "patch" && second2.type === "replace") {
85198
+ const invertedFirst = invertRet(first);
85199
+ const originalBefore = applyRet(second2.value.before, invertedFirst);
85200
+ return variant("replace", { before: originalBefore, after: second2.value.after });
85201
+ } else {
85202
+ const p1Ops = first.value;
85203
+ const p2Ops = second2.value;
85204
+ const result = [...p1Ops, ...p2Ops];
85205
+ if (result.length === 0) {
85206
+ return variant("unchanged", null);
85207
+ }
85208
+ return variant("patch", result);
85209
+ }
85210
+ };
85211
+ const arrayEqual = equalFor(t2, ctx.equal);
85212
+ const arrayPrint = printFor(t2, ctx.print);
85213
+ ctx.compose.push(composeRet);
85214
+ ctx.types.push(t2);
85215
+ ctx.equal.push(arrayEqual);
85216
+ ctx.print.push(arrayPrint);
85217
+ applyRet = applyFor(t2, { apply: ctx.apply, types: ctx.types, equal: ctx.equal, print: ctx.print });
85218
+ invertRet = invertFor(t2, { invert: ctx.invert, types: ctx.types, equal: ctx.equal });
85219
+ ctx.apply.push(applyRet);
85220
+ ctx.invert.push(invertRet);
85221
+ composeFor(t2.value, ctx);
85222
+ ctx.compose.pop();
85223
+ ctx.apply.pop();
85224
+ ctx.invert.pop();
85225
+ ctx.types.pop();
85226
+ ctx.equal.pop();
85227
+ ctx.print.pop();
85228
+ return composeRet;
85229
+ } else if (t2.type === "Set") {
85230
+ const keyPrint = printFor(t2.value);
85231
+ const keyCompare = compareFor(t2.value);
85232
+ const apply = applyFor(t2, { apply: ctx.apply, types: ctx.types, equal: ctx.equal, print: ctx.print });
85233
+ const invert = invertFor(t2, { invert: ctx.invert, types: ctx.types, equal: ctx.equal });
85234
+ return (first, second2) => {
85235
+ if (first.type === "unchanged") {
85236
+ return second2;
85237
+ } else if (second2.type === "unchanged") {
85238
+ return first;
85239
+ } else if (first.type === "replace" && second2.type === "replace") {
85240
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85241
+ } else if (first.type === "patch" && second2.type === "patch") {
85242
+ const result = new SortedMap(void 0, keyCompare);
85243
+ for (const [key, op] of first.value) {
85244
+ result.set(key, op);
85245
+ }
85246
+ for (const [key, op] of second2.value) {
85247
+ if (result.has(key)) {
85248
+ const firstOp = result.get(key);
85249
+ if (firstOp.type === "insert" && op.type === "delete") {
85250
+ result.delete(key);
85251
+ } else if (firstOp.type === "delete" && op.type === "insert") {
85252
+ result.delete(key);
85253
+ } else {
85254
+ throw new ConflictError(`Cannot compose patches - conflicting operations on key ${keyPrint(key)}`);
85255
+ }
85256
+ } else {
85257
+ result.set(key, op);
85258
+ }
85259
+ }
85260
+ if (result.size === 0) {
85261
+ return variant("unchanged", null);
85262
+ }
85263
+ return variant("patch", result);
85264
+ } else {
85265
+ if (first.type === "replace") {
85266
+ const afterSecond = apply(first.value.after, second2);
85267
+ return variant("replace", { before: first.value.before, after: afterSecond });
85268
+ } else {
85269
+ const invertedFirst = invert(first);
85270
+ const originalBefore = apply(second2.value.before, invertedFirst);
85271
+ return variant("replace", { before: originalBefore, after: second2.value.after });
85272
+ }
85273
+ }
85274
+ };
85275
+ } else if (t2.type === "Dict") {
85276
+ let valueCompose;
85277
+ let valueApply;
85278
+ let applyRet;
85279
+ let invertRet;
85280
+ const keyPrint = printFor(t2.value.key);
85281
+ const keyCompare = compareFor(t2.value.key);
85282
+ const composeRet = (first, second2) => {
85283
+ if (first.type === "unchanged") {
85284
+ return second2;
85285
+ } else if (second2.type === "unchanged") {
85286
+ return first;
85287
+ } else if (first.type === "replace" && second2.type === "replace") {
85288
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85289
+ } else if (first.type === "patch" && second2.type === "patch") {
85290
+ const result = new SortedMap(void 0, keyCompare);
85291
+ for (const [key, op] of first.value) {
85292
+ result.set(key, op);
85293
+ }
85294
+ for (const [key, op] of second2.value) {
85295
+ if (result.has(key)) {
85296
+ const firstOp = result.get(key);
85297
+ if (firstOp.type === "insert" && op.type === "delete") {
85298
+ result.delete(key);
85299
+ } else if (firstOp.type === "insert" && op.type === "update") {
85300
+ const newValue = valueApply(firstOp.value, op.value);
85301
+ result.set(key, variant("insert", newValue));
85302
+ } else if (firstOp.type === "delete" && op.type === "insert") {
85303
+ result.set(key, variant("update", variant("replace", { before: firstOp.value, after: op.value })));
85304
+ } else if (firstOp.type === "update" && op.type === "delete") {
85305
+ throw new ConflictError(`Cannot compose patches - update then delete on key ${keyPrint(key)}`);
85306
+ } else if (firstOp.type === "update" && op.type === "update") {
85307
+ const composed = valueCompose(firstOp.value, op.value);
85308
+ result.set(key, variant("update", composed));
85309
+ } else {
85310
+ throw new ConflictError(`Cannot compose patches - conflicting operations on key ${keyPrint(key)}`);
85311
+ }
85312
+ } else {
85313
+ result.set(key, op);
85314
+ }
85315
+ }
85316
+ if (result.size === 0) {
85317
+ return variant("unchanged", null);
85318
+ }
85319
+ return variant("patch", result);
85320
+ } else {
85321
+ if (first.type === "replace") {
85322
+ const afterSecond = applyRet(first.value.after, second2);
85323
+ return variant("replace", { before: first.value.before, after: afterSecond });
85324
+ } else {
85325
+ const invertedFirst = invertRet(first);
85326
+ const originalBefore = applyRet(second2.value.before, invertedFirst);
85327
+ return variant("replace", { before: originalBefore, after: second2.value.after });
85328
+ }
85329
+ }
85330
+ };
85331
+ const dictPrint = printFor(t2, ctx.print);
85332
+ const dictEqual = equalFor(t2, ctx.equal);
85333
+ ctx.compose.push(composeRet);
85334
+ ctx.types.push(t2);
85335
+ ctx.equal.push(dictEqual);
85336
+ ctx.print.push(dictPrint);
85337
+ applyRet = applyFor(t2, { apply: ctx.apply, types: ctx.types, equal: ctx.equal, print: ctx.print });
85338
+ invertRet = invertFor(t2, { invert: ctx.invert, types: ctx.types, equal: ctx.equal });
85339
+ ctx.apply.push(applyRet);
85340
+ ctx.invert.push(invertRet);
85341
+ valueCompose = composeFor(t2.value.value, ctx);
85342
+ valueApply = applyFor(t2.value.value, { apply: ctx.apply, types: ctx.types, equal: ctx.equal, print: ctx.print });
85343
+ ctx.compose.pop();
85344
+ ctx.apply.pop();
85345
+ ctx.invert.pop();
85346
+ ctx.types.pop();
85347
+ ctx.equal.pop();
85348
+ ctx.print.pop();
85349
+ return composeRet;
85350
+ } else if (t2.type === "Struct") {
85351
+ const fieldComposes = {};
85352
+ let applyRet;
85353
+ let invertRet;
85354
+ const composeRet = (first, second2) => {
85355
+ if (first.type === "unchanged") {
85356
+ return second2;
85357
+ } else if (second2.type === "unchanged") {
85358
+ return first;
85359
+ } else if (first.type === "replace" && second2.type === "replace") {
85360
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85361
+ } else if (first.type === "patch" && second2.type === "patch") {
85362
+ const result = {};
85363
+ let allUnchanged = true;
85364
+ for (const { name } of t2.value) {
85365
+ const composed = fieldComposes[name](first.value[name], second2.value[name]);
85366
+ result[name] = composed;
85367
+ if (composed.type !== "unchanged") {
85368
+ allUnchanged = false;
85369
+ }
85370
+ }
85371
+ if (allUnchanged) {
85372
+ return variant("unchanged", null);
85373
+ }
85374
+ return variant("patch", result);
85375
+ } else {
85376
+ if (first.type === "replace") {
85377
+ const afterSecond = applyRet(first.value.after, second2);
85378
+ return variant("replace", { before: first.value.before, after: afterSecond });
85379
+ } else {
85380
+ const invertedFirst = invertRet(first);
85381
+ const originalBefore = applyRet(second2.value.before, invertedFirst);
85382
+ return variant("replace", { before: originalBefore, after: second2.value.after });
85383
+ }
85384
+ }
85385
+ };
85386
+ const structEqual = equalFor(t2, ctx.equal);
85387
+ const structPrint = printFor(t2, ctx.print);
85388
+ ctx.compose.push(composeRet);
85389
+ ctx.types.push(t2);
85390
+ ctx.equal.push(structEqual);
85391
+ ctx.print.push(structPrint);
85392
+ applyRet = applyFor(t2, { apply: ctx.apply, types: ctx.types, equal: ctx.equal, print: ctx.print });
85393
+ invertRet = invertFor(t2, { invert: ctx.invert, types: ctx.types, equal: ctx.equal });
85394
+ ctx.apply.push(applyRet);
85395
+ ctx.invert.push(invertRet);
85396
+ for (const { name, type: fieldType } of t2.value) {
85397
+ fieldComposes[name] = composeFor(fieldType, ctx);
85398
+ }
85399
+ ctx.compose.pop();
85400
+ ctx.apply.pop();
85401
+ ctx.invert.pop();
85402
+ ctx.types.pop();
85403
+ ctx.equal.pop();
85404
+ ctx.print.pop();
85405
+ return composeRet;
85406
+ } else if (t2.type === "Variant") {
85407
+ const caseComposes = {};
85408
+ let applyRet;
85409
+ let invertRet;
85410
+ const composeRet = (first, second2) => {
85411
+ if (first.type === "unchanged") {
85412
+ return second2;
85413
+ } else if (second2.type === "unchanged") {
85414
+ return first;
85415
+ } else if (first.type === "replace" && second2.type === "replace") {
85416
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85417
+ } else if (first.type === "patch" && second2.type === "patch") {
85418
+ if (first.value.type !== second2.value.type) {
85419
+ throw new ConflictError(`Cannot compose variant patches for different cases: ${first.value.type} and ${second2.value.type}`);
85420
+ }
85421
+ const caseName = first.value.type;
85422
+ const composed = caseComposes[caseName](first.value.value, second2.value.value);
85423
+ if (composed.type === "unchanged") {
85424
+ return variant("unchanged", null);
85425
+ }
85426
+ return variant("patch", variant(caseName, composed));
85427
+ } else {
85428
+ if (first.type === "replace") {
85429
+ const afterSecond = applyRet(first.value.after, second2);
85430
+ return variant("replace", { before: first.value.before, after: afterSecond });
85431
+ } else {
85432
+ const invertedFirst = invertRet(first);
85433
+ const originalBefore = applyRet(second2.value.before, invertedFirst);
85434
+ return variant("replace", { before: originalBefore, after: second2.value.after });
85435
+ }
85436
+ }
85437
+ };
85438
+ const variantEqual = equalFor(t2, ctx.equal);
85439
+ const variantPrint = printFor(t2, ctx.print);
85440
+ ctx.compose.push(composeRet);
85441
+ ctx.types.push(t2);
85442
+ ctx.equal.push(variantEqual);
85443
+ ctx.print.push(variantPrint);
85444
+ applyRet = applyFor(t2, { apply: ctx.apply, types: ctx.types, equal: ctx.equal, print: ctx.print });
85445
+ invertRet = invertFor(t2, { invert: ctx.invert, types: ctx.types, equal: ctx.equal });
85446
+ ctx.apply.push(applyRet);
85447
+ ctx.invert.push(invertRet);
85448
+ for (const { name, type: caseType } of t2.value) {
85449
+ caseComposes[name] = composeFor(caseType, ctx);
85450
+ }
85451
+ ctx.compose.pop();
85452
+ ctx.apply.pop();
85453
+ ctx.invert.pop();
85454
+ ctx.types.pop();
85455
+ ctx.equal.pop();
85456
+ ctx.print.pop();
85457
+ return composeRet;
85458
+ } else if (t2.type === "Ref") {
85459
+ let innerCompose;
85460
+ let applyRet;
85461
+ let invertRet;
85462
+ const composeRet = (first, second2) => {
85463
+ if (first.type === "unchanged") {
85464
+ return second2;
85465
+ } else if (second2.type === "unchanged") {
85466
+ return first;
85467
+ } else if (first.type === "replace" && second2.type === "replace") {
85468
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85469
+ } else if (first.type === "patch" && second2.type === "patch") {
85470
+ const composed = innerCompose(first.value, second2.value);
85471
+ if (composed.type === "unchanged") {
85472
+ return variant("unchanged", null);
85473
+ }
85474
+ return variant("patch", composed);
85475
+ } else {
85476
+ if (first.type === "replace") {
85477
+ const afterSecond = applyRet(first.value.after, second2);
85478
+ return variant("replace", { before: first.value.before, after: afterSecond });
85479
+ } else {
85480
+ const invertedFirst = invertRet(first);
85481
+ const originalBefore = applyRet(second2.value.before, invertedFirst);
85482
+ return variant("replace", { before: originalBefore, after: second2.value.after });
85483
+ }
85484
+ }
85485
+ };
85486
+ const refPrint = printFor(t2, ctx.print);
85487
+ const refEqual = equalFor(t2, ctx.equal);
85488
+ ctx.compose.push(composeRet);
85489
+ ctx.types.push(t2);
85490
+ ctx.equal.push(refEqual);
85491
+ ctx.print.push(refPrint);
85492
+ applyRet = applyFor(t2, { apply: ctx.apply, types: ctx.types, equal: ctx.equal, print: ctx.print });
85493
+ invertRet = invertFor(t2, { invert: ctx.invert, types: ctx.types, equal: ctx.equal });
85494
+ ctx.apply.push(applyRet);
85495
+ ctx.invert.push(invertRet);
85496
+ innerCompose = composeFor(t2.value, ctx);
85497
+ ctx.compose.pop();
85498
+ ctx.apply.pop();
85499
+ ctx.invert.pop();
85500
+ ctx.types.pop();
85501
+ ctx.equal.pop();
85502
+ ctx.print.pop();
85503
+ return composeRet;
85504
+ } else if (t2.type === "Recursive") {
85505
+ return (first, second2) => {
85506
+ if (first.type === "unchanged") {
85507
+ return second2;
85508
+ } else if (second2.type === "unchanged") {
85509
+ return first;
85510
+ } else if (first.type === "replace" && second2.type === "replace") {
85511
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85512
+ } else {
85513
+ throw new Error(`Invalid patch types for recursive type composition: ${first.type}, ${second2.type}`);
85514
+ }
85515
+ };
85516
+ } else if (t2.type === "Function" || t2.type === "AsyncFunction") {
85517
+ return (first, second2) => {
85518
+ if (first.type === "unchanged") {
85519
+ return second2;
85520
+ } else if (second2.type === "unchanged") {
85521
+ return first;
85522
+ } else {
85523
+ return variant("replace", { before: first.value.before, after: second2.value.after });
85524
+ }
85525
+ };
85526
+ } else {
85527
+ throw new Error(`Unhandled type in composeFor: ${t2.type}`);
85528
+ }
85529
+ }
85530
+ function PatchType(type, ctx) {
85531
+ const context = ctx ?? /* @__PURE__ */ new Map();
85532
+ const cached = context.get(type);
85533
+ if (cached !== void 0) {
85534
+ return cached;
85535
+ }
85536
+ const t2 = type;
85537
+ if (t2.type === "Never" || t2.type === "Null" || t2.type === "Boolean" || t2.type === "Integer" || t2.type === "Float" || t2.type === "String" || t2.type === "DateTime" || t2.type === "Blob") {
85538
+ return VariantType({
85539
+ unchanged: NullType,
85540
+ replace: StructType({ before: type, after: type })
85541
+ });
85542
+ } else if (t2.type === "Array") {
85543
+ const elementType = t2.value;
85544
+ const elementPatchType = PatchType(elementType, context);
85545
+ const operationType = VariantType({
85546
+ delete: elementType,
85547
+ insert: elementType,
85548
+ update: elementPatchType
85549
+ });
85550
+ const entryType = StructType({
85551
+ key: IntegerType,
85552
+ offset: IntegerType,
85553
+ operation: operationType
85554
+ });
85555
+ return VariantType({
85556
+ unchanged: NullType,
85557
+ replace: StructType({ before: type, after: type }),
85558
+ patch: ArrayType(entryType)
85559
+ });
85560
+ } else if (t2.type === "Set") {
85561
+ const keyType = t2.key;
85562
+ const operationType = VariantType({
85563
+ delete: NullType,
85564
+ insert: NullType
85565
+ });
85566
+ return VariantType({
85567
+ unchanged: NullType,
85568
+ replace: StructType({ before: type, after: type }),
85569
+ patch: DictType(keyType, operationType)
85570
+ });
85571
+ } else if (t2.type === "Dict") {
85572
+ const keyType = t2.key;
85573
+ const valueType = t2.value;
85574
+ const valuePatchType = PatchType(valueType, context);
85575
+ const operationType = VariantType({
85576
+ delete: valueType,
85577
+ insert: valueType,
85578
+ update: valuePatchType
85579
+ });
85580
+ return VariantType({
85581
+ unchanged: NullType,
85582
+ replace: StructType({ before: type, after: type }),
85583
+ patch: DictType(keyType, operationType)
85584
+ });
85585
+ } else if (t2.type === "Struct") {
85586
+ const fieldTypes = t2.fields;
85587
+ const patchFields = {};
85588
+ for (const [name, fieldType] of Object.entries(fieldTypes)) {
85589
+ patchFields[name] = PatchType(fieldType, context);
85590
+ }
85591
+ return VariantType({
85592
+ unchanged: NullType,
85593
+ replace: StructType({ before: type, after: type }),
85594
+ patch: StructType(patchFields)
85595
+ });
85596
+ } else if (t2.type === "Variant") {
85597
+ const caseTypes = t2.cases;
85598
+ const patchCases = {};
85599
+ for (const [name, caseType] of Object.entries(caseTypes)) {
85600
+ patchCases[name] = PatchType(caseType, context);
85601
+ }
85602
+ return VariantType({
85603
+ unchanged: NullType,
85604
+ replace: StructType({ before: type, after: type }),
85605
+ patch: VariantType(patchCases)
85606
+ });
85607
+ } else if (t2.type === "Ref") {
85608
+ const innerType = t2.value;
85609
+ const innerPatchType = PatchType(innerType, context);
85610
+ return VariantType({
85611
+ unchanged: NullType,
85612
+ replace: StructType({ before: type, after: type }),
85613
+ patch: innerPatchType
85614
+ });
85615
+ } else if (t2.type === "Recursive") {
85616
+ const cached2 = context.get(type);
85617
+ if (cached2 !== void 0) {
85618
+ return cached2;
85619
+ }
85620
+ const replaceOnlyType = VariantType({
85621
+ unchanged: NullType,
85622
+ replace: StructType({ before: type, after: type })
85623
+ });
85624
+ context.set(type, replaceOnlyType);
85625
+ return PatchType(t2.node, context);
85626
+ } else if (t2.type === "Function" || t2.type === "AsyncFunction") {
85627
+ return VariantType({
85628
+ unchanged: NullType,
85629
+ replace: StructType({ before: type, after: type })
85630
+ });
85631
+ } else {
85632
+ throw new Error(`Unhandled type in PatchType: ${t2.type}`);
85633
+ }
85634
+ }
84068
85635
  class EastError extends Error {
84069
85636
  constructor(message, options) {
84070
85637
  super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
@@ -88985,6 +90552,34 @@ const builtin_evaluators = {
88985
90552
  LessEqual: (_location, _platformDef, T2) => lessEqualFor(T2),
88986
90553
  Greater: (_location, _platformDef, T2) => greaterFor(T2),
88987
90554
  GreaterEqual: (_location, _platformDef, T2) => greaterEqualFor(T2),
90555
+ Diff: (_location, _platformDef, T2) => diffFor(T2),
90556
+ ApplyPatch: (location, _platformDef, T2) => {
90557
+ const apply = applyFor(T2);
90558
+ return (base, patch) => {
90559
+ try {
90560
+ return apply(base, patch);
90561
+ } catch (e3) {
90562
+ if (e3 instanceof ConflictError) {
90563
+ throw new EastError(e3.message, { location });
90564
+ }
90565
+ throw e3;
90566
+ }
90567
+ };
90568
+ },
90569
+ ComposePatch: (location, _platformDef, T2) => {
90570
+ const compose3 = composeFor(T2);
90571
+ return (first, second2) => {
90572
+ try {
90573
+ return compose3(first, second2);
90574
+ } catch (e3) {
90575
+ if (e3 instanceof ConflictError) {
90576
+ throw new EastError(e3.message, { location });
90577
+ }
90578
+ throw e3;
90579
+ }
90580
+ };
90581
+ },
90582
+ InvertPatch: (_location, _platformDef, T2) => invertFor(T2),
88988
90583
  BooleanNot: (_location) => (x2) => !x2,
88989
90584
  BooleanOr: (_location) => (x2, y2) => x2 || y2,
88990
90585
  BooleanAnd: (_location) => (x2, y2) => x2 && y2,
@@ -91734,6 +93329,20 @@ function greaterEqual(left, right) {
91734
93329
  arguments: [Expr.ast(left), rightAst]
91735
93330
  });
91736
93331
  }
93332
+ const equals = equal;
93333
+ const eq = equal;
93334
+ const notEquals = notEqual;
93335
+ const ne = notEqual;
93336
+ const lessThan = less;
93337
+ const lt = less;
93338
+ const lessThanOrEqual = lessEqual;
93339
+ const lte = lessEqual;
93340
+ const le = lessEqual;
93341
+ const greaterThan = greater;
93342
+ const gt = greater;
93343
+ const greaterThanOrEqual = greaterEqual;
93344
+ const gte = greaterEqual;
93345
+ const ge = greaterEqual;
91737
93346
  function is(left, right) {
91738
93347
  const rightAst = valueOrExprToAstTyped(right, Expr.type(left));
91739
93348
  return fromAst({
@@ -91756,6 +93365,61 @@ function print(value) {
91756
93365
  arguments: [valueAst]
91757
93366
  });
91758
93367
  }
93368
+ function diff(before, after) {
93369
+ const beforeAst = Expr.ast(before);
93370
+ const afterAst = Expr.ast(after);
93371
+ const valueType = beforeAst.type;
93372
+ const patchType = PatchType(valueType);
93373
+ return fromAst({
93374
+ ast_type: "Builtin",
93375
+ type: patchType,
93376
+ location: get_location(2),
93377
+ builtin: "Diff",
93378
+ type_parameters: [valueType, patchType],
93379
+ arguments: [beforeAst, afterAst]
93380
+ });
93381
+ }
93382
+ function applyPatch(value, patch) {
93383
+ const valueAst = Expr.ast(value);
93384
+ const patchAst = Expr.ast(patch);
93385
+ const valueType = valueAst.type;
93386
+ const patchType = patchAst.type;
93387
+ return fromAst({
93388
+ ast_type: "Builtin",
93389
+ type: valueType,
93390
+ location: get_location(2),
93391
+ builtin: "ApplyPatch",
93392
+ type_parameters: [valueType, patchType],
93393
+ arguments: [valueAst, patchAst]
93394
+ });
93395
+ }
93396
+ function composePatch(first, second2, type) {
93397
+ const firstAst = Expr.ast(first);
93398
+ const secondAst = Expr.ast(second2);
93399
+ const valueType = type;
93400
+ const patchType = PatchType(valueType);
93401
+ return fromAst({
93402
+ ast_type: "Builtin",
93403
+ type: patchType,
93404
+ location: get_location(2),
93405
+ builtin: "ComposePatch",
93406
+ type_parameters: [valueType, patchType],
93407
+ arguments: [firstAst, secondAst]
93408
+ });
93409
+ }
93410
+ function invertPatch(patch, type) {
93411
+ const patchAst = Expr.ast(patch);
93412
+ const valueType = type;
93413
+ const patchType = PatchType(valueType);
93414
+ return fromAst({
93415
+ ast_type: "Builtin",
93416
+ type: patchType,
93417
+ location: get_location(2),
93418
+ builtin: "InvertPatch",
93419
+ type_parameters: [valueType, patchType],
93420
+ arguments: [patchAst]
93421
+ });
93422
+ }
91759
93423
  const BlockBuilder = (return_type) => {
91760
93424
  const statements = [];
91761
93425
  const $ = ((expr) => {
@@ -92436,7 +94100,27 @@ Object.assign(Expr, {
92436
94100
  greater,
92437
94101
  greaterEqual,
92438
94102
  is,
92439
- match: matchExpr
94103
+ match: matchExpr,
94104
+ // Comparison aliases
94105
+ equals,
94106
+ eq,
94107
+ notEquals,
94108
+ ne,
94109
+ lessThan,
94110
+ lt,
94111
+ lessThanOrEqual,
94112
+ lte,
94113
+ le,
94114
+ greaterThan,
94115
+ gt,
94116
+ greaterThanOrEqual,
94117
+ gte,
94118
+ ge,
94119
+ // Patch operations
94120
+ diff,
94121
+ applyPatch,
94122
+ composePatch,
94123
+ invertPatch
92440
94124
  });
92441
94125
  const OverlayManagerContext = React.createContext(null);
92442
94126
  let globalOverlayManager = null;