@neocompose/cli 0.80.0 → 0.81.1

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
@@ -715,11 +715,11 @@ var init_world_system_kinds_generated = __esm({
715
715
  ObjectCollider: "objectCollider",
716
716
  SortingGroup: "sortingGroup",
717
717
  LayerGroupBase: "layerGroupBase",
718
- SpriteObject: "spriteObject",
719
718
  PlacementTile: "placementTile",
720
719
  TileLayerLink: "tileLayerLink",
721
720
  ObjectLayerLink: "objectLayerLink",
722
721
  Object: "object",
722
+ SpriteObject: "spriteObject",
723
723
  SmartTile: "smartTile",
724
724
  SmartTileRule: "smartTileRule",
725
725
  SmartTileNeighbor: "smartTileNeighbor",
@@ -2910,6 +2910,8 @@ function isNSFunctionVariantApply(value) {
2910
2910
  if (!isNSPointer(info.variantPointer)) return false;
2911
2911
  if (info.rowPointer !== void 0 && !isNSPointer(info.rowPointer))
2912
2912
  return false;
2913
+ if (info.declarativeReplay !== void 0 && info.declarativeReplay !== true)
2914
+ return false;
2913
2915
  return isNSTypeInfoClass(info.schemaClassInfo) && info.schemaClassInfo.required;
2914
2916
  }
2915
2917
  function isNSFunctionClassConstructor(value) {
@@ -4920,7 +4922,9 @@ function isLiteralValueContent(value) {
4920
4922
  for (const field of [
4921
4923
  "instanceConstructorId",
4922
4924
  "instanceVariantId",
4923
- "instanceVariantRowValueId"
4925
+ "instanceVariantRowValueId",
4926
+ "instanceAppliedVariantId",
4927
+ "instanceAppliedVariantRowValueId"
4924
4928
  ]) {
4925
4929
  const provenance = getField(value, field);
4926
4930
  if (provenance !== void 0 && provenance !== null && (typeof provenance !== "string" || provenance.length === 0)) {
@@ -4946,6 +4950,9 @@ function isInitValueContent(value) {
4946
4950
  if (getField(value, "instanceConstructorId") !== void 0) return false;
4947
4951
  if (getField(value, "instanceVariantId") !== void 0) return false;
4948
4952
  if (getField(value, "instanceVariantRowValueId") !== void 0) return false;
4953
+ if (getField(value, "instanceAppliedVariantId") !== void 0) return false;
4954
+ if (getField(value, "instanceAppliedVariantRowValueId") !== void 0)
4955
+ return false;
4949
4956
  const classIdField = getField(value, "classId");
4950
4957
  return classIdField === void 0 || classIdField === null;
4951
4958
  }
@@ -5949,7 +5956,11 @@ function encodeStoredValueNode(node) {
5949
5956
  ...node.constructorArgs === void 0 ? {} : { constructorArgs: node.constructorArgs },
5950
5957
  ...node.instanceConstructorId === void 0 ? {} : { instanceConstructorId: node.instanceConstructorId },
5951
5958
  ...node.instanceVariantId === void 0 ? {} : { instanceVariantId: node.instanceVariantId },
5952
- ...node.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: node.instanceVariantRowValueId }
5959
+ ...node.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: node.instanceVariantRowValueId },
5960
+ ...node.instanceAppliedVariantId === void 0 ? {} : { instanceAppliedVariantId: node.instanceAppliedVariantId },
5961
+ ...node.instanceAppliedVariantRowValueId === void 0 ? {} : {
5962
+ instanceAppliedVariantRowValueId: node.instanceAppliedVariantRowValueId
5963
+ }
5953
5964
  };
5954
5965
  }
5955
5966
  function encodeStoredValueRowFields(row) {
@@ -5976,6 +5987,9 @@ function canonicalInstanceProvenanceViolation(value) {
5976
5987
  if ("instanceVariantRowValueId" in value && typeof value.instanceVariantRowValueId === "string" && typeof variantId !== "string") {
5977
5988
  return "variant-row-without-variant";
5978
5989
  }
5990
+ if ("instanceAppliedVariantRowValueId" in value && typeof value.instanceAppliedVariantRowValueId === "string" && !("instanceAppliedVariantId" in value && typeof value.instanceAppliedVariantId === "string")) {
5991
+ return "applied-variant-row-without-applied-variant";
5992
+ }
5979
5993
  return null;
5980
5994
  }
5981
5995
  var init_value_graph = __esm({
@@ -6005,7 +6019,11 @@ function pickInstanceProvenance(source) {
6005
6019
  ...source.constructorArgs === void 0 ? {} : { constructorArgs: source.constructorArgs },
6006
6020
  ...source.instanceConstructorId === void 0 ? {} : { instanceConstructorId: source.instanceConstructorId },
6007
6021
  ...source.instanceVariantId === void 0 ? {} : { instanceVariantId: source.instanceVariantId },
6008
- ...source.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: source.instanceVariantRowValueId }
6022
+ ...source.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: source.instanceVariantRowValueId },
6023
+ ...source.instanceAppliedVariantId === void 0 ? {} : { instanceAppliedVariantId: source.instanceAppliedVariantId },
6024
+ ...source.instanceAppliedVariantRowValueId === void 0 ? {} : {
6025
+ instanceAppliedVariantRowValueId: source.instanceAppliedVariantRowValueId
6026
+ }
6009
6027
  };
6010
6028
  }
6011
6029
  function isVirtualInstanceRootShape(value) {
@@ -6033,6 +6051,8 @@ var init_instance_provenance = __esm({
6033
6051
  "instanceConstructorId",
6034
6052
  "instanceVariantId",
6035
6053
  "instanceVariantRowValueId",
6054
+ "instanceAppliedVariantId",
6055
+ "instanceAppliedVariantRowValueId",
6036
6056
  "genericBindings"
6037
6057
  ];
6038
6058
  }
@@ -6299,7 +6319,7 @@ function decodeContentField(container, field, scope, children) {
6299
6319
  )
6300
6320
  };
6301
6321
  }
6302
- const decoded = {};
6322
+ const decoded = /* @__PURE__ */ Object.create(null);
6303
6323
  for (const [key, entry] of Object.entries(
6304
6324
  container
6305
6325
  )) {
@@ -6451,7 +6471,7 @@ function encodeContentField(container, pending, scope) {
6451
6471
  }
6452
6472
  if (typeof container !== "object" || container === null) return null;
6453
6473
  let changed = false;
6454
- const encoded = {};
6474
+ const encoded = /* @__PURE__ */ Object.create(null);
6455
6475
  for (const [key, entry] of Object.entries(
6456
6476
  container
6457
6477
  )) {
@@ -7675,64 +7695,6 @@ var init_world_system_classes_generated = __esm({
7675
7695
  modifier: 1 /* Abstract */,
7676
7696
  worldKind: "layerGroupBase"
7677
7697
  },
7678
- {
7679
- classId: "system_d48b66ab-4d59-47e7-a25a-591fe97062de",
7680
- name: "NeoSpriteObject",
7681
- extendsWorldKind: "objectBase",
7682
- schemaFields: [
7683
- {
7684
- memberId: "system_441cb790-a45f-4488-a5a9-6f375af6c369",
7685
- memberKind: "string",
7686
- defaultValue: "",
7687
- format: 1 /* Plain */,
7688
- distribution: 1 /* Packed */,
7689
- requirement: 1 /* Required */,
7690
- schemaKey: "Name"
7691
- },
7692
- {
7693
- memberId: "system_e9288ba9-f5a2-4485-8443-6afb155b31e0",
7694
- memberKind: "sprite",
7695
- defaultValue: { fileId: "", sliceIndex: 0 },
7696
- requirement: 1 /* Required */,
7697
- schemaKey: "Sprite"
7698
- },
7699
- {
7700
- memberId: "system_9fcab37a-9743-4e35-8eee-80cb560f1433",
7701
- memberKind: "bool",
7702
- defaultValue: false,
7703
- docsText: "Mirrors the sprite horizontally about its own centre. Maps to SpriteRenderer.flipX.",
7704
- requirement: 1 /* Required */,
7705
- schemaKey: "FlipX"
7706
- },
7707
- {
7708
- memberId: "system_ddd09f08-1656-4404-b36b-5570a4c01fcf",
7709
- memberKind: "bool",
7710
- defaultValue: false,
7711
- docsText: "Mirrors the sprite vertically about its own centre. Maps to SpriteRenderer.flipY.",
7712
- requirement: 1 /* Required */,
7713
- schemaKey: "FlipY"
7714
- },
7715
- {
7716
- memberId: "system_f2a8c86d-ace5-421b-9475-0f3f6f97b2a6",
7717
- memberKind: "enum",
7718
- defaultValue: ["system_9d607a4f-60c3-4347-94fc-f24b538bf468"],
7719
- docsText: "How this sprite reacts to sprite masks. Maps to SpriteRenderer.maskInteraction. The web canvas has no real sprite mask, so anything other than None previews as a distinguishable treatment rather than as the mask itself \u2014 only Unity renders the real thing.",
7720
- enumId: "system_4e6c4d6f-1d0b-402a-ad3a-be92242dceec",
7721
- requirement: 1 /* Required */,
7722
- schemaKey: "MaskInteraction"
7723
- },
7724
- {
7725
- memberId: "system_6f32f1f2-83ea-42fc-8647-34ed0946b7f1",
7726
- memberKind: "int",
7727
- defaultValue: null,
7728
- docsText: "Added to the object layer's sorting order; it does not replace it. The result competes with every renderer in the sorting layer, or in the enclosing sorting group, and among equal orders the renderer lower on screen draws in front. Leave unset to use the layer's order.",
7729
- minValue: -32768,
7730
- maxValue: 32767,
7731
- schemaKey: "SortingOrder"
7732
- }
7733
- ],
7734
- worldKind: "spriteObject"
7735
- },
7736
7698
  {
7737
7699
  classId: "system_ccc3330c-2db5-44dc-9c8e-5ebfe430dec9",
7738
7700
  name: "NeoPlacementTile",
@@ -7811,6 +7773,7 @@ var init_world_system_classes_generated = __esm({
7811
7773
  memberId: "system_5a9ca1f5-a21b-4d4e-8c55-00341af594b4",
7812
7774
  memberKind: "list",
7813
7775
  defaultValue: [],
7776
+ docsText: "The cells this object occupies, as offsets from its placement cell. An empty list occupies nothing: the object blocks no placement and answers no cell query, but a placed object still has a Cell.",
7814
7777
  entryMemberId: "system_96c7650a-1805-5b27-ae99-d1e49d3cb207",
7815
7778
  requirement: 1 /* Required */,
7816
7779
  schemaKey: "PlacementTiles"
@@ -7995,6 +7958,64 @@ var init_world_system_classes_generated = __esm({
7995
7958
  ],
7996
7959
  worldKind: "object"
7997
7960
  },
7961
+ {
7962
+ classId: "system_d48b66ab-4d59-47e7-a25a-591fe97062de",
7963
+ name: "NeoSpriteObject",
7964
+ extendsWorldKind: "object",
7965
+ schemaFields: [
7966
+ {
7967
+ memberId: "system_441cb790-a45f-4488-a5a9-6f375af6c369",
7968
+ memberKind: "string",
7969
+ defaultValue: "",
7970
+ format: 1 /* Plain */,
7971
+ distribution: 1 /* Packed */,
7972
+ requirement: 1 /* Required */,
7973
+ schemaKey: "Name"
7974
+ },
7975
+ {
7976
+ memberId: "system_e9288ba9-f5a2-4485-8443-6afb155b31e0",
7977
+ memberKind: "sprite",
7978
+ defaultValue: { fileId: "", sliceIndex: 0 },
7979
+ requirement: 1 /* Required */,
7980
+ schemaKey: "Sprite"
7981
+ },
7982
+ {
7983
+ memberId: "system_9fcab37a-9743-4e35-8eee-80cb560f1433",
7984
+ memberKind: "bool",
7985
+ defaultValue: false,
7986
+ docsText: "Mirrors the sprite horizontally about its own centre. Maps to SpriteRenderer.flipX.",
7987
+ requirement: 1 /* Required */,
7988
+ schemaKey: "FlipX"
7989
+ },
7990
+ {
7991
+ memberId: "system_ddd09f08-1656-4404-b36b-5570a4c01fcf",
7992
+ memberKind: "bool",
7993
+ defaultValue: false,
7994
+ docsText: "Mirrors the sprite vertically about its own centre. Maps to SpriteRenderer.flipY.",
7995
+ requirement: 1 /* Required */,
7996
+ schemaKey: "FlipY"
7997
+ },
7998
+ {
7999
+ memberId: "system_f2a8c86d-ace5-421b-9475-0f3f6f97b2a6",
8000
+ memberKind: "enum",
8001
+ defaultValue: ["system_9d607a4f-60c3-4347-94fc-f24b538bf468"],
8002
+ docsText: "How this sprite reacts to sprite masks. Maps to SpriteRenderer.maskInteraction. The web canvas has no real sprite mask, so anything other than None previews as a distinguishable treatment rather than as the mask itself \u2014 only Unity renders the real thing.",
8003
+ enumId: "system_4e6c4d6f-1d0b-402a-ad3a-be92242dceec",
8004
+ requirement: 1 /* Required */,
8005
+ schemaKey: "MaskInteraction"
8006
+ },
8007
+ {
8008
+ memberId: "system_6f32f1f2-83ea-42fc-8647-34ed0946b7f1",
8009
+ memberKind: "int",
8010
+ defaultValue: null,
8011
+ docsText: "Added to the object layer's sorting order; it does not replace it. The result competes with every renderer in the sorting layer, or in the enclosing sorting group, and among equal orders the renderer lower on screen draws in front. Leave unset to use the layer's order.",
8012
+ minValue: -32768,
8013
+ maxValue: 32767,
8014
+ schemaKey: "SortingOrder"
8015
+ }
8016
+ ],
8017
+ worldKind: "spriteObject"
8018
+ },
7998
8019
  {
7999
8020
  classId: "system_9f34deed-2616-43c9-b614-d812da89ee51",
8000
8021
  name: "NeoSmartTile",
@@ -12118,12 +12139,8 @@ function evaluateLiteralContainer(args) {
12118
12139
  const literal3 = {
12119
12140
  value: evaluated.value,
12120
12141
  classId: evaluated.classId,
12121
- ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) },
12122
- ...evaluated.instanceConstructorId === void 0 ? {} : { instanceConstructorId: evaluated.instanceConstructorId },
12123
- ...evaluated.instanceVariantId === void 0 ? {} : { instanceVariantId: evaluated.instanceVariantId },
12124
- ...evaluated.instanceVariantRowValueId === void 0 ? {} : {
12125
- instanceVariantRowValueId: evaluated.instanceVariantRowValueId
12126
- }
12142
+ ...pickInstanceProvenance(evaluated),
12143
+ ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) }
12127
12144
  };
12128
12145
  if (isMemberLookupBase(args.member)) {
12129
12146
  if (evaluated.existingValueRow !== void 0) {
@@ -12456,15 +12473,9 @@ function buildNewValue(projectId, body, timestamp2 = Date.now()) {
12456
12473
  if (body.constructorArgs !== void 0 && body.constructorArgs !== null) {
12457
12474
  props.constructorArgs = deepClonePlainData(body.constructorArgs);
12458
12475
  }
12459
- if (body.instanceConstructorId !== void 0) {
12460
- props.instanceConstructorId = body.instanceConstructorId;
12461
- }
12462
- if (body.instanceVariantId !== void 0) {
12463
- props.instanceVariantId = body.instanceVariantId;
12464
- }
12465
- if (body.instanceVariantRowValueId !== void 0) {
12466
- props.instanceVariantRowValueId = body.instanceVariantRowValueId;
12467
- }
12476
+ const { constructorArgs: _constructorArgs, ...provenance } = pickInstanceProvenance(body);
12477
+ void _constructorArgs;
12478
+ Object.assign(props, provenance);
12468
12479
  return props;
12469
12480
  }
12470
12481
  function retargetInitializerRootValueIds(rows, fromValueId, toValueId) {
@@ -12545,11 +12556,7 @@ function completeDefaultClassRecord(args) {
12545
12556
  if (!shouldMaterializeChildDefaultForRoot(
12546
12557
  args.constructorRoot,
12547
12558
  resolvedChildMember,
12548
- defaultSettlesConstruction2,
12549
- documentHasInitValueContent(
12550
- args.document,
12551
- resolvedChildMember.defaultValue
12552
- )
12559
+ defaultSettlesConstruction2
12553
12560
  )) {
12554
12561
  continue;
12555
12562
  }
@@ -12660,7 +12667,7 @@ function cloneDefaultDictionaryRecord(args) {
12660
12667
  args.document,
12661
12668
  args.member.entryMemberId
12662
12669
  );
12663
- const value = {};
12670
+ const value = /* @__PURE__ */ Object.create(null);
12664
12671
  for (const [key, sourceValueId] of Object.entries(sourceValue)) {
12665
12672
  value[key] = cloneDefaultValueForMember({
12666
12673
  document: args.document,
@@ -12937,9 +12944,7 @@ function cloneMemberValueBase(body) {
12937
12944
  return {
12938
12945
  value: deepClonePlainData(body.value),
12939
12946
  classId: body.classId,
12940
- ...body.instanceConstructorId === void 0 ? {} : { instanceConstructorId: body.instanceConstructorId },
12941
- ...body.instanceVariantId === void 0 ? {} : { instanceVariantId: body.instanceVariantId },
12942
- ...body.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: body.instanceVariantRowValueId },
12947
+ ...pickInstanceProvenance({ ...body, constructorArgs: void 0 }),
12943
12948
  ...body.constructorArgs === void 0 || body.constructorArgs === null ? {} : {
12944
12949
  constructorArgs: deepClonePlainData(body.constructorArgs)
12945
12950
  }
@@ -12977,11 +12982,6 @@ function shouldMaterializeChildDefault(member) {
12977
12982
  }
12978
12983
  return member.defaultValue !== void 0;
12979
12984
  }
12980
- function shouldMaterializeConstructorChildDefault(member, isInitializer = isInitValueContent(member.defaultValue)) {
12981
- if (isInitializer) return true;
12982
- if (!isRequiredMember(member)) return false;
12983
- return shouldMaterializeChildDefault(member);
12984
- }
12985
12985
  function skipProvidedConstructorSchemaKey(constructorRoot, schemaKey, member, defaultSettlesConstruction2, isInitializer = isInitValueContent(member.defaultValue)) {
12986
12986
  if (constructorRoot === void 0) return false;
12987
12987
  if (!constructorRoot.providedSchemaKeys.has(schemaKey)) return false;
@@ -12990,16 +12990,11 @@ function skipProvidedConstructorSchemaKey(constructorRoot, schemaKey, member, de
12990
12990
  }
12991
12991
  return !isInitializer && !defaultSettlesConstruction2;
12992
12992
  }
12993
- function shouldMaterializeChildDefaultForRoot(constructorRoot, member, defaultSettlesConstruction2, isInitializer = isInitValueContent(member.defaultValue)) {
12994
- if (constructorRoot === void 0)
12995
- return shouldMaterializeChildDefault(member);
12996
- if (constructorRoot.omitMissingRequired === true && !defaultSettlesConstruction2) {
12993
+ function shouldMaterializeChildDefaultForRoot(constructorRoot, member, defaultSettlesConstruction2) {
12994
+ if (constructorRoot?.omitMissingRequired === true && !defaultSettlesConstruction2) {
12997
12995
  return false;
12998
12996
  }
12999
- if (constructorRoot.runsMemberInitializers === true) {
13000
- return shouldMaterializeChildDefault(member);
13001
- }
13002
- return shouldMaterializeConstructorChildDefault(member, isInitializer);
12997
+ return shouldMaterializeChildDefault(member);
13003
12998
  }
13004
12999
  function primitiveFallbackValue(document, member) {
13005
13000
  if (isMemberBoolBase(member)) return { value: false };
@@ -13259,6 +13254,7 @@ var init_build_default_member_value = __esm({
13259
13254
  "../packages/models/src/members/build-default-member-value.ts"() {
13260
13255
  "use strict";
13261
13256
  init_member_value_id();
13257
+ init_instance_provenance();
13262
13258
  init_member_change_listeners();
13263
13259
  init_construction_requirements();
13264
13260
  init_deep_clone_plain_data();
@@ -23052,10 +23048,6 @@ function validateInternalRecordRelations(args) {
23052
23048
  const classesById = new Map(
23053
23049
  args.classes.map((schemaClass2) => [schemaClass2.id, schemaClass2])
23054
23050
  );
23055
- const worldKindsByClassId = indexWorldSystemClassKinds(
23056
- args.classes,
23057
- classesById
23058
- );
23059
23051
  const relationIds = /* @__PURE__ */ new Set();
23060
23052
  const edgeKeys = /* @__PURE__ */ new Set();
23061
23053
  const orderedKeys2 = /* @__PURE__ */ new Set();
@@ -23119,16 +23111,14 @@ function validateInternalRecordRelations(args) {
23119
23111
  contract,
23120
23112
  endpoint: "source",
23121
23113
  recordEndpoint: source,
23122
- classesById,
23123
- worldKindsByClassId
23114
+ classesById
23124
23115
  });
23125
23116
  validateWorldEndpoint({
23126
23117
  relation,
23127
23118
  contract,
23128
23119
  endpoint: "target",
23129
23120
  recordEndpoint: target,
23130
- classesById,
23131
- worldKindsByClassId
23121
+ classesById
23132
23122
  });
23133
23123
  const edgeKey = [
23134
23124
  relation.relationKind,
@@ -23439,8 +23429,7 @@ function validateWorldEndpoint(args) {
23439
23429
  `Internal record relation "${args.relation.id}" ${args.endpoint} ${classLabel} "${classId}" does not exist.`
23440
23430
  );
23441
23431
  }
23442
- const actualWorldKind = args.worldKindsByClassId.get(schemaClass2.id) ?? null;
23443
- if (actualWorldKind !== requiredWorldKind) {
23432
+ if (!classInheritsWorldKind(schemaClass2.id, requiredWorldKind, args.classesById)) {
23444
23433
  throw new Error(
23445
23434
  `Internal record relation "${args.relation.id}" ${args.endpoint} ${classLabel} "${schemaClass2.id}" must extend world class kind "${requiredWorldKind}".`
23446
23435
  );
@@ -24256,7 +24245,7 @@ function toCanonical(value) {
24256
24245
  if (Array.isArray(value)) return value.map((item) => toCanonical(item));
24257
24246
  if (typeof value === "object") {
24258
24247
  const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
24259
- const result = {};
24248
+ const result = /* @__PURE__ */ Object.create(null);
24260
24249
  for (const [key, entryValue] of entries) {
24261
24250
  result[key] = toCanonical(entryValue);
24262
24251
  }
@@ -35713,7 +35702,7 @@ var init_strict_resolver = __esm({
35713
35702
  };
35714
35703
  }
35715
35704
  resolveDictionaryKey(expectedKey, keyAst, scope, pos, requireNonOptional, dictionaryLiteral = false) {
35716
- const key = this.resolveExpression(keyAst, scope);
35705
+ const key = this.resolveExpression(keyAst, scope, expectedKey);
35717
35706
  if (requireNonOptional && isNullable(key.type)) {
35718
35707
  throw new CompileError(
35719
35708
  `Dictionary keys must be non-optional; got ${this.describe(key.type)}`,
@@ -54544,7 +54533,7 @@ var init_registry = __esm({
54544
54533
  "../packages/manifest/schema-contract/registry.mjs"() {
54545
54534
  "use strict";
54546
54535
  PROJECT_SCHEMA_CONTRACT = Object.freeze({
54547
- cliVersion: "0.80.0",
54536
+ cliVersion: "0.81.1",
54548
54537
  projectFileUploadBatchSize: 32,
54549
54538
  documentRecords: {
54550
54539
  member: {
@@ -65766,7 +65755,7 @@ function toCanonicalJsonValue(value) {
65766
65755
  });
65767
65756
  }
65768
65757
  const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
65769
- const canonicalObject = {};
65758
+ const canonicalObject = /* @__PURE__ */ Object.create(null);
65770
65759
  for (const [key, entryValue] of entries) {
65771
65760
  const canonicalValue = toCanonicalJsonValue(entryValue);
65772
65761
  if (canonicalValue === void 0) continue;
@@ -75128,7 +75117,11 @@ function buildIndex(source) {
75128
75117
  }
75129
75118
  const placement = {
75130
75119
  valueId,
75131
- isNeoObject: kinds.get(row.classId) === NeoWorldSystemClassKind.Object,
75120
+ isNeoObject: classInheritsWorldKind(
75121
+ row.classId,
75122
+ NeoWorldSystemClassKind.Object,
75123
+ relations.classesById
75124
+ ),
75132
75125
  classId: row.classId,
75133
75126
  gridId: root.id,
75134
75127
  layerId,
@@ -75964,6 +75957,7 @@ function makeUnindexedEvaluatorLookups(members, storedValues) {
75964
75957
  hasStoredValueId: (id2) => valueById.has(id2),
75965
75958
  unorderedListEntryIds: (containerValueId) => unorderedListMembership.get(containerValueId) ?? [],
75966
75959
  virtualInstanceRowsForValue: () => [],
75960
+ virtualInstanceRootIdForValue: () => null,
75967
75961
  rowForValueReference: (value) => valueRefMap.get(value) ?? null
75968
75962
  };
75969
75963
  }
@@ -76016,6 +76010,7 @@ function createInitializerBatchLookups(document) {
76016
76010
  },
76017
76011
  rowForValueReference: (value) => build.result.rowByValueReference.get(value) ?? null,
76018
76012
  virtualInstanceRowsForValue: () => [],
76013
+ virtualInstanceRootIdForValue: () => null,
76019
76014
  evaluatorIndexes: { ...build.result },
76020
76015
  constructorInitializerIndexes: constructorInitializerIndexes2
76021
76016
  });
@@ -76217,6 +76212,7 @@ function createEvaluatorLookupsBuild(members, storedValues, options = {}) {
76217
76212
  hasStoredValueId: (id2) => valueById.has(id2),
76218
76213
  unorderedListEntryIds: (containerValueId) => unorderedListMembership.get(containerValueId) ?? [],
76219
76214
  virtualInstanceRowsForValue: () => [],
76215
+ virtualInstanceRootIdForValue: () => null,
76220
76216
  rowForValueReference: (value) => rowByValueReference.get(value) ?? null,
76221
76217
  evaluatorIndexes: indexes3.result,
76222
76218
  ...options.constructorInitializerDocument === void 0 ? {} : {
@@ -76334,6 +76330,7 @@ function layerEvaluatorLookups(base, overlay) {
76334
76330
  hasStoredValueId: (id2) => overlay.rows.has(id2) || !overlay.hiddenIds.has(id2) && (base.hasStoredValueId?.(id2) ?? false),
76335
76331
  unorderedListEntryIds: unorderedListEntryIds2,
76336
76332
  virtualInstanceRowsForValue: () => [],
76333
+ virtualInstanceRootIdForValue: () => null,
76337
76334
  rowForValueReference: (value) => evaluatorIndexes2.rowByValueReference.get(value) ?? null,
76338
76335
  evaluatorIndexes: evaluatorIndexes2,
76339
76336
  constructorInitializerIndexes: constructorInitializerIndexes2
@@ -76739,13 +76736,15 @@ function bindThisValue(ctx, thisValue) {
76739
76736
  function observeValueWrite(ctx, row) {
76740
76737
  ctx.beforeValueWrite?.(row);
76741
76738
  ctx.__getterSubscriptions?.noteValueWrite(row.id);
76739
+ forgetVariantResolutionCopy(ctx, row.id);
76742
76740
  }
76743
76741
  function assertStoredReplayMutableValue(value, ctx, label, key) {
76744
- const observesWrites = ctx.beforeValueWrite !== void 0 || ctx.__getterSubscriptions?.empty === false;
76742
+ const observesWrites = ctx.beforeValueWrite !== void 0 || ctx.__getterSubscriptions?.empty === false || hasVariantResolutionCopies(ctx);
76745
76743
  if (ctx.storedConstructionReplay !== true && !ctx.assertValueWritable && !observesWrites)
76746
76744
  return;
76747
76745
  let rowId = findKnownRowIdByValueReference(value, ctx);
76748
76746
  if (rowId === null) return;
76747
+ forgetVariantResolutionCopy(ctx, rowId);
76749
76748
  const container = ctx.beforeValueWrite && evalValueById(ctx, rowId, ctx.__runtimeSessionValues, ctx.__valueOverlay);
76750
76749
  if (container) ctx.beforeValueWrite?.(container);
76751
76750
  if (key !== void 0 && value !== null && typeof value === "object") {
@@ -85509,12 +85508,7 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
85509
85508
  deleteRuntimeSessionValue(ctx, rootRow.id);
85510
85509
  ctx.__executionState?.constructorGroups.delete(rootRow.id);
85511
85510
  const constructorArgs2 = typeof result.value === "object" && result.value !== null ? ctx.__constructedArgumentsByValue.get(result.value) ?? rootRow.constructorArgs ?? void 0 : void 0;
85512
- const provenance = pickInstanceProvenance({
85513
- constructorArgs: constructorArgs2,
85514
- instanceConstructorId: rootRow.instanceConstructorId,
85515
- instanceVariantId: rootRow.instanceVariantId,
85516
- instanceVariantRowValueId: rootRow.instanceVariantRowValueId
85517
- });
85511
+ const provenance = pickInstanceProvenance({ ...rootRow, constructorArgs: constructorArgs2 });
85518
85512
  return {
85519
85513
  value: result.value,
85520
85514
  classId: rootRow.classId ?? null,
@@ -86379,7 +86373,7 @@ function evalVariantInitialize(info, scope, ctx) {
86379
86373
  scope,
86380
86374
  ctx
86381
86375
  );
86382
- stampInstanceVariantProvenance(instance, selection2, ctx, true);
86376
+ stampInstanceVariantProvenance(instance, selection2, ctx);
86383
86377
  return instance;
86384
86378
  }
86385
86379
  const graph = resolveVariantGraph(selection2, ctx);
@@ -86410,12 +86404,16 @@ function evalVariantInitialize(info, scope, ctx) {
86410
86404
  ctx,
86411
86405
  ctx.__variantDeclarativeAnsweredValueIds
86412
86406
  );
86413
- stampInstanceVariantProvenance(instance, selection2, ctx, true);
86407
+ stampInstanceVariantProvenance(instance, selection2, ctx);
86414
86408
  return instance;
86415
86409
  } finally {
86416
86410
  closeFrame();
86417
86411
  }
86418
86412
  }
86413
+ function isInsideAnotherExpansion(valueId, ctx) {
86414
+ const ownerRootId = ctx.vm.databaseVM?.virtualInstanceRootIdForValue(valueId) ?? null;
86415
+ return ownerRootId !== null && ownerRootId !== valueId;
86416
+ }
86419
86417
  function evalVariantApply(info, scope, ctx) {
86420
86418
  const receiver = evalPointer(info.receiverPointer, scope, ctx);
86421
86419
  if (receiver === null || receiver === void 0) {
@@ -86427,12 +86425,12 @@ function evalVariantApply(info, scope, ctx) {
86427
86425
  evalPointer(info.variantPointer, scope, ctx),
86428
86426
  "ToVariant argument"
86429
86427
  );
86430
- if (selection2.variantId === null) {
86431
- stampInstanceVariantProvenance(receiver, selection2, ctx);
86428
+ const graph = selection2.variantId === null ? null : resolveVariantGraph(selection2, ctx);
86429
+ if (info.declarativeReplay === true) {
86430
+ if (graph !== null) applyVariantDeclarativeHalves(receiver, graph, ctx);
86432
86431
  return receiver;
86433
86432
  }
86434
- const graph = resolveVariantGraph(selection2, ctx);
86435
- const rowParameters = resolveVariantRowParameter({
86433
+ const rowParameters = graph === null ? [] : resolveVariantRowParameter({
86436
86434
  graph,
86437
86435
  selection: selection2,
86438
86436
  explicitPointer: info.rowPointer,
@@ -86441,13 +86439,18 @@ function evalVariantApply(info, scope, ctx) {
86441
86439
  });
86442
86440
  const rootRow = trackedRowForValueReference(receiver, ctx);
86443
86441
  if (rootRow === null || !isLiteralValueContent(rootRow)) {
86442
+ if (graph === null) return receiver;
86444
86443
  throw new NSGetterRuntimeError(
86445
86444
  "ToVariant receiver has no addressable instance root."
86446
86445
  );
86447
86446
  }
86448
- const priorInstanceRoot = ctx.__runtimeSessionValues?.has(rootRow.id) === true ? null : deepClonePlainData(rootRow);
86449
- const applyValue = graph.root.Apply;
86450
- if (applyValue !== void 0 && applyValue !== null) {
86447
+ if (graph === null && typeof rootRow.instanceAppliedVariantId !== "string") {
86448
+ return receiver;
86449
+ }
86450
+ const inPlace = ctx.__runtimeSessionValues?.has(rootRow.id) === true || isInsideAnotherExpansion(rootRow.id, ctx);
86451
+ const priorInstanceRoot = inPlace ? null : deepClonePlainData(rootRow);
86452
+ const applyValue = graph?.root.Apply;
86453
+ if (graph !== null && applyValue !== void 0 && applyValue !== null) {
86451
86454
  invokeVariantClosure({
86452
86455
  closureValueId: applyValue,
86453
86456
  ctx,
@@ -86457,17 +86460,12 @@ function evalVariantApply(info, scope, ctx) {
86457
86460
  });
86458
86461
  }
86459
86462
  if (priorInstanceRoot === null) {
86460
- stampInstanceVariantProvenance(receiver, selection2, ctx);
86461
- applyVariantDeclarativeHalves(receiver, graph, ctx);
86463
+ if (graph !== null) applyVariantDeclarativeHalves(receiver, graph, ctx);
86462
86464
  return receiver;
86463
86465
  }
86464
86466
  priorInstanceRoot.value = deepClonePlainData(rootRow.value);
86465
- const answeredSlots = collectVariantDeclarativeAnsweredSlots(
86466
- receiver,
86467
- graph,
86468
- ctx
86469
- );
86470
- stampInstanceVariantProvenance(receiver, selection2, ctx);
86467
+ const answeredSlots = graph === null ? [] : collectVariantDeclarativeAnsweredSlots(receiver, graph, ctx);
86468
+ stampAppliedVariantProvenance(rootRow, receiver, selection2, ctx);
86471
86469
  const resolver = ctx.vm.databaseVM?.resolveVariantInstanceGraph;
86472
86470
  if (resolver === void 0) {
86473
86471
  if (answeredSlots.length > 0) {
@@ -86476,26 +86474,41 @@ function evalVariantApply(info, scope, ctx) {
86476
86474
  );
86477
86475
  }
86478
86476
  } else {
86477
+ const overlay = ctx.__valueOverlay;
86478
+ const copies = overlay === void 0 ? void 0 : variantResolutionCopies(overlay);
86479
86479
  const resolution = resolver.call(ctx.vm.databaseVM, {
86480
86480
  priorInstanceRoot,
86481
86481
  nextInstanceRoot: deepClonePlainData(rootRow),
86482
86482
  answeredValueIds: [...new Set(answeredSlots.map((slot) => slot.valueId))],
86483
86483
  localRows: [
86484
86484
  ...ctx.__runtimeSessionValues?.values() ?? [],
86485
- ...ctx.__valueOverlay?.values() ?? []
86486
- ]
86485
+ ...overlay?.values() ?? []
86486
+ ],
86487
+ virtualCopyIds: unwrittenVariantResolutionCopyIds(
86488
+ overlay,
86489
+ copies?.byRootId.get(rootRow.id)
86490
+ )
86487
86491
  });
86488
86492
  for (const valueId of resolution.clearedValueIds) {
86489
86493
  const previous = readNeoScriptRuntimeRow(ctx, valueId);
86490
86494
  if (previous) observeValueWrite(ctx, previous);
86491
86495
  deleteRuntimeSessionValue(ctx, valueId);
86492
- ctx.__valueOverlay?.delete(valueId);
86496
+ overlay?.delete(valueId);
86493
86497
  }
86498
+ for (const valueId of copies?.byRootId.get(rootRow.id)?.keys() ?? []) {
86499
+ forgetVariantResolutionCopy(ctx, valueId);
86500
+ }
86501
+ const virtualValueIds = new Set(resolution.virtualValueIds);
86494
86502
  for (const row of resolution.rows) {
86495
86503
  if (row.id === rootRow.id) continue;
86496
86504
  const previous = readNeoScriptRuntimeRow(ctx, row.id);
86497
86505
  if (previous) observeValueWrite(ctx, previous);
86498
- ctx.__valueOverlay?.set(row.id, deepClonePlainData(row));
86506
+ if (overlay === void 0 || copies === void 0) continue;
86507
+ const copy = deepClonePlainData(row);
86508
+ overlay.set(row.id, copy);
86509
+ if (virtualValueIds.has(row.id)) {
86510
+ trackVariantResolutionCopy(copies, rootRow.id, copy);
86511
+ }
86499
86512
  }
86500
86513
  if (typeof receiver !== "object" || receiver === null || Array.isArray(receiver) || typeof resolution.root.value !== "object" || resolution.root.value === null || Array.isArray(resolution.root.value)) {
86501
86514
  throw new NSGetterRuntimeError(
@@ -86509,14 +86522,69 @@ function evalVariantApply(info, scope, ctx) {
86509
86522
  }
86510
86523
  return receiver;
86511
86524
  }
86512
- function stampInstanceVariantProvenance(instance, selection2, ctx, preserveLookupRow = false) {
86525
+ function variantResolutionCopies(overlay) {
86526
+ let copies = variantResolutionCopiesByOverlay.get(overlay);
86527
+ if (copies === void 0) {
86528
+ copies = { byRootId: /* @__PURE__ */ new Map(), rootIdByValueId: /* @__PURE__ */ new Map() };
86529
+ variantResolutionCopiesByOverlay.set(overlay, copies);
86530
+ }
86531
+ return copies;
86532
+ }
86533
+ function hasVariantResolutionCopies(ctx) {
86534
+ const overlay = ctx.__valueOverlay;
86535
+ if (overlay === void 0) return false;
86536
+ const copies = variantResolutionCopiesByOverlay.get(overlay);
86537
+ return copies !== void 0 && copies.rootIdByValueId.size > 0;
86538
+ }
86539
+ function trackVariantResolutionCopy(copies, rootId, copy) {
86540
+ let rootCopies = copies.byRootId.get(rootId);
86541
+ if (rootCopies === void 0) {
86542
+ rootCopies = /* @__PURE__ */ new Map();
86543
+ copies.byRootId.set(rootId, rootCopies);
86544
+ }
86545
+ rootCopies.set(copy.id, copy);
86546
+ copies.rootIdByValueId.set(copy.id, rootId);
86547
+ }
86548
+ function unwrittenVariantResolutionCopyIds(overlay, rootCopies) {
86549
+ if (overlay === void 0 || rootCopies === void 0) return [];
86550
+ const ids = [];
86551
+ for (const [id2, copy] of rootCopies) {
86552
+ if (overlay.get(id2) === copy) ids.push(id2);
86553
+ }
86554
+ return ids;
86555
+ }
86556
+ function forgetVariantResolutionCopy(ctx, valueId) {
86557
+ const overlay = ctx.__valueOverlay;
86558
+ if (overlay === void 0) return;
86559
+ const copies = variantResolutionCopiesByOverlay.get(overlay);
86560
+ const rootId = copies?.rootIdByValueId.get(valueId);
86561
+ if (copies === void 0 || rootId === void 0) return;
86562
+ copies.rootIdByValueId.delete(valueId);
86563
+ copies.byRootId.get(rootId)?.delete(valueId);
86564
+ }
86565
+ function stampInstanceVariantProvenance(instance, selection2, ctx) {
86513
86566
  const row = trackedRowForValueReference(instance, ctx);
86514
86567
  if (row === null || !isLiteralValueContent(row)) return;
86515
- if (preserveLookupRow && row.id === selection2.rowValueId) return;
86568
+ if (row.id === selection2.rowValueId) return;
86516
86569
  assertStoredReplayMutableValue(instance, ctx, "variant provenance");
86517
86570
  row.instanceVariantId = selection2.variantId;
86518
86571
  row.instanceVariantRowValueId = selection2.rowValueId;
86519
86572
  }
86573
+ function stampAppliedVariantProvenance(rootRow, instance, selection2, ctx) {
86574
+ const applied = typeof rootRow.instanceAppliedVariantId === "string";
86575
+ const variantId = applied ? rootRow.instanceAppliedVariantId : rootRow.instanceVariantId ?? null;
86576
+ const rowValueId = applied ? rootRow.instanceAppliedVariantRowValueId : rootRow.instanceVariantRowValueId;
86577
+ if (variantId === selection2.variantId && (rowValueId ?? null) === selection2.rowValueId) {
86578
+ return;
86579
+ }
86580
+ assertStoredReplayMutableValue(instance, ctx, "variant provenance");
86581
+ if (!isVirtualInstanceRootShape(rootRow)) {
86582
+ rootRow.instanceConstructorId = null;
86583
+ rootRow.constructorArgs = {};
86584
+ }
86585
+ rootRow.instanceAppliedVariantId = selection2.variantId;
86586
+ rootRow.instanceAppliedVariantRowValueId = selection2.rowValueId;
86587
+ }
86520
86588
  function constructDeclaredClassValue(info, scope, ctx) {
86521
86589
  const descriptor = validateClassConstructorDescriptor(info, ctx, false);
86522
86590
  const schemaClass2 = descriptor.schemaClass;
@@ -86599,6 +86667,7 @@ function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope
86599
86667
  );
86600
86668
  }
86601
86669
  const rootRecord = root.value;
86670
+ recordConstructedFieldSchemaKeys(ctx, rootRecord, descriptor);
86602
86671
  if (record7 !== null) {
86603
86672
  const encoded = {};
86604
86673
  for (let index = 0; index < argumentValues.length; index += 1) {
@@ -86639,7 +86708,6 @@ function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope
86639
86708
  }
86640
86709
  const argumentsByValue = ctx.__constructedArgumentsByValue ?? (ctx.__constructedArgumentsByValue = /* @__PURE__ */ new WeakMap());
86641
86710
  argumentsByValue.set(rootRecord, encoded);
86642
- recordConstructedFieldSchemaKeys(ctx, rootRecord, descriptor);
86643
86711
  root.constructorArgs = deepClonePlainData(encoded);
86644
86712
  root.instanceConstructorId = record7.id;
86645
86713
  } else {
@@ -87032,7 +87100,7 @@ function cloneConstructorArgumentGraph(args) {
87032
87100
  member.classArguments,
87033
87101
  args.ctx.vm.classes
87034
87102
  );
87035
- const record7 = {};
87103
+ const record7 = /* @__PURE__ */ Object.create(null);
87036
87104
  clone.value = record7;
87037
87105
  const sourceRecord = {
87038
87106
  ...virtualExpandedRecordForReceiver(source.value, args.ctx),
@@ -87076,7 +87144,7 @@ function cloneConstructorArgumentGraph(args) {
87076
87144
  `Constructor import references missing Dictionary entry member '${member.entryMemberId}'.`
87077
87145
  );
87078
87146
  }
87079
- const record7 = {};
87147
+ const record7 = /* @__PURE__ */ Object.create(null);
87080
87148
  clone.value = record7;
87081
87149
  const entryEnv = envFromStamp(clone.genericBindings);
87082
87150
  for (const [key, childId] of Object.entries(source.value)) {
@@ -87319,7 +87387,7 @@ function materializeConstructorArgumentValue(args) {
87319
87387
  args.ctx.vm.members
87320
87388
  );
87321
87389
  const row = registerConstructorArgumentRow(args, {});
87322
- const record7 = {};
87390
+ const record7 = /* @__PURE__ */ Object.create(null);
87323
87391
  for (const [key, rawEntry] of Object.entries(args.value)) {
87324
87392
  const entry = constructorCollectionEntryValue(
87325
87393
  rawEntry,
@@ -87994,7 +88062,7 @@ function collectionEntryUsesReferenceResolution(collection, key, ctx) {
87994
88062
  );
87995
88063
  return referenceIndexes === void 0 || referenceIndexes.has(key);
87996
88064
  }
87997
- var DELEGATE_LEXICAL_THIS, DELEGATE_LEXICAL_ROOT, DELEGATE_LEXICAL_TYPE_ARGUMENTS, 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, FORWARDING_TYPE_ARGUMENTS, constantDeclarationRoots, NS_MATH_OP_NAMES, DOUBLE_INTEGRAL_MAGNITUDE, EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS;
88065
+ var DELEGATE_LEXICAL_THIS, DELEGATE_LEXICAL_ROOT, DELEGATE_LEXICAL_TYPE_ARGUMENTS, 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, FORWARDING_TYPE_ARGUMENTS, constantDeclarationRoots, NS_MATH_OP_NAMES, DOUBLE_INTEGRAL_MAGNITUDE, EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS, variantResolutionCopiesByOverlay;
87998
88066
  var init_evaluateNSGetter = __esm({
87999
88067
  "../packages/neoscript-runtime/src/neoscript/evaluateNSGetter.ts"() {
88000
88068
  "use strict";
@@ -88204,6 +88272,7 @@ var init_evaluateNSGetter = __esm({
88204
88272
  };
88205
88273
  DOUBLE_INTEGRAL_MAGNITUDE = 2 ** 53;
88206
88274
  EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS = [];
88275
+ variantResolutionCopiesByOverlay = /* @__PURE__ */ new WeakMap();
88207
88276
  }
88208
88277
  });
88209
88278
 
@@ -89896,6 +89965,8 @@ function expandStoredInstance(args) {
89896
89965
  instanceConstructorId: _instanceConstructorId,
89897
89966
  instanceVariantId: _instanceVariantId,
89898
89967
  instanceVariantRowValueId: _instanceVariantRowValueId,
89968
+ instanceAppliedVariantId: _instanceAppliedVariantId,
89969
+ instanceAppliedVariantRowValueId: _instanceAppliedVariantRowValueId,
89899
89970
  ...envelope
89900
89971
  } = instanceRoot;
89901
89972
  void _value;
@@ -89904,6 +89975,8 @@ function expandStoredInstance(args) {
89904
89975
  void _instanceConstructorId;
89905
89976
  void _instanceVariantId;
89906
89977
  void _instanceVariantRowValueId;
89978
+ void _instanceAppliedVariantId;
89979
+ void _instanceAppliedVariantRowValueId;
89907
89980
  const closedRootMember = closeClassArgumentsFromRowStamp(
89908
89981
  rootMember,
89909
89982
  instanceRoot
@@ -89985,11 +90058,26 @@ function expandStoredInstance(args) {
89985
90058
  }
89986
90059
  };
89987
90060
  };
89988
- const materialized = derivesContentFromMemberDefault({
90061
+ const constructed = derivesContentFromMemberDefault({
89989
90062
  member: replayMember,
89990
90063
  instanceRoot,
89991
90064
  effectiveClassId: classId
89992
90065
  }) ? replayDeclaredDefault() : replay([]);
90066
+ const appliedVariantId = instanceRoot.instanceAppliedVariantId;
90067
+ const materialized = typeof appliedVariantId !== "string" ? constructed : trackMaterialization(
90068
+ () => replayAppliedVariant({
90069
+ evaluateInitializer: args.evaluateInitializer,
90070
+ document: args.document,
90071
+ member: replayMember,
90072
+ constructed,
90073
+ classId,
90074
+ variantId: appliedVariantId,
90075
+ variantRowValueId: instanceRoot.instanceAppliedVariantRowValueId ?? null,
90076
+ ...readTracking === void 0 ? {} : { readTracking },
90077
+ saveStaticBindings: args.saveStaticBindings,
90078
+ sessionStaticBindings: args.sessionStaticBindings
90079
+ })
90080
+ );
89993
90081
  const rows = [materialized.root, ...materialized.createdValues];
89994
90082
  assertVirtualExpansionIsLiteral(rows);
89995
90083
  return {
@@ -89998,6 +90086,80 @@ function expandStoredInstance(args) {
89998
90086
  pinnedRootSchemaKeys: /* @__PURE__ */ new Set()
89999
90087
  };
90000
90088
  }
90089
+ function replayAppliedVariant(args) {
90090
+ const rootId = args.constructed.root.id;
90091
+ const sessionValues = /* @__PURE__ */ new Map();
90092
+ sessionValues.set(rootId, args.constructed.root);
90093
+ for (const row of args.constructed.createdValues)
90094
+ sessionValues.set(row.id, row);
90095
+ const variant2 = args.document.databaseVM?.variantById?.(args.variantId) ?? args.document.variants?.find((entry) => entry.id === args.variantId);
90096
+ const variantClassId = variant2?.classId ?? args.classId;
90097
+ const schemaClassInfo = {
90098
+ type: 7 /* Class */,
90099
+ required: true,
90100
+ classId: args.classId
90101
+ };
90102
+ args.evaluateInitializer({
90103
+ init: {
90104
+ code: `virtual-applied-variant:${rootId}`,
90105
+ compiled: {
90106
+ compilerRevision: NEOSCRIPT_COMPILER_REVISION,
90107
+ parameters: evaluatorEnvelopeParameters(),
90108
+ instructions: [
90109
+ {
90110
+ type: "return" /* return */,
90111
+ pointer: {
90112
+ type: "function" /* function */,
90113
+ function: {
90114
+ type: "variantApply" /* variantApply */,
90115
+ info: {
90116
+ receiverPointer: {
90117
+ type: "reference" /* reference */,
90118
+ valueId: rootId
90119
+ },
90120
+ variantPointer: {
90121
+ type: "variant" /* variant */,
90122
+ classId: variantClassId,
90123
+ variantId: args.variantId,
90124
+ rowValueId: args.variantRowValueId
90125
+ },
90126
+ schemaClassInfo,
90127
+ declarativeReplay: true
90128
+ }
90129
+ }
90130
+ }
90131
+ }
90132
+ ],
90133
+ typeInfo: schemaClassInfo
90134
+ }
90135
+ },
90136
+ member: args.member,
90137
+ document: args.document,
90138
+ createdValues: [],
90139
+ sessionValues,
90140
+ storedConstructionReplay: true,
90141
+ sourceValueId: rootId,
90142
+ ...args.readTracking === void 0 ? {} : { readTracking: args.readTracking },
90143
+ saveStaticBindings: args.saveStaticBindings,
90144
+ sessionStaticBindings: args.sessionStaticBindings
90145
+ });
90146
+ const root = sessionValues.get(rootId);
90147
+ if (root === void 0) {
90148
+ throw new Error(
90149
+ `Applied variant "${args.variantId}" replay lost instance root "${rootId}".`
90150
+ );
90151
+ }
90152
+ sessionValues.delete(rootId);
90153
+ return {
90154
+ ...args.constructed,
90155
+ root: {
90156
+ ...root,
90157
+ instanceAppliedVariantId: args.variantId,
90158
+ instanceAppliedVariantRowValueId: args.variantRowValueId
90159
+ },
90160
+ createdValues: [...sessionValues.values()]
90161
+ };
90162
+ }
90001
90163
  function resolveVirtualInstanceGraph(args) {
90002
90164
  const expansion = args.expansionIndex ?? indexExpansion(args);
90003
90165
  const recorder = args.readRecorder ?? null;
@@ -90971,6 +91133,11 @@ function expandStoredClassValue(args) {
90971
91133
  pinnedRootSchemaKeys: /* @__PURE__ */ new Set()
90972
91134
  };
90973
91135
  }
91136
+ function owningInstanceRootId(graph) {
91137
+ let owner = graph;
91138
+ while (owner?.containingGraph !== void 0) owner = owner.containingGraph;
91139
+ return owner?.instanceRootId ?? null;
91140
+ }
90974
91141
  function isStoredClassResolutionRoot(value) {
90975
91142
  if (!isLiteralValueContent(value)) return false;
90976
91143
  if (isVirtualInstanceRootShape(value)) return true;
@@ -91284,6 +91451,7 @@ function planCollapseVirtualInstance(args) {
91284
91451
  if (provenance.sameRecipe) return true;
91285
91452
  if (typeof stored.instanceConstructorId === "string") return false;
91286
91453
  if (typeof stored.instanceVariantId === "string") return false;
91454
+ if (typeof stored.instanceAppliedVariantId === "string") return false;
91287
91455
  const storedArgs = stored.constructorArgs;
91288
91456
  if (storedArgs != null && Object.keys(storedArgs).length > 0) return false;
91289
91457
  return !isInitValueContent(child2.member.defaultValue);
@@ -91682,10 +91850,35 @@ function sparsifyConstructedInstance(args) {
91682
91850
  if (typeof entryId === "string")
91683
91851
  protectArgument(entryId, type.entryTypeInfo);
91684
91852
  };
91853
+ const argumentValueIds = /* @__PURE__ */ new Set();
91854
+ const pinnedSubtreeIds = /* @__PURE__ */ new Set();
91855
+ const pinSubtree = (valueId) => {
91856
+ if (pinnedSubtreeIds.has(valueId)) return;
91857
+ pinnedSubtreeIds.add(valueId);
91858
+ protectedValueIds.add(valueId);
91859
+ const row = materializedGraph.valuesById.get(valueId);
91860
+ if (row === void 0) return;
91861
+ for (const childId of materializedGraph.referencedValueIds(row))
91862
+ pinSubtree(childId);
91863
+ };
91864
+ const pinArgumentFields = (valueId) => {
91865
+ if (argumentValueIds.has(valueId)) return;
91866
+ argumentValueIds.add(valueId);
91867
+ const row = materializedGraph.valuesById.get(valueId);
91868
+ if (row === void 0) return;
91869
+ const fields = isObjectRecord2(row.value) ? row.value : {};
91870
+ for (const schemaKey of args.pinnedSchemaKeysByValueId?.get(valueId) ?? []) {
91871
+ const fieldId = fields[schemaKey];
91872
+ if (typeof fieldId === "string") pinSubtree(fieldId);
91873
+ }
91874
+ for (const childId of materializedGraph.referencedValueIds(row))
91875
+ pinArgumentFields(childId);
91876
+ };
91685
91877
  for (const edge of materializedGraph.constructorEdges(
91686
91878
  args.constructed.root
91687
91879
  )) {
91688
91880
  protectArgument(edge.targetValueId, edge.typeInfo);
91881
+ pinArgumentFields(edge.targetValueId);
91689
91882
  }
91690
91883
  for (const schemaKey of args.pinnedRootSchemaKeys ?? []) {
91691
91884
  const location3 = graph.locationsByPath.get(
@@ -92340,7 +92533,9 @@ function compareContextualCreationProvenance(left, right, context) {
92340
92533
  constructorArgs: literal3.constructorArgs ?? {},
92341
92534
  instanceConstructorId: literal3.instanceConstructorId ?? null,
92342
92535
  instanceVariantId: literal3.instanceVariantId ?? null,
92343
- instanceVariantRowValueId: literal3.instanceVariantRowValueId ?? null
92536
+ instanceVariantRowValueId: literal3.instanceVariantRowValueId ?? null,
92537
+ instanceAppliedVariantId: literal3.instanceAppliedVariantId ?? null,
92538
+ instanceAppliedVariantRowValueId: literal3.instanceAppliedVariantRowValueId ?? null
92344
92539
  };
92345
92540
  };
92346
92541
  return {
@@ -92638,40 +92833,37 @@ function resolveVariantInstanceGraphForDocument(args) {
92638
92833
  rootMember,
92639
92834
  readRecorder: args.readRecorder
92640
92835
  });
92641
- const priorGraph = resolveVirtualInstanceGraph({
92836
+ let priorInstanceRoot = args.priorInstanceRoot;
92837
+ let nextInstanceRoot = args.nextInstanceRoot;
92838
+ const resolvePriorGraph = () => resolveVirtualInstanceGraph({
92642
92839
  document,
92643
- instanceRoot: args.priorInstanceRoot,
92840
+ instanceRoot: priorInstanceRoot,
92644
92841
  rootMember,
92645
92842
  expandedRoot: priorExpanded.root,
92646
92843
  expandedRows: priorExpanded.rows,
92647
92844
  materializedRows: [...materializedById.values()],
92648
92845
  readRecorder: args.readRecorder
92649
92846
  });
92650
- const priorAnsweredIds = [];
92651
- const incomingAnsweredIds = [];
92652
- for (const valueId of args.answeredValueIds) {
92653
- const bucket = priorGraph.locationsById.has(valueId) ? priorAnsweredIds : incomingAnsweredIds;
92654
- bucket.push(valueId);
92655
- }
92656
92847
  const clearedValueIds = /* @__PURE__ */ new Set();
92657
- let nextInstanceRoot = args.nextInstanceRoot;
92658
- const resetAnsweredValues = (graph, valueIds) => {
92659
- if (valueIds.length === 0) return;
92660
- const reset = planVirtualOverrideResets({ graph, valueIds });
92848
+ const applyReset = (graph, reset) => {
92661
92849
  for (const valueId of reset.deletes) {
92662
92850
  clearedValueIds.add(valueId);
92663
92851
  materializedById.delete(valueId);
92664
92852
  }
92665
92853
  for (const update of reset.updates) {
92666
92854
  if (update.valueId === nextInstanceRoot.id) {
92667
- const nextRecord = { ...stringRecord2(nextInstanceRoot.value) };
92668
92855
  const resetRecord = stringRecord2(update.value);
92669
92856
  const priorRecord = stringRecord2(graph.root.materializedRow?.value);
92670
- for (const schemaKey of Object.keys(priorRecord)) {
92671
- if (!Object.hasOwn(resetRecord, schemaKey))
92672
- delete nextRecord[schemaKey];
92673
- }
92674
- nextInstanceRoot = { ...nextInstanceRoot, value: nextRecord };
92857
+ const withoutReset = (root2) => {
92858
+ const record7 = { ...stringRecord2(root2.value) };
92859
+ for (const schemaKey of Object.keys(priorRecord)) {
92860
+ if (!Object.hasOwn(resetRecord, schemaKey))
92861
+ delete record7[schemaKey];
92862
+ }
92863
+ return { ...root2, value: record7 };
92864
+ };
92865
+ priorInstanceRoot = withoutReset(literalRow(priorInstanceRoot));
92866
+ nextInstanceRoot = withoutReset(literalRow(nextInstanceRoot));
92675
92867
  }
92676
92868
  const existing = materializedById.get(update.valueId);
92677
92869
  if (existing !== void 0) {
@@ -92683,6 +92875,28 @@ function resolveVariantInstanceGraphForDocument(args) {
92683
92875
  }
92684
92876
  materializedById.set(nextInstanceRoot.id, nextInstanceRoot);
92685
92877
  };
92878
+ let priorGraph = resolvePriorGraph();
92879
+ if (args.virtualCopyIds !== void 0 && args.virtualCopyIds.length > 0) {
92880
+ const collapse = planCollapseVirtualInstance({
92881
+ graph: priorGraph,
92882
+ removableValueIds: new Set(args.virtualCopyIds)
92883
+ });
92884
+ if (collapse.deletes.length > 0 || collapse.updates.length > 0) {
92885
+ applyReset(priorGraph, collapse);
92886
+ materializedById.set(priorInstanceRoot.id, priorInstanceRoot);
92887
+ priorGraph = resolvePriorGraph();
92888
+ }
92889
+ }
92890
+ const priorAnsweredIds = [];
92891
+ const incomingAnsweredIds = [];
92892
+ for (const valueId of args.answeredValueIds) {
92893
+ const bucket = priorGraph.locationsById.has(valueId) ? priorAnsweredIds : incomingAnsweredIds;
92894
+ bucket.push(valueId);
92895
+ }
92896
+ const resetAnsweredValues = (graph, valueIds) => {
92897
+ if (valueIds.length === 0) return;
92898
+ applyReset(graph, planVirtualOverrideResets({ graph, valueIds }));
92899
+ };
92686
92900
  resetAnsweredValues(priorGraph, priorAnsweredIds);
92687
92901
  materializedById.set(nextInstanceRoot.id, nextInstanceRoot);
92688
92902
  const nextExpanded = expandStoredInstance({
@@ -92726,10 +92940,15 @@ function resolveVariantInstanceGraphForDocument(args) {
92726
92940
  `ToVariant failed to resolve instance root '${args.nextInstanceRoot.id}'.`
92727
92941
  );
92728
92942
  }
92943
+ const virtualValueIds = /* @__PURE__ */ new Set();
92944
+ for (const location3 of nextGraph.locationsById.values()) {
92945
+ if (location3.materializedRow === null) virtualValueIds.add(location3.id);
92946
+ }
92729
92947
  return {
92730
92948
  root,
92731
92949
  rows: [...nextGraph.rowsById.values()],
92732
- clearedValueIds: [...clearedValueIds]
92950
+ clearedValueIds: [...clearedValueIds],
92951
+ virtualValueIds: [...virtualValueIds]
92733
92952
  };
92734
92953
  }
92735
92954
  function variantSwapDeclaredMember(document, rootValueId) {
@@ -93056,6 +93275,7 @@ var KEPT_ROW_SAMPLE_LIMIT, VirtualExpansionUnsupportedError, ROOT_PATH, OpenGene
93056
93275
  var init_virtual_instance_graph = __esm({
93057
93276
  "../packages/neoscript-runtime/src/virtual-instance-graph.ts"() {
93058
93277
  "use strict";
93278
+ init_value_comparison();
93059
93279
  init_listener_endpoint_projection();
93060
93280
  init_overlay_readonly_map();
93061
93281
  init_member_change_listeners();
@@ -93158,6 +93378,7 @@ function initializerEvaluatorLookups(document, readTracking) {
93158
93378
  return resolved;
93159
93379
  },
93160
93380
  virtualInstanceRowsForValue: (receiverValueId) => databaseVM.virtualInstanceRowsForValue(receiverValueId),
93381
+ virtualInstanceRootIdForValue: (valueId) => databaseVM.virtualInstanceRootIdForValue(valueId),
93161
93382
  ...databaseVM.worldGridQueryIndex === void 0 ? {} : { worldGridQueryIndex: () => databaseVM.worldGridQueryIndex() },
93162
93383
  rowForValueReference: (value) => databaseVM.rowForValueReference?.(value) ?? null,
93163
93384
  resolveVariantInstanceGraph: (args) => {
@@ -93213,6 +93434,9 @@ function initializerEvaluatorLookups(document, readTracking) {
93213
93434
  valueById: (id2) => indexedLookups.valueById(id2) ?? headlessVirtualResolver.valueById(id2),
93214
93435
  rowForValueReference: (value) => indexedLookups.rowForValueReference?.(value) ?? headlessVirtualResolver.rowForValueReference(value),
93215
93436
  virtualInstanceRowsForValue: (receiverValueId) => headlessVirtualResolver.virtualInstanceRowsForValue(receiverValueId),
93437
+ virtualInstanceRootIdForValue: (valueId) => owningInstanceRootId(
93438
+ headlessVirtualResolver.virtualInstanceGraphForValue(valueId)
93439
+ ),
93216
93440
  recordVirtualInstanceReads: (reads, read) => headlessVirtualResolver.recordReads(reads, read),
93217
93441
  // Headless hosts still evaluate `ToVariant` during
93218
93442
  // stored-construction replay — production's variant-constructed
@@ -93446,6 +93670,7 @@ function createInitializerMaterializationBatch(authoredDocument, pendingInitiali
93446
93670
  if (entry.global) globalReads.add(entry);
93447
93671
  return entry.rows;
93448
93672
  },
93673
+ virtualInstanceRootIdForValue: (id2) => owningInstanceRootId(virtual().virtualInstanceGraphForValue(id2)),
93449
93674
  resolveVariantInstanceGraph: (args) => resolveVariantInstanceGraphForDocument({
93450
93675
  evaluateInitializer: evaluateMemberInitializer,
93451
93676
  document,
@@ -93529,6 +93754,7 @@ function evaluateMemberInitializer(args) {
93529
93754
  );
93530
93755
  const compiled = compileMemberInitializer(args, databaseVM);
93531
93756
  const ctx = {
93757
+ ...args.sessionValues === void 0 ? {} : { __runtimeSessionValues: args.sessionValues },
93532
93758
  debugSink: args.document.debugSink,
93533
93759
  beforeValueAllocation: args.document.beforeValueAllocation,
93534
93760
  listenerDefaultCapture: args.document.listenerDefaultCapture,
@@ -93599,10 +93825,13 @@ function evaluateMemberInitializer(args) {
93599
93825
  args.argumentValues ?? [],
93600
93826
  {
93601
93827
  exportInitializerValues: true,
93602
- initializerResult: {
93603
- member: args.member,
93604
- genericEnv: args.genericEnv
93605
- }
93828
+ // Seeded rows already hold their placement.
93829
+ ...args.sessionValues === void 0 ? {
93830
+ initializerResult: {
93831
+ member: args.member,
93832
+ genericEnv: args.genericEnv
93833
+ }
93834
+ } : {}
93606
93835
  }
93607
93836
  );
93608
93837
  } catch (error) {
@@ -93625,9 +93854,12 @@ function evaluateMemberInitializer(args) {
93625
93854
  );
93626
93855
  }
93627
93856
  const rootRow = initializerRootRow(result.value, created);
93857
+ const pinnedSchemaKeysByValueId = /* @__PURE__ */ new Map();
93628
93858
  for (const row of created) {
93629
93859
  if (row === rootRow) continue;
93630
93860
  args.createdValues.push(row);
93861
+ const keys = typeof row.value === "object" && row.value !== null ? ctx.__constructedFieldSchemaKeysByValue?.get(row.value) : void 0;
93862
+ if (keys !== void 0) pinnedSchemaKeysByValueId.set(row.id, keys);
93631
93863
  }
93632
93864
  if (rootRow === null) return { value: result.value, classId: null };
93633
93865
  const constructorArgs2 = (typeof result.value === "object" && result.value !== null ? ctx.__constructedArgumentsByValue?.get(result.value) : void 0) ?? // An implicit `new()` records its empty args on the row rather than in
@@ -93635,17 +93867,13 @@ function evaluateMemberInitializer(args) {
93635
93867
  // origin or the recipe reads as an unrecorded overload.
93636
93868
  rootRow.constructorArgs ?? void 0;
93637
93869
  const pinnedRootSchemaKeys = typeof result.value === "object" && result.value !== null ? ctx.__constructedFieldSchemaKeysByValue?.get(result.value) : void 0;
93638
- const provenance = pickInstanceProvenance({
93639
- constructorArgs: constructorArgs2,
93640
- instanceConstructorId: rootRow.instanceConstructorId,
93641
- instanceVariantId: rootRow.instanceVariantId,
93642
- instanceVariantRowValueId: rootRow.instanceVariantRowValueId
93643
- });
93870
+ const provenance = pickInstanceProvenance({ ...rootRow, constructorArgs: constructorArgs2 });
93644
93871
  return {
93645
93872
  value: result.value,
93646
93873
  classId: rootRow.classId ?? null,
93647
93874
  ...rootRow.genericBindings === void 0 ? {} : { genericBindings: { ...rootRow.genericBindings } },
93648
93875
  ...pinnedRootSchemaKeys === void 0 ? {} : { pinnedRootSchemaKeys },
93876
+ ...pinnedSchemaKeysByValueId.size === 0 ? {} : { pinnedSchemaKeysByValueId },
93649
93877
  provisionalRootId: rootRow.id,
93650
93878
  ...provenance,
93651
93879
  ...provenance.constructorArgs === void 0 ? {} : {
@@ -93851,12 +94079,7 @@ function materializeInitializerValue(args) {
93851
94079
  value: evaluated.value,
93852
94080
  ...evaluated.classId === null ? {} : { classId: evaluated.classId },
93853
94081
  ...evaluated.genericBindings === void 0 ? {} : { genericBindings: { ...evaluated.genericBindings } },
93854
- ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) },
93855
- ...evaluated.instanceConstructorId === void 0 ? {} : { instanceConstructorId: evaluated.instanceConstructorId },
93856
- ...evaluated.instanceVariantId === void 0 ? {} : { instanceVariantId: evaluated.instanceVariantId },
93857
- ...evaluated.instanceVariantRowValueId === void 0 ? {} : {
93858
- instanceVariantRowValueId: evaluated.instanceVariantRowValueId
93859
- }
94082
+ ...deepClonePlainData(pickInstanceProvenance(evaluated))
93860
94083
  };
93861
94084
  const allCreated = [root, ...createdValues];
93862
94085
  if (evaluated.provisionalRootId !== void 0) {
@@ -93879,7 +94102,8 @@ function materializeInitializerValue(args) {
93879
94102
  return {
93880
94103
  root,
93881
94104
  createdValues,
93882
- pinnedRootSchemaKeys: evaluated.pinnedRootSchemaKeys ?? /* @__PURE__ */ new Set()
94105
+ pinnedRootSchemaKeys: evaluated.pinnedRootSchemaKeys ?? /* @__PURE__ */ new Set(),
94106
+ pinnedSchemaKeysByValueId: evaluated.pinnedSchemaKeysByValueId ?? /* @__PURE__ */ new Map()
93883
94107
  };
93884
94108
  }
93885
94109
  function materializeMemberDefaultValue(args) {
@@ -93996,7 +94220,12 @@ function materializeMemberDefaultValue(args) {
93996
94220
  storageKeyDeclarations,
93997
94221
  supersededRootId: built.id
93998
94222
  });
93999
- return { root, createdValues: interior, pinnedRootSchemaKeys: /* @__PURE__ */ new Set() };
94223
+ return {
94224
+ root,
94225
+ createdValues: interior,
94226
+ pinnedRootSchemaKeys: /* @__PURE__ */ new Set(),
94227
+ pinnedSchemaKeysByValueId: /* @__PURE__ */ new Map()
94228
+ };
94000
94229
  }
94001
94230
  var declarationInitializerContextByDocument, defaultValuePlansByDocument;
94002
94231
  var init_initializer_materialization = __esm({
@@ -94005,6 +94234,7 @@ var init_initializer_materialization = __esm({
94005
94234
  init_deep_clone_plain_data();
94006
94235
  init_members();
94007
94236
  init_inheritance();
94237
+ init_instance_provenance();
94008
94238
  init_generics();
94009
94239
  init_evaluateInitializer();
94010
94240
  init_evaluateNSGetter();
@@ -110398,7 +110628,7 @@ function toCanonicalJsonValue2(value) {
110398
110628
  if (!isPlainRecord2(value)) {
110399
110629
  throw new Error("Cannot canonicalize a non-plain object.");
110400
110630
  }
110401
- const canonical = {};
110631
+ const canonical = /* @__PURE__ */ Object.create(null);
110402
110632
  const entries = Object.entries(value).sort(
110403
110633
  ([left], [right]) => left.localeCompare(right)
110404
110634
  );
@@ -113781,6 +114011,7 @@ function headlessVirtualInstanceLookups(document, options = {}) {
113781
114011
  valueById: (id2) => indexed.valueById(id2) ?? virtual.valueById(id2),
113782
114012
  rowForValueReference: (value) => indexed.rowForValueReference(value) ?? virtual.rowForValueReference(value),
113783
114013
  virtualInstanceRowsForValue: (receiverValueId) => virtual.virtualInstanceRowsForValue(receiverValueId),
114014
+ virtualInstanceRootIdForValue: (valueId) => owningInstanceRootId(virtual.virtualInstanceGraphForValue(valueId)),
113784
114015
  // Stored-construction replay evaluates `ToVariant`, and production's
113785
114016
  // variant-constructed placements collapse through exactly this path.
113786
114017
  resolveVariantInstanceGraph: (args) => resolveVariantInstanceGraphForDocument2({
@@ -114689,6 +114920,7 @@ function validateWorldPlacementSidecars(args) {
114689
114920
  validatePlacementVariantBinding({
114690
114921
  assetClassId,
114691
114922
  placementId: args.placement.id,
114923
+ layer: "built",
114692
114924
  variantId: optionalNonEmptyString(
114693
114925
  args.isTile || !hasObjectSidecar ? getField(args.placement, "instanceVariantId") : record7.variantId
114694
114926
  ),
@@ -114697,12 +114929,25 @@ function validateWorldPlacementSidecars(args) {
114697
114929
  ),
114698
114930
  context: args.context
114699
114931
  });
114932
+ validatePlacementVariantBinding({
114933
+ assetClassId,
114934
+ placementId: args.placement.id,
114935
+ layer: "applied",
114936
+ variantId: optionalNonEmptyString(
114937
+ getField(args.placement, "instanceAppliedVariantId")
114938
+ ),
114939
+ rowValueId: optionalNonEmptyString(
114940
+ getField(args.placement, "instanceAppliedVariantRowValueId")
114941
+ ),
114942
+ context: args.context
114943
+ });
114700
114944
  }
114701
114945
  function validatePlacementVariantBinding(args) {
114946
+ const noun = args.layer === "built" ? "variant" : "applied variant";
114702
114947
  if (args.variantId === null) {
114703
114948
  if (args.rowValueId !== null) {
114704
114949
  throw new Error(
114705
- `Placement value "${args.placementId}" binds row "${args.rowValueId}" without a variant.`
114950
+ `Placement value "${args.placementId}" binds row "${args.rowValueId}" without a ${noun}.`
114706
114951
  );
114707
114952
  }
114708
114953
  return;
@@ -114710,19 +114955,24 @@ function validatePlacementVariantBinding(args) {
114710
114955
  const variant2 = args.context.variantsById.get(args.variantId);
114711
114956
  if (variant2 === void 0) {
114712
114957
  throw new Error(
114713
- `Placement value "${args.placementId}" references variant "${args.variantId}", which does not resolve to a live variant record.`
114958
+ `Placement value "${args.placementId}" references ${noun} "${args.variantId}", which does not resolve to a live variant record.`
114714
114959
  );
114715
114960
  }
114716
- if (variant2.classId !== args.assetClassId) {
114961
+ if (args.layer === "built" && variant2.classId !== args.assetClassId) {
114717
114962
  throw new Error(
114718
114963
  `Placement value "${args.placementId}" places class "${args.assetClassId}" but names variant "${args.variantId}" of class "${variant2.classId}"; variant lookup is not virtual.`
114719
114964
  );
114720
114965
  }
114966
+ if (args.layer === "applied" && !args.context.relationResolver.classAncestry(args.assetClassId).includes(variant2.classId)) {
114967
+ throw new Error(
114968
+ `Placement value "${args.placementId}" places class "${args.assetClassId}" but applies variant "${args.variantId}" of class "${variant2.classId}", which is not that class or a base of it.`
114969
+ );
114970
+ }
114721
114971
  const lookupRows = variant2.lookupRowValueIds;
114722
114972
  if (lookupRows === void 0) {
114723
114973
  if (args.rowValueId !== null) {
114724
114974
  throw new Error(
114725
- `Placement value "${args.placementId}" binds a row to plain variant "${args.variantId}".`
114975
+ `Placement value "${args.placementId}" binds a row to plain ${noun} "${args.variantId}".`
114726
114976
  );
114727
114977
  }
114728
114978
  return;
@@ -114734,7 +114984,7 @@ function validatePlacementVariantBinding(args) {
114734
114984
  }
114735
114985
  if (args.rowValueId === null || !rowIds.has(args.rowValueId)) {
114736
114986
  throw new Error(
114737
- `Placement value "${args.placementId}" must bind a live row from lookup variant "${args.variantId}".`
114987
+ `Placement value "${args.placementId}" must bind a live row from lookup ${noun} "${args.variantId}".`
114738
114988
  );
114739
114989
  }
114740
114990
  }
@@ -114839,11 +115089,14 @@ function optionalNonEmptyString(value) {
114839
115089
  return typeof value === "string" && value.length > 0 ? value : null;
114840
115090
  }
114841
115091
  function consumeWorldPlacementSidecarKeys(args) {
114842
- const worldKind = args.worldKindsByClassId === void 0 ? resolveWorldSystemClassKind(args.classId, args.classes) : args.worldKindsByClassId.get(args.classId) ?? null;
114843
- if (worldKind === null) return /* @__PURE__ */ new Set();
114844
- const assetKind = WORLD_PLACEMENT_ASSET_KIND.get(worldKind);
114845
- if (assetKind === void 0) return /* @__PURE__ */ new Set();
114846
115092
  const classesById = args.classesById ?? new Map(args.classes.map((schemaClass2) => [schemaClass2.id, schemaClass2]));
115093
+ if (!classInheritsWorldKind(
115094
+ args.classId,
115095
+ NeoWorldSystemClassKind.Object,
115096
+ classesById
115097
+ )) {
115098
+ return /* @__PURE__ */ new Set();
115099
+ }
114847
115100
  const present = /* @__PURE__ */ new Set();
114848
115101
  for (const key of WORLD_PLACEMENT_SIDECAR_KEYS) {
114849
115102
  if (!Object.hasOwn(args.body, key)) continue;
@@ -114860,13 +115113,13 @@ function consumeWorldPlacementSidecarKeys(args) {
114860
115113
  classId: assetClassId,
114861
115114
  worldKindsByClassId: args.worldKindsByClassId ?? indexWorldSystemClassKinds(args.classes, classesById),
114862
115115
  classesById,
114863
- expectedKind: assetKind,
115116
+ expectedKind: NeoWorldSystemClassKind.Object,
114864
115117
  label: `${args.label} assetClassId`
114865
115118
  });
114866
115119
  }
114867
115120
  return present;
114868
115121
  }
114869
- var WORLD_PLACEMENT_SIDECAR_KEYS, TILE_CLASS_LEVEL_KEYS, WORLD_PLACEMENT_ASSET_KIND;
115122
+ var WORLD_PLACEMENT_SIDECAR_KEYS, TILE_CLASS_LEVEL_KEYS;
114870
115123
  var init_world_content_sidecar_validation = __esm({
114871
115124
  "../src/models/project/world-content-sidecar-validation.ts"() {
114872
115125
  "use strict";
@@ -114891,7 +115144,6 @@ var init_world_content_sidecar_validation = __esm({
114891
115144
  ).flatMap(
114892
115145
  (field) => field.mutability === 1 /* ReadOnly */ ? [field.schemaKey] : []
114893
115146
  );
114894
- WORLD_PLACEMENT_ASSET_KIND = /* @__PURE__ */ new Map([[NeoWorldSystemClassKind.Object, NeoWorldSystemClassKind.Object]]);
114895
115147
  }
114896
115148
  });
114897
115149
 
@@ -117807,6 +118059,12 @@ function materializePreparedInstanceInitializers(args) {
117807
118059
  );
117808
118060
  let currentReader = null;
117809
118061
  const requireCurrentReader = () => currentReader ??= new EffectiveValueReader(materializationScope.document);
118062
+ let ownedValueCollector;
118063
+ let valueHashes;
118064
+ const liveValueHashes = () => valueHashes ??= indexLiveContentHashesByRecordId(
118065
+ args.contentHashHeads,
118066
+ "value"
118067
+ );
117810
118068
  const owners = resolveSemanticOwnerMembersForValues(
117811
118069
  materializationScope.document,
117812
118070
  new Set(sites.keys()),
@@ -117854,7 +118112,17 @@ function materializePreparedInstanceInitializers(args) {
117854
118112
  storedConstructionReplay: true
117855
118113
  });
117856
118114
  if (existingConstructedRoot !== void 0) {
117857
- if (!isLiteralValueContent(materialized.root) || existingConstructedRoot.classId !== materialized.root.classId || !replayedCreationDataMatches({
118115
+ if (!isLiteralValueContent(materialized.root)) {
118116
+ throw new Error(
118117
+ `construction-arguments-conflict: Value "${valueId}" is already materialized, and its construction no longer evaluates to a stored instance. Delete and recreate the value with the new construction.`
118118
+ );
118119
+ }
118120
+ if (existingConstructedRoot.classId !== materialized.root.classId) {
118121
+ throw new Error(
118122
+ `construction-arguments-conflict: Value "${valueId}" is already materialized as class "${String(existingConstructedRoot.classId)}", and this construction builds class "${String(materialized.root.classId)}". Delete and recreate the value to change its class.`
118123
+ );
118124
+ }
118125
+ if (replayedCreationDataMatches({
117858
118126
  // The synthetic variant binding members are part of the ownership
117859
118127
  // scope that compiled and evaluated this initializer. Stored replay
117860
118128
  // closes its generic slot from the same ephemeral member id, so its
@@ -117865,13 +118133,10 @@ function materializePreparedInstanceInitializers(args) {
117865
118133
  replayRoot: materialized.root,
117866
118134
  replayCreated: materialized.createdValues
117867
118135
  })) {
117868
- throw new Error(
117869
- `construction-arguments-conflict: Value "${valueId}" is already materialized, and this construction changes its original arguments. Edit the instance's members, or delete and recreate the value with the new construction.`
117870
- );
118136
+ replayOnlyIndexes.push(site.index);
118137
+ batch.upsert([existingConstructedRoot]);
118138
+ return;
117871
118139
  }
117872
- replayOnlyIndexes.push(site.index);
117873
- batch.upsert([existingConstructedRoot]);
117874
- return;
117875
118140
  }
117876
118141
  const baseline = materializeInitializerValue2({
117877
118142
  document: currentDocument,
@@ -117898,7 +118163,8 @@ function materializePreparedInstanceInitializers(args) {
117898
118163
  // §4: a call-site field is an explicit override even when it equals
117899
118164
  // the class default, so the evaluated construction's own field list is
117900
118165
  // what pins rows against collapse.
117901
- pinnedRootSchemaKeys: materialized.pinnedRootSchemaKeys
118166
+ pinnedRootSchemaKeys: materialized.pinnedRootSchemaKeys,
118167
+ pinnedSchemaKeysByValueId: materialized.pinnedSchemaKeysByValueId
117902
118168
  });
117903
118169
  assertStoredClosuresKeepNoCaptures({
117904
118170
  sourceValueId: valueId,
@@ -117911,15 +118177,40 @@ function materializePreparedInstanceInitializers(args) {
117911
118177
  ...original,
117912
118178
  nextData: sparse2.root
117913
118179
  };
118180
+ if (existingConstructedRoot !== void 0) {
118181
+ const produced = new Set(sparse2.createdChildren.map((row) => row.id));
118182
+ ownedValueCollector ??= createOwnedValueDeletionCollector(args.document);
118183
+ for (const ownedId of ownedValueCollector.collect({
118184
+ rootIds: [valueId],
118185
+ rootMembers: /* @__PURE__ */ new Map([[valueId, member]])
118186
+ })) {
118187
+ if (ownedId === valueId || produced.has(ownedId)) continue;
118188
+ const contentHash = liveValueHashes().get(ownedId);
118189
+ if (contentHash === void 0) continue;
118190
+ args.prepared.push({
118191
+ recordKind: "value",
118192
+ recordId: ownedId,
118193
+ operation: "delete",
118194
+ deleted: true,
118195
+ expectedBaseContentHash: contentHash,
118196
+ intent: createProjectVersionIntent("value.delete", {
118197
+ source: "server-initializer-materialization",
118198
+ sourceValueId: valueId
118199
+ })
118200
+ });
118201
+ existingValueById.delete(ownedId);
118202
+ }
118203
+ }
117914
118204
  for (const created of sparse2.createdChildren) {
117915
118205
  const existing = existingValueById.get(created.id);
117916
118206
  if (existing !== void 0) {
117917
118207
  if (materializedValueRowsEqual(existing, created)) continue;
117918
- const contentHash = liveContentHash(
117919
- args.contentHashHeads,
117920
- "value",
117921
- created.id
117922
- );
118208
+ const contentHash = liveValueHashes().get(created.id);
118209
+ if (contentHash === void 0) {
118210
+ throw new Error(
118211
+ `Cannot reconcile materialized initializer row "${created.id}": its live content hash is unavailable.`
118212
+ );
118213
+ }
117923
118214
  args.prepared.push({
117924
118215
  recordKind: "value",
117925
118216
  recordId: created.id,
@@ -119152,7 +119443,11 @@ function seedRootRow(member, seed, rootId) {
119152
119443
  ...seed.constructorArgs === void 0 ? {} : { constructorArgs: seed.constructorArgs },
119153
119444
  ...seed.instanceConstructorId === void 0 ? {} : { instanceConstructorId: seed.instanceConstructorId },
119154
119445
  ...seed.instanceVariantId === void 0 ? {} : { instanceVariantId: seed.instanceVariantId },
119155
- ...seed.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: seed.instanceVariantRowValueId }
119446
+ ...seed.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: seed.instanceVariantRowValueId },
119447
+ ...seed.instanceAppliedVariantId === void 0 ? {} : { instanceAppliedVariantId: seed.instanceAppliedVariantId },
119448
+ ...seed.instanceAppliedVariantRowValueId === void 0 ? {} : {
119449
+ instanceAppliedVariantRowValueId: seed.instanceAppliedVariantRowValueId
119450
+ }
119156
119451
  };
119157
119452
  }
119158
119453
  function authoredSeedRowMatchesValue(row, value) {
@@ -119169,7 +119464,7 @@ function authoredSeedRowMatchesValue(row, value) {
119169
119464
  return isLiteralValueContent(value);
119170
119465
  }
119171
119466
  if (isInitValueContent(value)) return false;
119172
- const seedDeclaresProvenance = row.constructorArgs !== void 0 || row.instanceConstructorId !== void 0 || row.instanceVariantId !== void 0 || row.instanceVariantRowValueId !== void 0;
119467
+ const seedDeclaresProvenance = row.constructorArgs !== void 0 || row.instanceConstructorId !== void 0 || row.instanceVariantId !== void 0 || row.instanceVariantRowValueId !== void 0 || row.instanceAppliedVariantId !== void 0 || row.instanceAppliedVariantRowValueId !== void 0;
119173
119468
  return canonicallyEqual2(
119174
119469
  {
119175
119470
  value: row.value,
@@ -119295,6 +119590,10 @@ function materializeAuthoredSeedRow(args) {
119295
119590
  },
119296
119591
  ...args.row.instanceVariantId === void 0 ? {} : { instanceVariantId: args.row.instanceVariantId },
119297
119592
  ...args.row.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: args.row.instanceVariantRowValueId },
119593
+ ...args.row.instanceAppliedVariantId === void 0 ? {} : { instanceAppliedVariantId: args.row.instanceAppliedVariantId },
119594
+ ...args.row.instanceAppliedVariantRowValueId === void 0 ? {} : {
119595
+ instanceAppliedVariantRowValueId: args.row.instanceAppliedVariantRowValueId
119596
+ },
119298
119597
  ...args.row.containerId === void 0 ? {} : { containerId: args.row.containerId },
119299
119598
  ...args.row.genericBindings === void 0 ? {} : { genericBindings: { ...args.row.genericBindings } },
119300
119599
  ...args.row.sourceValueId === void 0 ? {} : { sourceValueId: args.row.sourceValueId },
@@ -128147,7 +128446,11 @@ function assertVariantMemberTargetValid(args) {
128147
128446
  `${label} targets class "${target.classId}", which is not in this project.`
128148
128447
  );
128149
128448
  }
128150
- if (resolveWorldKindFromClassMap(target.classId, classesById) !== NeoWorldSystemClassKind.Object) {
128449
+ if (!classInheritsWorldKind(
128450
+ target.classId,
128451
+ NeoWorldSystemClassKind.Object,
128452
+ classesById
128453
+ )) {
128151
128454
  throw new Error(
128152
128455
  `${label} targets class "${targetClass.name}", which does not derive from NeoObject. Only NeoObject-derived classes declare variants (P67 \xA71).`
128153
128456
  );
@@ -129587,6 +129890,7 @@ function prepareClientPush(args) {
129587
129890
  if (change.recordKind !== "value" || change.operation !== "update") {
129588
129891
  continue;
129589
129892
  }
129893
+ if (isInitValueContent(change.nextData)) continue;
129590
129894
  const refusal = valueDematerializationRefusal({
129591
129895
  valueId: change.recordId,
129592
129896
  baseData: args.base.records.get(`value:${change.recordId}`)?.data,
@@ -129755,6 +130059,7 @@ var init_server_preparation_preflight = __esm({
129755
130059
  init_project_document_read();
129756
130060
  init_project_snapshot_derived_edges();
129757
130061
  init_project_version_whole_graph_validation();
130062
+ init_members();
129758
130063
  init_performance();
129759
130064
  init_trusted_commit_verification();
129760
130065
  ServerPreparationPreflightError = class extends Error {
@@ -129852,17 +130157,8 @@ function replayStoredConstructionV4(args) {
129852
130157
  createdAt: 0,
129853
130158
  updatedAt: 0
129854
130159
  };
129855
- const rootRecord = root;
129856
- const envelope = { ...rootRecord };
129857
- delete envelope.value;
129858
- delete envelope.classId;
129859
- delete envelope.constructorArgs;
129860
- delete envelope.instanceConstructorId;
129861
- delete envelope.instanceVariantId;
129862
- delete envelope.instanceVariantRowValueId;
129863
- delete envelope.init;
129864
130160
  const candidate = {
129865
- ...envelope,
130161
+ ...withoutMaterializedInstanceFields(root),
129866
130162
  init: args.compiledInitializer ?? { code: args.code }
129867
130163
  };
129868
130164
  if (args.compiledInitializer === void 0)
@@ -129921,7 +130217,7 @@ function replayStoredConstructionV4(args) {
129921
130217
  ...args.omitConstructionFields === true ? { constructionBaselineReplay: true } : {},
129922
130218
  ...args.initializerArgumentValues === void 0 ? {} : { argumentValues: args.initializerArgumentValues }
129923
130219
  });
129924
- args.onPinnedRootSchemaKeys?.(materialized.pinnedRootSchemaKeys);
130220
+ args.onPinnedSchemaKeys?.(materialized);
129925
130221
  return new Map(
129926
130222
  [materialized.root, ...materialized.createdValues].map((row) => [
129927
130223
  row.id,
@@ -130025,6 +130321,18 @@ function compilePulledProjectDocumentForEvaluationV4(document, compilationProjec
130025
130321
  }
130026
130322
  return compiled;
130027
130323
  }
130324
+ function withoutMaterializedInstanceFields(row) {
130325
+ const envelope = { ...row };
130326
+ delete envelope.value;
130327
+ delete envelope.classId;
130328
+ delete envelope.constructorArgs;
130329
+ delete envelope.instanceConstructorId;
130330
+ delete envelope.instanceVariantId;
130331
+ delete envelope.instanceVariantRowValueId;
130332
+ delete envelope.instanceAppliedVariantId;
130333
+ delete envelope.instanceAppliedVariantRowValueId;
130334
+ return envelope;
130335
+ }
130028
130336
  function assertPulledConstructorsCompiled(document, replayContext) {
130029
130337
  if (replayContext !== void 0 && replayContext.document !== document) {
130030
130338
  throw new Error(
@@ -132330,22 +132638,7 @@ function mergedOverStoredRow(base, lowered) {
132330
132638
  const code = storedInitCode(base, lowered.init.code);
132331
132639
  if (code !== lowered.init.code) merged.init = { ...lowered.init, code };
132332
132640
  }
132333
- const {
132334
- value: _value,
132335
- classId: _classId,
132336
- constructorArgs: _constructorArgs,
132337
- instanceConstructorId: _instanceConstructorId,
132338
- instanceVariantId: _instanceVariantId,
132339
- instanceVariantRowValueId: _instanceVariantRowValueId,
132340
- ...initializer
132341
- } = merged;
132342
- void _value;
132343
- void _classId;
132344
- void _constructorArgs;
132345
- void _instanceConstructorId;
132346
- void _instanceVariantId;
132347
- void _instanceVariantRowValueId;
132348
- return initializer;
132641
+ return withoutMaterializedInstanceFields(merged);
132349
132642
  }
132350
132643
  function storedCompiledClosure(stored, lowered) {
132351
132644
  if (!isNSDelegateClosureValueDraft(lowered)) return null;
@@ -132619,7 +132912,7 @@ function lowerMemberDefaultSourcesV4(state, analysis, manifest, options = {}) {
132619
132912
  `Member default ${label} was classified as an owned literal graph but lowered as an initializer.`
132620
132913
  );
132621
132914
  }
132622
- const emptyInlineClassDefault = member.kind === "class" && isObjectRecord2(seed.value) && Object.keys(seed.value).length === 0 && (seed.constructorArgs === void 0 || Object.keys(seed.constructorArgs).length === 0) && seed.instanceConstructorId == null && seed.instanceVariantId == null && seed.instanceVariantRowValueId == null;
132915
+ const emptyInlineClassDefault = member.kind === "class" && isObjectRecord2(seed.value) && Object.keys(seed.value).length === 0 && (seed.constructorArgs === void 0 || Object.keys(seed.constructorArgs).length === 0) && seed.instanceConstructorId == null && seed.instanceVariantId == null && seed.instanceVariantRowValueId == null && seed.instanceAppliedVariantId == null && seed.instanceAppliedVariantRowValueId == null;
132623
132916
  const matchesStoredDefault = storedDefault !== null && canonicallyEqual(seed.value, storedDefault.value) && (seed.classId ?? null) === (typeof storedDefaultClassId === "string" ? storedDefaultClassId : null);
132624
132917
  if ((emptyInlineClassDefault || matchesStoredDefault) && (seed.values === void 0 || seed.values.length === 0) && (seed.bindingMembers === void 0 || seed.bindingMembers.length === 0) && (seed.localizedTexts === void 0 || seed.localizedTexts.length === 0)) {
132625
132918
  for (const id2 of context.pendingValues.keys()) {
@@ -134137,7 +134430,11 @@ function readInstanceProvenance(value) {
134137
134430
  },
134138
134431
  instanceConstructorId: nullableString5(value.instanceConstructorId),
134139
134432
  instanceVariantId: nullableString5(value.instanceVariantId),
134140
- instanceVariantRowValueId: nullableString5(value.instanceVariantRowValueId)
134433
+ instanceVariantRowValueId: nullableString5(value.instanceVariantRowValueId),
134434
+ instanceAppliedVariantId: nullableString5(value.instanceAppliedVariantId),
134435
+ instanceAppliedVariantRowValueId: nullableString5(
134436
+ value.instanceAppliedVariantRowValueId
134437
+ )
134141
134438
  };
134142
134439
  }
134143
134440
  function preserveReboundValue(context, currentValueId, nextValueId, binding) {
@@ -134187,6 +134484,10 @@ function lowerStaticSeed(context, member, sourceExpression, source, valueId) {
134187
134484
  ...root.instanceConstructorId === void 0 ? {} : { instanceConstructorId: root.instanceConstructorId },
134188
134485
  ...root.instanceVariantId === void 0 ? {} : { instanceVariantId: root.instanceVariantId },
134189
134486
  ...root.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: root.instanceVariantRowValueId },
134487
+ ...root.instanceAppliedVariantId === void 0 ? {} : { instanceAppliedVariantId: root.instanceAppliedVariantId },
134488
+ ...root.instanceAppliedVariantRowValueId === void 0 ? {} : {
134489
+ instanceAppliedVariantRowValueId: root.instanceAppliedVariantRowValueId
134490
+ },
134190
134491
  ...rows.size === 0 && member.kind !== "class" && member.kind !== "list" && member.kind !== "set" && member.kind !== "dictionary" && localizedTexts.size === 0 ? {} : { values: [...rows.values()] },
134191
134492
  ...bindingMembers.length === 0 ? {} : { bindingMembers },
134192
134493
  ...localizedTexts.size === 0 ? {} : { localizedTexts: [...localizedTexts.values()] }
@@ -135596,37 +135897,15 @@ function lowerClassValue(context, member, expression, base, source, outerEnviron
135596
135897
  }
135597
135898
  }
135598
135899
  if (materializedConstruction !== "lower") {
135599
- if (materializedConstruction === "preserve" && isObjectRecord2(base.constructorArgs) && // An explicit `null` IS the recorded identity of a parameterless
135600
- // construction, so it owns no argument rows to retain. Inferring an
135601
- // overload for it would resolve the wrong constructor or refuse the
135602
- // plan outright.
135603
- base.instanceConstructorId !== null) {
135604
- const constructor2 = storedValueConstructor(
135900
+ if (materializedConstruction === "preserve" && classId === currentClassId) {
135901
+ retainConstructionArguments(
135605
135902
  context,
135903
+ base,
135606
135904
  schemaClass2,
135607
- recordedStoredConstructorId(base, schemaClass2)
135608
- );
135609
- const authoredArguments = constructorArgumentExpressions(expression);
135610
- for (let index = 0; index < constructor2.arguments.length; index += 1) {
135611
- const argument2 = constructor2.arguments[index];
135612
- if (argument2 === void 0) continue;
135613
- const valueId = base.constructorArgs[`__arg_${index}__`];
135614
- if (typeof valueId !== "string") continue;
135615
- if (!constructorArgumentOwnsRow(
135616
- argument2.type,
135617
- authoredArguments.get(argument2.name)
135618
- )) {
135619
- continue;
135620
- }
135621
- retainStoredValueSubgraph(
135622
- context,
135623
- valueId,
135624
- source.source,
135625
- /* @__PURE__ */ new Set(),
135626
- null,
135627
- environment
135628
- );
135629
- }
135905
+ expression,
135906
+ source.source,
135907
+ environment
135908
+ );
135630
135909
  }
135631
135910
  }
135632
135911
  return {
@@ -135635,6 +135914,163 @@ function lowerClassValue(context, member, expression, base, source, outerEnviron
135635
135914
  ...classId === currentClassId ? {} : { classId }
135636
135915
  };
135637
135916
  }
135917
+ function retainConstructionArguments(context, row, schemaClass2, expression, source, environment) {
135918
+ const constructorArgs2 = row.constructorArgs;
135919
+ if (!isObjectRecord2(constructorArgs2)) return;
135920
+ if (row.instanceConstructorId === null) return;
135921
+ const constructor2 = storedValueConstructor(
135922
+ context,
135923
+ schemaClass2,
135924
+ recordedStoredConstructorId(row, schemaClass2)
135925
+ );
135926
+ const authoredArguments = constructorArgumentExpressions(expression);
135927
+ const argumentEnvironment = valueGenericEnvironment(row, environment);
135928
+ for (let index = 0; index < constructor2.arguments.length; index += 1) {
135929
+ const argument2 = constructor2.arguments[index];
135930
+ if (argument2 === void 0) continue;
135931
+ const valueId = constructorArgs2[`__arg_${index}__`];
135932
+ if (typeof valueId !== "string") continue;
135933
+ const authored = authoredArguments.get(argument2.name);
135934
+ if (!constructorArgumentOwnsRow(argument2.type, authored)) continue;
135935
+ retainStoredValueSubgraph(
135936
+ context,
135937
+ valueId,
135938
+ source,
135939
+ /* @__PURE__ */ new Set(),
135940
+ null,
135941
+ argumentEnvironment
135942
+ );
135943
+ const building2 = authored === void 0 ? null : rowBuildingExpression(authored);
135944
+ if (building2 === null) continue;
135945
+ retainInlineConstructionArguments(
135946
+ context,
135947
+ valueId,
135948
+ argument2.type,
135949
+ building2,
135950
+ source,
135951
+ argumentEnvironment
135952
+ );
135953
+ }
135954
+ }
135955
+ function rowBuildingExpression(expression) {
135956
+ const unwrapped = annotatedValue(expression).expression;
135957
+ return unwrapped.kind === "new" || unwrapped.kind === "litList" || unwrapped.kind === "litDict" ? unwrapped : null;
135958
+ }
135959
+ function retainInlineConstructionArguments(context, valueId, slot, authored, source, environment) {
135960
+ const row = context.state[`value:${valueId}`]?.data;
135961
+ if (!isObjectRecord2(row)) return;
135962
+ if (authored.kind === "new") {
135963
+ const classId = stringOrNull2(row.classId);
135964
+ const schemaClass2 = classId === null ? void 0 : context.classes.get(classId);
135965
+ if (schemaClass2 === void 0) return;
135966
+ retainConstructionArguments(
135967
+ context,
135968
+ row,
135969
+ schemaClass2,
135970
+ authored,
135971
+ source,
135972
+ environment
135973
+ );
135974
+ if (authored.initializer === void 0) return;
135975
+ if (!isObjectRecord2(row.value)) return;
135976
+ retainInitializerConstructionArguments(
135977
+ context,
135978
+ row,
135979
+ row.value,
135980
+ schemaClass2.id,
135981
+ authored.initializer,
135982
+ source,
135983
+ environment
135984
+ );
135985
+ return;
135986
+ }
135987
+ const settled = settledArgumentSlot(context, slot, environment);
135988
+ if (authored.kind === "litList" && settled.kind === "list" && Array.isArray(row.value)) {
135989
+ const entrySlot = argumentSlotEntry(context, settled);
135990
+ if (entrySlot === null) return;
135991
+ for (const [index, element] of authored.elements.entries()) {
135992
+ const entryId = row.value[index];
135993
+ if (typeof entryId !== "string") continue;
135994
+ const building2 = rowBuildingExpression(element);
135995
+ if (building2 === null) continue;
135996
+ retainInlineConstructionArguments(
135997
+ context,
135998
+ entryId,
135999
+ entrySlot,
136000
+ building2,
136001
+ source,
136002
+ environment
136003
+ );
136004
+ }
136005
+ return;
136006
+ }
136007
+ if (authored.kind === "litDict" && settled.kind === "dictionary" && isObjectRecord2(row.value)) {
136008
+ const entrySlot = argumentSlotEntry(context, settled);
136009
+ if (entrySlot === null) return;
136010
+ const keyEnumId = dictionarySlotKeyEnumId(settled);
136011
+ const keyEnum = keyEnumId === null ? null : keyEnumById(context, keyEnumId);
136012
+ for (const entry of authored.entries) {
136013
+ const key = nestedDictionaryKey(entry.key, keyEnum);
136014
+ const entryId = key === null ? void 0 : row.value[key];
136015
+ if (typeof entryId !== "string") continue;
136016
+ const building2 = rowBuildingExpression(entry.value);
136017
+ if (building2 === null) continue;
136018
+ retainInlineConstructionArguments(
136019
+ context,
136020
+ entryId,
136021
+ entrySlot,
136022
+ building2,
136023
+ source,
136024
+ environment
136025
+ );
136026
+ }
136027
+ }
136028
+ }
136029
+ function settledArgumentSlot(context, slot, environment) {
136030
+ if (slot.kind !== "generic") return slot;
136031
+ if ("source" in slot) {
136032
+ return resolveGenericSchemaMember(context, slot, environment);
136033
+ }
136034
+ return storedGenericArgumentType(
136035
+ { manifestMembers: context.members },
136036
+ slot,
136037
+ environment
136038
+ );
136039
+ }
136040
+ function argumentSlotEntry(context, slot) {
136041
+ if ("entryType" in slot) return slot.entryType;
136042
+ return memberById(context, slot.entryMemberId);
136043
+ }
136044
+ function dictionarySlotKeyEnumId(slot) {
136045
+ if ("keyEnumId" in slot) return slot.keyEnumId;
136046
+ return slot.key.kind === "enum" ? slot.key.enumId : null;
136047
+ }
136048
+ function retainInitializerConstructionArguments(context, row, body, classId, initializer, source, environment) {
136049
+ const authoredMembers = /* @__PURE__ */ new Map();
136050
+ for (const assignment of initializer) {
136051
+ const building2 = rowBuildingExpression(assignment.value);
136052
+ if (building2 !== null) authoredMembers.set(assignment.name, building2);
136053
+ }
136054
+ if (authoredMembers.size === 0) return;
136055
+ const memberIds = storedClassSchemaMemberIds(context, classId);
136056
+ const renames = renamedSchemaKeys(context, classId);
136057
+ const memberEnvironment = valueGenericEnvironment(row, environment);
136058
+ for (const [storedKey, childId] of Object.entries(body)) {
136059
+ if (typeof childId !== "string") continue;
136060
+ const building2 = authoredMembers.get(renames.get(storedKey) ?? storedKey);
136061
+ if (building2 === void 0) continue;
136062
+ const member = memberById(context, memberIds.get(storedKey));
136063
+ if (member === null) continue;
136064
+ retainInlineConstructionArguments(
136065
+ context,
136066
+ childId,
136067
+ member,
136068
+ building2,
136069
+ source,
136070
+ memberEnvironment
136071
+ );
136072
+ }
136073
+ }
135638
136074
  function constructorArgumentOwnsRow(type, authoredArgument) {
135639
136075
  if (type.kind !== "class" && type.kind !== "interface" && type.kind !== "generic" && type.kind !== "list" && type.kind !== "set" && type.kind !== "dictionary") {
135640
136076
  return false;
@@ -137682,6 +138118,7 @@ function freshChildReplaysDeclaredDefault(args) {
137682
138118
  if (child2.genericBindings !== void 0) return false;
137683
138119
  if (child2.instanceVariantId != null) return false;
137684
138120
  if (child2.instanceVariantRowValueId != null) return false;
138121
+ if (child2.instanceAppliedVariantId != null) return false;
137685
138122
  if (context.collectionBindingMemberIds.has(childMember.id)) return false;
137686
138123
  const resolved = resolveGenericSchemaMember(
137687
138124
  context,
@@ -138152,15 +138589,16 @@ function requiredMember(context, id2) {
138152
138589
  }
138153
138590
  function dictionaryKeyEnum(context, member) {
138154
138591
  if (member.key.kind === "string") return null;
138155
- const name = context.enumNames.get(member.key.enumId);
138156
- const optionsByName = context.enumOptions.get(member.key.enumId);
138592
+ return keyEnumById(context, member.key.enumId);
138593
+ }
138594
+ function keyEnumById(context, enumId) {
138595
+ const name = context.enumNames.get(enumId);
138596
+ const optionsByName = context.enumOptions.get(enumId);
138157
138597
  if (name === void 0) {
138158
- throw new Error(`Unknown dictionary key enum ${member.key.enumId}.`);
138598
+ throw new Error(`Unknown dictionary key enum ${enumId}.`);
138159
138599
  }
138160
138600
  if (optionsByName === void 0) {
138161
- throw new Error(
138162
- `Dictionary key enum ${member.key.enumId} has no option index.`
138163
- );
138601
+ throw new Error(`Dictionary key enum ${enumId} has no option index.`);
138164
138602
  }
138165
138603
  return { name, optionsByName };
138166
138604
  }
@@ -138667,7 +139105,7 @@ function storedReplayLeafValueMatches(type, value) {
138667
139105
  }
138668
139106
  function literalStoredReplayInitializer(context, valueId, code, member) {
138669
139107
  const value = context.values.get(valueId);
138670
- if (value === void 0 || typeof value.classId !== "string" || typeof value.instanceConstructorId !== "string" || typeof value.instanceVariantId === "string" || !isObjectRecord2(value.constructorArgs))
139108
+ if (value === void 0 || typeof value.classId !== "string" || typeof value.instanceConstructorId !== "string" || typeof value.instanceVariantId === "string" || typeof value.instanceAppliedVariantId === "string" || !isObjectRecord2(value.constructorArgs))
138671
139109
  return void 0;
138672
139110
  const schemaClass2 = context.manifestClasses.get(value.classId);
138673
139111
  if (schemaClass2?.requiredConstructorId !== value.instanceConstructorId)
@@ -139176,7 +139614,8 @@ function storedConstructorArgumentSource(context, type, value, environment, visi
139176
139614
  visited,
139177
139615
  false,
139178
139616
  false,
139179
- constructorOwnsGraph
139617
+ constructorOwnsGraph,
139618
+ cloneAggregateArguments
139180
139619
  );
139181
139620
  case "lookup":
139182
139621
  return referenceValue(
@@ -139511,7 +139950,7 @@ function storedSchemaTypeName(context, type, environment, valueId) {
139511
139950
  return "null";
139512
139951
  }
139513
139952
  }
139514
- function storedTypedRowSource(context, type, valueId, environment, visited, writeIdentity, partial = false, constructorOwnsGraph = false) {
139953
+ function storedTypedRowSource(context, type, valueId, environment, visited, writeIdentity, partial = false, constructorOwnsGraph = false, cloneAggregateArguments = false) {
139515
139954
  const symbol = context.symbolsByValueId.get(valueId);
139516
139955
  if (symbol !== void 0) return symbol;
139517
139956
  const row = context.values.get(valueId);
@@ -139520,6 +139959,18 @@ function storedTypedRowSource(context, type, valueId, environment, visited, writ
139520
139959
  `Stored ${type.kind} constructor argument references missing value row ${valueId}.`
139521
139960
  );
139522
139961
  }
139962
+ if (cloneAggregateArguments) {
139963
+ const settled = type.kind === "generic" ? storedGenericArgumentType(context, type, environment) : type;
139964
+ if (settled.kind === "class" || settled.kind === "interface") {
139965
+ return storedAggregateReplaySource(
139966
+ context,
139967
+ settled,
139968
+ valueId,
139969
+ environment,
139970
+ constructorOwnsGraph
139971
+ );
139972
+ }
139973
+ }
139523
139974
  if (isSharedConstructorArgument(context, valueId, constructorOwnsGraph)) {
139524
139975
  return `Reference<${storedSchemaTypeName(context, type, environment, valueId)}>(id: ${quote3(valueId)})`;
139525
139976
  }
@@ -139576,7 +140027,8 @@ ${ids.map(
139576
140027
  visited,
139577
140028
  true,
139578
140029
  false,
139579
- constructorOwnsGraph
140030
+ constructorOwnsGraph,
140031
+ cloneAggregateArguments
139580
140032
  ),
139581
140033
  2
139582
140034
  )
@@ -139605,7 +140057,8 @@ ${entries.flatMap(
139605
140057
  visited,
139606
140058
  false,
139607
140059
  false,
139608
- constructorOwnsGraph
140060
+ constructorOwnsGraph,
140061
+ cloneAggregateArguments
139609
140062
  )}`,
139610
140063
  2
139611
140064
  )
@@ -141215,8 +141668,8 @@ function initializerRecompileTargets(args) {
141215
141668
  })
141216
141669
  });
141217
141670
  }
141218
- function materializedInitializerReconciliationFailuresV4(args) {
141219
- if (args.reconciliations.size === 0) return [];
141671
+ function reconcileMaterializedInitializersV4(args) {
141672
+ if (args.reconciliations.size === 0) return { failures: [], rebuilds: [] };
141220
141673
  const records3 = reconciliationRecords(
141221
141674
  args.workspace,
141222
141675
  args.changes,
@@ -141294,7 +141747,6 @@ function materializedInitializerReconciliationFailuresV4(args) {
141294
141747
  }
141295
141748
  }
141296
141749
  const expressionsGrew = canonicalExpressions.size > (cached?.expressions.size ?? 0);
141297
- const authoredConstructionChangedByValueId = /* @__PURE__ */ new Map();
141298
141750
  const replayableValueIds = /* @__PURE__ */ new Set();
141299
141751
  for (const [valueId, reconciliation] of constructions) {
141300
141752
  const owner = candidateOwners.get(valueId);
@@ -141306,11 +141758,7 @@ function materializedInitializerReconciliationFailuresV4(args) {
141306
141758
  );
141307
141759
  }
141308
141760
  const authoredConstructionChanged = args.manifest !== void 0 && canonicalExpression !== reconciliation.construction;
141309
- authoredConstructionChangedByValueId.set(
141310
- valueId,
141311
- authoredConstructionChanged
141312
- );
141313
- if (reconciliation.kind === "storedArguments" && (authoredConstructionChanged || currentState().recompileTargets.valueIds.has(valueId))) {
141761
+ if (authoredConstructionChanged || reconciliation.kind === "storedArguments" && currentState().recompileTargets.valueIds.has(valueId)) {
141314
141762
  replayableValueIds.add(valueId);
141315
141763
  }
141316
141764
  }
@@ -141377,26 +141825,9 @@ function materializedInitializerReconciliationFailuresV4(args) {
141377
141825
  }
141378
141826
  let currentRows;
141379
141827
  let currentReader;
141828
+ let ownedValues;
141829
+ const rebuilds = [];
141380
141830
  for (const reconciliation of constructions.values()) {
141381
- if (reconciliation.kind === "canonicalConstruction") {
141382
- if (authoredConstructionChangedByValueId.get(reconciliation.valueId) !== true) {
141383
- continue;
141384
- }
141385
- const position2 = composeReferenceSitePosition(
141386
- reconciliation.site,
141387
- args.sourceTextByUri
141388
- );
141389
- failures.push(
141390
- new SchemaSourceError(
141391
- `construction-arguments-conflict: Value "${reconciliation.valueId}" is already materialized without durable constructor arguments, and this construction no longer matches its pulled canonical projection. Delete and recreate the value to change its construction.`,
141392
- position2.file,
141393
- position2.line,
141394
- position2.column,
141395
- "construction-arguments-conflict"
141396
- )
141397
- );
141398
- continue;
141399
- }
141400
141831
  if (!replayableValueIds.has(reconciliation.valueId)) continue;
141401
141832
  const owner = candidateOwners.get(reconciliation.valueId);
141402
141833
  if (owner === void 0) {
@@ -141424,7 +141855,7 @@ function materializedInitializerReconciliationFailuresV4(args) {
141424
141855
  }
141425
141856
  } catch (error) {
141426
141857
  if (error instanceof NSGetterRuntimeError && error.source === void 0 && args.forceRecompile !== true) {
141427
- return materializedInitializerReconciliationFailuresV4({
141858
+ return reconcileMaterializedInitializersV4({
141428
141859
  ...args,
141429
141860
  forceRecompile: true,
141430
141861
  useBuildCaches: false,
@@ -141448,34 +141879,81 @@ function materializedInitializerReconciliationFailuresV4(args) {
141448
141879
  );
141449
141880
  currentReader ??= new EffectiveValueReader(replayDocument, currentRows);
141450
141881
  const replay = replayRows.get(reconciliation.valueId);
141451
- const replayArgs = replay !== void 0 && isLiteralValueContent(replay) ? replay.constructorArgs : void 0;
141882
+ if (replay === void 0) {
141883
+ throw new Error(
141884
+ `Construction replay for value "${reconciliation.valueId}" produced no root row.`
141885
+ );
141886
+ }
141452
141887
  const currentRoot = currentRows.get(reconciliation.valueId);
141453
- const [storedArgs, replayedArgs] = isObjectRecord2(replayArgs) ? withoutSharedArguments(reconciliation.storedConstructorArgs, replayArgs) : [reconciliation.storedConstructorArgs, replayArgs];
141454
- const currentNormalized = currentRoot === void 0 ? void 0 : currentReader.normalizeConstructorArguments(
141455
- storedArgs,
141888
+ if (currentRoot === void 0) {
141889
+ throw new Error(
141890
+ `Cannot reconcile stored construction for value "${reconciliation.valueId}": its stored row is missing.`
141891
+ );
141892
+ }
141893
+ if (replay.classId !== currentRoot.classId) {
141894
+ const position = composeReferenceSitePosition(
141895
+ reconciliation.site,
141896
+ args.sourceTextByUri
141897
+ );
141898
+ failures.push(
141899
+ new SchemaSourceError(
141900
+ `construction-arguments-conflict: Value "${reconciliation.valueId}" is already materialized as another class. Delete and recreate the value to change its class.`,
141901
+ position.file,
141902
+ position.line,
141903
+ position.column,
141904
+ "construction-arguments-conflict"
141905
+ )
141906
+ );
141907
+ continue;
141908
+ }
141909
+ if (reconciliation.kind === "storedArguments" && storedArgumentsMatch({
141910
+ reader: currentReader,
141911
+ stored: reconciliation.storedConstructorArgs,
141456
141912
  currentRoot,
141913
+ replay,
141914
+ replayRows,
141457
141915
  owner
141458
- );
141459
- const replayNormalized = replay === void 0 || !isObjectRecord2(replayedArgs) ? void 0 : currentReader.withRowOverrides(replayRows).normalizeConstructorArguments(replayedArgs, replay, owner);
141460
- const argumentsMatch = isObjectRecord2(replayArgs) && currentRoot !== void 0 && replay !== void 0 && effectiveValuesEqual(currentNormalized, replayNormalized);
141461
- if (argumentsMatch) {
141916
+ })) {
141462
141917
  continue;
141463
141918
  }
141464
- const position = composeReferenceSitePosition(
141465
- reconciliation.site,
141466
- args.sourceTextByUri
141467
- );
141468
- failures.push(
141469
- new SchemaSourceError(
141470
- `construction-arguments-conflict: Value "${reconciliation.valueId}" is already materialized, and this construction changes its original arguments. Edit the instance's members, or delete and recreate the value with the new construction.`,
141471
- position.file,
141472
- position.line,
141473
- position.column,
141474
- "construction-arguments-conflict"
141475
- )
141476
- );
141919
+ const stored = currentState().records.get(
141920
+ `value:${reconciliation.valueId}`
141921
+ )?.data;
141922
+ if (!isObjectRecord2(stored)) {
141923
+ throw new Error(
141924
+ `Cannot rebuild construction for value "${reconciliation.valueId}": its pulled row is missing.`
141925
+ );
141926
+ }
141927
+ ownedValues ??= createOwnedValueDeletionCollector(replayDocument);
141928
+ rebuilds.push({
141929
+ valueId: reconciliation.valueId,
141930
+ row: rebuiltConstructionRow(stored, reconciliation.code),
141931
+ ownedValueIds: ownedValues.collect({
141932
+ rootIds: [reconciliation.valueId],
141933
+ rootMembers: /* @__PURE__ */ new Map([[reconciliation.valueId, owner]])
141934
+ })
141935
+ });
141477
141936
  }
141478
- return failures;
141937
+ return { failures, rebuilds };
141938
+ }
141939
+ function storedArgumentsMatch(args) {
141940
+ const replayArgs = isLiteralValueContent(args.replay) ? args.replay.constructorArgs : void 0;
141941
+ if (!isObjectRecord2(replayArgs)) return false;
141942
+ const [storedArgs, replayedArgs] = withoutSharedArguments(
141943
+ args.stored,
141944
+ replayArgs
141945
+ );
141946
+ return effectiveValuesEqual(
141947
+ args.reader.normalizeConstructorArguments(
141948
+ storedArgs,
141949
+ args.currentRoot,
141950
+ args.owner
141951
+ ),
141952
+ args.reader.withRowOverrides(args.replayRows).normalizeConstructorArguments(replayedArgs, args.replay, args.owner)
141953
+ );
141954
+ }
141955
+ function rebuiltConstructionRow(data, code) {
141956
+ return { ...withoutMaterializedInstanceFields(data), init: { code } };
141479
141957
  }
141480
141958
  function retainedLiteralCompiles(document, retained, owners, rootOwners, stored) {
141481
141959
  if (retained.length === 0) return null;
@@ -141777,7 +142255,10 @@ function materializeInitializersLocallyV4(args) {
141777
142255
  });
141778
142256
  const code = initializerCode(records3, sourceValueId);
141779
142257
  let compiledInitializer;
141780
- let pinnedRootSchemaKeys = /* @__PURE__ */ new Set();
142258
+ let pinned = {
142259
+ pinnedRootSchemaKeys: /* @__PURE__ */ new Set(),
142260
+ pinnedSchemaKeysByValueId: /* @__PURE__ */ new Map()
142261
+ };
141781
142262
  const evaluated = replayStoredConstructionV4({
141782
142263
  records: records3,
141783
142264
  document,
@@ -141791,8 +142272,8 @@ function materializeInitializersLocallyV4(args) {
141791
142272
  compiledInitializer = init;
141792
142273
  compiledInitializers.set(sourceValueId, init);
141793
142274
  },
141794
- onPinnedRootSchemaKeys: (schemaKeys) => {
141795
- pinnedRootSchemaKeys = schemaKeys;
142275
+ onPinnedSchemaKeys: (keys) => {
142276
+ pinned = keys;
141796
142277
  }
141797
142278
  });
141798
142279
  const evaluatedRoot = evaluated.get(sourceValueId);
@@ -141856,7 +142337,8 @@ function materializeInitializersLocallyV4(args) {
141856
142337
  // §4: a call-site field is an explicit override even when it equals the
141857
142338
  // class default, so the evaluated construction's own field list is what
141858
142339
  // pins rows against collapse. Push preparation pins the same set.
141859
- pinnedRootSchemaKeys,
142340
+ pinnedRootSchemaKeys: pinned.pinnedRootSchemaKeys,
142341
+ pinnedSchemaKeysByValueId: pinned.pinnedSchemaKeysByValueId,
141860
142342
  virtualValueIdForSource: (instanceRootId, sourceIdentity3) => isPendingId(instanceRootId) || hasPendingVirtualSourceIdentity(sourceIdentity3) ? pendingVirtualValueId(instanceRootId, sourceIdentity3) : virtualValueId(instanceRootId, sourceIdentity3)
141861
142343
  });
141862
142344
  const evaluatedRows = [sparse2.root, ...sparse2.createdChildren];
@@ -142045,6 +142527,7 @@ var init_local_initializer_materialization = __esm({
142045
142527
  init_constructor_argument_ownership();
142046
142528
  init_neo_script_recompile_scope();
142047
142529
  init_compiler_adapter();
142530
+ init_owned_value_deletion();
142048
142531
  init_compiled_construction_types();
142049
142532
  init_project_version_schema_commit();
142050
142533
  init_value_row_owner_members();
@@ -148922,23 +149405,28 @@ function computeStatus(workspace, options, conflictedFiles, parseErrors, parseWa
148922
149405
  }
148923
149406
  if (!parseErrors.some(isBlockingSchemaSourceError)) {
148924
149407
  try {
148925
- parseErrors.push(
148926
- ...materializedInitializerReconciliationFailuresV4({
148927
- workspace,
148928
- changes,
148929
- authoredValueSeeds,
148930
- reconciliations: valueLowerRegistry.initializerReconciliations,
148931
- canonicalConstructions: valueLowerRegistry.materializedConstructorExpressions,
148932
- localizedTextDependencies,
148933
- manifest,
148934
- analysis: projectAnalysisV4,
148935
- forceRecompile: options.forceRecompile,
148936
- useBuildCaches: options.useBuildCaches,
148937
- sourceTextByUri: new Map(
148938
- sourceEntries.map((entry) => [entry.relPath, entry.source])
148939
- )
148940
- })
148941
- );
149408
+ const reconciliation = reconcileMaterializedInitializersV4({
149409
+ workspace,
149410
+ changes,
149411
+ authoredValueSeeds,
149412
+ reconciliations: valueLowerRegistry.initializerReconciliations,
149413
+ canonicalConstructions: valueLowerRegistry.materializedConstructorExpressions,
149414
+ localizedTextDependencies,
149415
+ manifest,
149416
+ analysis: projectAnalysisV4,
149417
+ forceRecompile: options.forceRecompile,
149418
+ useBuildCaches: options.useBuildCaches,
149419
+ sourceTextByUri: new Map(
149420
+ sourceEntries.map((entry) => [entry.relPath, entry.source])
149421
+ )
149422
+ });
149423
+ parseErrors.push(...reconciliation.failures);
149424
+ applyConstructionRebuildsV4({
149425
+ workspace,
149426
+ reconstructed: reconstructed3,
149427
+ changes,
149428
+ rebuilds: reconciliation.rebuilds
149429
+ });
148942
149430
  } catch (error) {
148943
149431
  parseErrors.push(
148944
149432
  error instanceof SchemaSourceError ? error : new SchemaSourceError(
@@ -149415,6 +149903,58 @@ function expandProspectiveAnimationInstances(document) {
149415
149903
  }
149416
149904
  return [...byId.values()];
149417
149905
  }
149906
+ function applyConstructionRebuildsV4(args) {
149907
+ if (args.rebuilds.length === 0) return;
149908
+ const replanned = /* @__PURE__ */ new Set();
149909
+ for (const rebuild of args.rebuilds) {
149910
+ for (const id2 of rebuild.ownedValueIds) {
149911
+ if (id2 === rebuild.valueId) continue;
149912
+ const key = recordStateKey("value", id2);
149913
+ replanned.add(key);
149914
+ const base = args.workspace.state.records[key];
149915
+ if (base === void 0) {
149916
+ args.reconstructed.delete(key);
149917
+ continue;
149918
+ }
149919
+ const reconstructed3 = args.reconstructed.get(key);
149920
+ if (reconstructed3 === void 0) continue;
149921
+ if (!isObjectRecord2(base.data)) {
149922
+ throw new Error(
149923
+ `Cannot replan value "${id2}" for a rebuilt construction: its pulled row is not an object.`
149924
+ );
149925
+ }
149926
+ args.reconstructed.set(key, { ...reconstructed3, fullData: base.data });
149927
+ }
149928
+ }
149929
+ const output = /* @__PURE__ */ new Map();
149930
+ for (const change of args.changes) {
149931
+ const key = recordStateKey(change.recordKind, change.recordId);
149932
+ if (!replanned.has(key)) output.set(key, change);
149933
+ }
149934
+ for (const rebuild of args.rebuilds) {
149935
+ const key = recordStateKey("value", rebuild.valueId);
149936
+ const base = args.workspace.state.records[key];
149937
+ if (base === void 0) {
149938
+ throw new Error(
149939
+ `Cannot rebuild construction for value "${rebuild.valueId}": it has no pulled row.`
149940
+ );
149941
+ }
149942
+ const reconstructed3 = args.reconstructed.get(key);
149943
+ if (reconstructed3 !== void 0)
149944
+ args.reconstructed.set(key, { ...reconstructed3, fullData: rebuild.row });
149945
+ output.set(
149946
+ key,
149947
+ recordUpsertChange({
149948
+ base,
149949
+ recordKind: "value",
149950
+ recordId: rebuild.valueId,
149951
+ file: reconstructed3?.file ?? output.get(key)?.file ?? null,
149952
+ nextData: rebuild.row
149953
+ })
149954
+ );
149955
+ }
149956
+ args.changes.splice(0, args.changes.length, ...output.values());
149957
+ }
149418
149958
  function collapseLocalizedSourceRevertsV4(args) {
149419
149959
  const edited = args.changes.filter(
149420
149960
  (change) => change.recordKind === "value" && change.kind !== "delete" && isMemberValue(change.nextData) && typeof change.nextData.value === "string" && args.loweringRecords[recordStateKey("localized-text", change.nextData.value)] === void 0 && !recordsSemanticallyEqual(
@@ -171787,7 +172327,7 @@ function classExtendsClass(ctx, classId, ancestorClassId) {
171787
172327
  function generateClassBackedWorldMembers(ctx, classDef, className) {
171788
172328
  if (isAbstractClass(classDef)) return [];
171789
172329
  const worldKind = ctx.worldKinds.get(classDef.id) ?? null;
171790
- if (worldKind === NeoWorldSystemClassKind.Tile || worldKind === NeoWorldSystemClassKind.Object) {
172330
+ if (worldKind === NeoWorldSystemClassKind.Tile || descendsFromWorldObject(ctx, classDef.id)) {
171791
172331
  return [
171792
172332
  `public static NeoClassRef<${className}> Definition { get; } = new NeoClassRef<${className}>("${escapeCSharpString(classDef.id)}");`
171793
172333
  ];
@@ -173537,9 +174077,10 @@ function objectSpawnHookClassMembers(classDef) {
173537
174077
  "",
173538
174078
  "/// <summary>",
173539
174079
  "/// Renderer spawn hook \u2014 override in a partial class to attach Unity",
173540
- "/// components (e.g. Rigidbody2D) to the instance's fully-built root",
173541
- `/// GameObject. See <see cref="${OBJECT_SPAWN_HOOKS_INTERFACE}"/> for timing and`,
173542
- "/// respawn semantics.",
174080
+ "/// components (e.g. Rigidbody2D) to this object's GameObject. Runs on",
174081
+ "/// the placed root and every object in its composition, parents first;",
174082
+ "/// check behaviour.IsRoot for the placed instance. See",
174083
+ `/// <see cref="${OBJECT_SPAWN_HOOKS_INTERFACE}"/> for timing and respawn semantics.`,
173543
174084
  "/// </summary>",
173544
174085
  "protected virtual void OnObjectSpawned(NeoObjectBehaviour behaviour)",
173545
174086
  "{",
@@ -173547,8 +174088,8 @@ function objectSpawnHookClassMembers(classDef) {
173547
174088
  "",
173548
174089
  "/// <summary>",
173549
174090
  "/// Renderer despawn hook \u2014 override in a partial class to release",
173550
- "/// per-GameObject state before the instance's root GameObject is",
173551
- "/// destroyed.",
174091
+ "/// per-GameObject state before this object's GameObject is destroyed.",
174092
+ "/// Children despawn before their parents.",
173552
174093
  "/// </summary>",
173553
174094
  "protected virtual void OnObjectDespawned(NeoObjectBehaviour behaviour)",
173554
174095
  "{",
@@ -181263,7 +181804,7 @@ var UNITY_CODEGEN_REVISION;
181263
181804
  var init_unity_codegen_revision = __esm({
181264
181805
  "../src/models/exports/unity-codegen-revision.ts"() {
181265
181806
  "use strict";
181266
- UNITY_CODEGEN_REVISION = "edfd4061dffcd1a747b234cd135b99beca6f4cf1958cb69715029c5935dd7f1b";
181807
+ UNITY_CODEGEN_REVISION = "d4026a3848848c8507d45dd54b6d31c1a0588b17b64c35e3fe9b25c89eb2fc05";
181267
181808
  }
181268
181809
  });
181269
181810
 
@@ -185153,7 +185694,9 @@ function rewrittenSeedProvenance(memberId, seed) {
185153
185694
  for (const field of [
185154
185695
  "instanceConstructorId",
185155
185696
  "instanceVariantId",
185156
- "instanceVariantRowValueId"
185697
+ "instanceVariantRowValueId",
185698
+ "instanceAppliedVariantId",
185699
+ "instanceAppliedVariantRowValueId"
185157
185700
  ]) {
185158
185701
  const candidate = seed[field];
185159
185702
  if (candidate !== void 0 && candidate !== null && typeof candidate !== "string") {
@@ -185170,6 +185713,12 @@ function rewrittenSeedProvenance(memberId, seed) {
185170
185713
  ...seed.instanceVariantId === void 0 ? {} : { instanceVariantId: seed.instanceVariantId },
185171
185714
  ...seed.instanceVariantRowValueId === void 0 ? {} : {
185172
185715
  instanceVariantRowValueId: seed.instanceVariantRowValueId
185716
+ },
185717
+ ...seed.instanceAppliedVariantId === void 0 ? {} : {
185718
+ instanceAppliedVariantId: seed.instanceAppliedVariantId
185719
+ },
185720
+ ...seed.instanceAppliedVariantRowValueId === void 0 ? {} : {
185721
+ instanceAppliedVariantRowValueId: seed.instanceAppliedVariantRowValueId
185173
185722
  }
185174
185723
  };
185175
185724
  }
@@ -201083,7 +201632,7 @@ There is no --keep-current: preserving current semantic state defines flatten.
201083
201632
  async function main() {
201084
201633
  const args = parseArgs(process.argv.slice(2));
201085
201634
  if (args.command === "--version") {
201086
- console.log("0.80.0");
201635
+ console.log("0.81.1");
201087
201636
  return;
201088
201637
  }
201089
201638
  if (args.command === null || args.command === "help" || args.command === "--help" || args.command === "-h") {