@neocompose/cli 0.89.6 → 0.89.8

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.
@@ -24776,6 +24776,69 @@ function liveListIndexRegistry(ctx) {
24776
24776
  liveListIndexesByProject.set(projectKey, created);
24777
24777
  return created;
24778
24778
  }
24779
+ var EvaluatorParentLinks = class {
24780
+ ordinary = /* @__PURE__ */ new Map();
24781
+ buckets = /* @__PURE__ */ new Map();
24782
+ /** Only shared selection targets need direct parent removal. */
24783
+ indexParents(childId) {
24784
+ if (this.buckets.has(childId)) return;
24785
+ const links = this.ordinary.get(childId) ?? [];
24786
+ this.ordinary.delete(childId);
24787
+ this.buckets.set(childId, { links: /* @__PURE__ */ new Set(), byParent: /* @__PURE__ */ new Map() });
24788
+ for (const link of links) this.add(childId, link);
24789
+ }
24790
+ get(childId) {
24791
+ const bucket = this.buckets.get(childId);
24792
+ if (bucket === void 0) return this.ordinary.get(childId);
24793
+ return bucket.snapshot ??= [...bucket.links];
24794
+ }
24795
+ has(childId) {
24796
+ return this.buckets.has(childId) || this.ordinary.has(childId);
24797
+ }
24798
+ add(childId, link) {
24799
+ const bucket = this.buckets.get(childId);
24800
+ if (bucket === void 0) {
24801
+ const links = this.ordinary.get(childId) ?? [];
24802
+ links.push(link);
24803
+ this.ordinary.set(childId, links);
24804
+ return;
24805
+ }
24806
+ bucket.links.add(link);
24807
+ let parent = bucket.byParent.get(link.parentId);
24808
+ if (parent === void 0) {
24809
+ parent = /* @__PURE__ */ new Set();
24810
+ bucket.byParent.set(link.parentId, parent);
24811
+ }
24812
+ parent.add(link);
24813
+ bucket.snapshot = void 0;
24814
+ }
24815
+ remove(childId, parentId, key) {
24816
+ const bucket = this.buckets.get(childId);
24817
+ if (bucket === void 0) {
24818
+ const links = this.ordinary.get(childId)?.filter(
24819
+ (link) => link.parentId !== parentId || key !== void 0 && link.key !== key
24820
+ );
24821
+ if (links === void 0 || links.length === 0)
24822
+ this.ordinary.delete(childId);
24823
+ else this.ordinary.set(childId, links);
24824
+ return;
24825
+ }
24826
+ const parent = bucket.byParent.get(parentId);
24827
+ if (parent === void 0) return;
24828
+ for (const link of parent) {
24829
+ if (key !== void 0 && link.key !== key) continue;
24830
+ bucket.links.delete(link);
24831
+ parent.delete(link);
24832
+ bucket.snapshot = void 0;
24833
+ }
24834
+ if (parent.size === 0) bucket.byParent.delete(parentId);
24835
+ if (bucket.links.size === 0) this.buckets.delete(childId);
24836
+ }
24837
+ delete(childId) {
24838
+ this.ordinary.delete(childId);
24839
+ this.buckets.delete(childId);
24840
+ }
24841
+ };
24779
24842
  var evaluatorOwnershipCachesByBase = /* @__PURE__ */ new WeakMap();
