@neocompose/cli 0.89.12 → 0.89.14

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.
@@ -19377,7 +19377,7 @@ var init_registry = __esm({
19377
19377
  "../packages/manifest/schema-contract/registry.mjs"() {
19378
19378
  "use strict";
19379
19379
  PROJECT_SCHEMA_CONTRACT = Object.freeze({
19380
- cliVersion: "0.89.12",
19380
+ cliVersion: "0.89.14",
19381
19381
  projectFileUploadBatchSize: 32,
19382
19382
  documentRecords: {
19383
19383
  member: {
@@ -25194,6 +25194,10 @@ function* staticMembersInitializedByName(analysis, syntax) {
25194
25194
  }
25195
25195
  }
25196
25196
  }
25197
+ function pendingLocalValueId(global) {
25198
+ const source = global.source;
25199
+ return `__pending__:value:${encodeURIComponent(source.uri)}:${source.range.start.line}:${source.range.start.character}:${encodeURIComponent(global.name)}`;
25200
+ }
25197
25201
  function typeText(type2) {
25198
25202
  return type2.name + (type2.arguments.length === 0 ? "" : `<${type2.arguments.map(typeText).join(", ")}>`) + (type2.nullable ? "?" : "");
25199
25203
  }
@@ -25243,6 +25247,7 @@ var init_local_values = __esm({
25243
25247
  resolve(expression, source, valueId) {
25244
25248
  if (expression.kind !== "ident") return { expression, source };
25245
25249
  let text;
25250
+ let pendingIdentity;
25246
25251
  for (const step of this.chain(expression.name)) {
25247
25252
  const global = step.global;
25248
25253
  if (valueId !== void 0) {
@@ -25264,8 +25269,9 @@ var init_local_values = __esm({
25264
25269
  source: global.source,
25265
25270
  label: global.name
25266
25271
  };
25272
+ pendingIdentity = this.scalarTypes.has(global.type.name) ? void 0 : pendingLocalValueId(global);
25267
25273
  }
25268
- return { expression, source, text };
25274
+ return { expression, source, text, pendingIdentity };
25269
25275
  }
25270
25276
  /**
25271
25277
  * The expression and text a bare local name stands for, through any alias
@@ -25303,7 +25309,7 @@ var init_local_values = __esm({
25303
25309
  * Compile authoring locals without introducing runtime globals. The splices
25304
25310
  * are the uses of `code` this replaced.
25305
25311
  */
25306
- executable(code, runtimeIdentifiers = /* @__PURE__ */ new Set(), materializationRoot, identity3, storedValueAtPath) {
25312
+ executable(code, runtimeIdentifiers = /* @__PURE__ */ new Set(), materializationRoot, identity3) {
25307
25313
  if (this.definitions.size === 0 || !mayUseLocalInitializer(code, this.definitions))
25308
25314
  return { code, splices: [] };
25309
25315
  const terminalName = (name) => {
@@ -25380,23 +25386,40 @@ var init_local_values = __esm({
25380
25386
  const annotation2 = terminal2.expression.kind === "annotated" ? terminal2.expression.annotations.find(
25381
25387
  (entry) => entry.name === "id"
25382
25388
  )?.args[0] : void 0;
25383
- const existingId = storedValueAtPath?.(
25384
- materializationRoot,
25385
- placementPath
25386
- );
25387
- if (annotation2?.kind === "litString" && existingId !== annotation2.value) {
25388
- throw new Error(
25389
- `Local initializer ${terminal2.global.name} has an @id that does not identify its existing row inside this constructor-backed owner. Remove that @id and let preparation assign the owning tree, or place the value directly in its own static member.`
25390
- );
25391
- }
25392
25389
  const source = terminal2.global.source;
25393
25390
  const suffix = this.scalarTypes.has(terminal2.global.type.name) ? `:${encodeURIComponent(JSON.stringify([materializationRoot, placementPath]))}` : "";
25394
- const id2 = annotation2?.kind === "litString" ? annotation2.value : `__pending__:value:${encodeURIComponent(source.uri)}:${source.range.start.line}:${source.range.start.character}:${encodeURIComponent(terminal2.global.name)}${suffix}`;
25391
+ const id2 = annotation2?.kind === "litString" ? annotation2.value : `${pendingLocalValueId(terminal2.global)}${suffix}`;
25392
+ if (annotation2?.kind === "litString")
25393
+ identity3?.validateAuthoredId?.(id2);
25395
25394
  for (const { global } of steps) {
25396
25395
  const owners = this.owners.get(global.name) ?? /* @__PURE__ */ new Map();
25397
- owners.set(existingId ?? id2, global.name);
25396
+ owners.set(id2, global.name);
25398
25397
  this.owners.set(global.name, owners);
25399
25398
  }
25399
+ const normalizeLocation = (rootId, path2) => {
25400
+ const seen = /* @__PURE__ */ new Set();
25401
+ let location4 = { rootId, path: path2 };
25402
+ while (!seen.has(location4.rootId)) {
25403
+ seen.add(location4.rootId);
25404
+ const parent = identity3?.sites.get(location4.rootId)?.materializedLocation ?? identity3?.storedParent?.(location4.rootId);
25405
+ if (parent === void 0) break;
25406
+ location4 = {
25407
+ rootId: parent.rootId,
25408
+ path: [...parent.path, ...location4.path]
25409
+ };
25410
+ }
25411
+ return location4;
25412
+ };
25413
+ const location3 = normalizeLocation(
25414
+ materializationRoot,
25415
+ placementPath
25416
+ );
25417
+ const prior = identity3?.sites.get(id2)?.materializedLocation;
25418
+ const priorLocation = prior === void 0 ? void 0 : normalizeLocation(prior.rootId, prior.path);
25419
+ if (priorLocation !== void 0 && (priorLocation.rootId !== location3.rootId || JSON.stringify(priorLocation.path) !== JSON.stringify(location3.path)))
25420
+ throw new Error(
25421
+ `Local value ${terminal2.global.name} has two owning assignments. Use Reference(${terminal2.global.name}) for a reference, or duplicate its initializer.`
25422
+ );
25400
25423
  identity3?.sites.set(id2, {
25401
25424
  id: id2,
25402
25425
  uri: source.uri,
@@ -25406,8 +25429,10 @@ var init_local_values = __esm({
25406
25429
  stampForm: 0 /* Prefix */,
25407
25430
  nestedListEntries: identity3.localListEntries(terminal2.global),
25408
25431
  materializedLocation: {
25409
- rootId: materializationRoot,
25410
- path: placementPath
25432
+ preserveIdentity: !this.scalarTypes.has(
25433
+ terminal2.global.type.name
25434
+ ),
25435
+ ...location3
25411
25436
  },
25412
25437
  stampIdentity: annotation2 === void 0 && !this.scalarTypes.has(terminal2.global.type.name)
25413
25438
  });
@@ -36196,7 +36221,7 @@ function initializerEvaluatorCacheRevision(document) {
36196
36221
  function initializerReadDependenciesEqual(left, right) {
36197
36222
  if (left === right) return true;
36198
36223
  if (left === null || right === null) return false;
36199
- return left.hasUnattributableValueRead === right.hasUnattributableValueRead && left.hasValuePlacementRead === right.hasValuePlacementRead && setsEqual(left.valueIds, right.valueIds) && setsEqual(left.localizedTextIds, right.localizedTextIds) && setsEqual(left.variantIds, right.variantIds) && setsEqual(left.containerIds, right.containerIds) && setsEqual(left.staticMemberIds, right.staticMemberIds) && left.worldQueries.equals(right.worldQueries);
36224
+ return left.hasUnattributableValueRead === right.hasUnattributableValueRead && left.hasValuePlacementRead === right.hasValuePlacementRead && left.hasUnnamedValuePlacementRead === right.hasUnnamedValuePlacementRead && setsEqual(left.placementIds, right.placementIds) && setsEqual(left.valueIds, right.valueIds) && setsEqual(left.localizedTextIds, right.localizedTextIds) && setsEqual(left.variantIds, right.variantIds) && setsEqual(left.containerIds, right.containerIds) && setsEqual(left.staticMemberIds, right.staticMemberIds) && left.worldQueries.equals(right.worldQueries);
36200
36225
  }
36201
36226
  var InitializerReadSet;
36202
36227
  var init_initializer_context = __esm({
@@ -36213,6 +36238,8 @@ var init_initializer_context = __esm({
36213
36238
  staticMemberIds = /* @__PURE__ */ new Set();
36214
36239
  worldQueries = new WorldGridQueryReadSet();
36215
36240
  hasValuePlacementRead = false;
36241
+ hasUnnamedValuePlacementRead = false;
36242
+ placementIds = /* @__PURE__ */ new Set();
36216
36243
  hasUnattributableValueRead = false;
36217
36244
  /**
36218
36245
  * The unattributable reads by scope, for a fork of the same document to
@@ -36236,8 +36263,10 @@ var init_initializer_context = __esm({
36236
36263
  return;
36237
36264
  }
36238
36265
  };
36239
- recordValuePlacementRead = () => {
36266
+ recordValuePlacementRead = (valueId) => {
36240
36267
  this.hasValuePlacementRead = true;
36268
+ if (valueId === void 0) this.hasUnnamedValuePlacementRead = true;
36269
+ else this.placementIds.add(valueId);
36241
36270
  };
36242
36271
  };
36243
36272
  }
@@ -36861,6 +36890,7 @@ var init_getter_subscriptions = __esm({
36861
36890
  const reads = new InitializerReadSet();
36862
36891
  for (const key of [
36863
36892
  "valueIds",
36893
+ "placementIds",
36864
36894
  "localizedTextIds",
36865
36895
  "variantIds",
36866
36896
  "containerIds",
@@ -36872,6 +36902,7 @@ var init_getter_subscriptions = __esm({
36872
36902
  for (const read of source.reads.worldQueries)
36873
36903
  reads.worldQueries.add(read);
36874
36904
  reads.hasValuePlacementRead = source.reads.hasValuePlacementRead;
36905
+ reads.hasUnnamedValuePlacementRead = source.reads.hasUnnamedValuePlacementRead;
36875
36906
  reads.hasUnattributableValueRead = source.reads.hasUnattributableValueRead;
36876
36907
  cloned.setReads(copy, reads);
36877
36908
  }
@@ -51098,6 +51129,13 @@ function applyConstructorFields(args) {
51098
51129
  let kept = 0;
51099
51130
  for (const row of createdValues) {
51100
51131
  if (row.id === keptId || row.containerId === keptId) {
51132
+ if (row.containerId === keptId) {
51133
+ if (ctx.__indexes !== void 0)
51134
+ unindexEvaluatorRow(ctx.__indexes, row);
51135
+ delete row.containerId;
51136
+ if (ctx.__indexes !== void 0)
51137
+ indexEvaluatorRow(ctx.__indexes, row);
51138
+ }
51101
51139
  createdById.delete(row.id);
51102
51140
  continue;
51103
51141
  }
@@ -54309,6 +54347,9 @@ function materializeConstructorArgumentValue(args) {
54309
54347
  for (const entry of rows) sourceEntries.push(entry.value);
54310
54348
  }
54311
54349
  const ids = [];
54350
+ const authoredEntries = args.ctx.__constructionEntryIds === void 0 ? void 0 : [];
54351
+ if (authoredEntries !== void 0)
54352
+ args.ctx.__constructionEntryIds?.set(row.id, authoredEntries);
54312
54353
  const references = recordedReferenceEntries(sourceEntries, args.ctx) ?? (args.collectionEntriesAreReferences === false ? 1 /* Values */ : collectionReferences(sourceEntries, args.ctx));
54313
54354
  for (const [index, rawEntry] of sourceEntries.entries()) {
54314
54355
  if (args.collectionOwnerId !== void 0 && args.collectionEntriesAreReferences !== false && isReferenceEntry(references, index) && typeof rawEntry === "string" && evalValueById(
@@ -54318,6 +54359,7 @@ function materializeConstructorArgumentValue(args) {
54318
54359
  args.ctx.__valueOverlay
54319
54360
  ) !== null) {
54320
54361
  ids.push(rawEntry);
54362
+ authoredEntries?.push(rawEntry);
54321
54363
  continue;
54322
54364
  }
54323
54365
  const entryValue = constructorCollectionEntryValue(
@@ -54339,6 +54381,7 @@ function materializeConstructorArgumentValue(args) {
54339
54381
  },
54340
54382
  destinationName: `${args.member.name}[${index}]`
54341
54383
  });
54384
+ authoredEntries?.push(child2.id);
54342
54385
  if (listKindOf(args.member) === 1 /* Unordered */) {
54343
54386
  child2.containerId = row.id;
54344
54387
  } else {
@@ -57427,7 +57470,16 @@ var init_constructor_argument_ownership = __esm({
57427
57470
  ownershipFacts() {
57428
57471
  if (this.ownership !== void 0) return this.ownership;
57429
57472
  const targetValueIds = new Set(this.valuesById.keys());
57430
- const owners = resolveOwnerMembersForValues(this.document, targetValueIds);
57473
+ const owners = resolveOwnerMembersForValues(
57474
+ this.document,
57475
+ targetValueIds,
57476
+ [...this.contextualRootMembersByValueId ?? []].map(
57477
+ ([valueId, member]) => ({
57478
+ valueId,
57479
+ member: resolveMember(member, this.document.members)
57480
+ })
57481
+ )
57482
+ );
57431
57483
  this.ownership = {
57432
57484
  owners,
57433
57485
  independentlyOwnedValueIds: new Set(owners.keys())
@@ -57750,6 +57802,7 @@ function evaluateInitializerMaterialization(args) {
57750
57802
  const createdValues = [];
57751
57803
  const storageKeyDeclarations = /* @__PURE__ */ new Map();
57752
57804
  const evaluated = args.evaluateInitializer({
57805
+ constructionEntryIds: args.constructionEntryIds,
57753
57806
  randomSource: args.randomSource,
57754
57807
  genericEnv: args.genericEnv,
57755
57808
  init: args.init,
@@ -57829,7 +57882,9 @@ function finalizeMaterializedRoot(args) {
57829
57882
  });
57830
57883
  }
57831
57884
  function materializeInitializerValue(args) {
57885
+ const constructionEntryIds = args.captureConstructionEntries ? /* @__PURE__ */ new Map() : void 0;
57832
57886
  const { evaluated, createdValues, storageKeyDeclarations } = evaluateInitializerMaterialization({
57887
+ constructionEntryIds,
57833
57888
  randomSource: args.randomSource,
57834
57889
  evaluateInitializer: args.evaluateInitializer,
57835
57890
  init: args.row.init,
@@ -57881,6 +57936,7 @@ function materializeInitializerValue(args) {
57881
57936
  return {
57882
57937
  root,
57883
57938
  createdValues,
57939
+ constructionEntryIds,
57884
57940
  snapshot: evaluated.snapshot,
57885
57941
  pinnedRootSchemaKeys: evaluated.pinnedRootSchemaKeys ?? /* @__PURE__ */ new Set(),
57886
57942
  pinnedSchemaKeysByValueId: evaluated.pinnedSchemaKeysByValueId ?? /* @__PURE__ */ new Map()
@@ -58598,7 +58654,7 @@ function buildVirtualInstanceMaterializedIndex(args) {
58598
58654
  return {
58599
58655
  rows,
58600
58656
  rowsById,
58601
- graph: new MaterializedValueGraphContext(
58657
+ graph: args.materializedGraph ?? new MaterializedValueGraphContext(
58602
58658
  { ...args.document, values: rows },
58603
58659
  rowsById
58604
58660
  ),
@@ -58707,7 +58763,9 @@ function materializationReadTracking(recorder) {
58707
58763
  for (const read of readTracking.worldQueries) {
58708
58764
  recorder.recordWorldQueryRead?.(read);
58709
58765
  }
58710
- if (readTracking.hasValuePlacementRead) {
58766
+ for (const id2 of readTracking.placementIds)
58767
+ recorder.recordValuePlacementRead(id2);
58768
+ if (readTracking.hasUnnamedValuePlacementRead) {
58711
58769
  recorder.recordValuePlacementRead();
58712
58770
  }
58713
58771
  for (const containerId of readTracking.containerEntryReadIds) {
@@ -59081,7 +59139,9 @@ function resolveVirtualInstanceGraph(args) {
59081
59139
  if (parent !== void 0 && isMemberEntryCollectionBase(parent.member) && listKindOf(parent.member) === 1 /* Unordered */)
59082
59140
  effective.containerId = parentId;
59083
59141
  }
59084
- if (isClassSlotMember(indexed.member) && effective.value !== null) {
59142
+ if (args.opaquePaths?.has(pathKey)) {
59143
+ effective.value = materialized?.value ?? indexed.expandedRow.value;
59144
+ } else if (isClassSlotMember(indexed.member) && effective.value !== null) {
59085
59145
  const storedRecord = stringRecord(materialized?.value);
59086
59146
  const classId = rowClassId(indexed.member, effective);
59087
59147
  const constructedChildren = materialized === null ? /* @__PURE__ */ new Map() : settledAggregateChildren(materialized, classId, pathKey);
@@ -60671,6 +60731,16 @@ function keptRowReason(facts) {
60671
60731
  if (!facts.defaultEqual) return "provenanceOnly";
60672
60732
  return "pinnedOrReference";
60673
60733
  }
60734
+ function indexAuthoredConstructionIdentities(locations) {
60735
+ const byRoot = /* @__PURE__ */ new Map();
60736
+ for (const [id2, location3] of locations) {
60737
+ if (!location3.preserveIdentity) continue;
60738
+ const entries = byRoot.get(location3.rootId) ?? [];
60739
+ entries.push({ id: id2, path: location3.path });
60740
+ byRoot.set(location3.rootId, entries);
60741
+ }
60742
+ return byRoot;
60743
+ }
60674
60744
  function sparsifyConstructedInstance(args) {
60675
60745
  const materializedRows = [
60676
60746
  args.constructed.root,
@@ -60685,18 +60755,107 @@ function sparsifyConstructedInstance(args) {
60685
60755
  new Map(materializedRows.map((row) => [row.id, row])),
60686
60756
  /* @__PURE__ */ new Map([[args.constructed.root.id, args.rootMember]])
60687
60757
  );
60758
+ const anchors = /* @__PURE__ */ new Map();
60759
+ const authoredIds = /* @__PURE__ */ new Set();
60760
+ for (const identity3 of args.authoredIdentities ?? []) {
60761
+ let row = args.constructed.root;
60762
+ for (const segment of identity3.path) {
60763
+ const payload = row.value;
60764
+ let childId;
60765
+ if (Array.isArray(payload) && typeof segment === "number")
60766
+ childId = args.constructionEntryIds?.get(row.id)?.[segment] ?? payload[segment];
60767
+ else if (isObjectRecord(payload)) childId = payload[String(segment)];
60768
+ if (typeof childId !== "string")
60769
+ throw new Error(
60770
+ `Named construction ${identity3.id} has no value at ${JSON.stringify(identity3.path)}.`
60771
+ );
60772
+ const child2 = materializedGraph.valuesById.get(childId);
60773
+ if (child2 === void 0)
60774
+ throw new Error(
60775
+ `Named construction ${identity3.id} points to missing child ${childId}.`
60776
+ );
60777
+ row = child2;
60778
+ }
60779
+ if (anchors.has(row.id))
60780
+ throw new Error(`Constructed row ${row.id} has multiple named owners.`);
60781
+ if (authoredIds.has(identity3.id))
60782
+ throw new Error(
60783
+ `Named construction identity ${identity3.id} has multiple owning placements.`
60784
+ );
60785
+ if (identity3.id !== row.id && materializedGraph.valuesById.has(identity3.id))
60786
+ throw new Error(
60787
+ `Named construction identity ${identity3.id} collides with another constructed row.`
60788
+ );
60789
+ anchors.set(row.id, identity3.id);
60790
+ authoredIds.add(identity3.id);
60791
+ }
60792
+ const rootId = args.constructed.root.id;
60793
+ const boundaries = /* @__PURE__ */ new Map();
60794
+ const namedPaths = namedConstructionPaths(
60795
+ materializedGraph,
60796
+ new Map([[rootId, rootId], ...anchors]),
60797
+ args.constructionEntryIds,
60798
+ boundaries
60799
+ );
60800
+ const materializedIndex = buildVirtualInstanceMaterializedIndex({
60801
+ document: args.document,
60802
+ materializedRows,
60803
+ materializedGraph
60804
+ });
60688
60805
  const graph = resolveVirtualInstanceGraph({
60689
60806
  document: args.document,
60690
60807
  instanceRoot: args.constructed.root,
60691
60808
  rootMember: args.rootMember,
60692
60809
  expandedRoot: args.baseline.root,
60693
60810
  expandedRows: [args.baseline.root, ...args.baseline.createdChildren],
60694
- materializedRows,
60695
- materializedGraph
60696
- });
60697
- const protectedValueIds = /* @__PURE__ */ new Set();
60811
+ materializedIndex,
60812
+ materializedGraph,
60813
+ opaquePaths: boundaries.get(rootId)
60814
+ });
60815
+ const namedClaims = /* @__PURE__ */ new Map();
60816
+ const namedIds2 = /* @__PURE__ */ new Map();
60817
+ const scopedId = (rowId) => {
60818
+ const anchor = anchors.get(rowId);
60819
+ if (anchor !== void 0) return anchor;
60820
+ const cached = namedIds2.get(rowId);
60821
+ if (cached !== void 0) return cached;
60822
+ const scope = namedPaths.get(rowId);
60823
+ if (scope === void 0 || scope.id === rootId) return void 0;
60824
+ const relativePath = scope.path;
60825
+ const claims = namedClaims.get(scope.id) ?? /* @__PURE__ */ new Map();
60826
+ namedClaims.set(scope.id, claims);
60827
+ const claimed = claimVirtualIdentity({
60828
+ claimedVirtualIds: claims,
60829
+ instanceRootId: scope.id,
60830
+ rawSourceIdentity: `materialized:${relativePath}`,
60831
+ pathKey: relativePath
60832
+ });
60833
+ const id2 = args.virtualValueIdForSource?.(scope.id, claimed.sourceIdentity) ?? claimed.virtualId;
60834
+ namedIds2.set(rowId, id2);
60835
+ return id2;
60836
+ };
60837
+ const namedRootIds = new Set(anchors.keys());
60838
+ const protectedValueIds = new Set(namedRootIds);
60698
60839
  if (args.snapshot)
60699
60840
  for (const row of materializedRows) protectedValueIds.add(row.id);
60841
+ const pinNamedTarget = (id2) => {
60842
+ const scope = namedPaths.get(id2);
60843
+ if (scope !== void 0 && scope.id !== rootId) protectedValueIds.add(id2);
60844
+ };
60845
+ if (anchors.size > 0) {
60846
+ for (const row of materializedRows) {
60847
+ const owner = materializedGraph.ownerForValue(row.id);
60848
+ if (owner?.kind === 9 /* Lookup */)
60849
+ for (const id2 of materializedGraph.referencedValueIds(row))
60850
+ pinNamedTarget(id2);
60851
+ if (owner?.kind === 25 /* NSDelegate */ && isMemberDelegateTarget(row.value)) {
60852
+ if (typeof row.value.valueId === "string")
60853
+ pinNamedTarget(row.value.valueId);
60854
+ }
60855
+ for (const id2 of materializedGraph.referenceArgumentIds(row))
60856
+ pinNamedTarget(id2);
60857
+ }
60858
+ }
60700
60859
  const localizedTextIds = args.localizedTextIds ?? new Set(args.document.localizedTexts?.map((text) => text.id));
60701
60860
  for (const location3 of graph.locationsByPath.values()) {
60702
60861
  const row = location3.materializedRow;
@@ -60738,11 +60897,13 @@ function sparsifyConstructedInstance(args) {
60738
60897
  for (const childId of materializedGraph.referencedValueIds(row))
60739
60898
  pinArgumentFields(childId);
60740
60899
  };
60741
- for (const edge of materializedGraph.constructorEdges(
60742
- args.constructed.root
60743
- )) {
60744
- protectArgument(edge.targetValueId, edge.typeInfo);
60745
- pinArgumentFields(edge.targetValueId);
60900
+ for (const id2 of [args.constructed.root.id, ...anchors.keys()]) {
60901
+ for (const edge of materializedGraph.constructorEdges(
60902
+ materializedGraph.valuesById.get(id2)
60903
+ )) {
60904
+ protectArgument(edge.targetValueId, edge.typeInfo);
60905
+ pinArgumentFields(edge.targetValueId);
60906
+ }
60746
60907
  }
60747
60908
  for (const schemaKey of args.pinnedRootSchemaKeys ?? []) {
60748
60909
  const location3 = graph.locationsByPath.get(
@@ -60752,8 +60913,30 @@ function sparsifyConstructedInstance(args) {
60752
60913
  protectedValueIds.add(location3.materializedRow.id);
60753
60914
  }
60754
60915
  }
60755
- const rootId = args.constructed.root.id;
60756
- const locationValueId = (location3) => args.virtualValueIdForSource?.(rootId, location3.sourceIdentity) ?? location3.virtualRow.id;
60916
+ const pinnedNamedCalls = /* @__PURE__ */ new Set();
60917
+ const pinNamedCallFields = (id2) => {
60918
+ if (pinnedNamedCalls.has(id2)) return;
60919
+ pinnedNamedCalls.add(id2);
60920
+ const row = materializedGraph.valuesById.get(id2);
60921
+ if (row === void 0) return;
60922
+ const member = materializedGraph.ownerForValue(id2);
60923
+ if (member !== void 0 && (isMemberEntryCollectionBase(member) || isMemberDictionaryBase(member) || isMemberTupleBase(member))) {
60924
+ for (const child2 of materializedGraph.referencedValueIds(row))
60925
+ pinNamedCallFields(child2);
60926
+ for (const child2 of materializedGraph.childrenByContainerId.get(id2) ?? [])
60927
+ pinNamedCallFields(child2.id);
60928
+ return;
60929
+ }
60930
+ if (!isObjectRecord(row.value)) return;
60931
+ for (const key of args.pinnedSchemaKeysByValueId?.get(id2) ?? []) {
60932
+ const child2 = row.value[key];
60933
+ if (typeof child2 !== "string") continue;
60934
+ protectedValueIds.add(child2);
60935
+ pinNamedCallFields(child2);
60936
+ }
60937
+ };
60938
+ for (const id2 of anchors.keys()) pinNamedCallFields(id2);
60939
+ const locationValueId = (location3) => (location3.materializedRow === null ? void 0 : scopedId(location3.materializedRow.id)) ?? args.virtualValueIdForSource?.(rootId, location3.sourceIdentity) ?? location3.virtualRow.id;
60757
60940
  if (args.bindingTargets !== void 0)
60758
60941
  pinReferencedSlots(
60759
60942
  graph,
@@ -60766,7 +60949,8 @@ function sparsifyConstructedInstance(args) {
60766
60949
  try {
60767
60950
  plan = planCollapseVirtualInstance({
60768
60951
  graph,
60769
- pinnedValueIds: protectedValueIds
60952
+ pinnedValueIds: protectedValueIds,
60953
+ nestedRootValueIds: namedRootIds
60770
60954
  });
60771
60955
  } catch (error) {
60772
60956
  if (!(error instanceof OpenGenericComparisonError)) throw error;
@@ -60776,6 +60960,59 @@ function sparsifyConstructedInstance(args) {
60776
60960
  const updatedValueById = new Map(
60777
60961
  plan.updates.map((update) => [update.valueId, update.value])
60778
60962
  );
60963
+ if (!args.snapshot) {
60964
+ for (const [rowId, authoredId] of anchors) {
60965
+ const root2 = materializedGraph.valuesById.get(rowId);
60966
+ const placement = materializedGraph.ownerForValue(rowId);
60967
+ if (placement === void 0)
60968
+ throw new Error(
60969
+ `Named construction ${authoredId} has no typed owning placement.`
60970
+ );
60971
+ const member = storedClassResolutionMember(
60972
+ placement,
60973
+ root2,
60974
+ args.document.members
60975
+ );
60976
+ if (member === null) continue;
60977
+ if (args.expandNamedRoot === void 0)
60978
+ throw new Error(
60979
+ "Named Class preparation requires its own construction expansion."
60980
+ );
60981
+ const baseline = args.expandNamedRoot(root2, member, materializedRows);
60982
+ const ownGraph = resolveVirtualInstanceGraph({
60983
+ document: args.document,
60984
+ instanceRoot: root2,
60985
+ rootMember: member,
60986
+ expandedRoot: baseline.root,
60987
+ expandedRows: baseline.rows,
60988
+ pinnedRootSchemaKeys: args.pinnedSchemaKeysByValueId?.get(rowId),
60989
+ materializedIndex,
60990
+ materializedGraph,
60991
+ opaquePaths: boundaries.get(authoredId)
60992
+ });
60993
+ for (const location3 of ownGraph.locationsByPath.values()) {
60994
+ const row = location3.materializedRow;
60995
+ if (row !== null && isMemberStringBase(location3.member) && isLocalizedStringMember(location3.member) && typeof row.value === "string" && row.value !== "" && !localizedTextIds.has(row.value))
60996
+ protectedValueIds.add(row.id);
60997
+ }
60998
+ if (args.bindingTargets !== void 0)
60999
+ pinReferencedSlots(
61000
+ ownGraph,
61001
+ authoredId,
61002
+ args.bindingTargets,
61003
+ locationValueId,
61004
+ protectedValueIds
61005
+ );
61006
+ const ownPlan = planCollapseVirtualInstance({
61007
+ graph: ownGraph,
61008
+ pinnedValueIds: protectedValueIds,
61009
+ nestedRootValueIds: namedRootIds
61010
+ });
61011
+ for (const id2 of ownPlan.deletes) deletedIds.add(id2);
61012
+ for (const update of ownPlan.updates)
61013
+ updatedValueById.set(update.valueId, update.value);
61014
+ }
61015
+ }
60779
61016
  restoreRowsRetainedRowsName(
60780
61017
  materializedGraph,
60781
61018
  materializedRows,
@@ -60797,6 +61034,10 @@ function sparsifyConstructedInstance(args) {
60797
61034
  );
60798
61035
  }
60799
61036
  nextIdById.set(args.constructed.root.id, args.constructed.root.id);
61037
+ for (const row of retainedRows) {
61038
+ const id2 = scopedId(row.id);
61039
+ if (id2 !== void 0) nextIdById.set(row.id, id2);
61040
+ }
60800
61041
  const unmappedRows = retainedRows.filter((row) => !nextIdById.has(row.id));
60801
61042
  const fallbackRows = (unmappedRows.length === 0 ? [] : (() => {
60802
61043
  const fallbackPaths = materializedFallbackPaths(
@@ -60812,6 +61053,11 @@ function sparsifyConstructedInstance(args) {
60812
61053
  (left, right) => left.path.localeCompare(right.path) || left.row.id.localeCompare(right.row.id)
60813
61054
  );
60814
61055
  for (const { row, path } of fallbackRows) {
61056
+ const namedId = scopedId(row.id);
61057
+ if (namedId !== void 0) {
61058
+ nextIdById.set(row.id, namedId);
61059
+ continue;
61060
+ }
60815
61061
  const rawSourceIdentity = typeof row.sourceValueId === "string" && row.sourceValueId.length > 0 ? row.sourceValueId : `materialized:${path}`;
60816
61062
  const { sourceIdentity: sourceIdentity3, virtualId } = claimVirtualIdentity({
60817
61063
  claimedVirtualIds,
@@ -60832,6 +61078,8 @@ function sparsifyConstructedInstance(args) {
60832
61078
  if (retainedId !== void 0) return retainedId;
60833
61079
  const receiver = graph.locationsById.get(id2);
60834
61080
  if (receiver === void 0) return id2;
61081
+ const named = scopedId(id2);
61082
+ if (named !== void 0) return named;
60835
61083
  return args.virtualValueIdForSource?.(
60836
61084
  args.constructed.root.id,
60837
61085
  receiver.sourceIdentity
@@ -60899,6 +61147,54 @@ function restoreRowsRetainedRowsName(materializedGraph, rows, updatedValueById,
60899
61147
  restore(valueId);
60900
61148
  }
60901
61149
  }
61150
+ function namedConstructionPaths(graph, anchors, entries, boundaries) {
61151
+ const paths = /* @__PURE__ */ new Map();
61152
+ const queue = [];
61153
+ for (const [rowId, id2] of anchors) {
61154
+ paths.set(rowId, { id: id2, path: ROOT_PATH });
61155
+ queue.push(rowId);
61156
+ }
61157
+ if (queue.length === 0) return paths;
61158
+ const add = (childId, scope, segment) => {
61159
+ if (typeof childId !== "string" || !graph.valuesById.has(childId)) return;
61160
+ const path = appendVirtualValuePath(scope.path, segment);
61161
+ if (anchors.has(childId)) {
61162
+ const paths2 = boundaries.get(scope.id) ?? /* @__PURE__ */ new Set();
61163
+ paths2.add(path);
61164
+ boundaries.set(scope.id, paths2);
61165
+ return;
61166
+ }
61167
+ if (paths.has(childId)) return;
61168
+ paths.set(childId, { id: scope.id, path });
61169
+ queue.push(childId);
61170
+ };
61171
+ for (let index = 0; index < queue.length; index++) {
61172
+ const rowId = queue[index];
61173
+ const row = graph.valuesById.get(rowId);
61174
+ const scope = paths.get(rowId);
61175
+ if (row === void 0) continue;
61176
+ const member = graph.ownerForValue(rowId);
61177
+ if (Array.isArray(row.value) && member !== void 0 && (isMemberEntryCollectionBase(member) || isMemberTupleBase(member))) {
61178
+ const children3 = entries?.get(rowId) ?? (row.value.length > 0 ? row.value : graph.childrenByContainerId.get(rowId)?.map((child2) => child2.id) ?? []);
61179
+ children3.forEach((id2, index2) => add(id2, scope, { kind: "list", index: index2 }));
61180
+ } else if (isObjectRecord(row.value) && (typeof row.classId === "string" || member !== void 0 && (isClassSlotMember(member) || isMemberDictionaryBase(member)))) {
61181
+ for (const [schemaKey, id2] of Object.entries(row.value))
61182
+ add(
61183
+ id2,
61184
+ scope,
61185
+ member !== void 0 && isMemberDictionaryBase(member) ? { kind: "dictionary", key: schemaKey } : { kind: "class", schemaKey }
61186
+ );
61187
+ }
61188
+ for (const edge of graph.edgesByOwnerValueId.get(rowId) ?? []) {
61189
+ if (graph.independentlyOwnedValueIds.has(edge.targetValueId)) continue;
61190
+ add(edge.targetValueId, scope, {
61191
+ kind: "class",
61192
+ schemaKey: `@constructor:${edge.parameterId}`
61193
+ });
61194
+ }
61195
+ }
61196
+ return paths;
61197
+ }
60902
61198
  function materializedFallbackPaths(rows, graph, materializedGraph) {
60903
61199
  const rowsById = new Map(rows.map((row) => [row.id, row]));
60904
61200
  const unorderedEntriesByContainerId = buildUnorderedListMembershipIndex(rows);
@@ -61082,6 +61378,7 @@ function indexExpansion(args) {
61082
61378
  discoveredNodes?.push(node);
61083
61379
  nodesByPath.set(pathKey, node);
61084
61380
  appendChildPath(parentPath, pathKey);
61381
+ if (args.opaquePaths?.has(pathKey)) return;
61085
61382
  if (isClassTypedMember(member)) {
61086
61383
  const record7 = stringRecord(row.value);
61087
61384
  const classId = row.classId ?? member.classId;
@@ -62613,6 +62910,10 @@ function createHeadlessVirtualInstanceResolver(args) {
62613
62910
  if (valueId !== void 0) {
62614
62911
  for (const active of activeReads) active.placementIds.add(valueId);
62615
62912
  ownReads()?.placementIds.add(valueId);
62913
+ } else {
62914
+ for (const active of activeReads) active.global = true;
62915
+ const own = ownReads();
62916
+ if (own !== void 0) own.global = true;
62616
62917
  }
62617
62918
  args.readRecorder?.recordValuePlacementRead(valueId);
62618
62919
  },
@@ -62850,7 +63151,9 @@ function createHeadlessVirtualInstanceResolver(args) {
62850
63151
  for (const id2 of reads.variantIds) external.recordVariantRead(id2);
62851
63152
  for (const id2 of reads.staticMemberIds)
62852
63153
  external.recordStaticMemberRead(id2);
62853
- if (reads.placementIds.size > 0) external.recordValuePlacementRead();
63154
+ for (const id2 of reads.placementIds)
63155
+ external.recordValuePlacementRead(id2);
63156
+ if (reads.global) external.recordGlobalRead("virtual-instance-expansion");
62854
63157
  for (const reason of reads.corpusIndexReads)
62855
63158
  external.recordGlobalRead(reason);
62856
63159
  }
@@ -63045,7 +63348,8 @@ function createHeadlessVirtualInstanceResolver(args) {
63045
63348
  share.containerChanged
63046
63349
  );
63047
63350
  if (shared === null) return null;
63048
- recorder.recordValuePlacementRead();
63351
+ for (const id2 of shared.reads.placementIds)
63352
+ recorder.recordValuePlacementRead(id2);
63049
63353
  for (const id2 of shared.reads.valueIds) recorder.recordValueRead(id2);
63050
63354
  for (const id2 of shared.reads.containerIds)
63051
63355
  recorder.recordContainerMembershipRead(id2);
@@ -63080,12 +63384,10 @@ function createHeadlessVirtualInstanceResolver(args) {
63080
63384
  const virtualInstanceRowsForValue = (receiverValueId) => {
63081
63385
  const adopted = adoptSharedExpansion(receiverValueId);
63082
63386
  if (adopted !== null) return adopted;
63083
- recorder.recordValuePlacementRead();
63084
63387
  recorder.recordValueRead(receiverValueId);
63085
63388
  const readPlacement = (valueId) => {
63086
- for (const active of activeReads) active.placementIds.add(valueId);
63087
- ownReads()?.placementIds.add(valueId);
63088
- return placements().get(valueId) ?? null;
63389
+ recorder.recordValuePlacementRead(valueId);
63390
+ return rawById.has(valueId) ? placements().get(valueId) ?? null : null;
63089
63391
  };
63090
63392
  let placement = readPlacement(receiverValueId);
63091
63393
  const roots = [];
@@ -63122,10 +63424,19 @@ function createHeadlessVirtualInstanceResolver(args) {
63122
63424
  observeRoot(known.instanceRootId);
63123
63425
  observeOwner(valueId, true);
63124
63426
  }
63125
- if (known?.instanceRootId === valueId) return known;
63427
+ const readKnown = (graph2) => {
63428
+ const result = resultByRootId.get(graph2.instanceRootId);
63429
+ if (result !== void 0) {
63430
+ settledRows(result);
63431
+ forwardReads(result.reads);
63432
+ }
63433
+ observeOwner(valueId, true);
63434
+ return graph2;
63435
+ };
63436
+ if (known?.instanceRootId === valueId) return readKnown(known);
63126
63437
  const stored = rawById.get(valueId);
63127
63438
  if (known !== void 0 && (stored === void 0 || !isStoredClassResolutionRoot(stored) || isMaterializedSpine(known.locationsById.get(valueId))))
63128
- return known;
63439
+ return readKnown(known);
63129
63440
  virtualInstanceRowsForValue(valueId);
63130
63441
  if (frames.length === 0) return graphByValueId.get(valueId) ?? null;
63131
63442
  const graph = observeSettled(valueId);
@@ -63225,7 +63536,7 @@ function createHeadlessVirtualInstanceResolver(args) {
63225
63536
  readRecorder: recorder,
63226
63537
  recordReads: (target, read) => {
63227
63538
  let reads = callerReads.get(target);
63228
- if (reads === void 0) {
63539
+ if (reads === void 0 || reads.valueIds !== target.valueIds || reads.containerIds !== target.containerIds || reads.localizedTextIds !== target.localizedTextIds || reads.variantIds !== target.variantIds || reads.staticMemberIds !== target.staticMemberIds) {
63229
63540
  reads = {
63230
63541
  valueIds: target.valueIds,
63231
63542
  containerIds: target.containerIds,
@@ -63249,6 +63560,9 @@ function createHeadlessVirtualInstanceResolver(args) {
63249
63560
  return read();
63250
63561
  } finally {
63251
63562
  activeReads.pop();
63563
+ for (const id2 of reads.placementIds)
63564
+ target.recordValuePlacementRead(id2);
63565
+ reads.placementIds.clear();
63252
63566
  if (reads.global)
63253
63567
  target.recordUnattributableValueRead("virtual-instance-expansion");
63254
63568
  for (const reason of reads.corpusIndexReads)
@@ -63451,9 +63765,23 @@ function sharedHeadlessResolver(overlay2) {
63451
63765
  containerChanged: (id2) => overlay2.changedContainerIds.has(id2)
63452
63766
  };
63453
63767
  }
63454
- function initializerStoredClassGraph(document, rootId, member) {
63768
+ function initializerStoredClassGraph(document, rootId, member, readTracking) {
63455
63769
  initializerEvaluatorLookups(document);
63456
- return headlessResolversByLookupKey.get(initializerBehaviorCacheKey(document))?.storedClassGraph(rootId, member) ?? null;
63770
+ const resolver = headlessResolversByLookupKey.get(
63771
+ initializerBehaviorCacheKey(document)
63772
+ );
63773
+ if (resolver === void 0) return null;
63774
+ const read = () => resolver.storedClassGraph(rootId, member);
63775
+ return readTracking === void 0 ? read() : resolver.recordReads(readTracking, read);
63776
+ }
63777
+ function initializerContainingClassGraph(document, valueId, readTracking) {
63778
+ initializerEvaluatorLookups(document);
63779
+ const resolver = headlessResolversByLookupKey.get(
63780
+ initializerBehaviorCacheKey(document)
63781
+ );
63782
+ if (resolver === void 0) return null;
63783
+ const read = () => resolver.virtualInstanceGraphForValue(valueId);
63784
+ return readTracking === void 0 ? read() : resolver.recordReads(readTracking, read);
63457
63785
  }
63458
63786
  function initializerEvaluatorLookups(document, readTracking) {
63459
63787
  const trackedHeadless = readTracking !== void 0 && document.databaseVM === void 0;
@@ -63708,7 +64036,9 @@ function createInitializerMaterializationBatch(authoredDocument, pendingInitiali
63708
64036
  },
63709
64037
  // Resolver placement walks record every ancestor id. Upserts below also
63710
64038
  // invalidate old/new ownership targets, including newly attached rows.
63711
- recordValuePlacementRead: () => {
64039
+ recordValuePlacementRead: (id2) => {
64040
+ if (id2 !== void 0) recordRead(id2);
64041
+ else for (const entry of activeReads) entry.global = true;
63712
64042
  }
63713
64043
  };
63714
64044
  const forget = (entry) => {
@@ -63732,10 +64062,11 @@ function createInitializerMaterializationBatch(authoredDocument, pendingInitiali
63732
64062
  entry.invalidated();
63733
64063
  };
63734
64064
  const watchReads = (reads, invalidated) => {
63735
- const global = reads.worldQueries.size > 0 || reads.hasValuePlacementRead || reads.corpusReadReasons.size > 0;
64065
+ const global = reads.worldQueries.size > 0 || reads.hasUnnamedValuePlacementRead || reads.corpusReadReasons.size > 0;
63736
64066
  const entry = {
63737
64067
  reads: /* @__PURE__ */ new Set([
63738
64068
  ...reads.valueIds,
64069
+ ...reads.placementIds,
63739
64070
  ...reads.containerIds,
63740
64071
  ...reads.containerEntryReadIds
63741
64072
  ]),
@@ -64044,6 +64375,7 @@ function evaluateMemberInitializer(args) {
64044
64375
  );
64045
64376
  const compiled = compileMemberInitializer(args, databaseVM);
64046
64377
  const ctx = {
64378
+ __constructionEntryIds: args.constructionEntryIds,
64047
64379
  randomSource: args.randomSource,
64048
64380
  randomIdentity,
64049
64381
  ...args.sessionValues === void 0 ? {} : { __runtimeSessionValues: args.sessionValues },
@@ -118624,6 +118956,43 @@ function storedValueAtPathV4(rows, rootId, path) {
118624
118956
  }
118625
118957
  return id2;
118626
118958
  }
118959
+ function storedValueOwnsPathV4(records3, rows, ownerForValue) {
118960
+ const placements = buildStoredValuePlacementIndexV4(records3, rows);
118961
+ const parents = /* @__PURE__ */ new Map();
118962
+ for (const [id2, edge] of placements.placementByChildValueId)
118963
+ parents.set(id2, { id: edge.parentValueId, key: edge.schemaKey });
118964
+ for (const [id2, row] of rows) {
118965
+ if (typeof row.containerId === "string")
118966
+ parents.set(id2, { id: row.containerId, key: null });
118967
+ }
118968
+ for (const [id2, row] of rows) {
118969
+ if (!Array.isArray(row.value)) continue;
118970
+ const owner = ownerForValue(id2);
118971
+ if (owner === void 0) continue;
118972
+ if (!isMemberEntryCollectionBase(owner) && !isMemberTupleBase(owner))
118973
+ continue;
118974
+ row.value.forEach((child2, index) => {
118975
+ if (typeof child2 !== "string") return;
118976
+ const container = rows.get(child2)?.containerId;
118977
+ if (container !== void 0 && container !== id2) return;
118978
+ if (container === void 0 && parents.has(child2)) return;
118979
+ parents.set(child2, { id: id2, key: index });
118980
+ });
118981
+ }
118982
+ return (rootId, path, valueId) => {
118983
+ let id2 = valueId;
118984
+ for (let index = path.length - 1; index >= 0; index--) {
118985
+ const parent = parents.get(id2);
118986
+ if (parent === void 0) return false;
118987
+ const key = path[index];
118988
+ if (parent.key === null) {
118989
+ if (typeof key !== "number") return false;
118990
+ } else if (parent.key !== key) return false;
118991
+ id2 = parent.id;
118992
+ }
118993
+ return id2 === rootId;
118994
+ };
118995
+ }
118627
118996
  function buildStoredValuePlacementIndexV4(records3, logicalValues) {
118628
118997
  const live = [...records3].filter((record7) => record7.deleted !== true);
118629
118998
  const values = logicalValues ?? storedValueRowsByIdV4(live);
@@ -123112,9 +123481,18 @@ var init_effective_value_reader = __esm({
123112
123481
  if (position === void 0) break;
123113
123482
  const parentMember = this.memberForId(position.memberId);
123114
123483
  if (parentMember !== null && isClassSlotMember(parentMember)) {
123115
- const containingRows = this.resolveGraph(parentId, parentMember);
123116
- if (isMaterializedSpine(this.locations.get(valueId)))
123117
- return containingRows;
123484
+ const canShareFrame = this.context.saveStaticBindings === void 0 && this.context.sessionStaticBindings === void 0 && parentMember.payload !== 1 /* Partial */ && isStoredClassResolutionRoot(this.rawRow(parentId));
123485
+ const frame = canShareFrame ? initializerContainingClassGraph(
123486
+ this.readDocument,
123487
+ parentId,
123488
+ this.context.readTracking
123489
+ ) : null;
123490
+ const location3 = frame?.locationsById.get(valueId);
123491
+ if (frame === null || isMaterializedSpine(location3)) {
123492
+ const containingRows = this.resolveGraph(parentId, parentMember);
123493
+ if (isMaterializedSpine(this.locations.get(valueId)))
123494
+ return containingRows;
123495
+ }
123118
123496
  break;
123119
123497
  }
123120
123498
  parentId = position.parentValueId;
@@ -123129,7 +123507,12 @@ var init_effective_value_reader = __esm({
123129
123507
  materializeInitializerValue,
123130
123508
  materializeMemberDefaultValue: materializeMemberDefaultValue2,
123131
123509
  materializedIndex: this.materializedIndex,
123132
- resolveClassGraph: this.context.readTracking === void 0 && this.context.saveStaticBindings === void 0 && this.context.sessionStaticBindings === void 0 ? (root2, member) => initializerStoredClassGraph(this.readDocument, root2.id, member) : void 0,
123510
+ resolveClassGraph: this.context.saveStaticBindings === void 0 && this.context.sessionStaticBindings === void 0 ? (root2, member) => initializerStoredClassGraph(
123511
+ this.readDocument,
123512
+ root2.id,
123513
+ member,
123514
+ this.context.readTracking
123515
+ ) : void 0,
123133
123516
  onResolvedListenerDefaults: (ownerId, entry) => {
123134
123517
  if (entry === void 0) this.listenerDefaults.delete(ownerId);
123135
123518
  else this.listenerDefaults.set(ownerId, entry);
@@ -123566,6 +123949,14 @@ var init_project_migration_member_listeners = __esm({
123566
123949
  });
123567
123950
 
123568
123951
  // ../packages/neoscript-runtime/src/virtual-instance-values.ts
123952
+ function expandStoredClassValue2(args) {
123953
+ return expandStoredClassValue({
123954
+ ...args,
123955
+ evaluateInitializer: evaluateMemberInitializer,
123956
+ materializeInitializerValue,
123957
+ materializeMemberDefaultValue: materializeMemberDefaultValue2
123958
+ });
123959
+ }
123569
123960
  function expandStoredInstance2(args) {
123570
123961
  return expandStoredInstance({
123571
123962
  ...args,
@@ -123599,9 +123990,52 @@ function resolveStoredClassValue2(args) {
123599
123990
  materializeMemberDefaultValue: materializeMemberDefaultValue2
123600
123991
  });
123601
123992
  }
123993
+ function sparsifyConstructedInstance2(args) {
123994
+ let document;
123995
+ return sparsifyConstructedInstance({
123996
+ ...args,
123997
+ expandNamedRoot: (instanceRoot, rootMember, materializedRows) => {
123998
+ if (document === void 0) {
123999
+ if (!("project" in args.document))
124000
+ throw new Error(
124001
+ "Named Class preparation requires the project evaluation context."
124002
+ );
124003
+ const base = args.document;
124004
+ const baseRows = initializerEvaluatorLookups(base).evaluatorIndexes?.valueById ?? new Map(base.values.map((row) => [row.id, row]));
124005
+ const rows = new Map(materializedRows.map((row) => [row.id, row]));
124006
+ const valuesById = new OverlayReadonlyMap(baseRows, rows, /* @__PURE__ */ new Set());
124007
+ const values = lazyArray(() => valuesById.values());
124008
+ const changedContainerIds = new Set(rows.keys());
124009
+ for (const row of rows.values())
124010
+ if (row.containerId) changedContainerIds.add(row.containerId);
124011
+ document = {
124012
+ ...base,
124013
+ databaseVM: void 0,
124014
+ indexedView: void 0,
124015
+ evaluatorCache: void 0,
124016
+ worldQueryCache: void 0,
124017
+ values,
124018
+ valueById: (id2) => valuesById.get(id2) ?? null,
124019
+ evaluatorOverlay: {
124020
+ base,
124021
+ rows,
124022
+ hiddenIds: /* @__PURE__ */ new Set(),
124023
+ changedContainerIds,
124024
+ values,
124025
+ valuesById,
124026
+ containerMembership: "merge"
124027
+ }
124028
+ };
124029
+ }
124030
+ return expandStoredClassValue2({ document, instanceRoot, rootMember });
124031
+ }
124032
+ });
124033
+ }
123602
124034
  var init_virtual_instance_values = __esm({
123603
124035
  "../packages/neoscript-runtime/src/virtual-instance-values.ts"() {
123604
124036
  "use strict";
124037
+ init_overlay_readonly_map();
124038
+ init_lazy_array();
123605
124039
  init_initializer_materialization();
123606
124040
  init_evaluateInitializer();
123607
124041
  init_virtual_instance_graph();
@@ -144571,7 +145005,7 @@ function createScheduledConstructionReplayComparer(args) {
144571
145005
  get worldQueries() {
144572
145006
  return created.reads.worldQueries;
144573
145007
  },
144574
- recordValuePlacementRead: () => created.reads.recordValuePlacementRead(),
145008
+ recordValuePlacementRead: (valueId) => created.reads.recordValuePlacementRead(valueId),
144575
145009
  recordUnattributableValueRead: (reason) => created.reads.recordUnattributableValueRead(reason)
144576
145010
  };
144577
145011
  const reader = schemaReader.withIndexedSnapshot(document2).withRowOverrides(input.replayRows, { readTracking: tracking });
@@ -148047,6 +148481,7 @@ function* prepareServerOwnedSchemaCommitPasses(args) {
148047
148481
  });
148048
148482
  materializePreparedInstanceInitializers({
148049
148483
  referenceOwners: args.initializerReferenceOwners,
148484
+ constructionIdentities: args.constructionIdentities,
148050
148485
  document: args.document,
148051
148486
  physicalValues: args.document.physicalValues,
148052
148487
  prepared,
@@ -148422,6 +148857,7 @@ function materializePreparedInstanceInitializers(args) {
148422
148857
  }
148423
148858
  const materialized = replay(
148424
148859
  (readTracking) => materializeInitializerValue2({
148860
+ captureConstructionEntries: args.constructionIdentities?.has(valueId),
148425
148861
  readTracking,
148426
148862
  // Every site that survives the declaration-default guard is source for
148427
148863
  // a persisted instance construction. The trusted replay mode both
@@ -148485,9 +148921,12 @@ function materializePreparedInstanceInitializers(args) {
148485
148921
  constructionBaselineReplay: true,
148486
148922
  storedConstructionReplay: true
148487
148923
  });
148488
- const sparse2 = sparsifyConstructedInstance({
148924
+ const authoredIdentities = args.constructionIdentities?.get(valueId);
148925
+ const sparse2 = sparsifyConstructedInstance2({
148926
+ authoredIdentities,
148927
+ constructionEntryIds: materialized.constructionEntryIds,
148489
148928
  localizedTextIds,
148490
- document: currentDocument,
148929
+ document: authoredIdentities?.length ? batch.comparisonDocument() : currentDocument,
148491
148930
  rootMember: member,
148492
148931
  constructed: {
148493
148932
  root: materialized.root,
@@ -160240,6 +160679,7 @@ function preparationArgs(context) {
160240
160679
  return {
160241
160680
  document: context.document,
160242
160681
  initializerReferenceOwners: args.initializerReferenceOwners,
160682
+ constructionIdentities: args.constructionIdentities,
160243
160683
  contentHashHeads: context.contentHashHeads,
160244
160684
  changes: args.changes,
160245
160685
  authoredValueSeeds: args.authoredValueSeeds,
@@ -160814,8 +161254,14 @@ function verifyProjectSourceCommitAgainstStateV4(args) {
160814
161254
  ${blockingErrors.map((error) => error.message).join("\n")}` : `Trusted source lowering found conflict markers in ${status.conflictedFiles.join(", ")}.`
160815
161255
  );
160816
161256
  }
161257
+ const identitySeeds = new Map(status.authoredValueSeeds);
161258
+ identitySeeds.set("source-owned constructions", {
161259
+ values: [...status.pendingValueIdentitySites ?? []].flatMap(
161260
+ ([id2, site]) => site.materializedLocation?.preserveIdentity === true ? [{ id: id2, value: null }] : []
161261
+ )
161262
+ });
160817
161263
  auditAuthoredSeedRowIdentities(
160818
- status.authoredValueSeeds,
161264
+ identitySeeds,
160819
161265
  args.stateRecords,
160820
161266
  assignments,
160821
161267
  derivedSeedRowIds
@@ -160852,6 +161298,18 @@ ${blockingErrors.map((error) => error.message).join("\n")}` : `Trusted source lo
160852
161298
  ...rewrite(seed)
160853
161299
  })
160854
161300
  );
161301
+ const constructionIdentities = indexAuthoredConstructionIdentities(
161302
+ [...status.pendingValueIdentitySites ?? []].flatMap(([id2, site]) => {
161303
+ const location3 = site.materializedLocation;
161304
+ if (location3?.preserveIdentity !== true) return [];
161305
+ return [
161306
+ [
161307
+ rewrite(id2),
161308
+ { ...location3, rootId: rewrite(location3.rootId) }
161309
+ ]
161310
+ ];
161311
+ })
161312
+ );
160855
161313
  for (const pendingId2 of assignments.keys()) {
160856
161314
  if (!usedAssignments.has(pendingId2)) {
160857
161315
  const message = `Pending id assignment ${pendingId2} is not present in the verified source manifest.`;
@@ -160872,6 +161330,7 @@ ${blockingErrors.map((error) => error.message).join("\n")}` : `Trusted source lo
160872
161330
  });
160873
161331
  compareChanges(expectedChanges, verifiableChanges);
160874
161332
  compareSeeds(expectedSeeds, args.authoredValueSeeds);
161333
+ return constructionIdentities;
160875
161334
  }
160876
161335
  function isDerivedOnlyRefresh(change, stateRecords) {
160877
161336
  if (change.operation !== "update") return false;
@@ -161412,6 +161871,7 @@ var ProjectSourceCommitVerificationError, ABSENT_DIFFERENCE_VALUE;
161412
161871
  var init_trusted_commit_verification = __esm({
161413
161872
  "src/project-source/trusted-commit-verification.ts"() {
161414
161873
  "use strict";
161874
+ init_virtual_instance_values();
161415
161875
  init_animation_child_binding_id();
161416
161876
  init_world_system_classes();
161417
161877
  init_tuple_element_member_id();
@@ -161500,6 +161960,7 @@ function sourceCommitPreparation(args) {
161500
161960
  }),
161501
161961
  authoredValueSeeds: args.authoredValueSeeds,
161502
161962
  initializerReferenceOwners: args.initializerReferenceOwners,
161963
+ constructionIdentities: args.constructionIdentities,
161503
161964
  forceRecompile: args.forceRecompile,
161504
161965
  scriptSources: args.scriptSources,
161505
161966
  serverTimestamp: args.serverTimestamp
@@ -161783,6 +162244,7 @@ function replayStoredConstructionV4(args) {
161783
162244
  // explicit typed descriptor for evaluation that compiled the replay.
161784
162245
  member: compileMember,
161785
162246
  row: evaluationRow,
162247
+ captureConstructionEntries: args.captureConstructionEntries,
161786
162248
  storedConstructionReplay: true,
161787
162249
  ...args.omitConstructionFields === true ? { constructionBaselineReplay: true } : {},
161788
162250
  ...args.initializerArgumentValues === void 0 ? {} : { argumentValues: args.initializerArgumentValues }
@@ -163209,10 +163671,10 @@ function buildValueEmitIndexesV4(records3, manifest, localizedTextDependencies,
163209
163671
  storedPlacements,
163210
163672
  rootPathsByValueId
163211
163673
  ),
163212
- readUnstoredSlots: () => unstoredSlots ??= unstoredSlotParents(
163674
+ unstoredSlotParent: (id2) => (unstoredSlots ??= unstoredSlotParents(
163213
163675
  readDocument(),
163214
- readCompilationProject()
163215
- ),
163676
+ readCompilationProject
163677
+ ))(id2),
163216
163678
  collectionBindingValueIds: /* @__PURE__ */ new Set([
163217
163679
  ...manifest.members.flatMap(
163218
163680
  (member) => member.kind === "lookup" && typeof member.collectionValueId === "string" ? [member.collectionValueId] : []
@@ -166874,9 +167336,18 @@ function lowerSeedRow(context, member, sourceExpression, source, valueId, path,
166874
167336
  valueId,
166875
167337
  {
166876
167338
  sites: context.pendingValueIdentitySites,
167339
+ storedParent: (id2) => {
167340
+ const edge = context.readStoredValuePlacements().placementByChildValueId.get(id2);
167341
+ return edge === void 0 ? void 0 : { rootId: edge.parentValueId, path: [edge.schemaKey] };
167342
+ },
167343
+ validateAuthoredId: (id2) => {
167344
+ if (!isPendingId(id2) && context.state[`value:${id2}`] === void 0 && !isUuidV4Id(id2))
167345
+ throw new Error(
167346
+ `New local value @id(${JSON.stringify(id2)}) requires a UUID v4.`
167347
+ );
167348
+ },
166877
167349
  localListEntries: (local2) => localNestedListEntries(context, local2)
166878
- },
166879
- context.storedValueAtPath
167350
+ }
166880
167351
  );
166881
167352
  const settled = settleInitializerReferenceSpellings(
166882
167353
  executable.code,
@@ -167618,7 +168089,7 @@ function lowerSeedChild(context, member, expression, source, path, rows, localiz
167618
168089
  )
167619
168090
  });
167620
168091
  }
167621
- const valueId = annotatedId2 ?? context.structuralStoredIds.get(path) ?? pendingNestedValueId(source, path);
168092
+ const valueId = annotatedId2 ?? context.structuralStoredIds.get(path) ?? local.pendingIdentity ?? pendingNestedValueId(source, path);
167622
168093
  if (!context.structuralConstruction && annotatedId2 !== null && context.state[`value:${annotatedId2}`] !== void 0) {
167623
168094
  const failure = storedClassMoveFailure(
167624
168095
  context,
@@ -167668,7 +168139,7 @@ function lowerSeedChild(context, member, expression, source, path, rows, localiz
167668
168139
  expression,
167669
168140
  source,
167670
168141
  valueId,
167671
- unorderedRowSubtreePath(valueId, path, containerId),
168142
+ local.pendingIdentity === void 0 ? unorderedRowSubtreePath(valueId, path, containerId) : valueId,
167672
168143
  rows,
167673
168144
  localizedTexts,
167674
168145
  containerId,
@@ -167847,9 +168318,18 @@ function lowerAuthoredValueRow(context, member, sourceExpression, expectedValueI
167847
168318
  expectedValueId,
167848
168319
  {
167849
168320
  sites: context.pendingValueIdentitySites,
168321
+ storedParent: (id3) => {
168322
+ const edge = context.readStoredValuePlacements().placementByChildValueId.get(id3);
168323
+ return edge === void 0 ? void 0 : { rootId: edge.parentValueId, path: [edge.schemaKey] };
168324
+ },
168325
+ validateAuthoredId: (id3) => {
168326
+ if (!isPendingId(id3) && context.state[`value:${id3}`] === void 0 && !isUuidV4Id(id3))
168327
+ throw new Error(
168328
+ `New local value @id(${JSON.stringify(id3)}) requires a UUID v4.`
168329
+ );
168330
+ },
167850
168331
  localListEntries: (local2) => localNestedListEntries(context, local2)
167851
- },
167852
- context.storedValueAtPath
168332
+ }
167853
168333
  );
167854
168334
  const settled = settleInitializerReferenceSpellings(
167855
168335
  executable.code,
@@ -169441,9 +169921,10 @@ function recordRepeatedRow(context, rowId, collection, site, placedIds = context
169441
169921
  function lowerPendingListItem(context, member, expression, source, path, containerId, environment, authoredSlice) {
169442
169922
  const rows = /* @__PURE__ */ new Map();
169443
169923
  const localizedTexts = /* @__PURE__ */ new Map();
169444
- const annotatedId2 = authoredRowId(context, expression, source);
169445
- const valueId = annotatedId2 ?? pendingNestedValueId(source, path);
169446
- const stablePath = isPendingId(valueId) ? valueId : unorderedRowSubtreePath(valueId, path, containerId);
169924
+ const local = context.localValues.resolve(expression, source);
169925
+ const annotatedId2 = annotatedValue(local.expression).id;
169926
+ const valueId = annotatedId2 ?? local.pendingIdentity ?? pendingNestedValueId(source, path);
169927
+ const stablePath = isPendingId(valueId) || local.pendingIdentity !== void 0 ? valueId : unorderedRowSubtreePath(valueId, path, containerId);
169447
169928
  lowerSeedRow(
169448
169929
  context,
169449
169930
  member,
@@ -171426,6 +171907,14 @@ function emitValue(context, member, valueId, options) {
171426
171907
  context.localizedTextIds = /* @__PURE__ */ new Set();
171427
171908
  const expression2 = emitValue(context, member, valueId, {
171428
171909
  ...options,
171910
+ writeIdentity: options.writeIdentity || !context.symbolsByValueId.has(valueId) && member.valueId !== valueId && (typeof member.id !== "string" || memberValueId(member.id) !== valueId) && (!isObjectRecord(member.defaultValue) || member.defaultValue.id !== valueId) && [
171911
+ 7 /* Class */,
171912
+ 22 /* Interface */,
171913
+ 6 /* List */,
171914
+ 28 /* Set */,
171915
+ 5 /* Dictionary */,
171916
+ 30 /* Tuple */
171917
+ ].includes(numberField(member, "kind")),
171429
171918
  localDefinition: true,
171430
171919
  visited,
171431
171920
  decorateLocal: void 0
@@ -174214,7 +174703,7 @@ function slotRootPath(context, targetId) {
174214
174703
  id2 = edge.parentValueId;
174215
174704
  continue;
174216
174705
  }
174217
- const slot = context.readUnstoredSlots().get(id2);
174706
+ const slot = context.unstoredSlotParent(id2);
174218
174707
  if (slot === void 0) return null;
174219
174708
  segments.push(slot.schemaKey);
174220
174709
  id2 = slot.parentId;
@@ -174222,9 +174711,6 @@ function slotRootPath(context, targetId) {
174222
174711
  return null;
174223
174712
  }
174224
174713
  function unstoredSlotParents(document, project) {
174225
- const lookups = headlessVirtualInstanceLookups(document, {
174226
- initializerCompiler: documentInitializerCompiler(document, project)
174227
- });
174228
174714
  const classIndex = new Map(document.classes.map((c) => [c.id, c]));
174229
174715
  const memberIndex = new Map(document.members.map((m) => [m.id, m]));
174230
174716
  const slots = /* @__PURE__ */ new Map();
@@ -174243,24 +174729,36 @@ function unstoredSlotParents(document, project) {
174243
174729
  });
174244
174730
  }
174245
174731
  };
174246
- const visited = /* @__PURE__ */ new Set();
174247
- for (const row of document.values) {
174248
- addDerived(row);
174249
- if (typeof row.classId !== "string") continue;
174250
- const graph = lookups.virtualInstanceGraphForValue(row.id);
174251
- if (graph === null || visited.has(graph.instanceRootId)) continue;
174252
- visited.add(graph.instanceRootId);
174253
- for (const [id2, location3] of graph.locationsById) {
174254
- addDerived(location3.virtualRow);
174255
- if (location3.parentId == null) continue;
174256
- if (location3.parentSegment?.kind !== "class") continue;
174257
- slots.set(id2, {
174258
- parentId: location3.parentId,
174259
- schemaKey: location3.parentSegment.schemaKey
174260
- });
174732
+ for (const row of document.values) addDerived(row);
174733
+ function* expandSlots() {
174734
+ const lookups = headlessVirtualInstanceLookups(document, {
174735
+ initializerCompiler: documentInitializerCompiler(document, project())
174736
+ });
174737
+ const visited = /* @__PURE__ */ new Set();
174738
+ for (const row of document.values) {
174739
+ if (typeof row.classId !== "string") continue;
174740
+ const graph = lookups.virtualInstanceGraphForValue(row.id);
174741
+ if (graph === null || visited.has(graph.instanceRootId)) continue;
174742
+ visited.add(graph.instanceRootId);
174743
+ for (const [id2, location3] of graph.locationsById) {
174744
+ addDerived(location3.virtualRow);
174745
+ if (location3.parentId == null) continue;
174746
+ if (location3.parentSegment?.kind !== "class") continue;
174747
+ slots.set(id2, {
174748
+ parentId: location3.parentId,
174749
+ schemaKey: location3.parentSegment.schemaKey
174750
+ });
174751
+ }
174752
+ yield;
174261
174753
  }
174262
174754
  }
174263
- return slots;
174755
+ const expansion = expandSlots();
174756
+ return (id2) => {
174757
+ while (!slots.has(id2)) {
174758
+ if (expansion.next().done) break;
174759
+ }
174760
+ return slots.get(id2);
174761
+ };
174264
174762
  }
174265
174763
  function memberReferenceType(context, member) {
174266
174764
  if (typeof member.classId === "string") {
@@ -175763,6 +176261,9 @@ function reconciliationRecords(workspace, changes, seeds = /* @__PURE__ */ new M
175763
176261
  });
175764
176262
  }
175765
176263
  function materializeInitializersLocallyV4(args) {
176264
+ const constructionIdentities = indexAuthoredConstructionIdentities(
176265
+ args.localReferenceLocations ?? []
176266
+ );
175766
176267
  const records3 = prospectiveInitializerRecordsV4(args);
175767
176268
  const sourceRoots = initializerSourceRootIds(
175768
176269
  args.changes,
@@ -175995,7 +176496,7 @@ function materializeInitializersLocallyV4(args) {
175995
176496
  throw new PendingInitializerDependency(location3.rootId);
175996
176497
  if (pendingRoots.has(location3.rootId))
175997
176498
  throw new PendingInitializerDependency(location3.rootId);
175998
- const target = resolvedLocalIds.get(id2) ?? storedValueAtPathV4(
176499
+ const target = resolvedLocalIds.get(id2) ?? (location3.preserveIdentity && batch.valuesById.has(id2) ? id2 : null) ?? storedValueAtPathV4(
175999
176500
  batch.valuesById,
176000
176501
  location3.rootId,
176001
176502
  location3.path
@@ -176038,6 +176539,7 @@ function materializeInitializersLocallyV4(args) {
176038
176539
  pinnedSchemaKeysByValueId: /* @__PURE__ */ new Map()
176039
176540
  };
176040
176541
  const evaluated2 = replayStoredConstructionV4({
176542
+ captureConstructionEntries: constructionIdentities.has(sourceValueId),
176041
176543
  readTracking,
176042
176544
  records: records3,
176043
176545
  document,
@@ -176117,9 +176619,12 @@ function materializeInitializersLocallyV4(args) {
176117
176619
  }
176118
176620
  return [row];
176119
176621
  });
176120
- const sparse2 = sparsifyConstructedInstance({
176622
+ const authoredIdentities = constructionIdentities.get(sourceValueId);
176623
+ const sparse2 = sparsifyConstructedInstance2({
176624
+ authoredIdentities,
176625
+ constructionEntryIds: pinned.constructionEntryIds,
176121
176626
  localizedTextIds,
176122
- document,
176627
+ document: authoredIdentities?.length ? comparisonDocument() : document,
176123
176628
  rootMember: rootOwner,
176124
176629
  constructed: {
176125
176630
  root: evaluatedRoot,
@@ -176177,11 +176682,7 @@ function materializeInitializersLocallyV4(args) {
176177
176682
  for (const [id2, location3] of args.localReferenceLocations ?? []) {
176178
176683
  if (resolvedLocalIds.has(id2)) continue;
176179
176684
  if (unavailableRootIds.has(location3.rootId)) continue;
176180
- const target = storedValueAtPathV4(
176181
- batch.valuesById,
176182
- location3.rootId,
176183
- location3.path
176184
- );
176685
+ const target = location3.preserveIdentity && batch.valuesById.has(id2) ? id2 : storedValueAtPathV4(batch.valuesById, location3.rootId, location3.path);
176185
176686
  if (target !== null) resolvedLocalIds.set(id2, target);
176186
176687
  }
176187
176688
  return { roots, resolvedLocalIds, failures, unavailableRootIds };
@@ -185216,12 +185717,15 @@ function hydrateProspectiveMemberOverride(data, members2) {
185216
185717
  return hydrated;
185217
185718
  }
185218
185719
  function validProspectiveMember(member) {
185219
- if (!isMember(member)) {
185220
- throw new Error(
185221
- `Prospective animation validation received an invalid member record ${recordLabel(member)}.`
185222
- );
185223
- }
185224
- return member;
185720
+ if (isMember(member)) return member;
185721
+ const authored = readWithoutClientDerivedBodies(
185722
+ ProjectRecordKind.Member,
185723
+ member
185724
+ );
185725
+ if (isMember(authored)) return authored;
185726
+ throw new Error(
185727
+ `Prospective animation validation received an invalid member record ${recordLabel(member)}.`
185728
+ );
185225
185729
  }
185226
185730
  function closeInheritedCallableSignature(member, classes, members2) {
185227
185731
  if (typeof member.id !== "string") return member;
@@ -185645,6 +186149,7 @@ var sourceSchemaValidation, pulledAnimationValues, animationCompilationProject,
185645
186149
  var init_workspace_status_core = __esm({
185646
186150
  "src/project-source/workspace-status-core.ts"() {
185647
186151
  "use strict";
186152
+ init_neo_script_derived_bodies();
185648
186153
  init_identity_rewriter();
185649
186154
  init_initializer_replay();
185650
186155
  init_project_version_whole_graph_validation();
@@ -188867,6 +189372,48 @@ function preserveProjectFileRegistrySource(existing, emitted, records3 = /* @__P
188867
189372
  if (registryOnly) emitted = existing;
188868
189373
  return applySourceEdits(emitted, replacements);
188869
189374
  }
189375
+ function augmentAuthoredProjectFileRegistries(existing, emitted) {
189376
+ const authored = parseNeoProjectSource(existing, "definition");
189377
+ const generated = parseNeoProjectSource(emitted, "definition");
189378
+ const declarations = new Map(
189379
+ authored.declarations.flatMap(
189380
+ (declaration) => declaration.kind === "global" ? [[declaration.name, declaration]] : []
189381
+ )
189382
+ );
189383
+ const edits = [];
189384
+ const additions = [];
189385
+ for (const declaration of generated.declarations) {
189386
+ if (declaration.kind !== "global") continue;
189387
+ if (!["ImageRegistry", "AudioClipRegistry"].includes(declaration.type.name))
189388
+ continue;
189389
+ const content = emitted.slice(
189390
+ generated.syntax.source.offsetAt(declaration.range.start),
189391
+ generated.syntax.source.offsetAt(declaration.range.end)
189392
+ );
189393
+ const prior = declarations.get(declaration.name);
189394
+ if (prior === void 0) {
189395
+ additions.push(content);
189396
+ continue;
189397
+ }
189398
+ const start = authored.syntax.source.offsetAt(prior.range.start);
189399
+ const end = authored.syntax.source.offsetAt(prior.range.end);
189400
+ edits.push({
189401
+ start,
189402
+ end,
189403
+ text: preserveProjectFileRegistrySource(
189404
+ existing.slice(start, end),
189405
+ content
189406
+ )
189407
+ });
189408
+ }
189409
+ if (additions.length > 0)
189410
+ edits.push({
189411
+ start: existing.length,
189412
+ end: existing.length,
189413
+ text: "\n" + additions.join("\n\n") + "\n"
189414
+ });
189415
+ return applySourceEdits(existing, edits);
189416
+ }
188870
189417
  function registries(document, source, templateIds) {
188871
189418
  if (document.diagnostics.some((diagnostic) => diagnostic.severity === "error"))
188872
189419
  return [];
@@ -193952,6 +194499,10 @@ function expressionTokensBefore(tokens, endExclusive) {
193952
194499
  start = name;
193953
194500
  continue;
193954
194501
  }
194502
+ if (depth === 0 && token.kind === "keyword" && token.text === "in" && ![".", "?."].includes(tokens[start - 1]?.text ?? "")) {
194503
+ const opener = receiverEnclosingOpeners(tokens)[start] ?? -1;
194504
+ if (tokens[opener - 1]?.text === "foreach") break;
194505
+ }
193955
194506
  if (depth === 0 && token.text === "when" && start < endExclusive - 1 && ![".", "?.", "!", "[", "<"].includes(tokens[start + 1]?.text ?? "") && followsSwitchPattern(tokens, start))
193956
194507
  break;
193957
194508
  if (depth === 0 && (token.kind === "punctuation" && [";", "{", "}", ",", ":", "?"].includes(token.text) || // Only `?.` and `!` continue a receiver; every other operator
@@ -224398,7 +224949,7 @@ import {
224398
224949
  statSync as statSync7
224399
224950
  } from "node:fs";
224400
224951
  import { join as join22, relative as relative8, sep as sep9 } from "node:path";
224401
- function assignPendingIds(changes, authoredValueSeeds, reconstructed3, previousLedger = {}, codePendingIdCandidates = []) {
224952
+ function assignPendingIds(changes, authoredValueSeeds, reconstructed3, previousLedger = {}, codePendingIdCandidates = [], authoredPendingIds = []) {
224402
224953
  const assigned = /* @__PURE__ */ new Map();
224403
224954
  const minted = /* @__PURE__ */ new Map();
224404
224955
  let mint = (pendingId2) => {
@@ -224543,6 +225094,7 @@ function assignPendingIds(changes, authoredValueSeeds, reconstructed3, previousL
224543
225094
  for (const change of changes) collectCodeIds(change.nextData);
224544
225095
  for (const seed of authoredValueSeeds.values()) collectCodeIds(seed);
224545
225096
  }
225097
+ for (const id2 of authoredPendingIds) collect(id2);
224546
225098
  for (const root of roots) assign(root);
224547
225099
  const keys = identityLedgerKeys(minted.keys());
224548
225100
  const ledger = {};
@@ -225459,7 +226011,7 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
225459
226011
  } : void 0;
225460
226012
  onPhase("Hashing project source\u2026");
225461
226013
  const source = projectSourceIdentityForStatus(status);
225462
- const verificationSource = options.fullValidation ? locatedPendingProjectSourceIdentity(workspace, status) : null;
226014
+ const verificationSource = options.fullValidation ? authoredVerificationSource(workspace, status, source) : null;
225463
226015
  onPhase("Assigning pending value identities\u2026");
225464
226016
  const release = options.purpose === "evaluation" /* Evaluation */ ? await acquireWorkspaceLock(
225465
226017
  workspace.root,
@@ -225475,6 +226027,9 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
225475
226027
  { ...options.identityLedger, ...latestLedger },
225476
226028
  [...status.pendingValueIdentitySites ?? []].flatMap(
225477
226029
  ([id2, site]) => site.materializedLocation !== void 0 && pendingVirtualValueIdentity(id2) !== null ? [id2] : []
226030
+ ),
226031
+ [...status.pendingValueIdentitySites ?? []].flatMap(
226032
+ ([id2, site]) => site.materializedLocation?.preserveIdentity === true ? [id2] : []
225478
226033
  )
225479
226034
  );
225480
226035
  if (!mergeReservedIdentities(workspace.root, pendingAssignment.ledger)) {
@@ -225501,6 +226056,7 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
225501
226056
  status.changes,
225502
226057
  localizedTextCreateEnvelopeConfig2(workspace, status.changes)
225503
226058
  );
226059
+ let verifiedConstructionIdentities;
225504
226060
  try {
225505
226061
  if (verificationSource !== null) {
225506
226062
  onPhase("Verifying the assigned value-id stamps\u2026");
@@ -225510,8 +226066,8 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
225510
226066
  status.pendingValueIdentitySites,
225511
226067
  { sourceSnapshot: status.sourceSnapshot, validateResult: true }
225512
226068
  );
225513
- onPhase("Verifying the complete source round trip\u2026");
225514
- verifyProjectSourceCommitAgainstStateV4({
226069
+ onPhase("Verifying the authored source and ownership\u2026");
226070
+ verifiedConstructionIdentities = verifyProjectSourceCommitAgainstStateV4({
225515
226071
  projectId: workspace.config.projectId,
225516
226072
  versionId: workspace.config.versionId,
225517
226073
  stateRecords: workspace.state.records,
@@ -225533,6 +226089,23 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
225533
226089
  let prepared;
225534
226090
  try {
225535
226091
  const preparationArgs2 = {
226092
+ constructionIdentities: verifiedConstructionIdentities ?? indexAuthoredConstructionIdentities(
226093
+ [...status.pendingValueIdentitySites ?? []].flatMap(
226094
+ ([id2, site]) => {
226095
+ const location3 = site.materializedLocation;
226096
+ if (location3 === void 0) return [];
226097
+ return [
226098
+ [
226099
+ pendingAssignment.assigned.get(id2) ?? id2,
226100
+ {
226101
+ ...location3,
226102
+ rootId: pendingAssignment.assigned.get(location3.rootId) ?? location3.rootId
226103
+ }
226104
+ ]
226105
+ ];
226106
+ }
226107
+ )
226108
+ ),
225536
226109
  initializerReferenceOwners: new Map(
225537
226110
  [...status.pendingValueIdentitySites ?? []].flatMap(
225538
226111
  ([id2, site]) => site.materializedLocation === void 0 ? [] : [
@@ -225621,17 +226194,6 @@ function locatePreparationError(error, status, assigned) {
225621
226194
  if (source === void 0) return error;
225622
226195
  return new Error(`${source.file}:${source.line} \u2014 ${error.message}`);
225623
226196
  }
225624
- function locatedPendingProjectSourceIdentity(workspace, status) {
225625
- try {
225626
- return createPendingProjectSourceIdentityV4(
225627
- workspace,
225628
- status,
225629
- status.authoredValueSeeds
225630
- );
225631
- } catch (error) {
225632
- throw locatePreparationError(error, status, /* @__PURE__ */ new Map());
225633
- }
225634
- }
225635
226197
  async function prepareLocalCandidateV4(workspace, options = {}) {
225636
226198
  const pushOptions = {
225637
226199
  dryRun: options.dryRun ?? true,
@@ -225869,6 +226431,30 @@ function reportDryRunFailure(error, json) {
225869
226431
  }
225870
226432
  console.error(`Dry run failed: ${message}`);
225871
226433
  }
226434
+ function authoredVerificationSource(workspace, status, source) {
226435
+ let canonical;
226436
+ try {
226437
+ canonical = createPendingProjectSourceIdentityV4(
226438
+ workspace,
226439
+ status,
226440
+ status.authoredValueSeeds
226441
+ );
226442
+ } catch (error) {
226443
+ throw locatePreparationError(error, status, /* @__PURE__ */ new Map());
226444
+ }
226445
+ const files = new Map(source.files.map((file) => [file.path, file]));
226446
+ for (const file of canonical.files) {
226447
+ const prior = files.get(file.path);
226448
+ const content = augmentAuthoredProjectFileRegistries(
226449
+ prior?.content ?? "",
226450
+ file.content
226451
+ );
226452
+ if (content === (prior?.content ?? "")) continue;
226453
+ files.set(file.path, { ...file, content });
226454
+ }
226455
+ const result = [...files.values()];
226456
+ return { files: result, sourceHash: hashProjectSourceFiles(result) };
226457
+ }
225872
226458
  function projectSourceIdentityForStatus(status) {
225873
226459
  if (status.sourceSnapshot === void 0) {
225874
226460
  throw new Error(
@@ -226219,11 +226805,46 @@ ${blockingErrors.map((error) => ` ${error.message}`).join("\n")}`
226219
226805
  replacements.exact
226220
226806
  );
226221
226807
  const ownedLocalReplacements = new Map(replacements.exact);
226808
+ let committedNamedRows;
226809
+ let ownsCommittedPath;
226222
226810
  for (const [locator, site] of localStatus.pendingValueIdentitySites ?? []) {
226223
226811
  const location3 = site.materializedLocation;
226224
226812
  if (location3 === void 0) continue;
226225
226813
  const rootId = rewritePlacementValueId(location3.rootId, replacements);
226226
- const id2 = committedValueAtPath(rootId, location3.path);
226814
+ const expectedId = rewritePlacementValueId(locator, replacements);
226815
+ let id2 = committedValueAtPath(rootId, location3.path);
226816
+ if (location3.preserveIdentity === true) {
226817
+ committedNamedRows ??= storedValueRowsByIdV4(Object.values(nextRecords));
226818
+ const row = committedNamedRows.get(expectedId);
226819
+ if (row === void 0)
226820
+ throw new Error(
226821
+ `Committed named value ${locator} is missing its assigned identity ${expectedId}.`
226822
+ );
226823
+ if (id2 !== expectedId) {
226824
+ if (ownsCommittedPath === void 0) {
226825
+ const document = readProjectDocument(
226826
+ pulledProjectDocumentRaw({
226827
+ ...workspace,
226828
+ state: { ...workspace.state, records: nextRecords }
226829
+ })
226830
+ );
226831
+ const graph = new MaterializedValueGraphContext(document);
226832
+ ownsCommittedPath = storedValueOwnsPathV4(
226833
+ Object.values(nextRecords),
226834
+ committedNamedRows,
226835
+ (id3) => graph.ownerForValue(id3)
226836
+ );
226837
+ }
226838
+ const path = location3.path.map(
226839
+ (key) => typeof key === "string" ? replacements.exact.get(key) ?? key : key
226840
+ );
226841
+ if (!ownsCommittedPath(rootId, path, expectedId))
226842
+ throw new Error(
226843
+ `Committed named value ${locator} is absent from its owning path.`
226844
+ );
226845
+ }
226846
+ id2 = expectedId;
226847
+ }
226227
226848
  if (id2 === null)
226228
226849
  throw new Error(
226229
226850
  `Committed local value ${locator} has no row at its owning path.`
@@ -226778,8 +227399,13 @@ function materializeAssignedValueIdsInAuthoredSource(workspace, replacements, pe
226778
227399
  assignedId,
226779
227400
  options.committedValueAtPath
226780
227401
  );
226781
- if (entryStamps === null) continue;
226782
- if (site.stampIdentity !== false) {
227402
+ if (entryStamps === null && !site.materializedLocation?.preserveIdentity)
227403
+ continue;
227404
+ if (site.stampIdentity !== false && site.materializedLocation?.preserveIdentity) {
227405
+ file.edits.push(
227406
+ idStamp(file, sourceOffset2(file, site.declarationStart), assignedId)
227407
+ );
227408
+ } else if (site.stampIdentity !== false) {
226783
227409
  const row = rowAt(file, expressionOffset);
226784
227410
  if (row === null) continue;
226785
227411
  if (row.slot === 0 /* Entry */) {
@@ -226793,7 +227419,7 @@ function materializeAssignedValueIdsInAuthoredSource(workspace, replacements, pe
226793
227419
  file.edits.push(...stamp);
226794
227420
  }
226795
227421
  }
226796
- file.edits.push(...entryStamps);
227422
+ file.edits.push(...entryStamps ?? []);
226797
227423
  }
226798
227424
  const preserved = /* @__PURE__ */ new Map();
226799
227425
  for (const [uri, file] of files)
@@ -227610,6 +228236,8 @@ var compileNSVoidBody2, compileNSFunction2, compileNSGetter2, compileNSSetter2,
227610
228236
  var init_push = __esm({
227611
228237
  "src/commands/push.ts"() {
227612
228238
  "use strict";
228239
+ init_constructor_argument_ownership();
228240
+ init_virtual_instance_values();
227613
228241
  init_animation_child_binding_id();
227614
228242
  init_world_system_classes();
227615
228243
  init_local_project_file_storage();
@@ -243158,7 +243786,7 @@ var releaseWorkspaceLock = () => void 0;
243158
243786
  async function main() {
243159
243787
  const args = parseArgs(process.argv.slice(2));
243160
243788
  if (args.command === "--version") {
243161
- console.log("0.89.12");
243789
+ console.log("0.89.14");
243162
243790
  return;
243163
243791
  }
243164
243792
  if (args.command === null || args.command === "help" || args.command === "--help" || args.command === "-h") {