@neocompose/cli 0.26.3 → 0.26.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/neo.mjs CHANGED
@@ -41382,8 +41382,8 @@ function envFromStamp(stamp) {
41382
41382
  }
41383
41383
  return env;
41384
41384
  }
41385
- function substituteMember(member, env, members) {
41386
- const resolved = resolveMember2(member, members);
41385
+ function substituteMember(member, env, members, preResolvedMember) {
41386
+ const resolved = preResolvedMember ?? resolveMember2(member, members);
41387
41387
  if (isMemberGenericBase(resolved)) {
41388
41388
  const binding = substituteMember(
41389
41389
  resolveTerminalBinding(
@@ -42342,6 +42342,12 @@ function stampCreatedValuesMapKey(values, mapKey) {
42342
42342
  }
42343
42343
  }
42344
42344
  function applyDeclaredStorageKeyOverrides(args) {
42345
+ const boundaryValues = args.createdValues.filter(
42346
+ (value) => normalizeStorageKeyDeclaration(
42347
+ args.declarationByValueId.get(value.id)
42348
+ ) !== STORAGE_KEY_INHERIT
42349
+ );
42350
+ if (boundaryValues.length === 0) return;
42345
42351
  const createdById = new Map(
42346
42352
  args.createdValues.map((value) => [value.id, value])
42347
42353
  );
@@ -42367,12 +42373,7 @@ function applyDeclaredStorageKeyOverrides(args) {
42367
42373
  }
42368
42374
  return depth;
42369
42375
  };
42370
- const boundaries = args.createdValues.filter((value) => {
42371
- const declaration = normalizeStorageKeyDeclaration(
42372
- args.declarationByValueId.get(value.id)
42373
- );
42374
- return declaration !== STORAGE_KEY_INHERIT;
42375
- }).sort((left, right) => depthOf(left) - depthOf(right));
42376
+ const boundaries = boundaryValues.sort((left, right) => depthOf(left) - depthOf(right));
42376
42377
  for (const boundary of boundaries) {
42377
42378
  const parentCreated = parentOf.get(boundary.id);
42378
42379
  const parent = parentCreated !== void 0 ? {
@@ -43567,7 +43568,59 @@ function descendPositionThroughMember(position, memberId) {
43567
43568
  }
43568
43569
  function recordStorageKeyDeclaration(sink, valueId, member) {
43569
43570
  if (sink === void 0) return;
43570
- sink.set(valueId, normalizeStorageKeyDeclaration(member.storageKey));
43571
+ const declaration = normalizeStorageKeyDeclaration(member.storageKey);
43572
+ if (declaration === STORAGE_KEY_INHERIT) return;
43573
+ sink.set(valueId, declaration);
43574
+ }
43575
+ function documentHasInitValueContent(document, value) {
43576
+ return document.isInitValueContent?.(value) ?? isInitValueContent(value);
43577
+ }
43578
+ function createDocumentValueRow(document, projectId, body) {
43579
+ return document.createValueRow?.(projectId, body) ?? buildNewValue(projectId, body);
43580
+ }
43581
+ function directScalarDefaultBody(document, member) {
43582
+ if (member.kind !== 1 /* Bool */ && member.kind !== 2 /* Int */ && member.kind !== 4 /* Float */ && member.kind !== 3 /* String */ && member.kind !== 20 /* Decimal */ && member.kind !== 8 /* Enum */ && member.kind !== 0 /* Null */) {
43583
+ return void 0;
43584
+ }
43585
+ if (!member.required && (member.defaultValue === void 0 || member.defaultValue === null)) {
43586
+ return void 0;
43587
+ }
43588
+ if (documentHasInitValueContent(document, member.defaultValue)) {
43589
+ return void 0;
43590
+ }
43591
+ const body = member.defaultValue ?? primitiveFallbackValue(document, member);
43592
+ if (!isLiteralValueContent(body)) return void 0;
43593
+ if (body.value !== null && typeof body.value !== "boolean" && typeof body.value !== "number" && typeof body.value !== "string") {
43594
+ return void 0;
43595
+ }
43596
+ validateProjectDocumentFileMemberValue(
43597
+ document,
43598
+ member,
43599
+ body,
43600
+ DECLARATION_DEFAULT_POSITION
43601
+ );
43602
+ return { value: body.value, classId: body.classId };
43603
+ }
43604
+ function buildDefaultClassMaterializationPlan(document, classId, instanceEnv) {
43605
+ const merged = document.storedInstanceSchema?.(classId) ?? mergeStoredInstanceSchema(classId, document.classes, document.members);
43606
+ return merged.flatMap((entry) => {
43607
+ if (entry.memberId === null) return [];
43608
+ const childMember = findMemberInDocument(document, entry.memberId);
43609
+ if (!memberKindOwnsStoredValue(childMember.kind)) return [];
43610
+ const member = substituteMember(
43611
+ childMember,
43612
+ instanceEnv,
43613
+ document.members,
43614
+ document.resolvedMember?.(childMember)
43615
+ );
43616
+ return [
43617
+ {
43618
+ schemaKey: entry.schemaKey,
43619
+ member,
43620
+ directScalarBody: directScalarDefaultBody(document, member)
43621
+ }
43622
+ ];
43623
+ });
43571
43624
  }
43572
43625
  function assertLookupInitializerLiteral(member, literal2) {
43573
43626
  if (!isMemberLookupBase(member)) return;
@@ -43589,7 +43642,6 @@ function assertLookupInitializerLiteral(member, literal2) {
43589
43642
  function evaluateLiteralContainer(args) {
43590
43643
  const body = args.body;
43591
43644
  if (body === void 0) return void 0;
43592
- if (!isInitValueContent(body)) return { literal: body };
43593
43645
  if (args.initEvaluator === void 0) {
43594
43646
  throw new Error(
43595
43647
  `Cannot materialize member "${args.member.name}": its value is a NeoScript initializer, which this builder cannot evaluate. Supply an initEvaluator.`
@@ -43621,9 +43673,16 @@ function evaluateLiteralContainer(args) {
43621
43673
  };
43622
43674
  }
43623
43675
  function buildDefaultMemberValue(args) {
43624
- const member = args.genericEnv !== void 0 ? substituteMember(args.member, args.genericEnv, args.document.members) : resolveMember2(args.member, args.document.members);
43676
+ const resolvedMember = args.document.resolvedMember?.(args.member) ?? resolveMember2(args.member, args.document.members);
43677
+ const member = args.genericEnv !== void 0 ? substituteMember(
43678
+ args.member,
43679
+ args.genericEnv,
43680
+ args.document.members,
43681
+ resolvedMember
43682
+ ) : resolvedMember;
43625
43683
  const declaredDefault = member.defaultValue;
43626
- if (isInitValueContent(declaredDefault)) {
43684
+ if (documentHasInitValueContent(args.document, declaredDefault)) {
43685
+ const initializerCreatedValuesStart = args.createdValues.length;
43627
43686
  const evaluated = evaluateLiteralContainer({
43628
43687
  body: declaredDefault,
43629
43688
  member,
@@ -43637,13 +43696,17 @@ function buildDefaultMemberValue(args) {
43637
43696
  if (evaluated.existingValueRow !== void 0) {
43638
43697
  return evaluated.existingValueRow;
43639
43698
  }
43640
- const value2 = buildNewValue(args.projectId, evaluated.literal);
43699
+ const value2 = createDocumentValueRow(
43700
+ args.document,
43701
+ args.projectId,
43702
+ evaluated.literal
43703
+ );
43641
43704
  if (evaluated.genericBindings !== void 0) {
43642
43705
  value2.genericBindings = { ...evaluated.genericBindings };
43643
43706
  }
43644
43707
  if (evaluated.provisionalRootId !== void 0) {
43645
43708
  retargetDelegateReceiverValueIds(
43646
- [value2, ...args.createdValues],
43709
+ [value2, ...args.createdValues.slice(initializerCreatedValuesStart)],
43647
43710
  evaluated.provisionalRootId,
43648
43711
  value2.id
43649
43712
  );
@@ -43659,7 +43722,11 @@ function buildDefaultMemberValue(args) {
43659
43722
  `Required Class member "${member.name}" cannot have a null default.`
43660
43723
  );
43661
43724
  }
43662
- const value3 = buildNewValue(args.projectId, declaredDefault);
43725
+ const value3 = createDocumentValueRow(
43726
+ args.document,
43727
+ args.projectId,
43728
+ declaredDefault
43729
+ );
43663
43730
  args.createdValues.push(value3);
43664
43731
  recordStorageKeyDeclaration(
43665
43732
  args.storageKeyDeclarations,
@@ -43685,7 +43752,7 @@ function buildDefaultMemberValue(args) {
43685
43752
  `Cannot create a value of abstract class "${effectiveClass.name}".`
43686
43753
  );
43687
43754
  }
43688
- const childEnv = resolveInstanceEnv(
43755
+ const childEnv = args.document.instanceEnv?.(effectiveClassId, member.classArguments) ?? resolveInstanceEnv(
43689
43756
  effectiveClassId,
43690
43757
  member.classArguments,
43691
43758
  args.document.classes
@@ -43710,10 +43777,13 @@ function buildDefaultMemberValue(args) {
43710
43777
  );
43711
43778
  }
43712
43779
  }
43713
- const merged = mergeStoredInstanceSchema(
43780
+ const materializationPlan = args.document.storedInstanceMaterializationPlan?.(
43714
43781
  effectiveClassId,
43715
- args.document.classes,
43716
- args.document.members
43782
+ childEnv
43783
+ ) ?? buildDefaultClassMaterializationPlan(
43784
+ args.document,
43785
+ effectiveClassId,
43786
+ childEnv
43717
43787
  );
43718
43788
  const record3 = member.partial === true ? {} : cloneDefaultClassRecord({
43719
43789
  document: args.document,
@@ -43733,39 +43803,43 @@ function buildDefaultMemberValue(args) {
43733
43803
  position: DECLARATION_DEFAULT_POSITION
43734
43804
  });
43735
43805
  let anchorsParentClassPartition = false;
43736
- for (const entry of member.partial === true ? [] : merged) {
43737
- if (entry.memberId === null) continue;
43738
- const childMember = findMemberInDocument(args.document, entry.memberId);
43739
- if (!memberKindOwnsStoredValue(childMember.kind)) continue;
43740
- const resolvedChildMember = substituteMember(
43741
- childMember,
43742
- childEnv,
43743
- args.document.members
43744
- );
43806
+ for (const {
43807
+ schemaKey,
43808
+ member: resolvedChildMember,
43809
+ directScalarBody
43810
+ } of member.partial === true ? [] : materializationPlan) {
43745
43811
  if (storageKeyReferencesParentClass(
43746
43812
  normalizeStorageKeyDeclaration(resolvedChildMember.storageKey)
43747
43813
  )) {
43748
43814
  anchorsParentClassPartition = true;
43749
43815
  }
43750
- if (record3[entry.schemaKey] !== void 0) continue;
43751
- if (args.authoredRoot?.suppliedSchemaKeys.has(entry.schemaKey) === true) {
43816
+ if (record3[schemaKey] !== void 0) continue;
43817
+ if (args.authoredRoot?.suppliedSchemaKeys.has(schemaKey) === true) {
43752
43818
  continue;
43753
43819
  }
43754
43820
  if (skipProvidedConstructorSchemaKey(
43755
43821
  args.constructorRoot,
43756
- entry.schemaKey,
43757
- resolvedChildMember
43822
+ schemaKey,
43823
+ resolvedChildMember,
43824
+ documentHasInitValueContent(
43825
+ args.document,
43826
+ resolvedChildMember.defaultValue
43827
+ )
43758
43828
  )) {
43759
43829
  continue;
43760
43830
  }
43761
43831
  if (!shouldMaterializeChildDefaultForRoot(
43762
43832
  args.constructorRoot,
43763
- resolvedChildMember
43833
+ resolvedChildMember,
43834
+ documentHasInitValueContent(
43835
+ args.document,
43836
+ resolvedChildMember.defaultValue
43837
+ )
43764
43838
  )) {
43765
43839
  continue;
43766
43840
  }
43767
43841
  if (shouldSkipRequiredChildDefault(resolvedChildMember)) continue;
43768
- const childValue = buildDefaultMemberValue({
43842
+ const childValue = directScalarBody === void 0 ? buildDefaultMemberValue({
43769
43843
  document: args.document,
43770
43844
  projectId: args.projectId,
43771
43845
  member: resolvedChildMember,
@@ -43773,13 +43847,29 @@ function buildDefaultMemberValue(args) {
43773
43847
  storageKeyDeclarations: args.storageKeyDeclarations,
43774
43848
  initEvaluator: args.initEvaluator,
43775
43849
  genericEnv: childEnv
43776
- });
43777
- record3[entry.schemaKey] = childValue.id;
43850
+ }) : createDocumentValueRow(
43851
+ args.document,
43852
+ args.projectId,
43853
+ directScalarBody
43854
+ );
43855
+ if (directScalarBody !== void 0) {
43856
+ args.createdValues.push(childValue);
43857
+ recordStorageKeyDeclaration(
43858
+ args.storageKeyDeclarations,
43859
+ childValue.id,
43860
+ resolvedChildMember
43861
+ );
43862
+ }
43863
+ record3[schemaKey] = childValue.id;
43778
43864
  }
43779
- const value2 = buildNewValue(args.projectId, {
43780
- value: record3,
43781
- classId: member.partial === true || effectiveClassId !== member.classId || anchorsParentClassPartition ? effectiveClassId : void 0
43782
- });
43865
+ const value2 = createDocumentValueRow(
43866
+ args.document,
43867
+ args.projectId,
43868
+ {
43869
+ value: record3,
43870
+ classId: member.partial === true || effectiveClassId !== member.classId || anchorsParentClassPartition ? effectiveClassId : void 0
43871
+ }
43872
+ );
43783
43873
  args.createdValues.push(value2);
43784
43874
  recordStorageKeyDeclaration(args.storageKeyDeclarations, value2.id, member);
43785
43875
  return value2;
@@ -43797,7 +43887,11 @@ function buildDefaultMemberValue(args) {
43797
43887
  path: /* @__PURE__ */ new Set(),
43798
43888
  position: DECLARATION_DEFAULT_POSITION
43799
43889
  });
43800
- const value2 = buildNewValue(args.projectId, record3);
43890
+ const value2 = createDocumentValueRow(
43891
+ args.document,
43892
+ args.projectId,
43893
+ record3
43894
+ );
43801
43895
  stampGenericBindings(value2, member, args);
43802
43896
  args.createdValues.push(value2);
43803
43897
  recordStorageKeyDeclaration(args.storageKeyDeclarations, value2.id, member);
@@ -43816,14 +43910,20 @@ function buildDefaultMemberValue(args) {
43816
43910
  path: /* @__PURE__ */ new Set(),
43817
43911
  position: DECLARATION_DEFAULT_POSITION
43818
43912
  });
43819
- const value2 = buildNewValue(args.projectId, list);
43913
+ const value2 = createDocumentValueRow(
43914
+ args.document,
43915
+ args.projectId,
43916
+ list
43917
+ );
43820
43918
  stampGenericBindings(value2, member, args);
43821
43919
  args.createdValues.push(value2);
43822
43920
  recordStorageKeyDeclaration(args.storageKeyDeclarations, value2.id, member);
43823
43921
  return value2;
43824
43922
  }
43825
43923
  if (isMemberNullBase(member)) {
43826
- const value2 = buildNewValue(args.projectId, { value: null });
43924
+ const value2 = createDocumentValueRow(args.document, args.projectId, {
43925
+ value: null
43926
+ });
43827
43927
  args.createdValues.push(value2);
43828
43928
  recordStorageKeyDeclaration(args.storageKeyDeclarations, value2.id, member);
43829
43929
  return value2;
@@ -43843,30 +43943,33 @@ function buildDefaultMemberValue(args) {
43843
43943
  DECLARATION_DEFAULT_POSITION
43844
43944
  );
43845
43945
  }
43846
- const value = buildNewValue(args.projectId, clonedBody);
43946
+ const value = createDocumentValueRow(
43947
+ args.document,
43948
+ args.projectId,
43949
+ clonedBody
43950
+ );
43847
43951
  args.createdValues.push(value);
43848
43952
  recordStorageKeyDeclaration(args.storageKeyDeclarations, value.id, member);
43849
43953
  return value;
43850
43954
  }
43851
- function buildNewValue(projectId, body) {
43955
+ function buildNewValue(projectId, body, timestamp = Date.now()) {
43852
43956
  if (isInitValueContent(body)) {
43853
43957
  throw new Error(
43854
43958
  "Cannot build a value row from an initializer-backed container: the initializer must be evaluated into a literal value first."
43855
43959
  );
43856
43960
  }
43857
- const now = Date.now();
43858
43961
  const id2 = v4_default();
43859
43962
  const props = {
43860
43963
  id: id2,
43861
43964
  projectId,
43862
43965
  value: body.value,
43863
43966
  classId: body.classId ?? void 0,
43864
- ...body.constructorArgs === void 0 || body.constructorArgs === null ? {} : {
43865
- constructorArgs: cloneJsonValue(body.constructorArgs)
43866
- },
43867
- createdAt: now,
43868
- updatedAt: now
43967
+ createdAt: timestamp,
43968
+ updatedAt: timestamp
43869
43969
  };
43970
+ if (body.constructorArgs !== void 0 && body.constructorArgs !== null) {
43971
+ props.constructorArgs = cloneJsonValue(body.constructorArgs);
43972
+ }
43870
43973
  return props;
43871
43974
  }
43872
43975
  function retargetDelegateReceiverValueIds(rows, fromValueId, toValueId) {
@@ -44009,9 +44112,11 @@ function cloneDefaultValueForMember(args) {
44009
44112
  const member = substituteMember(
44010
44113
  args.member,
44011
44114
  args.genericEnv,
44012
- args.document.members
44115
+ args.document.members,
44116
+ args.document.resolvedMember?.(args.member)
44013
44117
  );
44014
- if (isInitValueContent(sourceValue)) {
44118
+ if (documentHasInitValueContent(args.document, sourceValue)) {
44119
+ const initializerCreatedValuesStart = args.createdValues.length;
44015
44120
  const evaluated = evaluateLiteralContainer({
44016
44121
  body: sourceValue,
44017
44122
  member,
@@ -44026,13 +44131,20 @@ function cloneDefaultValueForMember(args) {
44026
44131
  if (evaluated.existingValueRow !== void 0) {
44027
44132
  return evaluated.existingValueRow;
44028
44133
  }
44029
- const evaluatedRow = buildNewValue(args.projectId, evaluated.literal);
44134
+ const evaluatedRow = createDocumentValueRow(
44135
+ args.document,
44136
+ args.projectId,
44137
+ evaluated.literal
44138
+ );
44030
44139
  if (evaluated.genericBindings !== void 0) {
44031
44140
  evaluatedRow.genericBindings = { ...evaluated.genericBindings };
44032
44141
  }
44033
44142
  if (evaluated.provisionalRootId !== void 0) {
44034
44143
  retargetDelegateReceiverValueIds(
44035
- [evaluatedRow, ...args.createdValues],
44144
+ [
44145
+ evaluatedRow,
44146
+ ...args.createdValues.slice(initializerCreatedValuesStart)
44147
+ ],
44036
44148
  evaluated.provisionalRootId,
44037
44149
  evaluatedRow.id
44038
44150
  );
@@ -44049,7 +44161,7 @@ function cloneDefaultValueForMember(args) {
44049
44161
  let body;
44050
44162
  if (isMemberClassBase(member)) {
44051
44163
  const effectiveClassId = typeof sourceValue.classId === "string" ? sourceValue.classId : member.classId;
44052
- const childEnv = resolveInstanceEnv(
44164
+ const childEnv = args.document.instanceEnv?.(effectiveClassId, member.classArguments) ?? resolveInstanceEnv(
44053
44165
  effectiveClassId,
44054
44166
  member.classArguments,
44055
44167
  args.document.classes
@@ -44107,7 +44219,7 @@ function cloneDefaultValueForMember(args) {
44107
44219
  args.position
44108
44220
  );
44109
44221
  }
44110
- const value = buildNewValue(args.projectId, body);
44222
+ const value = createDocumentValueRow(args.document, args.projectId, body);
44111
44223
  value.sourceValueId = sourceValue.sourceValueId ?? sourceValue.id;
44112
44224
  if (isMemberListBase(member) || isMemberDictionaryBase(member)) {
44113
44225
  stampGenericBindings(value, member, args);
@@ -44130,9 +44242,7 @@ function formatDefaultReferenceLocation(memberName, key) {
44130
44242
  }
44131
44243
  function getSchemaEntryMap(document, classId) {
44132
44244
  return new Map(
44133
- mergeStoredInstanceSchema(classId, document.classes, document.members).map(
44134
- (entry) => [entry.schemaKey, entry]
44135
- )
44245
+ (document.storedInstanceSchema?.(classId) ?? mergeStoredInstanceSchema(classId, document.classes, document.members)).map((entry) => [entry.schemaKey, entry])
44136
44246
  );
44137
44247
  }
44138
44248
  function cloneMemberValueBase(body) {
@@ -44189,26 +44299,26 @@ function shouldMaterializeChildDefault(member) {
44189
44299
  }
44190
44300
  return member.defaultValue !== void 0;
44191
44301
  }
44192
- function shouldMaterializeConstructorChildDefault(member) {
44193
- if (isInitValueContent(member.defaultValue)) return true;
44302
+ function shouldMaterializeConstructorChildDefault(member, isInitializer = isInitValueContent(member.defaultValue)) {
44303
+ if (isInitializer) return true;
44194
44304
  if (!member.required) return false;
44195
44305
  return shouldMaterializeChildDefault(member);
44196
44306
  }
44197
- function skipProvidedConstructorSchemaKey(constructorRoot, schemaKey, member) {
44307
+ function skipProvidedConstructorSchemaKey(constructorRoot, schemaKey, member, isInitializer = isInitValueContent(member.defaultValue)) {
44198
44308
  if (constructorRoot === void 0) return false;
44199
44309
  if (!constructorRoot.providedSchemaKeys.has(schemaKey)) return false;
44200
44310
  if (constructorRoot.runsMemberInitializers !== true) {
44201
- return !isInitValueContent(member.defaultValue);
44311
+ return !isInitializer;
44202
44312
  }
44203
44313
  return member.defaultValue === void 0;
44204
44314
  }
44205
- function shouldMaterializeChildDefaultForRoot(constructorRoot, member) {
44315
+ function shouldMaterializeChildDefaultForRoot(constructorRoot, member, isInitializer = isInitValueContent(member.defaultValue)) {
44206
44316
  if (constructorRoot === void 0)
44207
44317
  return shouldMaterializeChildDefault(member);
44208
44318
  if (constructorRoot.runsMemberInitializers === true) {
44209
44319
  return shouldMaterializeChildDefault(member);
44210
44320
  }
44211
- return shouldMaterializeConstructorChildDefault(member);
44321
+ return shouldMaterializeConstructorChildDefault(member, isInitializer);
44212
44322
  }
44213
44323
  function primitiveFallbackValue(document, member) {
44214
44324
  if (isMemberBoolBase(member)) return { value: false };
@@ -58443,6 +58553,7 @@ function buildEvaluatorBaseIndexes(members, values, valueById = new Map(
58443
58553
  ownershipRootIdsByRowId: /* @__PURE__ */ new Map(),
58444
58554
  ownershipDistancesByRowId: /* @__PURE__ */ new Map(),
58445
58555
  ownedValueAttachmentsByValueId: /* @__PURE__ */ new Map(),
58556
+ constructorOwnershipDirtyValueIds: /* @__PURE__ */ new Set(),
58446
58557
  memberByRowId: /* @__PURE__ */ new Map()
58447
58558
  };
58448
58559
  const membersByValueId = /* @__PURE__ */ new Map();
@@ -58454,7 +58565,7 @@ function buildEvaluatorBaseIndexes(members, values, valueById = new Map(
58454
58565
  membersByValueId.set(member.valueId, bucket);
58455
58566
  }
58456
58567
  }
58457
- for (const row of values) indexEvaluatorRow(indexes, row);
58568
+ indexEvaluatorRows(indexes, values);
58458
58569
  return {
58459
58570
  rows: values,
58460
58571
  valueById,
@@ -58498,6 +58609,7 @@ function evaluatorIndexes(ctx) {
58498
58609
  ownershipRootIdsByRowId: sharedOwnershipCaches?.ownershipRootIdsByRowId ?? /* @__PURE__ */ new Map(),
58499
58610
  ownershipDistancesByRowId: sharedOwnershipCaches?.ownershipDistancesByRowId ?? /* @__PURE__ */ new Map(),
58500
58611
  ownedValueAttachmentsByValueId: /* @__PURE__ */ new Map(),
58612
+ constructorOwnershipDirtyValueIds: /* @__PURE__ */ new Set(),
58501
58613
  memberByRowId: /* @__PURE__ */ new Map()
58502
58614
  };
58503
58615
  if (base === void 0) {
@@ -58506,18 +58618,21 @@ function evaluatorIndexes(ctx) {
58506
58618
  indexes.memberByValueId.set(member.valueId, member);
58507
58619
  }
58508
58620
  }
58509
- for (const row of evaluatorValues(ctx)) indexEvaluatorRow(indexes, row);
58621
+ indexEvaluatorRows(indexes, evaluatorValues(ctx));
58510
58622
  } else {
58623
+ const localRows = [];
58511
58624
  for (const row of ctx.__runtimeSessionValues?.values() ?? []) {
58512
58625
  indexes.shadowedBaseRowIds.add(row.id);
58513
- indexEvaluatorRow(indexes, row, true);
58626
+ localRows.push(row);
58514
58627
  }
58515
58628
  for (const row of ctx.__valueOverlay?.values() ?? []) {
58516
58629
  indexes.shadowedBaseRowIds.add(row.id);
58517
- indexEvaluatorRow(indexes, row, true);
58630
+ localRows.push(row);
58518
58631
  }
58632
+ indexEvaluatorRows(indexes, localRows, true);
58519
58633
  }
58520
58634
  syncLazyOverlayReferences(indexes, ctx.__valueOverlay);
58635
+ indexes.constructorOwnershipDirtyValueIds.clear();
58521
58636
  ctx.__indexes = indexes;
58522
58637
  return indexes;
58523
58638
  }
@@ -58534,27 +58649,32 @@ function syncLazyOverlayReferences(indexes, overlay) {
58534
58649
  }
58535
58650
  indexes.indexedOverlayRowCount += materializedRows.length;
58536
58651
  }
58537
- function indexEvaluatorRow(indexes, row, allowBaseShadow = false) {
58652
+ function indexEvaluatorRow(indexes, row, allowBaseShadow = false, sharedCachesAlreadyInvalidated = false) {
58653
+ if (indexes.indexedRowIds.has(row.id) || !allowBaseShadow && indexes.baseIndexedRowIds?.has(row.id) === true) {
58654
+ return;
58655
+ }
58656
+ if (!sharedCachesAlreadyInvalidated) {
58657
+ indexes.ownershipRootIdsByRowId.clear();
58658
+ indexes.ownershipDistancesByRowId.clear();
58659
+ indexes.memberByRowId.clear();
58660
+ }
58538
58661
  indexes.ownedValueAttachmentsByValueId.delete(row.id);
58662
+ indexes.constructorOwnershipDirtyValueIds.add(row.id);
58539
58663
  if (Array.isArray(row.value)) {
58540
58664
  for (const childId of row.value) {
58541
58665
  if (typeof childId === "string") {
58542
58666
  indexes.ownedValueAttachmentsByValueId.delete(childId);
58667
+ indexes.constructorOwnershipDirtyValueIds.add(childId);
58543
58668
  }
58544
58669
  }
58545
58670
  } else if (typeof row.value === "object" && row.value !== null) {
58546
58671
  for (const childId of Object.values(row.value)) {
58547
58672
  if (typeof childId === "string") {
58548
58673
  indexes.ownedValueAttachmentsByValueId.delete(childId);
58674
+ indexes.constructorOwnershipDirtyValueIds.add(childId);
58549
58675
  }
58550
58676
  }
58551
58677
  }
58552
- indexes.ownershipRootIdsByRowId.clear();
58553
- indexes.ownershipDistancesByRowId.clear();
58554
- indexes.memberByRowId.clear();
58555
- if (indexes.indexedRowIds.has(row.id) || !allowBaseShadow && indexes.baseIndexedRowIds?.has(row.id) === true) {
58556
- return;
58557
- }
58558
58678
  indexes.indexedRowIds.add(row.id);
58559
58679
  if (typeof row.sourceValueId === "string") {
58560
58680
  const rows = indexes.rowsBySourceValueId.get(row.sourceValueId) ?? [];
@@ -58582,6 +58702,55 @@ function indexEvaluatorRow(indexes, row, allowBaseShadow = false) {
58582
58702
  }
58583
58703
  }
58584
58704
  }
58705
+ function indexEvaluatorRows(indexes, rows, allowBaseShadow = false) {
58706
+ let sharedCachesInvalidated = false;
58707
+ for (const row of rows) {
58708
+ const alreadyIndexed = indexes.indexedRowIds.has(row.id) || !allowBaseShadow && indexes.baseIndexedRowIds?.has(row.id) === true;
58709
+ if (alreadyIndexed) continue;
58710
+ if (!sharedCachesInvalidated) {
58711
+ indexes.ownershipRootIdsByRowId.clear();
58712
+ indexes.ownershipDistancesByRowId.clear();
58713
+ indexes.memberByRowId.clear();
58714
+ sharedCachesInvalidated = true;
58715
+ }
58716
+ indexEvaluatorRow(indexes, row, allowBaseShadow, true);
58717
+ }
58718
+ }
58719
+ function unindexEvaluatorRow(indexes, row) {
58720
+ indexes.indexedRowIds.delete(row.id);
58721
+ indexes.ownedValueAttachmentsByValueId.delete(row.id);
58722
+ indexes.constructorOwnershipDirtyValueIds.delete(row.id);
58723
+ indexes.parentLinksByChildId.delete(row.id);
58724
+ if (typeof row.value === "object" && row.value !== null && indexes.rowByValueReference.get(row.value) === row) {
58725
+ indexes.rowByValueReference.delete(row.value);
58726
+ }
58727
+ if (typeof row.sourceValueId === "string") {
58728
+ const sourceRows = indexes.rowsBySourceValueId.get(row.sourceValueId);
58729
+ if (sourceRows !== void 0) {
58730
+ const retained = sourceRows.filter((candidate) => candidate !== row);
58731
+ if (retained.length === 0) {
58732
+ indexes.rowsBySourceValueId.delete(row.sourceValueId);
58733
+ } else {
58734
+ indexes.rowsBySourceValueId.set(row.sourceValueId, retained);
58735
+ }
58736
+ }
58737
+ }
58738
+ const childIds = Array.isArray(row.value) ? row.value : typeof row.value === "object" && row.value !== null ? Object.values(row.value) : [];
58739
+ for (const childId of childIds) {
58740
+ if (typeof childId !== "string") continue;
58741
+ const links = indexes.parentLinksByChildId.get(childId);
58742
+ if (links !== void 0) {
58743
+ const retained = links.filter((link) => link.parentId !== row.id);
58744
+ if (retained.length === 0) indexes.parentLinksByChildId.delete(childId);
58745
+ else indexes.parentLinksByChildId.set(childId, retained);
58746
+ }
58747
+ indexes.ownedValueAttachmentsByValueId.delete(childId);
58748
+ indexes.constructorOwnershipDirtyValueIds.add(childId);
58749
+ }
58750
+ indexes.ownershipRootIdsByRowId.clear();
58751
+ indexes.ownershipDistancesByRowId.clear();
58752
+ indexes.memberByRowId.clear();
58753
+ }
58585
58754
  function addEvaluatorParentLink(indexes, childId, parentId, key) {
58586
58755
  const links = indexes.parentLinksByChildId.get(childId) ?? [];
58587
58756
  links.push({ parentId, key });
@@ -58751,6 +58920,12 @@ function evaluatorResolutionCache(ctx) {
58751
58920
  compiledFunctionByMemberId: /* @__PURE__ */ new Map(),
58752
58921
  compiledGetterByMemberId: /* @__PURE__ */ new Map(),
58753
58922
  compiledSetterByMemberId: /* @__PURE__ */ new Map(),
58923
+ resolvedMemberById: /* @__PURE__ */ new Map(),
58924
+ storedInstanceSchemaByClassId: /* @__PURE__ */ new Map(),
58925
+ instanceEnvByKey: /* @__PURE__ */ new Map(),
58926
+ validatedConstructorDescriptorByInfo: /* @__PURE__ */ new WeakMap(),
58927
+ validatedInitValueContents: /* @__PURE__ */ new WeakSet(),
58928
+ storedInstanceMaterializationPlanByClassAndEnv: /* @__PURE__ */ new Map(),
58754
58929
  effectiveStorageResolver: void 0
58755
58930
  };
58756
58931
  resolutionCacheByMembers.set(members, {
@@ -58762,10 +58937,139 @@ function evaluatorResolutionCache(ctx) {
58762
58937
  ctx.__resolutionCache = cache;
58763
58938
  return cache;
58764
58939
  }
58765
- function createdSessionValuesSince(session, existingIds) {
58940
+ function cachedResolvedMember(member, ctx) {
58941
+ const memberId = member.id;
58942
+ if (typeof memberId !== "string") {
58943
+ return resolveMember2(member, ctx.vm.members);
58944
+ }
58945
+ const cache = evaluatorResolutionCache(ctx).resolvedMemberById;
58946
+ const cached = cache.get(memberId);
58947
+ if (cached !== void 0) return cached;
58948
+ const resolved = resolveMember2(member, ctx.vm.members);
58949
+ cache.set(memberId, resolved);
58950
+ return resolved;
58951
+ }
58952
+ function cachedStoredInstanceSchema(classId, ctx) {
58953
+ const cache = evaluatorResolutionCache(ctx).storedInstanceSchemaByClassId;
58954
+ const cached = cache.get(classId);
58955
+ if (cached !== void 0) return cached;
58956
+ const merged = mergeStoredInstanceSchema(
58957
+ classId,
58958
+ ctx.vm.classes,
58959
+ ctx.vm.members
58960
+ );
58961
+ cache.set(classId, merged);
58962
+ return merged;
58963
+ }
58964
+ function cachedStoredInstanceMaterializationPlan(classId, instanceEnv, ctx) {
58965
+ const cache = evaluatorResolutionCache(
58966
+ ctx
58967
+ ).storedInstanceMaterializationPlanByClassAndEnv;
58968
+ let byEnvironment = cache.get(classId);
58969
+ const cached = byEnvironment?.get(instanceEnv);
58970
+ if (cached !== void 0) return cached;
58971
+ const plan = buildDefaultClassMaterializationPlan(
58972
+ {
58973
+ project: ctx.vm.project,
58974
+ members: ctx.vm.members,
58975
+ classes: ctx.vm.classes,
58976
+ enums: ctx.vm.enums,
58977
+ values: ctx.vm.values,
58978
+ memberById: ctx.vm.databaseVM?.memberById,
58979
+ valueById: ctx.vm.databaseVM?.valueById,
58980
+ resolvedMember: (member) => cachedResolvedMember(member, ctx),
58981
+ storedInstanceSchema: (nestedClassId) => cachedStoredInstanceSchema(nestedClassId, ctx),
58982
+ instanceEnv: (nestedClassId, classArguments2) => cachedInstanceEnv(nestedClassId, classArguments2, ctx),
58983
+ isInitValueContent: (value) => cachedIsInitValueContent(value, ctx),
58984
+ projectFiles: ctx.vm.projectFiles ?? [],
58985
+ textureTemplates: ctx.vm.textureTemplates ?? []
58986
+ },
58987
+ classId,
58988
+ instanceEnv
58989
+ );
58990
+ byEnvironment ??= /* @__PURE__ */ new WeakMap();
58991
+ byEnvironment.set(instanceEnv, plan);
58992
+ cache.set(classId, byEnvironment);
58993
+ return plan;
58994
+ }
58995
+ function cachedInstanceEnv(classId, classArguments2, ctx) {
58996
+ const key = `${classId}:${JSON.stringify(classArguments2 ?? null)}`;
58997
+ const cache = evaluatorResolutionCache(ctx).instanceEnvByKey;
58998
+ const cached = cache.get(key);
58999
+ if (cached !== void 0) return cached;
59000
+ const resolved = resolveInstanceEnv(classId, classArguments2, ctx.vm.classes);
59001
+ cache.set(key, resolved);
59002
+ return resolved;
59003
+ }
59004
+ function cachedIsInitValueContent(value, ctx) {
59005
+ if (typeof value !== "object" || value === null) return false;
59006
+ const cache = evaluatorResolutionCache(ctx).validatedInitValueContents;
59007
+ if (cache.has(value)) return true;
59008
+ if (!isInitValueContent(value)) return false;
59009
+ cache.add(value);
59010
+ return true;
59011
+ }
59012
+ function sessionCreationCheckpoint(ctx) {
59013
+ if (ctx.__sessionCreationStrategy === "snapshot") {
59014
+ return new Set(ctx.__runtimeSessionValues?.keys());
59015
+ }
59016
+ const state = ctx.__executionState;
59017
+ if (state === void 0) {
59018
+ throw new NSGetterRuntimeError(
59019
+ "Created Session values require an effect-capable evaluator scope."
59020
+ );
59021
+ }
59022
+ return state.sessionCreationJournal.length;
59023
+ }
59024
+ function registerRuntimeSessionValue(ctx, row) {
59025
+ const session = ctx.__runtimeSessionValues;
59026
+ const state = ctx.__executionState;
59027
+ if (session === void 0 || state === void 0) {
59028
+ throw new NSGetterRuntimeError(
59029
+ "Session publication requires an effect-capable evaluator scope."
59030
+ );
59031
+ }
59032
+ if (!state.knownSessionValueIds.has(row.id)) {
59033
+ state.knownSessionValueIds.add(row.id);
59034
+ state.sessionCreationJournal.push(row.id);
59035
+ }
59036
+ session.set(row.id, row);
59037
+ }
59038
+ function deleteRuntimeSessionValue(ctx, rowId) {
59039
+ const session = ctx.__runtimeSessionValues;
59040
+ if (session === void 0) return;
59041
+ const row = session.get(rowId);
59042
+ if (row !== void 0 && ctx.__indexes !== void 0) {
59043
+ unindexEvaluatorRow(ctx.__indexes, row);
59044
+ }
59045
+ session.delete(rowId);
59046
+ }
59047
+ function createdSessionValuesSince(ctx, checkpoint) {
59048
+ const session = ctx.__runtimeSessionValues;
59049
+ const state = ctx.__executionState;
59050
+ if (session === void 0 || state === void 0) {
59051
+ throw new NSGetterRuntimeError(
59052
+ "Created Session values require an effect-capable evaluator scope."
59053
+ );
59054
+ }
58766
59055
  const created = [];
58767
- for (const row of session.values()) {
58768
- if (existingIds.has(row.id)) continue;
59056
+ if (typeof checkpoint !== "number") {
59057
+ for (const row of session.values()) {
59058
+ if (checkpoint.has(row.id)) continue;
59059
+ if (!isLiteralValueContent(row)) {
59060
+ throw new NSGetterRuntimeError(
59061
+ `Evaluator Session row ${row.id} carries an unevaluated initializer instead of a value.`
59062
+ );
59063
+ }
59064
+ created.push(row);
59065
+ }
59066
+ return created;
59067
+ }
59068
+ for (let index = checkpoint; index < state.sessionCreationJournal.length; index += 1) {
59069
+ const rowId = state.sessionCreationJournal[index];
59070
+ if (rowId === void 0) continue;
59071
+ const row = session.get(rowId);
59072
+ if (row === void 0) continue;
58769
59073
  if (!isLiteralValueContent(row)) {
58770
59074
  throw new NSGetterRuntimeError(
58771
59075
  `Evaluator Session row '${row.id}' carries an unevaluated initializer instead of a value.`
@@ -58784,7 +59088,7 @@ function evaluateNSGetterWithEffects(getter, ctx, argumentValues = []) {
58784
59088
  const runtimeCtx = withEvaluationRuntime(ctx, requestedWrites);
58785
59089
  consumeBudget(runtimeCtx, "workUnits", 1, "work unit");
58786
59090
  const writes = runtimeCtx.__executionState?.writes ?? requestedWrites;
58787
- const existingIds = new Set(runtimeCtx.__runtimeSessionValues.keys());
59091
+ const creationCheckpoint = sessionCreationCheckpoint(runtimeCtx);
58788
59092
  const scope = createTopLevelScope(runtimeCtx);
58789
59093
  const parameters = getter.parameters.slice(2);
58790
59094
  if (parameters.length !== argumentValues.length) {
@@ -58816,8 +59120,8 @@ function evaluateNSGetterWithEffects(getter, ctx, argumentValues = []) {
58816
59120
  );
58817
59121
  result.value = preserveReadOnlyReturnIdentity(result.value, runtimeCtx);
58818
59122
  const createdSessionValues = createdSessionValuesSince(
58819
- runtimeCtx.__runtimeSessionValues,
58820
- existingIds
59123
+ runtimeCtx,
59124
+ creationCheckpoint
58821
59125
  );
58822
59126
  return createdSessionValues.length === 0 ? { value: result.value, writes } : { value: result.value, writes, createdSessionValues };
58823
59127
  }
@@ -58834,7 +59138,7 @@ function evaluateNSVoidBody(action, ctx) {
58834
59138
  const writes = [];
58835
59139
  const runtimeCtx = withEvaluationRuntime(ctx, writes);
58836
59140
  consumeBudget(runtimeCtx, "workUnits", 1, "work unit");
58837
- const existingIds = new Set(runtimeCtx.__runtimeSessionValues.keys());
59141
+ const creationCheckpoint = sessionCreationCheckpoint(runtimeCtx);
58838
59142
  const scope = createTopLevelScope(runtimeCtx);
58839
59143
  try {
58840
59144
  const result = evalInstructions(action.instructions, scope, runtimeCtx, {
@@ -58855,8 +59159,8 @@ function evaluateNSVoidBody(action, ctx) {
58855
59159
  throw error;
58856
59160
  }
58857
59161
  const createdSessionValues = createdSessionValuesSince(
58858
- runtimeCtx.__runtimeSessionValues,
58859
- existingIds
59162
+ runtimeCtx,
59163
+ creationCheckpoint
58860
59164
  );
58861
59165
  return createdSessionValues.length === 0 ? { writes } : { writes, createdSessionValues };
58862
59166
  }
@@ -58865,7 +59169,7 @@ function evaluateNSFunction(action, ctx, args) {
58865
59169
  const writes = [];
58866
59170
  const runtimeCtx = withEvaluationRuntime(ctx, writes);
58867
59171
  consumeBudget(runtimeCtx, "workUnits", 1, "work unit");
58868
- const existingIds = new Set(runtimeCtx.__runtimeSessionValues.keys());
59172
+ const creationCheckpoint = sessionCreationCheckpoint(runtimeCtx);
58869
59173
  const runtimeArgs = remapRuntimeArguments(args, runtimeCtx);
58870
59174
  let value;
58871
59175
  try {
@@ -58886,8 +59190,8 @@ function evaluateNSFunction(action, ctx, args) {
58886
59190
  throw error;
58887
59191
  }
58888
59192
  const createdSessionValues = createdSessionValuesSince(
58889
- runtimeCtx.__runtimeSessionValues,
58890
- existingIds
59193
+ runtimeCtx,
59194
+ creationCheckpoint
58891
59195
  );
58892
59196
  return createdSessionValues.length === 0 ? { value, writes } : { value, writes, createdSessionValues };
58893
59197
  }
@@ -58912,6 +59216,7 @@ function withEvaluationRuntime(ctx, writes) {
58912
59216
  }
58913
59217
  const overlay = ctx.__valueOverlay ?? (ctx.storedConstructionReplay === true ? /* @__PURE__ */ new Map() : buildValueOverlay(ctx.vm));
58914
59218
  const referenceRemap = ctx.__runtimeReferenceRemap ?? /* @__PURE__ */ new Map();
59219
+ const runtimeSessionValues = ctx.__runtimeSessionValues ?? /* @__PURE__ */ new Map();
58915
59220
  const runtimeReferences = runtimeSessionValueReferences(
58916
59221
  ctx.__runtimeSessionValues
58917
59222
  );
@@ -58930,7 +59235,7 @@ function withEvaluationRuntime(ctx, writes) {
58930
59235
  primary: remap(ctx.dialogueContext.primary),
58931
59236
  trigger: remap(ctx.dialogueContext.trigger)
58932
59237
  },
58933
- __runtimeSessionValues: ctx.__runtimeSessionValues ?? /* @__PURE__ */ new Map(),
59238
+ __runtimeSessionValues: runtimeSessionValues,
58934
59239
  __saveStaticBindings: ctx.__saveStaticBindings ?? staticBindingMap(ctx.saveStaticBindings),
58935
59240
  __sessionStaticBindings: ctx.__sessionStaticBindings ?? staticBindingMap(ctx.sessionStaticBindings),
58936
59241
  __valueOverlay: overlay,
@@ -58939,7 +59244,12 @@ function withEvaluationRuntime(ctx, writes) {
58939
59244
  writes,
58940
59245
  functionStack: [],
58941
59246
  delegateStack: [],
59247
+ knownSessionValueIds: new Set(runtimeSessionValues.keys()),
59248
+ sessionCreationJournal: [],
58942
59249
  constructorGroups: /* @__PURE__ */ new Map(),
59250
+ constructorGroupByRowId: /* @__PURE__ */ new Map(),
59251
+ constructorGroupDependencies: /* @__PURE__ */ new Map(),
59252
+ constructionTimestamp: Date.now(),
58943
59253
  ownedValueAttachments: /* @__PURE__ */ new Map(),
58944
59254
  constructionStack: [],
58945
59255
  loopIterations: 0,
@@ -59098,10 +59408,22 @@ function finalizeConstructorAllocations(ctx, returnValue, ownsInvocationState, r
59098
59408
  }
59099
59409
  const escapedRoots = /* @__PURE__ */ new Set();
59100
59410
  const scannedRows = /* @__PURE__ */ new Set();
59411
+ const markConstructorGroupEscaped = (rootId) => {
59412
+ if (escapedRoots.has(rootId)) return;
59413
+ escapedRoots.add(rootId);
59414
+ for (const dependencyRootId of state.constructorGroupDependencies.get(
59415
+ rootId
59416
+ ) ?? []) {
59417
+ markConstructorGroupEscaped(dependencyRootId);
59418
+ }
59419
+ };
59101
59420
  const isOwnedRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
59102
59421
  const scanOwnedRow = (valueId, hintedMember) => {
59103
59422
  const groupRoot = groupByRowId.get(valueId);
59104
- if (groupRoot !== void 0) escapedRoots.add(groupRoot);
59423
+ if (groupRoot !== void 0) {
59424
+ markConstructorGroupEscaped(groupRoot);
59425
+ return;
59426
+ }
59105
59427
  if (scannedRows.has(valueId)) return;
59106
59428
  scannedRows.add(valueId);
59107
59429
  const row = evalValueById(
@@ -59213,7 +59535,10 @@ function finalizeConstructorAllocations(ctx, returnValue, ownsInvocationState, r
59213
59535
  const scanReturnedValue = (value, typeInfo) => {
59214
59536
  if (typeof value === "object" && value !== null) {
59215
59537
  const direct = groupByValueReference.get(value);
59216
- if (direct !== void 0) escapedRoots.add(direct);
59538
+ if (direct !== void 0) {
59539
+ markConstructorGroupEscaped(direct);
59540
+ return;
59541
+ }
59217
59542
  const tracked = trackedRowForValueReference(value, ctx);
59218
59543
  if (tracked !== null) {
59219
59544
  scanOwnedRow(tracked.id);
@@ -59261,7 +59586,7 @@ function finalizeConstructorAllocations(ctx, returnValue, ownsInvocationState, r
59261
59586
  if (typeof row?.value === "object" && row.value !== null) {
59262
59587
  collectedReferences.add(row.value);
59263
59588
  }
59264
- session.delete(rowId);
59589
+ deleteRuntimeSessionValue(ctx, rowId);
59265
59590
  collectedIds.add(rowId);
59266
59591
  }
59267
59592
  }
@@ -59285,6 +59610,8 @@ function finalizeConstructorAllocations(ctx, returnValue, ownsInvocationState, r
59285
59610
  invalidateEvaluatorIndexes(ctx);
59286
59611
  }
59287
59612
  state.constructorGroups.clear();
59613
+ state.constructorGroupByRowId.clear();
59614
+ state.constructorGroupDependencies.clear();
59288
59615
  }
59289
59616
  function buildValueOverlay(vm) {
59290
59617
  return new LazyValueOverlay(vm);
@@ -60149,9 +60476,11 @@ function applyOverlayStaticAssignment(memberId, value, ctx) {
60149
60476
  "Static assignment requires an evaluator Session row registry."
60150
60477
  );
60151
60478
  }
60479
+ if (ctx.__indexes !== void 0) {
60480
+ indexEvaluatorRows(ctx.__indexes, createdValues);
60481
+ }
60152
60482
  for (const created of createdValues) {
60153
- destination.set(created.id, created);
60154
- if (ctx.__indexes !== void 0) indexEvaluatorRow(ctx.__indexes, created);
60483
+ registerRuntimeSessionValue(ctx, created);
60155
60484
  }
60156
60485
  bindings.set(member.id, row.id);
60157
60486
  invalidateEvaluatorIndexes(ctx);
@@ -61908,6 +62237,7 @@ function dispatchSchemaMember(receiver, schemaKey, ctx) {
61908
62237
  };
61909
62238
  }
61910
62239
  if (!Object.prototype.hasOwnProperty.call(receiver, schemaKey)) {
62240
+ if (!member.required) return { kind: "ok", value: null };
61911
62241
  return { kind: "no-info", matchedMember: true };
61912
62242
  }
61913
62243
  const at = receiver[schemaKey];
@@ -62939,11 +63269,17 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
62939
63269
  }
62940
63270
  const genericSlot = ctx.__constructionGenericSlots?.toReversed().find((slot) => slot.classId === classId) ?? ctx.__storedConstructionReplaySlot;
62941
63271
  const classArguments2 = genericSlot?.classId === classId ? genericSlot.classArguments : void 0;
62942
- const instanceEnv = resolveInstanceEnv(
62943
- classId,
62944
- classArguments2,
62945
- ctx.vm.classes
62946
- );
63272
+ const descriptorCache = evaluatorResolutionCache(ctx).validatedConstructorDescriptorByInfo;
63273
+ const descriptorCacheKey = `${requireEveryRequiredField}:${ctx.storedConstructionReplay === true}:${JSON.stringify(classArguments2 ?? null)}`;
63274
+ const cachedDescriptor = descriptorCache.get(info)?.get(descriptorCacheKey);
63275
+ if (cachedDescriptor !== void 0) return cachedDescriptor;
63276
+ const cacheDescriptor = (descriptor) => {
63277
+ const variants = descriptorCache.get(info) ?? /* @__PURE__ */ new Map();
63278
+ variants.set(descriptorCacheKey, descriptor);
63279
+ descriptorCache.set(info, variants);
63280
+ return descriptor;
63281
+ };
63282
+ const instanceEnv = cachedInstanceEnv(classId, classArguments2, ctx);
62947
63283
  if (firstUnboundParamId(instanceEnv) !== null) {
62948
63284
  throw new NSGetterRuntimeError(
62949
63285
  `Cannot construct open generic Class '${schemaClass2.name}'.`
@@ -62956,11 +63292,7 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
62956
63292
  }
62957
63293
  let mergedSchema;
62958
63294
  try {
62959
- mergedSchema = mergeStoredInstanceSchema(
62960
- classId,
62961
- ctx.vm.classes,
62962
- ctx.vm.members
62963
- );
63295
+ mergedSchema = [...cachedStoredInstanceSchema(classId, ctx)];
62964
63296
  } catch (error) {
62965
63297
  throw new NSGetterRuntimeError(
62966
63298
  `Cannot validate constructor for '${schemaClass2.name}': ${error instanceof Error ? error.message : String(error)}`
@@ -63019,7 +63351,12 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
63019
63351
  );
63020
63352
  }
63021
63353
  if (!requireEveryRequiredField) {
63022
- return { schemaClass: schemaClass2, fields, instanceEnv, classArguments: classArguments2 };
63354
+ return cacheDescriptor({
63355
+ schemaClass: schemaClass2,
63356
+ fields,
63357
+ instanceEnv,
63358
+ classArguments: classArguments2
63359
+ });
63023
63360
  }
63024
63361
  for (const entry of mergedSchema) {
63025
63362
  const rawMember = evalMemberById(ctx.vm, entry.memberId);
@@ -63031,7 +63368,8 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
63031
63368
  const member = substituteMember(
63032
63369
  rawMember,
63033
63370
  instanceEnv,
63034
- ctx.vm.members
63371
+ ctx.vm.members,
63372
+ cachedResolvedMember(rawMember, ctx)
63035
63373
  );
63036
63374
  if (member.isStatic || !memberKindSupportsStorage(member.kind) || member.kind === 21 /* Generic */) {
63037
63375
  continue;
@@ -63042,7 +63380,7 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
63042
63380
  );
63043
63381
  }
63044
63382
  }
63045
- return { schemaClass: schemaClass2, fields, instanceEnv, classArguments: classArguments2 };
63383
+ return cacheDescriptor({ schemaClass: schemaClass2, fields, instanceEnv, classArguments: classArguments2 });
63046
63384
  }
63047
63385
  function assertConstructorFieldSlotWritable(args) {
63048
63386
  const surfaceEntry = mergeInstanceSchema(
@@ -63069,7 +63407,8 @@ function validateConstructorFieldSlot(args) {
63069
63407
  const member = substituteMember(
63070
63408
  rawMember,
63071
63409
  args.instanceEnv,
63072
- ctx.vm.members
63410
+ ctx.vm.members,
63411
+ cachedResolvedMember(rawMember, ctx)
63073
63412
  );
63074
63413
  if (member.isStatic || !memberKindSupportsStorage(member.kind) || member.kind === 21 /* Generic */) {
63075
63414
  throw new NSGetterRuntimeError(
@@ -63111,7 +63450,7 @@ function constructionGenericSlotsForMember(rawMember, ctx, instanceEnv, visitedM
63111
63450
  const entryMember = evalMemberById(ctx.vm, member.entryMemberId);
63112
63451
  if (entryMember === null) return [];
63113
63452
  return constructionGenericSlotsForMember(
63114
- resolveMember2(entryMember, ctx.vm.members),
63453
+ cachedResolvedMember(entryMember, ctx),
63115
63454
  ctx,
63116
63455
  instanceEnv,
63117
63456
  nextVisited
@@ -63129,6 +63468,9 @@ function withConstructionGenericSlots(member, ctx, instanceEnv, evaluate) {
63129
63468
  }
63130
63469
  }
63131
63470
  function evaluateConstructorFields(descriptor, scope, ctx) {
63471
+ if (descriptor.fields.length === 0) {
63472
+ return EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS;
63473
+ }
63132
63474
  const schemaClass2 = descriptor.schemaClass;
63133
63475
  const evaluatedValues = descriptor.fields.map((validated) => {
63134
63476
  if (validated.valuePointer === null) {
@@ -63169,16 +63511,17 @@ function evaluateConstructorFields(descriptor, scope, ctx) {
63169
63511
  });
63170
63512
  }
63171
63513
  function syntheticConstructorMember(schemaClass2, classArguments2) {
63172
- return {
63514
+ const member = {
63173
63515
  name: `new ${schemaClass2.name}`,
63174
63516
  kind: 7 /* Class */,
63175
63517
  classId: schemaClass2.id,
63176
- ...classArguments2 === void 0 ? {} : { classArguments: classArguments2 },
63177
63518
  locked: false,
63178
63519
  required: true,
63179
63520
  isStatic: false,
63180
63521
  accessModifierKind: "public"
63181
63522
  };
63523
+ if (classArguments2 !== void 0) member.classArguments = classArguments2;
63524
+ return member;
63182
63525
  }
63183
63526
  function stampConstructedRootGenericBindings(root, descriptor) {
63184
63527
  const stamp = {};
@@ -63315,37 +63658,19 @@ function stageConstructedRows(createdValues, ctx) {
63315
63658
  );
63316
63659
  }
63317
63660
  for (const row of createdValues) {
63318
- destination.set(row.id, row);
63319
- if (ctx.__indexes !== void 0) indexEvaluatorRow(ctx.__indexes, row);
63661
+ registerRuntimeSessionValue(ctx, row);
63662
+ }
63663
+ if (ctx.__indexes !== void 0) {
63664
+ indexEvaluatorRows(ctx.__indexes, createdValues);
63320
63665
  }
63321
63666
  }
63322
- function bindConstructedDelegateTargets(rootId, ctx) {
63323
- const indexes = evaluatorIndexes(ctx);
63324
- const pending = [rootId];
63325
- const visited = /* @__PURE__ */ new Set();
63326
- while (pending.length > 0) {
63327
- const rowId = pending.pop();
63328
- if (rowId === void 0 || visited.has(rowId)) continue;
63329
- visited.add(rowId);
63330
- const row = evalValueById(
63331
- ctx,
63332
- rowId,
63333
- ctx.__runtimeSessionValues,
63334
- ctx.__valueOverlay
63335
- );
63336
- if (row === null) continue;
63337
- if (Array.isArray(row.value)) {
63338
- for (const childId of row.value) {
63339
- if (typeof childId === "string") pending.push(childId);
63340
- }
63341
- } else if (typeof row.value === "object" && row.value !== null) {
63342
- for (const childId of Object.values(row.value)) {
63343
- if (typeof childId === "string") pending.push(childId);
63344
- }
63345
- }
63667
+ function bindConstructedDelegateTargets(createdValues, ctx) {
63668
+ let indexes;
63669
+ for (const row of createdValues) {
63346
63670
  if (!isMemberDelegateTarget(row.value) || row.value.valueId !== null) {
63347
63671
  continue;
63348
63672
  }
63673
+ indexes ??= evaluatorIndexes(ctx);
63349
63674
  const target = evalMemberById(ctx.vm, row.value.memberId);
63350
63675
  if (target === null || target.isStatic === true) continue;
63351
63676
  const placement = findSchemaPlacement(target.id, ctx.vm.classes);
@@ -63390,8 +63715,10 @@ function bindConstructedDelegateTargets(rootId, ctx) {
63390
63715
  function publishConstructedRows(args) {
63391
63716
  const { root, createdValues, ctx } = args;
63392
63717
  assertConstructorRowsHaveSingleStructuralOwner(createdValues, ctx);
63393
- const beforeRetain = new Set(createdValues.map((row) => row.id));
63394
- retainOnlyCreatedRowsReachableFrom(root.id, createdValues, ctx);
63718
+ const beforeRetain = args.mayHaveOrphanedRows === false ? null : new Set(createdValues.map((row) => row.id));
63719
+ if (beforeRetain !== null) {
63720
+ retainOnlyCreatedRowsReachableFrom(root.id, createdValues, ctx);
63721
+ }
63395
63722
  stampCreatedValuesMapKey(createdValues, null);
63396
63723
  applyDeclaredStorageKeyOverrides({
63397
63724
  createdValues,
@@ -63440,29 +63767,84 @@ function publishConstructedRows(args) {
63440
63767
  "produced collection entry"
63441
63768
  );
63442
63769
  const retained = retainedIds;
63443
- for (const rowId of beforeRetain) {
63444
- if (retained.has(rowId)) continue;
63445
- destination.delete(rowId);
63770
+ if (beforeRetain !== null) {
63771
+ for (const rowId of beforeRetain) {
63772
+ if (retained.has(rowId)) continue;
63773
+ deleteRuntimeSessionValue(ctx, rowId);
63774
+ }
63446
63775
  }
63447
63776
  for (const row of createdValues) {
63448
- destination.set(row.id, row);
63449
- if (ctx.__indexes !== void 0) indexEvaluatorRow(ctx.__indexes, row);
63777
+ registerRuntimeSessionValue(ctx, row);
63778
+ }
63779
+ if (ctx.__indexes !== void 0) {
63780
+ indexEvaluatorRows(ctx.__indexes, createdValues);
63781
+ }
63782
+ bindConstructedDelegateTargets(createdValues, ctx);
63783
+ let rootDependencies = state.constructorGroupDependencies.get(root.id);
63784
+ for (const rowId of retained) {
63785
+ if (rowId === root.id) continue;
63786
+ const nestedDependencies = state.constructorGroupDependencies.get(rowId);
63787
+ if (nestedDependencies === void 0) continue;
63788
+ rootDependencies ??= /* @__PURE__ */ new Set();
63789
+ for (const dependencyRootId of nestedDependencies) {
63790
+ if (dependencyRootId !== root.id) {
63791
+ rootDependencies.add(dependencyRootId);
63792
+ }
63793
+ }
63794
+ state.constructorGroupDependencies.delete(rowId);
63795
+ }
63796
+ if (rootDependencies !== void 0) {
63797
+ state.constructorGroupDependencies.set(root.id, rootDependencies);
63450
63798
  }
63451
- bindConstructedDelegateTargets(root.id, ctx);
63452
63799
  state.constructorGroups.set(root.id, retained);
63800
+ for (const rowId of retained) {
63801
+ state.constructorGroupByRowId.set(rowId, root.id);
63802
+ }
63803
+ if (ctx.__indexes !== void 0) {
63804
+ for (const rowId of retained) {
63805
+ ctx.__indexes.constructorOwnershipDirtyValueIds.delete(rowId);
63806
+ }
63807
+ }
63453
63808
  state.ownedValueAttachments.clear();
63454
63809
  }
63455
63810
  function assertConstructorRowsHaveSingleStructuralOwner(createdValues, ctx) {
63456
- const candidateIds = new Set(createdValues.map((row) => row.id));
63457
- for (const rowIds of ctx.__executionState?.constructorGroups.values() ?? []) {
63458
- for (const rowId of rowIds) candidateIds.add(rowId);
63811
+ let indexes = ctx.__indexes;
63812
+ const candidateIds = /* @__PURE__ */ new Set();
63813
+ if (ctx.__constructorOwnershipStrategy === "cumulative") {
63814
+ indexes ??= evaluatorIndexes(ctx);
63815
+ for (const row of createdValues) candidateIds.add(row.id);
63816
+ for (const rowIds of ctx.__executionState?.constructorGroups.values() ?? []) {
63817
+ for (const rowId of rowIds) candidateIds.add(rowId);
63818
+ }
63819
+ } else if (indexes !== void 0) {
63820
+ const state = ctx.__executionState;
63821
+ for (const rowId of indexes.constructorOwnershipDirtyValueIds) {
63822
+ if (ctx.__constructorPerformanceMetrics !== void 0) {
63823
+ ctx.__constructorPerformanceMetrics.ownershipDirtyRowsVisited += 1;
63824
+ }
63825
+ const rootId = state?.constructorGroupByRowId.get(rowId);
63826
+ if (rootId !== void 0 && state?.constructorGroups.has(rootId)) {
63827
+ candidateIds.add(rowId);
63828
+ } else {
63829
+ indexes.constructorOwnershipDirtyValueIds.delete(rowId);
63830
+ }
63831
+ }
63832
+ }
63833
+ if (candidateIds.size === 0) return;
63834
+ indexes ??= evaluatorIndexes(ctx);
63835
+ if (ctx.__constructorPerformanceMetrics !== void 0) {
63836
+ ctx.__constructorPerformanceMetrics.ownershipCandidateRowsValidated += candidateIds.size;
63459
63837
  }
63460
63838
  for (const valueId of candidateIds) {
63461
63839
  const owners = currentOwnedValueAttachments(valueId, ctx);
63462
- if (owners.length <= 1) continue;
63463
- throw new NSGetterRuntimeError(
63464
- `Constructed value '${valueId}' has multiple structural parents (${owners.map((owner) => owner.label).join(", ")}). Reuse its row in one field or call Clone() explicitly.`
63465
- );
63840
+ if (owners.length > 1) {
63841
+ throw new NSGetterRuntimeError(
63842
+ `Constructed value '${valueId}' has multiple structural parents (${owners.map((owner) => owner.label).join(
63843
+ ", "
63844
+ )}). Reuse its row in one field or call Clone() explicitly.`
63845
+ );
63846
+ }
63847
+ indexes.constructorOwnershipDirtyValueIds.delete(valueId);
63466
63848
  }
63467
63849
  }
63468
63850
  function assertImplicitConstructionAllowed(schemaClass2) {
@@ -63507,6 +63889,20 @@ function constructClassValueWithinFrame(descriptor, scope, ctx) {
63507
63889
  values: ctx.vm.values,
63508
63890
  memberById: ctx.vm.databaseVM?.memberById,
63509
63891
  valueById: ctx.vm.databaseVM?.valueById,
63892
+ resolvedMember: (member) => member === syntheticMember ? syntheticMember : cachedResolvedMember(member, ctx),
63893
+ storedInstanceSchema: (nestedClassId) => cachedStoredInstanceSchema(nestedClassId, ctx),
63894
+ storedInstanceMaterializationPlan: (nestedClassId, instanceEnv) => cachedStoredInstanceMaterializationPlan(
63895
+ nestedClassId,
63896
+ instanceEnv,
63897
+ ctx
63898
+ ),
63899
+ instanceEnv: (nestedClassId, classArguments2) => cachedInstanceEnv(nestedClassId, classArguments2, ctx),
63900
+ isInitValueContent: (value) => cachedIsInitValueContent(value, ctx),
63901
+ createValueRow: (projectId, body) => buildNewValue(
63902
+ projectId,
63903
+ body,
63904
+ ctx.__executionState?.constructionTimestamp
63905
+ ),
63510
63906
  projectFiles: ctx.vm.projectFiles ?? [],
63511
63907
  textureTemplates: ctx.vm.textureTemplates ?? []
63512
63908
  },
@@ -63542,19 +63938,21 @@ function constructClassValueWithinFrame(descriptor, scope, ctx) {
63542
63938
  );
63543
63939
  }
63544
63940
  const rootRecord = root.value;
63545
- applyConstructorFields({
63546
- supplied,
63547
- root,
63548
- rootRecord,
63549
- schemaClass: schemaClass2,
63550
- instanceEnv: descriptor.instanceEnv,
63551
- createdValues,
63552
- createdById: new Map(createdValues.map((row) => [row.id, row])),
63553
- storageKeyDeclarations,
63554
- // Generated C# factories pass null for an omitted optional parameter.
63555
- nullMeansOmit: true,
63556
- ctx
63557
- });
63941
+ if (supplied.length > 0) {
63942
+ applyConstructorFields({
63943
+ supplied,
63944
+ root,
63945
+ rootRecord,
63946
+ schemaClass: schemaClass2,
63947
+ instanceEnv: descriptor.instanceEnv,
63948
+ createdValues,
63949
+ createdById: new Map(createdValues.map((row) => [row.id, row])),
63950
+ storageKeyDeclarations,
63951
+ // Generated C# factories pass null for an omitted optional parameter.
63952
+ nullMeansOmit: true,
63953
+ ctx
63954
+ });
63955
+ }
63558
63956
  } catch (error) {
63559
63957
  if (error instanceof NSGetterRuntimeError) throw error;
63560
63958
  throw new NSGetterRuntimeError(
@@ -63566,6 +63964,7 @@ function constructClassValueWithinFrame(descriptor, scope, ctx) {
63566
63964
  classId,
63567
63965
  createdValues,
63568
63966
  storageKeyDeclarations,
63967
+ mayHaveOrphanedRows: supplied.some((entry) => entry.value !== null),
63569
63968
  ctx
63570
63969
  });
63571
63970
  return root.value;
@@ -64094,9 +64493,12 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
64094
64493
  const closeFrame = pushConstructionFrame(ctx, `${member.name} initializer`);
64095
64494
  let result;
64096
64495
  try {
64496
+ const initializerCtx = ctx.thisValue === null ? ctx : Object.assign({}, ctx, {
64497
+ thisValue: null
64498
+ });
64097
64499
  result = evaluateNSGetterWithEffects(
64098
64500
  compiled,
64099
- { ...ctx, thisValue: null },
64501
+ initializerCtx,
64100
64502
  argumentValues
64101
64503
  );
64102
64504
  } finally {
@@ -64124,9 +64526,8 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
64124
64526
  }
64125
64527
  return { value: result.value, classId: existingRuntimeClassId };
64126
64528
  }
64127
- ctx.__runtimeSessionValues?.delete(rootRow.id);
64529
+ deleteRuntimeSessionValue(ctx, rootRow.id);
64128
64530
  ctx.__executionState?.constructorGroups.delete(rootRow.id);
64129
- invalidateEvaluatorIndexes(ctx);
64130
64531
  const constructorArgs = typeof result.value === "object" && result.value !== null ? ctx.__constructedArgumentsByValue.get(result.value) : void 0;
64131
64532
  return {
64132
64533
  value: result.value,
@@ -64145,10 +64546,9 @@ function encodeLookupInitializerResult(member, value, created, ctx) {
64145
64546
  );
64146
64547
  if (created.length > 0) {
64147
64548
  for (const row of created) {
64148
- ctx.__runtimeSessionValues?.delete(row.id);
64549
+ deleteRuntimeSessionValue(ctx, row.id);
64149
64550
  ctx.__executionState?.constructorGroups.delete(row.id);
64150
64551
  }
64151
- invalidateEvaluatorIndexes(ctx);
64152
64552
  }
64153
64553
  return { value: selection, classId: null };
64154
64554
  }
@@ -64204,10 +64604,25 @@ function initializerRootRow(value, created) {
64204
64604
  return created.find((row) => row.value === value) ?? null;
64205
64605
  }
64206
64606
  function constructorGroupForRow(valueId, ctx) {
64207
- for (const [rootId, rowIds] of ctx.__executionState?.constructorGroups ?? []) {
64208
- if (rowIds.has(valueId)) return rootId;
64209
- }
64210
- return null;
64607
+ const state = ctx.__executionState;
64608
+ if (state === void 0) return null;
64609
+ const rootId = state.constructorGroupByRowId.get(valueId);
64610
+ return rootId !== void 0 && state.constructorGroups.has(rootId) ? rootId : null;
64611
+ }
64612
+ function recordConstructorGroupDependency(valueId, destination, ctx) {
64613
+ if (!destination.identity.startsWith("value:")) return;
64614
+ const state = ctx.__executionState;
64615
+ if (state === void 0) return;
64616
+ const dependencyRootId = constructorGroupForRow(valueId, ctx);
64617
+ if (dependencyRootId === null) return;
64618
+ const ownerRootId = constructorGroupForRow(destination.label, ctx) ?? destination.label;
64619
+ if (ownerRootId === dependencyRootId) return;
64620
+ let dependencies = state.constructorGroupDependencies.get(ownerRootId);
64621
+ if (dependencies === void 0) {
64622
+ dependencies = /* @__PURE__ */ new Set();
64623
+ state.constructorGroupDependencies.set(ownerRootId, dependencies);
64624
+ }
64625
+ dependencies.add(dependencyRootId);
64211
64626
  }
64212
64627
  function encodeRequiredConstructorArgument(args) {
64213
64628
  const trackedId = findKnownRowIdByValueReference(args.value, args.ctx);
@@ -64341,6 +64756,10 @@ function constructDeclaredClassValueWithinFrame(descriptor, record3, info, scope
64341
64756
  );
64342
64757
  const createdValues = [];
64343
64758
  const storageKeyDeclarations = /* @__PURE__ */ new Map();
64759
+ const syntheticMember = syntheticConstructorMember(
64760
+ schemaClass2,
64761
+ descriptor.classArguments
64762
+ );
64344
64763
  let root;
64345
64764
  try {
64346
64765
  root = buildDefaultMemberValue({
@@ -64352,14 +64771,25 @@ function constructDeclaredClassValueWithinFrame(descriptor, record3, info, scope
64352
64771
  values: ctx.vm.values,
64353
64772
  memberById: ctx.vm.databaseVM?.memberById,
64354
64773
  valueById: ctx.vm.databaseVM?.valueById,
64774
+ resolvedMember: (member) => member === syntheticMember ? syntheticMember : cachedResolvedMember(member, ctx),
64775
+ storedInstanceSchema: (nestedClassId) => cachedStoredInstanceSchema(nestedClassId, ctx),
64776
+ storedInstanceMaterializationPlan: (nestedClassId, instanceEnv) => cachedStoredInstanceMaterializationPlan(
64777
+ nestedClassId,
64778
+ instanceEnv,
64779
+ ctx
64780
+ ),
64781
+ instanceEnv: (nestedClassId, classArguments2) => cachedInstanceEnv(nestedClassId, classArguments2, ctx),
64782
+ isInitValueContent: (value) => cachedIsInitValueContent(value, ctx),
64783
+ createValueRow: (projectId, body) => buildNewValue(
64784
+ projectId,
64785
+ body,
64786
+ ctx.__executionState?.constructionTimestamp
64787
+ ),
64355
64788
  projectFiles: ctx.vm.projectFiles ?? [],
64356
64789
  textureTemplates: ctx.vm.textureTemplates ?? []
64357
64790
  },
64358
64791
  projectId: ctx.vm.project.id,
64359
- member: syntheticConstructorMember(
64360
- schemaClass2,
64361
- descriptor.classArguments
64362
- ),
64792
+ member: syntheticMember,
64363
64793
  topLevelClassId: classId,
64364
64794
  createdValues,
64365
64795
  storageKeyDeclarations,
@@ -64426,7 +64856,7 @@ function constructDeclaredClassValueWithinFrame(descriptor, record3, info, scope
64426
64856
  root.constructorArgs = structuredClone(encoded);
64427
64857
  }
64428
64858
  stageConstructedRows(createdValues, ctx);
64429
- bindConstructedDelegateTargets(root.id, ctx);
64859
+ bindConstructedDelegateTargets(createdValues, ctx);
64430
64860
  if (record3 !== null) {
64431
64861
  runDeclaredConstructorChain({
64432
64862
  record: record3,
@@ -64464,20 +64894,22 @@ function constructDeclaredClassValueWithinFrame(descriptor, record3, info, scope
64464
64894
  }
64465
64895
  const supplied = evaluateConstructorFields(descriptor, scope, ctx);
64466
64896
  try {
64467
- applyConstructorFields({
64468
- supplied,
64469
- root,
64470
- rootRecord,
64471
- schemaClass: schemaClass2,
64472
- instanceEnv: descriptor.instanceEnv,
64473
- createdValues,
64474
- createdById: new Map(createdValues.map((row) => [row.id, row])),
64475
- storageKeyDeclarations,
64476
- // §6.1 step 4: these are initializer-block assignments, so an explicit
64477
- // null clears the slot rather than omitting the field.
64478
- nullMeansOmit: false,
64479
- ctx
64480
- });
64897
+ if (supplied.length > 0) {
64898
+ applyConstructorFields({
64899
+ supplied,
64900
+ root,
64901
+ rootRecord,
64902
+ schemaClass: schemaClass2,
64903
+ instanceEnv: descriptor.instanceEnv,
64904
+ createdValues,
64905
+ createdById: new Map(createdValues.map((row) => [row.id, row])),
64906
+ storageKeyDeclarations,
64907
+ // §6.1 step 4: these are initializer-block assignments, so an explicit
64908
+ // null clears the slot rather than omitting the field.
64909
+ nullMeansOmit: false,
64910
+ ctx
64911
+ });
64912
+ }
64481
64913
  } catch (error) {
64482
64914
  if (error instanceof NSGetterRuntimeError) throw error;
64483
64915
  throw new NSGetterRuntimeError(
@@ -64489,6 +64921,7 @@ function constructDeclaredClassValueWithinFrame(descriptor, record3, info, scope
64489
64921
  classId,
64490
64922
  createdValues,
64491
64923
  storageKeyDeclarations,
64924
+ mayHaveOrphanedRows: record3 !== null || supplied.length > 0,
64492
64925
  ctx
64493
64926
  });
64494
64927
  return root.value;
@@ -64522,6 +64955,7 @@ function assertOwnedValueAttachable(valueId, destination, destinationName2, ctx,
64522
64955
  );
64523
64956
  if (constructorArgumentReservation && (destination.label === reserved.label || destinationConstructorGroup === reserved.label)) {
64524
64957
  ctx.__executionState?.ownedValueAttachments.set(valueId, destination);
64958
+ recordConstructorGroupDependency(valueId, destination, ctx);
64525
64959
  return;
64526
64960
  }
64527
64961
  throw new NSGetterRuntimeError(
@@ -64531,11 +64965,15 @@ function assertOwnedValueAttachable(valueId, destination, destinationName2, ctx,
64531
64965
  if (reserveUntilPublished) {
64532
64966
  ctx.__executionState?.ownedValueAttachments.set(valueId, destination);
64533
64967
  }
64968
+ recordConstructorGroupDependency(valueId, destination, ctx);
64534
64969
  }
64535
64970
  function currentOwnedValueAttachments(valueId, ctx) {
64536
64971
  const indexes = evaluatorIndexes(ctx);
64537
64972
  const cached = indexes.ownedValueAttachmentsByValueId.get(valueId);
64538
64973
  if (cached !== void 0) return [...cached];
64974
+ if (ctx.__constructorPerformanceMetrics !== void 0) {
64975
+ ctx.__constructorPerformanceMetrics.ownershipAttachmentCacheMisses += 1;
64976
+ }
64539
64977
  const found = /* @__PURE__ */ new Map();
64540
64978
  const add = (attachment) => {
64541
64979
  found.set(attachment.identity, attachment);
@@ -65155,11 +65593,11 @@ function cloneClassValueGraph(receiver, expectedClassId, ctx) {
65155
65593
  `Class.Clone source value '${sourceId3}' has runtime Class '${runtimeClassId}', which is not assignable to '${expectedClassId}'.`
65156
65594
  );
65157
65595
  }
65158
- const destination = ctx.__runtimeSessionValues ?? (() => {
65596
+ if (ctx.__runtimeSessionValues === void 0) {
65159
65597
  throw new NSGetterRuntimeError(
65160
65598
  "Class.Clone requires an evaluator Session value registry."
65161
65599
  );
65162
- })();
65600
+ }
65163
65601
  const active = /* @__PURE__ */ new Set();
65164
65602
  const clonedBySourceId = /* @__PURE__ */ new Map();
65165
65603
  const constructorArgumentReferenceCounts = /* @__PURE__ */ new Map();
@@ -65189,7 +65627,7 @@ function cloneClassValueGraph(receiver, expectedClassId, ctx) {
65189
65627
  // parent explicitly supplies its fresh id.
65190
65628
  containerId: clonedContainerId ?? null
65191
65629
  };
65192
- destination.set(id2, clone);
65630
+ registerRuntimeSessionValue(ctx, clone);
65193
65631
  clonedBySourceId.set(sourceRow.id, clone);
65194
65632
  if (typeof sourceRow.value === "object" && sourceRow.value !== null && !Array.isArray(sourceRow.value)) {
65195
65633
  const sourceRecord = sourceRow.value;
@@ -65458,7 +65896,7 @@ function iterateCollection(c, ctx, callback) {
65458
65896
  return callback(entry, key, valueId);
65459
65897
  });
65460
65898
  }
65461
- var DELEGATE_LEXICAL_THIS, DELEGATE_LEXICAL_ROOT, NonCatchableNSGetterRuntimeError, NativeFunctionDelegateUnavailableError, CorruptNeoScriptIRError, NeoScriptResourceLimitError, NeoScriptWallClockTimeoutError, DEFAULT_NEO_SCRIPT_EXECUTION_BUDGET_LIMITS, liveListIndexesByProject, evaluatorOwnershipCachesByBase, MAX_CONSTRUCTION_DEPTH, MAX_LOOP_ITERATIONS, resolutionCacheByMembers, NO_SCHEMA_REVISION, LazyValueOverlay, READONLY_FOREACH_BINDING_ERROR, READONLY_CATCH_BINDING_ERROR;
65899
+ var DELEGATE_LEXICAL_THIS, DELEGATE_LEXICAL_ROOT, NonCatchableNSGetterRuntimeError, NativeFunctionDelegateUnavailableError, CorruptNeoScriptIRError, NeoScriptResourceLimitError, NeoScriptWallClockTimeoutError, DEFAULT_NEO_SCRIPT_EXECUTION_BUDGET_LIMITS, liveListIndexesByProject, evaluatorOwnershipCachesByBase, MAX_CONSTRUCTION_DEPTH, MAX_LOOP_ITERATIONS, resolutionCacheByMembers, NO_SCHEMA_REVISION, LazyValueOverlay, READONLY_FOREACH_BINDING_ERROR, READONLY_CATCH_BINDING_ERROR, EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS;
65462
65900
  var init_evaluateNSGetter = __esm({
65463
65901
  "../src/view-models/neoscript-evaluator/evaluateNSGetter.ts"() {
65464
65902
  "use strict";
@@ -65602,6 +66040,7 @@ var init_evaluateNSGetter = __esm({
65602
66040
  };
65603
66041
  READONLY_FOREACH_BINDING_ERROR = "Cannot assign to a read-only foreach iterator binding.";
65604
66042
  READONLY_CATCH_BINDING_ERROR = "Cannot assign to a read-only catch message binding.";
66043
+ EMPTY_SUPPLIED_CONSTRUCTOR_FIELDS = [];
65605
66044
  }
65606
66045
  });
65607
66046
 
@@ -83278,6 +83717,15 @@ function applyProjectVersionWriteChanges(document, changes) {
83278
83717
  "constructor"
83279
83718
  ),
83280
83719
  values: applyArrayChanges(document.values ?? [], changes, "value"),
83720
+ // Project-file staging finalizes pending uploads before schema
83721
+ // preparation. Defaults and authored instance graphs may reference a file
83722
+ // created by the same source transaction, so every construction pass must
83723
+ // see that finalized row in its post-write document.
83724
+ projectFiles: applyArrayChanges(
83725
+ document.projectFiles ?? [],
83726
+ changes,
83727
+ "project-file"
83728
+ ),
83281
83729
  internalRecordRelations: applyArrayChanges(
83282
83730
  document.internalRecordRelations ?? [],
83283
83731
  changes,
@@ -87427,10 +87875,28 @@ function emitMemberDefaultSourcesV4(records2, manifest) {
87427
87875
  continue;
87428
87876
  }
87429
87877
  const member = record3.data;
87878
+ const manifestMember = context.manifestMembers.get(record3.recordId);
87879
+ const defaultValue = isObjectRecord2(member.defaultValue) ? member.defaultValue : {};
87880
+ const linkedLocalizedTextId = defaultValue.value;
87881
+ if (manifestMember?.kind === "string" && manifestMember.localizable && typeof linkedLocalizedTextId === "string" && context.localizedTexts.has(linkedLocalizedTextId)) {
87882
+ const localizedText = context.localizedTexts.get(linkedLocalizedTextId);
87883
+ const localeValues = isObjectRecord2(localizedText?.localeValues) ? localizedText.localeValues : {};
87884
+ const mainLocale = localeValues[context.mainLocale];
87885
+ const mainLocaleValue = isObjectRecord2(mainLocale) ? mainLocale.value : void 0;
87886
+ initializers.set(
87887
+ record3.recordId,
87888
+ mainLocaleValue === null ? quote5(linkedLocalizedTextId) : quote5(localizedString(context, member, linkedLocalizedTextId))
87889
+ );
87890
+ recordKeysByMember.set(
87891
+ record3.recordId,
87892
+ /* @__PURE__ */ new Set([`localized-text:${linkedLocalizedTextId}`])
87893
+ );
87894
+ context.localizedTextIds.clear();
87895
+ continue;
87896
+ }
87430
87897
  const backed = rowBackedDefaultBody(member, (id2) => context.values.has(id2));
87431
87898
  if (backed === null) continue;
87432
87899
  const visited = /* @__PURE__ */ new Set();
87433
- const defaultValue = isObjectRecord2(member.defaultValue) ? member.defaultValue : {};
87434
87900
  const environment = declaringClassGenericEnvironment(context, member);
87435
87901
  let expression;
87436
87902
  if (backed.kind === "class") {
@@ -87787,6 +88253,39 @@ function lowerMemberDefaultSourcesV4(state, analysis, manifest, options = {}) {
87787
88253
  bindingRuntimeIdentifiers(context, binding)
87788
88254
  );
87789
88255
  const baseData3 = stateData(context, "member", memberId);
88256
+ const annotatedExpression = annotatedValue(expression).expression;
88257
+ const storedDefault = isObjectRecord2(baseData3?.defaultValue) ? baseData3.defaultValue : null;
88258
+ const storedLocalizedTextId = storedDefault?.value;
88259
+ const storedDefaultClassId = storedDefault?.classId;
88260
+ const storedLocalizedText = typeof storedLocalizedTextId === "string" ? state[`localized-text:${storedLocalizedTextId}`]?.data : void 0;
88261
+ const authoredLocalizedValue = annotatedExpression.kind === "litString" ? annotatedExpression.value : annotatedExpression.kind === "litNull" ? null : void 0;
88262
+ if (member.kind === "string" && member.localizable && authoredLocalizedValue !== void 0 && typeof storedLocalizedTextId === "string" && isObjectRecord2(storedLocalizedText)) {
88263
+ if (annotatedExpression.kind === "litString" && annotatedExpression.value === storedLocalizedTextId) {
88264
+ addReconstructed(
88265
+ context,
88266
+ "localized-text",
88267
+ storedLocalizedTextId,
88268
+ nonVolatileFields(storedLocalizedText),
88269
+ binding.source
88270
+ );
88271
+ memberDefaultValues.set(memberId, {
88272
+ value: storedLocalizedTextId,
88273
+ classId: typeof storedDefaultClassId === "string" ? storedDefaultClassId : null
88274
+ });
88275
+ continue;
88276
+ }
88277
+ const preservedTextId = lowerLinkedLocalizedText(
88278
+ context,
88279
+ storedLocalizedTextId,
88280
+ authoredLocalizedValue,
88281
+ binding
88282
+ );
88283
+ memberDefaultValues.set(memberId, {
88284
+ value: preservedTextId,
88285
+ classId: typeof storedDefaultClassId === "string" ? storedDefaultClassId : null
88286
+ });
88287
+ continue;
88288
+ }
87790
88289
  const backed = baseData3 === null || requiresEvaluation ? null : rowBackedDefaultBody(baseData3, (id2) => pulledValueIds.has(id2));
87791
88290
  if (backed !== null && baseData3 !== null) {
87792
88291
  const existingReconstructedKeys = new Set(context.reconstructed.keys());
@@ -90290,6 +90789,18 @@ function lowerStringValue(context, member, expression, base, source) {
90290
90789
  if (!isObjectRecord2(textState?.data)) {
90291
90790
  return expression.value;
90292
90791
  }
90792
+ return lowerLinkedLocalizedText(
90793
+ context,
90794
+ base.value,
90795
+ expression.value,
90796
+ source
90797
+ );
90798
+ }
90799
+ function lowerLinkedLocalizedText(context, textId, value, source) {
90800
+ const textState = context.state[`localized-text:${textId}`];
90801
+ if (!isObjectRecord2(textState?.data)) {
90802
+ throw new Error(`Localized text ${textId} was not pulled.`);
90803
+ }
90293
90804
  const textBase = textState.data;
90294
90805
  const localeValues = isObjectRecord2(textBase.localeValues) ? textBase.localeValues : {};
90295
90806
  const currentValue = localeValues[context.mainLocale];
@@ -90297,17 +90808,17 @@ function lowerStringValue(context, member, expression, base, source) {
90297
90808
  addReconstructed(
90298
90809
  context,
90299
90810
  "localized-text",
90300
- base.value,
90811
+ textId,
90301
90812
  {
90302
90813
  ...nonVolatileFields(textBase),
90303
90814
  localeValues: {
90304
90815
  ...localeValues,
90305
- [context.mainLocale]: { ...current, value: expression.value }
90816
+ [context.mainLocale]: { ...current, value }
90306
90817
  }
90307
90818
  },
90308
90819
  source.source
90309
90820
  );
90310
- return base.value;
90821
+ return textId;
90311
90822
  }
90312
90823
  function lowerEnum2(context, member, expression) {
90313
90824
  const elements = member.multiselect ? expression.kind === "litList" ? expression.elements : null : [expression];
@@ -93979,16 +94490,28 @@ var init_workspace_status = __esm({
93979
94490
  // src/project-source/status-output.ts
93980
94491
  function groupProjectStatusChangesV4(status) {
93981
94492
  const groups = /* @__PURE__ */ new Map();
94493
+ const group = (source) => {
94494
+ const existing = groups.get(source);
94495
+ if (existing !== void 0) return existing;
94496
+ const created = { changes: [], authoredValueSeeds: [] };
94497
+ groups.set(source, created);
94498
+ return created;
94499
+ };
93982
94500
  for (const change of status.changes) {
93983
94501
  const reconstructed3 = status.reconstructed.get(
93984
94502
  recordStateKey(change.recordKind, change.recordId)
93985
94503
  );
93986
94504
  const source = reconstructed3?.sourceSpan?.path ?? change.file ?? "<unplaced>";
93987
- const entries = groups.get(source) ?? [];
93988
- entries.push(change);
93989
- groups.set(source, entries);
94505
+ group(source).changes.push(change);
93990
94506
  }
93991
- return [...groups].sort(([left], [right]) => compareCodePoints(left, right)).map(([source, changes]) => ({ source, changes }));
94507
+ for (const [memberId, seed] of status.authoredValueSeeds) {
94508
+ const reconstructed3 = status.reconstructed.get(
94509
+ recordStateKey("member", memberId)
94510
+ );
94511
+ const source = reconstructed3?.sourceSpan?.path ?? "<unplaced>";
94512
+ group(source).authoredValueSeeds.push({ memberId, seed });
94513
+ }
94514
+ return [...groups].sort(([left], [right]) => compareCodePoints(left, right)).map(([source, entries]) => ({ source, ...entries }));
93992
94515
  }
93993
94516
  function projectStatusJsonV4(status, options) {
93994
94517
  return {
@@ -94030,7 +94553,18 @@ function projectStatusJsonV4(status, options) {
94030
94553
  mimeType: binary.mimeType
94031
94554
  } : null,
94032
94555
  conflictArtifactPath: binary.conflictArtifactPath ?? null
94033
- }))
94556
+ })),
94557
+ authoredValueSeeds: [...status.authoredValueSeeds].sort(([left], [right]) => compareCodePoints(left, right)).map(([memberId, seed]) => {
94558
+ const reconstructed3 = status.reconstructed.get(
94559
+ recordStateKey("member", memberId)
94560
+ );
94561
+ return {
94562
+ operation: "create",
94563
+ memberId,
94564
+ valueId: seed.valueId ?? null,
94565
+ sourceSpan: reconstructed3?.sourceSpan ?? null
94566
+ };
94567
+ })
94034
94568
  };
94035
94569
  }
94036
94570
  function recordChangeJsonV4(change, status, options) {
@@ -101055,7 +101589,11 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
101055
101589
  );
101056
101590
  preparedChanges = assertServerPreparationSucceeds({
101057
101591
  workspace,
101058
- changes: transportChanges,
101592
+ changes: completeLocallyStagedProjectFileChanges({
101593
+ projectId: workspace.config.projectId,
101594
+ changes: transportChanges,
101595
+ stagedRecordIds: new Set(preparedFiles.map((file) => file.recordId))
101596
+ }),
101059
101597
  authoredValueSeeds: transportSeeds,
101060
101598
  sourceByRecord: status.reconstructed,
101061
101599
  localInitializerMaterialization: pendingAssignment.localInitializerMaterialization,
@@ -101178,6 +101716,33 @@ async function prepareLocalCandidateV4(workspace, options = {}) {
101178
101716
  preparedLocal
101179
101717
  };
101180
101718
  }
101719
+ function completeLocallyStagedProjectFileChanges(args) {
101720
+ return args.changes.map((change) => {
101721
+ if (!args.stagedRecordIds.has(change.recordId)) return change;
101722
+ if (change.recordKind !== "project-file") {
101723
+ throw new Error(
101724
+ `Staged project file ${change.recordId} matched a ${change.recordKind} change.`
101725
+ );
101726
+ }
101727
+ if (!isObjectRecord2(change.nextData)) {
101728
+ throw new Error(
101729
+ `Staged project file ${change.recordId} has no local source record.`
101730
+ );
101731
+ }
101732
+ const completed = {
101733
+ ...change,
101734
+ nextData: {
101735
+ ...change.nextData,
101736
+ id: change.recordId,
101737
+ projectId: args.projectId,
101738
+ status: "uploaded",
101739
+ storageKey: `local-candidate/${change.recordId}`,
101740
+ storageETag: "local-candidate"
101741
+ }
101742
+ };
101743
+ return completed;
101744
+ });
101745
+ }
101181
101746
  function transportChangesForStatus(status) {
101182
101747
  return status.changes.map((change) => ({
101183
101748
  recordKind: change.recordKind,
@@ -102632,7 +103197,7 @@ var init_registry2 = __esm({
102632
103197
  PROJECT_SCHEMA_CONTRACT = Object.freeze({
102633
103198
  formatVersion: 3,
102634
103199
  contractVersion: "3.9",
102635
- cliVersion: "0.26.3",
103200
+ cliVersion: "0.26.5",
102636
103201
  projectFileUploadBatchSize: 32,
102637
103202
  documentRecords: {
102638
103203
  member: {
@@ -109197,7 +109762,7 @@ There is no --keep-current: preserving current semantic state defines flatten.
109197
109762
  async function main() {
109198
109763
  const args = parseArgs(process.argv.slice(2));
109199
109764
  if (args.command === "--version") {
109200
- console.log("0.26.3");
109765
+ console.log("0.26.5");
109201
109766
  return;
109202
109767
  }
109203
109768
  if (args.command === null || args.command === "help" || args.command === "--help" || args.command === "-h") {
@@ -109612,17 +110177,17 @@ async function main() {
109612
110177
  ` ${paintChangeKind(change.kind)} ${describeChange(change).replace(`${change.kind} `, "")}`
109613
110178
  );
109614
110179
  }
110180
+ if (group.authoredValueSeeds.length > 0) {
110181
+ console.log(
110182
+ ` ${paintChangeKind("create")} ${group.authoredValueSeeds.length} member value seed(s)`
110183
+ );
110184
+ }
109615
110185
  }
109616
110186
  for (const binary of status.binaryChanges ?? []) {
109617
110187
  console.log(
109618
110188
  `${paintChangeKind(binary.action === "create" ? "create" : "update")} project-file bytes ${binary.symbol} (${binary.path}) \u2014 ${binary.action}`
109619
110189
  );
109620
110190
  }
109621
- if (status.authoredValueSeeds.size > 0) {
109622
- console.log(
109623
- ` ${paintChangeKind("create")} ${status.authoredValueSeeds.size} member value seed(s)`
109624
- );
109625
- }
109626
110191
  if (status.conflictedFiles.length === 0 && status.parseErrors.length === 0 && status.changes.length === 0 && status.authoredValueSeeds.size === 0 && (status.binaryChanges?.length ?? 0) === 0) {
109627
110192
  console.log(`${sym.ok} Working copy is clean.`);
109628
110193
  }
@@ -109654,13 +110219,18 @@ async function main() {
109654
110219
  console.log(color.dim(` ${line}`));
109655
110220
  }
109656
110221
  }
110222
+ if (group.authoredValueSeeds.length > 0) {
110223
+ console.log(
110224
+ ` ${paintChangeKind("create")} ${group.authoredValueSeeds.length} member value seed(s)`
110225
+ );
110226
+ }
109657
110227
  }
109658
110228
  for (const binary of status.binaryChanges ?? []) {
109659
110229
  console.log(
109660
110230
  `${paintChangeKind(binary.action === "create" ? "create" : "update")} project-file bytes ${binary.symbol} (${binary.path}) \u2014 ${binary.action}`
109661
110231
  );
109662
110232
  }
109663
- if (status.changes.length === 0 && (status.binaryChanges?.length ?? 0) === 0) {
110233
+ if (status.changes.length === 0 && status.authoredValueSeeds.size === 0 && (status.binaryChanges?.length ?? 0) === 0) {
109664
110234
  console.log(`${sym.ok} No local changes.`);
109665
110235
  }
109666
110236
  return;