@neocompose/cli 0.78.0 → 0.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/neo.mjs CHANGED
@@ -761,7 +761,7 @@ function isEpochMillis(value) {
761
761
  return Number.isFinite(value);
762
762
  }
763
763
  function isSystemProtectionKind(value) {
764
- return value === SystemProtectionKind.WorldAuthoring || value === SystemProtectionKind.DialogueMemorySchema || value === SystemProtectionKind.DialogueMemoryContainer || value === SystemProtectionKind.DialoguePriorityDefault || value === SystemProtectionKind.PolicyImmutable || value === SystemProtectionKind.PolicyDeleteBlocked || value === SystemProtectionKind.ScriptRuntime;
764
+ return value === SystemProtectionKind.WorldAuthoring || value === SystemProtectionKind.DialogueMemorySchema || value === SystemProtectionKind.DialogueMemoryContainer || value === SystemProtectionKind.DialoguePriorityDefault || value === SystemProtectionKind.PolicyImmutable || value === SystemProtectionKind.PolicyDeleteBlocked || value === SystemProtectionKind.ScriptRuntime || value === SystemProtectionKind.SystemPreset;
765
765
  }
766
766
  function isSystemMetadata(value) {
767
767
  const v = value;
@@ -806,7 +806,8 @@ var init_core_types = __esm({
806
806
  DialoguePriorityDefault: "dialoguePriorityDefault",
807
807
  PolicyImmutable: "policyImmutable",
808
808
  PolicyDeleteBlocked: "policyDeleteBlocked",
809
- ScriptRuntime: "scriptRuntime"
809
+ ScriptRuntime: "scriptRuntime",
810
+ SystemPreset: "systemPreset"
810
811
  };
811
812
  }
812
813
  });