24780
24843
  function evaluatorOwnershipCachesForBase(base) {
24781
24844
  const existing = evaluatorOwnershipCachesByBase.get(base);
@@ -24791,7 +24854,8 @@ function blankEvaluatorIndexes(memberByValueId) {
24791
24854
  return {
24792
24855
  rowByValueReference: /* @__PURE__ */ new WeakMap(),
24793
24856
  memberByValueId,
24794
- parentLinksByChildId: /* @__PURE__ */ new Map(),
24857
+ parentLinksByChildId: new EvaluatorParentLinks(),
24858
+ placementParentLinksByChildId: /* @__PURE__ */ new Map(),
24795
24859
  indexedRowIds: /* @__PURE__ */ new Set(),
24796
24860
  indexedOverlayValues: /* @__PURE__ */ new Map(),
24797
24861
  indexedOverlayRowCount: 0,
@@ -25030,8 +25094,15 @@ function evaluatorIndexes(ctx) {
25030
25094
  rowByValueReference: /* @__PURE__ */ new WeakMap(),
25031
25095
  baseRowByValueReference: base?.rowByValueReference,
25032
25096
  memberByValueId: base?.memberByValueId ?? /* @__PURE__ */ new Map(),
25033
- parentLinksByChildId: /* @__PURE__ */ new Map(),
25097
+ parentLinksByChildId: new EvaluatorParentLinks(),
25098
+ placementParentLinksByChildId: /* @__PURE__ */ new Map(),
25034
25099
  baseParentLinksByChildId: base?.parentLinksByChildId,
25100
+ isSelectionRow: (row) => {
25101
+ const member = runtimeCollectionMember(row, ctx);
25102
+ if (member === null || !isMemberLookupBase(member)) return false;
25103
+ const direct = indexes4.memberByValueId.get(row.id);
25104
+ return direct === void 0 || isMemberLookupBase(direct);
25105
+ },
25035
25106
  indexedRowIds: /* @__PURE__ */ new Set(),
25036
25107
  baseIndexedRowIds: base?.indexedRowIds,
25037
25108
  indexedOverlayValues: /* @__PURE__ */ new Map(),
@@ -25125,7 +25196,13 @@ function indexEvaluatorRow(indexes4, row, allowBaseShadow = false, sharedCachesA
25125
25196
  visitEvaluatorRecordOwnershipEdges(indexes4, row, (childId, key) => {
25126
25197
  indexes4.ownedValueAttachmentsByValueId.delete(childId);
25127
25198
  indexes4.constructorOwnershipDirtyValueIds.add(childId);
25128
- addEvaluatorParentLink(indexes4, childId, row.id, key);
25199
+ addEvaluatorParentLink(
25200
+ indexes4,
25201
+ childId,
25202
+ row.id,
25203
+ key,
25204
+ indexes4.isSelectionRow?.(row) === true
25205
+ );
25129
25206
  });
25130
25207
  }
25131
25208
  function indexEvaluatorRows(indexes4, rows, allowBaseShadow = false, liveOverlayRowById) {
@@ -25174,7 +25251,13 @@ function augmentEvaluatorOwnershipEdges(indexes4, row, liveRow) {
25174
25251
  if (links.some((link) => link.parentId === row.id && link.key === key)) {
25175
25252
  return;
25176
25253
  }
25177
- addEvaluatorParentLink(indexes4, childId, row.id, key);
25254
+ addEvaluatorParentLink(
25255
+ indexes4,
25256
+ childId,
25257
+ row.id,
25258
+ key,
25259
+ indexes4.isSelectionRow?.(row) === true
25260
+ );
25178
25261
  indexes4.ownedValueAttachmentsByValueId.delete(childId);
25179
25262
  indexes4.constructorOwnershipDirtyValueIds.add(childId);
25180
25263
  });
@@ -25220,12 +25303,11 @@ function unindexEvaluatorRow(indexes4, row, preserveIncomingLinks = false) {
25220
25303
  indexes4.indexedRowIds.delete(row.id);
25221
25304
  indexes4.ownedValueAttachmentsByValueId.delete(row.id);
25222
25305
  indexes4.constructorOwnershipDirtyValueIds.delete(row.id);
25223
- if (!preserveIncomingLinks) indexes4.parentLinksByChildId.delete(row.id);
25224
- else if (typeof row.containerId === "string") {
25225
- const retained = indexes4.parentLinksByChildId.get(row.id)?.filter((link) => link.parentId !== row.containerId || link.key !== "");
25226
- if (retained === void 0 || retained.length === 0)
25227
- indexes4.parentLinksByChildId.delete(row.id);
25228
- else indexes4.parentLinksByChildId.set(row.id, retained);
25306
+ if (!preserveIncomingLinks) {
25307
+ indexes4.parentLinksByChildId.delete(row.id);
25308
+ indexes4.placementParentLinksByChildId.delete(row.id);
25309
+ } else if (typeof row.containerId === "string") {
25310
+ removeEvaluatorParentLinks(indexes4, row.id, row.containerId, "");
25229
25311
  }
25230
25312
  if (typeof row.value === "object" && row.value !== null && indexes4.rowByValueReference.get(row.value) === row) {
25231
25313
  indexes4.rowByValueReference.delete(row.value);
@@ -25242,12 +25324,7 @@ function unindexEvaluatorRow(indexes4, row, preserveIncomingLinks = false) {
25242
25324
  }
25243
25325
  }
25244
25326
  visitEvaluatorRecordOwnershipEdges(indexes4, row, (childId) => {
25245
- const links = indexes4.parentLinksByChildId.get(childId);
25246
- if (links !== void 0) {
25247
- const retained = links.filter((link) => link.parentId !== row.id);
25248
- if (retained.length === 0) indexes4.parentLinksByChildId.delete(childId);
25249
- else indexes4.parentLinksByChildId.set(childId, retained);
25250
- }
25327
+ removeEvaluatorParentLinks(indexes4, childId, row.id);
25251
25328
  indexes4.ownedValueAttachmentsByValueId.delete(childId);
25252
25329
  indexes4.constructorOwnershipDirtyValueIds.add(childId);
25253
25330
  });
@@ -25260,36 +25337,101 @@ function dropReconciledOwnershipRows(indexes4) {
25260
25337
  indexes4.reconciledOwnershipRows = /* @__PURE__ */ new WeakSet();
25261
25338
  indexes4.indexedVirtualRowSets = /* @__PURE__ */ new WeakSet();
25262
25339
  }
25263
- function addEvaluatorParentLink(indexes4, childId, parentId, key) {
25264
- const links = indexes4.parentLinksByChildId.get(childId) ?? [];
25265
- links.push({ parentId, key });
25266
- indexes4.parentLinksByChildId.set(childId, links);
25340
+ function addEvaluatorParentLink(indexes4, childId, parentId, key, selectionOnly = false) {
25341
+ const placements = indexes4.placementParentLinksByChildId.get(childId);
25342
+ if (selectionOnly) {
25343
+ if (placements === void 0) {
25344
+ indexes4.placementParentLinksByChildId.set(childId, [
25345
+ ...indexes4.parentLinksByChildId.get(childId) ?? []
25346
+ ]);
25347
+ indexes4.parentLinksByChildId.indexParents(childId);
25348
+ }
25349
+ } else {
25350
+ placements?.push({ parentId, key });
25351
+ }
25352
+ indexes4.parentLinksByChildId.add(childId, { parentId, key });
25267
25353
  }
25268
- function indexRuntimeCollectionAppend(collection, entry, ctx) {
25354
+ function removeEvaluatorParentLinks(indexes4, childId, parentId, key) {
25355
+ indexes4.parentLinksByChildId.remove(childId, parentId, key);
25356
+ if (!indexes4.parentLinksByChildId.has(childId)) {
25357
+ indexes4.placementParentLinksByChildId.delete(childId);
25358
+ return;
25359
+ }
25360
+ const placements = indexes4.placementParentLinksByChildId.get(childId);
25361
+ if (placements !== void 0)
25362
+ indexes4.placementParentLinksByChildId.set(
25363
+ childId,
25364
+ placements.filter(
25365
+ (link) => link.parentId !== parentId || key !== void 0 && link.key !== key
25366
+ )
25367
+ );
25368
+ }
25369
+ function indexRuntimeCollectionChange(collection, entry, ctx, removedEntries = null, entryKey, change = "entry") {
25269
25370
  const indexes4 = ctx.__indexes;
25270
25371
  const row = indexes4?.rowByValueReference.get(collection);
25271
25372
  if (indexes4 === void 0 || indexes4.invalidated || row === void 0 || ctx.__runtimeSessionValues?.get(row.id) !== row || !indexes4.indexedRowIds.has(row.id))
25272
25373
  return false;
25273
- if (typeof entry === "string") {
25274
- addEvaluatorParentLink(indexes4, entry, row.id, "");
25275
- indexes4.ownedValueAttachmentsByValueId.delete(entry);
25276
- indexes4.constructorOwnershipDirtyValueIds.add(entry);
25374
+ if (removedEntries !== null)
25375
+ for (const removed of removedEntries) {
25376
+ removeEvaluatorParentLinks(indexes4, removed, row.id, entryKey);
25377
+ indexes4.ownedValueAttachmentsByValueId.delete(removed);
25378
+ indexes4.constructorOwnershipDirtyValueIds.add(removed);
25379
+ }
25380
+ const addEdge = (childId, key) => {
25381
+ addEvaluatorParentLink(
25382
+ indexes4,
25383
+ childId,
25384
+ row.id,
25385
+ key,
25386
+ indexes4.isSelectionRow?.(row) === true
25387
+ );
25388
+ indexes4.ownedValueAttachmentsByValueId.delete(childId);
25389
+ indexes4.constructorOwnershipDirtyValueIds.add(childId);
25390
+ };
25391
+ if (typeof entry === "string") addEdge(entry, entryKey ?? "");
25392
+ else if (change === "contents")
25393
+ visitEvaluatorRecordOwnershipEdges(indexes4, row, addEdge);
25394
+ if (typeof entry === "string" || removedEntries !== null && removedEntries.length > 0) {
25277
25395
  indexes4.ownershipRootIdsByRowId.clear();
25278
25396
  indexes4.ownershipDistancesByRowId.clear();
25279
25397
  indexes4.memberByRowId.clear();
25280
25398
  }
25281
- forgetLocalListIndexes(ctx, collection);
25399
+ if (Array.isArray(collection)) forgetLocalListIndexes(ctx, collection);
25282
25400
  markOverlayMutated(ctx, collection);
25283
25401
  if (ctx.__valueOverlay instanceof LazyValueOverlay)
25284
25402
  indexes4.overlayRevision = ctx.__valueOverlay.revision;
25285
25403
  return true;
25286
25404
  }
25287
- function evaluatorParentLinks(indexes4, childId) {
25405
+ function indexRuntimeCollectionEntryWrite(collection, previous, value, key, ctx) {
25406
+ if (!Array.isArray(collection))
25407
+ return indexRuntimeCollectionChange(
25408
+ collection,
25409
+ value,
25410
+ ctx,
25411
+ typeof previous === "string" ? [previous] : [],
25412
+ String(key)
25413
+ );
25414
+ if (typeof previous !== "string" && typeof value !== "string")
25415
+ return indexRuntimeCollectionChange(collection, void 0, ctx);
25416
+ const edges = collection.filter(
25417
+ (entry) => typeof entry === "string"
25418
+ );
25419
+ if (typeof previous === "string") edges.push(previous);
25420
+ return indexRuntimeCollectionChange(
25421
+ collection,
25422
+ void 0,
25423
+ ctx,
25424
+ edges,
25425
+ void 0,
25426
+ "contents"
25427
+ );
25428
+ }
25429
+ function evaluatorParentLinks(indexes4, childId, placementOnly = false) {
25288
25430
  const unfilteredBase = indexes4.baseParentLinksByChildId?.get(childId) ?? [];
25289
25431
  const base = indexes4.shadowedBaseRowIds.size === 0 ? unfilteredBase : unfilteredBase.filter(
25290
25432
  (link) => !indexes4.shadowedBaseRowIds.has(link.parentId)
25291
25433
  );
25292
- const local = indexes4.parentLinksByChildId.get(childId) ?? [];
25434
+ const local = (placementOnly ? indexes4.placementParentLinksByChildId.get(childId) : void 0) ?? indexes4.parentLinksByChildId.get(childId) ?? [];
25293
25435
  if (base.length === 0) return local;
25294
25436
  if (local.length === 0) return base;
25295
25437
  return [...base, ...local];
@@ -26137,6 +26279,7 @@ function withEvaluationRuntime(ctx, writes) {
26137
26279
  ctx.__setEntryIndexes ??= /* @__PURE__ */ new WeakMap();
26138
26280
  ctx.__runtimeSets ??= /* @__PURE__ */ new WeakMap();
26139
26281
  ctx.__collectionElementTypes ??= /* @__PURE__ */ new WeakMap();
26282
+ ctx.__runtimeCollectionMembers ??= /* @__PURE__ */ new WeakMap();
26140
26283
  ctx.__dirtyRuntimeSets ??= /* @__PURE__ */ new Set();
26141
26284
  ctx.__runtimeClassOverrides ??= /* @__PURE__ */ new Map();
26142
26285
  ctx.__getterSubscriptions ??= getterSubscriptionsFor(ctx);
@@ -26174,6 +26317,7 @@ function withEvaluationRuntime(ctx, writes) {
26174
26317
  __setEntryIndexes: ctx.__setEntryIndexes ?? /* @__PURE__ */ new WeakMap(),
26175
26318
  __runtimeSets: ctx.__runtimeSets ?? /* @__PURE__ */ new WeakMap(),
26176
26319
  __collectionElementTypes: ctx.__collectionElementTypes ?? /* @__PURE__ */ new WeakMap(),
26320
+ __runtimeCollectionMembers: ctx.__runtimeCollectionMembers ?? /* @__PURE__ */ new WeakMap(),
26177
26321
  __tupleHandleIdentity: ctx.__tupleHandleIdentity ??= new TupleHandleIdentity(),
26178
26322
  __dirtyRuntimeSets: ctx.__dirtyRuntimeSets ?? /* @__PURE__ */ new Set(),
26179
26323
  __runtimeReferenceRemap: referenceRemap,
@@ -26745,11 +26889,10 @@ function remapRuntimeReferences(value, overlay, seen, preservedReferences) {
26745
26889
  const next = {};
26746
26890
  seen.set(value, next);
26747
26891
  for (const [key, entry] of Object.entries(value)) {
26748
- next[key] = remapRuntimeReferences(
26749
- entry,
26750
- overlay,
26751
- seen,
26752
- preservedReferences
26892
+ setOwnField(
26893
+ next,
26894
+ key,
26895
+ remapRuntimeReferences(entry, overlay, seen, preservedReferences)
26753
26896
  );
26754
26897
  }
26755
26898
  return next;
@@ -27733,7 +27876,8 @@ function evalInstructions(instructions, scope, ctx, options) {
27733
27876
  target.pointer,
27734
27877
  scope,
27735
27878
  ctx,
27736
- destination
27879
+ destination,
27880
+ value
27737
27881
  );
27738
27882
  const through = genericSlotReference(
27739
27883
  member,
@@ -27757,7 +27901,8 @@ function evalInstructions(instructions, scope, ctx, options) {
27757
27901
  target.pointer,
27758
27902
  scope,
27759
27903
  ctx,
27760
- destination
27904
+ destination,
27905
+ value
27761
27906
  );
27762
27907
  }
27763
27908
  if (target.structuredLeafKind !== void 0 && destination !== void 0)
@@ -27774,6 +27919,11 @@ function evalInstructions(instructions, scope, ctx, options) {
27774
27919
  ctx
27775
27920
  );
27776
27921
  const lookupMember = member !== null && isMemberLookup(member) ? member : null;
27922
+ const inlineReferenceValue = lookupMember !== null && target.pointer.type === "keyOf" /* keyOf */ && target.pointer.memberId === void 0 && destination !== void 0 && materializedCollectionEntryId(
27923
+ destination.receiver,
27924
+ destination.key,
27925
+ ctx
27926
+ ) === null ? { value } : void 0;
27777
27927
  if (lookupMember !== null) {
27778
27928
  materializeReferencedSlots(value, ctx);
27779
27929
  const holder = destination === void 0 ? null : trackedRowForValueReference(destination.receiver, ctx);
@@ -27830,7 +27980,8 @@ function evalInstructions(instructions, scope, ctx, options) {
27830
27980
  value,
27831
27981
  scope,
27832
27982
  ctx,
27833
- destination
27983
+ destination,
27984
+ inlineReferenceValue
27834
27985
  );
27835
27986
  }
27836
27987
  const unorderedReplacement = assignedReferenceValueId === null && member !== null && isMemberEntryCollectionBase(member) && listKindOf(member) === 1 /* Unordered */ && Array.isArray(value) ? unorderedReplacementProjection(
@@ -28495,7 +28646,7 @@ function validateStructuredFieldAssignment(kind, field, value) {
28495
28646
  { errorClassId: NEO_ERROR_CLASS_IDS.NeoArgumentError }
28496
28647
  );
28497
28648
  }
28498
- function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, destination) {
28649
+ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, destination, inlineReferenceValue) {
28499
28650
  if (target.type === "staticMember" /* staticMember */) {
28500
28651
  if (ctx.storedConstructionReplay === true) {
28501
28652
  throw new NSGetterRuntimeError(
@@ -28527,8 +28678,32 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
28527
28678
  "assignment target",
28528
28679
  reattachesReplaySlot ? void 0 : key
28529
28680
  );
28681
+ if (inlineReferenceValue !== void 0) {
28682
+ const entryId = trackInsertedCollection(
28683
+ inlineReferenceValue.value,
28684
+ targetTypeInfo,
28685
+ receiver,
28686
+ ctx
28687
+ );
28688
+ if (entryId !== null) {
28689
+ const collection = Array.isArray(receiver) ? receiver : objectArg(receiver, "Assignment target");
28690
+ const entryKey = typeof key === "number" ? key : String(key);
28691
+ setOwnField(collection, String(entryKey), entryId);
28692
+ recordWrittenEntry(collection, entryKey, true, ctx);
28693
+ if (!indexRuntimeCollectionChange(
28694
+ collection,
28695
+ entryId,
28696
+ ctx,
28697
+ null,
28698
+ Array.isArray(collection) ? void 0 : String(entryKey)
28699
+ ))
28700
+ invalidateEvaluatorIndexes(ctx, receiver);
28701
+ return;
28702
+ }
28703
+ }
28530
28704
  if (Array.isArray(receiver)) {
28531
28705
  const index = numberArg(key, "List assignment index");
28706
+ const previous2 = receiver[index];
28532
28707
  if (referenceValueId !== null) {
28533
28708
  const parentId = findKnownRowIdByValueReference(receiver, ctx);
28534
28709
  if (parentId !== null) {
@@ -28552,10 +28727,17 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
28552
28727
  }
28553
28728
  receiver[index] = referenceValueId;
28554
28729
  recordWrittenEntry(receiver, index, true, ctx);
28555
- invalidateEvaluatorIndexes(ctx, receiver);
28730
+ if (!indexRuntimeCollectionEntryWrite(
28731
+ receiver,
28732
+ previous2,
28733
+ referenceValueId,
28734
+ index,
28735
+ ctx
28736
+ ))
28737
+ invalidateEvaluatorIndexes(ctx, receiver);
28556
28738
  return;
28557
28739
  }
28558
- if (collectionReferences(receiver, ctx) === 0 /* RowIds */ && replaceEntryRowValue(
28740
+ if (isReferenceEntry(collectionReferences(receiver, ctx), index) && replaceEntryRowValue(
28559
28741
  receiver,
28560
28742
  receiver[index],
28561
28743
  value,
@@ -28565,11 +28747,13 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
28565
28747
  return;
28566
28748
  receiver[index] = value;
28567
28749
  recordWrittenEntry(receiver, index, false, ctx);
28568
- invalidateEvaluatorIndexes(ctx, receiver);
28750
+ if (!indexRuntimeCollectionEntryWrite(receiver, previous2, value, index, ctx))
28751
+ invalidateEvaluatorIndexes(ctx, receiver);
28569
28752
  return;
28570
28753
  }
28571
28754
  const object = objectArg(receiver, "Assignment target");
28572
28755
  const stringKey = String(key);
28756
+ const previous = object[stringKey];
28573
28757
  const field = target.memberId !== void 0;
28574
28758
  if (field && isTypeInfoWithEntries(targetTypeInfo)) {
28575
28759
  const slot = collectionSlotRow(target, { receiver, key }, ctx);
@@ -28600,18 +28784,27 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
28600
28784
  );
28601
28785
  noteDetachedRow(object[stringKey], referenceValueId, ctx);
28602
28786
  }
28603
- object[stringKey] = referenceValueId;
28787
+ setOwnField(object, stringKey, referenceValueId);
28604
28788
  if (!field) recordWrittenEntry(object, stringKey, true, ctx);
28605
- invalidateEvaluatorIndexes(ctx, receiver);
28789
+ if (field || !indexRuntimeCollectionEntryWrite(
28790
+ object,
28791
+ previous,
28792
+ referenceValueId,
28793
+ stringKey,
28794
+ ctx
28795
+ ))
28796
+ invalidateEvaluatorIndexes(ctx, receiver);
28606
28797
  return;
28607
28798
  }
28608
- if (collectionReferences(object, ctx) === 0 /* RowIds */ && replaceEntryRowValue(object, object[stringKey], value, targetTypeInfo, ctx))
28799
+ if (isReferenceEntry(collectionReferences(object, ctx), stringKey) && replaceEntryRowValue(object, object[stringKey], value, targetTypeInfo, ctx))
28609
28800
  return;
28610
28801
  if (field && (targetTypeInfo.type === 7 /* Class */ || targetTypeInfo.type === 22 /* Interface */))
28611
28802
  noteDetachedRow(object[stringKey], value, ctx);
28612
- object[stringKey] = value;
28803
+ setOwnField(object, stringKey, value);
28613
28804
  if (!field) recordWrittenEntry(object, stringKey, false, ctx);
28614
- invalidateEvaluatorIndexes(ctx, receiver);
28805
+ const scalarField = (previous == null || typeof previous === "number" || typeof previous === "boolean" || typeof previous === "string") && (value == null || typeof value === "number" || typeof value === "boolean" || typeof value === "string");
28806
+ if (field && !scalarField || !indexRuntimeCollectionEntryWrite(object, previous, value, stringKey, ctx))
28807
+ invalidateEvaluatorIndexes(ctx, receiver);
28615
28808
  }
28616
28809
  function keptCollectionSlotValue(target, targetTypeInfo, destination, value, ctx) {
28617
28810
  const sourceId = findKnownRowIdByValueReference(value, ctx);
@@ -28689,7 +28882,7 @@ function copiedCollectionContents(source, entryTypeInfo, slotId, ctx) {
28689
28882
  }
28690
28883
  }
28691
28884
  if (Array.isArray(copy)) copy.push(entry);
28692
- else copy[String(key)] = entry;
28885
+ else setOwnField(copy, String(key), entry);
28693
28886
  return 0 /* Continue */;
28694
28887
  });
28695
28888
  const cache = unorderedListProjectionCache(ctx);
@@ -28758,107 +28951,6 @@ function keepAssignedCollectionValues(value, targetTypeInfo, row, ctx) {
28758
28951
  return 0 /* Continue */;
28759
28952
  });
28760
28953
  }
28761
- function pendingConstructorRootsForRow(valueId, ctx) {
28762
- const roots = /* @__PURE__ */ new Set();
28763
- const open = ctx.__executionState?.openConstructions;
28764
- if (open === void 0 || open.size === 0) return roots;
28765
- const visited = /* @__PURE__ */ new Set();
28766
- const pending = [valueId];
28767
- const parentEntries = /* @__PURE__ */ new Map();
28768
- const placingMembers = /* @__PURE__ */ new Map();
28769
- while (pending.length > 0) {
28770
- const id = pending.pop();
28771
- if (id === void 0 || visited.has(id)) continue;
28772
- visited.add(id);
28773
- const row = evalValueById(
28774
- ctx,
28775
- id,
28776
- ctx.__runtimeSessionValues,
28777
- ctx.__valueOverlay
28778
- );
28779
- if (row === null) continue;
28780
- if (typeof row.value === "object" && row.value !== null && open.has(row.value))
28781
- roots.add(id);
28782
- for (const owner of currentOwnedValueAttachments(
28783
- id,
28784
- ctx,
28785
- parentEntries,
28786
- placingMembers
28787
- )) {
28788
- if (!owner.identity.startsWith("value:")) continue;
28789
- const parent = evalValueById(
28790
- ctx,
28791
- owner.label,
28792
- ctx.__runtimeSessionValues,
28793
- ctx.__valueOverlay
28794
- );
28795
- if (parent === null) continue;
28796
- if (parent.classId === void 0 || parent.classId === null) {
28797
- const raw = placingMember(
28798
- parent,
28799
- ctx,
28800
- void 0,
28801
- 0,
28802
- placingMembers,
28803
- parentEntries
28804
- );
28805
- if (raw === null) continue;
28806
- const member = raw.kind === 21 /* Generic */ ? substituteMember(raw, rowGenericEnv(parent, ctx), ctx.vm.members) : resolveMember(raw, ctx.vm.members);
28807
- if (isMemberWithEntries(member)) {
28808
- const rawEntry = evalMemberById(ctx.vm, member.entryMemberId);
28809
- if (rawEntry === null) continue;
28810
- const entry = rawEntry.kind === 21 /* Generic */ ? substituteMember(
28811
- rawEntry,
28812
- rowGenericEnv(parent, ctx),
28813
- ctx.vm.members
28814
- ) : resolveMember(rawEntry, ctx.vm.members);
28815
- if (entry.kind === 21 /* Generic */ || isMemberLookupBase(entry))
28816
- continue;
28817
- }
28818
- }
28819
- pending.push(owner.label);
28820
- }
28821
- for (const link of evaluatorParentLinks(evaluatorIndexes(ctx), id)) {
28822
- const parent = evalValueById(
28823
- ctx,
28824
- link.parentId,
28825
- ctx.__runtimeSessionValues,
28826
- ctx.__valueOverlay
28827
- );
28828
- if (parent === null || !Array.isArray(parent.value)) continue;
28829
- const member = placingMember(
28830
- parent,
28831
- ctx,
28832
- void 0,
28833
- 0,
28834
- placingMembers,
28835
- parentEntries
28836
- );
28837
- if (member === null || !isMemberTupleBase(member)) continue;
28838
- const positions = ownershipParentEntryKeys(
28839
- parent.value,
28840
- id,
28841
- parentEntries
28842
- );
28843
- for (const position of positions ?? []) {
28844
- if (typeof position !== "number") continue;
28845
- const entryId = member.elementMemberIds[position];
28846
- const rawEntry = entryId === void 0 ? null : evalMemberById(ctx.vm, entryId);
28847
- if (rawEntry === null) continue;
28848
- const entry = rawEntry.kind === 21 /* Generic */ ? substituteMember(
28849
- rawEntry,
28850
- rowGenericEnv(parent, ctx),
28851
- ctx.vm.members
28852
- ) : resolveMember(rawEntry, ctx.vm.members);
28853
- if (entry.kind === 21 /* Generic */ || isMemberLookupBase(entry))
28854
- continue;
28855
- pending.push(parent.id);
28856
- break;
28857
- }
28858
- }
28859
- }
28860
- return roots;
28861
- }
28862
28954
  function preflightAssignedCollection(collection, member, row, ctx) {
28863
28955
  if (member === null) return;
28864
28956
  const env = rowGenericEnv(row, ctx);
@@ -28871,8 +28963,6 @@ function preflightAssignedCollection(collection, member, row, ctx) {
28871
28963
  const attached = /* @__PURE__ */ new Set();
28872
28964
  const preflight = {
28873
28965
  parentEntries: /* @__PURE__ */ new Map(),
28874
- constructorRootIds: pendingConstructorRootsForRow(row.id, ctx),
28875
- constructorArgumentTransfers: /* @__PURE__ */ new Map(),
28876
28966
  dependencies: /* @__PURE__ */ new Map()
28877
28967
  };
28878
28968
  forEachRawCollectionEntry(collection, ctx, ({ raw, key, valueId }) => {
@@ -28895,8 +28985,6 @@ function preflightAssignedCollection(collection, member, row, ctx) {
28895
28985
  );
28896
28986
  return 0 /* Continue */;
28897
28987
  });
28898
- for (const [id, destination] of preflight.constructorArgumentTransfers)
28899
- ctx.__executionState?.ownedValueAttachments.set(id, destination);
28900
28988
  for (const [id, destination] of preflight.dependencies)
28901
28989
  recordConstructorGroupDependency(id, destination, ctx);
28902
28990
  }
@@ -29542,7 +29630,22 @@ function validateAssignmentTarget(target, scope, ctx, destination) {
29542
29630
  }
29543
29631
  return resolved;
29544
29632
  }
29545
- function assignmentTargetMember(target, scope, ctx, destination) {
29633
+ function materializedCollectionEntryId(receiver, key, ctx) {
29634
+ if (typeof receiver !== "object" || receiver === null) return null;
29635
+ const entryKey = typeof key === "number" ? key : String(key);
29636
+ if (!Object.prototype.hasOwnProperty.call(receiver, entryKey)) return null;
29637
+ const raw = Reflect.get(receiver, String(entryKey));
29638
+ if (typeof raw !== "string") return null;
29639
+ if (!isReferenceEntry(collectionReferences(receiver, ctx), entryKey))
29640
+ return null;
29641
+ return evalValueById(
29642
+ ctx,
29643
+ raw,
29644
+ ctx.__runtimeSessionValues,
29645
+ ctx.__valueOverlay
29646
+ ) === null ? null : raw;
29647
+ }
29648
+ function assignmentTargetMember(target, scope, ctx, destination, value) {
29546
29649
  if (target.type === "keyOf" /* keyOf */) {
29547
29650
  const receiver = destination === void 0 ? evalPointer(target.keyOf.pointer, scope, ctx) : destination.receiver;
29548
29651
  const key = destination === void 0 ? evalPointer(target.keyOf.key, scope, ctx) : destination.key;
@@ -29552,6 +29655,12 @@ function assignmentTargetMember(target, scope, ctx, destination) {
29552
29655
  ctx
29553
29656
  );
29554
29657
  if (runtimeMember2 !== null) return runtimeMember2;
29658
+ const raw = typeof receiver === "object" && receiver !== null ? Reflect.get(receiver, String(key)) : void 0;
29659
+ if (target.memberId === void 0 && typeof receiver === "object" && receiver !== null && (materializedCollectionEntryId(receiver, key, ctx) !== null || typeof raw !== "string" && findKnownRowIdByValueReference(value, ctx) !== null)) {
29660
+ const contract = storedCollectionEntryContract(receiver, ctx);
29661
+ if (contract !== null && isMemberLookupBase(contract.member))
29662
+ return { ...contract.entry, ...contract.member };
29663
+ }
29555
29664
  }
29556
29665
  if ((target.type === "keyOf" /* keyOf */ || target.type === "staticMember" /* staticMember */) && target.memberId !== void 0) {
29557
29666
  const member = evalMemberById(ctx.vm, target.memberId);
@@ -29824,14 +29933,17 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29824
29933
  return;
29825
29934
  }
29826
29935
  validateCollectionMutation(targetValue, ins.mutation, args);
29936
+ let insertedReferenceRowId = null;
29827
29937
  if (!isLookupSet && entryArgumentIndex !== null && (ins.mutation === "Add" /* Add */ || ins.mutation === "Insert" /* Insert */) && findKnownRowIdByValueReference(targetValue, ctx) !== null)
29828
- trackInsertedCollection(
29938
+ insertedReferenceRowId = trackInsertedCollection(
29829
29939
  args[entryArgumentIndex],
29830
29940
  collectionEntryWriteType(ins.target.typeInfo, targetValue, ctx),
29831
29941
  targetValue,
29832
29942
  ctx
29833
29943
  );
29834
29944
  const overlayArgs = [...args];
29945
+ let removedReferenceRowId = null;
29946
+ let referenceRemoval = false;
29835
29947
  if ((ins.mutation === "Add" /* Add */ || ins.mutation === "Remove" /* Remove */) && isArrayCollection(targetValue)) {
29836
29948
  if (setMatch !== null) overlayArgs[0] = setMatch.entry;
29837
29949
  else if (isLookupSet)
@@ -29847,12 +29959,32 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29847
29959
  } else if (ins.mutation === "Add" /* Add */ && !isArrayCollection(targetValue)) {
29848
29960
  overlayArgs[1] = findKnownRowIdByValueReference(args[1], ctx) ?? args[1];
29849
29961
  }
29962
+ if (ins.mutation === "Remove" /* Remove */ && Array.isArray(targetValue) && !isLookupSet && setEntryMember === null) {
29963
+ const contract = storedCollectionEntryContract(targetValue, ctx);
29964
+ if (contract !== null && isMemberLookupBase(contract.member)) {
29965
+ referenceRemoval = isMultiSelectionMember(contract.member) !== true;
29966
+ const references = collectionReferences(targetValue, ctx);
29967
+ const index = targetValue.findIndex(
29968
+ (entry, index2) => referenceEqual(
29969
+ isReferenceEntry(references, index2) ? resolveValueIfId(entry, ctx) : entry,
29970
+ args[0],
29971
+ ctx
29972
+ )
29973
+ );
29974
+ if (index >= 0 && typeof targetValue[index] === "string") {
29975
+ removedReferenceRowId = targetValue[index];
29976
+ overlayArgs[0] = removedReferenceRowId;
29977
+ }
29978
+ }
29979
+ }
29980
+ if (insertedReferenceRowId !== null && entryArgumentIndex !== null)
29981
+ overlayArgs[entryArgumentIndex] = insertedReferenceRowId;
29850
29982
  const unorderedEntriesBeforeMutation = unorderedContainerValueId === null || !Array.isArray(targetValue) || ins.mutation === "Add" /* Add */ ? null : [...targetValue];
29851
29983
  const writesEntry = (ins.mutation === "Add" /* Add */ || ins.mutation === "Insert" /* Insert */) && !isLookupSet;
29852
29984
  let attachedValueId = null;
29853
29985
  if (writesEntry) {
29854
29986
  const attachedValue = isArrayCollection(targetValue) && ins.mutation !== "Insert" /* Insert */ ? args[0] : args[1];
29855
- attachedValueId = findKnownRowIdByValueReference(attachedValue, ctx);
29987
+ attachedValueId = insertedReferenceRowId ?? findKnownRowIdByValueReference(attachedValue, ctx);
29856
29988
  const parentId = findKnownRowIdByValueReference(targetValue, ctx);
29857
29989
  if (attachedValueId !== null && parentId !== null) {
29858
29990
  assertInterfaceWriteAdmits(
@@ -29881,14 +30013,51 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29881
30013
  );
29882
30014
  }
29883
30015
  }
29884
- if (ins.mutation === "Add" /* Add */ && isArrayCollection(targetValue) && unorderedContainerValueId !== null && !isLookupSet && findKnownRowIdByValueReference(args[0], ctx) === null) {
30016
+ if (ins.mutation === "Add" /* Add */ && isArrayCollection(targetValue) && unorderedContainerValueId !== null && !isLookupSet && insertedReferenceRowId === null && findKnownRowIdByValueReference(args[0], ctx) === null) {
29885
30017
  overlayArgs[0] = createUnorderedScalarProjectionEntry(
29886
30018
  unorderedContainerValueId,
29887
30019
  args[0] instanceof NSSlotReference ? [args[0].targetId] : args[0],
29888
30020
  ctx
29889
30021
  );
29890
30022
  }
29891
- const removableRowIds = isLookupSet || ins.reference === true ? null : removableEntryRowIds(targetValue, ins.mutation, overlayArgs, ctx);
30023
+ const removableRowIds = isLookupSet ? null : removableEntryRowIds(targetValue, ins.mutation, overlayArgs, ctx);
30024
+ let previousEdges = null;
30025
+ if (ins.mutation !== "Add" /* Add */ && ins.mutation !== "Insert" /* Insert */) {
30026
+ const contents = targetValue instanceof RuntimeSet ? targetValue.source : targetValue;
30027
+ const entries = Array.isArray(contents) ? contents : Object.values(objectArg(contents, "collection mutation target"));
30028
+ previousEdges = entries.filter(
30029
+ (entry) => typeof entry === "string"
30030
+ );
30031
+ }
30032
+ const removedMembers = removableRowIds === null ? null : /* @__PURE__ */ new Map();
30033
+ for (const [, id] of removableRowIds ?? []) {
30034
+ if (ins.mutation === "Remove" /* Remove */ && Array.isArray(targetValue) && id !== overlayArgs[0])
30035
+ continue;
30036
+ const row = evalValueById(
30037
+ ctx,
30038
+ id,
30039
+ ctx.__runtimeSessionValues,
30040
+ ctx.__valueOverlay
30041
+ );
30042
+ if (row === null) continue;
30043
+ const placed = memberForValueRow(row, ctx);
30044
+ if (placed === null) continue;
30045
+ const member = {
30046
+ ...placed,
30047
+ ...substituteMember(placed, rowGenericEnv(row, ctx), ctx.vm.members)
30048
+ };
30049
+ if (isMemberEntryCollectionBase(member) || isMemberDictionaryBase(member))
30050
+ removedMembers?.set(id, {
30051
+ row,
30052
+ contract: {
30053
+ member,
30054
+ members: ctx.vm.members,
30055
+ classes: ctx.vm.classes,
30056
+ bindings: row.genericBindings === void 0 ? void 0 : { ...row.genericBindings }
30057
+ }
30058
+ });
30059
+ }
30060
+ const replacedEntry = writesEntry && dictionary && isPlainRecord(targetValue) ? Reflect.get(targetValue, String(args[0])) : null;
29892
30061
  const previousSetSize = targetValue instanceof RuntimeSet ? targetValue.size : null;
29893
30062
  const removedIndex = applyLocalCollectionMutation(
29894
30063
  targetValue,
@@ -29897,7 +30066,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29897
30066
  ctx,
29898
30067
  isLookupSet,
29899
30068
  ins.reference !== true && ins.mutation === "Remove" /* Remove */ && isArrayCollection(targetValue) && setEntryMember === null && !isLookupSet && findKnownRowIdByValueReference(args[0], ctx) === null,
29900
- ins.reference === true,
30069
+ ins.reference === true || referenceRemoval || removedReferenceRowId !== null,
29901
30070
  setEntryMember === null && decimalEntries
29902
30071
  );
29903
30072
  updateCollectionReferenceProvenance(
@@ -29909,8 +30078,12 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29909
30078
  if (removableRowIds !== null) {
29910
30079
  const key = Array.isArray(targetValue) ? removedIndex : String(args[0]);
29911
30080
  for (const [entryKey, rowId] of removableRowIds) {
29912
- if (ins.mutation === "Clear" /* Clear */ || entryKey === key)
30081
+ if (ins.mutation === "Clear" /* Clear */ || entryKey === key) {
29913
30082
  noteDetachedRow(rowId, null, ctx);
30083
+ const known = removedMembers?.get(rowId);
30084
+ if (known !== void 0)
30085
+ ctx.__runtimeCollectionMembers?.set(known.row, known.contract);
30086
+ }
29914
30087
  }
29915
30088
  }
29916
30089
  if (writesEntry && !(targetValue instanceof RuntimeSet)) {
@@ -29972,7 +30145,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29972
30145
  targetValue.reference,
29973
30146
  ctx
29974
30147
  );
29975
- indexedAppend = indexRuntimeCollectionAppend(
30148
+ indexedAppend = indexRuntimeCollectionChange(
29976
30149
  targetValue.source,
29977
30150
  overlayArgs[0],
29978
30151
  ctx
@@ -29982,6 +30155,34 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29982
30155
  exportRuntimeSetValue(targetValue, ctx);
29983
30156
  }
29984
30157
  }
30158
+ if (writesEntry && !(targetValue instanceof RuntimeSet)) {
30159
+ if (Array.isArray(targetValue))
30160
+ indexedAppend = indexRuntimeCollectionChange(
30161
+ targetValue,
30162
+ ins.mutation === "Insert" /* Insert */ ? overlayArgs[1] : overlayArgs[0],
30163
+ ctx
30164
+ );
30165
+ else if (dictionary && isPlainRecord(targetValue))
30166
+ indexedAppend = indexRuntimeCollectionChange(
30167
+ targetValue,
30168
+ overlayArgs[1],
30169
+ ctx,
30170
+ typeof replacedEntry === "string" ? [replacedEntry] : [],
30171
+ String(args[0])
30172
+ );
30173
+ }
30174
+ if (previousEdges !== null) {
30175
+ const collection = targetValue instanceof RuntimeSet ? targetValue.source : targetValue;
30176
+ if (Array.isArray(collection) || isPlainRecord(collection))
30177
+ indexedAppend = indexRuntimeCollectionChange(
30178
+ collection,
30179
+ void 0,
30180
+ ctx,
30181
+ previousEdges,
30182
+ void 0,
30183
+ "contents"
30184
+ );
30185
+ }
29985
30186
  if (!indexedAppend) invalidateEvaluatorIndexes(ctx, targetValue);
29986
30187
  switch (ins.mutation) {
29987
30188
  case "Insert" /* Insert */:
@@ -29990,7 +30191,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
29990
30191
  target: ins.target,
29991
30192
  index: numberArg(args[0], "Insert index"),
29992
30193
  value: args[1],
29993
- valueId: findKnownRowIdByValueReference(args[1], ctx) ?? void 0,
30194
+ valueId: insertedReferenceRowId ?? findKnownRowIdByValueReference(args[1], ctx) ?? void 0,
29994
30195
  ...resolvedDestinationFieldsForContainer(targetValue, ctx)
29995
30196
  });
29996
30197
  return;
@@ -30001,7 +30202,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
30001
30202
  target: ins.target,
30002
30203
  value: isLookupSet ? overlayArgs[0] : args[0],
30003
30204
  ...!isLookupSet ? {
30004
- valueId: unorderedContainerValueId !== null && typeof overlayArgs[0] === "string" ? overlayArgs[0] : findKnownRowIdByValueReference(args[0], ctx) ?? void 0
30205
+ valueId: insertedReferenceRowId ?? (unorderedContainerValueId !== null && typeof overlayArgs[0] === "string" ? overlayArgs[0] : findKnownRowIdByValueReference(args[0], ctx) ?? void 0)
30005
30206
  } : {},
30006
30207
  ...resolvedDestinationFieldsForContainer(targetValue, ctx)
30007
30208
  });
@@ -30012,7 +30213,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
30012
30213
  target: ins.target,
30013
30214
  key: String(args[0]),
30014
30215
  value: args[1],
30015
- valueId: findKnownRowIdByValueReference(args[1], ctx) ?? void 0,
30216
+ valueId: insertedReferenceRowId ?? findKnownRowIdByValueReference(args[1], ctx) ?? void 0,
30016
30217
  ...resolvedDestinationFieldsForContainer(targetValue, ctx)
30017
30218
  });
30018
30219
  return;
@@ -30023,7 +30224,7 @@ function evalCollectionMutationInstruction(ins, scope, ctx, options) {
30023
30224
  target: ins.target,
30024
30225
  value: isLookupSet ? overlayArgs[0] : args[0],
30025
30226
  ...!isLookupSet ? {
30026
- valueId: setMatch?.valueId ?? findKnownRowIdByValueReference(args[0], ctx) ?? void 0
30227
+ valueId: removedReferenceRowId ?? setMatch?.valueId ?? findKnownRowIdByValueReference(args[0], ctx) ?? void 0
30027
30228
  } : {},
30028
30229
  ...resolvedDestinationFieldsForContainer(targetValue, ctx)
30029
30230
  });
@@ -30119,7 +30320,15 @@ function sortCollectionInPlace(ins, value, scope, ctx, options) {
30119
30320
  references
30120
30321
  );
30121
30322
  forgetLocalListIndexes(ctx, list);
30122
- invalidateEvaluatorIndexes(ctx, list);
30323
+ if (!indexRuntimeCollectionChange(
30324
+ list,
30325
+ void 0,
30326
+ ctx,
30327
+ list.filter((entry) => typeof entry === "string"),
30328
+ void 0,
30329
+ "contents"
30330
+ ))
30331
+ invalidateEvaluatorIndexes(ctx, list);
30123
30332
  if (id !== null)
30124
30333
  options.writes.push({
30125
30334
  kind: "reorder",
@@ -30128,18 +30337,36 @@ function sortCollectionInPlace(ins, value, scope, ctx, options) {
30128
30337
  ...resolvedDestinationFieldsForContainer(list, ctx)
30129
30338
  });
30130
30339
  }
30131
- function trackInsertedCollection(value, type2, parentValue, ctx) {
30132
- if (!isTypeInfoWithEntries(type2) && type2.type !== 9 /* Lookup */ || value === null || typeof value !== "object" || findKnownRowIdByValueReference(value, ctx) !== null)
30133
- return;
30134
- const parent = trackedRowForValueReference(parentValue, ctx);
30340
+ function storedCollectionEntryContract(collection, ctx) {
30341
+ const parent = trackedRowForValueReference(collection, ctx);
30135
30342
  const placement = parent === null ? null : memberForValueRow(parent, ctx);
30136
- if (parent === null || placement === null) return;
30343
+ if (parent === null || placement === null) return null;
30137
30344
  const genericEnv = rowGenericEnv(parent, ctx);
30138
30345
  const parentMember = substituteMember(placement, genericEnv, ctx.vm.members);
30139
- if (!isMemberWithEntries(parentMember)) return;
30346
+ if (!isMemberWithEntries(parentMember)) return null;
30140
30347
  const entry = evalMemberById(ctx.vm, parentMember.entryMemberId);
30141
- if (entry === null) return;
30142
- const member = substituteMember(entry, genericEnv, ctx.vm.members);
30348
+ if (entry === null) return null;
30349
+ return {
30350
+ entry,
30351
+ member: substituteMember(entry, genericEnv, ctx.vm.members),
30352
+ genericEnv
30353
+ };
30354
+ }
30355
+ function trackInsertedCollection(value, type2, parentValue, ctx) {
30356
+ if (value !== null && typeof value !== "object" && type2.type !== 9 /* Lookup */)
30357
+ return null;
30358
+ const contract = storedCollectionEntryContract(parentValue, ctx);
30359
+ if (contract === null) return null;
30360
+ const { entry, member, genericEnv } = contract;
30361
+ const referenceEntry = isMemberLookupBase(member);
30362
+ if (referenceEntry && isMultiSelectionMember(member) !== true) {
30363
+ const target = lookupTargetTypeInfo(member, null, ctx);
30364
+ const localCollection = target.type === 6 /* List */ && Array.isArray(value) || (target.type === 28 /* Set */ || target.type === 9 /* Lookup */) && value instanceof RuntimeSet || target.type === 5 /* Dictionary */ && isPlainRecord(value);
30365
+ if (localCollection && findKnownRowIdByValueReference(value, ctx) === null)
30366
+ return null;
30367
+ }
30368
+ if (!referenceEntry && (!isTypeInfoWithEntries(type2) && type2.type !== 9 /* Lookup */ || value === null || typeof value !== "object" || findKnownRowIdByValueReference(value, ctx) !== null))
30369
+ return null;
30143
30370
  const createdValues = [];
30144
30371
  const collectionAliases = /* @__PURE__ */ new Map();
30145
30372
  const reservations = /* @__PURE__ */ new Map();
@@ -30154,13 +30381,21 @@ function trackInsertedCollection(value, type2, parentValue, ctx) {
30154
30381
  storageKeyDeclarations: /* @__PURE__ */ new Map(),
30155
30382
  collectionEntriesAreReferences: false,
30156
30383
  collectionAliases,
30157
- attachmentReservations: reservations
30384
+ attachmentReservations: reservations,
30385
+ insertedCollections: /* @__PURE__ */ new Set()
30158
30386
  });
30159
30387
  row.genericBindings = computeGenericBindingsStamp(
30160
30388
  entry,
30161
30389
  genericEnv,
30162
30390
  ctx.vm.members
30163
30391
  );
30392
+ if (referenceEntry)
30393
+ ctx.__runtimeCollectionMembers?.set(row, {
30394
+ member: { ...entry, ...member },
30395
+ members: ctx.vm.members,
30396
+ classes: ctx.vm.classes,
30397
+ bindings: row.genericBindings === void 0 ? void 0 : { ...row.genericBindings }
30398
+ });
30164
30399
  for (const [encoded, alias] of collectionAliases) {
30165
30400
  retainEncodedCollectionAlias(encoded, alias, ctx);
30166
30401
  }
@@ -30168,6 +30403,7 @@ function trackInsertedCollection(value, type2, parentValue, ctx) {
30168
30403
  registerRuntimeSessionValue(ctx, created);
30169
30404
  if (ctx.__indexes !== void 0)
30170
30405
  indexEvaluatorRows(ctx.__indexes, createdValues);
30406
+ return referenceEntry ? row.id : null;
30171
30407
  } catch (error) {
30172
30408
  for (const created of createdValues)
30173
30409
  ctx.__executionState?.constructorGroupDependencies.delete(created.id);
@@ -30238,7 +30474,7 @@ function storedSetEntryMember(collection, ctx) {
30238
30474
  }
30239
30475
  return substituteMember(
30240
30476
  entry,
30241
- runtimeGenericEnvForValueRow(container, ctx),
30477
+ rowGenericEnv(container, ctx),
30242
30478
  ctx.vm.members
30243
30479
  );
30244
30480
  }
@@ -30603,7 +30839,11 @@ function applyLocalCollectionMutation(targetValue, mutation, args, ctx, unique =
30603
30839
  }
30604
30840
  return null;
30605
30841
  }
30606
- objectArg(targetValue, "Dictionary Add target")[String(args[0])] = args[1];
30842
+ setOwnField(
30843
+ objectArg(targetValue, "Dictionary Add target"),
30844
+ String(args[0]),
30845
+ args[1]
30846
+ );
30607
30847
  return null;
30608
30848
  case "Remove" /* Remove */:
30609
30849
  if (Array.isArray(targetValue)) {
@@ -32354,7 +32594,11 @@ function runtimeParentGenericEnv(row, ctx, visited, readRow) {
32354
32594
  ctx.onUnattributableValueRead?.(
32355
32595
  ownershipChainRead("generic-parent-resolution", row.id)
32356
32596
  );
32357
- for (const link of evaluatorParentLinks(evaluatorIndexes(ctx), row.id)) {
32597
+ for (const link of evaluatorParentLinks(
32598
+ evaluatorIndexes(ctx),
32599
+ row.id,
32600
+ true
32601
+ )) {
32358
32602
  const parent = readRow === void 0 ? evalValueById(
32359
32603
  ctx,
32360
32604
  link.parentId,
@@ -33486,7 +33730,11 @@ function resolveValueIfId(at2, ctx) {
33486
33730
  ctx.__valueOverlay
33487
33731
  );
33488
33732
  if (!row) return at2;
33489
- const member = memberForValueRow(row, ctx);
33733
+ const placed = memberForValueRow(row, ctx);
33734
+ const member = placed?.kind === 21 /* Generic */ ? {
33735
+ ...placed,
33736
+ ...substituteMember(placed, rowGenericEnv(row, ctx), ctx.vm.members)
33737
+ } : placed;
33490
33738
  if (member !== null && isMemberEntryCollectionBase(member) && listKindOf(member) === 1 /* Unordered */ && Array.isArray(row.value)) {
33491
33739
  return evaluatorUnorderedListEntryIds(row.id, ctx);
33492
33740
  }
@@ -33829,7 +34077,25 @@ function resolveMemberForValueRow(row, ctx, visited) {
33829
34077
  const member = memberForCustomSchemaValue(classId, link.key, ctx);
33830
34078
  if (member !== null) return member;
33831
34079
  }
33832
- return null;
34080
+ return runtimeCollectionMember(row, ctx);
34081
+ }
34082
+ function runtimeCollectionMember(row, ctx) {
34083
+ const known = ctx.__runtimeCollectionMembers?.get(row);
34084
+ if (known === void 0) return null;
34085
+ if (known.members !== ctx.vm.members || known.classes !== ctx.vm.classes)
34086
+ return null;
34087
+ const bindings = row.genericBindings;
34088
+ if (Object.keys(bindings ?? {}).length !== Object.keys(known.bindings ?? {}).length)
34089
+ return null;
34090
+ for (const [id, memberId] of Object.entries(known.bindings ?? {}))
34091
+ if (bindings?.[id] !== memberId) return null;
34092
+ if (row.value !== null) {
34093
+ if ((isMemberEntryCollectionBase(known.member) || isMemberLookupBase(known.member)) && !Array.isArray(row.value))
34094
+ return null;
34095
+ if (isMemberDictionaryBase(known.member) && !isPlainRecord(row.value))
34096
+ return null;
34097
+ }
34098
+ return known.member;
33833
34099
  }
33834
34100
  function* evaluatorParentEdges(row, ctx, indexes4) {
33835
34101
  const cache = ctx.__unorderedListProjections;
@@ -33838,7 +34104,7 @@ function* evaluatorParentEdges(row, ctx, indexes4) {
33838
34104
  yield { parentId: writtenParentId, key: "" };
33839
34105
  }
33840
34106
  const written = cache?.writtenContainerIds;
33841
- for (const link of indexes4.parentLinksByChildId.get(row.id) ?? []) {
34107
+ for (const link of indexes4.placementParentLinksByChildId.get(row.id) ?? indexes4.parentLinksByChildId.get(row.id) ?? []) {
33842
34108
  if (written?.has(link.parentId) !== true) yield link;
33843
34109
  }
33844
34110
  const database = ctx.vm.databaseVM;
@@ -37064,6 +37330,7 @@ function publishConstructedRows(args) {
37064
37330
  if (beforeRetain !== null) {
37065
37331
  for (const rowId of beforeRetain) {
37066
37332
  if (retained.has(rowId)) continue;
37333
+ if (constructorGroupForRow(rowId, ctx) !== null) continue;
37067
37334
  deleteRuntimeSessionValue(ctx, rowId);
37068
37335
  }
37069
37336
  }
@@ -37149,16 +37416,55 @@ function assertImplicitConstructionAllowed(schemaClass2) {
37149
37416
  `Class '${schemaClass2.name}' declares a required constructor, so it cannot be constructed without one.`
37150
37417
  );
37151
37418
  }
37419
+ function constructionReplayContext(descriptor, ctx) {
37420
+ if (ctx.storedConstructionReplay !== true) return ctx;
37421
+ const target = ctx.__storedInitializerReplay;
37422
+ let rowId;
37423
+ let candidate;
37424
+ if (target !== void 0) {
37425
+ const row = storedReplayRowById(target.rowId, ctx);
37426
+ if (row !== null && classIdForValueRow(row, ctx) === descriptor.schemaClass.id) {
37427
+ rowId = target.rowId;
37428
+ candidate = { reattached: false };
37429
+ target.candidates.push(candidate);
37430
+ }
37431
+ } else if (ctx.__executionState?.constructionStack.length === 0 && ctx.__storedConstructionReplaySlot?.classId === descriptor.schemaClass.id) {
37432
+ rowId = ctx.__storedConstructionReplayRowId;
37433
+ }
37434
+ return {
37435
+ ...ctx,
37436
+ __storedInitializerReplay: void 0,
37437
+ __storedReplayCandidate: candidate,
37438
+ __storedConstructionReplayRowId: rowId,
37439
+ __storedConstructionReplayRootId: void 0,
37440
+ __storedConstructionReplaySlot: rowId === void 0 ? ctx.__storedConstructionReplaySlot : {
37441
+ classId: descriptor.schemaClass.id,
37442
+ classArguments: descriptor.classArguments ?? {}
37443
+ }
37444
+ };
37445
+ }
37446
+ function rollbackStoredConstructionReplay(ctx, checkpoint) {
37447
+ if (checkpoint === void 0) return;
37448
+ for (const row of createdSessionValuesSince(ctx, checkpoint))
37449
+ deleteRuntimeSessionValue(ctx, row.id);
37450
+ if (ctx.__storedReplayCandidate !== void 0)
37451
+ ctx.__storedReplayCandidate.reattached = false;
37452
+ }
37152
37453
  function constructClassValue(info, scope, ctx) {
37153
37454
  const descriptor = validateClassConstructorDescriptor(
37154
37455
  info,
37155
37456
  ctx,
37156
37457
  ctx.constructionBaselineReplay !== true
37157
37458
  );
37459
+ ctx = constructionReplayContext(descriptor, ctx);
37158
37460
  assertImplicitConstructionAllowed(descriptor.schemaClass);
37461
+ const replayCheckpoint = ctx.__storedConstructionReplayRowId === void 0 ? void 0 : sessionCreationCheckpoint(ctx);
37159
37462
  const closeFrame = pushConstructionFrame(ctx, descriptor.schemaClass.name);
37160
37463
  try {
37161
37464
  return constructClassValueWithinFrame(descriptor, scope, ctx);
37465
+ } catch (error) {
37466
+ rollbackStoredConstructionReplay(ctx, replayCheckpoint);
37467
+ throw error;
37162
37468
  } finally {
37163
37469
  closeFrame();
37164
37470
  }
@@ -37258,6 +37564,8 @@ function constructClassValueWithinFrame(descriptor, scope, ctx) {
37258
37564
  });
37259
37565
  root.classId = classId;
37260
37566
  stampConstructedRootGenericBindings(root, descriptor);
37567
+ if (ctx.__storedReplayCandidate !== void 0)
37568
+ ctx.__storedReplayCandidate.value = root.value;
37261
37569
  if (typeof root.value !== "object" || root.value === null || Array.isArray(root.value)) {
37262
37570
  throw new Error(
37263
37571
  `Class constructor for '${schemaClass2.name}' produced a non-record root.`
@@ -37687,15 +37995,20 @@ function constructionInitEvaluator(ctx, createdValues, argumentScopes, construct
37687
37995
  sourceValueId: sourceValueId ?? null,
37688
37996
  compileMemberId: scopeMemberId
37689
37997
  });
37998
+ const childId = storedInitializerChildId(member, ctx);
37999
+ const initializerCtx = childId === void 0 ? ctx : {
38000
+ ...ctx,
38001
+ __storedInitializerReplay: { rowId: childId, candidates: [] }
38002
+ };
37690
38003
  const evaluate = (argumentValues = []) => {
37691
- return withConstructionGenericSlots(
38004
+ const result = withConstructionGenericSlots(
37692
38005
  member,
37693
- ctx,
38006
+ initializerCtx,
37694
38007
  genericEnv,
37695
38008
  () => evaluateInitializerInContext(
37696
38009
  init,
37697
38010
  member,
37698
- ctx,
38011
+ initializerCtx,
37699
38012
  createdValues,
37700
38013
  argumentValues,
37701
38014
  sourceValueId ?? null,
@@ -37703,6 +38016,17 @@ function constructionInitEvaluator(ctx, createdValues, argumentScopes, construct
37703
38016
  genericEnv
37704
38017
  )
37705
38018
  );
38019
+ for (const candidate of initializerCtx.__storedInitializerReplay?.candidates ?? []) {
38020
+ if (!candidate.reattached) continue;
38021
+ if (candidate.value !== result.value) {
38022
+ throw new NSGetterRuntimeError(
38023
+ `Stored initializer '${member.name}' constructed an already owned value outside its returned child. Call Clone() explicitly.`
38024
+ );
38025
+ }
38026
+ if (ctx.__storedReplayCandidate !== void 0)
38027
+ ctx.__storedReplayCandidate.reattached = true;
38028
+ }
38029
+ return result;
37706
38030
  };
37707
38031
  const ownerClassId = scopeMemberId === null ? null : owningClassId(scopeMemberId);
37708
38032
  const expectedArgumentCount = compiled.parameters.slice(2).length;
@@ -37915,6 +38239,13 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
37915
38239
  (argument2) => trackedRowForValueReference(argument2, ctx)?.id === existingValueRow.id
37916
38240
  )) {
37917
38241
  assertInitializerPlacement(existingValueRow.id, member, ctx);
38242
+ if (storedInitializerChildId(member, ctx) === existingValueRow.id) {
38243
+ return {
38244
+ value: result.value,
38245
+ classId: existingRuntimeClassId,
38246
+ existingValueRow
38247
+ };
38248
+ }
37918
38249
  }
37919
38250
  if (existingValueRow !== null && existingRuntimeClassId !== null && isClassSlotMember(member)) {
37920
38251
  const storage = constructorArgumentStorage(existingValueRow.id, ctx);
@@ -38118,18 +38449,14 @@ function encodeRequiredConstructorArgument(args) {
38118
38449
  args.ctx.__valueOverlay
38119
38450
  ) !== null ? args.value : null;
38120
38451
  const adoptTracked = (id, suffix) => {
38121
- if (constructorGroupForRow(id, args.ctx) !== null) {
38122
- assertOwnedValueAttachable(
38123
- id,
38124
- {
38125
- identity: `value:${args.ownerRootId}:constructorArg:${args.parameterId}:${suffix}`,
38126
- label: args.ownerRootId
38127
- },
38128
- `constructor argument '${args.parameterId}'`,
38129
- args.ctx,
38130
- true
38131
- );
38132
- }
38452
+ recordConstructorGroupDependency(
38453
+ id,
38454
+ {
38455
+ identity: `value:${args.ownerRootId}:constructorArg:${args.parameterId}:${suffix}`,
38456
+ label: args.ownerRootId
38457
+ },
38458
+ args.ctx
38459
+ );
38133
38460
  return id;
38134
38461
  };
38135
38462
  if (args.typeInfo.type === 21 /* Generic */) {
@@ -39051,7 +39378,8 @@ function constructDeclaredClassValue(info, scope, ctx) {
39051
39378
  const descriptor = validateClassConstructorDescriptor(info, ctx, false);
39052
39379
  const schemaClass2 = descriptor.schemaClass;
39053
39380
  const record4 = resolveDeclaredConstructorRecord(info, schemaClass2, ctx);
39054
- const replayCheckpoint = ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === schemaClass2.id && ctx.__executionState?.constructionStack.length === 0 ? sessionCreationCheckpoint(ctx) : void 0;
39381
+ ctx = constructionReplayContext(descriptor, ctx);
39382
+ const replayCheckpoint = ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === schemaClass2.id ? sessionCreationCheckpoint(ctx) : void 0;
39055
39383
  const closeFrame = pushConstructionFrame(ctx, schemaClass2.name);
39056
39384
  try {
39057
39385
  return constructDeclaredClassValueWithinFrame(
@@ -39062,11 +39390,7 @@ function constructDeclaredClassValue(info, scope, ctx) {
39062
39390
  ctx
39063
39391
  );
39064
39392
  } catch (error) {
39065
- if (replayCheckpoint !== void 0) {
39066
- for (const row of createdSessionValuesSince(ctx, replayCheckpoint)) {
39067
- deleteRuntimeSessionValue(ctx, row.id);
39068
- }
39069
- }
39393
+ rollbackStoredConstructionReplay(ctx, replayCheckpoint);
39070
39394
  throw error;
39071
39395
  } finally {
39072
39396
  closeFrame();
@@ -39127,6 +39451,8 @@ function constructDeclaredClassValueWithinFrame(descriptor, record4, info, scope
39127
39451
  });
39128
39452
  root.classId = classId;
39129
39453
  stampConstructedRootGenericBindings(root, descriptor);
39454
+ if (ctx.__storedReplayCandidate !== void 0)
39455
+ ctx.__storedReplayCandidate.value = root.value;
39130
39456
  } catch (error) {
39131
39457
  if (error instanceof NSGetterRuntimeError) {
39132
39458
  positionAtPassingArgument(error, info, record4, argumentValues, ctx);
@@ -39139,7 +39465,7 @@ function constructDeclaredClassValueWithinFrame(descriptor, record4, info, scope
39139
39465
  `Declared constructor for '${schemaClass2.name}' produced a non-record root.`
39140
39466
  );
39141
39467
  }
39142
- if (ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === classId && ctx.__executionState?.constructionStack.length === 1) {
39468
+ if (ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === classId) {
39143
39469
  ctx = { ...ctx, __storedConstructionReplayRootId: root.id };
39144
39470
  }
39145
39471
  const rootRecord = root.value;
@@ -39303,8 +39629,13 @@ function assertOwnedValueAttachable(valueId, destination, destinationName, ctx,
39303
39629
  ctx,
39304
39630
  preflight?.parentEntries
39305
39631
  )) {
39306
- if (mode === "assign" && ownedAttachmentIdentity(owner, ctx) === ownedAttachmentIdentity(destination, ctx))
39632
+ if (mode === "assign" && ownedAttachmentIdentity(owner, ctx) === ownedAttachmentIdentity(destination, ctx)) {
39633
+ if (ctx.__storedReplayCandidate !== void 0 && ctx.__storedConstructionReplayRowId !== void 0 && owner.identity.startsWith(
39634
+ `value:${ctx.__storedConstructionReplayRowId}:slot:`
39635
+ ))
39636
+ ctx.__storedReplayCandidate.reattached = true;
39307
39637
  continue;
39638
+ }
39308
39639
  const error = new NSGetterRuntimeError(
39309
39640
  `Aggregate value '${valueId}' is already owned by parent value '${owner.label}' and cannot be attached to '${destinationName}'. Call Clone() explicitly.`
39310
39641
  );
@@ -39313,23 +39644,6 @@ function assertOwnedValueAttachable(valueId, destination, destinationName, ctx,
39313
39644
  }
39314
39645
  const reserved = ctx.__executionState?.ownedValueAttachments.get(valueId);
39315
39646
  if (reserved !== void 0 && (mode === "insert" || reserved.identity !== destination.identity)) {
39316
- const constructorArgumentReservation = reserved.identity.startsWith(
39317
- `value:${reserved.label}:constructorArg:`
39318
- );
39319
- const destinationConstructorGroup = constructorGroupForRow(
39320
- destination.label,
39321
- ctx
39322
- );
39323
- if (constructorArgumentReservation && (destination.label === reserved.label || destinationConstructorGroup === reserved.label || preflight?.constructorRootIds.has(reserved.label) === true)) {
39324
- if (preflight === void 0) {
39325
- ctx.__executionState?.ownedValueAttachments.set(valueId, destination);
39326
- recordConstructorGroupDependency(valueId, destination, ctx);
39327
- } else {
39328
- preflight.constructorArgumentTransfers.set(valueId, destination);
39329
- preflight.dependencies.set(valueId, destination);
39330
- }
39331
- return;
39332
- }
39333
39647
  throw new NSGetterRuntimeError(
39334
39648
  `Aggregate value '${valueId}' is already owned by parent value '${reserved.label}' and cannot be attached to '${destinationName}'. Call Clone() explicitly.`
39335
39649
  );
@@ -39341,6 +39655,29 @@ function assertOwnedValueAttachable(valueId, destination, destinationName, ctx,
39341
39655
  recordConstructorGroupDependency(valueId, destination, ctx);
39342
39656
  else preflight.dependencies.set(valueId, destination);
39343
39657
  }
39658
+ function storedReplayRowById(id, ctx) {
39659
+ ctx.valueDependencies?.add(id);
39660
+ ctx.__getterReads?.add(id);
39661
+ const database = ctx.vm.databaseVM;
39662
+ if (database?.storedValueById !== void 0)
39663
+ return database.storedValueById(id);
39664
+ if (database?.evaluatorIndexes !== void 0)
39665
+ return database.evaluatorIndexes.valueById.get(id) ?? null;
39666
+ return ctx.vm.values.find((row) => row.id === id) ?? null;
39667
+ }
39668
+ function storedInitializerChildId(member, ctx) {
39669
+ if (ctx.storedConstructionReplay !== true) return void 0;
39670
+ const parentId = ctx.__storedConstructionReplayRowId;
39671
+ const memberId = Reflect.get(member, "id");
39672
+ if (parentId === void 0 || typeof memberId !== "string") return void 0;
39673
+ const parent = storedReplayRowById(parentId, ctx);
39674
+ if (parent?.value === null || typeof parent?.value !== "object")
39675
+ return void 0;
39676
+ const schemaKey = cachedSchemaKeyForMember(memberId, ctx);
39677
+ if (schemaKey === null) return void 0;
39678
+ const childId = Reflect.get(parent.value, schemaKey);
39679
+ return typeof childId === "string" ? childId : void 0;
39680
+ }
39344
39681
  function assertInitializerPlacement(valueId, member, ctx) {
39345
39682
  const replayRowId = ctx.__storedConstructionReplayRowId;
39346
39683
  const memberId = Reflect.get(member, "id");
@@ -39378,7 +39715,7 @@ function ownershipParentEntryKeys(value, valueId, cache) {
39378
39715
  }
39379
39716
  return entries.get(valueId) ?? [];
39380
39717
  }
39381
- function currentOwnedValueAttachments(valueId, ctx, parentEntries, placingMembers) {
39718
+ function currentOwnedValueAttachments(valueId, ctx, parentEntries) {
39382
39719
  const indexes4 = evaluatorIndexes(ctx);
39383
39720
  const cached = indexes4.ownedValueAttachmentsByValueId.get(valueId);
39384
39721
  if (cached !== void 0) return [...cached];
@@ -39427,7 +39764,7 @@ function currentOwnedValueAttachments(valueId, ctx, parentEntries, placingMember
39427
39764
  ownershipChainRead("owned-value-parents", valueId)
39428
39765
  );
39429
39766
  const parentIds = new Set(
39430
- evaluatorParentLinks(indexes4, valueId).map((link) => link.parentId)
39767
+ evaluatorParentLinks(indexes4, valueId, true).map((link) => link.parentId)
39431
39768
  );
39432
39769
  for (const parentId of parentIds) {
39433
39770
  const parent = evalValueById(
@@ -39441,14 +39778,7 @@ function currentOwnedValueAttachments(valueId, ctx, parentEntries, placingMember
39441
39778
  let member = null;
39442
39779
  let classId = parent.classId;
39443
39780
  if (classId === void 0 || classId === null) {
39444
- member = activeStaticBindingRoot(parent.id, ctx)?.member ?? (placingMembers === void 0 ? memberForValueRow(parent, ctx) : placingMember(
39445
- parent,
39446
- ctx,
39447
- void 0,
39448
- 0,
39449
- placingMembers,
39450
- parentEntries
39451
- ));
39781
+ member = activeStaticBindingRoot(parent.id, ctx)?.member ?? memberForValueRow(parent, ctx);
39452
39782
  if (member !== null) {
39453
39783
  try {
39454
39784
  member = resolveMember(member, ctx.vm.members);
@@ -39837,6 +40167,35 @@ function materializeConstructorArgumentValue(args) {
39837
40167
  args.destinationName ?? args.member.name,
39838
40168
  args.ctx
39839
40169
  );
40170
+ if (args.insertedCollections !== void 0 && (isMemberEntryCollectionBase(args.member) || isMemberDictionaryBase(args.member)) && typeof args.value === "object" && args.value !== null) {
40171
+ const tracked = trackedRowForValueReference(args.value, args.ctx);
40172
+ if (tracked !== null) {
40173
+ if (args.owner === void 0)
40174
+ throw new NSGetterRuntimeError(
40175
+ "Inserted collection has no destination."
40176
+ );
40177
+ if (!args.attachmentReservations?.has(tracked.id))
40178
+ args.attachmentReservations?.set(
40179
+ tracked.id,
40180
+ args.ctx.__executionState?.ownedValueAttachments.get(tracked.id)
40181
+ );
40182
+ assertOwnedValueAttachable(
40183
+ tracked.id,
40184
+ args.owner,
40185
+ args.destinationName ?? args.member.name,
40186
+ args.ctx,
40187
+ true,
40188
+ "insert"
40189
+ );
40190
+ return tracked;
40191
+ }
40192
+ const identity2 = args.value instanceof RuntimeSet ? args.value.source : args.value;
40193
+ if (args.insertedCollections.has(identity2))
40194
+ throw new NSGetterRuntimeError(
40195
+ "Inserted collection graph contains a duplicate owned collection. Call Clone() explicitly."
40196
+ );
40197
+ args.insertedCollections.add(identity2);
40198
+ }
39840
40199
  const collectionAlias = args.value;
39841
40200
  if (args.value instanceof RuntimeSet)
39842
40201
  args = {
@@ -39887,7 +40246,7 @@ function materializeConstructorArgumentValue(args) {
39887
40246
  args.ctx
39888
40247
  )
39889
40248
  );
39890
- if (collectionAlias instanceof RuntimeSet)
40249
+ if (collectionAlias instanceof RuntimeSet && isMultiSelectionMember(args.member) === true)
39891
40250
  args.collectionAliases?.set(row, collectionAlias);
39892
40251
  return row;
39893
40252
  }
@@ -41536,11 +41895,23 @@ function derivedTupleElementMemberId(parentMemberId, index) {
41536
41895
  );
41537
41896
  }
41538
41897
 
41898
+ // ../src/models/members/entry-member-id.ts
41899
+ var NEO_ENTRY_MEMBER_NAMESPACE = "4d1c4a2f-1a0f-5f3e-9a5c-2b7d6e8f0c31";
41900
+ function derivedEntryMemberId(declaringMemberId) {
41901
+ return inSystemRecordNamespaceOf(
41902
+ declaringMemberId,
41903
+ v5_default(
41904
+ withoutSystemRecordIdPrefix(declaringMemberId),
41905
+ NEO_ENTRY_MEMBER_NAMESPACE
41906
+ )
41907
+ );
41908
+ }
41909
+
41539
41910
  // ../src/database/compiled-construction-types.ts
41540
41911
  function compiledConstructionTypeMembers(members2, bodies, projectId) {
41541
41912
  const created = [];
41542
- const createdKeys = [];
41543
- let existingIds;
41913
+ const processedKeys = [];
41914
+ let existingMembers;
41544
41915
  const byType = /* @__PURE__ */ new Map();
41545
41916
  const key = (type2) => canonicalJsonStringify(type2);
41546
41917
  const intern = (type2, slot) => {
@@ -41553,21 +41924,21 @@ function compiledConstructionTypeMembers(members2, bodies, projectId) {
41553
41924
  `neo:compiled-construction-type:${projectId}:${cacheKey}`,
41554
41925
  v5_default.URL
41555
41926
  );
41556
- existingIds ??= new Set(members2.map((member) => member.id));
41557
- if (existingIds.has(id)) {
41558
- byType.set(cacheKey, id);
41559
- return id;
41560
- }
41927
+ existingMembers ??= new Map(members2.map((member) => [member.id, member]));
41928
+ const storedMember = existingMembers.get(id);
41929
+ const alreadyStored = storedMember !== void 0;
41561
41930
  const common = {
41562
41931
  id,
41563
41932
  projectId,
41564
41933
  createdAt: 0,
41565
41934
  updatedAt: 0,
41566
41935
  name: slot?.name ?? "Type argument",
41936
+ ...slot?.format === void 0 ? {} : { format: slot.format },
41567
41937
  kind: type2.type,
41568
41938
  requirement: type2.required ? 1 /* Required */ : 0 /* Optional */
41569
41939
  };
41570
41940
  const mark = created.length;
41941
+ const processedMark = processedKeys.length;
41571
41942
  const fields = (() => {
41572
41943
  if (type2.type === 30 /* Tuple */) {
41573
41944
  const elementMemberIds = [];
@@ -41582,7 +41953,15 @@ function compiledConstructionTypeMembers(members2, bodies, projectId) {
41582
41953
  return { elementMemberIds };
41583
41954
  }
41584
41955
  if (type2.type === 6 /* List */ || type2.type === 28 /* Set */ || type2.type === 5 /* Dictionary */) {
41585
- const entryMemberId = intern(type2.entryTypeInfo);
41956
+ const storedEntryId = getField(storedMember, "entryMemberId");
41957
+ const entryMemberId = intern(
41958
+ type2.entryTypeInfo,
41959
+ type2.type === 28 /* Set */ && type2.entryTypeInfo.type === 3 /* String */ ? {
41960
+ id: typeof storedEntryId === "string" ? storedEntryId : derivedEntryMemberId(id),
41961
+ name: "Item",
41962
+ format: 1 /* Plain */
41963
+ } : void 0
41964
+ );
41586
41965
  if (entryMemberId === null) return null;
41587
41966
  return {
41588
41967
  entryMemberId,
@@ -41614,6 +41993,16 @@ function compiledConstructionTypeMembers(members2, bodies, projectId) {
41614
41993
  } else if (type2.type === 26 /* NSAction */) {
41615
41994
  return { argumentTypes: namedArguments(type2.argumentTypes) };
41616
41995
  } else if (type2.type === 29 /* Reference */) {
41996
+ const target = type2.targetTypeInfo;
41997
+ if (target.type === 6 /* List */ || target.type === 5 /* Dictionary */ || target.type === 28 /* Set */) {
41998
+ intern(target);
41999
+ } else if (target.type === 9 /* Lookup */ && target.collectionMemberId === void 0 && target.collectionValueId === void 0 && target.entryTypeInfo.type !== NS_TYPE_UNKNOWN && target.entryTypeInfo.required && SET_ENTRY_MEMBER_KINDS.has(target.entryTypeInfo.type)) {
42000
+ intern({
42001
+ type: 28 /* Set */,
42002
+ required: target.required,
42003
+ entryTypeInfo: target.entryTypeInfo
42004
+ });
42005
+ }
41617
42006
  return {
41618
42007
  kind: 9 /* Lookup */,
41619
42008
  declaredTypeInfo: type2.targetTypeInfo
@@ -41625,13 +42014,16 @@ function compiledConstructionTypeMembers(members2, bodies, projectId) {
41625
42014
  }
41626
42015
  })();
41627
42016
  if (fields === null) {
41628
- for (const member of created.splice(mark)) existingIds.delete(member.id);
41629
- for (const key2 of createdKeys.splice(mark)) byType.delete(key2);
41630
- return null;
41631
- }
41632
- created.push({ ...common, ...fields });
41633
- createdKeys.push(cacheKey);
41634
- existingIds.add(id);
42017
+ for (const member of created.splice(mark))
42018
+ existingMembers.delete(member.id);
42019
+ for (const key2 of processedKeys.splice(processedMark)) byType.delete(key2);
42020
+ if (!alreadyStored) return null;
42021
+ } else if (!alreadyStored) {
42022
+ const member = { ...common, ...fields };
42023
+ created.push(member);
42024
+ existingMembers.set(id, member);
42025
+ }
42026
+ processedKeys.push(cacheKey);
41635
42027
  byType.set(cacheKey, id);
41636
42028
  return id;
41637
42029
  };
@@ -53426,8 +53818,8 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
53426
53818
  this.persistingMethodGroup = false;
53427
53819
  }
53428
53820
  }
53429
- /** P112 §2.2. Checks a stored default's `Reference(place)` the push can't settle. */
53430
- resolvePersistedReference(expression, expected) {
53821
+ /** Check an initializer with its expected type, including contextual expressions. */
53822
+ validateInitializerExpression(expression, expected) {
53431
53823
  const resolved = this.resolveExpression(
53432
53824
  expression,
53433
53825
  this.initialScope(),
@@ -59201,6 +59593,8 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
59201
59593
  }
59202
59594
  const staticType = this.project.typeByName.get(receiverAst.name);
59203
59595
  if (staticType && staticType.kind !== "enum") {
59596
+ if (receiverAst.typeQualifier)
59597
+ this.resolveType(receiverAst.typeQualifier);
59204
59598
  this.assertUserSafe(
59205
59599
  { kind: "named", typeId: staticType.id },
59206
59600
  "a static receiver",
@@ -59340,6 +59734,9 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
59340
59734
  pointer: listIndexPointer(receiver.pointer, index),
59341
59735
  type: viewType,
59342
59736
  writability: "readOnly" /* ReadOnly */,
59737
+ ...receiver.entryWritability !== void 0 ? { entryWritability: receiver.entryWritability } : {},
59738
+ entryUserData: receiver.entryUserData === true,
59739
+ ...receiver.writeRoot !== void 0 ? { writeRoot: receiver.writeRoot } : {},
59343
59740
  indexDefinition: index,
59344
59741
  indexCollectionPointer: receiver.pointer
59345
59742
  };
@@ -59348,7 +59745,10 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
59348
59745
  return {
59349
59746
  pointer: receiver.pointer,
59350
59747
  type: { kind: "primitive", name: "unknown" },
59351
- indexSurface: receiver.type
59748
+ indexSurface: receiver.type,
59749
+ entryWritability: receiver.entryWritability ?? receiver.writability ?? "runtime" /* Runtime */,
59750
+ entryUserData: receiver.entryWritability === void 0 ? receiver.userData === true : receiver.entryUserData === true,
59751
+ writeRoot: this.expressionWriteRoot(receiver, scope)
59352
59752
  };
59353
59753
  }
59354
59754
  if ((name === "Keys" || name === "Values") && receiver.type.kind === "dictionary") {
@@ -59623,7 +60023,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
59623
60023
  pos
59624
60024
  );
59625
60025
  }
59626
- if (entry.id.startsWith(NEOSCRIPT_PENDING_SYMBOL_ID_PREFIX)) {
60026
+ if (entry.id.startsWith(NEOSCRIPT_PENDING_SYMBOL_ID_PREFIX) && !this.options.allowPendingRegistryEntries) {
59627
60027
  throw new CompileError(
59628
60028
  `${registry.entryType} '${name}' has no @id, so it has never been pushed and has no project file to reference. Push the file before referencing it.`,
59629
60029
  pos
@@ -59751,7 +60151,10 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
59751
60151
  key.pointer
59752
60152
  ),
59753
60153
  type: resultType,
59754
- writability: "readOnly" /* ReadOnly */
60154
+ writability: "readOnly" /* ReadOnly */,
60155
+ ...receiver.entryWritability !== void 0 ? { entryWritability: receiver.entryWritability } : {},
60156
+ entryUserData: receiver.entryUserData === true,
60157
+ ...receiver.writeRoot !== void 0 ? { writeRoot: receiver.writeRoot } : {}
59755
60158
  };
59756
60159
  }
59757
60160
  const readonlyCollection = receiver.symbol?.readonlyDeclaration === true && receiver.initWritability !== void 0 ? {
@@ -60587,6 +60990,8 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
60587
60990
  }
60588
60991
  const staticType = this.project.typeByName.get(callee.receiver.name);
60589
60992
  if (staticType && staticType.kind !== "enum") {
60993
+ if (callee.receiver.typeQualifier)
60994
+ this.resolveType(callee.receiver.typeQualifier);
60590
60995
  this.assertUserSafe(
60591
60996
  { kind: "named", typeId: staticType.id },
60592
60997
  "a static receiver",
@@ -78161,15 +78566,7 @@ function calculateDeclarationSignature(ctx, projectionClassId, schemaKey, declar
78161
78566
  declarationClassId: declaration.classDef.id,
78162
78567
  memberId: declaration.memberId,
78163
78568
  isAbstract: isAbstractMember(member) === true,
78164
- isVirtual: isVirtualMember(member) !== false,
78165
- // Openness belongs to the DECLARING class, not to whoever is asking: a
78166
- // descendant that closes the param still has to see a declaration it is
78167
- // obliged to implement.
78168
- requiresClosingImplementation: lookupDeclaredTypeInfo2(member) === null ? false : lookupNarrowingAwaitsClosingBinding(
78169
- ctx,
78170
- member,
78171
- resolveGenericEnvForEmission(ctx, declaration.classDef.id)
78172
- )
78569
+ isVirtual: isVirtualMember(member) !== false
78173
78570
  };
78174
78571
  if (isCallableMemberForCodegen(member)) {
78175
78572
  const parameterTypes = member.argumentTypes.map(
@@ -78379,7 +78776,7 @@ function generatedInstanceMemberSignaturesEqual(left, right) {
78379
78776
  return false;
78380
78777
  }
78381
78778
  function emitsAbstractDeclaration(signature) {
78382
- return signature.isAbstract || signature.requiresClosingImplementation;
78779
+ return signature.isAbstract;
78383
78780
  }
78384
78781
  function resolveGeneratedInstanceMemberPlan(ctx, classDef, schemaKey) {
78385
78782
  const declaration = ownInstanceMemberDeclaration(classDef, schemaKey);
@@ -80437,41 +80834,6 @@ function lookupDeclaredTypeInfo2(member) {
80437
80834
  if (!isMemberLookupBase(member)) return null;
80438
80835
  return member.declaredTypeInfo ?? null;
80439
80836
  }
80440
- function lookupTargetClassProjection(ctx, member, env) {
80441
- if (!isMemberLookupBase(member)) return null;
80442
- const declaredTypeInfo = lookupDeclaredTypeInfo2(member);
80443
- if (declaredTypeInfo === null) {
80444
- const entryMember = resolveLookupEntryMember(ctx, member);
80445
- if (entryMember === null) return null;
80446
- if (!isClassTypedMember(entryMember)) return null;
80447
- return {
80448
- classId: entryMember.classId,
80449
- constructedSuffix: constructedTypeArgumentsSuffix(ctx, entryMember, true, env) ?? ""
80450
- };
80451
- }
80452
- if (declaredTypeInfo.type === 7 /* Class */) {
80453
- return {
80454
- classId: declaredTypeInfo.classId,
80455
- constructedSuffix: typeInfoConstructedSuffix(ctx, declaredTypeInfo, true, env) ?? ""
80456
- };
80457
- }
80458
- if (declaredTypeInfo.type !== 21 /* Generic */) return null;
80459
- if (!isClassGenericParamTypeInfo(declaredTypeInfo)) return null;
80460
- const entry = env?.get(declaredTypeInfo.genericParamId);
80461
- if (entry === void 0) return null;
80462
- if (entry.kind !== "member") return null;
80463
- const bindingMember = resolveMemberById(
80464
- ctx,
80465
- entry.memberId,
80466
- `classes.${declaredTypeInfo.ownerClassId}.genericParams.${declaredTypeInfo.genericParamId}`
80467
- );
80468
- if (bindingMember === null) return null;
80469
- if (!isClassTypedMember(bindingMember)) return null;
80470
- return {
80471
- classId: bindingMember.classId,
80472
- constructedSuffix: constructedTypeArgumentsSuffix(ctx, bindingMember, true, env) ?? ""
80473
- };
80474
- }
80475
80837
  function referenceHandleTypeInfo(ctx, reference) {
80476
80838
  const target = reference.targetTypeInfo;
80477
80839
  if (referenceCategory(target, classConstrainedGenerics(ctx.classes)) !== "handle" /* Handle */) {
@@ -80535,11 +80897,6 @@ function lookupReferenceElementType(ctx, member, env) {
80535
80897
  function lookupNarrowsThroughGenericParam(member) {
80536
80898
  return lookupDeclaredTypeInfo2(member)?.type === 21 /* Generic */;
80537
80899
  }
80538
- function lookupNarrowingAwaitsClosingBinding(ctx, member, env) {
80539
- if (!lookupNarrowsThroughGenericParam(member)) return false;
80540
- if (lookupProjection(ctx, member) !== "class" /* Class */) return false;
80541
- return lookupTargetClassProjection(ctx, member, env) === null;
80542
- }
80543
80900
  function lookupTargetValueType(ctx, member, saved, env) {
80544
80901
  if (!isMemberLookupBase(member)) return "NeoLookupSelection";
80545
80902
  const targetSaved = lookupTargetSaved(ctx, member) ?? saved;