@neocompose/cli 0.81.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
@@ -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
  )) {
@@ -12119,12 +12139,8 @@ function evaluateLiteralContainer(args) {
12119
12139
  const literal3 = {
12120
12140
  value: evaluated.value,
12121
12141
  classId: evaluated.classId,
12122
- ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) },
12123
- ...evaluated.instanceConstructorId === void 0 ? {} : { instanceConstructorId: evaluated.instanceConstructorId },
12124
- ...evaluated.instanceVariantId === void 0 ? {} : { instanceVariantId: evaluated.instanceVariantId },
12125
- ...evaluated.instanceVariantRowValueId === void 0 ? {} : {
12126
- instanceVariantRowValueId: evaluated.instanceVariantRowValueId
12127
- }
12142
+ ...pickInstanceProvenance(evaluated),
12143
+ ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) }
12128
12144
  };
12129
12145
  if (isMemberLookupBase(args.member)) {
12130
12146
  if (evaluated.existingValueRow !== void 0) {
@@ -12457,15 +12473,9 @@ function buildNewValue(projectId, body, timestamp2 = Date.now()) {
12457
12473
  if (body.constructorArgs !== void 0 && body.constructorArgs !== null) {
12458
12474
  props.constructorArgs = deepClonePlainData(body.constructorArgs);
12459
12475
  }
12460
- if (body.instanceConstructorId !== void 0) {
12461
- props.instanceConstructorId = body.instanceConstructorId;
12462
- }
12463
- if (body.instanceVariantId !== void 0) {
12464
- props.instanceVariantId = body.instanceVariantId;
12465
- }
12466
- if (body.instanceVariantRowValueId !== void 0) {
12467
- props.instanceVariantRowValueId = body.instanceVariantRowValueId;
12468
- }
12476
+ const { constructorArgs: _constructorArgs, ...provenance } = pickInstanceProvenance(body);
12477
+ void _constructorArgs;
12478
+ Object.assign(props, provenance);
12469
12479
  return props;
12470
12480
  }
12471
12481
  function retargetInitializerRootValueIds(rows, fromValueId, toValueId) {
@@ -12657,7 +12667,7 @@ function cloneDefaultDictionaryRecord(args) {
12657
12667
  args.document,
12658
12668
  args.member.entryMemberId
12659
12669
  );
12660
- const value = {};
12670
+ const value = /* @__PURE__ */ Object.create(null);
12661
12671
  for (const [key, sourceValueId] of Object.entries(sourceValue)) {
12662
12672
  value[key] = cloneDefaultValueForMember({
12663
12673
  document: args.document,
@@ -12934,9 +12944,7 @@ function cloneMemberValueBase(body) {
12934
12944
  return {
12935
12945
  value: deepClonePlainData(body.value),
12936
12946
  classId: body.classId,
12937
- ...body.instanceConstructorId === void 0 ? {} : { instanceConstructorId: body.instanceConstructorId },
12938
- ...body.instanceVariantId === void 0 ? {} : { instanceVariantId: body.instanceVariantId },
12939
- ...body.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: body.instanceVariantRowValueId },
12947
+ ...pickInstanceProvenance({ ...body, constructorArgs: void 0 }),
12940
12948
  ...body.constructorArgs === void 0 || body.constructorArgs === null ? {} : {
12941
12949
  constructorArgs: deepClonePlainData(body.constructorArgs)
12942
12950
  }
@@ -13246,6 +13254,7 @@ var init_build_default_member_value = __esm({
13246
13254
  "../packages/models/src/members/build-default-member-value.ts"() {
13247
13255
  "use strict";
13248
13256
  init_member_value_id();
13257
+ init_instance_provenance();
13249
13258
  init_member_change_listeners();
13250
13259
  init_construction_requirements();
13251
13260
  init_deep_clone_plain_data();
@@ -24236,7 +24245,7 @@ function toCanonical(value) {
24236
24245
  if (Array.isArray(value)) return value.map((item) => toCanonical(item));
24237
24246
  if (typeof value === "object") {
24238
24247
  const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
24239
- const result = {};
24248
+ const result = /* @__PURE__ */ Object.create(null);
24240
24249
  for (const [key, entryValue] of entries) {
24241
24250
  result[key] = toCanonical(entryValue);
24242
24251
  }
@@ -35693,7 +35702,7 @@ var init_strict_resolver = __esm({
35693
35702
  };
35694
35703
  }
35695
35704
  resolveDictionaryKey(expectedKey, keyAst, scope, pos, requireNonOptional, dictionaryLiteral = false) {
35696
- const key = this.resolveExpression(keyAst, scope);
35705
+ const key = this.resolveExpression(keyAst, scope, expectedKey);
35697
35706
  if (requireNonOptional && isNullable(key.type)) {
35698
35707
  throw new CompileError(
35699
35708
  `Dictionary keys must be non-optional; got ${this.describe(key.type)}`,
@@ -54524,7 +54533,7 @@ var init_registry = __esm({
54524
54533
  "../packages/manifest/schema-contract/registry.mjs"() {
54525
54534
  "use strict";
54526
54535
  PROJECT_SCHEMA_CONTRACT = Object.freeze({
54527
- cliVersion: "0.81.0",
54536
+ cliVersion: "0.81.1",
54528
54537
  projectFileUploadBatchSize: 32,
54529
54538
  documentRecords: {
54530
54539
  member: {
@@ -65746,7 +65755,7 @@ function toCanonicalJsonValue(value) {
65746
65755
  });
65747
65756
  }
65748
65757
  const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
65749
- const canonicalObject = {};
65758
+ const canonicalObject = /* @__PURE__ */ Object.create(null);
65750
65759
  for (const [key, entryValue] of entries) {
65751
65760
  const canonicalValue = toCanonicalJsonValue(entryValue);
65752
65761
  if (canonicalValue === void 0) continue;
@@ -75948,6 +75957,7 @@ function makeUnindexedEvaluatorLookups(members, storedValues) {
75948
75957
  hasStoredValueId: (id2) => valueById.has(id2),
75949
75958
  unorderedListEntryIds: (containerValueId) => unorderedListMembership.get(containerValueId) ?? [],
75950
75959
  virtualInstanceRowsForValue: () => [],
75960
+ virtualInstanceRootIdForValue: () => null,
75951
75961
  rowForValueReference: (value) => valueRefMap.get(value) ?? null
75952
75962
  };
75953
75963
  }
@@ -76000,6 +76010,7 @@ function createInitializerBatchLookups(document) {
76000
76010
  },
76001
76011
  rowForValueReference: (value) => build.result.rowByValueReference.get(value) ?? null,
76002
76012
  virtualInstanceRowsForValue: () => [],
76013
+ virtualInstanceRootIdForValue: () => null,
76003
76014
  evaluatorIndexes: { ...build.result },
76004
76015
  constructorInitializerIndexes: constructorInitializerIndexes2
76005
76016
  });
@@ -76201,6 +76212,7 @@ function createEvaluatorLookupsBuild(members, storedValues, options = {}) {
76201
76212
  hasStoredValueId: (id2) => valueById.has(id2),
76202
76213
  unorderedListEntryIds: (containerValueId) => unorderedListMembership.get(containerValueId) ?? [],
76203
76214
  virtualInstanceRowsForValue: () => [],
76215
+ virtualInstanceRootIdForValue: () => null,
76204
76216
  rowForValueReference: (value) => rowByValueReference.get(value) ?? null,
76205
76217
  evaluatorIndexes: indexes3.result,
76206
76218
  ...options.constructorInitializerDocument === void 0 ? {} : {
@@ -76318,6 +76330,7 @@ function layerEvaluatorLookups(base, overlay) {
76318
76330
  hasStoredValueId: (id2) => overlay.rows.has(id2) || !overlay.hiddenIds.has(id2) && (base.hasStoredValueId?.(id2) ?? false),
76319
76331
  unorderedListEntryIds: unorderedListEntryIds2,
76320
76332
  virtualInstanceRowsForValue: () => [],
76333
+ virtualInstanceRootIdForValue: () => null,
76321
76334
  rowForValueReference: (value) => evaluatorIndexes2.rowByValueReference.get(value) ?? null,
76322
76335
  evaluatorIndexes: evaluatorIndexes2,
76323
76336
  constructorInitializerIndexes: constructorInitializerIndexes2
@@ -76723,13 +76736,15 @@ function bindThisValue(ctx, thisValue) {
76723
76736
  function observeValueWrite(ctx, row) {
76724
76737
  ctx.beforeValueWrite?.(row);
76725
76738
  ctx.__getterSubscriptions?.noteValueWrite(row.id);
76739
+ forgetVariantResolutionCopy(ctx, row.id);
76726
76740
  }
76727
76741
  function assertStoredReplayMutableValue(value, ctx, label, key) {
76728
- const observesWrites = ctx.beforeValueWrite !== void 0 || ctx.__getterSubscriptions?.empty === false;
76742
+ const observesWrites = ctx.beforeValueWrite !== void 0 || ctx.__getterSubscriptions?.empty === false || hasVariantResolutionCopies(ctx);
76729
76743
  if (ctx.storedConstructionReplay !== true && !ctx.assertValueWritable && !observesWrites)
76730
76744
  return;
76731
76745
  let rowId = findKnownRowIdByValueReference(value, ctx);
76732
76746
  if (rowId === null) return;
76747
+ forgetVariantResolutionCopy(ctx, rowId);
76733
76748
  const container = ctx.beforeValueWrite && evalValueById(ctx, rowId, ctx.__runtimeSessionValues, ctx.__valueOverlay);
76734
76749
  if (container) ctx.beforeValueWrite?.(container);
76735
76750
  if (key !== void 0 && value !== null && typeof value === "object") {
@@ -85493,12 +85508,7 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
85493
85508
  deleteRuntimeSessionValue(ctx, rootRow.id);
85494
85509
  ctx.__executionState?.constructorGroups.delete(rootRow.id);
85495
85510
  const constructorArgs2 = typeof result.value === "object" && result.value !== null ? ctx.__constructedArgumentsByValue.get(result.value) ?? rootRow.constructorArgs ?? void 0 : void 0;
85496
- const provenance = pickInstanceProvenance({
85497
- constructorArgs: constructorArgs2,
85498
- instanceConstructorId: rootRow.instanceConstructorId,
85499
- instanceVariantId: rootRow.instanceVariantId,
85500
- instanceVariantRowValueId: rootRow.instanceVariantRowValueId
85501
- });
85511
+ const provenance = pickInstanceProvenance({ ...rootRow, constructorArgs: constructorArgs2 });
85502
85512
  return {
85503
85513
  value: result.value,
85504
85514
  classId: rootRow.classId ?? null,
@@ -86363,7 +86373,7 @@ function evalVariantInitialize(info, scope, ctx) {
86363
86373
  scope,
86364
86374
  ctx
86365
86375
  );
86366
- stampInstanceVariantProvenance(instance, selection2, ctx, true);
86376
+ stampInstanceVariantProvenance(instance, selection2, ctx);
86367
86377
  return instance;
86368
86378
  }
86369
86379
  const graph = resolveVariantGraph(selection2, ctx);
@@ -86394,12 +86404,16 @@ function evalVariantInitialize(info, scope, ctx) {
86394
86404
  ctx,
86395
86405
  ctx.__variantDeclarativeAnsweredValueIds
86396
86406
  );
86397
- stampInstanceVariantProvenance(instance, selection2, ctx, true);
86407
+ stampInstanceVariantProvenance(instance, selection2, ctx);
86398
86408
  return instance;
86399
86409
  } finally {
86400
86410
  closeFrame();
86401
86411
  }
86402
86412
  }
86413
+ function isInsideAnotherExpansion(valueId, ctx) {
86414
+ const ownerRootId = ctx.vm.databaseVM?.virtualInstanceRootIdForValue(valueId) ?? null;
86415
+ return ownerRootId !== null && ownerRootId !== valueId;
86416
+ }
86403
86417
  function evalVariantApply(info, scope, ctx) {
86404
86418
  const receiver = evalPointer(info.receiverPointer, scope, ctx);
86405
86419
  if (receiver === null || receiver === void 0) {
@@ -86411,12 +86425,12 @@ function evalVariantApply(info, scope, ctx) {
86411
86425
  evalPointer(info.variantPointer, scope, ctx),
86412
86426
  "ToVariant argument"
86413
86427
  );
86414
- if (selection2.variantId === null) {
86415
- 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);
86416
86431
  return receiver;
86417
86432
  }
86418
- const graph = resolveVariantGraph(selection2, ctx);
86419
- const rowParameters = resolveVariantRowParameter({
86433
+ const rowParameters = graph === null ? [] : resolveVariantRowParameter({
86420
86434
  graph,
86421
86435
  selection: selection2,
86422
86436
  explicitPointer: info.rowPointer,
@@ -86425,13 +86439,18 @@ function evalVariantApply(info, scope, ctx) {
86425
86439
  });
86426
86440
  const rootRow = trackedRowForValueReference(receiver, ctx);
86427
86441
  if (rootRow === null || !isLiteralValueContent(rootRow)) {
86442
+ if (graph === null) return receiver;
86428
86443
  throw new NSGetterRuntimeError(
86429
86444
  "ToVariant receiver has no addressable instance root."
86430
86445
  );
86431
86446
  }
86432
- const priorInstanceRoot = ctx.__runtimeSessionValues?.has(rootRow.id) === true ? null : deepClonePlainData(rootRow);
86433
- const applyValue = graph.root.Apply;
86434
- 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) {
86435
86454
  invokeVariantClosure({
86436
86455
  closureValueId: applyValue,
86437
86456
  ctx,
@@ -86441,17 +86460,12 @@ function evalVariantApply(info, scope, ctx) {
86441
86460
  });
86442
86461
  }
86443
86462
  if (priorInstanceRoot === null) {
86444
- stampInstanceVariantProvenance(receiver, selection2, ctx);
86445
- applyVariantDeclarativeHalves(receiver, graph, ctx);
86463
+ if (graph !== null) applyVariantDeclarativeHalves(receiver, graph, ctx);
86446
86464
  return receiver;
86447
86465
  }
86448
86466
  priorInstanceRoot.value = deepClonePlainData(rootRow.value);
86449
- const answeredSlots = collectVariantDeclarativeAnsweredSlots(
86450
- receiver,
86451
- graph,
86452
- ctx
86453
- );
86454
- stampInstanceVariantProvenance(receiver, selection2, ctx);
86467
+ const answeredSlots = graph === null ? [] : collectVariantDeclarativeAnsweredSlots(receiver, graph, ctx);
86468
+ stampAppliedVariantProvenance(rootRow, receiver, selection2, ctx);
86455
86469
  const resolver = ctx.vm.databaseVM?.resolveVariantInstanceGraph;
86456
86470
  if (resolver === void 0) {
86457
86471
  if (answeredSlots.length > 0) {
@@ -86460,26 +86474,41 @@ function evalVariantApply(info, scope, ctx) {
86460
86474
  );
86461
86475
  }
86462
86476
  } else {
86477
+ const overlay = ctx.__valueOverlay;
86478
+ const copies = overlay === void 0 ? void 0 : variantResolutionCopies(overlay);
86463
86479
  const resolution = resolver.call(ctx.vm.databaseVM, {
86464
86480
  priorInstanceRoot,
86465
86481
  nextInstanceRoot: deepClonePlainData(rootRow),
86466
86482
  answeredValueIds: [...new Set(answeredSlots.map((slot) => slot.valueId))],
86467
86483
  localRows: [
86468
86484
  ...ctx.__runtimeSessionValues?.values() ?? [],
86469
- ...ctx.__valueOverlay?.values() ?? []
86470
- ]
86485
+ ...overlay?.values() ?? []
86486
+ ],
86487
+ virtualCopyIds: unwrittenVariantResolutionCopyIds(
86488
+ overlay,
86489
+ copies?.byRootId.get(rootRow.id)
86490
+ )
86471
86491
  });
86472
86492
  for (const valueId of resolution.clearedValueIds) {
86473
86493
  const previous = readNeoScriptRuntimeRow(ctx, valueId);
86474
86494
  if (previous) observeValueWrite(ctx, previous);
86475
86495
  deleteRuntimeSessionValue(ctx, valueId);
86476
- ctx.__valueOverlay?.delete(valueId);
86496
+ overlay?.delete(valueId);
86477
86497
  }
86498
+ for (const valueId of copies?.byRootId.get(rootRow.id)?.keys() ?? []) {
86499
+ forgetVariantResolutionCopy(ctx, valueId);
86500
+ }
86501
+ const virtualValueIds = new Set(resolution.virtualValueIds);
86478
86502
  for (const row of resolution.rows) {
86479
86503
  if (row.id === rootRow.id) continue;
86480
86504
  const previous = readNeoScriptRuntimeRow(ctx, row.id);
86481
86505
  if (previous) observeValueWrite(ctx, previous);
86482
- 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
+ }
86483
86512
  }
86484
86513
  if (typeof receiver !== "object" || receiver === null || Array.isArray(receiver) || typeof resolution.root.value !== "object" || resolution.root.value === null || Array.isArray(resolution.root.value)) {
86485
86514
  throw new NSGetterRuntimeError(
@@ -86493,14 +86522,69 @@ function evalVariantApply(info, scope, ctx) {
86493
86522
  }
86494
86523
  return receiver;
86495
86524
  }
86496
- 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) {
86497
86566
  const row = trackedRowForValueReference(instance, ctx);
86498
86567
  if (row === null || !isLiteralValueContent(row)) return;
86499
- if (preserveLookupRow && row.id === selection2.rowValueId) return;
86568
+ if (row.id === selection2.rowValueId) return;
86500
86569
  assertStoredReplayMutableValue(instance, ctx, "variant provenance");
86501
86570
  row.instanceVariantId = selection2.variantId;
86502
86571
  row.instanceVariantRowValueId = selection2.rowValueId;
86503
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
+ }
86504
86588
  function constructDeclaredClassValue(info, scope, ctx) {
86505
86589
  const descriptor = validateClassConstructorDescriptor(info, ctx, false);
86506
86590
  const schemaClass2 = descriptor.schemaClass;
@@ -86583,6 +86667,7 @@ function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope
86583
86667
  );
86584
86668
  }
86585
86669
  const rootRecord = root.value;
86670
+ recordConstructedFieldSchemaKeys(ctx, rootRecord, descriptor);
86586
86671
  if (record7 !== null) {
86587
86672
  const encoded = {};
86588
86673
  for (let index = 0; index < argumentValues.length; index += 1) {
@@ -86623,7 +86708,6 @@ function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope
86623
86708
  }
86624
86709
  const argumentsByValue = ctx.__constructedArgumentsByValue ?? (ctx.__constructedArgumentsByValue = /* @__PURE__ */ new WeakMap());
86625
86710
  argumentsByValue.set(rootRecord, encoded);
86626
- recordConstructedFieldSchemaKeys(ctx, rootRecord, descriptor);
86627
86711
  root.constructorArgs = deepClonePlainData(encoded);
86628
86712
  root.instanceConstructorId = record7.id;
86629
86713
  } else {
@@ -87016,7 +87100,7 @@ function cloneConstructorArgumentGraph(args) {
87016
87100
  member.classArguments,
87017
87101
  args.ctx.vm.classes
87018
87102
  );
87019
- const record7 = {};
87103
+ const record7 = /* @__PURE__ */ Object.create(null);
87020
87104
  clone.value = record7;
87021
87105
  const sourceRecord = {
87022
87106
  ...virtualExpandedRecordForReceiver(source.value, args.ctx),
@@ -87060,7 +87144,7 @@ function cloneConstructorArgumentGraph(args) {
87060
87144
  `Constructor import references missing Dictionary entry member '${member.entryMemberId}'.`
87061
87145
  );
87062
87146
  }
87063
- const record7 = {};
87147
+ const record7 = /* @__PURE__ */ Object.create(null);
87064
87148
  clone.value = record7;
87065
87149
  const entryEnv = envFromStamp(clone.genericBindings);
87066
87150
  for (const [key, childId] of Object.entries(source.value)) {
@@ -87303,7 +87387,7 @@ function materializeConstructorArgumentValue(args) {
87303
87387
  args.ctx.vm.members
87304
87388
  );
87305
87389
  const row = registerConstructorArgumentRow(args, {});
87306
- const record7 = {};
87390
+ const record7 = /* @__PURE__ */ Object.create(null);
87307
87391
  for (const [key, rawEntry] of Object.entries(args.value)) {
87308
87392
  const entry = constructorCollectionEntryValue(
87309
87393
  rawEntry,
@@ -87978,7 +88062,7 @@ function collectionEntryUsesReferenceResolution(collection, key, ctx) {
87978
88062
  );
87979
88063
  return referenceIndexes === void 0 || referenceIndexes.has(key);
87980
88064
  }
87981
- 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;
87982
88066
  var init_evaluateNSGetter = __esm({
87983
88067
  "../packages/neoscript-runtime/src/neoscript/evaluateNSGetter.ts"() {
87984
88068
  "use strict";
@@ -88188,6 +88272,7 @@ var init_evaluateNSGetter = __esm({
88188
88272
  };
88189
88273
  DOUBLE_INTEGRAL_MAGNITUDE = 2 ** 53;
88190
88274
  EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS = [];
88275
+ variantResolutionCopiesByOverlay = /* @__PURE__ */ new WeakMap();
88191
88276
  }
88192
88277
  });
88193
88278
 
@@ -89880,6 +89965,8 @@ function expandStoredInstance(args) {
89880
89965
  instanceConstructorId: _instanceConstructorId,
89881
89966
  instanceVariantId: _instanceVariantId,
89882
89967
  instanceVariantRowValueId: _instanceVariantRowValueId,
89968
+ instanceAppliedVariantId: _instanceAppliedVariantId,
89969
+ instanceAppliedVariantRowValueId: _instanceAppliedVariantRowValueId,
89883
89970
  ...envelope
89884
89971
  } = instanceRoot;
89885
89972
  void _value;
@@ -89888,6 +89975,8 @@ function expandStoredInstance(args) {
89888
89975
  void _instanceConstructorId;
89889
89976
  void _instanceVariantId;
89890
89977
  void _instanceVariantRowValueId;
89978
+ void _instanceAppliedVariantId;
89979
+ void _instanceAppliedVariantRowValueId;
89891
89980
  const closedRootMember = closeClassArgumentsFromRowStamp(
89892
89981
  rootMember,
89893
89982
  instanceRoot
@@ -89969,11 +90058,26 @@ function expandStoredInstance(args) {
89969
90058
  }
89970
90059
  };
89971
90060
  };
89972
- const materialized = derivesContentFromMemberDefault({
90061
+ const constructed = derivesContentFromMemberDefault({
89973
90062
  member: replayMember,
89974
90063
  instanceRoot,
89975
90064
  effectiveClassId: classId
89976
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
+ );
89977
90081
  const rows = [materialized.root, ...materialized.createdValues];
89978
90082
  assertVirtualExpansionIsLiteral(rows);
89979
90083
  return {
@@ -89982,6 +90086,80 @@ function expandStoredInstance(args) {
89982
90086
  pinnedRootSchemaKeys: /* @__PURE__ */ new Set()
89983
90087
  };
89984
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
+ }
89985
90163
  function resolveVirtualInstanceGraph(args) {
89986
90164
  const expansion = args.expansionIndex ?? indexExpansion(args);
89987
90165
  const recorder = args.readRecorder ?? null;
@@ -90955,6 +91133,11 @@ function expandStoredClassValue(args) {
90955
91133
  pinnedRootSchemaKeys: /* @__PURE__ */ new Set()
90956
91134
  };
90957
91135
  }
91136
+ function owningInstanceRootId(graph) {
91137
+ let owner = graph;
91138
+ while (owner?.containingGraph !== void 0) owner = owner.containingGraph;
91139
+ return owner?.instanceRootId ?? null;
91140
+ }
90958
91141
  function isStoredClassResolutionRoot(value) {
90959
91142
  if (!isLiteralValueContent(value)) return false;
90960
91143
  if (isVirtualInstanceRootShape(value)) return true;
@@ -91268,6 +91451,7 @@ function planCollapseVirtualInstance(args) {
91268
91451
  if (provenance.sameRecipe) return true;
91269
91452
  if (typeof stored.instanceConstructorId === "string") return false;
91270
91453
  if (typeof stored.instanceVariantId === "string") return false;
91454
+ if (typeof stored.instanceAppliedVariantId === "string") return false;
91271
91455
  const storedArgs = stored.constructorArgs;
91272
91456
  if (storedArgs != null && Object.keys(storedArgs).length > 0) return false;
91273
91457
  return !isInitValueContent(child2.member.defaultValue);
@@ -91666,10 +91850,35 @@ function sparsifyConstructedInstance(args) {
91666
91850
  if (typeof entryId === "string")
91667
91851
  protectArgument(entryId, type.entryTypeInfo);
91668
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
+ };
91669
91877
  for (const edge of materializedGraph.constructorEdges(
91670
91878
  args.constructed.root
91671
91879
  )) {
91672
91880
  protectArgument(edge.targetValueId, edge.typeInfo);
91881
+ pinArgumentFields(edge.targetValueId);
91673
91882
  }
91674
91883
  for (const schemaKey of args.pinnedRootSchemaKeys ?? []) {
91675
91884
  const location3 = graph.locationsByPath.get(
@@ -92324,7 +92533,9 @@ function compareContextualCreationProvenance(left, right, context) {
92324
92533
  constructorArgs: literal3.constructorArgs ?? {},
92325
92534
  instanceConstructorId: literal3.instanceConstructorId ?? null,
92326
92535
  instanceVariantId: literal3.instanceVariantId ?? null,
92327
- instanceVariantRowValueId: literal3.instanceVariantRowValueId ?? null
92536
+ instanceVariantRowValueId: literal3.instanceVariantRowValueId ?? null,
92537
+ instanceAppliedVariantId: literal3.instanceAppliedVariantId ?? null,
92538
+ instanceAppliedVariantRowValueId: literal3.instanceAppliedVariantRowValueId ?? null
92328
92539
  };
92329
92540
  };
92330
92541
  return {
@@ -92622,40 +92833,37 @@ function resolveVariantInstanceGraphForDocument(args) {
92622
92833
  rootMember,
92623
92834
  readRecorder: args.readRecorder
92624
92835
  });
92625
- const priorGraph = resolveVirtualInstanceGraph({
92836
+ let priorInstanceRoot = args.priorInstanceRoot;
92837
+ let nextInstanceRoot = args.nextInstanceRoot;
92838
+ const resolvePriorGraph = () => resolveVirtualInstanceGraph({
92626
92839
  document,
92627
- instanceRoot: args.priorInstanceRoot,
92840
+ instanceRoot: priorInstanceRoot,
92628
92841
  rootMember,
92629
92842
  expandedRoot: priorExpanded.root,
92630
92843
  expandedRows: priorExpanded.rows,
92631
92844
  materializedRows: [...materializedById.values()],
92632
92845
  readRecorder: args.readRecorder
92633
92846
  });
92634
- const priorAnsweredIds = [];
92635
- const incomingAnsweredIds = [];
92636
- for (const valueId of args.answeredValueIds) {
92637
- const bucket = priorGraph.locationsById.has(valueId) ? priorAnsweredIds : incomingAnsweredIds;
92638
- bucket.push(valueId);
92639
- }
92640
92847
  const clearedValueIds = /* @__PURE__ */ new Set();
92641
- let nextInstanceRoot = args.nextInstanceRoot;
92642
- const resetAnsweredValues = (graph, valueIds) => {
92643
- if (valueIds.length === 0) return;
92644
- const reset = planVirtualOverrideResets({ graph, valueIds });
92848
+ const applyReset = (graph, reset) => {
92645
92849
  for (const valueId of reset.deletes) {
92646
92850
  clearedValueIds.add(valueId);
92647
92851
  materializedById.delete(valueId);
92648
92852
  }
92649
92853
  for (const update of reset.updates) {
92650
92854
  if (update.valueId === nextInstanceRoot.id) {
92651
- const nextRecord = { ...stringRecord2(nextInstanceRoot.value) };
92652
92855
  const resetRecord = stringRecord2(update.value);
92653
92856
  const priorRecord = stringRecord2(graph.root.materializedRow?.value);
92654
- for (const schemaKey of Object.keys(priorRecord)) {
92655
- if (!Object.hasOwn(resetRecord, schemaKey))
92656
- delete nextRecord[schemaKey];
92657
- }
92658
- 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));
92659
92867
  }
92660
92868
  const existing = materializedById.get(update.valueId);
92661
92869
  if (existing !== void 0) {
@@ -92667,6 +92875,28 @@ function resolveVariantInstanceGraphForDocument(args) {
92667
92875
  }
92668
92876
  materializedById.set(nextInstanceRoot.id, nextInstanceRoot);
92669
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
+ };
92670
92900
  resetAnsweredValues(priorGraph, priorAnsweredIds);
92671
92901
  materializedById.set(nextInstanceRoot.id, nextInstanceRoot);
92672
92902
  const nextExpanded = expandStoredInstance({
@@ -92710,10 +92940,15 @@ function resolveVariantInstanceGraphForDocument(args) {
92710
92940
  `ToVariant failed to resolve instance root '${args.nextInstanceRoot.id}'.`
92711
92941
  );
92712
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
+ }
92713
92947
  return {
92714
92948
  root,
92715
92949
  rows: [...nextGraph.rowsById.values()],
92716
- clearedValueIds: [...clearedValueIds]
92950
+ clearedValueIds: [...clearedValueIds],
92951
+ virtualValueIds: [...virtualValueIds]
92717
92952
  };
92718
92953
  }
92719
92954
  function variantSwapDeclaredMember(document, rootValueId) {
@@ -93040,6 +93275,7 @@ var KEPT_ROW_SAMPLE_LIMIT, VirtualExpansionUnsupportedError, ROOT_PATH, OpenGene
93040
93275
  var init_virtual_instance_graph = __esm({
93041
93276
  "../packages/neoscript-runtime/src/virtual-instance-graph.ts"() {
93042
93277
  "use strict";
93278
+ init_value_comparison();
93043
93279
  init_listener_endpoint_projection();
93044
93280
  init_overlay_readonly_map();
93045
93281
  init_member_change_listeners();
@@ -93142,6 +93378,7 @@ function initializerEvaluatorLookups(document, readTracking) {
93142
93378
  return resolved;
93143
93379
  },
93144
93380
  virtualInstanceRowsForValue: (receiverValueId) => databaseVM.virtualInstanceRowsForValue(receiverValueId),
93381
+ virtualInstanceRootIdForValue: (valueId) => databaseVM.virtualInstanceRootIdForValue(valueId),
93145
93382
  ...databaseVM.worldGridQueryIndex === void 0 ? {} : { worldGridQueryIndex: () => databaseVM.worldGridQueryIndex() },
93146
93383
  rowForValueReference: (value) => databaseVM.rowForValueReference?.(value) ?? null,
93147
93384
  resolveVariantInstanceGraph: (args) => {
@@ -93197,6 +93434,9 @@ function initializerEvaluatorLookups(document, readTracking) {
93197
93434
  valueById: (id2) => indexedLookups.valueById(id2) ?? headlessVirtualResolver.valueById(id2),
93198
93435
  rowForValueReference: (value) => indexedLookups.rowForValueReference?.(value) ?? headlessVirtualResolver.rowForValueReference(value),
93199
93436
  virtualInstanceRowsForValue: (receiverValueId) => headlessVirtualResolver.virtualInstanceRowsForValue(receiverValueId),
93437
+ virtualInstanceRootIdForValue: (valueId) => owningInstanceRootId(
93438
+ headlessVirtualResolver.virtualInstanceGraphForValue(valueId)
93439
+ ),
93200
93440
  recordVirtualInstanceReads: (reads, read) => headlessVirtualResolver.recordReads(reads, read),
93201
93441
  // Headless hosts still evaluate `ToVariant` during
93202
93442
  // stored-construction replay — production's variant-constructed
@@ -93430,6 +93670,7 @@ function createInitializerMaterializationBatch(authoredDocument, pendingInitiali
93430
93670
  if (entry.global) globalReads.add(entry);
93431
93671
  return entry.rows;
93432
93672
  },
93673
+ virtualInstanceRootIdForValue: (id2) => owningInstanceRootId(virtual().virtualInstanceGraphForValue(id2)),
93433
93674
  resolveVariantInstanceGraph: (args) => resolveVariantInstanceGraphForDocument({
93434
93675
  evaluateInitializer: evaluateMemberInitializer,
93435
93676
  document,
@@ -93513,6 +93754,7 @@ function evaluateMemberInitializer(args) {
93513
93754
  );
93514
93755
  const compiled = compileMemberInitializer(args, databaseVM);
93515
93756
  const ctx = {
93757
+ ...args.sessionValues === void 0 ? {} : { __runtimeSessionValues: args.sessionValues },
93516
93758
  debugSink: args.document.debugSink,
93517
93759
  beforeValueAllocation: args.document.beforeValueAllocation,
93518
93760
  listenerDefaultCapture: args.document.listenerDefaultCapture,
@@ -93583,10 +93825,13 @@ function evaluateMemberInitializer(args) {
93583
93825
  args.argumentValues ?? [],
93584
93826
  {
93585
93827
  exportInitializerValues: true,
93586
- initializerResult: {
93587
- member: args.member,
93588
- genericEnv: args.genericEnv
93589
- }
93828
+ // Seeded rows already hold their placement.
93829
+ ...args.sessionValues === void 0 ? {
93830
+ initializerResult: {
93831
+ member: args.member,
93832
+ genericEnv: args.genericEnv
93833
+ }
93834
+ } : {}
93590
93835
  }
93591
93836
  );
93592
93837
  } catch (error) {
@@ -93609,9 +93854,12 @@ function evaluateMemberInitializer(args) {
93609
93854
  );
93610
93855
  }
93611
93856
  const rootRow = initializerRootRow(result.value, created);
93857
+ const pinnedSchemaKeysByValueId = /* @__PURE__ */ new Map();
93612
93858
  for (const row of created) {
93613
93859
  if (row === rootRow) continue;
93614
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);
93615
93863
  }
93616
93864
  if (rootRow === null) return { value: result.value, classId: null };
93617
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
@@ -93619,17 +93867,13 @@ function evaluateMemberInitializer(args) {
93619
93867
  // origin or the recipe reads as an unrecorded overload.
93620
93868
  rootRow.constructorArgs ?? void 0;
93621
93869
  const pinnedRootSchemaKeys = typeof result.value === "object" && result.value !== null ? ctx.__constructedFieldSchemaKeysByValue?.get(result.value) : void 0;
93622
- const provenance = pickInstanceProvenance({
93623
- constructorArgs: constructorArgs2,
93624
- instanceConstructorId: rootRow.instanceConstructorId,
93625
- instanceVariantId: rootRow.instanceVariantId,
93626
- instanceVariantRowValueId: rootRow.instanceVariantRowValueId
93627
- });
93870
+ const provenance = pickInstanceProvenance({ ...rootRow, constructorArgs: constructorArgs2 });
93628
93871
  return {
93629
93872
  value: result.value,
93630
93873
  classId: rootRow.classId ?? null,
93631
93874
  ...rootRow.genericBindings === void 0 ? {} : { genericBindings: { ...rootRow.genericBindings } },
93632
93875
  ...pinnedRootSchemaKeys === void 0 ? {} : { pinnedRootSchemaKeys },
93876
+ ...pinnedSchemaKeysByValueId.size === 0 ? {} : { pinnedSchemaKeysByValueId },
93633
93877
  provisionalRootId: rootRow.id,
93634
93878
  ...provenance,
93635
93879
  ...provenance.constructorArgs === void 0 ? {} : {
@@ -93835,12 +94079,7 @@ function materializeInitializerValue(args) {
93835
94079
  value: evaluated.value,
93836
94080
  ...evaluated.classId === null ? {} : { classId: evaluated.classId },
93837
94081
  ...evaluated.genericBindings === void 0 ? {} : { genericBindings: { ...evaluated.genericBindings } },
93838
- ...evaluated.constructorArgs === void 0 ? {} : { constructorArgs: deepClonePlainData(evaluated.constructorArgs) },
93839
- ...evaluated.instanceConstructorId === void 0 ? {} : { instanceConstructorId: evaluated.instanceConstructorId },
93840
- ...evaluated.instanceVariantId === void 0 ? {} : { instanceVariantId: evaluated.instanceVariantId },
93841
- ...evaluated.instanceVariantRowValueId === void 0 ? {} : {
93842
- instanceVariantRowValueId: evaluated.instanceVariantRowValueId
93843
- }
94082
+ ...deepClonePlainData(pickInstanceProvenance(evaluated))
93844
94083
  };
93845
94084
  const allCreated = [root, ...createdValues];
93846
94085
  if (evaluated.provisionalRootId !== void 0) {
@@ -93863,7 +94102,8 @@ function materializeInitializerValue(args) {
93863
94102
  return {
93864
94103
  root,
93865
94104
  createdValues,
93866
- pinnedRootSchemaKeys: evaluated.pinnedRootSchemaKeys ?? /* @__PURE__ */ new Set()
94105
+ pinnedRootSchemaKeys: evaluated.pinnedRootSchemaKeys ?? /* @__PURE__ */ new Set(),
94106
+ pinnedSchemaKeysByValueId: evaluated.pinnedSchemaKeysByValueId ?? /* @__PURE__ */ new Map()
93867
94107
  };
93868
94108
  }
93869
94109
  function materializeMemberDefaultValue(args) {
@@ -93980,7 +94220,12 @@ function materializeMemberDefaultValue(args) {
93980
94220
  storageKeyDeclarations,
93981
94221
  supersededRootId: built.id
93982
94222
  });
93983
- 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
+ };
93984
94229
  }
93985
94230
  var declarationInitializerContextByDocument, defaultValuePlansByDocument;
93986
94231
  var init_initializer_materialization = __esm({
@@ -93989,6 +94234,7 @@ var init_initializer_materialization = __esm({
93989
94234
  init_deep_clone_plain_data();
93990
94235
  init_members();
93991
94236
  init_inheritance();
94237
+ init_instance_provenance();
93992
94238
  init_generics();
93993
94239
  init_evaluateInitializer();
93994
94240
  init_evaluateNSGetter();
@@ -110382,7 +110628,7 @@ function toCanonicalJsonValue2(value) {
110382
110628
  if (!isPlainRecord2(value)) {
110383
110629
  throw new Error("Cannot canonicalize a non-plain object.");
110384
110630
  }
110385
- const canonical = {};
110631
+ const canonical = /* @__PURE__ */ Object.create(null);
110386
110632
  const entries = Object.entries(value).sort(
110387
110633
  ([left], [right]) => left.localeCompare(right)
110388
110634
  );
@@ -113765,6 +114011,7 @@ function headlessVirtualInstanceLookups(document, options = {}) {
113765
114011
  valueById: (id2) => indexed.valueById(id2) ?? virtual.valueById(id2),
113766
114012
  rowForValueReference: (value) => indexed.rowForValueReference(value) ?? virtual.rowForValueReference(value),
113767
114013
  virtualInstanceRowsForValue: (receiverValueId) => virtual.virtualInstanceRowsForValue(receiverValueId),
114014
+ virtualInstanceRootIdForValue: (valueId) => owningInstanceRootId(virtual.virtualInstanceGraphForValue(valueId)),
113768
114015
  // Stored-construction replay evaluates `ToVariant`, and production's
113769
114016
  // variant-constructed placements collapse through exactly this path.
113770
114017
  resolveVariantInstanceGraph: (args) => resolveVariantInstanceGraphForDocument2({
@@ -114673,6 +114920,7 @@ function validateWorldPlacementSidecars(args) {
114673
114920
  validatePlacementVariantBinding({
114674
114921
  assetClassId,
114675
114922
  placementId: args.placement.id,
114923
+ layer: "built",
114676
114924
  variantId: optionalNonEmptyString(
114677
114925
  args.isTile || !hasObjectSidecar ? getField(args.placement, "instanceVariantId") : record7.variantId
114678
114926
  ),
@@ -114681,12 +114929,25 @@ function validateWorldPlacementSidecars(args) {
114681
114929
  ),
114682
114930
  context: args.context
114683
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
+ });
114684
114944
  }
114685
114945
  function validatePlacementVariantBinding(args) {
114946
+ const noun = args.layer === "built" ? "variant" : "applied variant";
114686
114947
  if (args.variantId === null) {
114687
114948
  if (args.rowValueId !== null) {
114688
114949
  throw new Error(
114689
- `Placement value "${args.placementId}" binds row "${args.rowValueId}" without a variant.`
114950
+ `Placement value "${args.placementId}" binds row "${args.rowValueId}" without a ${noun}.`
114690
114951
  );
114691
114952
  }
114692
114953
  return;
@@ -114694,19 +114955,24 @@ function validatePlacementVariantBinding(args) {
114694
114955
  const variant2 = args.context.variantsById.get(args.variantId);
114695
114956
  if (variant2 === void 0) {
114696
114957
  throw new Error(
114697
- `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.`
114698
114959
  );
114699
114960
  }
114700
- if (variant2.classId !== args.assetClassId) {
114961
+ if (args.layer === "built" && variant2.classId !== args.assetClassId) {
114701
114962
  throw new Error(
114702
114963
  `Placement value "${args.placementId}" places class "${args.assetClassId}" but names variant "${args.variantId}" of class "${variant2.classId}"; variant lookup is not virtual.`
114703
114964
  );
114704
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
+ }
114705
114971
  const lookupRows = variant2.lookupRowValueIds;
114706
114972
  if (lookupRows === void 0) {
114707
114973
  if (args.rowValueId !== null) {
114708
114974
  throw new Error(
114709
- `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}".`
114710
114976
  );
114711
114977
  }
114712
114978
  return;
@@ -114718,7 +114984,7 @@ function validatePlacementVariantBinding(args) {
114718
114984
  }
114719
114985
  if (args.rowValueId === null || !rowIds.has(args.rowValueId)) {
114720
114986
  throw new Error(
114721
- `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}".`
114722
114988
  );
114723
114989
  }
114724
114990
  }
@@ -117793,6 +118059,12 @@ function materializePreparedInstanceInitializers(args) {
117793
118059
  );
117794
118060
  let currentReader = null;
117795
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
+ );
117796
118068
  const owners = resolveSemanticOwnerMembersForValues(
117797
118069
  materializationScope.document,
117798
118070
  new Set(sites.keys()),
@@ -117840,7 +118112,17 @@ function materializePreparedInstanceInitializers(args) {
117840
118112
  storedConstructionReplay: true
117841
118113
  });
117842
118114
  if (existingConstructedRoot !== void 0) {
117843
- 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({
117844
118126
  // The synthetic variant binding members are part of the ownership
117845
118127
  // scope that compiled and evaluated this initializer. Stored replay
117846
118128
  // closes its generic slot from the same ephemeral member id, so its
@@ -117851,13 +118133,10 @@ function materializePreparedInstanceInitializers(args) {
117851
118133
  replayRoot: materialized.root,
117852
118134
  replayCreated: materialized.createdValues
117853
118135
  })) {
117854
- throw new Error(
117855
- `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.`
117856
- );
118136
+ replayOnlyIndexes.push(site.index);
118137
+ batch.upsert([existingConstructedRoot]);
118138
+ return;
117857
118139
  }
117858
- replayOnlyIndexes.push(site.index);
117859
- batch.upsert([existingConstructedRoot]);
117860
- return;
117861
118140
  }
117862
118141
  const baseline = materializeInitializerValue2({
117863
118142
  document: currentDocument,
@@ -117884,7 +118163,8 @@ function materializePreparedInstanceInitializers(args) {
117884
118163
  // §4: a call-site field is an explicit override even when it equals
117885
118164
  // the class default, so the evaluated construction's own field list is
117886
118165
  // what pins rows against collapse.
117887
- pinnedRootSchemaKeys: materialized.pinnedRootSchemaKeys
118166
+ pinnedRootSchemaKeys: materialized.pinnedRootSchemaKeys,
118167
+ pinnedSchemaKeysByValueId: materialized.pinnedSchemaKeysByValueId
117888
118168
  });
117889
118169
  assertStoredClosuresKeepNoCaptures({
117890
118170
  sourceValueId: valueId,
@@ -117897,15 +118177,40 @@ function materializePreparedInstanceInitializers(args) {
117897
118177
  ...original,
117898
118178
  nextData: sparse2.root
117899
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
+ }
117900
118204
  for (const created of sparse2.createdChildren) {
117901
118205
  const existing = existingValueById.get(created.id);
117902
118206
  if (existing !== void 0) {
117903
118207
  if (materializedValueRowsEqual(existing, created)) continue;
117904
- const contentHash = liveContentHash(
117905
- args.contentHashHeads,
117906
- "value",
117907
- created.id
117908
- );
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
+ }
117909
118214
  args.prepared.push({
117910
118215
  recordKind: "value",
117911
118216
  recordId: created.id,
@@ -119138,7 +119443,11 @@ function seedRootRow(member, seed, rootId) {
119138
119443
  ...seed.constructorArgs === void 0 ? {} : { constructorArgs: seed.constructorArgs },
119139
119444
  ...seed.instanceConstructorId === void 0 ? {} : { instanceConstructorId: seed.instanceConstructorId },
119140
119445
  ...seed.instanceVariantId === void 0 ? {} : { instanceVariantId: seed.instanceVariantId },
119141
- ...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
+ }
119142
119451
  };
119143
119452
  }
119144
119453
  function authoredSeedRowMatchesValue(row, value) {
@@ -119155,7 +119464,7 @@ function authoredSeedRowMatchesValue(row, value) {
119155
119464
  return isLiteralValueContent(value);
119156
119465
  }
119157
119466
  if (isInitValueContent(value)) return false;
119158
- 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;
119159
119468
  return canonicallyEqual2(
119160
119469
  {
119161
119470
  value: row.value,
@@ -119281,6 +119590,10 @@ function materializeAuthoredSeedRow(args) {
119281
119590
  },
119282
119591
  ...args.row.instanceVariantId === void 0 ? {} : { instanceVariantId: args.row.instanceVariantId },
119283
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
+ },
119284
119597
  ...args.row.containerId === void 0 ? {} : { containerId: args.row.containerId },
119285
119598
  ...args.row.genericBindings === void 0 ? {} : { genericBindings: { ...args.row.genericBindings } },
119286
119599
  ...args.row.sourceValueId === void 0 ? {} : { sourceValueId: args.row.sourceValueId },
@@ -129577,6 +129890,7 @@ function prepareClientPush(args) {
129577
129890
  if (change.recordKind !== "value" || change.operation !== "update") {
129578
129891
  continue;
129579
129892
  }
129893
+ if (isInitValueContent(change.nextData)) continue;
129580
129894
  const refusal = valueDematerializationRefusal({
129581
129895
  valueId: change.recordId,
129582
129896
  baseData: args.base.records.get(`value:${change.recordId}`)?.data,
@@ -129745,6 +130059,7 @@ var init_server_preparation_preflight = __esm({
129745
130059
  init_project_document_read();
129746
130060
  init_project_snapshot_derived_edges();
129747
130061
  init_project_version_whole_graph_validation();
130062
+ init_members();
129748
130063
  init_performance();
129749
130064
  init_trusted_commit_verification();
129750
130065
  ServerPreparationPreflightError = class extends Error {
@@ -129842,17 +130157,8 @@ function replayStoredConstructionV4(args) {
129842
130157
  createdAt: 0,
129843
130158
  updatedAt: 0
129844
130159
  };
129845
- const rootRecord = root;
129846
- const envelope = { ...rootRecord };
129847
- delete envelope.value;
129848
- delete envelope.classId;
129849
- delete envelope.constructorArgs;
129850
- delete envelope.instanceConstructorId;
129851
- delete envelope.instanceVariantId;
129852
- delete envelope.instanceVariantRowValueId;
129853
- delete envelope.init;
129854
130160
  const candidate = {
129855
- ...envelope,
130161
+ ...withoutMaterializedInstanceFields(root),
129856
130162
  init: args.compiledInitializer ?? { code: args.code }
129857
130163
  };
129858
130164
  if (args.compiledInitializer === void 0)
@@ -129911,7 +130217,7 @@ function replayStoredConstructionV4(args) {
129911
130217
  ...args.omitConstructionFields === true ? { constructionBaselineReplay: true } : {},
129912
130218
  ...args.initializerArgumentValues === void 0 ? {} : { argumentValues: args.initializerArgumentValues }
129913
130219
  });
129914
- args.onPinnedRootSchemaKeys?.(materialized.pinnedRootSchemaKeys);
130220
+ args.onPinnedSchemaKeys?.(materialized);
129915
130221
  return new Map(
129916
130222
  [materialized.root, ...materialized.createdValues].map((row) => [
129917
130223
  row.id,
@@ -130015,6 +130321,18 @@ function compilePulledProjectDocumentForEvaluationV4(document, compilationProjec
130015
130321
  }
130016
130322
  return compiled;
130017
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
+ }
130018
130336
  function assertPulledConstructorsCompiled(document, replayContext) {
130019
130337
  if (replayContext !== void 0 && replayContext.document !== document) {
130020
130338
  throw new Error(
@@ -132320,22 +132638,7 @@ function mergedOverStoredRow(base, lowered) {
132320
132638
  const code = storedInitCode(base, lowered.init.code);
132321
132639
  if (code !== lowered.init.code) merged.init = { ...lowered.init, code };
132322
132640
  }
132323
- const {
132324
- value: _value,
132325
- classId: _classId,
132326
- constructorArgs: _constructorArgs,
132327
- instanceConstructorId: _instanceConstructorId,
132328
- instanceVariantId: _instanceVariantId,
132329
- instanceVariantRowValueId: _instanceVariantRowValueId,
132330
- ...initializer
132331
- } = merged;
132332
- void _value;
132333
- void _classId;
132334
- void _constructorArgs;
132335
- void _instanceConstructorId;
132336
- void _instanceVariantId;
132337
- void _instanceVariantRowValueId;
132338
- return initializer;
132641
+ return withoutMaterializedInstanceFields(merged);
132339
132642
  }
132340
132643
  function storedCompiledClosure(stored, lowered) {
132341
132644
  if (!isNSDelegateClosureValueDraft(lowered)) return null;
@@ -132609,7 +132912,7 @@ function lowerMemberDefaultSourcesV4(state, analysis, manifest, options = {}) {
132609
132912
  `Member default ${label} was classified as an owned literal graph but lowered as an initializer.`
132610
132913
  );
132611
132914
  }
132612
- 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;
132613
132916
  const matchesStoredDefault = storedDefault !== null && canonicallyEqual(seed.value, storedDefault.value) && (seed.classId ?? null) === (typeof storedDefaultClassId === "string" ? storedDefaultClassId : null);
132614
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)) {
132615
132918
  for (const id2 of context.pendingValues.keys()) {
@@ -134127,7 +134430,11 @@ function readInstanceProvenance(value) {
134127
134430
  },
134128
134431
  instanceConstructorId: nullableString5(value.instanceConstructorId),
134129
134432
  instanceVariantId: nullableString5(value.instanceVariantId),
134130
- instanceVariantRowValueId: nullableString5(value.instanceVariantRowValueId)
134433
+ instanceVariantRowValueId: nullableString5(value.instanceVariantRowValueId),
134434
+ instanceAppliedVariantId: nullableString5(value.instanceAppliedVariantId),
134435
+ instanceAppliedVariantRowValueId: nullableString5(
134436
+ value.instanceAppliedVariantRowValueId
134437
+ )
134131
134438
  };
134132
134439
  }
134133
134440
  function preserveReboundValue(context, currentValueId, nextValueId, binding) {
@@ -134177,6 +134484,10 @@ function lowerStaticSeed(context, member, sourceExpression, source, valueId) {
134177
134484
  ...root.instanceConstructorId === void 0 ? {} : { instanceConstructorId: root.instanceConstructorId },
134178
134485
  ...root.instanceVariantId === void 0 ? {} : { instanceVariantId: root.instanceVariantId },
134179
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
+ },
134180
134491
  ...rows.size === 0 && member.kind !== "class" && member.kind !== "list" && member.kind !== "set" && member.kind !== "dictionary" && localizedTexts.size === 0 ? {} : { values: [...rows.values()] },
134181
134492
  ...bindingMembers.length === 0 ? {} : { bindingMembers },
134182
134493
  ...localizedTexts.size === 0 ? {} : { localizedTexts: [...localizedTexts.values()] }
@@ -135586,37 +135897,15 @@ function lowerClassValue(context, member, expression, base, source, outerEnviron
135586
135897
  }
135587
135898
  }
135588
135899
  if (materializedConstruction !== "lower") {
135589
- if (materializedConstruction === "preserve" && isObjectRecord2(base.constructorArgs) && // An explicit `null` IS the recorded identity of a parameterless
135590
- // construction, so it owns no argument rows to retain. Inferring an
135591
- // overload for it would resolve the wrong constructor or refuse the
135592
- // plan outright.
135593
- base.instanceConstructorId !== null) {
135594
- const constructor2 = storedValueConstructor(
135900
+ if (materializedConstruction === "preserve" && classId === currentClassId) {
135901
+ retainConstructionArguments(
135595
135902
  context,
135903
+ base,
135596
135904
  schemaClass2,
135597
- recordedStoredConstructorId(base, schemaClass2)
135598
- );
135599
- const authoredArguments = constructorArgumentExpressions(expression);
135600
- for (let index = 0; index < constructor2.arguments.length; index += 1) {
135601
- const argument2 = constructor2.arguments[index];
135602
- if (argument2 === void 0) continue;
135603
- const valueId = base.constructorArgs[`__arg_${index}__`];
135604
- if (typeof valueId !== "string") continue;
135605
- if (!constructorArgumentOwnsRow(
135606
- argument2.type,
135607
- authoredArguments.get(argument2.name)
135608
- )) {
135609
- continue;
135610
- }
135611
- retainStoredValueSubgraph(
135612
- context,
135613
- valueId,
135614
- source.source,
135615
- /* @__PURE__ */ new Set(),
135616
- null,
135617
- environment
135618
- );
135619
- }
135905
+ expression,
135906
+ source.source,
135907
+ environment
135908
+ );
135620
135909
  }
135621
135910
  }
135622
135911
  return {
@@ -135625,6 +135914,163 @@ function lowerClassValue(context, member, expression, base, source, outerEnviron
135625
135914
  ...classId === currentClassId ? {} : { classId }
135626
135915
  };
135627
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
+ }
135628
136074
  function constructorArgumentOwnsRow(type, authoredArgument) {
135629
136075
  if (type.kind !== "class" && type.kind !== "interface" && type.kind !== "generic" && type.kind !== "list" && type.kind !== "set" && type.kind !== "dictionary") {
135630
136076
  return false;
@@ -137672,6 +138118,7 @@ function freshChildReplaysDeclaredDefault(args) {
137672
138118
  if (child2.genericBindings !== void 0) return false;
137673
138119
  if (child2.instanceVariantId != null) return false;
137674
138120
  if (child2.instanceVariantRowValueId != null) return false;
138121
+ if (child2.instanceAppliedVariantId != null) return false;
137675
138122
  if (context.collectionBindingMemberIds.has(childMember.id)) return false;
137676
138123
  const resolved = resolveGenericSchemaMember(
137677
138124
  context,
@@ -138142,15 +138589,16 @@ function requiredMember(context, id2) {
138142
138589
  }
138143
138590
  function dictionaryKeyEnum(context, member) {
138144
138591
  if (member.key.kind === "string") return null;
138145
- const name = context.enumNames.get(member.key.enumId);
138146
- 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);
138147
138597
  if (name === void 0) {
138148
- throw new Error(`Unknown dictionary key enum ${member.key.enumId}.`);
138598
+ throw new Error(`Unknown dictionary key enum ${enumId}.`);
138149
138599
  }
138150
138600
  if (optionsByName === void 0) {
138151
- throw new Error(
138152
- `Dictionary key enum ${member.key.enumId} has no option index.`
138153
- );
138601
+ throw new Error(`Dictionary key enum ${enumId} has no option index.`);
138154
138602
  }
138155
138603
  return { name, optionsByName };
138156
138604
  }
@@ -138657,7 +139105,7 @@ function storedReplayLeafValueMatches(type, value) {
138657
139105
  }
138658
139106
  function literalStoredReplayInitializer(context, valueId, code, member) {
138659
139107
  const value = context.values.get(valueId);
138660
- 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))
138661
139109
  return void 0;
138662
139110
  const schemaClass2 = context.manifestClasses.get(value.classId);
138663
139111
  if (schemaClass2?.requiredConstructorId !== value.instanceConstructorId)
@@ -139166,7 +139614,8 @@ function storedConstructorArgumentSource(context, type, value, environment, visi
139166
139614
  visited,
139167
139615
  false,
139168
139616
  false,
139169
- constructorOwnsGraph
139617
+ constructorOwnsGraph,
139618
+ cloneAggregateArguments
139170
139619
  );
139171
139620
  case "lookup":
139172
139621
  return referenceValue(
@@ -139501,7 +139950,7 @@ function storedSchemaTypeName(context, type, environment, valueId) {
139501
139950
  return "null";
139502
139951
  }
139503
139952
  }
139504
- 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) {
139505
139954
  const symbol = context.symbolsByValueId.get(valueId);
139506
139955
  if (symbol !== void 0) return symbol;
139507
139956
  const row = context.values.get(valueId);
@@ -139510,6 +139959,18 @@ function storedTypedRowSource(context, type, valueId, environment, visited, writ
139510
139959
  `Stored ${type.kind} constructor argument references missing value row ${valueId}.`
139511
139960
  );
139512
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
+ }
139513
139974
  if (isSharedConstructorArgument(context, valueId, constructorOwnsGraph)) {
139514
139975
  return `Reference<${storedSchemaTypeName(context, type, environment, valueId)}>(id: ${quote3(valueId)})`;
139515
139976
  }
@@ -139566,7 +140027,8 @@ ${ids.map(
139566
140027
  visited,
139567
140028
  true,
139568
140029
  false,
139569
- constructorOwnsGraph
140030
+ constructorOwnsGraph,
140031
+ cloneAggregateArguments
139570
140032
  ),
139571
140033
  2
139572
140034
  )
@@ -139595,7 +140057,8 @@ ${entries.flatMap(
139595
140057
  visited,
139596
140058
  false,
139597
140059
  false,
139598
- constructorOwnsGraph
140060
+ constructorOwnsGraph,
140061
+ cloneAggregateArguments
139599
140062
  )}`,
139600
140063
  2
139601
140064
  )
@@ -141205,8 +141668,8 @@ function initializerRecompileTargets(args) {
141205
141668
  })
141206
141669
  });
141207
141670
  }
141208
- function materializedInitializerReconciliationFailuresV4(args) {
141209
- if (args.reconciliations.size === 0) return [];
141671
+ function reconcileMaterializedInitializersV4(args) {
141672
+ if (args.reconciliations.size === 0) return { failures: [], rebuilds: [] };
141210
141673
  const records3 = reconciliationRecords(
141211
141674
  args.workspace,
141212
141675
  args.changes,
@@ -141284,7 +141747,6 @@ function materializedInitializerReconciliationFailuresV4(args) {
141284
141747
  }
141285
141748
  }
141286
141749
  const expressionsGrew = canonicalExpressions.size > (cached?.expressions.size ?? 0);
141287
- const authoredConstructionChangedByValueId = /* @__PURE__ */ new Map();
141288
141750
  const replayableValueIds = /* @__PURE__ */ new Set();
141289
141751
  for (const [valueId, reconciliation] of constructions) {
141290
141752
  const owner = candidateOwners.get(valueId);
@@ -141296,11 +141758,7 @@ function materializedInitializerReconciliationFailuresV4(args) {
141296
141758
  );
141297
141759
  }
141298
141760
  const authoredConstructionChanged = args.manifest !== void 0 && canonicalExpression !== reconciliation.construction;
141299
- authoredConstructionChangedByValueId.set(
141300
- valueId,
141301
- authoredConstructionChanged
141302
- );
141303
- if (reconciliation.kind === "storedArguments" && (authoredConstructionChanged || currentState().recompileTargets.valueIds.has(valueId))) {
141761
+ if (authoredConstructionChanged || reconciliation.kind === "storedArguments" && currentState().recompileTargets.valueIds.has(valueId)) {
141304
141762
  replayableValueIds.add(valueId);
141305
141763
  }
141306
141764
  }
@@ -141367,26 +141825,9 @@ function materializedInitializerReconciliationFailuresV4(args) {
141367
141825
  }
141368
141826
  let currentRows;
141369
141827
  let currentReader;
141828
+ let ownedValues;
141829
+ const rebuilds = [];
141370
141830
  for (const reconciliation of constructions.values()) {
141371
- if (reconciliation.kind === "canonicalConstruction") {
141372
- if (authoredConstructionChangedByValueId.get(reconciliation.valueId) !== true) {
141373
- continue;
141374
- }
141375
- const position2 = composeReferenceSitePosition(
141376
- reconciliation.site,
141377
- args.sourceTextByUri
141378
- );
141379
- failures.push(
141380
- new SchemaSourceError(
141381
- `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.`,
141382
- position2.file,
141383
- position2.line,
141384
- position2.column,
141385
- "construction-arguments-conflict"
141386
- )
141387
- );
141388
- continue;
141389
- }
141390
141831
  if (!replayableValueIds.has(reconciliation.valueId)) continue;
141391
141832
  const owner = candidateOwners.get(reconciliation.valueId);
141392
141833
  if (owner === void 0) {
@@ -141414,7 +141855,7 @@ function materializedInitializerReconciliationFailuresV4(args) {
141414
141855
  }
141415
141856
  } catch (error) {
141416
141857
  if (error instanceof NSGetterRuntimeError && error.source === void 0 && args.forceRecompile !== true) {
141417
- return materializedInitializerReconciliationFailuresV4({
141858
+ return reconcileMaterializedInitializersV4({
141418
141859
  ...args,
141419
141860
  forceRecompile: true,
141420
141861
  useBuildCaches: false,
@@ -141438,34 +141879,81 @@ function materializedInitializerReconciliationFailuresV4(args) {
141438
141879
  );
141439
141880
  currentReader ??= new EffectiveValueReader(replayDocument, currentRows);
141440
141881
  const replay = replayRows.get(reconciliation.valueId);
141441
- 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
+ }
141442
141887
  const currentRoot = currentRows.get(reconciliation.valueId);
141443
- const [storedArgs, replayedArgs] = isObjectRecord2(replayArgs) ? withoutSharedArguments(reconciliation.storedConstructorArgs, replayArgs) : [reconciliation.storedConstructorArgs, replayArgs];
141444
- const currentNormalized = currentRoot === void 0 ? void 0 : currentReader.normalizeConstructorArguments(
141445
- 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,
141446
141912
  currentRoot,
141913
+ replay,
141914
+ replayRows,
141447
141915
  owner
141448
- );
141449
- const replayNormalized = replay === void 0 || !isObjectRecord2(replayedArgs) ? void 0 : currentReader.withRowOverrides(replayRows).normalizeConstructorArguments(replayedArgs, replay, owner);
141450
- const argumentsMatch = isObjectRecord2(replayArgs) && currentRoot !== void 0 && replay !== void 0 && effectiveValuesEqual(currentNormalized, replayNormalized);
141451
- if (argumentsMatch) {
141916
+ })) {
141452
141917
  continue;
141453
141918
  }
141454
- const position = composeReferenceSitePosition(
141455
- reconciliation.site,
141456
- args.sourceTextByUri
141457
- );
141458
- failures.push(
141459
- new SchemaSourceError(
141460
- `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.`,
141461
- position.file,
141462
- position.line,
141463
- position.column,
141464
- "construction-arguments-conflict"
141465
- )
141466
- );
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
+ });
141467
141936
  }
141468
- 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 } };
141469
141957
  }
141470
141958
  function retainedLiteralCompiles(document, retained, owners, rootOwners, stored) {
141471
141959
  if (retained.length === 0) return null;
@@ -141767,7 +142255,10 @@ function materializeInitializersLocallyV4(args) {
141767
142255
  });
141768
142256
  const code = initializerCode(records3, sourceValueId);
141769
142257
  let compiledInitializer;
141770
- let pinnedRootSchemaKeys = /* @__PURE__ */ new Set();
142258
+ let pinned = {
142259
+ pinnedRootSchemaKeys: /* @__PURE__ */ new Set(),
142260
+ pinnedSchemaKeysByValueId: /* @__PURE__ */ new Map()
142261
+ };
141771
142262
  const evaluated = replayStoredConstructionV4({
141772
142263
  records: records3,
141773
142264
  document,
@@ -141781,8 +142272,8 @@ function materializeInitializersLocallyV4(args) {
141781
142272
  compiledInitializer = init;
141782
142273
  compiledInitializers.set(sourceValueId, init);
141783
142274
  },
141784
- onPinnedRootSchemaKeys: (schemaKeys) => {
141785
- pinnedRootSchemaKeys = schemaKeys;
142275
+ onPinnedSchemaKeys: (keys) => {
142276
+ pinned = keys;
141786
142277
  }
141787
142278
  });
141788
142279
  const evaluatedRoot = evaluated.get(sourceValueId);
@@ -141846,7 +142337,8 @@ function materializeInitializersLocallyV4(args) {
141846
142337
  // §4: a call-site field is an explicit override even when it equals the
141847
142338
  // class default, so the evaluated construction's own field list is what
141848
142339
  // pins rows against collapse. Push preparation pins the same set.
141849
- pinnedRootSchemaKeys,
142340
+ pinnedRootSchemaKeys: pinned.pinnedRootSchemaKeys,
142341
+ pinnedSchemaKeysByValueId: pinned.pinnedSchemaKeysByValueId,
141850
142342
  virtualValueIdForSource: (instanceRootId, sourceIdentity3) => isPendingId(instanceRootId) || hasPendingVirtualSourceIdentity(sourceIdentity3) ? pendingVirtualValueId(instanceRootId, sourceIdentity3) : virtualValueId(instanceRootId, sourceIdentity3)
141851
142343
  });
141852
142344
  const evaluatedRows = [sparse2.root, ...sparse2.createdChildren];
@@ -142035,6 +142527,7 @@ var init_local_initializer_materialization = __esm({
142035
142527
  init_constructor_argument_ownership();
142036
142528
  init_neo_script_recompile_scope();
142037
142529
  init_compiler_adapter();
142530
+ init_owned_value_deletion();
142038
142531
  init_compiled_construction_types();
142039
142532
  init_project_version_schema_commit();
142040
142533
  init_value_row_owner_members();
@@ -148912,23 +149405,28 @@ function computeStatus(workspace, options, conflictedFiles, parseErrors, parseWa
148912
149405
  }
148913
149406
  if (!parseErrors.some(isBlockingSchemaSourceError)) {
148914
149407
  try {
148915
- parseErrors.push(
148916
- ...materializedInitializerReconciliationFailuresV4({
148917
- workspace,
148918
- changes,
148919
- authoredValueSeeds,
148920
- reconciliations: valueLowerRegistry.initializerReconciliations,
148921
- canonicalConstructions: valueLowerRegistry.materializedConstructorExpressions,
148922
- localizedTextDependencies,
148923
- manifest,
148924
- analysis: projectAnalysisV4,
148925
- forceRecompile: options.forceRecompile,
148926
- useBuildCaches: options.useBuildCaches,
148927
- sourceTextByUri: new Map(
148928
- sourceEntries.map((entry) => [entry.relPath, entry.source])
148929
- )
148930
- })
148931
- );
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
+ });
148932
149430
  } catch (error) {
148933
149431
  parseErrors.push(
148934
149432
  error instanceof SchemaSourceError ? error : new SchemaSourceError(
@@ -149405,6 +149903,58 @@ function expandProspectiveAnimationInstances(document) {
149405
149903
  }
149406
149904
  return [...byId.values()];
149407
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
+ }
149408
149958
  function collapseLocalizedSourceRevertsV4(args) {
149409
149959
  const edited = args.changes.filter(
149410
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(
@@ -185144,7 +185694,9 @@ function rewrittenSeedProvenance(memberId, seed) {
185144
185694
  for (const field of [
185145
185695
  "instanceConstructorId",
185146
185696
  "instanceVariantId",
185147
- "instanceVariantRowValueId"
185697
+ "instanceVariantRowValueId",
185698
+ "instanceAppliedVariantId",
185699
+ "instanceAppliedVariantRowValueId"
185148
185700
  ]) {
185149
185701
  const candidate = seed[field];
185150
185702
  if (candidate !== void 0 && candidate !== null && typeof candidate !== "string") {
@@ -185161,6 +185713,12 @@ function rewrittenSeedProvenance(memberId, seed) {
185161
185713
  ...seed.instanceVariantId === void 0 ? {} : { instanceVariantId: seed.instanceVariantId },
185162
185714
  ...seed.instanceVariantRowValueId === void 0 ? {} : {
185163
185715
  instanceVariantRowValueId: seed.instanceVariantRowValueId
185716
+ },
185717
+ ...seed.instanceAppliedVariantId === void 0 ? {} : {
185718
+ instanceAppliedVariantId: seed.instanceAppliedVariantId
185719
+ },
185720
+ ...seed.instanceAppliedVariantRowValueId === void 0 ? {} : {
185721
+ instanceAppliedVariantRowValueId: seed.instanceAppliedVariantRowValueId
185164
185722
  }
185165
185723
  };
185166
185724
  }
@@ -201074,7 +201632,7 @@ There is no --keep-current: preserving current semantic state defines flatten.
201074
201632
  async function main() {
201075
201633
  const args = parseArgs(process.argv.slice(2));
201076
201634
  if (args.command === "--version") {
201077
- console.log("0.81.0");
201635
+ console.log("0.81.1");
201078
201636
  return;
201079
201637
  }
201080
201638
  if (args.command === null || args.command === "help" || args.command === "--help" || args.command === "-h") {