@@ -6884,6 +6885,7 @@ var WORLD_GRID_CHILDREN_MEMBER_ID, WORLD_GRID_CHILDREN_ENTRY_MEMBER_ID, WORLD_OB
6884
6885
  var init_world_system_classes_generated = __esm({
6885
6886
  "../packages/models/src/classes/world-system-classes.generated.ts"() {
6886
6887
  "use strict";
6888
+ init_core_types();
6887
6889
  WORLD_GRID_CHILDREN_MEMBER_ID = "system_98578ba3-a70e-4397-9283-996a898d44c8";
6888
6890
  WORLD_GRID_CHILDREN_ENTRY_MEMBER_ID = "system_c86da069-7ef9-5693-a54b-5c331755fde9";
6889
6891
  WORLD_OBJECT_BASE_ENABLED_SCHEMA_KEY = "Enabled";
@@ -6953,7 +6955,7 @@ var init_world_system_classes_generated = __esm({
6953
6955
  {
6954
6956
  classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7",
6955
6957
  name: "NeoCellPattern",
6956
- docsText: "An immutable ordered pattern of cell offsets, relative to an origin.\nHand-built patterns preserve order and duplicates; factories order cells nearest first.",
6958
+ docsText: "An ordered pattern of cell offsets, relative to an origin.\nHand-built patterns preserve order and duplicates; factories order cells nearest first.",
6957
6959
  modifier: 2 /* Sealed */,
6958
6960
  constructorIds: ["system_f68684d6-6ea0-5d57-9f96-d544b17bf369"],
6959
6961
  constructors: [
@@ -6992,63 +6994,55 @@ var init_world_system_classes_generated = __esm({
6992
6994
  },
6993
6995
  {
6994
6996
  memberId: "system_d90a6e51-0b1e-5354-b4e2-ad4155a833f1",
6995
- memberKind: "computed",
6997
+ memberKind: "class",
6998
+ protection: SystemProtectionKind.SystemPreset,
6996
6999
  modifier: 3 /* Static */,
7000
+ storage: 1 /* Immutable */,
7001
+ staticInitializerCode: "new NeoCellPattern(offsets: [new(0, 0)])",
6997
7002
  docsText: "Only the origin cell.",
6998
- returnTypeInfo: {
6999
- type: 7,
7000
- required: true,
7001
- classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7002
- },
7003
- code: "return new NeoCellPattern(offsets: [new(0, 0)]);",
7003
+ schemaClassWorldKind: "cellPattern",
7004
7004
  requirement: 1 /* Required */,
7005
7005
  schemaKey: "Center"
7006
7006
  },
7007
7007
  {
7008
7008
  memberId: "system_57290d57-16dd-54d6-ad1e-81a72bd7f457",
7009
- memberKind: "computed",
7009
+ memberKind: "class",
7010
+ protection: SystemProtectionKind.SystemPreset,
7010
7011
  modifier: 3 /* Static */,
7012
+ storage: 1 /* Immutable */,
7013
+ staticInitializerCode: "NeoCellPattern.Cross(1, null, .Center)",
7011
7014
  docsText: "The four edge-adjacent cells, excluding the origin.",
7012
- returnTypeInfo: {
7013
- type: 7,
7014
- required: true,
7015
- classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7016
- },
7017
- code: "return NeoCellPattern.Cross(1, null, .Center);",
7015
+ schemaClassWorldKind: "cellPattern",
7018
7016
  requirement: 1 /* Required */,
7019
7017
  schemaKey: "FourNeighbors"
7020
7018
  },
7021
7019
  {
7022
7020
  memberId: "system_a8f2f798-7988-5df8-8294-decdd4316c7e",
7023
- memberKind: "computed",
7021
+ memberKind: "class",
7022
+ protection: SystemProtectionKind.SystemPreset,
7024
7023
  modifier: 3 /* Static */,
7024
+ storage: 1 /* Immutable */,
7025
+ staticInitializerCode: "NeoCellPattern.Box(1, null, .Center)",
7025
7026
  docsText: "The eight surrounding cells, excluding the origin.",
7026
- returnTypeInfo: {
7027
- type: 7,
7028
- required: true,
7029
- classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7030
- },
7031
- code: "return NeoCellPattern.Box(1, null, .Center);",
7027
+ schemaClassWorldKind: "cellPattern",
7032
7028
  requirement: 1 /* Required */,
7033
7029
  schemaKey: "EightNeighbors"
7034
7030
  },
7035
7031
  {
7036
7032
  memberId: "system_98d035f6-9f7d-5d2b-ae01-70ce90621333",
7037
- memberKind: "computed",
7033
+ memberKind: "class",
7034
+ protection: SystemProtectionKind.SystemPreset,
7038
7035
  modifier: 3 /* Static */,
7036
+ storage: 1 /* Immutable */,
7037
+ staticInitializerCode: "new NeoCellPattern(offsets: [])",
7039
7038
  docsText: "No cells.",
7040
- returnTypeInfo: {
7041
- type: 7,
7042
- required: true,
7043
- classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7044
- },
7045
- code: "return new NeoCellPattern(offsets: []);",
7039
+ schemaClassWorldKind: "cellPattern",
7046
7040
  requirement: 1 /* Required */,
7047
7041
  schemaKey: "Empty"
7048
7042
  },
7049
7043
  {
7050
7044
  memberId: "system_aaad2df6-e31e-5f5d-95b9-e265211faed5",
7051
- memberKind: "function",
7045
+ memberKind: "nsFunction",
7052
7046
  modifier: 3 /* Static */,
7053
7047
  docsText: "A filled rectangle of offsets. Omitting radiusY uses radiusX on both axes.",
7054
7048
  returnTypeInfo: {
@@ -7075,11 +7069,12 @@ var init_world_system_classes_generated = __esm({
7075
7069
  }
7076
7070
  ],
7077
7071
  dispatch: 0 /* Synchronous */,
7072
+ code: 'int y = radiusY ?? radiusX;\nif (radiusX < 0 || y < 0) {\n throw $"Box radii must be non-negative; got {radiusX}, {y}.";\n}\nreturn NeoCellPattern.Shells(-radiusX, radiusX, -y, y, excluding == NeoCellPatternExcluding.Center ? 1 : 0);',
7078
7073
  schemaKey: "Box"
7079
7074
  },
7080
7075
  {
7081
7076
  memberId: "system_df8ebca6-a1d1-57c1-8762-227943fc51d8",
7082
- memberKind: "function",
7077
+ memberKind: "nsFunction",
7083
7078
  modifier: 3 /* Static */,
7084
7079
  docsText: "Axis-aligned offsets. Omitting radiusY uses radiusX on both axes.",
7085
7080
  returnTypeInfo: {
@@ -7106,11 +7101,12 @@ var init_world_system_classes_generated = __esm({
7106
7101
  }
7107
7102
  ],
7108
7103
  dispatch: 0 /* Synchronous */,
7104
+ code: 'int y = radiusY ?? radiusX;\nif (radiusX < 0 || y < 0) {\n throw $"Cross radii must be non-negative; got {radiusX}, {y}.";\n}\nList<Vector2Int> cells = [];\nif (excluding == NeoCellPatternExcluding.None) {\n cells.Add(new(0, 0));\n}\nfor (int distance = 1; distance <= Math.Max(radiusX, y); distance++) {\n if (distance <= radiusX) {\n cells.Add(new(-distance, 0));\n cells.Add(new(distance, 0));\n }\n if (distance <= y) {\n cells.Add(new(0, -distance));\n cells.Add(new(0, distance));\n }\n}\nreturn new NeoCellPattern(offsets: cells);',
7109
7105
  schemaKey: "Cross"
7110
7106
  },
7111
7107
  {
7112
7108
  memberId: "system_82222600-f67f-5127-bb2d-278381b4ef2f",
7113
- memberKind: "function",
7109
+ memberKind: "nsFunction",
7114
7110
  modifier: 3 /* Static */,
7115
7111
  docsText: "The square ring at the given Chebyshev radius. Zero returns the center.",
7116
7112
  returnTypeInfo: {
@@ -7120,11 +7116,12 @@ var init_world_system_classes_generated = __esm({
7120
7116
  },
7121
7117
  argumentTypes: [{ name: "radius", type: 2, required: true }],
7122
7118
  dispatch: 0 /* Synchronous */,
7119
+ code: 'if (radius < 0) {\n throw $"Ring radius must be non-negative; got {radius}.";\n}\nreturn NeoCellPattern.Shells(-radius, radius, -radius, radius, radius);',
7123
7120
  schemaKey: "Ring"
7124
7121
  },
7125
7122
  {
7126
7123
  memberId: "system_d803cfd5-ce53-57da-abc2-7cd69befeb01",
7127
- memberKind: "function",
7124
+ memberKind: "nsFunction",
7128
7125
  modifier: 3 /* Static */,
7129
7126
  docsText: "Cells from the origin through size minus one. Both dimensions must be positive.",
7130
7127
  returnTypeInfo: {
@@ -7134,11 +7131,12 @@ var init_world_system_classes_generated = __esm({
7134
7131
  },
7135
7132
  argumentTypes: [{ name: "size", type: 15, required: true }],
7136
7133
  dispatch: 0 /* Synchronous */,
7134
+ code: 'if (size.x < 1 || size.y < 1) {\n throw $"Rect size must be positive; got {size.x}, {size.y}.";\n}\nreturn NeoCellPattern.Shells(0, size.x - 1, 0, size.y - 1, 0);',
7137
7135
  schemaKey: "Rect"
7138
7136
  },
7139
7137
  {
7140
7138
  memberId: "system_ef0d4cbb-7182-5d93-9bb8-60a5a18f81a5",
7141
- memberKind: "function",
7139
+ memberKind: "nsFunction",
7142
7140
  modifier: 3 /* Static */,
7143
7141
  docsText: "Offsets from the origin through length steps in direction. Center excludes only the origin.",
7144
7142
  returnTypeInfo: {
@@ -7160,6 +7158,7 @@ var init_world_system_classes_generated = __esm({
7160
7158
  }
7161
7159
  ],
7162
7160
  dispatch: 0 /* Synchronous */,
7161
+ code: 'if (direction.x == 0 && direction.y == 0) {\n throw "Line direction must be non-zero.";\n}\nif (length < 0) {\n throw $"Line length must be non-negative; got {length}.";\n}\nList<Vector2Int> cells = [];\nif (excluding == NeoCellPatternExcluding.None) {\n cells.Add(new(0, 0));\n}\nfor (int step = 1; step <= length; step++) {\n cells.Add(new(direction.x * step, direction.y * step));\n}\nreturn new NeoCellPattern(offsets: cells);',
7163
7162
  schemaKey: "Line"
7164
7163
  },
7165
7164
  {
@@ -7242,6 +7241,28 @@ var init_world_system_classes_generated = __esm({
7242
7241
  ],
7243
7242
  dispatch: 0 /* Synchronous */,
7244
7243
  schemaKey: "Union"
7244
+ },
7245
+ {
7246
+ memberId: "system_faf10f4f-f5c2-47d8-b4e2-8f196c756668",
7247
+ memberKind: "nsFunction",
7248
+ access: 2 /* Private */,
7249
+ modifier: 3 /* Static */,
7250
+ docsText: "Square shells firstShell through the rectangle's Chebyshev radius, each clipped to the rectangle.\nA shell runs left column, then bottom/top pairs by x, then right column.",
7251
+ returnTypeInfo: {
7252
+ type: 7,
7253
+ required: true,
7254
+ classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7255
+ },
7256
+ argumentTypes: [
7257
+ { name: "minX", type: 2, required: true },
7258
+ { name: "maxX", type: 2, required: true },
7259
+ { name: "minY", type: 2, required: true },
7260
+ { name: "maxY", type: 2, required: true },
7261
+ { name: "firstShell", type: 2, required: true }
7262
+ ],
7263
+ dispatch: 0 /* Synchronous */,
7264
+ code: "List<Vector2Int> cells = [];\nint radius = Math.Max(Math.Max(-minX, maxX), Math.Max(-minY, maxY));\nfor (int shell = firstShell; shell <= radius; shell++) {\n int firstY = Math.Max(minY, -shell);\n int lastY = Math.Min(maxY, shell);\n if (shell == 0) {\n if (minX <= 0 && maxX >= 0 && firstY <= lastY) {\n cells.Add(new(0, 0));\n }\n } else if (firstY <= lastY) {\n if (-shell >= minX && -shell <= maxX) {\n for (int y = firstY; y <= lastY; y++) {\n cells.Add(new(-shell, y));\n }\n }\n bool bottom = -shell >= minY && -shell <= maxY;\n bool top = shell >= minY && shell <= maxY;\n if (bottom || top) {\n for (int x = Math.Max(minX, -shell + 1); x <= Math.Min(maxX, shell - 1); x++) {\n if (bottom) {\n cells.Add(new(x, -shell));\n }\n if (top) {\n cells.Add(new(x, shell));\n }\n }\n }\n if (shell >= minX && shell <= maxX) {\n for (int y = firstY; y <= lastY; y++) {\n cells.Add(new(shell, y));\n }\n }\n }\n}\nreturn new NeoCellPattern(offsets: cells);",
7265
+ schemaKey: "Shells"
7245
7266
  }
7246
7267
  ],
7247
7268
  supportingFields: [
@@ -7710,7 +7731,7 @@ var init_world_system_classes_generated = __esm({
7710
7731
  {
7711
7732
  memberId: "system_f5ca386c-990c-54a1-8473-2d49d2cd887d",
7712
7733
  memberKind: "function",
7713
- docsText: "Objects at the cells around this placement, in pattern order. Use GetObjects<T>(pattern) to filter by class. A repeated footprint can appear more than once.",
7734
+ docsText: "Objects at the cells around this placement, shifted by offset, in pattern order. Use GetObjects<T>(pattern, offset) to filter by class. A repeated footprint can appear more than once.",
7714
7735
  returnTypeInfo: {
7715
7736
  type: 6,
7716
7737
  required: true,
@@ -7726,6 +7747,12 @@ var init_world_system_classes_generated = __esm({
7726
7747
  type: 7,
7727
7748
  required: true,
7728
7749
  classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7750
+ },
7751
+ {
7752
+ name: "offset",
7753
+ type: 15,
7754
+ required: false,
7755
+ defaultValue: { value: null }
7729
7756
  }
7730
7757
  ],
7731
7758
  dispatch: 0 /* Synchronous */,
@@ -7734,7 +7761,7 @@ var init_world_system_classes_generated = __esm({
7734
7761
  {
7735
7762
  memberId: "system_593e6208-e2ca-505e-9933-04b17102b6d2",
7736
7763
  memberKind: "function",
7737
- docsText: "The first tile found in pattern order around this placement, or null. Each cell uses the grid layer precedence.",
7764
+ docsText: "The first tile found in pattern order around this placement, shifted by offset, or null. Each cell uses the grid layer precedence.",
7738
7765
  returnTypeInfo: {
7739
7766
  type: 7,
7740
7767
  required: false,
@@ -7746,10 +7773,46 @@ var init_world_system_classes_generated = __esm({
7746
7773
  type: 7,
7747
7774
  required: true,
7748
7775
  classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7776
+ },
7777
+ {
7778
+ name: "offset",
7779
+ type: 15,
7780
+ required: false,
7781
+ defaultValue: { value: null }
7749
7782
  }
7750
7783
  ],
7751
7784
  dispatch: 0 /* Synchronous */,
7752
7785
  schemaKey: "GetTile"
7786
+ },
7787
+ {
7788
+ memberId: "system_5a41d36a-bcd9-4867-9e46-d743f6e09582",
7789
+ memberKind: "function",
7790
+ docsText: "The tiles at the cells around this placement, shifted by offset, in pattern order. Each cell uses the grid layer precedence and empty cells are skipped.",
7791
+ returnTypeInfo: {
7792
+ type: 6,
7793
+ required: true,
7794
+ entryTypeInfo: {
7795
+ type: 7,
7796
+ required: true,
7797
+ classId: "system_d7fa161b-b269-4bf1-9ec9-3aebec67e6e0"
7798
+ }
7799
+ },
7800
+ argumentTypes: [
7801
+ {
7802
+ name: "pattern",
7803
+ type: 7,
7804
+ required: true,
7805
+ classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7"
7806
+ },
7807
+ {
7808
+ name: "offset",
7809
+ type: 15,
7810
+ required: false,
7811
+ defaultValue: { value: null }
7812
+ }
7813
+ ],
7814
+ dispatch: 0 /* Synchronous */,
7815
+ schemaKey: "GetTiles"
7753
7816
  }
7754
7817
  ],
7755
7818
  supportingFields: [
@@ -23943,59 +24006,6 @@ var init_neoscript_pattern_bindings = __esm({
23943
24006
  }
23944
24007
  });
23945
24008
 
23946
- // ../packages/neoscript-language/src/cell-pattern.ts
23947
- var NEO_CELL_PATTERN_CLASS_ID, NEO_CELL_PATTERN_CONSTRUCTOR_ID, NEO_CELL_PATTERN_EXCLUDING_ENUM_ID, NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS, NEO_CELL_PATTERN_MEMBER_IDS, NEO_OBJECT_GRID_MEMBER_IDS, NEO_CELL_PATTERN_PURE_NATIVE_MEMBER_IDS, NEO_OBJECT_CLASS_ID;
23948
- var init_cell_pattern = __esm({
23949
- "../packages/neoscript-language/src/cell-pattern.ts"() {
23950
- "use strict";
23951
- NEO_CELL_PATTERN_CLASS_ID = "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7";
23952
- NEO_CELL_PATTERN_CONSTRUCTOR_ID = "system_f68684d6-6ea0-5d57-9f96-d544b17bf369";
23953
- NEO_CELL_PATTERN_EXCLUDING_ENUM_ID = "system_072f749f-62fe-5917-9f7e-f9f29c3a7063";
23954
- NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS = {
23955
- None: "system_5c30e23b-1767-5e15-b633-40ae182157a7",
23956
- Center: "system_456431b5-aa5b-5ea0-9f72-0e16f7114e09"
23957
- };
23958
- NEO_CELL_PATTERN_MEMBER_IDS = {
23959
- Count: "system_51d883c9-d451-5747-bcf0-e314e44bffa8",
23960
- Center: "system_d90a6e51-0b1e-5354-b4e2-ad4155a833f1",
23961
- FourNeighbors: "system_57290d57-16dd-54d6-ad1e-81a72bd7f457",
23962
- EightNeighbors: "system_a8f2f798-7988-5df8-8294-decdd4316c7e",
23963
- Empty: "system_98d035f6-9f7d-5d2b-ae01-70ce90621333",
23964
- Box: "system_aaad2df6-e31e-5f5d-95b9-e265211faed5",
23965
- Cross: "system_df8ebca6-a1d1-57c1-8762-227943fc51d8",
23966
- Ring: "system_82222600-f67f-5127-bb2d-278381b4ef2f",
23967
- Rect: "system_d803cfd5-ce53-57da-abc2-7cd69befeb01",
23968
- Line: "system_ef0d4cbb-7182-5d93-9bb8-60a5a18f81a5",
23969
- Contains: "system_65a16908-05a6-52f9-a467-4e37e95ba0be",
23970
- Cells: "system_c72d9b09-fc4c-55db-b763-f1954a536069",
23971
- WithCenter: "system_1da9303d-c362-541a-a77b-244fb0ffcbb6",
23972
- WithoutCenter: "system_7dce7f78-2c8f-5a1f-aa80-89dc217dcdff",
23973
- Translate: "system_efc67858-0c95-573f-a8a9-d7e07d0a1d55",
23974
- Union: "system_77b14581-e34c-5eb1-a820-788618276e46"
23975
- };
23976
- NEO_OBJECT_GRID_MEMBER_IDS = {
23977
- Cell: "system_c609fed3-53e4-5147-b493-e4aa23031d79",
23978
- GetCell: "system_df1c2d06-eeec-5340-addc-740f3668c9e4",
23979
- GetObjects: "system_f5ca386c-990c-54a1-8473-2d49d2cd887d",
23980
- GetTile: "system_593e6208-e2ca-505e-9933-04b17102b6d2"
23981
- };
23982
- NEO_CELL_PATTERN_PURE_NATIVE_MEMBER_IDS = /* @__PURE__ */ new Set([
23983
- NEO_CELL_PATTERN_MEMBER_IDS.Box,
23984
- NEO_CELL_PATTERN_MEMBER_IDS.Cross,
23985
- NEO_CELL_PATTERN_MEMBER_IDS.Ring,
23986
- NEO_CELL_PATTERN_MEMBER_IDS.Rect,
23987
- NEO_CELL_PATTERN_MEMBER_IDS.Line,
23988
- NEO_CELL_PATTERN_MEMBER_IDS.Contains,
23989
- NEO_CELL_PATTERN_MEMBER_IDS.Cells,
23990
- NEO_CELL_PATTERN_MEMBER_IDS.WithCenter,
23991
- NEO_CELL_PATTERN_MEMBER_IDS.WithoutCenter,
23992
- NEO_CELL_PATTERN_MEMBER_IDS.Translate,
23993
- NEO_CELL_PATTERN_MEMBER_IDS.Union
23994
- ]);
23995
- NEO_OBJECT_CLASS_ID = "system_f671535d-0eb6-4139-9caf-5c5276febd31";
23996
- }
23997
- });
23998
-
23999
24009
  // ../packages/models/src/variants/variant-member.ts
24000
24010
  function neoVariantSystemClass(classes, lookup = false) {
24001
24011
  const declared = classes.find(
@@ -24250,6 +24260,12 @@ function schemaKeyToMemberName(schemaKey) {
24250
24260
  function toCSharpTypeName(value, fallback) {
24251
24261
  return generatedCSharpTypeName(value, fallback);
24252
24262
  }
24263
+ function isCSharpNamespace(value) {
24264
+ const segments = value.split(".");
24265
+ return segments.length > 0 && segments.every(
24266
+ (segment) => isCSharpIdentifier(segment) && !isCSharpReservedKeyword(segment)
24267
+ );
24268
+ }
24253
24269
  var init_csharp_identifiers = __esm({
24254
24270
  "../src/models/exports/unity-codegen/csharp-identifiers.ts"() {
24255
24271
  "use strict";
@@ -24405,12 +24421,6 @@ function resolveGeneratedNamespace(exportData, diagnostics) {
24405
24421
  function resolveUnitySingleton(exportData) {
24406
24422
  return exportData.project.exportSettings?.unity?.singleton !== false;
24407
24423
  }
24408
- function isCSharpNamespace(value) {
24409
- const segments = value.split(".");
24410
- return segments.length > 0 && segments.every(
24411
- (segment) => isCSharpIdentifier(segment) && !isCSharpReservedKeyword(segment)
24412
- );
24413
- }
24414
24424
  function buildNameMap(values, fallbackPrefix, diagnostics) {
24415
24425
  const used = /* @__PURE__ */ new Map();
24416
24426
  const names = /* @__PURE__ */ new Map();
@@ -24895,11 +24905,12 @@ function resolveGeneratedInstanceMemberPlan(ctx, classDef, schemaKey) {
24895
24905
  schemaKey
24896
24906
  );
24897
24907
  const inheritedSignature = inherited?.signature ?? null;
24908
+ const emitsVirtual = signature.isVirtual && !isSealedClass(classDef);
24898
24909
  if (inheritedSignature === null) {
24899
24910
  return {
24900
24911
  signature,
24901
24912
  inheritedSignature: null,
24902
- modifier: emitsAbstract ? "abstract" : signature.isVirtual ? "virtual" : "",
24913
+ modifier: emitsAbstract ? "abstract" : emitsVirtual ? "virtual" : "",
24903
24914
  emitBody: !emitsAbstract
24904
24915
  };
24905
24916
  }
@@ -24909,7 +24920,7 @@ function resolveGeneratedInstanceMemberPlan(ctx, classDef, schemaKey) {
24909
24920
  );
24910
24921
  if (!compatible || !inheritedSignature.isVirtual) {
24911
24922
  const sameName = signature.name === inheritedSignature.name;
24912
- const modifier = emitsAbstract ? sameName ? "new abstract" : "abstract" : signature.isVirtual ? sameName ? "new virtual" : "virtual" : sameName ? "new" : "";
24923
+ const modifier = emitsAbstract ? sameName ? "new abstract" : "abstract" : emitsVirtual ? sameName ? "new virtual" : "virtual" : sameName ? "new" : "";
24913
24924
  return {
24914
24925
  signature,
24915
24926
  inheritedSignature,
@@ -25116,8 +25127,6 @@ function constructedTypeArgumentsSuffix(ctx, member, saved, env, genericBindingS
25116
25127
  return `<${projected.join(", ")}>`;
25117
25128
  }
25118
25129
  function schemaClassFamilyName(ctx, classId, typeName, saved) {
25119
- if (classId === NEO_CELL_PATTERN_CLASS_ID)
25120
- return "NeoCompose.Runtime.NeoCellPattern";
25121
25130
  const constraint = classAllowedStorage(ctx, classId);
25122
25131
  if (constraint === 1 /* Immutable */) {
25123
25132
  return readOnlyInterfaceName(typeName);
@@ -25282,8 +25291,6 @@ function collectionEntrySaved(collection, entryMember, saved) {
25282
25291
  return entryMember !== null && (isMemberClassBase(entryMember) || isMemberGenericBase(entryMember));
25283
25292
  }
25284
25293
  function csharpValueType(ctx, member, saved = false, env, genericBindingSaved = saved) {
25285
- if (isMemberEnumBase(member) && member.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
25286
- return isMultiSelectionMember(member) ? "IReadOnlyList<NeoCompose.Runtime.NeoCellPatternExcluding>" : `NeoCompose.Runtime.NeoCellPatternExcluding${isRequiredMember(member) ? "" : "?"}`;
25287
25294
  if (isMemberDelegateBase(member)) {
25288
25295
  const delegateType = csharpDelegateType(
25289
25296
  ctx,
@@ -25560,8 +25567,6 @@ function csharpTypeInfoValueType(ctx, typeInfo, saved, genericEnv, genericBindin
25560
25567
  case 19 /* Color */:
25561
25568
  return optional2 ? "Color?" : "Color";
25562
25569
  case 8 /* Enum */: {
25563
- if (typeInfo.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
25564
- return `NeoCompose.Runtime.NeoCellPatternExcluding${optional2 ? "?" : ""}`;
25565
25570
  const enumName = ctx.enumNames.get(typeInfo.enumId);
25566
25571
  return enumName === void 0 ? null : `${enumName}${optional2 ? "?" : ""}`;
25567
25572
  }
@@ -26399,15 +26404,6 @@ function lookupDeclaredTypeInfo(member) {
26399
26404
  if (!isMemberLookupBase(member)) return null;
26400
26405
  return member.declaredTypeInfo ?? null;
26401
26406
  }
26402
- function rejectCellPatternIdentity(ctx, classId, use, path) {
26403
- if (classId !== NEO_CELL_PATTERN_CLASS_ID) return false;
26404
- const message = `CellPattern is a detached SDK value and cannot be used as a ${use}. Use an ordinary CellPattern field, List, Dictionary, or unconstrained generic value.`;
26405
- if (!ctx.diagnostics.some(
26406
- (diagnostic) => diagnostic.path === path && diagnostic.message === message
26407
- ))
26408
- ctx.diagnostics.push({ severity: "error", message, path });
26409
- return true;
26410
- }
26411
26407
  function lookupTargetClassProjection(ctx, member, env) {
26412
26408
  if (!isMemberLookupBase(member)) return null;
26413
26409
  const declaredTypeInfo = lookupDeclaredTypeInfo(member);
@@ -26415,26 +26411,12 @@ function lookupTargetClassProjection(ctx, member, env) {
26415
26411
  const entryMember = resolveLookupEntryMember(ctx, member);
26416
26412
  if (entryMember === null) return null;
26417
26413
  if (!isMemberClassBase(entryMember)) return null;
26418
- if (rejectCellPatternIdentity(
26419
- ctx,
26420
- entryMember.classId,
26421
- "Lookup target",
26422
- `members.${member.name}`
26423
- ))
26424
- return null;
26425
26414
  return {
26426
26415
  classId: entryMember.classId,
26427
26416
  constructedSuffix: constructedTypeArgumentsSuffix(ctx, entryMember, true, env) ?? ""
26428
26417
  };
26429
26418
  }
26430
26419
  if (declaredTypeInfo.type === 7 /* Class */) {
26431
- if (rejectCellPatternIdentity(
26432
- ctx,
26433
- declaredTypeInfo.classId,
26434
- "Lookup target",
26435
- `members.${member.name}`
26436
- ))
26437
- return null;
26438
26420
  return {
26439
26421
  classId: declaredTypeInfo.classId,
26440
26422
  constructedSuffix: typeInfoConstructedSuffix(ctx, declaredTypeInfo, true, env) ?? ""
@@ -26451,13 +26433,6 @@ function lookupTargetClassProjection(ctx, member, env) {
26451
26433
  );
26452
26434
  if (bindingMember === null) return null;
26453
26435
  if (!isMemberClassBase(bindingMember)) return null;
26454
- if (rejectCellPatternIdentity(
26455
- ctx,
26456
- bindingMember.classId,
26457
- "Lookup target",
26458
- `members.${member.name}`
26459
- ))
26460
- return null;
26461
26436
  return {
26462
26437
  classId: bindingMember.classId,
26463
26438
  constructedSuffix: constructedTypeArgumentsSuffix(ctx, bindingMember, true, env) ?? ""
@@ -26541,19 +26516,6 @@ function shortId(id2) {
26541
26516
  function variantTargetCSharpType(ctx, member, env) {
26542
26517
  const target = member.targetTypeInfo;
26543
26518
  if (target.type === 21 /* Generic */) {
26544
- const binding = env?.get(target.genericParamId);
26545
- const boundMember = binding?.kind === "member" ? resolveMemberById(
26546
- ctx,
26547
- binding.memberId,
26548
- `members.${member.name}.targetTypeInfo`
26549
- ) : null;
26550
- if (boundMember !== null && isMemberClassBase(boundMember) && rejectCellPatternIdentity(
26551
- ctx,
26552
- boundMember.classId,
26553
- "Variant target",
26554
- `members.${member.name}.targetTypeInfo`
26555
- ))
26556
- return null;
26557
26519
  return csharpGenericParamType(
26558
26520
  ctx,
26559
26521
  target.genericParamId,
@@ -26570,13 +26532,6 @@ function variantTargetCSharpType(ctx, member, env) {
26570
26532
  });
26571
26533
  return null;
26572
26534
  }
26573
- if (rejectCellPatternIdentity(
26574
- ctx,
26575
- target.classId,
26576
- "Variant target",
26577
- `members.${member.name}.targetTypeInfo`
26578
- ))
26579
- return null;
26580
26535
  const typeName = ctx.typeNames.get(target.classId);
26581
26536
  if (typeName === void 0) {
26582
26537
  ctx.diagnostics.push({
@@ -26591,28 +26546,6 @@ function variantTargetCSharpType(ctx, member, env) {
26591
26546
  function variantValueCSharpType(ctx, member, env) {
26592
26547
  const valueTypeInfo = member.valueTypeInfo;
26593
26548
  if (valueTypeInfo == null) return null;
26594
- if (valueTypeInfo.type === 21 /* Generic */) {
26595
- const binding = env?.get(valueTypeInfo.genericParamId);
26596
- const boundMember = binding?.kind === "member" ? resolveMemberById(
26597
- ctx,
26598
- binding.memberId,
26599
- `members.${member.name}.valueTypeInfo`
26600
- ) : null;
26601
- if (boundMember !== null && isMemberClassBase(boundMember) && rejectCellPatternIdentity(
26602
- ctx,
26603
- boundMember.classId,
26604
- "Variant value",
26605
- `members.${member.name}.valueTypeInfo`
26606
- ))
26607
- return null;
26608
- }
26609
- if (valueTypeInfo.type === 7 /* Class */ && rejectCellPatternIdentity(
26610
- ctx,
26611
- valueTypeInfo.classId,
26612
- "Variant value",
26613
- `members.${member.name}.valueTypeInfo`
26614
- ))
26615
- return null;
26616
26549
  return csharpTypeInfoValueType(
26617
26550
  ctx,
26618
26551
  { ...valueTypeInfo, required: true },
@@ -26625,7 +26558,6 @@ var init_unity_member_signatures = __esm({
26625
26558
  "../src/models/exports/unity-codegen/unity-member-signatures.ts"() {
26626
26559
  "use strict";
26627
26560
  init_neoscript_pattern_bindings();
26628
- init_cell_pattern();
26629
26561
  init_generated_csharp_identifiers();
26630
26562
  init_members();
26631
26563
  init_world_system_classes();
@@ -29954,6 +29886,50 @@ var init_collection_query = __esm({
29954
29886
  }
29955
29887
  });
29956
29888
 
29889
+ // ../packages/neoscript-language/src/cell-pattern.ts
29890
+ var NEO_CELL_PATTERN_CLASS_ID, NEO_CELL_PATTERN_CONSTRUCTOR_ID, NEO_CELL_PATTERN_MEMBER_IDS, NEO_OBJECT_GRID_MEMBER_IDS, NEO_CELL_PATTERN_PURE_NATIVE_MEMBER_IDS, NEO_OBJECT_CLASS_ID;
29891
+ var init_cell_pattern = __esm({
29892
+ "../packages/neoscript-language/src/cell-pattern.ts"() {
29893
+ "use strict";
29894
+ NEO_CELL_PATTERN_CLASS_ID = "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7";
29895
+ NEO_CELL_PATTERN_CONSTRUCTOR_ID = "system_f68684d6-6ea0-5d57-9f96-d544b17bf369";
29896
+ NEO_CELL_PATTERN_MEMBER_IDS = {
29897
+ Count: "system_51d883c9-d451-5747-bcf0-e314e44bffa8",
29898
+ Center: "system_d90a6e51-0b1e-5354-b4e2-ad4155a833f1",
29899
+ FourNeighbors: "system_57290d57-16dd-54d6-ad1e-81a72bd7f457",
29900
+ EightNeighbors: "system_a8f2f798-7988-5df8-8294-decdd4316c7e",
29901
+ Empty: "system_98d035f6-9f7d-5d2b-ae01-70ce90621333",
29902
+ Box: "system_aaad2df6-e31e-5f5d-95b9-e265211faed5",
29903
+ Cross: "system_df8ebca6-a1d1-57c1-8762-227943fc51d8",
29904
+ Ring: "system_82222600-f67f-5127-bb2d-278381b4ef2f",
29905
+ Rect: "system_d803cfd5-ce53-57da-abc2-7cd69befeb01",
29906
+ Line: "system_ef0d4cbb-7182-5d93-9bb8-60a5a18f81a5",
29907
+ Contains: "system_65a16908-05a6-52f9-a467-4e37e95ba0be",
29908
+ Cells: "system_c72d9b09-fc4c-55db-b763-f1954a536069",
29909
+ WithCenter: "system_1da9303d-c362-541a-a77b-244fb0ffcbb6",
29910
+ WithoutCenter: "system_7dce7f78-2c8f-5a1f-aa80-89dc217dcdff",
29911
+ Translate: "system_efc67858-0c95-573f-a8a9-d7e07d0a1d55",
29912
+ Union: "system_77b14581-e34c-5eb1-a820-788618276e46"
29913
+ };
29914
+ NEO_OBJECT_GRID_MEMBER_IDS = {
29915
+ Cell: "system_c609fed3-53e4-5147-b493-e4aa23031d79",
29916
+ GetCell: "system_df1c2d06-eeec-5340-addc-740f3668c9e4",
29917
+ GetObjects: "system_f5ca386c-990c-54a1-8473-2d49d2cd887d",
29918
+ GetTile: "system_593e6208-e2ca-505e-9933-04b17102b6d2",
29919
+ GetTiles: "system_5a41d36a-bcd9-4867-9e46-d743f6e09582"
29920
+ };
29921
+ NEO_CELL_PATTERN_PURE_NATIVE_MEMBER_IDS = /* @__PURE__ */ new Set([
29922
+ NEO_CELL_PATTERN_MEMBER_IDS.Contains,
29923
+ NEO_CELL_PATTERN_MEMBER_IDS.Cells,
29924
+ NEO_CELL_PATTERN_MEMBER_IDS.WithCenter,
29925
+ NEO_CELL_PATTERN_MEMBER_IDS.WithoutCenter,
29926
+ NEO_CELL_PATTERN_MEMBER_IDS.Translate,
29927
+ NEO_CELL_PATTERN_MEMBER_IDS.Union
29928
+ ]);
29929
+ NEO_OBJECT_CLASS_ID = "system_f671535d-0eb6-4139-9caf-5c5276febd31";
29930
+ }
29931
+ });
29932
+
29957
29933
  // ../packages/neoscript-language/src/declared-constructors.ts
29958
29934
  function neoScriptArgumentNameSetKey(names) {
29959
29935
  return [...names].map((name) => name.toLowerCase()).sort().join(",");
@@ -41129,7 +41105,8 @@ var init_project_schema_contract_generated = __esm({
41129
41105
  "DialoguePriorityDefault",
41130
41106
  "PolicyImmutable",
41131
41107
  "PolicyDeleteBlocked",
41132
- "ScriptRuntime"
41108
+ "ScriptRuntime",
41109
+ "SystemPreset"
41133
41110
  ],
41134
41111
  "NeoMemberRequirement": [
41135
41112
  "Optional",
@@ -45238,6 +45215,73 @@ function validateRetiredParameterReads(uri, declaration, scope, diagnostics) {
45238
45215
  }
45239
45216
  }
45240
45217
  }
45218
+ function validateOwnedStaticDefault(uri, member, ownerName, scope, environment, diagnostics) {
45219
+ const initializer = member.initializer;
45220
+ if (initializer === void 0) return;
45221
+ if (member.type.name === "Reference") return;
45222
+ let expression;
45223
+ try {
45224
+ expression = parseExpression(initializer.text);
45225
+ } catch (error) {
45226
+ if (!(error instanceof CompileError)) throw error;
45227
+ return;
45228
+ }
45229
+ while (expression.kind === "annotated") expression = expression.expression;
45230
+ const path = [];
45231
+ let receiver = expression;
45232
+ while (receiver.kind === "member" || receiver.kind === "index") {
45233
+ path.push(receiver.kind === "member" ? receiver.name : null);
45234
+ receiver = receiver.receiver;
45235
+ }
45236
+ path.reverse();
45237
+ if (receiver.kind !== "ident") return;
45238
+ if (path[0] === void 0 || path[0] === null) return;
45239
+ if (scope.has(receiver.name) || environment.globals.has(receiver.name))
45240
+ return;
45241
+ const index = environment.projectIndex;
45242
+ let owner = index.typeByName.get(receiver.name);
45243
+ let type;
45244
+ let referenced = false;
45245
+ for (const [hop, name] of path.entries()) {
45246
+ if (name === null) {
45247
+ type = elementTypeRef(type);
45248
+ if (type === void 0) return;
45249
+ } else {
45250
+ const field = owner?.members.find(
45251
+ (candidate) => candidate.name === name && candidate.static === true === (hop === 0)
45252
+ );
45253
+ if (field === void 0) return;
45254
+ if (field.kind !== "property") return;
45255
+ if (field.computed === true) return;
45256
+ type = field.type;
45257
+ referenced = field.lookup !== void 0;
45258
+ }
45259
+ owner = type.kind === "named" ? index.typeById.get(type.typeId) : void 0;
45260
+ }
45261
+ if (type === void 0) return;
45262
+ if (referenced) return;
45263
+ if (!isOwnedAggregateTypeRef(type, index)) return;
45264
+ pushDiagnostic(
45265
+ diagnostics,
45266
+ uri,
45267
+ initializer.range,
45268
+ "owned-static-value",
45269
+ `Member '${ownerName}.${member.name}' defaults to '${initializer.text.trim()}', which is already owned by that static. Call Clone() or use Reference.`
45270
+ );
45271
+ }
45272
+ function elementTypeRef(type) {
45273
+ if (type?.kind === "list") return type.elementType;
45274
+ if (type?.kind === "set") return type.elementType;
45275
+ if (type?.kind === "dictionary") return type.valueType;
45276
+ return void 0;
45277
+ }
45278
+ function isOwnedAggregateTypeRef(type, index) {
45279
+ if (type.kind === "list") return true;
45280
+ if (type.kind === "set") return true;
45281
+ if (type.kind === "dictionary") return true;
45282
+ if (type.kind !== "named") return false;
45283
+ return index.typeById.get(type.typeId)?.kind === "class";
45284
+ }
45241
45285
  function identifierRange(anchor, read, fallback) {
45242
45286
  const offset = anchorOffset(anchor, read.pos);
45243
45287
  const slice = anchor.text.slice(offset, offset + read.name.length);
@@ -45376,6 +45420,16 @@ function validateMember(uri, member, ownerName, documentKind, ownerScope, enviro
45376
45420
  label: `Member '${ownerName}.${member.name}' initializer`
45377
45421
  }
45378
45422
  );
45423
+ if (documentKind !== "flow" && !member.modifiers.includes("static")) {
45424
+ validateOwnedStaticDefault(
45425
+ uri,
45426
+ member,
45427
+ ownerName,
45428
+ scope,
45429
+ environment,
45430
+ diagnostics
45431
+ );
45432
+ }
45379
45433
  }
45380
45434
  if (documentKind === "flow" && member.flowInitializer?.body?.kind === "block") {
45381
45435
  validateFlowContent(
@@ -46727,13 +46781,13 @@ function validateExpression(expression, expected, scope, environment, uri, range
46727
46781
  );
46728
46782
  return;
46729
46783
  }
46730
- const signature = expression.callee.kind === "ident" ? environment.functions.get(expression.callee.name)?.[0] : void 0;
46784
+ const parameters = callParameters(expression.callee, scope, environment);
46731
46785
  expression.args.forEach((argument2, index) => {
46732
- const named = expression.argumentNames?.[index];
46733
- const parameterIndex = named && signature ? index : index;
46786
+ const name = expression.argumentNames?.[index];
46787
+ const parameter4 = name === void 0 || name === null ? parameters?.[index] : parameters?.find((candidate) => candidate.name === name);
46734
46788
  validateExpression(
46735
46789
  argument2,
46736
- signature?.parameters[parameterIndex],
46790
+ parameter4?.type,
46737
46791
  scope,
46738
46792
  environment,
46739
46793
  uri,
@@ -47503,6 +47557,23 @@ function inferExpressionType(expression, scope, environment) {
47503
47557
  }
47504
47558
  return void 0;
47505
47559
  }
47560
+ function callParameters(callee, scope, environment) {
47561
+ if (callee.kind === "ident") {
47562
+ return environment.functions.get(callee.name)?.[0]?.parameters.map((type) => ({ name: null, type }));
47563
+ }
47564
+ if (callee.kind !== "member") return void 0;
47565
+ const receiverType = inferExpressionType(callee.receiver, scope, environment);
47566
+ const staticDeclaration = receiverType === void 0 && callee.receiver.kind === "ident" ? environment.types.get(callee.receiver.name) : void 0;
47567
+ const resolved = staticDeclaration === void 0 ? receiverType === void 0 ? void 0 : sourceClassMemberForType(receiverType, callee.name, environment) : sourceClassMemberByName(staticDeclaration, callee.name, environment);
47568
+ if (resolved?.member.kind !== "function") return void 0;
47569
+ return resolved.member.parameters.map((parameter4) => ({
47570
+ name: parameter4.name,
47571
+ type: substituteSemanticType(
47572
+ semanticType(parameter4.type),
47573
+ resolved.bindings
47574
+ )
47575
+ }));
47576
+ }
47506
47577
  function semanticMemberType(member, environment, bindings = /* @__PURE__ */ new Map()) {
47507
47578
  const type = substituteSemanticType(semanticType(member.type), bindings);
47508
47579
  if (type.name !== "List") return type;
@@ -53951,7 +54022,7 @@ var init_registry = __esm({
53951
54022
  "../packages/manifest/schema-contract/registry.mjs"() {
53952
54023
  "use strict";
53953
54024
  PROJECT_SCHEMA_CONTRACT = Object.freeze({
53954
- cliVersion: "0.78.0",
54025
+ cliVersion: "0.79.0",
53955
54026
  projectFileUploadBatchSize: 32,
53956
54027
  documentRecords: {
53957
54028
  member: {
@@ -54671,7 +54742,8 @@ var init_registry = __esm({
54671
54742
  "DialoguePriorityDefault",
54672
54743
  "PolicyImmutable",
54673
54744
  "PolicyDeleteBlocked",
54674
- "ScriptRuntime"
54745
+ "ScriptRuntime",
54746
+ "SystemPreset"
54675
54747
  ],
54676
54748
  NeoMemberRequirement: ["Optional", "Required"],
54677
54749
  NeoMemberMutability: ["Mutable", "ReadOnly"],
@@ -57797,7 +57869,8 @@ var init_schema_member = __esm({
57797
57869
  "dialoguePriorityDefault",
57798
57870
  "policyImmutable",
57799
57871
  "policyDeleteBlocked",
57800
- "scriptRuntime"
57872
+ "scriptRuntime",
57873
+ "systemPreset"
57801
57874
  ]);
57802
57875
  worldSystemClassKindSchema = picklist([
57803
57876
  "cellPattern",
@@ -59495,7 +59568,8 @@ function isSchemaSystemMetadata(value) {
59495
59568
  "dialoguePriorityDefault",
59496
59569
  "policyImmutable",
59497
59570
  "policyDeleteBlocked",
59498
- "scriptRuntime"
59571
+ "scriptRuntime",
59572
+ "systemPreset"
59499
59573
  ]);
59500
59574
  const worlds = /* @__PURE__ */ new Set([
59501
59575
  "cellPattern",
@@ -67275,7 +67349,10 @@ function resolveMemberDeclaredTypeInfoInternal(member, members, seen, ownerClass
67275
67349
  };
67276
67350
  }
67277
67351
  const collectionKind = resolved.kind;
67278
- if (collectionKind === 6 /* List */ || collectionKind === 28 /* Set */ || collectionKind === 5 /* Dictionary */ && isMemberDictionaryBase(resolved)) {
67352
+ if (collectionKind === 5 /* Dictionary */ && !isMemberDictionaryBase(resolved)) {
67353
+ return null;
67354
+ }
67355
+ if (collectionKind === 6 /* List */ || collectionKind === 28 /* Set */ || collectionKind === 5 /* Dictionary */) {
67279
67356
  const entryMemberId = getField(resolved, "entryMemberId");
67280
67357
  const entry = members.find((candidate) => candidate.id === entryMemberId);
67281
67358
  if (entry === void 0) return null;
@@ -72779,7 +72856,8 @@ var init_NSGetterRuntimeError = __esm({
72779
72856
  node: { writable: true, value: void 0 },
72780
72857
  callerNode: { writable: true, value: void 0 },
72781
72858
  initializerValueId: { writable: true, value: void 0 },
72782
- sourceOwnerId: { writable: true, value: void 0 }
72859
+ sourceOwnerId: { writable: true, value: void 0 },
72860
+ attachedValueId: { writable: true, value: void 0 }
72783
72861
  });
72784
72862
  if (options?.cause instanceof Error && "neoScriptFrames" in options.cause && Array.isArray(options.cause.neoScriptFrames)) {
72785
72863
  const frames = options.cause.neoScriptFrames;
@@ -72918,6 +72996,9 @@ function initializerOwnerContext(document, valueId, rootOwners, valuesById, reco
72918
72996
  const ownerClass = typeof lexicalRootId === "string" ? findSchemaPlacement(lexicalRootId, document.classes)?.ownerClass ?? null : null;
72919
72997
  return { ownerClass, lexicalThisClass: ownerClass };
72920
72998
  }
72999
+ function isClassRecordValue(value) {
73000
+ return value !== null && typeof value === "object" && !Array.isArray(value);
73001
+ }
72921
73002
  function isRecordValue(value) {
72922
73003
  if (value === null) return false;
72923
73004
  if (typeof value !== "object") return false;
@@ -73023,7 +73104,7 @@ function resolveOwnerMembersForValues(document, targetValueIds, additionalRoots,
73023
73104
  }
73024
73105
  function searchChildren(member, rootOwner, body, ambientEnv, rootKind) {
73025
73106
  if (isMemberClassBase(member)) {
73026
- if (!isRecordValue(body.value)) return;
73107
+ if (!isClassRecordValue(body.value)) return;
73027
73108
  const effectiveClassId = body.classId ?? member.classId;
73028
73109
  const schemaClass2 = classesById.get(effectiveClassId);
73029
73110
  if (schemaClass2 === void 0) return;
@@ -73038,7 +73119,7 @@ function resolveOwnerMembersForValues(document, targetValueIds, additionalRoots,
73038
73119
  if (complete2) break;
73039
73120
  if (entry.memberId === null) continue;
73040
73121
  const childValueId = body.value[entry.schemaKey];
73041
- if (childValueId === void 0) continue;
73122
+ if (typeof childValueId !== "string") continue;
73042
73123
  const childMember = membersById.get(entry.memberId);
73043
73124
  if (childMember === void 0) continue;
73044
73125
  const substituted = trySubstituteMember(childMember, env);
@@ -73211,7 +73292,7 @@ function findOwningMembersForValues(document, valueIds, additionalRoots, travers
73211
73292
  const env = overlayStamp(classEnv, args.genericBindings);
73212
73293
  for (const entry of merged) {
73213
73294
  const childValueId = args.record[entry.schemaKey];
73214
- if (childValueId === void 0) continue;
73295
+ if (typeof childValueId !== "string") continue;
73215
73296
  const childMember = membersById.get(entry.memberId);
73216
73297
  if (childMember === void 0) continue;
73217
73298
  queue.push({
@@ -73254,7 +73335,7 @@ function findOwningMembersForValues(document, valueIds, additionalRoots, travers
73254
73335
  const defaultValue = member.defaultValue;
73255
73336
  if (defaultValue == null) continue;
73256
73337
  if (isMemberClassBase(member)) {
73257
- if (!isRecordValue(defaultValue.value)) continue;
73338
+ if (!isClassRecordValue(defaultValue.value)) continue;
73258
73339
  enqueueClassInstanceChildren({
73259
73340
  member,
73260
73341
  record: defaultValue.value,
@@ -73356,7 +73437,7 @@ function findOwningMembersForValues(document, valueIds, additionalRoots, travers
73356
73437
  const storedValue = valuesById.get(current.id);
73357
73438
  if (storedValue === void 0) continue;
73358
73439
  if (isMemberClassBase(current.member)) {
73359
- if (!isRecordValue(storedValue.value)) continue;
73440
+ if (!isClassRecordValue(storedValue.value)) continue;
73360
73441
  enqueueClassInstanceChildren({
73361
73442
  member: current.member,
73362
73443
  record: storedValue.value,
@@ -73428,12 +73509,12 @@ var init_value_row_owner_members = __esm({
73428
73509
  });
73429
73510
 
73430
73511
  // ../packages/neoscript-runtime/src/neoscript/cell-pattern.ts
73431
- function integer2(value, name, minimum = -2147483648) {
73512
+ function integer2(value, name) {
73432
73513
  if (typeof value !== "number" || !Number.isInteger(value)) {
73433
73514
  throw new TypeError(`${name} must be an integer.`);
73434
73515
  }
73435
- if (value < minimum) {
73436
- throw new RangeError(`${name} must be at least ${minimum}.`);
73516
+ if (value < -2147483648) {
73517
+ throw new RangeError(`${name} is below the supported integer range.`);
73437
73518
  }
73438
73519
  if (value > 2147483647) {
73439
73520
  throw new RangeError(`${name} exceeds the supported integer range.`);
@@ -73446,61 +73527,7 @@ function vector(value, name) {
73446
73527
  }
73447
73528
  return { x: integer2(value.x, `${name}.x`), y: integer2(value.y, `${name}.y`) };
73448
73529
  }
73449
- function exclusion(value) {
73450
- if (!Array.isArray(value) || value.length !== 1) {
73451
- throw new TypeError(
73452
- "excluding must select one NeoCellPatternExcluding option."
73453
- );
73454
- }
73455
- if (value[0] === NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS.None) return "none";
73456
- if (value[0] === NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS.Center)
73457
- return "center";
73458
- throw new RangeError("excluding is not a NeoCellPatternExcluding option.");
73459
- }
73460
- function reserve(ctx, count) {
73461
- if (!Number.isSafeInteger(count) || count < 0) {
73462
- throw new RangeError("Cell pattern contains too many offsets.");
73463
- }
73464
- ctx.reserveEntries(count);
73465
- }
73466
- function appendShell(result, radius, minX, maxX, minY, maxY) {
73467
- if (radius === 0) {
73468
- if (minX <= 0 && maxX >= 0 && minY <= 0 && maxY >= 0)
73469
- result.push({ x: 0, y: 0 });
73470
- return;
73471
- }
73472
- const firstY = Math.max(minY, -radius) || 0;
73473
- const lastY = Math.min(maxY, radius);
73474
- if (firstY > lastY) return;
73475
- if (-radius >= minX && -radius <= maxX) {
73476
- for (let y = firstY; y <= lastY; y++) result.push({ x: -radius, y });
73477
- }
73478
- const bottom = -radius >= minY && -radius <= maxY;
73479
- const top = radius !== 0 && radius >= minY && radius <= maxY;
73480
- if (bottom || top) {
73481
- const firstX = Math.max(minX, -radius + 1) || 0;
73482
- const lastX = Math.min(maxX, radius - 1);
73483
- for (let x2 = firstX; x2 <= lastX; x2++) {
73484
- if (bottom) result.push({ x: x2, y: -radius });
73485
- if (top) result.push({ x: x2, y: radius });
73486
- }
73487
- }
73488
- if (radius !== 0 && radius >= minX && radius <= maxX) {
73489
- for (let y = firstY; y <= lastY; y++) result.push({ x: radius, y });
73490
- }
73491
- }
73492
- function rectangle(ctx, minX, maxX, minY, maxY, excluding) {
73493
- const count = (maxX - minX + 1) * (maxY - minY + 1);
73494
- reserve(ctx, count - (excluding === "center" ? 1 : 0));
73495
- const offsets = [];
73496
- const radius = Math.max(-minX, maxX, -minY, maxY);
73497
- for (let shell = excluding === "center" ? 1 : 0; shell <= radius; shell++) {
73498
- appendShell(offsets, shell, minX, maxX, minY, maxY);
73499
- }
73500
- return offsets;
73501
- }
73502
- function translated(offsets, origin, ctx) {
73503
- reserve(ctx, offsets.length);
73530
+ function translated(offsets, origin) {
73504
73531
  return offsets.map((offset) => ({
73505
73532
  x: integer2(offset.x + origin.x, "Translated cell.x"),
73506
73533
  y: integer2(offset.y + origin.y, "Translated cell.y")
@@ -73517,57 +73544,7 @@ function evaluateCellPatternNative(memberId, receiver, args, ctx) {
73517
73544
  handled: true,
73518
73545
  value: ctx.constructPattern(offsets2)
73519
73546
  });
73520
- switch (memberId) {
73521
- case NEO_CELL_PATTERN_MEMBER_IDS.Box: {
73522
- const x2 = integer2(args[0], "Box radiusX", 0);
73523
- const y = args[1] === null ? x2 : integer2(args[1], "Box radiusY", 0);
73524
- return pattern(rectangle(ctx, -x2, x2, -y, y, exclusion(args[2])));
73525
- }
73526
- case NEO_CELL_PATTERN_MEMBER_IDS.Cross: {
73527
- const x2 = integer2(args[0], "Cross radiusX", 0);
73528
- const y = args[1] === null ? x2 : integer2(args[1], "Cross radiusY", 0);
73529
- const excluding = exclusion(args[2]);
73530
- reserve(ctx, 2 * (x2 + y) + (excluding === "none" ? 1 : 0));
73531
- const offsets2 = excluding === "none" ? [{ x: 0, y: 0 }] : [];
73532
- for (let distance = 1; distance <= Math.max(x2, y); distance++) {
73533
- if (distance <= x2)
73534
- offsets2.push({ x: -distance, y: 0 }, { x: distance, y: 0 });
73535
- if (distance <= y)
73536
- offsets2.push({ x: 0, y: -distance }, { x: 0, y: distance });
73537
- }
73538
- return pattern(offsets2);
73539
- }
73540
- case NEO_CELL_PATTERN_MEMBER_IDS.Ring: {
73541
- const radius = integer2(args[0], "Ring radius", 0);
73542
- reserve(ctx, radius === 0 ? 1 : 8 * radius);
73543
- const offsets2 = [];
73544
- appendShell(offsets2, radius, -radius, radius, -radius, radius);
73545
- return pattern(offsets2);
73546
- }
73547
- case NEO_CELL_PATTERN_MEMBER_IDS.Rect: {
73548
- const size = vector(args[0], "Rect size");
73549
- integer2(size.x, "Rect size.x", 1);
73550
- integer2(size.y, "Rect size.y", 1);
73551
- return pattern(rectangle(ctx, 0, size.x - 1, 0, size.y - 1, "none"));
73552
- }
73553
- case NEO_CELL_PATTERN_MEMBER_IDS.Line: {
73554
- const direction = vector(args[0], "Line direction");
73555
- if (isCenter(direction))
73556
- throw new RangeError("Line direction must be non-zero.");
73557
- const length = integer2(args[1], "Line length", 0);
73558
- const excluding = exclusion(args[2]);
73559
- reserve(ctx, length + (excluding === "none" ? 1 : 0));
73560
- integer2(direction.x * length, "Line endpoint.x");
73561
- integer2(direction.y * length, "Line endpoint.y");
73562
- const offsets2 = excluding === "none" ? [{ x: 0, y: 0 }] : [];
73563
- for (let step = 1; step <= length; step++) {
73564
- offsets2.push({ x: direction.x * step, y: direction.y * step });
73565
- }
73566
- return pattern(offsets2);
73567
- }
73568
- }
73569
73547
  const offsets = ctx.readPattern(receiver);
73570
- ctx.visitEntries(offsets.length);
73571
73548
  switch (memberId) {
73572
73549
  case NEO_CELL_PATTERN_MEMBER_IDS.Contains: {
73573
73550
  const offset = vector(args[0], "Contains offset");
@@ -73581,34 +73558,27 @@ function evaluateCellPatternNative(memberId, receiver, args, ctx) {
73581
73558
  case NEO_CELL_PATTERN_MEMBER_IDS.Cells:
73582
73559
  return {
73583
73560
  handled: true,
73584
- value: translated(offsets, vector(args[0], "Cells origin"), ctx)
73561
+ value: translated(offsets, vector(args[0], "Cells origin"))
73585
73562
  };
73586
73563
  case NEO_CELL_PATTERN_MEMBER_IDS.WithCenter:
73587
73564
  if (offsets.some(isCenter)) return { handled: true, value: receiver };
73588
- reserve(ctx, offsets.length + 1);
73589
73565
  return pattern([{ x: 0, y: 0 }, ...offsets]);
73590
- case NEO_CELL_PATTERN_MEMBER_IDS.WithoutCenter: {
73591
- let count = 0;
73592
- for (const offset of offsets) if (!isCenter(offset)) count++;
73593
- if (count === offsets.length) return { handled: true, value: receiver };
73594
- reserve(ctx, count);
73566
+ case NEO_CELL_PATTERN_MEMBER_IDS.WithoutCenter:
73567
+ if (!offsets.some(isCenter)) return { handled: true, value: receiver };
73595
73568
  return pattern(offsets.filter((offset) => !isCenter(offset)));
73596
- }
73597
73569
  case NEO_CELL_PATTERN_MEMBER_IDS.Translate: {
73598
73570
  const offset = vector(args[0], "Translate offset");
73599
73571
  if (isCenter(offset)) return { handled: true, value: receiver };
73600
- return pattern(translated(offsets, offset, ctx));
73572
+ return pattern(translated(offsets, offset));
73601
73573
  }
73602
73574
  case NEO_CELL_PATTERN_MEMBER_IDS.Union: {
73603
73575
  const other = ctx.readPattern(args[0]);
73604
- ctx.visitEntries(other.length);
73605
73576
  const seen = /* @__PURE__ */ new Set();
73606
73577
  const result = [];
73607
73578
  for (const source of [offsets, other]) {
73608
73579
  for (const offset of source) {
73609
73580
  const key = `${offset.x},${offset.y}`;
73610
73581
  if (seen.has(key)) continue;
73611
- reserve(ctx, 1);
73612
73582
  seen.add(key);
73613
73583
  result.push(offset);
73614
73584
  }
@@ -74094,6 +74064,9 @@ function timestamp(value) {
74094
74064
  if (typeof value === "string") return Date.parse(value) || 0;
74095
74065
  return 0;
74096
74066
  }
74067
+ function shiftedOrigin(placement, shift) {
74068
+ return shift === null ? placement.cell : translated2(placement.cell, shift);
74069
+ }
74097
74070
  function translated2(cell, offset) {
74098
74071
  return {
74099
74072
  x: checkedCoordinate(cell.x + offset.x),
@@ -74196,29 +74169,44 @@ var init_world_grid_query = __esm({
74196
74169
  );
74197
74170
  return matches[0];
74198
74171
  }
74199
- objects(placement, offsets, reads, reserveResults) {
74172
+ /** `shift` moves the whole pattern; null queries around the placement cell. */
74173
+ objects(placement, offsets, reads, shift = null) {
74200
74174
  reads?.add({ kind: "placement", valueId: placement.valueId });
74175
+ const origin = shiftedOrigin(placement, shift);
74201
74176
  const result = [];
74202
74177
  for (const offset of offsets) {
74203
- const cell = translated2(placement.cell, offset);
74178
+ const cell = translated2(origin, offset);
74204
74179
  reads?.add({ kind: "objects", gridId: placement.gridId, cell });
74205
74180
  for (const item of this.objectsAt(placement.gridId, cell)) {
74206
- reserveResults?.(1);
74207
74181
  result.push(item.valueId);
74208
74182
  }
74209
74183
  }
74210
74184
  return result;
74211
74185
  }
74212
- tile(placement, offsets, reads) {
74186
+ tile(placement, offsets, reads, shift = null) {
74213
74187
  reads?.add({ kind: "placement", valueId: placement.valueId });
74188
+ const origin = shiftedOrigin(placement, shift);
74214
74189
  let result = null;
74215
74190
  for (const offset of offsets) {
74216
- const cell = translated2(placement.cell, offset);
74191
+ const cell = translated2(origin, offset);
74217
74192
  reads?.add({ kind: "tile", gridId: placement.gridId, cell });
74218
74193
  result ??= this.tileAt(placement.gridId, cell);
74219
74194
  }
74220
74195
  return result;
74221
74196
  }
74197
+ /** One tile per occupied pattern cell, in pattern order. */
74198
+ tiles(placement, offsets, reads, shift = null) {
74199
+ reads?.add({ kind: "placement", valueId: placement.valueId });
74200
+ const origin = shiftedOrigin(placement, shift);
74201
+ const result = [];
74202
+ for (const offset of offsets) {
74203
+ const cell = translated2(origin, offset);
74204
+ reads?.add({ kind: "tile", gridId: placement.gridId, cell });
74205
+ const tile = this.tileAt(placement.gridId, cell);
74206
+ if (tile !== null) result.push(tile.placementValueId);
74207
+ }
74208
+ return result;
74209
+ }
74222
74210
  /** Stable dependency value: unrelated cells and non-geometric payload edits compare equal. */
74223
74211
  signature(read) {
74224
74212
  if (read.kind === "placement") {
@@ -74991,7 +74979,8 @@ function blankEvaluatorIndexes(memberByValueId) {
74991
74979
  indexedVirtualRowSets: /* @__PURE__ */ new WeakSet(),
74992
74980
  ownedValueAttachmentsByValueId: /* @__PURE__ */ new Map(),
74993
74981
  constructorOwnershipDirtyValueIds: /* @__PURE__ */ new Set(),
74994
- memberByRowId: /* @__PURE__ */ new Map()
74982
+ memberByRowId: /* @__PURE__ */ new Map(),
74983
+ invalidated: false
74995
74984
  };
74996
74985
  }
74997
74986
  function createEvaluatorBaseIndexBuild(members, values, valueById) {
@@ -75200,7 +75189,7 @@ function layerEvaluatorLookups(base, overlay) {
75200
75189
  }
75201
75190
  function evaluatorIndexes(ctx) {
75202
75191
  const overlayRevision = ctx.__valueOverlay instanceof LazyValueOverlay ? ctx.__valueOverlay.revision : void 0;
75203
- if (ctx.__indexes !== void 0 && ctx.__indexes.overlayRevision === overlayRevision) {
75192
+ if (ctx.__indexes !== void 0 && !ctx.__indexes.invalidated && ctx.__indexes.overlayRevision === overlayRevision) {
75204
75193
  syncLazyOverlayReferences(ctx.__indexes, ctx.__valueOverlay);
75205
75194
  return ctx.__indexes;
75206
75195
  }
@@ -75235,7 +75224,8 @@ function evaluatorIndexes(ctx) {
75235
75224
  indexedVirtualRowSets: /* @__PURE__ */ new WeakSet(),
75236
75225
  ownedValueAttachmentsByValueId: /* @__PURE__ */ new Map(),
75237
75226
  constructorOwnershipDirtyValueIds: /* @__PURE__ */ new Set(),
75238
- memberByRowId: /* @__PURE__ */ new Map()
75227
+ memberByRowId: /* @__PURE__ */ new Map(),
75228
+ invalidated: false
75239
75229
  };
75240
75230
  if (base === void 0) {
75241
75231
  for (const member of ctx.vm.members) {
@@ -75559,13 +75549,21 @@ function resolveRuntimeReferenceRow(sourceValueId, ctx, withProvenance) {
75559
75549
  );
75560
75550
  }
75561
75551
  function invalidateEvaluatorIndexes(ctx, changedValue) {
75562
- if (ctx.__valueOverlay instanceof LazyValueOverlay) {
75563
- const overlay = ctx.__valueOverlay;
75564
- const constructionLocal = changedValue !== void 0 && (ctx.__executionState?.constructionStack.length ?? 0) > 0 && !overlay.isSourceValueReference(changedValue);
75565
- overlay.markMutated(changedValue !== null && !constructionLocal);
75566
- }
75552
+ markOverlayMutated(ctx, changedValue);
75553
+ if (ctx.__indexes !== void 0) ctx.__indexes.invalidated = true;
75567
75554
  ctx.__indexes = void 0;
75568
75555
  }
75556
+ function markOverlayMutated(ctx, changedValue) {
75557
+ if (!(ctx.__valueOverlay instanceof LazyValueOverlay)) return;
75558
+ const overlay = ctx.__valueOverlay;
75559
+ const constructionLocal = changedValue !== void 0 && (ctx.__executionState?.constructionStack.length ?? 0) > 0 && !overlay.isSourceValueReference(changedValue);
75560
+ overlay.markMutated(changedValue !== null && !constructionLocal);
75561
+ }
75562
+ function forgetLocalListIndexes(ctx, list) {
75563
+ ctx.__setEntryIndexes?.delete(list);
75564
+ ctx.__indexes?.listIdentityByArray.delete(list);
75565
+ ctx.__indexes?.declaredListByArray.delete(list);
75566
+ }
75569
75567
  function trackedRowForValueReference(value, ctx) {
75570
75568
  if (typeof value !== "object" || value === null) return null;
75571
75569
  const indexes3 = evaluatorIndexes(ctx);
@@ -75624,7 +75622,7 @@ function pushConstructionFrame(ctx, label) {
75624
75622
  "Class construction requires an effect-capable evaluator Session scope."
75625
75623
  );
75626
75624
  }
75627
- consumeBudget(ctx, "workUnits", 1, "work unit");
75625
+ checkDeadline(ctx);
75628
75626
  if (state.constructionStack.length >= MAX_CONSTRUCTION_DEPTH) {
75629
75627
  const chain = [...state.constructionStack, label].join(" -> ");
75630
75628
  throw new NSGetterRuntimeError(
@@ -75891,12 +75889,6 @@ function exportInitializerCollections(created, writes, ctx) {
75891
75889
  createdValues: [encoded, ...children],
75892
75890
  declarationByValueId: declarations
75893
75891
  });
75894
- consumeBudget(
75895
- ctx,
75896
- "constructedSessionRows",
75897
- children.length,
75898
- "constructed Session row"
75899
- );
75900
75892
  for (const child2 of children) {
75901
75893
  if (!isLiteralValueContent(child2)) {
75902
75894
  throw new NSGetterRuntimeError(
@@ -75946,7 +75938,7 @@ function evaluateNSGetterWithEffects(getter, ctx, argumentValues = [], options =
75946
75938
  const ownsInvocationState = ctx.__executionState === void 0;
75947
75939
  const requestedWrites = [];
75948
75940
  const runtimeCtx = withEvaluationRuntime(ctx, requestedWrites);
75949
- consumeBudget(runtimeCtx, "workUnits", 1, "work unit");
75941
+ checkDeadline(runtimeCtx);
75950
75942
  const writes = runtimeCtx.__executionState?.writes ?? requestedWrites;
75951
75943
  const writeCheckpoint = writes.length;
75952
75944
  const creationCheckpoint = sessionCreationCheckpoint(runtimeCtx);
@@ -76006,6 +75998,13 @@ function evaluateNSGetterWithEffects(getter, ctx, argumentValues = [], options =
76006
75998
  const rootIndex = created.findIndex(
76007
75999
  (row) => row.value === result.value
76008
76000
  );
76001
+ if (initializerResult !== void 0 && rootIndex === -1) {
76002
+ assertExportedPlacement(
76003
+ result.value,
76004
+ initializerResult.member,
76005
+ runtimeCtx
76006
+ );
76007
+ }
76009
76008
  const exported2 = exportInitializerCollections(
76010
76009
  created,
76011
76010
  writes,
@@ -76060,11 +76059,17 @@ function evaluateNSGetterWithEffects(getter, ctx, argumentValues = [], options =
76060
76059
  finalizeConstructorAllocations(runtimeCtx, void 0, ownsInvocationState);
76061
76060
  throw new NSGetterRuntimeError("Function ended without a return statement");
76062
76061
  }
76062
+ function assertExportedPlacement(value, member, ctx) {
76063
+ if (!isMemberClassBase(member) && !isMemberWithEntries(member)) return;
76064
+ const existing = trackedRowForValueReference(value, ctx);
76065
+ if (existing === null) return;
76066
+ assertInitializerPlacement(existing.id, member, ctx);
76067
+ }
76063
76068
  function evaluateNSVoidBody(action, ctx, options = {}) {
76064
76069
  const ownsInvocationState = ctx.__executionState === void 0;
76065
76070
  const requestedWrites = [];
76066
76071
  const runtimeCtx = withEvaluationRuntime(ctx, requestedWrites);
76067
- consumeBudget(runtimeCtx, "workUnits", 1, "work unit");
76072
+ checkDeadline(runtimeCtx);
76068
76073
  const writes = runtimeCtx.__executionState?.writes ?? requestedWrites;
76069
76074
  const writeCheckpoint = writes.length;
76070
76075
  const creationCheckpoint = sessionCreationCheckpoint(runtimeCtx);
@@ -76127,7 +76132,7 @@ function evaluateNSFunction(action, ctx, args) {
76127
76132
  const ownsInvocationState = ctx.__executionState === void 0;
76128
76133
  const requestedWrites = [];
76129
76134
  const runtimeCtx = withEvaluationRuntime(ctx, requestedWrites);
76130
- consumeBudget(runtimeCtx, "workUnits", 1, "work unit");
76135
+ checkDeadline(runtimeCtx);
76131
76136
  const writes = runtimeCtx.__executionState?.writes ?? requestedWrites;
76132
76137
  const writeCheckpoint = writes.length;
76133
76138
  const creationCheckpoint = sessionCreationCheckpoint(runtimeCtx);
@@ -76265,63 +76270,15 @@ function withEvaluationRuntime(ctx, writes) {
76265
76270
  constructionTimestamp: Date.now(),
76266
76271
  ownedValueAttachments: /* @__PURE__ */ new Map(),
76267
76272
  constructionStack: [],
76268
- openConstructions: /* @__PURE__ */ new Map(),
76269
- loopIterations: 0,
76270
- budgetedConstructedRowIds: /* @__PURE__ */ new Set(),
76271
- budgetedProducedEntriesByRowId: /* @__PURE__ */ new Map(),
76272
- budget: ctx.sharedExecutionBudget ?? createNeoScriptExecutionBudget(ctx.executionBudgetLimits)
76273
+ openConstructions: /* @__PURE__ */ new Map()
76273
76274
  },
76274
76275
  __indexes: ctx.__executionState === void 0 || ctx.__valueOverlay === void 0 ? void 0 : ctx.__indexes
76275
76276
  };
76276
76277
  }
76277
- function createNeoScriptExecutionBudget(requested) {
76278
- const limits = { ...DEFAULT_NEO_SCRIPT_EXECUTION_BUDGET_LIMITS };
76279
- for (const key of Object.keys(limits)) {
76280
- const value = requested?.[key];
76281
- if (value === void 0) continue;
76282
- if (!Number.isSafeInteger(value)) {
76283
- throw new NeoScriptResourceLimitError(
76284
- `NeoScript ${key} limit must be a safe integer.`
76285
- );
76286
- }
76287
- if (value < 0) {
76288
- throw new NeoScriptResourceLimitError(
76289
- `NeoScript ${key} limit must not be negative.`
76290
- );
76291
- }
76292
- if (value > DEFAULT_NEO_SCRIPT_EXECUTION_BUDGET_LIMITS[key]) {
76293
- throw new NeoScriptResourceLimitError(
76294
- `NeoScript ${key} limit cannot exceed the safety ceiling of ${DEFAULT_NEO_SCRIPT_EXECUTION_BUDGET_LIMITS[key]}.`
76295
- );
76296
- }
76297
- limits[key] = value;
76298
- }
76299
- return {
76300
- limits,
76301
- workUnits: 0,
76302
- collectionVisits: 0,
76303
- producedCollectionEntries: 0,
76304
- constructedSessionRows: 0,
76305
- producedStringCharacters: 0
76306
- };
76307
- }
76308
- function consumeBudget(ctx, counter, amount, label) {
76278
+ function checkDeadline(ctx) {
76309
76279
  if (ctx.wallClockDeadlineMs !== void 0 && Date.now() >= ctx.wallClockDeadlineMs) {
76310
76280
  throw new NeoScriptWallClockTimeoutError();
76311
76281
  }
76312
- const budget = ctx.__executionState?.budget;
76313
- if (budget === void 0) {
76314
- throw new NSGetterRuntimeError(
76315
- "NeoScript work executed without a shared execution budget."
76316
- );
76317
- }
76318
- const limit = budget.limits[counter];
76319
- if (amount > limit - budget[counter]) {
76320
- throw new NeoScriptResourceLimitError(
76321
- `NeoScript ${label} limit of ${limit} exceeded.`
76322
- );
76323
- }
76324
- budget[counter] += amount;
76325
76282
  }
76326
76283
  function staticBindingMap(bindings) {
76327
76284
  if (bindings === void 0) return /* @__PURE__ */ new Map();
@@ -76960,21 +76917,6 @@ function createTopLevelScope(ctx) {
76960
76917
  );
76961
76918
  return scope;
76962
76919
  }
76963
- function consumeLoopIteration(ctx) {
76964
- const state = ctx.__executionState;
76965
- if (state === void 0) {
76966
- throw new NSGetterRuntimeError(
76967
- "NeoScript loop executed without a shared execution state."
76968
- );
76969
- }
76970
- if (state.loopIterations >= MAX_LOOP_ITERATIONS) {
76971
- throw new NeoScriptResourceLimitError(
76972
- `NeoScript loop iteration limit of ${MAX_LOOP_ITERATIONS} exceeded.`
76973
- );
76974
- }
76975
- state.loopIterations += 1;
76976
- consumeBudget(ctx, "workUnits", 1, "work unit");
76977
- }
76978
76920
  function synchronizeExistingBindings(parent, child2, bindingIds) {
76979
76921
  for (const bindingId of bindingIds) {
76980
76922
  parent.setLocal(bindingId, child2.get(bindingId));
@@ -77179,7 +77121,7 @@ function positionNeoScriptFrame(ctx, position) {
77179
77121
  function evalInstructions(instructions, scope, ctx, options) {
77180
77122
  for (const ins of instructions) {
77181
77123
  try {
77182
- consumeBudget(ctx, "workUnits", 1, "work unit");
77124
+ checkDeadline(ctx);
77183
77125
  switch (ins.type) {
77184
77126
  case "debug" /* debug */: {
77185
77127
  const condition = ins.condition === void 0 ? false : evalPointer(ins.condition, scope, ctx);
@@ -77348,7 +77290,7 @@ function evalInstructions(instructions, scope, ctx, options) {
77348
77290
  let firstIteration = ins.type === "doWhile" /* doWhile */;
77349
77291
  while (firstIteration || evalBooleanExpression(ins.condition, scope, ctx)) {
77350
77292
  firstIteration = false;
77351
- consumeLoopIteration(ctx);
77293
+ checkDeadline(ctx);
77352
77294
  const result = evalInstructionsInChildScope(
77353
77295
  ins.instructions,
77354
77296
  scope,
@@ -77371,7 +77313,7 @@ function evalInstructions(instructions, scope, ctx, options) {
77371
77313
  );
77372
77314
  loopScope.setLocal(ins.initializer.id, initialValue);
77373
77315
  while (evalBooleanExpression(ins.condition, loopScope, ctx)) {
77374
- consumeLoopIteration(ctx);
77316
+ checkDeadline(ctx);
77375
77317
  const result = evalInstructionsInChildScope(
77376
77318
  ins.instructions,
77377
77319
  loopScope,
@@ -77399,7 +77341,7 @@ function evalInstructions(instructions, scope, ctx, options) {
77399
77341
  );
77400
77342
  try {
77401
77343
  for (const rawEntry of membership) {
77402
- consumeLoopIteration(ctx);
77344
+ checkDeadline(ctx);
77403
77345
  loopScope.setLocal(
77404
77346
  ins.binding.id,
77405
77347
  coerceAssignmentValue(
@@ -78021,9 +77963,8 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
78021
77963
  ctx.__valueOverlay
78022
77964
  );
78023
77965
  if (row !== null) {
78024
- row.value = value;
77966
+ replaceRowValue(row, value, receiver, ctx);
78025
77967
  updateUnorderedListProjectionAfterAssignment(row, value, ctx);
78026
- invalidateEvaluatorIndexes(ctx, receiver);
78027
77968
  return;
78028
77969
  }
78029
77970
  }
@@ -78059,15 +78000,28 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
78059
78000
  ctx.__valueOverlay
78060
78001
  );
78061
78002
  if (row !== null) {
78062
- row.value = value;
78003
+ replaceRowValue(row, value, receiver, ctx);
78063
78004
  updateUnorderedListProjectionAfterAssignment(row, value, ctx);
78064
- invalidateEvaluatorIndexes(ctx, receiver);
78065
78005
  return;
78066
78006
  }
78067
78007
  }
78068
78008
  object2[stringKey] = value;
78069
78009
  invalidateEvaluatorIndexes(ctx, receiver);
78070
78010
  }
78011
+ function replaceRowValue(row, value, receiver, ctx) {
78012
+ const indexes3 = ctx.__indexes;
78013
+ if (indexes3 === void 0 || ctx.__runtimeSessionValues?.get(row.id) !== row || !indexes3.indexedRowIds.has(row.id)) {
78014
+ row.value = value;
78015
+ invalidateEvaluatorIndexes(ctx, receiver);
78016
+ return;
78017
+ }
78018
+ unindexEvaluatorRow(indexes3, row, true);
78019
+ row.value = value;
78020
+ indexEvaluatorRow(indexes3, row, true);
78021
+ markOverlayMutated(ctx, receiver);
78022
+ if (ctx.__valueOverlay instanceof LazyValueOverlay)
78023
+ indexes3.overlayRevision = ctx.__valueOverlay.revision;
78024
+ }
78071
78025
  function applyOverlayStaticAssignment(memberId, value, ctx) {
78072
78026
  const member = evalMemberById(ctx.vm, memberId);
78073
78027
  if (member === null || !isStaticMember(member)) {
@@ -78307,7 +78261,7 @@ function resolvedDestinationFieldsForContainer(targetValue, ctx) {
78307
78261
  return containerValueId === null ? {} : { resolvedDestination: { containerValueId } };
78308
78262
  }
78309
78263
  function dispatchNSSetter(target, value, scope, ctx, writes) {
78310
- consumeBudget(ctx, "workUnits", 1, "work unit");
78264
+ checkDeadline(ctx);
78311
78265
  if (target.type !== "callGetter" /* callGetter */) {
78312
78266
  throw new NSGetterRuntimeError(
78313
78267
  "Setter write target must be a callGetter pointer."
@@ -78435,14 +78389,6 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
78435
78389
  if (ins.mutation === "Remove" /* Remove */ && setEntryMember !== null && setMatch === null) {
78436
78390
  return;
78437
78391
  }
78438
- if (ins.mutation === "Add" /* Add */ || ins.mutation === "Insert" /* Insert */) {
78439
- consumeBudget(
78440
- ctx,
78441
- "producedCollectionEntries",
78442
- 1,
78443
- "produced collection entry"
78444
- );
78445
- }
78446
78392
  if (mutatesLocalVariable && variablePointer !== null) {
78447
78393
  if (isLookupSet && (ins.mutation === "Add" /* Add */ || ins.mutation === "Remove" /* Remove */)) {
78448
78394
  args[0] = lookupSetSelectionValue(args[0], ins.target.typeInfo, ctx);
@@ -78462,8 +78408,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
78462
78408
  removedIndex2,
78463
78409
  ctx
78464
78410
  );
78465
- if (Array.isArray(targetValue)) ctx.__setEntryIndexes?.delete(targetValue);
78466
- invalidateEvaluatorIndexes(ctx, targetValue);
78411
+ if (Array.isArray(targetValue)) forgetLocalListIndexes(ctx, targetValue);
78467
78412
  scope.setLocal(variablePointer.variableId, targetValue);
78468
78413
  return;
78469
78414
  }
@@ -78488,8 +78433,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
78488
78433
  overlayArgs[0] = createUnorderedScalarProjectionEntry(
78489
78434
  unorderedContainerValueId,
78490
78435
  args[0],
78491
- ctx,
78492
- false
78436
+ ctx
78493
78437
  );
78494
78438
  }
78495
78439
  const unorderedEntriesBeforeMutation = unorderedContainerValueId === null || !Array.isArray(targetValue) || ins.mutation === "Add" /* Add */ ? null : [...targetValue];
@@ -78661,7 +78605,6 @@ function storedSetEntries(set, entryMember, ctx) {
78661
78605
  const indexes3 = ctx.__setEntryIndexes ??= /* @__PURE__ */ new WeakMap();
78662
78606
  const existing = indexes3.get(set);
78663
78607
  if (existing !== void 0) return existing;
78664
- consumeBudget(ctx, "collectionVisits", set.length, "collection visit");
78665
78608
  const entries = /* @__PURE__ */ new Map();
78666
78609
  for (const raw of set) {
78667
78610
  const match = storedSetEntryMatch(raw, entryMember, ctx);
@@ -78697,12 +78640,6 @@ function applyLocalCollectionMutation(targetValue, mutation, args, ctx, unique =
78697
78640
  case "Insert" /* Insert */: {
78698
78641
  const list = listArg(targetValue, "Insert target");
78699
78642
  const index = numberArg(args[0], "Insert index");
78700
- consumeBudget(
78701
- ctx,
78702
- "collectionVisits",
78703
- list.length - index,
78704
- "collection visit"
78705
- );
78706
78643
  list.splice(index, 0, args[1]);
78707
78644
  return index;
78708
78645
  }
@@ -78711,7 +78648,6 @@ function applyLocalCollectionMutation(targetValue, mutation, args, ctx, unique =
78711
78648
  let alreadyPresent = false;
78712
78649
  if (unique) {
78713
78650
  for (const entry of targetValue) {
78714
- consumeBudget(ctx, "collectionVisits", 1, "collection visit");
78715
78651
  if (reference2 ? referenceEqual(entry, args[0], ctx) : jsEqual(entry, args[0])) {
78716
78652
  alreadyPresent = true;
78717
78653
  break;
@@ -78729,7 +78665,6 @@ function applyLocalCollectionMutation(targetValue, mutation, args, ctx, unique =
78729
78665
  if (Array.isArray(targetValue)) {
78730
78666
  let index = -1;
78731
78667
  for (let candidate = 0; candidate < targetValue.length; candidate += 1) {
78732
- consumeBudget(ctx, "collectionVisits", 1, "collection visit");
78733
78668
  const entry = targetValue[candidate];
78734
78669
  if (reference2) {
78735
78670
  if (referenceEqual(entry, args[0], ctx)) {
@@ -78763,17 +78698,10 @@ function applyLocalCollectionMutation(targetValue, mutation, args, ctx, unique =
78763
78698
  }
78764
78699
  case "Clear" /* Clear */:
78765
78700
  if (Array.isArray(targetValue)) {
78766
- consumeBudget(
78767
- ctx,
78768
- "collectionVisits",
78769
- targetValue.length,
78770
- "collection visit"
78771
- );
78772
78701
  targetValue.length = 0;
78773
78702
  return null;
78774
78703
  }
78775
78704
  const keys = Object.keys(objectArg(targetValue, "Clear target"));
78776
- consumeBudget(ctx, "collectionVisits", keys.length, "collection visit");
78777
78705
  for (const key of keys) {
78778
78706
  delete objectArg(targetValue, "Clear target")[key];
78779
78707
  }
@@ -79060,20 +78988,8 @@ function evalPointerCore(pointer, scope, ctx, resultUsage = "value") {
79060
78988
  case "function" /* function */:
79061
78989
  return evalFunction(pointer.function, scope, ctx);
79062
78990
  case "listLiteral" /* listLiteral */:
79063
- consumeBudget(
79064
- ctx,
79065
- "producedCollectionEntries",
79066
- pointer.entries.length,
79067
- "produced collection entry"
79068
- );
79069
78991
  return pointer.entries.map((e) => evalPointer(e, scope, ctx));
79070
78992
  case "dictLiteral" /* dictLiteral */: {
79071
- consumeBudget(
79072
- ctx,
79073
- "producedCollectionEntries",
79074
- pointer.entries.length,
79075
- "produced collection entry"
79076
- );
79077
78993
  const out = {};
79078
78994
  for (const e of pointer.entries) {
79079
78995
  const k = evalPointer(e.key, scope, ctx);
@@ -79139,7 +79055,7 @@ function evalPointerCore(pointer, scope, ctx, resultUsage = "value") {
79139
79055
  }
79140
79056
  const args = fillCallableCallSiteArguments(suppliedArgs, member, ctx);
79141
79057
  const interceptedMemberId = member?.id ?? pointer.memberId ?? pointer.memberKey ?? pointer.callSiteId;
79142
- consumeBudget(ctx, "workUnits", 1, "work unit");
79058
+ checkDeadline(ctx);
79143
79059
  const intercepted = ctx.callInterceptor?.({
79144
79060
  resultUsage,
79145
79061
  memberId: interceptedMemberId,
@@ -79282,7 +79198,7 @@ function evalPointerCore(pointer, scope, ctx, resultUsage = "value") {
79282
79198
  case "callAction" /* callAction */: {
79283
79199
  const read = readActionWithOwner(pointer.action, scope, ctx);
79284
79200
  const args = pointer.args.map((arg) => evalPointer(arg, scope, ctx));
79285
- consumeBudget(ctx, "workUnits", 1, "work unit");
79201
+ checkDeadline(ctx);
79286
79202
  invokeActionListeners(
79287
79203
  actionListenersOf(
79288
79204
  read.action,
@@ -79340,12 +79256,6 @@ function evalPointerCore(pointer, scope, ctx, resultUsage = "value") {
79340
79256
  case "stringify" /* stringify */: {
79341
79257
  const v = evalPointer(pointer.pointer, scope, ctx);
79342
79258
  const formatted = formatForInterp(v, pointer.sourceType, ctx);
79343
- consumeBudget(
79344
- ctx,
79345
- "producedStringCharacters",
79346
- formatted.length,
79347
- "produced string character"
79348
- );
79349
79259
  return formatted;
79350
79260
  }
79351
79261
  }
@@ -79473,7 +79383,7 @@ function invokeDelegateValue(value, args, ctx, callSiteId, ownerReceiver, result
79473
79383
  ].join(" -> ")}.`
79474
79384
  );
79475
79385
  }
79476
- consumeBudget(ctx, "workUnits", 1, "work unit");
79386
+ checkDeadline(ctx);
79477
79387
  const intercept = () => ctx.callInterceptor?.({
79478
79388
  resultUsage,
79479
79389
  memberId: member.id,
@@ -80867,7 +80777,7 @@ function createUnorderedListProjectionCache() {
80867
80777
  referenceEntryKeysByRecord: /* @__PURE__ */ new WeakMap()
80868
80778
  };
80869
80779
  }
80870
- function createUnorderedScalarProjectionEntry(containerValueId, value, ctx, consumeEntryBudget = true) {
80780
+ function createUnorderedScalarProjectionEntry(containerValueId, value, ctx) {
80871
80781
  const container = evalValueById(
80872
80782
  ctx,
80873
80783
  containerValueId,
@@ -80879,14 +80789,6 @@ function createUnorderedScalarProjectionEntry(containerValueId, value, ctx, cons
80879
80789
  `Unordered List container '${containerValueId}' is missing.`
80880
80790
  );
80881
80791
  }
80882
- if (consumeEntryBudget) {
80883
- consumeBudget(
80884
- ctx,
80885
- "producedCollectionEntries",
80886
- 1,
80887
- "produced collection entry"
80888
- );
80889
- }
80890
80792
  ctx.beforeValueAllocation?.();
80891
80793
  const now = Date.now();
80892
80794
  const row = {
@@ -81274,9 +81176,16 @@ function readCellPattern(value, ctx) {
81274
81176
  }
81275
81177
  return offsets;
81276
81178
  }
81179
+ function readGridQueryOffset(value) {
81180
+ if (value === void 0 || value === null) return null;
81181
+ if (!isVector2IntValue(value)) {
81182
+ throw new NSGetterRuntimeError("Grid query offset must be a Vector2Int.");
81183
+ }
81184
+ return value;
81185
+ }
81277
81186
  function evaluateSystemNative(memberId, receiver, args, ctx) {
81278
81187
  try {
81279
- if (memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetCell || memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetObjects || memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetTile) {
81188
+ if (memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetCell || memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetObjects || memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetTile || memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetTiles) {
81280
81189
  const receiverRow = trackedRowForValueReference(receiver, ctx);
81281
81190
  if (receiverRow === null) {
81282
81191
  throw new NSGetterRuntimeError(
@@ -81291,21 +81200,31 @@ function evaluateSystemNative(memberId, receiver, args, ctx) {
81291
81200
  if (memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetCell)
81292
81201
  return { handled: true, value: { ...placement.cell } };
81293
81202
  const offsets = readCellPattern(args[0], ctx);
81203
+ const shift = readGridQueryOffset(args[1]);
81294
81204
  if (memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetObjects) {
81295
81205
  const value = index.objects(
81296
81206
  placement,
81297
81207
  offsets,
81298
81208
  ctx.worldQueryDependencies,
81299
- (count) => consumeBudget(
81300
- ctx,
81301
- "producedCollectionEntries",
81302
- count,
81303
- "collection entry"
81304
- )
81209
+ shift
81210
+ );
81211
+ return { handled: true, value };
81212
+ }
81213
+ if (memberId === NEO_OBJECT_GRID_MEMBER_IDS.GetTiles) {
81214
+ const value = index.tiles(
81215
+ placement,
81216
+ offsets,
81217
+ ctx.worldQueryDependencies,
81218
+ shift
81305
81219
  );
81306
81220
  return { handled: true, value };
81307
81221
  }
81308
- const tile = index.tile(placement, offsets, ctx.worldQueryDependencies);
81222
+ const tile = index.tile(
81223
+ placement,
81224
+ offsets,
81225
+ ctx.worldQueryDependencies,
81226
+ shift
81227
+ );
81309
81228
  if (tile === null) return { handled: true, value: null };
81310
81229
  const row = evalValueById(
81311
81230
  ctx,
@@ -81353,14 +81272,7 @@ function evaluateSystemNative(memberId, receiver, args, ctx) {
81353
81272
  },
81354
81273
  createTopLevelScope(ctx),
81355
81274
  ctx
81356
- ),
81357
- reserveEntries: (count) => consumeBudget(
81358
- ctx,
81359
- "producedCollectionEntries",
81360
- count,
81361
- "collection entry"
81362
- ),
81363
- visitEntries: (count) => consumeBudget(ctx, "collectionVisits", count, "collection visit")
81275
+ )
81364
81276
  });
81365
81277
  } catch (error) {
81366
81278
  if (error instanceof RangeError || error instanceof TypeError || error instanceof WorldGridQueryError) {
@@ -81432,22 +81344,10 @@ function applyArithmetic(op, operands, decimal2, ctx, numeric) {
81432
81344
  }
81433
81345
  if (op === "+" /* addition */ && operands.every((o) => typeof o === "string")) {
81434
81346
  const result = operands.join("");
81435
- consumeBudget(
81436
- ctx,
81437
- "producedStringCharacters",
81438
- result.length,
81439
- "produced string character"
81440
- );
81441
81347
  return result;
81442
81348
  }
81443
81349
  if (op === "+" /* addition */ && operands.some((o) => typeof o === "string")) {
81444
81350
  const result = operands.map((o) => stringifyForInterp(o)).join("");
81445
- consumeBudget(
81446
- ctx,
81447
- "producedStringCharacters",
81448
- result.length,
81449
- "produced string character"
81450
- );
81451
81351
  return result;
81452
81352
  }
81453
81353
  const numbers = operands.map((o) => {
@@ -81712,12 +81612,6 @@ function evalListRepeat(info, scope, ctx) {
81712
81612
  `List.Repeat count must be non-negative; got ${count}.`
81713
81613
  );
81714
81614
  }
81715
- consumeBudget(
81716
- ctx,
81717
- "producedCollectionEntries",
81718
- count,
81719
- "produced collection entry"
81720
- );
81721
81615
  return new Array(count).fill(value);
81722
81616
  }
81723
81617
  function stringifyForInterp(v) {
@@ -82025,7 +81919,7 @@ function prepareCollectionCallback(callback, parentScope, ctx, isList, returnCon
82025
81919
  if (ctx.__collectionCallbackStrategy === "fresh" || ctx.__collectionCallbackStrategy === "prepared") {
82026
81920
  return (entry, key, valueId) => {
82027
81921
  if (onPredicateMatch !== void 0) {
82028
- consumeBudget(ctx, "workUnits", 1, "work unit");
81922
+ checkDeadline(ctx);
82029
81923
  }
82030
81924
  const boundEntry = coerceAssignmentValue(
82031
81925
  entry,
@@ -82088,14 +81982,14 @@ function prepareCollectionCallback(callback, parentScope, ctx, isList, returnCon
82088
81982
  }
82089
81983
  if (requiresInvocationReset) {
82090
81984
  return (entry, key, valueId) => {
82091
- consumeBudget(ctx, "workUnits", 1, "work unit");
81985
+ checkDeadline(ctx);
82092
81986
  innerScope.resetInvocationLocals(parameterCount);
82093
81987
  bindValues(entry, key);
82094
81988
  return finishBody(innerScope) === true ? onPredicateMatch(entry, key, valueId) : 0 /* Continue */;
82095
81989
  };
82096
81990
  }
82097
81991
  return (entry, key, valueId) => {
82098
- consumeBudget(ctx, "workUnits", 1, "work unit");
81992
+ checkDeadline(ctx);
82099
81993
  bindValues(entry, key);
82100
81994
  return finishBody(innerScope) === true ? onPredicateMatch(entry, key, valueId) : 0 /* Continue */;
82101
81995
  };
@@ -82164,7 +82058,7 @@ function evalCollectionQuery(info, scope, ctx) {
82164
82058
  ) : null;
82165
82059
  const invoke = (entry, key, valueId) => {
82166
82060
  if (!callback) return true;
82167
- consumeBudget(ctx, "workUnits", 1, "work unit");
82061
+ checkDeadline(ctx);
82168
82062
  return callback(entry, key, valueId);
82169
82063
  };
82170
82064
  if (info.op === "Any" || info.op === "All" || info.op === "Last" || info.op === "LastOrDefault" || info.op === "Single" || info.op === "SingleOrDefault") {
@@ -82200,12 +82094,6 @@ function evalCollectionQuery(info, scope, ctx) {
82200
82094
  const output = [];
82201
82095
  let references = /* @__PURE__ */ new Set();
82202
82096
  const append2 = (entry, _key, valueId) => {
82203
- consumeBudget(
82204
- ctx,
82205
- "producedCollectionEntries",
82206
- 1,
82207
- "produced collection entry"
82208
- );
82209
82097
  if (valueId !== null && !info.enumEntries) references.add(output.length);
82210
82098
  output.push(collectionQueryEntry(entry, valueId, info.enumEntries));
82211
82099
  return 0 /* Continue */;
@@ -82222,12 +82110,6 @@ function evalCollectionQuery(info, scope, ctx) {
82222
82110
  let entries = [];
82223
82111
  iterateCollection(collection, ctx, (entry, key, valueId) => {
82224
82112
  const sortKey = invoke(entry, key, valueId);
82225
- consumeBudget(
82226
- ctx,
82227
- "producedCollectionEntries",
82228
- 1,
82229
- "produced collection entry"
82230
- );
82231
82113
  entries.push({ entry, valueId, key: sortKey });
82232
82114
  return 0 /* Continue */;
82233
82115
  });
@@ -82241,7 +82123,6 @@ function evalCollectionQuery(info, scope, ctx) {
82241
82123
  for (let destination = start; destination < end; destination++) {
82242
82124
  let useLeft = right >= end;
82243
82125
  if (left < middle && right < end) {
82244
- consumeBudget(ctx, "workUnits", 1, "work unit");
82245
82126
  const order = compareCollectionKeys(
82246
82127
  entries[left].key,
82247
82128
  entries[right].key,
@@ -82584,32 +82465,14 @@ function evalFunction(fn, scope, ctx) {
82584
82465
  switch (fn.info.op) {
82585
82466
  case "toLower": {
82586
82467
  const result = receiver.toLowerCase();
82587
- consumeBudget(
82588
- ctx,
82589
- "producedStringCharacters",
82590
- result.length,
82591
- "produced string character"
82592
- );
82593
82468
  return result;
82594
82469
  }
82595
82470
  case "toUpper": {
82596
82471
  const result = receiver.toUpperCase();
82597
- consumeBudget(
82598
- ctx,
82599
- "producedStringCharacters",
82600
- result.length,
82601
- "produced string character"
82602
- );
82603
82472
  return result;
82604
82473
  }
82605
82474
  case "trim": {
82606
82475
  const result = receiver.trim();
82607
- consumeBudget(
82608
- ctx,
82609
- "producedStringCharacters",
82610
- result.length,
82611
- "produced string character"
82612
- );
82613
82476
  return result;
82614
82477
  }
82615
82478
  case "replace": {
@@ -82639,32 +82502,7 @@ function evalFunction(fn, scope, ctx) {
82639
82502
  throw new NSGetterRuntimeError(
82640
82503
  "string.Replace search must not be empty."
82641
82504
  );
82642
- let count = 0;
82643
- let offset = 0;
82644
- let match = receiver.indexOf(search, offset);
82645
- while (match !== -1) {
82646
- consumeBudget(ctx, "workUnits", 1, "work unit");
82647
- count++;
82648
- offset = match + search.length;
82649
- match = receiver.indexOf(search, offset);
82650
- }
82651
- consumeBudget(
82652
- ctx,
82653
- "producedStringCharacters",
82654
- receiver.length + count * (replacement.length - search.length),
82655
- "produced string character"
82656
- );
82657
- if (count === 0) return receiver;
82658
- const parts = [];
82659
- offset = 0;
82660
- match = receiver.indexOf(search, offset);
82661
- while (match !== -1) {
82662
- parts.push(receiver.slice(offset, match), replacement);
82663
- offset = match + search.length;
82664
- match = receiver.indexOf(search, offset);
82665
- }
82666
- parts.push(receiver.slice(offset));
82667
- return parts.join("");
82505
+ return receiver.split(search).join(replacement);
82668
82506
  }
82669
82507
  case "startsWith":
82670
82508
  case "endsWith": {
@@ -82698,12 +82536,6 @@ function evalFunction(fn, scope, ctx) {
82698
82536
  isList,
82699
82537
  "predicate",
82700
82538
  (entry, key, valueId) => {
82701
- consumeBudget(
82702
- ctx,
82703
- "producedCollectionEntries",
82704
- 1,
82705
- "produced collection entry"
82706
- );
82707
82539
  if (isList) {
82708
82540
  if (valueId !== null) {
82709
82541
  referenceEntryIndexes.add(out.length);
@@ -82777,14 +82609,8 @@ function evalFunction(fn, scope, ctx) {
82777
82609
  );
82778
82610
  const out = [];
82779
82611
  iterateCollection(c, ctx, (entry, key, valueId) => {
82780
- consumeBudget(ctx, "workUnits", 1, "work unit");
82612
+ checkDeadline(ctx);
82781
82613
  const value = callback(entry, key, valueId);
82782
- consumeBudget(
82783
- ctx,
82784
- "producedCollectionEntries",
82785
- 1,
82786
- "produced collection entry"
82787
- );
82788
82614
  out.push(value);
82789
82615
  return 0 /* Continue */;
82790
82616
  });
@@ -83336,31 +83162,6 @@ function publishConstructedRows(args) {
83336
83162
  "Class construction requires an effect-capable evaluator Session scope."
83337
83163
  );
83338
83164
  }
83339
- let newlyConstructedRows = 0;
83340
- let newlyProducedEntries = 0;
83341
- for (const row of createdValues) {
83342
- if (!state.budgetedConstructedRowIds.has(row.id)) {
83343
- state.budgetedConstructedRowIds.add(row.id);
83344
- newlyConstructedRows += 1;
83345
- }
83346
- const currentEntries = Array.isArray(row.value) ? row.value.length : typeof row.value === "object" && row.value !== null ? Object.keys(row.value).length : 0;
83347
- const priorEntries = state.budgetedProducedEntriesByRowId.get(row.id) ?? 0;
83348
- if (currentEntries <= priorEntries) continue;
83349
- newlyProducedEntries += currentEntries - priorEntries;
83350
- state.budgetedProducedEntriesByRowId.set(row.id, currentEntries);
83351
- }
83352
- consumeBudget(
83353
- ctx,
83354
- "constructedSessionRows",
83355
- newlyConstructedRows,
83356
- "constructed Session row"
83357
- );
83358
- consumeBudget(
83359
- ctx,
83360
- "producedCollectionEntries",
83361
- newlyProducedEntries,
83362
- "produced collection entry"
83363
- );
83364
83165
  const retained = retainedIds;
83365
83166
  if (beforeRetain !== null) {
83366
83167
  for (const rowId of beforeRetain) {
@@ -84177,6 +83978,11 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
84177
83978
  existingValueRow
84178
83979
  };
84179
83980
  }
83981
+ if (existingValueRow !== null && (isMemberClassBase(member) || isMemberWithEntries(member)) && argumentValues.some(
83982
+ (argument2) => trackedRowForValueReference(argument2, ctx)?.id === existingValueRow.id
83983
+ )) {
83984
+ assertInitializerPlacement(existingValueRow.id, member, ctx);
83985
+ }
84180
83986
  if (existingValueRow !== null && existingRuntimeClassId !== null && isMemberClassBase(member)) {
84181
83987
  const storage = constructorArgumentStorage(existingValueRow.id, ctx);
84182
83988
  if (storage !== 3 /* Session */) {
@@ -84881,7 +84687,6 @@ function applyVariantDeclarativeHalves(instance, graph, ctx, answeredValueIds) {
84881
84687
  }
84882
84688
  const entries = listRow.value;
84883
84689
  if (!Array.isArray(entries)) return;
84884
- consumeBudget(ctx, "workUnits", entries.length, "work unit");
84885
84690
  for (const entryId of entries) {
84886
84691
  if (typeof entryId !== "string") continue;
84887
84692
  const entryRow = evalValueById(
@@ -85022,7 +84827,6 @@ function collectVariantDeclarativeAnsweredSlots(instance, graph, ctx) {
85022
84827
  );
85023
84828
  }
85024
84829
  if (!Array.isArray(listRow.value)) return slots;
85025
- consumeBudget(ctx, "workUnits", listRow.value.length, "work unit");
85026
84830
  for (const entryId of listRow.value) {
85027
84831
  if (typeof entryId !== "string") continue;
85028
84832
  const entryRow = evalValueById(
@@ -85060,7 +84864,6 @@ function collectVariantDeclarativeAnsweredSlots(instance, graph, ctx) {
85060
84864
  return slots;
85061
84865
  }
85062
84866
  function evalVariantInitialize(info, scope, ctx) {
85063
- consumeBudget(ctx, "workUnits", 1, "work unit");
85064
84867
  const selection2 = readVariantSelection(
85065
84868
  evalPointer(info.variantPointer, scope, ctx),
85066
84869
  "Variant.Initialize receiver"
@@ -85117,7 +84920,6 @@ function evalVariantInitialize(info, scope, ctx) {
85117
84920
  }
85118
84921
  }
85119
84922
  function evalVariantApply(info, scope, ctx) {
85120
- consumeBudget(ctx, "workUnits", 1, "work unit");
85121
84923
  const receiver = evalPointer(info.receiverPointer, scope, ctx);
85122
84924
  if (receiver === null || receiver === void 0) {
85123
84925
  throw new NSGetterRuntimeError(
@@ -85235,6 +85037,15 @@ function constructDeclaredClassValue(info, scope, ctx) {
85235
85037
  closeFrame();
85236
85038
  }
85237
85039
  }
85040
+ function positionAtPassingArgument(error, info, record7, argumentValues, ctx) {
85041
+ if (error.attachedValueId === void 0 || record7 === null) return;
85042
+ const index = argumentValues.findIndex(
85043
+ (value) => findKnownRowIdByValueReference(value, ctx) === error.attachedValueId
85044
+ );
85045
+ const name = record7.argumentTypes[index]?.name;
85046
+ const argument2 = info.args.find((candidate) => candidate.name === name);
85047
+ if (argument2 !== void 0) error.at(argument2.valuePointer);
85048
+ }
85238
85049
  function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope, ctx) {
85239
85050
  const schemaClass2 = descriptor.schemaClass;
85240
85051
  const classId = schemaClass2.id;
@@ -85277,7 +85088,10 @@ function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope
85277
85088
  root.classId = classId;
85278
85089
  stampConstructedRootGenericBindings(root, descriptor);
85279
85090
  } catch (error) {
85280
- if (error instanceof NSGetterRuntimeError) throw error;
85091
+ if (error instanceof NSGetterRuntimeError) {
85092
+ positionAtPassingArgument(error, info, record7, argumentValues, ctx);
85093
+ throw error;
85094
+ }
85281
85095
  throw new NSGetterRuntimeError(
85282
85096
  `Failed to construct '${schemaClass2.name}': ${error instanceof Error ? error.message : String(error)}`
85283
85097
  );
@@ -85440,9 +85254,11 @@ function assertOwnedValueAttachable(valueId, destination, destinationName2, ctx,
85440
85254
  }
85441
85255
  for (const owner of currentOwnedValueAttachments(valueId, ctx)) {
85442
85256
  if (mode === "assign" && owner.identity === destination.identity) continue;
85443
- throw new NSGetterRuntimeError(
85257
+ const error = new NSGetterRuntimeError(
85444
85258
  `Aggregate value '${valueId}' is already owned by parent value '${owner.label}' and cannot be attached to '${destinationName2}'. Call Clone() explicitly.`
85445
85259
  );
85260
+ error.attachedValueId = valueId;
85261
+ throw error;
85446
85262
  }
85447
85263
  const reserved = ctx.__executionState?.ownedValueAttachments.get(valueId);
85448
85264
  if (reserved !== void 0 && (mode === "insert" || reserved.identity !== destination.identity)) {
@@ -85467,6 +85283,16 @@ function assertOwnedValueAttachable(valueId, destination, destinationName2, ctx,
85467
85283
  }
85468
85284
  recordConstructorGroupDependency(valueId, destination, ctx);
85469
85285
  }
85286
+ function assertInitializerPlacement(valueId, member, ctx) {
85287
+ const replayRowId = ctx.__storedConstructionReplayRowId;
85288
+ const memberId = Reflect.get(member, "id");
85289
+ const schemaKey = replayRowId === void 0 || typeof memberId !== "string" ? null : cachedSchemaKeyForMember(memberId, ctx);
85290
+ const destination = schemaKey === null ? { identity: `initializer:${member.name}`, label: member.name } : {
85291
+ identity: `value:${replayRowId}:slot:${schemaKey}`,
85292
+ label: member.name
85293
+ };
85294
+ assertOwnedValueAttachable(valueId, destination, member.name, ctx);
85295
+ }
85470
85296
  function currentOwnedValueAttachments(valueId, ctx) {
85471
85297
  const indexes3 = evaluatorIndexes(ctx);
85472
85298
  const cached = indexes3.ownedValueAttachmentsByValueId.get(valueId);
@@ -85528,7 +85354,7 @@ function currentOwnedValueAttachments(valueId, ctx) {
85528
85354
  if (parent.id === valueId) continue;
85529
85355
  let member = null;
85530
85356
  let classId = parent.classId;
85531
- if (classId === void 0) {
85357
+ if (classId === void 0 || classId === null) {
85532
85358
  member = activeStaticBindingRoot(parent.id, ctx)?.member ?? memberForValueRow(parent, ctx);
85533
85359
  if (member !== null) {
85534
85360
  try {
@@ -86574,7 +86400,6 @@ function collectionLength(c) {
86574
86400
  function snapshotCollectionMembership(collection, ctx) {
86575
86401
  const membership = [];
86576
86402
  const valid = forEachRawCollectionEntry(collection, (entry) => {
86577
- consumeBudget(ctx, "collectionVisits", 1, "collection visit");
86578
86403
  membership.push({
86579
86404
  raw: entry.raw,
86580
86405
  resolveAsReference: collectionEntryUsesReferenceResolution(
@@ -86619,7 +86444,6 @@ function forEachRawCollectionEntry(c, callback) {
86619
86444
  function collectionEntries(c, ctx) {
86620
86445
  const entries = [];
86621
86446
  forEachRawCollectionEntry(c, ({ raw, key }) => {
86622
- consumeBudget(ctx, "collectionVisits", 1, "collection visit");
86623
86447
  entries.push(resolveCollectionEntry(c, raw, key, ctx));
86624
86448
  return 0 /* Continue */;
86625
86449
  });
@@ -86629,7 +86453,6 @@ function referenceIndexOf(c, target, ctx) {
86629
86453
  const targetId = target === null || target === void 0 ? null : referenceIdOf(target, ctx);
86630
86454
  let found = null;
86631
86455
  forEachRawCollectionEntry(c, ({ raw, key }) => {
86632
- consumeBudget(ctx, "collectionVisits", 1, "collection visit");
86633
86456
  if (raw === target || targetId !== null && raw !== null && raw !== void 0 && referenceIdOf(raw, ctx) === targetId) {
86634
86457
  found = key;
86635
86458
  return 1 /* Break */;
@@ -86640,7 +86463,6 @@ function referenceIndexOf(c, target, ctx) {
86640
86463
  }
86641
86464
  function iterateCollection(c, ctx, callback) {
86642
86465
  forEachRawCollectionEntry(c, ({ raw, key, valueId }) => {
86643
- consumeBudget(ctx, "collectionVisits", 1, "collection visit");
86644
86466
  const effectiveValueId = collectionEntryUsesReferenceResolution(c, key, ctx) ? valueId : null;
86645
86467
  return callback(
86646
86468
  resolveCollectionEntry(c, raw, key, ctx),
@@ -86659,7 +86481,7 @@ function collectionEntryUsesReferenceResolution(collection, key, ctx) {
86659
86481
  );
86660
86482
  return referenceIndexes === void 0 || referenceIndexes.has(key);
86661
86483
  }
86662
- var DELEGATE_LEXICAL_THIS, DELEGATE_LEXICAL_ROOT, NonCatchableNSGetterRuntimeError, NativeFunctionDelegateUnavailableError, CorruptNeoScriptIRError, NeoScriptResourceLimitError, NeoScriptWallClockTimeoutError, DEFAULT_NEO_SCRIPT_EXECUTION_BUDGET_LIMITS, liveListIndexesByProject, evaluatorOwnershipCachesByBase, MAX_CONSTRUCTION_DEPTH, MAX_LOOP_ITERATIONS, resolutionCacheByMembers, NO_SCHEMA_REVISION, LazyValueOverlay, READONLY_FOREACH_BINDING_ERROR, READONLY_CATCH_BINDING_ERROR, DIALOGUE_CONTEXT_PARAMETER_ID, constantDeclarationRoots, NS_MATH_OP_NAMES, DOUBLE_INTEGRAL_MAGNITUDE, EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS;
86484
+ var DELEGATE_LEXICAL_THIS, DELEGATE_LEXICAL_ROOT, NonCatchableNSGetterRuntimeError, NativeFunctionDelegateUnavailableError, CorruptNeoScriptIRError, NeoScriptWallClockTimeoutError, liveListIndexesByProject, evaluatorOwnershipCachesByBase, MAX_CONSTRUCTION_DEPTH, resolutionCacheByMembers, NO_SCHEMA_REVISION, LazyValueOverlay, READONLY_FOREACH_BINDING_ERROR, READONLY_CATCH_BINDING_ERROR, DIALOGUE_CONTEXT_PARAMETER_ID, constantDeclarationRoots, NS_MATH_OP_NAMES, DOUBLE_INTEGRAL_MAGNITUDE, EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS;
86663
86485
  var init_evaluateNSGetter = __esm({
86664
86486
  "../packages/neoscript-runtime/src/neoscript/evaluateNSGetter.ts"() {
86665
86487
  "use strict";
@@ -86722,29 +86544,15 @@ var init_evaluateNSGetter = __esm({
86722
86544
  };
86723
86545
  CorruptNeoScriptIRError = class extends NonCatchableNSGetterRuntimeError {
86724
86546
  };
86725
- NeoScriptResourceLimitError = class extends NonCatchableNSGetterRuntimeError {
86726
- constructor(message) {
86727
- super(message);
86728
- this.name = "NeoScriptResourceLimitError";
86729
- }
86730
- };
86731
- NeoScriptWallClockTimeoutError = class extends NeoScriptResourceLimitError {
86547
+ NeoScriptWallClockTimeoutError = class extends NonCatchableNSGetterRuntimeError {
86732
86548
  constructor() {
86733
86549
  super("NeoScript wall-clock timeout exceeded.");
86734
86550
  this.name = "NeoScriptWallClockTimeoutError";
86735
86551
  }
86736
86552
  };
86737
- DEFAULT_NEO_SCRIPT_EXECUTION_BUDGET_LIMITS = Object.freeze({
86738
- workUnits: 1e5,
86739
- collectionVisits: 1e5,
86740
- producedCollectionEntries: 1e4,
86741
- constructedSessionRows: 4096,
86742
- producedStringCharacters: 1024 * 1024
86743
- });
86744
86553
  liveListIndexesByProject = /* @__PURE__ */ new WeakMap();
86745
86554
  evaluatorOwnershipCachesByBase = /* @__PURE__ */ new WeakMap();
86746
86555
  MAX_CONSTRUCTION_DEPTH = 64;
86747
- MAX_LOOP_ITERATIONS = 1e4;
86748
86556
  resolutionCacheByMembers = /* @__PURE__ */ new WeakMap();
86749
86557
  NO_SCHEMA_REVISION = [];
86750
86558
  LazyValueOverlay = class extends Map {
@@ -86965,7 +86773,17 @@ var init_effective_value_comparison = __esm({
86965
86773
  });
86966
86774
 
86967
86775
  // ../packages/neoscript-runtime/src/values/constructor-argument-ownership.ts
86968
- function resolveSemanticOwnerMembersForValues(document, targetValueIds, additionalRoots, rootOwners, rootKinds) {
86776
+ function recordEntries(value) {
86777
+ if (typeof value !== "object" || value === null) return [];
86778
+ return Object.values(value);
86779
+ }
86780
+ function resolveSemanticOwnerMembersForValues(document, targetValueIds, additionalRoots, rootOwners, rootKinds, graphOf = () => new MaterializedValueGraphContext(
86781
+ document,
86782
+ void 0,
86783
+ new Map(
86784
+ (additionalRoots ?? []).map((root) => [root.valueId, root.member])
86785
+ )
86786
+ )) {
86969
86787
  const result = /* @__PURE__ */ new Map();
86970
86788
  if (targetValueIds.size === 0) return result;
86971
86789
  const directRootOwners = /* @__PURE__ */ new Map();
@@ -86989,11 +86807,7 @@ function resolveSemanticOwnerMembersForValues(document, targetValueIds, addition
86989
86807
  }
86990
86808
  return result;
86991
86809
  }
86992
- const graph = new MaterializedValueGraphContext(
86993
- document,
86994
- new Map(document.values.map((value) => [value.id, value])),
86995
- new Map((additionalRoots ?? []).map((root) => [root.valueId, root.member]))
86996
- );
86810
+ const graph = graphOf();
86997
86811
  const allValueIds = new Set(graph.valuesById.keys());
86998
86812
  const semanticRoots = [
86999
86813
  ...additionalRoots ?? []
@@ -87312,6 +87126,7 @@ var init_constructor_argument_ownership = __esm({
87312
87126
  constructorsById;
87313
87127
  contextualRootMembersByValueId;
87314
87128
  parameterTypesByRow = /* @__PURE__ */ new WeakMap();
87129
+ argumentInteriorTypesById;
87315
87130
  settleConstructorParameter;
87316
87131
  aggregateTypeByTargetValueId = /* @__PURE__ */ new Map();
87317
87132
  ownership;
@@ -87388,13 +87203,16 @@ var init_constructor_argument_ownership = __esm({
87388
87203
  }
87389
87204
  return result;
87390
87205
  }
87391
- constructorEdges(row) {
87206
+ constructorEdges(row, contextualMember) {
87392
87207
  if (!isLiteralValueContent(row)) return [];
87393
87208
  if (row.constructorArgs === void 0 || row.constructorArgs === null) {
87394
87209
  return [];
87395
87210
  }
87396
87211
  const edges = [];
87397
- for (const [parameterId, typeInfo] of this.constructorParameterTypes(row)) {
87212
+ for (const [parameterId, typeInfo] of this.constructorParameterTypes(
87213
+ row,
87214
+ contextualMember
87215
+ )) {
87398
87216
  const targetValueId = row.constructorArgs[parameterId];
87399
87217
  if (typeof targetValueId !== "string") continue;
87400
87218
  if (!isAggregateTypeInfo(typeInfo)) continue;
@@ -87473,28 +87291,24 @@ var init_constructor_argument_ownership = __esm({
87473
87291
  if (!isLiteralValueContent(row)) {
87474
87292
  return { ...row, id: replacements.get(row.id) ?? row.id };
87475
87293
  }
87476
- const ownerId = args.ownerValueId ?? row.id;
87477
- const owner = args.owner ?? this.ownerForValue(ownerId);
87478
- const aggregateType = owner === void 0 ? this.aggregateTypeForRow(ownerId) : void 0;
87479
87294
  const rewriteId = (value2) => replacements.get(value2) ?? value2;
87480
87295
  let value = row.value;
87481
- if (owner !== void 0 || aggregateType !== void 0) {
87482
- if ((owner !== void 0 ? isMemberEntryCollectionBase(owner) : aggregateType === 6 /* List */ || aggregateType === 28 /* Set */) && Array.isArray(value)) {
87483
- value = value.map(
87484
- (entry) => typeof entry === "string" ? rewriteId(entry) : entry
87485
- );
87486
- } else if ((owner !== void 0 && (isMemberClassBase(owner) || isMemberDictionaryBase(owner)) || aggregateType === 7 /* Class */ || aggregateType === 22 /* Interface */ || aggregateType === 5 /* Dictionary */) && value !== null && typeof value === "object" && !Array.isArray(value)) {
87487
- value = Object.fromEntries(
87488
- Object.entries(value).map(([key, entry]) => [
87489
- key,
87490
- typeof entry === "string" ? rewriteId(entry) : entry
87491
- ])
87492
- );
87493
- } else if (owner?.kind === 9 /* Lookup */ && Array.isArray(value)) {
87494
- value = value.map(
87495
- (entry) => typeof entry === "string" ? rewriteId(entry) : entry
87496
- );
87497
- }
87296
+ const slots = this.referenceSlots(
87297
+ args.ownerValueId ?? row.id,
87298
+ args.owner,
87299
+ value
87300
+ );
87301
+ if (slots === 1 /* Entries */ && Array.isArray(value)) {
87302
+ value = value.map(
87303
+ (entry) => typeof entry === "string" ? rewriteId(entry) : entry
87304
+ );
87305
+ } else if (slots === 2 /* Fields */) {
87306
+ value = Object.fromEntries(
87307
+ Object.entries(value).map(([key, entry]) => [
87308
+ key,
87309
+ typeof entry === "string" ? rewriteId(entry) : entry
87310
+ ])
87311
+ );
87498
87312
  }
87499
87313
  const parameterTypes = this.constructorParameterTypes(row);
87500
87314
  const constructorArgs2 = row.constructorArgs === void 0 || row.constructorArgs === null ? row.constructorArgs : Object.fromEntries(
@@ -87524,11 +87338,101 @@ var init_constructor_argument_ownership = __esm({
87524
87338
  preservedValueIds
87525
87339
  );
87526
87340
  }
87341
+ /**
87342
+ * Row ids an indexed row names through its typed slots: body entries or
87343
+ * fields and aggregate constructor arguments. Leaf text that happens to
87344
+ * equal an id is not a reference.
87345
+ */
87346
+ referencedValueIds(row) {
87347
+ if (!isLiteralValueContent(row)) return [];
87348
+ const ids = [];
87349
+ for (const entry of this.slotEntries(row)) {
87350
+ if (typeof entry === "string") ids.push(entry);
87351
+ }
87352
+ for (const edge of this.edgesByOwnerValueId.get(row.id) ?? [])
87353
+ ids.push(edge.targetValueId);
87354
+ return ids;
87355
+ }
87356
+ slotEntries(row) {
87357
+ const value = row.value;
87358
+ switch (this.referenceSlots(row.id, void 0, value)) {
87359
+ case 1 /* Entries */:
87360
+ return Array.isArray(value) ? value : [];
87361
+ case 2 /* Fields */:
87362
+ return recordEntries(value);
87363
+ case 0 /* None */:
87364
+ return [];
87365
+ }
87366
+ }
87367
+ referenceSlots(ownerId, explicitOwner, value) {
87368
+ const owner = explicitOwner ?? this.ownerForValue(ownerId);
87369
+ const aggregateType = owner === void 0 ? this.aggregateTypeForRow(ownerId) : void 0;
87370
+ if (owner === void 0 && aggregateType === void 0)
87371
+ return 0 /* None */;
87372
+ if (Array.isArray(value)) {
87373
+ const entries = owner !== void 0 ? isMemberEntryCollectionBase(owner) || owner.kind === 9 /* Lookup */ : aggregateType === 6 /* List */ || aggregateType === 28 /* Set */;
87374
+ return entries ? 1 /* Entries */ : 0 /* None */;
87375
+ }
87376
+ if (typeof value !== "object" || value === null) return 0 /* None */;
87377
+ const fields = owner !== void 0 ? isMemberClassBase(owner) || isMemberDictionaryBase(owner) : aggregateType === 7 /* Class */ || aggregateType === 22 /* Interface */ || aggregateType === 5 /* Dictionary */;
87378
+ return fields ? 2 /* Fields */ : 0 /* None */;
87379
+ }
87527
87380
  aggregateTypeForRow(valueId) {
87528
87381
  if (typeof this.valuesById.get(valueId)?.classId === "string") {
87529
87382
  return 7 /* Class */;
87530
87383
  }
87531
- return this.aggregateTypeByTargetValueId.get(valueId);
87384
+ return this.aggregateTypeByTargetValueId.get(valueId) ?? this.argumentInteriorTypes().get(valueId);
87385
+ }
87386
+ /**
87387
+ * Aggregate kinds of rows nested inside constructor arguments, typed by the
87388
+ * declared argument type. A row two edges name is typed by the first: both
87389
+ * must agree on it.
87390
+ */
87391
+ argumentInteriorTypes() {
87392
+ if (this.argumentInteriorTypesById !== void 0)
87393
+ return this.argumentInteriorTypesById;
87394
+ const types = /* @__PURE__ */ new Map();
87395
+ const visit = (valueId, type) => {
87396
+ if (type === null || !isAggregateTypeInfo(type)) return;
87397
+ if (types.has(valueId)) return;
87398
+ types.set(valueId, type.type);
87399
+ const row = this.valuesById.get(valueId);
87400
+ if (row === void 0 || !isLiteralValueContent(row)) return;
87401
+ if (typeof row.classId === "string") {
87402
+ if (typeof row.value !== "object" || row.value === null) return;
87403
+ const body = row.value;
87404
+ const env = this.genericEnvironmentForRow(row);
87405
+ for (const entry of mergeInstanceSurfaceSchema(
87406
+ row.classId,
87407
+ this.document.classes,
87408
+ this.document.members
87409
+ )) {
87410
+ const childId = body[entry.schemaKey];
87411
+ const member = this.membersById.get(entry.memberId);
87412
+ if (typeof childId !== "string" || member === void 0) continue;
87413
+ visit(childId, this.memberTypeInfo(member, env));
87414
+ }
87415
+ return;
87416
+ }
87417
+ if (type.type === 7 /* Class */ || type.type === 22 /* Interface */)
87418
+ return;
87419
+ for (const entryId of this.collectionEntryIds(row, type.type)) {
87420
+ if (typeof entryId === "string") visit(entryId, type.entryTypeInfo);
87421
+ }
87422
+ };
87423
+ for (const edges of this.edgesByOwnerValueId.values())
87424
+ for (const edge of edges) visit(edge.targetValueId, edge.typeInfo);
87425
+ this.argumentInteriorTypesById = types;
87426
+ return types;
87427
+ }
87428
+ /** A collection row's entry ids: dictionary values, contained or listed. */
87429
+ collectionEntryIds(row, kind) {
87430
+ if (kind === 5 /* Dictionary */) {
87431
+ return recordEntries(row.value);
87432
+ }
87433
+ const contained = this.childrenByContainerId.get(row.id);
87434
+ if (contained !== void 0) return contained.map((entry) => entry.id);
87435
+ return Array.isArray(row.value) ? row.value : [];
87532
87436
  }
87533
87437
  resolveTypeInfo(rawTypeInfo, env) {
87534
87438
  if (rawTypeInfo.type === 21 /* Generic */) {
@@ -88367,7 +88271,7 @@ function claimVirtualIdentity(args) {
88367
88271
  virtualId: args.fixedVirtualId
88368
88272
  };
88369
88273
  }
88370
- const valueId = (sourceIdentity4) => args.instanceRootId.startsWith("__pending__:") || hasPendingVirtualSourceIdentity(sourceIdentity4) ? pendingVirtualValueId(args.instanceRootId, sourceIdentity4) : virtualValueId(args.instanceRootId, sourceIdentity4);
88274
+ const valueId = (sourceIdentity4) => derivedVirtualValueId(args.instanceRootId, sourceIdentity4);
88371
88275
  const derivedId = valueId(args.rawSourceIdentity);
88372
88276
  const claimedPath = args.claimedVirtualIds.get(derivedId);
88373
88277
  if (claimedPath === void 0 || claimedPath === args.pathKey) {
@@ -88379,6 +88283,9 @@ function claimVirtualIdentity(args) {
88379
88283
  args.claimedVirtualIds.set(virtualId, args.pathKey);
88380
88284
  return { sourceIdentity: sourceIdentity3, virtualId };
88381
88285
  }
88286
+ function derivedVirtualValueId(instanceRootId, sourceIdentity3) {
88287
+ return instanceRootId.startsWith("__pending__:") || hasPendingVirtualSourceIdentity(sourceIdentity3) ? pendingVirtualValueId(instanceRootId, sourceIdentity3) : virtualValueId(instanceRootId, sourceIdentity3);
88288
+ }
88382
88289
  function materializationReadTracking(recorder) {
88383
88290
  if (recorder === void 0)
88384
88291
  return { readTracking: void 0, trackMaterialization: (m) => m() };
@@ -88691,7 +88598,7 @@ function resolveVirtualInstanceGraph(args) {
88691
88598
  });
88692
88599
  if (!expansion.nodesByPath.has(childPath)) continue;
88693
88600
  const storedChildId = storedRecord[entry.schemaKey] ?? constructedChildren.get(entry.schemaKey) ?? null;
88694
- if (args.preserveUnloadedStoredChildren && storedChildId !== null && !materializedById.has(storedChildId)) {
88601
+ if (storedChildId !== null && !materializedById.has(storedChildId) && (typeof args.preserveUnloadedStoredChildren === "function" ? args.preserveUnloadedStoredChildren(storedChildId) : args.preserveUnloadedStoredChildren)) {
88695
88602
  effectiveRecord[entry.schemaKey] = storedChildId;
88696
88603
  continue;
88697
88604
  }
@@ -89102,12 +89009,149 @@ function resolveVirtualInstanceGraph(args) {
89102
89009
  ),
89103
89010
  normalizeLeafPayload(location3.virtualRow, location3.member)
89104
89011
  );
89012
+ let expandedEntryIdsByContainerId;
89013
+ const argumentChildren = (row, type) => {
89014
+ if (typeof row.classId === "string") {
89015
+ const body = stringRecord2(row.value);
89016
+ const env = materializedGraph.genericEnvironmentForRow(row);
89017
+ return resolvedClassSchema(
89018
+ row.classId,
89019
+ args.document.classes,
89020
+ args.document.members
89021
+ ).surface.flatMap((entry) => {
89022
+ const id2 = body[entry.schemaKey];
89023
+ const member = materializedGraph.memberForId(entry.memberId);
89024
+ if (id2 === void 0 || member === void 0) return [];
89025
+ return [
89026
+ {
89027
+ id: id2,
89028
+ segment: { kind: "class", schemaKey: entry.schemaKey },
89029
+ type: materializedGraph.typeInfoForMember(member, env)
89030
+ }
89031
+ ];
89032
+ });
89033
+ }
89034
+ if (type?.type === 5 /* Dictionary */) {
89035
+ const entryType2 = type.entryTypeInfo;
89036
+ return Object.entries(stringRecord2(row.value)).map(([key, id2]) => ({
89037
+ id: id2,
89038
+ segment: { kind: "dictionary", key },
89039
+ type: entryType2
89040
+ }));
89041
+ }
89042
+ if (type?.type !== 6 /* List */ && type?.type !== 28 /* Set */)
89043
+ return [];
89044
+ const entryType = type.entryTypeInfo;
89045
+ expandedEntryIdsByContainerId ??= buildUnorderedListMembershipIndex(
89046
+ args.expandedRows
89047
+ );
89048
+ const entries = expandedEntryIdsByContainerId.get(row.id) ?? (Array.isArray(row.value) ? row.value : []);
89049
+ return entries.flatMap(
89050
+ (id2, index) => typeof id2 === "string" ? [{ id: id2, segment: { kind: "list", index }, type: entryType }] : []
89051
+ );
89052
+ };
89053
+ const constructionArguments = (location3) => {
89054
+ const node = expansion.nodesByPath.get(location3.pathKey);
89055
+ if (node === void 0) return null;
89056
+ const owner = node.expandedRow;
89057
+ const pending = [];
89058
+ const enqueueArguments = (row, path, member) => {
89059
+ const edges = materializedGraph.constructorEdges(row, member);
89060
+ for (const edge of edges)
89061
+ pending.push({
89062
+ id: edge.targetValueId,
89063
+ path: appendVirtualValuePath(path, {
89064
+ kind: "class",
89065
+ schemaKey: `@constructor:${edge.parameterId}`
89066
+ }),
89067
+ type: edge.typeInfo
89068
+ });
89069
+ return edges;
89070
+ };
89071
+ const ownerEdges = enqueueArguments(owner, ROOT_PATH, node.member);
89072
+ if (ownerEdges.length === 0) return null;
89073
+ const ids = /* @__PURE__ */ new Map();
89074
+ const aliasedValueIds = [];
89075
+ const argumentRows = [];
89076
+ for (let index = 0; index < pending.length; index += 1) {
89077
+ const { id: id2, path, type } = pending[index];
89078
+ if (ids.has(id2)) continue;
89079
+ const aliased = expansion.nodesByExpandedId.get(id2);
89080
+ if (aliased !== void 0) {
89081
+ const target = locationsByPath.get(aliased.pathKey);
89082
+ if (target === void 0) continue;
89083
+ ids.set(id2, target.id);
89084
+ aliasedValueIds.push(target.id);
89085
+ continue;
89086
+ }
89087
+ const row = expansion.rowsByExpandedId.get(id2);
89088
+ if (row === void 0) continue;
89089
+ const argumentId = derivedVirtualValueId(
89090
+ location3.instanceRootId,
89091
+ `${location3.sourceIdentity}:${path}`
89092
+ );
89093
+ ids.set(id2, argumentId);
89094
+ const bodyIds = /* @__PURE__ */ new Set();
89095
+ for (const child2 of argumentChildren(row, type)) {
89096
+ bodyIds.add(child2.id);
89097
+ pending.push({
89098
+ id: child2.id,
89099
+ path: appendVirtualValuePath(path, child2.segment),
89100
+ type: child2.type
89101
+ });
89102
+ }
89103
+ argumentRows.push({
89104
+ row,
89105
+ id: argumentId,
89106
+ edges: enqueueArguments(row, path),
89107
+ bodyIds
89108
+ });
89109
+ }
89110
+ const retargetArguments = (row, edges) => {
89111
+ const stored = literalRow(row).constructorArgs;
89112
+ if (stored == null || edges.length === 0) return stored;
89113
+ const next = { ...stored };
89114
+ for (const edge of edges)
89115
+ next[edge.parameterId] = ids.get(edge.targetValueId) ?? edge.targetValueId;
89116
+ return next;
89117
+ };
89118
+ const retargetBody = (value, bodyIds) => {
89119
+ if (bodyIds.size === 0) return value;
89120
+ const retarget = (entry) => typeof entry === "string" && bodyIds.has(entry) ? ids.get(entry) ?? entry : entry;
89121
+ if (Array.isArray(value)) return value.map(retarget);
89122
+ return Object.fromEntries(
89123
+ Object.entries(value).map(
89124
+ ([key, entry]) => [key, retarget(entry)]
89125
+ )
89126
+ );
89127
+ };
89128
+ return {
89129
+ constructorArgs: retargetArguments(owner, ownerEdges) ?? {},
89130
+ rows: argumentRows.map(({ row, id: id2, edges, bodyIds }) => {
89131
+ const create = createFromRow(
89132
+ literalRow(row),
89133
+ id2,
89134
+ retargetBody(row.value, bodyIds)
89135
+ );
89136
+ const constructorArgs2 = retargetArguments(row, edges);
89137
+ return {
89138
+ ...create,
89139
+ ...constructorArgs2 === void 0 ? {} : { constructorArgs: constructorArgs2 },
89140
+ ...create.containerId === void 0 ? {} : {
89141
+ containerId: ids.get(create.containerId) ?? create.containerId
89142
+ }
89143
+ };
89144
+ }),
89145
+ aliasedValueIds
89146
+ };
89147
+ };
89105
89148
  return {
89106
89149
  instanceRootId: args.instanceRoot.id,
89107
89150
  ...listenerDefaultsByOwner === void 0 ? {} : { listenerDefaultsByOwner },
89108
89151
  pinnedRootSchemaKeys: args.pinnedRootSchemaKeys,
89109
89152
  compareCreationProvenance,
89110
89153
  compareLeafContent,
89154
+ constructionArguments,
89111
89155
  rowsById,
89112
89156
  locationsById,
89113
89157
  locationsByPath,
@@ -89202,6 +89246,7 @@ function prepareStoredClassValueResolution(args) {
89202
89246
  expandedRows: expanded.rows,
89203
89247
  pinnedRootSchemaKeys: expanded.pinnedRootSchemaKeys,
89204
89248
  materializedIndex: args.materializedIndex,
89249
+ preserveUnloadedStoredChildren: args.preserveUnloadedStoredChildren,
89205
89250
  readRecorder: args.readRecorder
89206
89251
  };
89207
89252
  }
@@ -89465,6 +89510,10 @@ function virtualWriteGraph(graph) {
89465
89510
  compareLeafContent: (location3) => {
89466
89511
  const local = graph.locationsById.get(location3.id);
89467
89512
  return local === void 0 ? parent.compareLeafContent(location3) : graph.compareLeafContent(local);
89513
+ },
89514
+ constructionArguments: (location3) => {
89515
+ const local = graph.locationsById.get(location3.id);
89516
+ return local === void 0 ? parent.constructionArguments(location3) : graph.constructionArguments(local);
89468
89517
  }
89469
89518
  };
89470
89519
  }
@@ -89474,6 +89523,61 @@ function planVirtualOverrideWrite(args) {
89474
89523
  ...args,
89475
89524
  graph: virtualWriteGraph(args.graph)
89476
89525
  });
89526
+ const plan = planSparseOverrideWrite(args);
89527
+ storeConstructionArguments(args.graph, plan.creates, args);
89528
+ return plan;
89529
+ }
89530
+ function storeConstructionArguments(graph, creates, update) {
89531
+ const createdIds = new Set(creates.map((create) => create.id));
89532
+ for (let index = 0; index < creates.length; index += 1) {
89533
+ const create = creates[index];
89534
+ if (create.constructorArgs == null) continue;
89535
+ if (create.id === update.valueId && update.constructorArgs !== void 0)
89536
+ continue;
89537
+ const location3 = graph.locationsById.get(create.id);
89538
+ if (location3 === void 0) continue;
89539
+ const construction = graph.constructionArguments(location3);
89540
+ if (construction === null) continue;
89541
+ creates[index] = {
89542
+ ...create,
89543
+ constructorArgs: construction.constructorArgs
89544
+ };
89545
+ for (const row of construction.rows) {
89546
+ if (createdIds.has(row.id)) continue;
89547
+ createdIds.add(row.id);
89548
+ creates.push(row);
89549
+ }
89550
+ for (const aliasedId of construction.aliasedValueIds) {
89551
+ const aliased = graph.locationsById.get(aliasedId);
89552
+ if (aliased === void 0) continue;
89553
+ if (aliased.materializedRow !== null || createdIds.has(aliased.id))
89554
+ continue;
89555
+ const subtree = [aliased];
89556
+ for (let next = 0; next < subtree.length; next += 1) {
89557
+ const entry = subtree[next];
89558
+ for (const childPath of graph.childPathsByParentPath.get(
89559
+ entry.pathKey
89560
+ ) ?? []) {
89561
+ const child2 = graph.locationsByPath.get(childPath);
89562
+ if (child2 !== void 0) subtree.push(child2);
89563
+ }
89564
+ if (entry.materializedRow !== null || createdIds.has(entry.id))
89565
+ continue;
89566
+ const effective = graph.rowsById.get(entry.id);
89567
+ if (effective === void 0) {
89568
+ throw new Error(
89569
+ `Constructor argument alias cannot resolve row "${entry.id}" at ${entry.pathKey}.`
89570
+ );
89571
+ }
89572
+ createdIds.add(entry.id);
89573
+ creates.push(
89574
+ createFromVirtual(entry, deepClonePlainData(effective.value))
89575
+ );
89576
+ }
89577
+ }
89578
+ }
89579
+ }
89580
+ function planSparseOverrideWrite(args) {
89477
89581
  const target = args.graph.locationsById.get(args.valueId);
89478
89582
  if (target === void 0) {
89479
89583
  throw new Error(
@@ -90081,6 +90185,12 @@ function sparsifyConstructedInstance(args) {
90081
90185
  const updatedValueById = new Map(
90082
90186
  plan.updates.map((update) => [update.valueId, update.value])
90083
90187
  );
90188
+ restoreRowsRetainedRowsName(
90189
+ materializedGraph,
90190
+ materializedRows,
90191
+ updatedValueById,
90192
+ deletedIds
90193
+ );
90084
90194
  const retainedRows = materializedRows.filter(
90085
90195
  (row) => !deletedIds.has(row.id)
90086
90196
  );
@@ -90129,14 +90239,6 @@ function sparsifyConstructedInstance(args) {
90129
90239
  ) ?? virtualId
90130
90240
  );
90131
90241
  }
90132
- const remap = (value) => {
90133
- if (typeof value === "string") return nextIdById.get(value) ?? value;
90134
- if (Array.isArray(value)) return value.map(remap);
90135
- if (typeof value !== "object" || value === null) return value;
90136
- return Object.fromEntries(
90137
- Object.entries(value).map(([key, entry]) => [key, remap(entry)])
90138
- );
90139
- };
90140
90242
  const remapReceiver = (id2) => {
90141
90243
  const retainedId = nextIdById.get(id2);
90142
90244
  if (retainedId !== void 0) return retainedId;
@@ -90147,18 +90249,35 @@ function sparsifyConstructedInstance(args) {
90147
90249
  receiver.sourceIdentity
90148
90250
  ) ?? receiver.virtualRow.id;
90149
90251
  };
90252
+ let constructedOwners;
90253
+ const constructedOwner = (valueId) => {
90254
+ constructedOwners ??= resolveOwnerMembersForValues(
90255
+ constructionDocument,
90256
+ new Set(retainedRows.map((row) => row.id)),
90257
+ [
90258
+ {
90259
+ member: resolveMember(args.rootMember, args.document.members),
90260
+ valueId: args.constructed.root.id
90261
+ }
90262
+ ]
90263
+ );
90264
+ return constructedOwners.get(valueId);
90265
+ };
90150
90266
  const rewrite = (row) => {
90151
90267
  const literal3 = literalRow(row);
90152
90268
  const payload = updatedValueById.get(row.id) ?? literal3.value;
90153
- const member = graph.locationsById.get(row.id)?.member ?? materializedGraph.ownerForValue(row.id);
90154
- const value = member?.kind === 25 /* NSDelegate */ && isMemberDelegateTarget(payload) ? remapMemberDelegateReceiver(payload, remapReceiver) : remap(payload);
90269
+ const member = graph.locationsById.get(row.id)?.member ?? materializedGraph.ownerForValue(row.id) ?? constructedOwner(row.id);
90270
+ const rewritten = materializedGraph.rewriteReferences({
90271
+ row: { ...literal3, value: payload },
90272
+ replacements: nextIdById,
90273
+ ...member === void 0 ? {} : { owner: member }
90274
+ });
90275
+ const value = member?.kind === 25 /* NSDelegate */ && isMemberDelegateTarget(payload) ? remapMemberDelegateReceiver(payload, remapReceiver) : rewritten.value;
90155
90276
  return {
90156
90277
  ...literal3,
90157
90278
  id: nextIdById.get(row.id) ?? row.id,
90158
90279
  value,
90159
- ...literal3.constructorArgs === void 0 ? {} : {
90160
- constructorArgs: remap(literal3.constructorArgs)
90161
- },
90280
+ ...literal3.constructorArgs === void 0 ? {} : { constructorArgs: literalRow(rewritten).constructorArgs },
90162
90281
  ...typeof row.containerId === "string" ? { containerId: nextIdById.get(row.containerId) ?? row.containerId } : {}
90163
90282
  };
90164
90283
  };
@@ -90168,6 +90287,28 @@ function sparsifyConstructedInstance(args) {
90168
90287
  }
90169
90288
  return { root, createdChildren };
90170
90289
  }
90290
+ function restoreRowsRetainedRowsName(materializedGraph, rows, updatedValueById, deletedIds) {
90291
+ if (deletedIds.size === 0) return;
90292
+ const rowsById = new Map(rows.map((row) => [row.id, row]));
90293
+ let entriesByContainerId;
90294
+ const pending = rows.filter((row) => !deletedIds.has(row.id));
90295
+ const restore = (valueId) => {
90296
+ const row = rowsById.get(valueId);
90297
+ if (row === void 0 || !deletedIds.delete(valueId)) return;
90298
+ pending.push(row);
90299
+ };
90300
+ for (let index = 0; index < pending.length; index += 1) {
90301
+ const row = literalRow(pending[index]);
90302
+ const updated = updatedValueById.get(row.id);
90303
+ for (const valueId of materializedGraph.referencedValueIds(
90304
+ updated === void 0 ? row : { ...row, value: updated }
90305
+ ))
90306
+ restore(valueId);
90307
+ entriesByContainerId ??= buildUnorderedListMembershipIndex(rows);
90308
+ for (const valueId of entriesByContainerId.get(row.id) ?? [])
90309
+ restore(valueId);
90310
+ }
90311
+ }
90171
90312
  function materializedFallbackPaths(rows, graph, materializedGraph) {
90172
90313
  const rowsById = new Map(rows.map((row) => [row.id, row]));
90173
90314
  const unorderedEntriesByContainerId = buildUnorderedListMembershipIndex(rows);
@@ -90562,10 +90703,17 @@ function rewriteExpandedRow(node, expansion) {
90562
90703
  return row;
90563
90704
  }
90564
90705
  function createFromVirtual(location3, value, update) {
90565
- const prior = literalRow(location3.virtualRow);
90706
+ return createFromRow(
90707
+ literalRow(location3.virtualRow),
90708
+ location3.id,
90709
+ value,
90710
+ update
90711
+ );
90712
+ }
90713
+ function createFromRow(prior, id2, value, update) {
90566
90714
  const row = update?.classId !== void 0 && update.classId !== prior.classId ? replaceLiteralValueClass(prior, update.classId) : prior;
90567
90715
  const create = {
90568
- id: location3.id,
90716
+ id: id2,
90569
90717
  value,
90570
90718
  ...typeof row.classId !== "string" ? {} : { classId: row.classId },
90571
90719
  ...pickInstanceProvenance(row),
@@ -90575,16 +90723,6 @@ function createFromVirtual(location3, value, update) {
90575
90723
  ...row.genericBindings === void 0 ? {} : { genericBindings: { ...row.genericBindings } },
90576
90724
  ...row.sourceValueId === void 0 ? {} : { sourceValueId: row.sourceValueId }
90577
90725
  };
90578
- if (location3.parentId !== null && location3.parentSegment !== null) {
90579
- create.valuePlacement = {
90580
- kind: "placed",
90581
- scope: "authored",
90582
- memberId: location3.memberId,
90583
- parentRecordKind: "value",
90584
- parentRecordId: location3.parentId,
90585
- relation: location3.parentSegment.kind === "class" ? "classField" : "collectionEntry"
90586
- };
90587
- }
90588
90726
  return create;
90589
90727
  }
90590
90728
  function virtualOverrideFields(update) {
@@ -91399,6 +91537,7 @@ var init_virtual_instance_graph = __esm({
91399
91537
  init_member_change_listeners();
91400
91538
  init_initializer_dependencies();
91401
91539
  init_constructor_argument_ownership();
91540
+ init_value_row_owner_members();
91402
91541
  init_constructor_parameter_settlement();
91403
91542
  init_generics();
91404
91543
  init_inheritance();
@@ -91866,7 +92005,6 @@ function evaluateMemberInitializer(args) {
91866
92005
  );
91867
92006
  const compiled = compileMemberInitializer(args, databaseVM);
91868
92007
  const ctx = {
91869
- ...args.document.evaluationLimits,
91870
92008
  debugSink: args.document.debugSink,
91871
92009
  beforeValueAllocation: args.document.beforeValueAllocation,
91872
92010
  listenerDefaultCapture: args.document.listenerDefaultCapture,
@@ -91913,6 +92051,7 @@ function evaluateMemberInitializer(args) {
91913
92051
  sessionStaticBindings: args.sessionStaticBindings,
91914
92052
  ...args.storedConstructionReplay === true ? {
91915
92053
  storedConstructionReplay: true,
92054
+ ...args.sourceValueId == null ? {} : { __storedConstructionReplayRowId: args.sourceValueId },
91916
92055
  ...isMemberClassBase(args.member) ? {
91917
92056
  __storedConstructionReplaySlot: {
91918
92057
  classId: args.member.classId,
@@ -107012,7 +107151,7 @@ var init_project_version_transaction_planning = __esm({
107012
107151
  bytesRead: 6 * MIB,
107013
107152
  bytesWritten: 4 * MIB,
107014
107153
  documentsRead: 4e3,
107015
- documentsWritten: 1800,
107154
+ documentsWritten: 2100,
107016
107155
  databaseQueries: 1140,
107017
107156
  indexRanges: 1140,
107018
107157
  functionsScheduled: 24,
@@ -112433,6 +112572,26 @@ var init_stored_closure_captures = __esm({
112433
112572
  }
112434
112573
  });
112435
112574
 
112575
+ // ../src/models/project/world-layer-compatibility-error.ts
112576
+ var WorldLayerCompatibilityError;
112577
+ var init_world_layer_compatibility_error = __esm({
112578
+ "../src/models/project/world-layer-compatibility-error.ts"() {
112579
+ "use strict";
112580
+ WorldLayerCompatibilityError = class extends Error {
112581
+ constructor(assetName, layerName) {
112582
+ super(
112583
+ `Placed asset class "${assetName}" is not compatible with layer class "${layerName}".`
112584
+ );
112585
+ this.assetName = assetName;
112586
+ this.layerName = layerName;
112587
+ this.name = "WorldLayerCompatibilityError";
112588
+ }
112589
+ assetName;
112590
+ layerName;
112591
+ };
112592
+ }
112593
+ });
112594
+
112436
112595
  // ../src/models/project/world-content-sidecar-validation.ts
112437
112596
  function cachedWorldLayerTarget(context, args) {
112438
112597
  let target = context.linkTargetsByClassId.get(args.sourceClassId);
@@ -112882,9 +113041,9 @@ function validateWorldPlacementSidecars(args) {
112882
113041
  sourceClassId: assetClassId
112883
113042
  });
112884
113043
  if (!compatibleLayerIds.has(args.layerClassId)) {
112885
- throw new Error(
112886
- `Placement value "${args.placement.id}" asset class "${assetClassId}" is not compatible with layer class "${args.layerClassId}".`
112887
- );
113044
+ const assetName = args.classesById.get(assetClassId)?.name ?? assetClassId;
113045
+ const layerName = args.classesById.get(args.layerClassId)?.name ?? args.layerClassId;
113046
+ throw new WorldLayerCompatibilityError(assetName, layerName);
112888
113047
  }
112889
113048
  validateOwnedSparseValue({
112890
113049
  classesById: args.classesById,
@@ -113087,6 +113246,7 @@ var init_world_content_sidecar_validation = __esm({
113087
113246
  init_evaluateInitializer();
113088
113247
  init_internal_record_relations();
113089
113248
  init_classes();
113249
+ init_world_layer_compatibility_error();
113090
113250
  WORLD_PLACEMENT_SIDECAR_KEYS = [
113091
113251
  "assetClassId",
113092
113252
  "assetValueId",
@@ -116468,7 +116628,10 @@ function indexAuthoredSeedDocument(document) {
116468
116628
  localizedTextIds: new Set(
116469
116629
  (document.localizedTexts ?? []).map((text) => text.id)
116470
116630
  ),
116471
- declaringClassIdsByMemberId
116631
+ declaringClassIdsByMemberId,
116632
+ deferredChildIds: /* @__PURE__ */ new Map(),
116633
+ attachedChildIds: /* @__PURE__ */ new Map(),
116634
+ heldChildIdsByParentId: /* @__PURE__ */ new Map()
116472
116635
  };
116473
116636
  }
116474
116637
  function declaringClassIds(index, memberId) {
@@ -116591,8 +116754,7 @@ function materializeAuthoredValueSeeds(args) {
116591
116754
  }
116592
116755
  if (change.operation === "update" && seed === void 0) continue;
116593
116756
  if (change.operation === "create" && seed === void 0 && typeof member.valueId === "string") {
116594
- if (!documentIndex.valuesById.has(member.valueId))
116595
- sharedBindings.push({ member, valueId: member.valueId });
116757
+ sharedBindings.push({ member, valueId: member.valueId });
116596
116758
  continue;
116597
116759
  }
116598
116760
  const shouldBind = isRequiredMember(member) || seed !== void 0;
@@ -116735,18 +116897,31 @@ function materializeAuthoredValueSeeds(args) {
116735
116897
  });
116736
116898
  consumedSeedMemberIds.add(seed.memberId);
116737
116899
  }
116738
- if (sharedBindings.length > 0) {
116900
+ assertAttachedChildrenUnowned(args.document, documentIndex);
116901
+ assertSharedBindingsUnowned(args.document, documentIndex, sharedBindings);
116902
+ if (documentIndex.deferredChildIds.size > 0 || sharedBindings.length > 0) {
116739
116903
  const createdValueIds = /* @__PURE__ */ new Set();
116740
116904
  for (const change of args.prepared) {
116741
116905
  if (change.recordKind === "value" && change.operation === "create")
116742
116906
  createdValueIds.add(change.recordId);
116743
116907
  }
116908
+ for (const [id2, parentId] of documentIndex.deferredChildIds) {
116909
+ if (!createdValueIds.has(id2))
116910
+ throw new Error(`Authored value graph references missing row "${id2}".`);
116911
+ throw new Error(
116912
+ `Authored value graph places row "${id2}" under value "${parentId}", but another seed in this commit creates and owns it.`
116913
+ );
116914
+ }
116744
116915
  for (const { member, valueId } of sharedBindings) {
116916
+ if (documentIndex.valuesById.has(valueId)) continue;
116745
116917
  if (!createdValueIds.has(valueId)) {
116746
116918
  throw new Error(
116747
116919
  `Stored static member "${member.name}" (${member.id}) binds missing value "${valueId}".`
116748
116920
  );
116749
116921
  }
116922
+ throw new Error(
116923
+ `Stored static member "${member.name}" (${member.id}) binds value "${valueId}", but another seed in this commit creates and owns it.`
116924
+ );
116750
116925
  }
116751
116926
  }
116752
116927
  return pendingGraphValidations;
@@ -117623,14 +117798,12 @@ function materializeAuthoredClassFields(args) {
117623
117798
  args.storageKeyDeclarations
117624
117799
  );
117625
117800
  }
117626
- const materializedChild = materializeAuthoredChild({
117627
- ...args,
117628
- member: childMember,
117629
- childId,
117630
- genericEnv: childEnv
117631
- });
117801
+ const materializedChild = materializeAuthoredChild(
117802
+ { ...args, member: childMember, childId, genericEnv: childEnv },
117803
+ args.rootValue.id
117804
+ );
117632
117805
  const nextBody = isStringValueRecord(args.rootValue.value) ? args.rootValue.value : {};
117633
- nextBody[schemaKey] = materializedChild.id;
117806
+ nextBody[schemaKey] = materializedChild;
117634
117807
  args.rootValue.value = nextBody;
117635
117808
  }
117636
117809
  }
@@ -117662,13 +117835,12 @@ function materializeAuthoredListItems(args) {
117662
117835
  `${MemberKind[args.member.kind]} value "${args.row.id}" contains a non-id entry.`
117663
117836
  );
117664
117837
  }
117665
- const child2 = materializeAuthoredChild({
117666
- ...args,
117667
- member: entryMember,
117668
- childId
117669
- });
117670
- if (unordered) child2.containerId = args.rootValue.id;
117671
- materializedIds.push(child2.id);
117838
+ const child2 = materializeAuthoredChild(
117839
+ { ...args, member: entryMember, childId },
117840
+ args.rootValue.id,
117841
+ unordered
117842
+ );
117843
+ materializedIds.push(child2);
117672
117844
  }
117673
117845
  args.rootValue.value = unordered ? [] : materializedIds;
117674
117846
  }
@@ -117684,26 +117856,91 @@ function materializeAuthoredDictionaryEntries(args) {
117684
117856
  );
117685
117857
  const body = {};
117686
117858
  for (const [key, childId] of Object.entries(args.row.value)) {
117687
- body[key] = materializeAuthoredChild({
117688
- ...args,
117689
- member: entryMember,
117690
- childId
117691
- }).id;
117859
+ body[key] = materializeAuthoredChild(
117860
+ { ...args, member: entryMember, childId },
117861
+ args.rootValue.id
117862
+ );
117692
117863
  }
117693
117864
  args.rootValue.value = body;
117694
117865
  }
117695
- function materializeAuthoredChild(args) {
117866
+ function materializeAuthoredChild(args, parentId, contained = false) {
117696
117867
  const authored = args.authoredRows.get(args.childId);
117697
117868
  if (authored !== void 0) {
117698
- return materializeAuthoredSeedRow({ ...args, row: authored });
117869
+ const child2 = materializeAuthoredSeedRow({ ...args, row: authored });
117870
+ if (contained) child2.containerId = parentId;
117871
+ return child2.id;
117699
117872
  }
117700
- const existing = args.documentIndex.valuesById.get(args.childId);
117701
- if (existing === void 0) {
117873
+ const stored = args.documentIndex.valuesById.get(args.childId);
117874
+ if (stored === void 0) {
117875
+ args.documentIndex.deferredChildIds.set(args.childId, parentId);
117876
+ return args.childId;
117877
+ }
117878
+ if (!storedParentHolds(args.documentIndex, parentId, stored))
117879
+ args.documentIndex.attachedChildIds.set(stored.id, parentId);
117880
+ if (contained) stored.containerId = parentId;
117881
+ return stored.id;
117882
+ }
117883
+ function storedParentHolds(index, parentId, child2) {
117884
+ if (child2.containerId === parentId) return true;
117885
+ let held = index.heldChildIdsByParentId.get(parentId);
117886
+ if (held === void 0) {
117887
+ held = storedChildIds(index.valuesById.get(parentId)?.value);
117888
+ index.heldChildIdsByParentId.set(parentId, held);
117889
+ }
117890
+ return held.has(child2.id);
117891
+ }
117892
+ function storedChildIds(body) {
117893
+ if (Array.isArray(body)) return new Set(body);
117894
+ if (isStringValueRecord(body)) return new Set(Object.values(body));
117895
+ return /* @__PURE__ */ new Set();
117896
+ }
117897
+ function assertSharedBindingsUnowned(document, index, bindings) {
117898
+ const stored = bindings.filter(
117899
+ (binding) => index.valuesById.has(binding.valueId)
117900
+ );
117901
+ if (stored.length === 0) return;
117902
+ const bindingMemberIds = new Set(stored.map((binding) => binding.member.id));
117903
+ const owners = findOwningMembersForValues(
117904
+ {
117905
+ ...document,
117906
+ members: document.members.filter(
117907
+ (member) => !bindingMemberIds.has(member.id)
117908
+ )
117909
+ },
117910
+ new Set(stored.map((binding) => binding.valueId))
117911
+ );
117912
+ for (const { member, valueId } of stored) {
117913
+ const owner = owners.get(valueId);
117914
+ if (owner === void 0) continue;
117915
+ if (owner.parentValueId === null) {
117916
+ throw new Error(
117917
+ `Stored static member "${member.name}" (${member.id}) binds value "${valueId}", but member "${owner.member.name}" already owns it.`
117918
+ );
117919
+ }
117920
+ throw new Error(
117921
+ `Stored static member "${member.name}" (${member.id}) binds value "${valueId}", but value "${owner.parentValueId}" already owns it.`
117922
+ );
117923
+ }
117924
+ }
117925
+ function assertAttachedChildrenUnowned(document, index) {
117926
+ if (index.attachedChildIds.size === 0) return;
117927
+ const owners = findOwningMembersForValues(
117928
+ document,
117929
+ new Set(index.attachedChildIds.keys())
117930
+ );
117931
+ for (const [childId, parentId] of index.attachedChildIds) {
117932
+ const owner = owners.get(childId);
117933
+ if (owner === void 0) continue;
117934
+ if (owner.parentValueId === parentId) continue;
117935
+ if (owner.parentValueId === null) {
117936
+ throw new Error(
117937
+ `Authored value graph places row "${childId}" under value "${parentId}", but member "${owner.member.name}" already owns it.`
117938
+ );
117939
+ }
117702
117940
  throw new Error(
117703
- `Authored value graph references missing row "${args.childId}".`
117941
+ `Authored value graph places row "${childId}" under value "${parentId}", but value "${owner.parentValueId}" already owns it.`
117704
117942
  );
117705
117943
  }
117706
- return existing;
117707
117944
  }
117708
117945
  function renameCreatedValueId(args) {
117709
117946
  if (args.generatedId === args.requestedId) return;
@@ -120138,17 +120375,13 @@ var init_user_delegate_target_validation = __esm({
120138
120375
 
120139
120376
  // ../src/models/exports/unity-static-members.ts
120140
120377
  function requiresUnitySingleton(member) {
120141
- return isStaticMember(member) === true && !nativePatternMembers.has(member.id);
120378
+ return isStaticMember(member) && !isSystemRecordId(member.id);
120142
120379
  }
120143
- var nativePatternMembers;
120144
120380
  var init_unity_static_members = __esm({
120145
120381
  "../src/models/exports/unity-static-members.ts"() {
120146
120382
  "use strict";
120147
- init_cell_pattern();
120383
+ init_system_record_id();
120148
120384
  init_member_kinds();
120149
- nativePatternMembers = new Set(
120150
- Object.values(NEO_CELL_PATTERN_MEMBER_IDS)
120151
- );
120152
120385
  }
120153
120386
  });
120154
120387
 
@@ -124425,6 +124658,15 @@ var init_system_protection = __esm({
124425
124658
  ],
124426
124659
  reasonKey: "systemProtection.reasons.scriptRuntime",
124427
124660
  serverReason: "Lifecycle interface the Neo Compose script runtime calls."
124661
+ },
124662
+ [SystemProtectionKind.SystemPreset]: {
124663
+ disallow: [
124664
+ SystemDisallowedOperation.EditRecord,
124665
+ SystemDisallowedOperation.DeleteRecord,
124666
+ SystemDisallowedOperation.ReplaceValue
124667
+ ],
124668
+ reasonKey: "systemProtection.reasons.systemPreset",
124669
+ serverReason: "Built-in preset value shared by every Neo Compose project."
124428
124670
  }
124429
124671
  };
124430
124672
  }
@@ -124597,10 +124839,26 @@ function assertProtectedValuesNotReplaced(document, changes) {
124597
124839
  candidateValueIds.add(childId);
124598
124840
  }
124599
124841
  }
124842
+ let graph;
124843
+ const graphOf = () => graph ??= new MaterializedValueGraphContext(document);
124600
124844
  const owners = resolveSemanticOwnerMembersForValues(
124601
124845
  document,
124602
- candidateValueIds
124846
+ candidateValueIds,
124847
+ void 0,
124848
+ void 0,
124849
+ void 0,
124850
+ graphOf
124603
124851
  );
124852
+ const unowned = [...candidateValueIds].filter((id2) => !owners.has(id2));
124853
+ if (unowned.length > 0) {
124854
+ for (const [valueId, owner] of protectedStaticConstructorRowOwners(
124855
+ document,
124856
+ new Set(unowned),
124857
+ graphOf()
124858
+ )) {
124859
+ owners.set(valueId, owner);
124860
+ }
124861
+ }
124604
124862
  for (const valueId of candidateValueIds) {
124605
124863
  const owner = owners.get(valueId);
124606
124864
  if (owner === void 0) continue;
@@ -124616,6 +124874,22 @@ function assertProtectedValuesNotReplaced(document, changes) {
124616
124874
  );
124617
124875
  }
124618
124876
  }
124877
+ function protectedStaticConstructorRowOwners(document, valueIds, graph) {
124878
+ const owners = /* @__PURE__ */ new Map();
124879
+ for (const member of document.members) {
124880
+ if (member.valueId === void 0) continue;
124881
+ if (!hasSystemDisallowedOperation(
124882
+ readSystemMetadata(member),
124883
+ SystemDisallowedOperation.ReplaceValue
124884
+ )) {
124885
+ continue;
124886
+ }
124887
+ for (const valueId of graph.collectSoftOwnedRows(member.valueId)) {
124888
+ if (valueIds.has(valueId)) owners.set(valueId, member);
124889
+ }
124890
+ }
124891
+ return owners;
124892
+ }
124619
124893
  function repointedChildValueIds(document, change) {
124620
124894
  const baseValue = document.values.find(
124621
124895
  (candidate) => candidate.id === change.recordId
@@ -128869,7 +129143,7 @@ function buildValueEmitIndexesV4(records3, manifest, localizedTextDependencies,
128869
129143
  const enums = dataById(records3, "enum");
128870
129144
  const localizedTexts = dataById(records3, "localized-text");
128871
129145
  const dialogues = dataById(records3, "dialogue");
128872
- const { symbolsByValueId, staticOwnerIds } = staticSymbols(classes, members);
129146
+ const symbolsByValueId = staticSymbols(classes, members);
128873
129147
  let document;
128874
129148
  const readDocument = () => document ??= trackPulledLocalizedTextReads(
128875
129149
  readPulledProjectDocumentV4(records3),
@@ -129010,7 +129284,6 @@ function buildValueEmitIndexesV4(records3, manifest, localizedTextDependencies,
129010
129284
  localizedTexts,
129011
129285
  mainLocale: projectMainLocale(records3),
129012
129286
  symbolsByValueId,
129013
- staticOwnerIds,
129014
129287
  rootPathsByValueId,
129015
129288
  readRootIndexPaths: () => rootIndexPaths ??= indexRootIndexPaths(
129016
129289
  values,
@@ -129062,8 +129335,6 @@ function emitStoredValueBindingSourcesV4(records3, memberIds, options) {
129062
129335
  );
129063
129336
  let initializer = emitValue(context, member, valueId, {
129064
129337
  environment: declaringClassGenericEnvironment(context, member),
129065
- // A static sharing another static's row names that static (#1385).
129066
- definitionSite: (context.staticOwnerIds.get(valueId) ?? memberId) === memberId,
129067
129338
  // The row is `derivedMemberValueId(memberId)` and the declaration
129068
129339
  // above it already carries `@id(memberId)`.
129069
129340
  writeIdentity: false,
@@ -129399,7 +129670,6 @@ function emitVariantValueSourcesV4(records3, manifest, options = {}) {
129399
129670
  }
129400
129671
  return emitValue(context, member, childId, {
129401
129672
  environment,
129402
- definitionSite: true,
129403
129673
  writeIdentity: false,
129404
129674
  visited
129405
129675
  });
@@ -129462,7 +129732,6 @@ function createStoredConstructionProbeV4(records3, manifest, localizedTextDepend
129462
129732
  const probeContext = sharedContext();
129463
129733
  emitValue(probeContext, member, valueId, {
129464
129734
  environment: declaringClassGenericEnvironment(probeContext, member),
129465
- definitionSite: true,
129466
129735
  writeIdentity: false,
129467
129736
  visited: /* @__PURE__ */ new Set()
129468
129737
  });
@@ -131146,8 +131415,15 @@ function composeReferenceSitePosition(site, sourceTextByUri) {
131146
131415
  return { file: site.uri, line: origin.line + line, column };
131147
131416
  }
131148
131417
  function composeCompiledInitializerPosition(site, sourceTextByUri, compiledCode, position) {
131149
- const anchor = composeReferenceSitePosition(site, sourceTextByUri);
131150
- if (site.expression === null) return anchor;
131418
+ return mappedCompiledInitializerPosition(
131419
+ site,
131420
+ sourceTextByUri,
131421
+ compiledCode,
131422
+ position
131423
+ ) ?? composeReferenceSitePosition(site, sourceTextByUri);
131424
+ }
131425
+ function mappedCompiledInitializerPosition(site, sourceTextByUri, compiledCode, position) {
131426
+ if (site.expression === null) return null;
131151
131427
  let code = compiledCode;
131152
131428
  let positionOffset = initializerOffsetAtPos(compiledCode, position);
131153
131429
  const rewrites = site.expression.rewrites;
@@ -131157,7 +131433,7 @@ function composeCompiledInitializerPosition(site, sourceTextByUri, compiledCode,
131157
131433
  compiledCode,
131158
131434
  positionOffset
131159
131435
  );
131160
- if (unwound === null) return anchor;
131436
+ if (unwound === null) return null;
131161
131437
  code = rewrites.code;
131162
131438
  positionOffset = unwound;
131163
131439
  }
@@ -131165,7 +131441,7 @@ function composeCompiledInitializerPosition(site, sourceTextByUri, compiledCode,
131165
131441
  try {
131166
131442
  codeAnchor = expressionAnchorPos(parseExpression(code));
131167
131443
  } catch {
131168
- return anchor;
131444
+ return null;
131169
131445
  }
131170
131446
  const { initializer } = site.expression;
131171
131447
  const authored = significantTokens(lex(initializer).tokens);
@@ -131182,12 +131458,12 @@ function composeCompiledInitializerPosition(site, sourceTextByUri, compiledCode,
131182
131458
  (token) => token.end > compiledAnchorOffset
131183
131459
  );
131184
131460
  const target = compiled.findIndex((token) => token.end > positionOffset);
131185
- if (authoredAnchor < 0 || compiledAnchor < 0 || target < 0) return anchor;
131461
+ if (authoredAnchor < 0 || compiledAnchor < 0 || target < 0) return null;
131186
131462
  const shift = authoredAnchor - compiledAnchor;
131187
131463
  const from = Math.min(compiledAnchor, target);
131188
131464
  const to = Math.max(compiledAnchor, target);
131189
131465
  for (let index = from; index <= to; index += 1) {
131190
- if (authored[index + shift]?.text !== compiled[index].text) return anchor;
131466
+ if (authored[index + shift]?.text !== compiled[index].text) return null;
131191
131467
  }
131192
131468
  const offset = authored[target + shift].start + Math.max(0, positionOffset - compiled[target].start);
131193
131469
  const mapped = sourcePositionAtOffset(initializer, offset);
@@ -131598,12 +131874,15 @@ function lowerRowBackedDefault(context, member, backed, baseData3, binding) {
131598
131874
  );
131599
131875
  continue;
131600
131876
  }
131601
- const placedId = sourceValueSymbol(context, assignment.value);
131602
- if (placedId !== null) {
131603
- throw new Error(
131604
- `Default value ${binding.label}.${assignment.name} cannot place existing value ${placedId} into a new structural slot. Create the nested value inline so the atomic construction transaction can own it.`
131605
- );
131606
- }
131877
+ if (refusesOwnedStaticPlacement(
131878
+ context,
131879
+ childValueMember,
131880
+ assignment.value,
131881
+ binding,
131882
+ `${binding.label}.${assignment.name}`,
131883
+ environment
131884
+ ))
131885
+ continue;
131607
131886
  body[assignment.name] = lowerSeedChild(
131608
131887
  context,
131609
131888
  childValueMember,
@@ -131630,16 +131909,16 @@ function lowerRowBackedDefault(context, member, backed, baseData3, binding) {
131630
131909
  const existingIds = new Set(backed.body);
131631
131910
  const placedIds = /* @__PURE__ */ new Set();
131632
131911
  const entrySlices = topLevelEntrySlices(binding.initializer, "[", "]");
131633
- const ids = expression.elements.map((element, index) => {
131634
- const symbolId = sourceValueSymbol(context, element);
131635
- if (symbolId !== null) {
131636
- if (!existingIds.has(symbolId)) {
131637
- throw new Error(
131638
- `Default list ${binding.label} adds value ${symbolId}. Changing default value placement is not implemented by this slice.`
131639
- );
131640
- }
131641
- return symbolId;
131642
- }
131912
+ const ids = expression.elements.flatMap((element, index) => {
131913
+ if (refusesOwnedStaticPlacement(
131914
+ context,
131915
+ entryMember,
131916
+ element,
131917
+ binding,
131918
+ `${binding.label}[${index}]`,
131919
+ bindingEnvironment
131920
+ ))
131921
+ return [];
131643
131922
  const itemId = authoredRowId(context, element, binding);
131644
131923
  if (itemId === null || context.state[`value:${itemId}`] === void 0) {
131645
131924
  if (itemId !== null && !isPendingId(itemId) && !isUuidV4Id(itemId)) {
@@ -131797,18 +132076,17 @@ function lowerStoredBinding(context, binding, memberValueIds, seeds) {
131797
132076
  );
131798
132077
  return;
131799
132078
  }
131800
- const referenced = member.kind === "class" || member.kind === "list" || member.kind === "set" || member.kind === "dictionary" ? sourceValueSymbol(context, expression) : null;
131801
- if (referenced !== null) {
131802
- const listeners = context.listenerBindings.get(
131803
- `${binding.purpose}:${binding.memberId}`
132079
+ if (refusesOwnedStaticPlacement(
132080
+ context,
132081
+ member,
132082
+ expression,
132083
+ binding,
132084
+ binding.label
132085
+ )) {
132086
+ memberValueIds.set(
132087
+ binding.memberId,
132088
+ currentValueId ?? memberValueId(binding.memberId)
131804
132089
  );
131805
- if (listeners !== void 0)
131806
- context.listenerBindings.set(`${binding.purpose}:${binding.memberId}`, {
131807
- ...listeners,
131808
- rootId: referenced
131809
- });
131810
- memberValueIds.set(binding.memberId, referenced);
131811
- preserveReboundValue(context, currentValueId, referenced, binding);
131812
132090
  return;
131813
132091
  }
131814
132092
  const valueId = currentValueId ?? memberValueId(binding.memberId);
@@ -132434,11 +132712,24 @@ function lowerSeedRow(context, member, sourceExpression, source, valueId, path,
132434
132712
  assignment.name
132435
132713
  );
132436
132714
  const childPath = `${path}.${assignment.name}`;
132715
+ const childValueMember = recursivePartialMember(
132716
+ resolvedMember,
132717
+ childMember
132718
+ );
132719
+ if (refusesOwnedStaticPlacement(
132720
+ context,
132721
+ childValueMember,
132722
+ assignment.value,
132723
+ source,
132724
+ childPath,
132725
+ environment
132726
+ ))
132727
+ continue;
132437
132728
  let childId;
132438
132729
  try {
132439
132730
  childId = lowerSeedChild(
132440
132731
  context,
132441
- recursivePartialMember(resolvedMember, childMember),
132732
+ childValueMember,
132442
132733
  assignment.value,
132443
132734
  source,
132444
132735
  childPath,
@@ -132480,13 +132771,24 @@ function lowerSeedRow(context, member, sourceExpression, source, valueId, path,
132480
132771
  }
132481
132772
  const entryMember = requiredMember(context, resolvedMember.entryMemberId);
132482
132773
  const entrySlices = authoredSlice === void 0 ? [] : topLevelEntrySlices(authoredSlice, "[", "]");
132483
- const ids = expression.elements.map((element, index) => {
132774
+ const ids = [];
132775
+ for (const [index, element] of expression.elements.entries()) {
132776
+ const entryPath = `${path}[${index}]`;
132777
+ if (refusesOwnedStaticPlacement(
132778
+ context,
132779
+ entryMember,
132780
+ element,
132781
+ source,
132782
+ entryPath,
132783
+ inheritedEnvironment
132784
+ ))
132785
+ continue;
132484
132786
  const entryId = lowerSeedChild(
132485
132787
  context,
132486
132788
  entryMember,
132487
132789
  element,
132488
132790
  source,
132489
- `${path}[${index}]`,
132791
+ entryPath,
132490
132792
  rows,
132491
132793
  localizedTexts,
132492
132794
  isUnorderedList(resolvedMember) ? valueId : void 0,
@@ -132494,8 +132796,8 @@ function lowerSeedRow(context, member, sourceExpression, source, valueId, path,
132494
132796
  entrySlices[index]
132495
132797
  );
132496
132798
  notePendingListEntrySite(context, element, source, entryId);
132497
- return entryId;
132498
- });
132799
+ ids.push(entryId);
132800
+ }
132499
132801
  context.authoredListEntries.set(valueId, ids);
132500
132802
  value = isUnorderedList(resolvedMember) ? [] : ids;
132501
132803
  } else if (resolvedMember.kind === "dictionary") {
@@ -132506,22 +132808,30 @@ function lowerSeedRow(context, member, sourceExpression, source, valueId, path,
132506
132808
  const keyEnum = dictionaryKeyEnum(context, resolvedMember);
132507
132809
  const body = {};
132508
132810
  const entrySlices = authoredSlice === void 0 ? [] : topLevelEntrySlices(authoredSlice, "{", "}");
132509
- let entryIndex = 0;
132510
- for (const entry of expression.entries) {
132811
+ for (const [entryIndex, entry] of expression.entries.entries()) {
132511
132812
  const key = lowerDictionaryKey(entry.key, keyEnum, path);
132813
+ const entryPath = `${path}[${JSON.stringify(key)}]`;
132814
+ if (refusesOwnedStaticPlacement(
132815
+ context,
132816
+ entryMember,
132817
+ entry.value,
132818
+ source,
132819
+ entryPath,
132820
+ inheritedEnvironment
132821
+ ))
132822
+ continue;
132512
132823
  body[key] = lowerSeedChild(
132513
132824
  context,
132514
132825
  entryMember,
132515
132826
  entry.value,
132516
132827
  source,
132517
- `${path}[${JSON.stringify(key)}]`,
132828
+ entryPath,
132518
132829
  rows,
132519
132830
  localizedTexts,
132520
132831
  void 0,
132521
132832
  inheritedEnvironment,
132522
132833
  dictionaryValueSlice(entrySlices[entryIndex])
132523
132834
  );
132524
- entryIndex += 1;
132525
132835
  }
132526
132836
  value = body;
132527
132837
  } else if (resolvedMember.kind === "string" && resolvedMember.localizable) {
@@ -132786,12 +133096,23 @@ function lowerStructuralConstructionRow(context, member, expression, source, val
132786
133096
  effectiveClass.id,
132787
133097
  assignment.name
132788
133098
  );
133099
+ const childValueMember = recursivePartialMember(member, childMember);
133100
+ const childPath = `${path}.${assignment.name}`;
133101
+ if (refusesOwnedStaticPlacement(
133102
+ context,
133103
+ childValueMember,
133104
+ assignment.value,
133105
+ source,
133106
+ childPath,
133107
+ environment
133108
+ ))
133109
+ continue;
132789
133110
  const childId = lowerSeedChild(
132790
133111
  context,
132791
- recursivePartialMember(member, childMember),
133112
+ childValueMember,
132792
133113
  assignment.value,
132793
133114
  source,
132794
- `${path}.${assignment.name}`,
133115
+ childPath,
132795
133116
  rows,
132796
133117
  localizedTexts,
132797
133118
  void 0,
@@ -132902,8 +133223,6 @@ function structuralMemberByParameterName(context, effectiveClass) {
132902
133223
  return settledBy;
132903
133224
  }
132904
133225
  function lowerSeedChild(context, member, expression, source, path, rows, localizedTexts, containerId, environment, authoredSlice) {
132905
- const symbolId = sourceValueSymbol(context, expression);
132906
- if (symbolId !== null) return symbolId;
132907
133226
  const local = context.localValues.resolve(expression, source);
132908
133227
  const annotatedId2 = annotatedValue(local.expression).id;
132909
133228
  if (annotatedId2 !== null && !isPendingId(annotatedId2) && context.state[`value:${annotatedId2}`] === void 0 && member.owner.kind === "classMember" && !isUuidV4Id(annotatedId2)) {
@@ -133449,12 +133768,15 @@ function lowerClassValue(context, member, expression, base, source, outerEnviron
133449
133768
  const childMember = classMemberByName(context, classId, assignment.name);
133450
133769
  const childId = body[assignment.name];
133451
133770
  if (typeof childId !== "string") {
133452
- const symbolId2 = sourceValueSymbol(context, assignment.value);
133453
- if (symbolId2 !== null) {
133454
- throw new Error(
133455
- `Class value ${String(base.id)}.${assignment.name} cannot place existing value ${symbolId2} into a new structural slot. Create the nested value inline so the atomic construction transaction can own it.`
133456
- );
133457
- }
133771
+ if (refusesOwnedStaticPlacement(
133772
+ context,
133773
+ childMember,
133774
+ assignment.value,
133775
+ source,
133776
+ `${String(base.id)}.${assignment.name}`,
133777
+ environment
133778
+ ))
133779
+ continue;
133458
133780
  const rows = /* @__PURE__ */ new Map();
133459
133781
  const localizedTexts = /* @__PURE__ */ new Map();
133460
133782
  const seededId = lowerSeedChild(
@@ -133483,16 +133805,15 @@ function lowerClassValue(context, member, expression, base, source, outerEnviron
133483
133805
  body[assignment.name] = seededId;
133484
133806
  continue;
133485
133807
  }
133486
- const symbolId = sourceValueSymbol(context, assignment.value);
133487
- if (symbolId !== null) {
133488
- if (symbolId !== childId) {
133489
- throw new Error(
133490
- `Class value ${String(base.id)}.${assignment.name} changes value placement from ${childId} to ${symbolId}. The atomic placement transaction is not implemented by this slice.`
133491
- );
133492
- }
133493
- body[assignment.name] = symbolId;
133808
+ if (refusesOwnedStaticPlacement(
133809
+ context,
133810
+ childMember,
133811
+ assignment.value,
133812
+ source,
133813
+ `${String(base.id)}.${assignment.name}`,
133814
+ environment
133815
+ ))
133494
133816
  continue;
133495
- }
133496
133817
  body[assignment.name] = lowerValueRow(
133497
133818
  context,
133498
133819
  recursivePartialMember(member, childMember),
@@ -134293,20 +134614,18 @@ function lowerListValue(context, member, expression, base, source, inheritedEnvi
134293
134614
  throw new Error("List values require [...].");
134294
134615
  const entryMember = requiredMember(context, member.entryMemberId);
134295
134616
  const environment = valueGenericEnvironment(base, inheritedEnvironment);
134296
- const existingIds = existingListItemIds(context, member, base);
134297
134617
  const entrySlices = authoredSlice === void 0 ? [] : topLevelEntrySlices(authoredSlice, "[", "]");
134298
134618
  const ids = [];
134299
134619
  for (const [index, element] of expression.elements.entries()) {
134300
- const symbolId = sourceValueSymbol(context, element);
134301
- if (symbolId !== null) {
134302
- if (!existingIds.has(symbolId)) {
134303
- throw new Error(
134304
- `List ${member.name} adds static value ${symbolId}. Changing value placement requires the atomic placement transaction and is not implemented by this slice.`
134305
- );
134306
- }
134307
- ids.push(symbolId);
134620
+ if (refusesOwnedStaticPlacement(
134621
+ context,
134622
+ entryMember,
134623
+ element,
134624
+ source,
134625
+ `${member.name}[${index}]`,
134626
+ environment
134627
+ ))
134308
134628
  continue;
134309
- }
134310
134629
  const annotatedItemId = authoredRowId(context, element, source);
134311
134630
  if (annotatedItemId === null) {
134312
134631
  ids.push(
@@ -134450,16 +134769,6 @@ function notePendingListEntrySite(context, element, source, rowId) {
134450
134769
  nestedListEntries: []
134451
134770
  });
134452
134771
  }
134453
- function existingListItemIds(context, member, base) {
134454
- if (isUnorderedList(member)) {
134455
- const containerId = stringOrNull2(base.id);
134456
- if (containerId === null) return /* @__PURE__ */ new Set();
134457
- return context.valuePlacements.valueIdsByContainerId.get(containerId) ?? /* @__PURE__ */ new Set();
134458
- }
134459
- return new Set(
134460
- Array.isArray(base.value) ? base.value.filter((entry) => typeof entry === "string") : []
134461
- );
134462
- }
134463
134772
  function lowerDictionaryValue(context, member, expression, base, source, inheritedEnvironment, authoredSlice) {
134464
134773
  if (expression.kind === "litNull")
134465
134774
  return { ...valueFileFields(base), value: null };
@@ -134476,16 +134785,15 @@ function lowerDictionaryValue(context, member, expression, base, source, inherit
134476
134785
  for (const [entryIndex, entry] of expression.entries.entries()) {
134477
134786
  const key = lowerDictionaryKey(entry.key, keyEnum, member.name);
134478
134787
  const existingId = baseBody[key];
134479
- const symbolId = sourceValueSymbol(context, entry.value);
134480
- if (symbolId !== null) {
134481
- if (symbolId !== existingId) {
134482
- throw new Error(
134483
- `Dictionary ${member.name}[${JSON.stringify(key)}] changes value placement from ${String(existingId)} to ${symbolId}. The atomic placement transaction is not implemented by this slice.`
134484
- );
134485
- }
134486
- body[key] = symbolId;
134788
+ if (refusesOwnedStaticPlacement(
134789
+ context,
134790
+ entryMember,
134791
+ entry.value,
134792
+ source,
134793
+ `${member.name}[${JSON.stringify(key)}]`,
134794
+ environment
134795
+ ))
134487
134796
  continue;
134488
- }
134489
134797
  const explicitId = annotatedValue(entry.value).id;
134490
134798
  const valueId = explicitId ?? existingId;
134491
134799
  if (typeof valueId !== "string") {
@@ -134780,6 +135088,18 @@ function requiredDecimal(expression) {
134780
135088
  }
134781
135089
  throw new Error("Expected a decimal literal.");
134782
135090
  }
135091
+ function refusesOwnedStaticPlacement(context, member, expression, source, path, environment) {
135092
+ if (sourceValueSymbol(context, expression) === null) return false;
135093
+ if (!structuralArgumentIsAggregate(context, member, environment))
135094
+ return false;
135095
+ const staticPath = memberPath2(annotatedValue(expression).expression);
135096
+ context.loweringFailures.push({
135097
+ code: "owned-static-value",
135098
+ message: `Value ${path} places '${staticPath}', which is already owned by that static. Call Clone() or use Reference.`,
135099
+ site: referenceSite(source, expression)
135100
+ });
135101
+ return true;
135102
+ }
134783
135103
  function sourceValueSymbol(context, expression) {
134784
135104
  const unwrapped = annotatedValue(expression).expression;
134785
135105
  const path = memberPath2(unwrapped);
@@ -135548,11 +135868,6 @@ function indexSourceStaticTargets(targets, state, analysis, manifest, parsedInit
135548
135868
  parsedInitializers,
135549
135869
  declaration.initializer
135550
135870
  );
135551
- const direct = sourceValueSymbolFromMap(targets, expression);
135552
- if (direct) {
135553
- targets.set(symbol, direct);
135554
- continue;
135555
- }
135556
135871
  const memberData = state[`member:${memberId}`]?.data;
135557
135872
  const current = isObjectRecord2(memberData) && typeof memberData.valueId === "string" ? memberData.valueId : null;
135558
135873
  targets.set(
@@ -135563,10 +135878,6 @@ function indexSourceStaticTargets(targets, state, analysis, manifest, parsedInit
135563
135878
  }
135564
135879
  }
135565
135880
  }
135566
- function sourceValueSymbolFromMap(targets, expression) {
135567
- const path = memberPath2(annotatedValue(expression).expression);
135568
- return path === null ? null : targets.get(path) ?? null;
135569
- }
135570
135881
  function returnedSymbol(body) {
135571
135882
  if (!body) return null;
135572
135883
  const getterSource = propertyAccessors(body).get;
@@ -136196,10 +136507,6 @@ function emitValue(context, member, valueId, options) {
136196
136507
  }
136197
136508
  return captured;
136198
136509
  }
136199
- const externalSymbol = context.symbolsByValueId.get(valueId);
136200
- if (!options.definitionSite && externalSymbol !== void 0) {
136201
- return externalSymbol;
136202
- }
136203
136510
  if (options.visited.has(valueId)) {
136204
136511
  throw new Error(`Project value containment cycle reaches ${valueId}.`);
136205
136512
  }
@@ -136514,7 +136821,6 @@ function classValueBody(context, member, value, visited, targetTyped, outerEnvir
136514
136821
  fields.push(
136515
136822
  `${key} = ${emitValue(context, emittedChildMember, childId, {
136516
136823
  environment,
136517
- definitionSite: !context.symbolsByValueId.has(childId),
136518
136824
  // New and moved identities must survive repeat lowering against the old placement.
136519
136825
  writeIdentity: needsProspectiveValueIdentity(
136520
136826
  context,
@@ -137714,7 +138020,6 @@ function constructorProjectionSource(context, classId, body, visited, environmen
137714
138020
  projectedMember,
137715
138021
  childValueId,
137716
138022
  {
137717
- definitionSite: true,
137718
138023
  writeIdentity: false,
137719
138024
  environment,
137720
138025
  visited
@@ -137943,8 +138248,7 @@ ${ids.map(
137943
138248
  (id2) => indentNeoSource(
137944
138249
  emitValue(context, entryMember, id2, {
137945
138250
  environment,
137946
- definitionSite: context.symbolsByValueId.get(id2) === void 0,
137947
- writeIdentity: context.symbolsByValueId.get(id2) === void 0,
138251
+ writeIdentity: true,
137948
138252
  visited
137949
138253
  }),
137950
138254
  2
@@ -137976,7 +138280,6 @@ ${entries.flatMap(
137976
138280
  id2,
137977
138281
  {
137978
138282
  environment,
137979
- definitionSite: !context.symbolsByValueId.has(id2),
137980
138283
  // Existing keys recover identity from their owning row;
137981
138284
  // new authored identities must survive repeat lowering.
137982
138285
  writeIdentity: needsProspectiveValueIdentity(
@@ -138303,25 +138606,21 @@ function localizedString(context, member, body) {
138303
138606
  }
138304
138607
  function staticSymbols(classes, members) {
138305
138608
  const symbolsByValueId = /* @__PURE__ */ new Map();
138306
- const staticOwnerIds = /* @__PURE__ */ new Map();
138307
138609
  for (const schemaClass2 of classes.values()) {
138308
138610
  if (typeof schemaClass2.name !== "string" || !isObjectRecord2(schemaClass2.schema))
138309
138611
  continue;
138310
138612
  for (const memberId of Object.values(schemaClass2.schema)) {
138311
138613
  if (typeof memberId !== "string") continue;
138312
138614
  const member = members.get(memberId);
138313
- if (member?.modifier === 3 && typeof member.name === "string" && typeof member.valueId === "string" && // A static naming another static shares its row. The member the row
138314
- // derives from owns it; otherwise the first keeps it.
138315
- (!staticOwnerIds.has(member.valueId) || member.valueId === memberValueId(memberId))) {
138615
+ if (member?.modifier === 3 && typeof member.name === "string" && typeof member.valueId === "string") {
138316
138616
  symbolsByValueId.set(
138317
138617
  member.valueId,
138318
138618
  `${schemaClass2.name}.${member.name}`
138319
138619
  );
138320
- staticOwnerIds.set(member.valueId, memberId);
138321
138620
  }
138322
138621
  }
138323
138622
  }
138324
- return { symbolsByValueId, staticOwnerIds };
138623
+ return symbolsByValueId;
138325
138624
  }
138326
138625
  function projectFileSymbols(records3) {
138327
138626
  const files = [...records3.values()].flatMap((record7) => {
@@ -138586,8 +138885,13 @@ function initializerRuntimeDiagnostic(error, sites, texts, analysis, recordId) {
138586
138885
  let position = site === void 0 ? void 0 : composeReferenceSitePosition(site, texts);
138587
138886
  if (error instanceof NSGetterRuntimeError && error.source !== void 0) {
138588
138887
  const source = error.source;
138589
- if (source.uri !== void 0 && texts.get(source.uri) === source.text) {
138590
- position = { file: source.uri, line: source.line, column: source.column };
138888
+ const uri = source.uri;
138889
+ const exact = uri !== void 0 && texts.get(uri) === source.text;
138890
+ const inSite = exact || site === void 0 ? null : wrappedInitializerPosition(site, texts, source);
138891
+ if (exact) {
138892
+ position = { file: uri, line: source.line, column: source.column };
138893
+ } else if (inSite !== null) {
138894
+ position = inSite;
138591
138895
  } else {
138592
138896
  const bodyLex = lex(source.text);
138593
138897
  let tokens = significantTokens(bodyLex.tokens);
@@ -138649,6 +138953,14 @@ function initializerRuntimeDiagnostic(error, sites, texts, analysis, recordId) {
138649
138953
  position?.column ?? 1
138650
138954
  );
138651
138955
  }
138956
+ function wrappedInitializerPosition(site, texts, source) {
138957
+ const wrapped = /^return\n([^]*);$/u.exec(source.text);
138958
+ if (wrapped === null) return null;
138959
+ return mappedCompiledInitializerPosition(site, texts, wrapped[1], {
138960
+ line: source.line - 1,
138961
+ column: source.column
138962
+ });
138963
+ }
138652
138964
  function sourceOwnerLocation(analysis, id2) {
138653
138965
  if (analysis === null || analysis === void 0 || id2 === void 0)
138654
138966
  return void 0;
@@ -146355,6 +146667,13 @@ function computeStatus(workspace, options, conflictedFiles, parseErrors, parseWa
146355
146667
  registry: valueLowerRegistry
146356
146668
  });
146357
146669
  if (collectionBindings !== void 0) {
146670
+ const bindings = collectionBindings;
146671
+ const templateInitializer = (id2) => {
146672
+ const sourceValueId = bindings.rowForValue(id2)?.sourceValueId;
146673
+ if (typeof sourceValueId !== "string") return null;
146674
+ const template = bindings.rowForValue(sourceValueId);
146675
+ return isInitValueContent(template) ? template.init : null;
146676
+ };
146358
146677
  const bindingSeeds = new Map(authoredValueSeeds);
146359
146678
  const rootRecordsById = new Map(
146360
146679
  rootRecords.filter((record7) => record7.recordKind === "value").map((record7) => [record7.recordId, record7])
@@ -146383,13 +146702,53 @@ function computeStatus(workspace, options, conflictedFiles, parseErrors, parseWa
146383
146702
  if (memberId === void 0 || root === void 0) continue;
146384
146703
  const seed = authoredValueSeeds.get(memberId);
146385
146704
  const rows = new Map((seed?.values ?? []).map((row) => [row.id, row]));
146705
+ const copiedById = /* @__PURE__ */ new Map();
146706
+ const insideInitializerCopy = (id2) => {
146707
+ const walked = [];
146708
+ let inside = false;
146709
+ let parentId = bindings.locationForValue(id2)?.parentId;
146710
+ while (typeof parentId === "string" && parentId !== rootId) {
146711
+ const known = copiedById.get(parentId);
146712
+ if (known !== void 0) {
146713
+ inside = known;
146714
+ break;
146715
+ }
146716
+ walked.push(parentId);
146717
+ if (templateInitializer(parentId) !== null) {
146718
+ inside = true;
146719
+ break;
146720
+ }
146721
+ parentId = bindings.locationForValue(parentId)?.parentId;
146722
+ }
146723
+ for (const ancestorId of walked) copiedById.set(ancestorId, inside);
146724
+ return inside;
146725
+ };
146386
146726
  for (const id2 of rowIds) {
146387
146727
  if (id2 === rootId) continue;
146388
- const row = collectionBindings.rowForValue(id2);
146389
146728
  const location3 = collectionBindings.locationForValue(id2);
146390
- if (row === void 0 || !isLiteralValueContent(row) || location3 === void 0)
146391
- throw new Error(`Collection binding row ${id2} has no member.`);
146729
+ if (location3 === void 0) continue;
146730
+ if (insideInitializerCopy(id2)) continue;
146731
+ const row = collectionBindings.rowForValue(id2);
146732
+ if (row === void 0)
146733
+ throw new Error(`Collection binding row ${id2} is missing.`);
146734
+ if (!isLiteralValueContent(row))
146735
+ throw new Error(`Collection binding row ${id2} is not a literal.`);
146392
146736
  const isNew = rootPathResolutionState[`value:${id2}`] === void 0;
146737
+ const init = templateInitializer(id2);
146738
+ if (init !== null) {
146739
+ const authored2 = staticValueSeedRow(
146740
+ {
146741
+ id: id2,
146742
+ init,
146743
+ containerId: row.containerId,
146744
+ genericBindings: row.genericBindings
146745
+ },
146746
+ location3.memberId
146747
+ );
146748
+ rows.set(id2, authored2);
146749
+ if (isNew) valueLowerRegistry.pendingValues.set(id2, authored2);
146750
+ continue;
146751
+ }
146393
146752
  const classId = row.classId ?? (isMemberClassBase(location3.member) ? location3.member.classId : null);
146394
146753
  const authored = staticValueSeedRow(
146395
146754
  {
@@ -167506,7 +167865,7 @@ function generateUnitySchemaTypes(exportData, docs = EMPTY_UNITY_CODEGEN_DOCS) {
167506
167865
  generateDialogueMemoryPartials(ctx)
167507
167866
  ),
167508
167867
  "",
167509
- ...Object.values(exportData.enums).filter((enumDef) => enumDef.id !== NEO_CELL_PATTERN_EXCLUDING_ENUM_ID).flatMap(
167868
+ ...Object.values(exportData.enums).flatMap(
167510
167869
  (enumDef) => emit(
167511
167870
  `enum:${enumDef.id}`,
167512
167871
  `Enums/${ctx.enumNames.get(enumDef.id)}`,
@@ -167523,7 +167882,7 @@ function generateUnitySchemaTypes(exportData, docs = EMPTY_UNITY_CODEGEN_DOCS) {
167523
167882
  ""
167524
167883
  ]),
167525
167884
  ...Object.values(exportData.classes).flatMap(
167526
- (classDef) => isRuntimeHandleSystemClass(ctx, classDef) || classDef.id === NEO_CELL_PATTERN_CLASS_ID ? [] : emit(
167885
+ (classDef) => isRuntimeHandleSystemClass(ctx, classDef) ? [] : emit(
167527
167886
  `class:${classDef.id}`,
167528
167887
  `Classes/${ctx.typeNames.get(classDef.id)}`,
167529
167888
  generateNeoSchemaClassClass(ctx, classDef.id)
@@ -167805,8 +168164,6 @@ function generateGeneratedValueFactories(ctx) {
167805
168164
  " new Dictionary<string, NeoGeneratedTypesSupport.ReadOnlyClassFactory>",
167806
168165
  " {",
167807
168166
  ...concreteClasses.map((classDef) => {
167808
- if (classDef.id === NEO_CELL_PATTERN_CLASS_ID)
167809
- return ` ["${classDef.id}"] = NeoCellPatternStorage.ReadRequired,`;
167810
168167
  const className = ctx.typeNames.get(classDef.id);
167811
168168
  return ` ["${escapeCSharpString(classDef.id)}"] = (client, node) => ${qualifyGeneratedType(ctx, className)}.Create(client, node),`;
167812
168169
  }),
@@ -167823,8 +168180,6 @@ function generateGeneratedValueFactories(ctx) {
167823
168180
  ...concreteClasses.filter(
167824
168181
  (classDef) => classAllowedStorage(ctx, classDef.id) !== 1 /* Immutable */
167825
168182
  ).map((classDef) => {
167826
- if (classDef.id === NEO_CELL_PATTERN_CLASS_ID)
167827
- return ` ["${classDef.id}"] = (client, node) => NeoCellPatternStorage.ReadRequired(client, node),`;
167828
168183
  const className = ctx.typeNames.get(classDef.id);
167829
168184
  return ` ["${escapeCSharpString(classDef.id)}"] = (client, node) => ${qualifyGeneratedType(ctx, savedTypeName(className))}.CreateWritable(client, node),`;
167830
168185
  }),
@@ -167837,8 +168192,6 @@ function generateGeneratedValueFactories(ctx) {
167837
168192
  " new Dictionary<Type, string>",
167838
168193
  " {",
167839
168194
  ...concreteClasses.map((classDef) => {
167840
- if (classDef.id === NEO_CELL_PATTERN_CLASS_ID)
167841
- return ` [typeof(NeoCompose.Runtime.NeoCellPattern)] = "${classDef.id}",`;
167842
168195
  const className = ctx.typeNames.get(classDef.id);
167843
168196
  return ` [typeof(${qualifyGeneratedType(ctx, className)})] = "${escapeCSharpString(classDef.id)}",`;
167844
168197
  }),
@@ -167886,6 +168239,11 @@ function generateNativeFunctionInvokers(ctx) {
167886
168239
  function callableIsDeferred(member) {
167887
168240
  return isAsynchronousFunctionMember(member);
167888
168241
  }
168242
+ function emitsStaticMember(ctx, member) {
168243
+ if (member === void 0) return false;
168244
+ if (!isStaticMember(member)) return false;
168245
+ return ctx.singleton || requiresUnitySingleton(member);
168246
+ }
167889
168247
  function isPlatformNativeMemberId(memberId) {
167890
168248
  return memberId === NEO_TILE_CONVERT_MEMBER_ID || NEO_CELL_PATTERN_PURE_NATIVE_MEMBER_IDS.has(memberId) || Object.values(NEO_OBJECT_GRID_MEMBER_IDS).some((id2) => id2 === memberId);
167891
168249
  }
@@ -167907,6 +168265,7 @@ function collectFunctionInvokers(ctx) {
167907
168265
  if (member === null || !isMemberFunctionBase(member)) continue;
167908
168266
  seen.add(memberId);
167909
168267
  if (isStaticMember(member) === true) {
168268
+ if (!emitsStaticMember(ctx, ctx.exportData.members[memberId])) continue;
167910
168269
  invokers.push({
167911
168270
  memberId,
167912
168271
  deferred: isAsynchronousFunctionMember(member),
@@ -169292,6 +169651,9 @@ function rootGeneratedClassBaseName(classDef) {
169292
169651
  if (classDef.system?.worldKind === NeoWorldSystemClassKind.ObjectBase) {
169293
169652
  return "NeoGeneratedWorldObjectValue";
169294
169653
  }
169654
+ if (classDef.system?.worldKind === NeoWorldSystemClassKind.CellPattern) {
169655
+ return CELL_PATTERN_VALUE_BASE;
169656
+ }
169295
169657
  return "NeoGeneratedClassValue";
169296
169658
  }
169297
169659
  function rootGeneratedClassInterfaceName(classDef) {
@@ -169464,7 +169826,7 @@ function generateNeoSchemaClassClass(ctx, classId) {
169464
169826
  (entry) => entry[1] !== null && isStaticMember(ctx.exportData.members[entry[1]]) !== true
169465
169827
  );
169466
169828
  const ownStaticMemberEntries = ownEntries.filter(
169467
- (entry) => entry[1] !== null && isStaticMember(ctx.exportData.members[entry[1]]) === true
169829
+ (entry) => entry[1] !== null && emitsStaticMember(ctx, ctx.exportData.members[entry[1]])
169468
169830
  );
169469
169831
  const mergedEntries = getMergedSchemaEntries(ctx, classDef);
169470
169832
  const mergedMemberEntries = mergedEntries.filter(
@@ -171163,6 +171525,9 @@ function planWorldKindContractEmission(ctx, classDef) {
171163
171525
  if (WORLD_OBJECT_CONTRACT_WORLD_KINDS.has(worldKind)) {
171164
171526
  return planWorldObjectEmission(ctx, classDef, worldKind);
171165
171527
  }
171528
+ if (worldKind === NeoWorldSystemClassKind.CellPattern) {
171529
+ return CELL_PATTERN_CONTRACT_PLAN;
171530
+ }
171166
171531
  return EMPTY_RUNTIME_CONTRACT_PLAN;
171167
171532
  }
171168
171533
  function planWorldObjectEmission(ctx, classDef, worldKind) {
@@ -172071,13 +172436,6 @@ function genericParamConstraintClauses(ctx, classDef, scope, saved, env) {
172071
172436
  if (constraint === void 0 || !isClassGenericConstraint(constraint)) {
172072
172437
  continue;
172073
172438
  }
172074
- if (rejectCellPatternIdentity(
172075
- ctx,
172076
- constraint.classId,
172077
- "generic class constraint",
172078
- `classes.${classDef.id}.genericParams.${inScope.param.id}.constraint`
172079
- ))
172080
- continue;
172081
172439
  const targetName = ctx.typeNames.get(constraint.classId);
172082
172440
  if (targetName === void 0) {
172083
172441
  ctx.diagnostics.push({
@@ -172268,7 +172626,7 @@ function generateCreateDetachedMethod(ctx, classId, className) {
172268
172626
  function classSupportsDetachedViews(ctx, classId) {
172269
172627
  try {
172270
172628
  return resolveInheritanceChain(classId, ctx.classes).every(
172271
- (classDef) => schemaClassHasWritableFamily(ctx, classDef.id) && resolveGenericEnvForEmission(ctx, classDef.id).size === 0 && rootGeneratedClassBaseName(classDef) === "NeoGeneratedClassValue"
172629
+ (classDef) => schemaClassHasWritableFamily(ctx, classDef.id) && resolveGenericEnvForEmission(ctx, classDef.id).size === 0 && DETACHED_VIEW_ROOT_BASES.has(rootGeneratedClassBaseName(classDef))
172272
172630
  );
172273
172631
  } catch {
172274
172632
  return false;
@@ -172910,7 +173268,7 @@ function staticStoredGetter(ctx, member, memberId, storage, saved, nodeType, val
172910
173268
  ];
172911
173269
  }
172912
173270
  function isEnumSetMember(member) {
172913
- return isMemberEnumBase(member) && isMultiSelectionMember(member) && member.enumId !== NEO_CELL_PATTERN_EXCLUDING_ENUM_ID;
173271
+ return isMemberEnumBase(member) && isMultiSelectionMember(member);
172914
173272
  }
172915
173273
  function staticReadNodeType(member, nodeType, saved) {
172916
173274
  if (!saved) return nodeType;
@@ -173732,8 +174090,6 @@ function renderCSharpParameterDefault(ctx, argument2, path) {
173732
174090
  });
173733
174091
  return null;
173734
174092
  }
173735
- if (argument2.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
173736
- return `NeoCompose.Runtime.NeoCellPatternExcluding.${schemaKeyToMemberName(option.name)}`;
173737
174093
  return `${enumName}.${accessor}`;
173738
174094
  }
173739
174095
  default: {
@@ -173743,7 +174099,7 @@ function renderCSharpParameterDefault(ctx, argument2, path) {
173743
174099
  }
173744
174100
  }
173745
174101
  function scriptValueExpression(ctx, typeInfo, expression) {
173746
- return typeInfo.type === 8 /* Enum */ && typeInfo.enumId !== NEO_CELL_PATTERN_EXCLUDING_ENUM_ID && ctx.enumNames.has(typeInfo.enumId) ? `${expression}${typeInfo.required ? "" : "?"}.OptionId()` : expression;
174102
+ return typeInfo.type === 8 /* Enum */ && ctx.enumNames.has(typeInfo.enumId) ? `${expression}${typeInfo.required ? "" : "?"}.OptionId()` : expression;
173747
174103
  }
173748
174104
  function renderFunctionParameters(ctx, member, genericBindingSaved, genericEnv, path) {
173749
174105
  return member.argumentTypes.map((argument2, index) => {
@@ -173862,11 +174218,13 @@ function generateFunctionMethod(ctx, member, schemaKey, modifier = "", emitBody
173862
174218
  "{",
173863
174219
  ...indent([
173864
174220
  `var result = client.ScriptGridQueries.Invoke("${member.id}", this, new object?[] ${deferredArgs});`,
174221
+ // A grid query returns the placed row as stored: authored placements
174222
+ // are asset-owned, and a save-owned row still reads as writable.
173865
174223
  ...nsGetterResultReturnExpression(
173866
174224
  ctx,
173867
174225
  member.returnTypeInfo,
173868
174226
  "result",
173869
- true,
174227
+ false,
173870
174228
  genericEnv
173871
174229
  )
173872
174230
  ]),
@@ -173974,8 +174332,6 @@ function nativeFunctionArgExpression(ctx, typeInfo, valueExpression, argumentNam
173974
174332
  case 19 /* Color */:
173975
174333
  return required2 ? `NeoGeneratedTypesSupport.ReadColorValue(${valueExpression}) ?? throw new InvalidOperationException("Required Color argument '${escapeCSharpString(argumentName)}' could not be resolved.")` : `NeoGeneratedTypesSupport.ReadColorValue(${valueExpression})`;
173976
174334
  case 8 /* Enum */: {
173977
- if (typeInfo.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
173978
- return `NeoCellPatternStorage.${required2 ? "ReadExcluding" : "ReadOptionalExcluding"}(${valueExpression})`;
173979
174335
  const parser = enumParser(ctx, typeInfo.enumId);
173980
174336
  return required2 ? `NeoGeneratedTypesSupport.ReadEnumSingle(${valueExpression}, ${parser}) ?? throw new InvalidOperationException("Required enum argument '${escapeCSharpString(argumentName)}' could not be resolved.")` : `NeoGeneratedTypesSupport.ReadEnumSingle(${valueExpression}, ${parser})`;
173981
174337
  }
@@ -173984,8 +174340,6 @@ function nativeFunctionArgExpression(ctx, typeInfo, valueExpression, argumentNam
173984
174340
  return required2 ? `new NeoDialogueReference(client, ${dialogueIds}[0])` : `${valueExpression} is null ? null : new NeoDialogueReference(client, ${dialogueIds}[0])`;
173985
174341
  }
173986
174342
  case 7 /* Class */: {
173987
- if (typeInfo.classId === NEO_CELL_PATTERN_CLASS_ID)
173988
- return `NeoCellPatternStorage.ReadResult(client, ${valueExpression}, ${required2})${required2 ? "!" : ""}`;
173989
174343
  const typeName = ctx.typeNames.get(typeInfo.classId);
173990
174344
  const suffix = typeInfoConstructedSuffix(
173991
174345
  ctx,
@@ -174014,8 +174368,6 @@ function nativeFunctionArgExpression(ctx, typeInfo, valueExpression, argumentNam
174014
174368
  return `(${projected})${valueExpression}!`;
174015
174369
  }
174016
174370
  if (isMemberEnumBase(binding) && isMultiSelectionMember(binding)) {
174017
- if (binding.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
174018
- return `NeoCellPatternStorage.ReadExcludingList(${valueExpression})`;
174019
174371
  return `NeoGeneratedTypesSupport.ReadEnumSet(${valueExpression}${enumKeyCodecArguments(ctx, binding.enumId)})`;
174020
174372
  }
174021
174373
  if (isMemberClassBase(binding)) {
@@ -174248,11 +174600,6 @@ function nsGetterResultReturnExpression(ctx, returnTypeInfo, valueExpression, sa
174248
174600
  optional2 ? "return resolvedColor;" : 'return resolvedColor ?? throw new InvalidOperationException("NSProperty returned null for a required Color value.");'
174249
174601
  ];
174250
174602
  case 8 /* Enum */: {
174251
- if (returnTypeInfo.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
174252
- return [
174253
- ...prefix,
174254
- `return NeoCellPatternStorage.${optional2 ? "ReadOptionalExcluding" : "ReadExcluding"}(${valueExpression});`
174255
- ];
174256
174603
  return [
174257
174604
  ...prefix,
174258
174605
  `var selected = NeoGeneratedTypesSupport.ReadEnumSingle(${valueExpression}, ${enumParser(ctx, returnTypeInfo.enumId)});`,
@@ -174308,8 +174655,6 @@ function nsCollectionResultExpression(ctx, typeInfo, valueExpression, saved, gen
174308
174655
  return typeInfo.required ? read : `${valueExpression} is null ? null : ${read}`;
174309
174656
  }
174310
174657
  function nsGetterCustomResultExpression(ctx, classId, required2, valueExpression, saved, constructedSuffix, qualifyType = false) {
174311
- if (classId === NEO_CELL_PATTERN_CLASS_ID)
174312
- return `NeoCellPatternStorage.ReadResult(client, ${valueExpression}, ${required2})${required2 ? "!" : ""}`;
174313
174658
  const typeName = ctx.typeNames.get(classId);
174314
174659
  if (typeName === void 0) return valueExpression;
174315
174660
  const constraint = classAllowedStorage(ctx, classId);
@@ -174366,8 +174711,6 @@ function nsGetterGenericResultExpression(ctx, typeInfo, valueExpression, saved,
174366
174711
  return required2 ? `NeoGeneratedTypesSupport.ReadAudioClip(client, ${valueExpression}) ?? throw new InvalidOperationException("Required generic AudioClip result could not be resolved.")` : `NeoGeneratedTypesSupport.ReadAudioClip(client, ${valueExpression})`;
174367
174712
  }
174368
174713
  if (isMemberEnumBase(binding)) {
174369
- if (binding.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
174370
- return `NeoCellPatternStorage.${isMultiSelectionMember(binding) ? "ReadExcludingList" : required2 ? "ReadExcluding" : "ReadOptionalExcluding"}(${valueExpression})`;
174371
174714
  const parser = enumParser(ctx, binding.enumId);
174372
174715
  if (isMultiSelectionMember(binding)) {
174373
174716
  return `NeoGeneratedTypesSupport.ReadEnumSet(${valueExpression}${enumKeyCodecArguments(ctx, binding.enumId)})`;
@@ -174524,8 +174867,6 @@ function detachedValueExpression(ctx, member, value, required2, saved, genericEn
174524
174867
  if (isMemberStringBase(member))
174525
174868
  return required2 ? `(string)${value}!` : `(string?)${value}`;
174526
174869
  if (isMemberEnumBase(member)) {
174527
- if (member.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
174528
- return `NeoCellPatternStorage.${isMultiSelectionMember(member) ? "ReadExcludingList" : required2 ? "ReadExcluding" : "ReadOptionalExcluding"}(${value})`;
174529
174870
  if (!ctx.enumNames.has(member.enumId)) return null;
174530
174871
  const parser = enumParser(ctx, member.enumId);
174531
174872
  if (isMultiSelectionMember(member))
@@ -174633,10 +174974,6 @@ function storedReadExpression(ctx, member, schemaKey, nodeType, saved, ownerClas
174633
174974
  );
174634
174975
  }
174635
174976
  if (isMemberClassBase(member)) {
174636
- if (member.classId === NEO_CELL_PATTERN_CLASS_ID)
174637
- return [
174638
- `return NeoCellPatternStorage.${isRequiredMember(member) ? "ReadRequired" : "Read"}(client, ${getNode});`
174639
- ];
174640
174977
  const typeName = ctx.typeNames.get(member.classId) ?? "NeoNode";
174641
174978
  const constructedSuffix = constructedTypeArgumentsSuffix(ctx, member, true, genericEnv) ?? "";
174642
174979
  const savedTypeRef = `${qualifyGeneratedType(ctx, savedTypeName(typeName))}${constructedSuffix}`;
@@ -174695,10 +175032,6 @@ function storedReadExpression(ctx, member, schemaKey, nodeType, saved, ownerClas
174695
175032
  ];
174696
175033
  }
174697
175034
  if (isMemberEnumBase(member)) {
174698
- if (member.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
174699
- return [
174700
- `return NeoCellPatternStorage.${isMultiSelectionMember(member) ? "ReadExcludingList" : isRequiredMember(member) ? "ReadExcluding" : "ReadOptionalExcluding"}(${getNode}.Selected());`
174701
- ];
174702
175035
  if (isMultiSelectionMember(member)) {
174703
175036
  return enumSetReadExpression(
174704
175037
  ctx,
@@ -174867,10 +175200,6 @@ function writeExpression(ctx, member, schemaKey, ownerClassName, ownerClassId) {
174867
175200
  ];
174868
175201
  }
174869
175202
  if (isMemberEnumBase(member)) {
174870
- if (member.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
174871
- return [
174872
- `NeoGeneratedTypesSupport.SetValue(writableNode, "${key}", NeoGeneratedTypesSupport.Value(NeoCellPatternStorage.${isMultiSelectionMember(member) ? "ExcludingListIds" : "OptionalExcludingIds"}(value)));`
174873
- ];
174874
175203
  if (isMultiSelectionMember(member)) return null;
174875
175204
  return isRequiredMember(member) ? [
174876
175205
  `NeoGeneratedTypesSupport.SetValue(writableNode, "${key}", NeoGeneratedTypesSupport.Value(new[] { value.OptionId() }));`
@@ -174905,10 +175234,6 @@ function writeExpression(ctx, member, schemaKey, ownerClassName, ownerClassId) {
174905
175234
  ] : isRequiredMember(member) ? [`${nodeAccess}.Set(new[] { value.Id });`] : [`${nodeAccess}.Set(value is null ? null : new[] { value.Id });`];
174906
175235
  }
174907
175236
  if (isMemberClassBase(member)) {
174908
- if (member.classId === NEO_CELL_PATTERN_CLASS_ID)
174909
- return [
174910
- `NeoGeneratedTypesSupport.SetValue(writableNode, "${key}", NeoCellPatternStorage.Serialize(client, value));`
174911
- ];
174912
175237
  return isRequiredMember(member) ? [
174913
175238
  `NeoGeneratedTypesSupport.SetValue(writableNode, "${key}", NeoGeneratedTypesSupport.ValueReference(value));`
174914
175239
  ] : [
@@ -175004,7 +175329,7 @@ function readOnlySetSerializeArgument(ctx, member, entryMember, node, genericEnv
175004
175329
  return `, item => ${serialize2}`;
175005
175330
  }
175006
175331
  function enumKeyCodecArguments(ctx, enumId) {
175007
- return enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID ? ", id => NeoCellPatternStorage.ReadExcluding(new[] { id }), key => NeoCellPatternStorage.ExcludingIds(key)[0]" : `, ${enumParser(ctx, enumId)}, key => key.OptionId()`;
175332
+ return `, ${enumParser(ctx, enumId)}, key => key.OptionId()`;
175008
175333
  }
175009
175334
  function dictionaryKeyCodecArguments(ctx, member) {
175010
175335
  if (!isEnumKeyedDictionaryMember(member)) return "";
@@ -175014,10 +175339,8 @@ function dictionaryKeyCodecArguments(ctx, member) {
175014
175339
  function serializeItemExpression(ctx, member, valueExpression) {
175015
175340
  if (member === null) return valueExpression;
175016
175341
  if (isMemberClassBase(member))
175017
- return member.classId === NEO_CELL_PATTERN_CLASS_ID ? `NeoCellPatternStorage.Serialize(client, ${valueExpression})` : `NeoGeneratedTypesSupport.ValueReference(${valueExpression})`;
175342
+ return `NeoGeneratedTypesSupport.ValueReference(${valueExpression})`;
175018
175343
  if (isMemberEnumBase(member)) {
175019
- if (member.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
175020
- return `NeoGeneratedTypesSupport.Value(NeoCellPatternStorage.${isMultiSelectionMember(member) ? "ExcludingListIds" : "OptionalExcludingIds"}(${valueExpression}))`;
175021
175344
  const rawExpression = isMultiSelectionMember(member) ? `${enumOptionsName(ctx, member.enumId)}.ToOptionIds(${valueExpression})` : `${valueExpression} is ${ctx.enumNames.get(member.enumId) ?? "NeoEnum"} enumOption ? new[] { enumOption.OptionId() } : null`;
175022
175345
  return `NeoGeneratedTypesSupport.Value(${rawExpression})`;
175023
175346
  }
@@ -175209,8 +175532,6 @@ function childConverter(ctx, member, saved = false, branchOnReadOnly = false, ge
175209
175532
  return isRequiredMember(member) ? `new ${wrapperType}((NeoMemberColor)child${leafOwnerArgument})` : `((NeoMemberColor)child).value is null ? null : new ${wrapperType}((NeoMemberColor)child${leafOwnerArgument})`;
175210
175533
  }
175211
175534
  if (isMemberClassBase(member)) {
175212
- if (member.classId === NEO_CELL_PATTERN_CLASS_ID)
175213
- return `NeoCellPatternStorage.${isRequiredMember(member) ? "ReadRequired" : "Read"}(client, (NeoMemberClass)child)`;
175214
175535
  const typeName = ctx.typeNames.get(member.classId) ?? "NeoNode";
175215
175536
  const constructedSuffix = constructedTypeArgumentsSuffix(ctx, member, true, genericEnv) ?? "";
175216
175537
  const savedTypeRef = `${qualifyGeneratedType(ctx, savedTypeName(typeName))}${constructedSuffix}`;
@@ -175223,8 +175544,6 @@ function childConverter(ctx, member, saved = false, branchOnReadOnly = false, ge
175223
175544
  return isRequiredMember(member) ? factory : `((NeoMemberClass)child).value?.value is null ? null : ${factory}`;
175224
175545
  }
175225
175546
  if (isMemberEnumBase(member)) {
175226
- if (member.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
175227
- return `NeoCellPatternStorage.${isMultiSelectionMember(member) ? "ReadExcludingList" : isRequiredMember(member) ? "ReadExcluding" : "ReadOptionalExcluding"}(((NeoMemberEnum)child).Selected())`;
175228
175547
  const parser = enumParser(ctx, member.enumId);
175229
175548
  const setType = csharpValueType(ctx, member, saved, genericEnv);
175230
175549
  return isMultiSelectionMember(member) ? saved ? `new ${setType}(client, (NeoMemberEnum)child, () => (NeoMemberEnumWritable)child${enumKeyCodecArguments(ctx, member.enumId)})` : `new ${setType}(client, (NeoMemberEnum)child${enumKeyCodecArguments(ctx, member.enumId)})` : isRequiredMember(member) ? `NeoGeneratedTypesSupport.ReadEnumSingle(((NeoMemberEnum)child).Selected(), ${parser}) ?? throw new InvalidOperationException("Required enum '${escapeCSharpString(member.name)}' has no selected option.")` : `NeoGeneratedTypesSupport.ReadEnumSingle(((NeoMemberEnum)child).Selected(), ${parser})`;
@@ -175279,8 +175598,6 @@ function nsGetterChildConverter(ctx, returnTypeInfo, saved, genericEnv) {
175279
175598
  return returnTypeInfo.required ? `${readExpression2} ?? throw new InvalidOperationException("NSProperty returned null for a required Color value.")` : readExpression2;
175280
175599
  }
175281
175600
  case 8 /* Enum */: {
175282
- if (returnTypeInfo.enumId === NEO_CELL_PATTERN_EXCLUDING_ENUM_ID)
175283
- return `NeoCellPatternStorage.${returnTypeInfo.required ? "ReadExcluding" : "ReadOptionalExcluding"}(${valueExpression})`;
175284
175601
  const readExpression2 = `NeoGeneratedTypesSupport.ReadEnumSingle(${valueExpression}, ${enumParser(ctx, returnTypeInfo.enumId)})`;
175285
175602
  return returnTypeInfo.required ? `${readExpression2} ?? throw new InvalidOperationException("NSProperty returned null for a required enum value.")` : readExpression2;
175286
175603
  }
@@ -175351,7 +175668,7 @@ function escapeCSharpString(value) {
175351
175668
  (character) => CSHARP_STRING_ESCAPES.get(character) ?? `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`
175352
175669
  );
175353
175670
  }
175354
- var NEO_MEMORY_SCHEMA_KEYS, NEO_MEMORY_CLASS_NAMES, CHILDREN_SCHEMA_KEY, TILE_LAYER_LINK_INTERFACE, OBJECT_LAYER_LINK_INTERFACE, OBJECT_SPAWN_HOOKS_INTERFACE, TILE_LAYER_RENDER_TARGET_PROVIDER_INTERFACE, SMART_TILE_SOURCE_INTERFACE, SMART_TILE_INTERFACE, SMART_TILE_RULE_INTERFACE, SMART_TILE_NEIGHBOR_INTERFACE, WORLD_OBJECT_VALUE_INTERFACE, OBJECT_COMPOSITION_SOURCE_INTERFACE, COLLIDER_SOURCE_INTERFACE, SORTING_GROUP_SOURCE_INTERFACE, COLLIDER_INTERFACE, SORTING_GROUP_INTERFACE, SPRITE_OBJECT_VALUE_INTERFACE, SORTING_GROUP_SOURCE_MEMBER_NAME, OBJECT_BASE_NAME_SCHEMA_KEY, OBJECT_BASE_POSITION_SCHEMA_KEY, OBJECT_BASE_SIZE_SCHEMA_KEY, SPRITE_OBJECT_SPRITE_SCHEMA_KEY, SPRITE_OBJECT_FLIP_X_SCHEMA_KEY, SPRITE_OBJECT_FLIP_Y_SCHEMA_KEY, SPRITE_OBJECT_MASK_INTERACTION_SCHEMA_KEY, SPRITE_OBJECT_SORTING_ORDER_SCHEMA_KEY, TILE_CELL_SCHEMA_KEY, EMPTY_RUNTIME_CONTRACT_PLAN, SMART_TILE_CONTRACT_WORLD_KINDS, WORLD_OBJECT_CONTRACT_WORLD_KINDS, SMART_TILE_NEIGHBOR_TILE_RELATION_EXPRESSION, REQUIRED_STRING_CONTRACT_FIELD, REQUIRED_BOOL_CONTRACT_FIELD, OPTIONAL_BOOL_CONTRACT_FIELD, OPTIONAL_INT_CONTRACT_FIELD, REQUIRED_FLOAT_CONTRACT_FIELD, REQUIRED_SPRITE_CONTRACT_FIELD, REQUIRED_VECTOR2_CONTRACT_FIELD, OPTIONAL_VECTOR2_CONTRACT_FIELD, REQUIRED_VECTOR2_INT_CONTRACT_FIELD, REQUIRED_VECTOR3_CONTRACT_FIELD, concreteDescendants, VARIANTS_SCOPE_NAME, BASE_VARIANT_NAME, VARIANT_APPLY_METHOD_NAME, VARIANT_FOLDER_SEPARATOR, SCRIPT_COLLECTION_READERS, CSHARP_STRING_ESCAPES, UNRESOLVED_VARIANT_TARGET;
175671
+ var NEO_MEMORY_SCHEMA_KEYS, NEO_MEMORY_CLASS_NAMES, CELL_PATTERN_VALUE_BASE, DETACHED_VIEW_ROOT_BASES, CHILDREN_SCHEMA_KEY, TILE_LAYER_LINK_INTERFACE, OBJECT_LAYER_LINK_INTERFACE, OBJECT_SPAWN_HOOKS_INTERFACE, TILE_LAYER_RENDER_TARGET_PROVIDER_INTERFACE, SMART_TILE_SOURCE_INTERFACE, SMART_TILE_INTERFACE, SMART_TILE_RULE_INTERFACE, SMART_TILE_NEIGHBOR_INTERFACE, WORLD_OBJECT_VALUE_INTERFACE, OBJECT_COMPOSITION_SOURCE_INTERFACE, COLLIDER_SOURCE_INTERFACE, SORTING_GROUP_SOURCE_INTERFACE, COLLIDER_INTERFACE, SORTING_GROUP_INTERFACE, SPRITE_OBJECT_VALUE_INTERFACE, CELL_PATTERN_INTERFACE, SORTING_GROUP_SOURCE_MEMBER_NAME, OBJECT_BASE_NAME_SCHEMA_KEY, OBJECT_BASE_POSITION_SCHEMA_KEY, OBJECT_BASE_SIZE_SCHEMA_KEY, SPRITE_OBJECT_SPRITE_SCHEMA_KEY, SPRITE_OBJECT_FLIP_X_SCHEMA_KEY, SPRITE_OBJECT_FLIP_Y_SCHEMA_KEY, SPRITE_OBJECT_MASK_INTERACTION_SCHEMA_KEY, SPRITE_OBJECT_SORTING_ORDER_SCHEMA_KEY, TILE_CELL_SCHEMA_KEY, EMPTY_RUNTIME_CONTRACT_PLAN, CELL_PATTERN_CONTRACT_PLAN, SMART_TILE_CONTRACT_WORLD_KINDS, WORLD_OBJECT_CONTRACT_WORLD_KINDS, SMART_TILE_NEIGHBOR_TILE_RELATION_EXPRESSION, REQUIRED_STRING_CONTRACT_FIELD, REQUIRED_BOOL_CONTRACT_FIELD, OPTIONAL_BOOL_CONTRACT_FIELD, OPTIONAL_INT_CONTRACT_FIELD, REQUIRED_FLOAT_CONTRACT_FIELD, REQUIRED_SPRITE_CONTRACT_FIELD, REQUIRED_VECTOR2_CONTRACT_FIELD, OPTIONAL_VECTOR2_CONTRACT_FIELD, REQUIRED_VECTOR2_INT_CONTRACT_FIELD, REQUIRED_VECTOR3_CONTRACT_FIELD, concreteDescendants, VARIANTS_SCOPE_NAME, BASE_VARIANT_NAME, VARIANT_APPLY_METHOD_NAME, VARIANT_FOLDER_SEPARATOR, SCRIPT_COLLECTION_READERS, CSHARP_STRING_ESCAPES, UNRESOLVED_VARIANT_TARGET;
175355
175672
  var init_generate_unity_classes = __esm({
175356
175673
  "../src/models/exports/unity-codegen/generate-unity-classes.ts"() {
175357
175674
  "use strict";
@@ -175396,6 +175713,11 @@ var init_generate_unity_classes = __esm({
175396
175713
  textNodeMemory: "NeoTextNodeMemory",
175397
175714
  choiceLog: "NeoChoiceLog"
175398
175715
  };
175716
+ CELL_PATTERN_VALUE_BASE = "NeoGeneratedCellPatternValue";
175717
+ DETACHED_VIEW_ROOT_BASES = /* @__PURE__ */ new Set([
175718
+ "NeoGeneratedClassValue",
175719
+ CELL_PATTERN_VALUE_BASE
175720
+ ]);
175399
175721
  CHILDREN_SCHEMA_KEY = "Children";
175400
175722
  TILE_LAYER_LINK_INTERFACE = "INeoTileLayerLinkValue";
175401
175723
  OBJECT_LAYER_LINK_INTERFACE = "INeoObjectLayerLinkValue";
@@ -175412,6 +175734,7 @@ var init_generate_unity_classes = __esm({
175412
175734
  COLLIDER_INTERFACE = "INeoCollider";
175413
175735
  SORTING_GROUP_INTERFACE = "INeoSortingGroup";
175414
175736
  SPRITE_OBJECT_VALUE_INTERFACE = "INeoSpriteObjectValue";
175737
+ CELL_PATTERN_INTERFACE = "INeoCellPattern";
175415
175738
  SORTING_GROUP_SOURCE_MEMBER_NAME = "SortingGroup";
175416
175739
  OBJECT_BASE_NAME_SCHEMA_KEY = "Name";
175417
175740
  OBJECT_BASE_POSITION_SCHEMA_KEY = "Position";
@@ -175427,6 +175750,12 @@ var init_generate_unity_classes = __esm({
175427
175750
  classMembers: [],
175428
175751
  shadowedSchemaKeys: /* @__PURE__ */ new Set()
175429
175752
  };
175753
+ CELL_PATTERN_CONTRACT_PLAN = {
175754
+ runtimeInterfaces: [CELL_PATTERN_INTERFACE],
175755
+ classMembers: [],
175756
+ // NeoScript `Count` hides `IReadOnlyCollection<Vector2Int>.Count`.
175757
+ shadowedSchemaKeys: /* @__PURE__ */ new Set(["Count"])
175758
+ };
175430
175759
  SMART_TILE_CONTRACT_WORLD_KINDS = /* @__PURE__ */ new Set([
175431
175760
  NeoWorldSystemClassKind.Tile,
175432
175761
  NeoWorldSystemClassKind.SmartTile,
@@ -178722,7 +179051,7 @@ var UNITY_CODEGEN_REVISION;
178722
179051
  var init_unity_codegen_revision = __esm({
178723
179052
  "../src/models/exports/unity-codegen-revision.ts"() {
178724
179053
  "use strict";
178725
- UNITY_CODEGEN_REVISION = "8e940ebfec562d0be7fe7b82014f66293ea075c2ca394c3a3eaac419eaddfeb8";
179054
+ UNITY_CODEGEN_REVISION = "bac1e765b6731dfd0abb8404c7b4c2b65f161f2a539cc485ee297e555852f3ab";
178726
179055
  }
178727
179056
  });
178728
179057
 
@@ -184476,6 +184805,32 @@ var init_push = __esm({
184476
184805
  }
184477
184806
  });
184478
184807
 
184808
+ // ../src/database/project-record-delta.ts
184809
+ function decodeProjectRecordDelta(row) {
184810
+ const { dataJson, projectId, createdAt, ...record7 } = row;
184811
+ if (row.deleted) return { ...record7, data: null };
184812
+ const context = `Live delta row for ${row.recordKind} "${row.recordId}"`;
184813
+ if (dataJson === null) throw new Error(`${context} has no dataJson.`);
184814
+ if (projectId === null) throw new Error(`${context} has no projectId.`);
184815
+ if (createdAt === null) throw new Error(`${context} has no createdAt.`);
184816
+ return {
184817
+ ...record7,
184818
+ data: decodeProjectRecordSnapshotData({
184819
+ recordKind: row.recordKind,
184820
+ recordId: row.recordId,
184821
+ dataJson,
184822
+ projectId,
184823
+ createdAt
184824
+ })
184825
+ };
184826
+ }
184827
+ var init_project_record_delta = __esm({
184828
+ "../src/database/project-record-delta.ts"() {
184829
+ "use strict";
184830
+ init_projectRecordSnapshotStorage();
184831
+ }
184832
+ });
184833
+
184479
184834
  // src/document.ts
184480
184835
  function cursorFromRevision(revision) {
184481
184836
  return {
@@ -184760,7 +185115,8 @@ async function fetchProjectDocumentDelta(workspace, cursor) {
184760
185115
  );
184761
185116
  const { records: records3, heads } = document;
184762
185117
  const changedKeys = /* @__PURE__ */ new Set();
184763
- for (const record7 of result.records) {
185118
+ for (const wire of result.records) {
185119
+ const record7 = decodeProjectRecordDelta(wire);
184764
185120
  const key = `${record7.recordKind}:${record7.recordId}`;
184765
185121
  if (record7.deleted) {
184766
185122
  if (!records3.has(key)) continue;
@@ -184866,6 +185222,7 @@ var fetchProjectDocumentRawChunked2, readProjectDocumentContentHashHeads2, readP
184866
185222
  var init_document = __esm({
184867
185223
  "src/document.ts"() {
184868
185224
  "use strict";
185225
+ init_project_record_delta();
184869
185226
  init_project_read_base();
184870
185227
  init_project_document_read();
184871
185228
  init_project();
@@ -185788,7 +186145,14 @@ async function finishFormat4Pull(args) {
185788
186145
  for (const recovery of localResult.staticMemberOwnershipRecoveries ?? []) {
185789
186146
  warn(staticMemberOwnershipRecoveryMessage(recovery));
185790
186147
  }
185791
- const serverResult = conflictCount === 0 ? null : emitProjectDocumentFilesV4(
186148
+ let needsServerProjection = conflictCount > 0;
186149
+ for (const [key, record7] of document.records) {
186150
+ if (record7.recordKind === "value" && !record7.deleted && workspace.state.records[key] === void 0 && !localResult.recordFiles.has(key)) {
186151
+ needsServerProjection = true;
186152
+ break;
186153
+ }
186154
+ }
186155
+ const serverResult = !needsServerProjection ? null : emitProjectDocumentFilesV4(
185792
186156
  buildEmitRecordSet(document, plans, "server"),
185793
186157
  {
185794
186158
  formatSource,
@@ -198473,7 +198837,7 @@ There is no --keep-current: preserving current semantic state defines flatten.
198473
198837
  async function main() {
198474
198838
  const args = parseArgs(process.argv.slice(2));
198475
198839
  if (args.command === "--version") {
198476
- console.log("0.78.0");
198840
+ console.log("0.79.0");
198477
198841
  return;
198478
198842
  }
198479
198843
  if (args.command === null || args.command === "help" || args.command === "--help" || args.command === "-h") {