@neocompose/cli 0.75.2 → 0.76.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5295,6 +5295,9 @@ var ProjectSchemaIndex = class {
5295
5295
  for (const schemaClass2 of source.classes) {
5296
5296
  this.classesById.set(schemaClass2.id, schemaClass2);
5297
5297
  append(this.classesByName, schemaClass2.name, schemaClass2);
5298
+ if (schemaClass2.extendsClassId) {
5299
+ append(this.subclassesById, schemaClass2.extendsClassId, schemaClass2);
5300
+ }
5298
5301
  for (const [schemaKey, memberId] of Object.entries(schemaClass2.schema)) {
5299
5302
  append(this.schemaPlacementsByMemberId, memberId, {
5300
5303
  ownerClass: schemaClass2,
@@ -5339,6 +5342,8 @@ var ProjectSchemaIndex = class {
5339
5342
  source;
5340
5343
  classesById = /* @__PURE__ */ new Map();
5341
5344
  classesByName = /* @__PURE__ */ new Map();
5345
+ /** Direct subclasses by the class they extend. */
5346
+ subclassesById = /* @__PURE__ */ new Map();
5342
5347
  membersById = /* @__PURE__ */ new Map();
5343
5348
  membersByName = /* @__PURE__ */ new Map();
5344
5349
  enumsById = /* @__PURE__ */ new Map();
@@ -5523,6 +5528,9 @@ function indexSchema(classes, members) {
5523
5528
  function classIndexFor(classes) {
5524
5529
  return indexClasses(classes).classesById;
5525
5530
  }
5531
+ function subclassIndexFor(classes) {
5532
+ return indexClasses(classes).subclassesById;
5533
+ }
5526
5534
  function memberIndexFor(members) {
5527
5535
  return projectSchemaIndexFor({ classes: NO_CLASSES, members }).membersById;
5528
5536
  }
@@ -5601,11 +5609,8 @@ function resolvedClassSchemaFromIndexes(classId, classIndex, memberIndex) {
5601
5609
  if (cached !== void 0) return cached;
5602
5610
  const chain = resolveChainFromIndex(classId, classIndex);
5603
5611
  const surface = [];
5604
- const stored = [];
5605
- const readOnly = [];
5606
5612
  const statics = [];
5607
5613
  const surfaceByKey = /* @__PURE__ */ new Map();
5608
- const storedByKey = /* @__PURE__ */ new Map();
5609
5614
  for (const entry of mergeSchemas(chain)) {
5610
5615
  const member = memberIndex.get(entry.memberId);
5611
5616
  if (member !== void 0 && isStaticMember(member)) {
@@ -5614,20 +5619,8 @@ function resolvedClassSchemaFromIndexes(classId, classIndex, memberIndex) {
5614
5619
  }
5615
5620
  surface.push(entry);
5616
5621
  surfaceByKey.set(entry.schemaKey, entry);
5617
- if (member !== void 0 && isReadOnlyMember(member)) readOnly.push(entry);
5618
- else {
5619
- stored.push(entry);
5620
- storedByKey.set(entry.schemaKey, entry);
5621
- }
5622
5622
  }
5623
- const node = {
5624
- surface,
5625
- stored,
5626
- readOnly,
5627
- statics,
5628
- surfaceByKey,
5629
- storedByKey
5630
- };
5623
+ const node = { surface, statics, surfaceByKey };
5631
5624
  byClass.set(classId, node);
5632
5625
  return node;
5633
5626
  }
@@ -5647,9 +5640,6 @@ function mergeInstanceSurfaceSchemaFromIndexes(classId, classIndex, memberIndex)
5647
5640
  ...resolvedClassSchemaFromIndexes(classId, classIndex, memberIndex).surface
5648
5641
  ];
5649
5642
  }
5650
- function mergeStoredInstanceSchema(classId, classes, members) {
5651
- return [...resolvedClassSchema(classId, classes, members).stored];
5652
- }
5653
5643
  function findSchemaPlacement(memberId, classes) {
5654
5644
  return indexClasses(classes).firstSchemaPlacement(memberId);
5655
5645
  }
@@ -5742,15 +5732,7 @@ function resolveMemberWithIndex(member, memberIndex) {
5742
5732
  return Object.freeze(merged);
5743
5733
  }
5744
5734
  function descendantClassIds(classId, allClasses) {
5745
- const childrenByClassId = /* @__PURE__ */ new Map();
5746
- for (const schemaClass2 of allClasses) {
5747
- if (!schemaClass2.extendsClassId) continue;
5748
- const children = childrenByClassId.get(schemaClass2.extendsClassId);
5749
- if (children === void 0) {
5750
- childrenByClassId.set(schemaClass2.extendsClassId, [schemaClass2]);
5751
- } else children.push(schemaClass2);
5752
- }
5753
- return descendantClassIdsInChildIndex(classId, childrenByClassId);
5735
+ return descendantClassIdsInChildIndex(classId, subclassIndexFor(allClasses));
5754
5736
  }
5755
5737
  function descendantClassIdsInChildIndex(classId, childrenByClassId) {
5756
5738
  const result = /* @__PURE__ */ new Set();
@@ -5766,6 +5748,46 @@ function descendantClassIdsInChildIndex(classId, childrenByClassId) {
5766
5748
  return result;
5767
5749
  }
5768
5750
 
5751
+ // ../packages/models/src/members/instance-provenance.ts
5752
+ var LITERAL_INSTANCE_IDENTITY_FIELDS = [
5753
+ "classId",
5754
+ "constructorArgs",
5755
+ "instanceConstructorId",
5756
+ "instanceVariantId",
5757
+ "instanceVariantRowValueId",
5758
+ "genericBindings"
5759
+ ];
5760
+ function replaceLiteralValueClass(value, classId) {
5761
+ const next = { ...value, classId };
5762
+ for (const field of LITERAL_INSTANCE_IDENTITY_FIELDS) {
5763
+ if (field !== "classId") Reflect.deleteProperty(next, field);
5764
+ }
5765
+ return next;
5766
+ }
5767
+ function overlayLiteralValueContent(base, override) {
5768
+ const merged = { ...base, ...override };
5769
+ if (!("value" in override) || override.value !== null) return merged;
5770
+ for (const field of LITERAL_INSTANCE_IDENTITY_FIELDS) {
5771
+ if (!Object.hasOwn(override, field)) Reflect.deleteProperty(merged, field);
5772
+ }
5773
+ return merged;
5774
+ }
5775
+ function pickInstanceProvenance(source) {
5776
+ return {
5777
+ ...source.constructorArgs === void 0 ? {} : { constructorArgs: source.constructorArgs },
5778
+ ...source.instanceConstructorId === void 0 ? {} : { instanceConstructorId: source.instanceConstructorId },
5779
+ ...source.instanceVariantId === void 0 ? {} : { instanceVariantId: source.instanceVariantId },
5780
+ ...source.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: source.instanceVariantRowValueId }
5781
+ };
5782
+ }
5783
+ function isVirtualInstanceRootShape(value) {
5784
+ if (value.instanceConstructorId !== void 0) return true;
5785
+ return typeof value.instanceVariantId === "string";
5786
+ }
5787
+ function isCollapseStampedInstanceRoot(value) {
5788
+ return isLiteralValueContent(value) && isVirtualInstanceRootShape(value);
5789
+ }
5790
+
5769
5791
  // ../packages/models/src/system-record-id.ts
5770
5792
  var SYSTEM_RECORD_ID_PREFIX = "system_";
5771
5793
  function isSystemRecordId(id) {
@@ -5806,46 +5828,638 @@ function inSystemRecordNamespaceOf(ownerId, derivedId) {
5806
5828
  return systemRecordId(derivedId);
5807
5829
  }
5808
5830
 
5809
- // ../packages/models/src/classes/world-system-classes.generated.ts
5810
- var WORLD_SPRITE_MASK_INTERACTION_ENUM_ID = "system_4e6c4d6f-1d0b-402a-ad3a-be92242dceec";
5811
- var WORLD_SPRITE_MASK_INTERACTION_NONE_OPTION_ID = "system_9d607a4f-60c3-4347-94fc-f24b538bf468";
5812
- var WORLD_SPRITE_MASK_INTERACTION_VISIBLE_INSIDE_OPTION_ID = "system_4c670ac9-78a4-44e9-9833-94e1c69dca97";
5813
- var WORLD_SPRITE_MASK_INTERACTION_VISIBLE_OUTSIDE_OPTION_ID = "system_a0aeb200-7216-49e2-aad2-e151ff35c336";
5814
- var WORLD_ANIMATION_CHILD_OVERRIDE_ENTRY_PARAM_ID = "system_de23448a-45be-4e3f-8965-072a545e08f0";
5815
- var WORLD_ANIMATION_FRAME_OVERRIDES_MEMBER_ID = "system_8ab7bb00-a475-43f0-8579-1b08f133d658";
5816
- var WORLD_ANIMATION_FRAME_CHILD_OVERRIDES_MEMBER_ID = "system_a5905750-c472-46a8-89e9-f04f0bf66696";
5817
- var WORLD_ANIMATION_FRAME_CHILD_OVERRIDES_ENTRY_MEMBER_ID = "system_86688965-6b26-529e-95f3-a4070f022582";
5818
- var WORLD_ANIMATION_CHILD_OVERRIDE_OVERRIDES_MEMBER_ID = "system_819b3743-0c3d-4896-b679-9aeeb73255f4";
5819
- var WORLD_PLAY_DIRECTION_ENUM_ID = "system_705ccc39-e46e-4c9f-af3e-3ec8fd818709";
5820
- var WORLD_PLAY_DIRECTION_FORWARD_OPTION_ID = "system_2e4ca40e-f305-49c6-a91b-b99d56239ba0";
5821
- var WORLD_PLAY_DIRECTION_REVERSE_OPTION_ID = "system_6478d195-3905-48db-befe-d276eb5478f0";
5822
- var WORLD_SYSTEM_CLASS_DEFINITIONS = [
5823
- {
5824
- classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7",
5825
- name: "NeoCellPattern",
5826
- docsText: "An immutable ordered pattern of cell offsets, relative to an origin.\nHand-built patterns preserve order and duplicates; factories order cells nearest first.",
5827
- modifier: 2 /* Sealed */,
5828
- constructorIds: ["system_f68684d6-6ea0-5d57-9f96-d544b17bf369"],
5829
- constructors: [
5830
- {
5831
- constructorId: "system_f68684d6-6ea0-5d57-9f96-d544b17bf369",
5832
- argumentTypes: [
5833
- {
5834
- name: "offsets",
5835
- type: 6,
5836
- required: true,
5837
- entryTypeInfo: { type: 15, required: true }
5838
- }
5839
- ],
5840
- code: "this._offsets = offsets.Select((offset) => { return Vector2Int(offset.x, offset.y); });"
5831
+ // ../packages/models/src/members/member-value-id.ts
5832
+ var NEO_MEMBER_VALUE_NAMESPACE = "7f2b9c14-58d6-5a07-b3e1-4c9d0a6f8b25";
5833
+ var NEO_VIRTUAL_VALUE_NAMESPACE = "3e8ca0b3-e3f1-5d5f-bf2f-6ab5ee3896d0";
5834
+ var virtualNamespaceBytes = parse_default(NEO_VIRTUAL_VALUE_NAMESPACE);
5835
+ var virtualIdentityEncoder = new TextEncoder();
5836
+ var SURROGATE_CODE_UNIT = /[\ud800-\udfff]/;
5837
+ function derivedMemberValueId(memberId) {
5838
+ return inSystemRecordNamespaceOf(
5839
+ memberId,
5840
+ v5_default(withoutSystemRecordIdPrefix(memberId), NEO_MEMBER_VALUE_NAMESPACE)
5841
+ );
5842
+ }
5843
+ function virtualValueId(instanceRootId, sourceIdentity2) {
5844
+ const identity = `${withoutSystemRecordIdPrefix(instanceRootId)}:${sourceIdentity2}`;
5845
+ const bytes = SURROGATE_CODE_UNIT.test(identity) ? identity : virtualIdentityEncoder.encode(identity);
5846
+ return inSystemRecordNamespaceOf(
5847
+ instanceRootId,
5848
+ v5_default(bytes, virtualNamespaceBytes)
5849
+ );
5850
+ }
5851
+ function virtualSourceIdentityHead(sourceIdentity2) {
5852
+ const pathStart = sourceIdentity2.indexOf(":$");
5853
+ return pathStart < 0 ? sourceIdentity2 : sourceIdentity2.slice(0, pathStart);
5854
+ }
5855
+ function hasPendingVirtualSourceIdentity(sourceIdentity2) {
5856
+ const head = virtualSourceIdentityHead(sourceIdentity2);
5857
+ return head.startsWith("path:__pending__:") || head.startsWith("__pending__:");
5858
+ }
5859
+ var PENDING_VIRTUAL_VALUE_PREFIX = "__pending__:virtual-value:";
5860
+ function pendingVirtualValueId(pendingInstanceRootId, sourceIdentity2) {
5861
+ return `${PENDING_VIRTUAL_VALUE_PREFIX}${encodeURIComponent(pendingInstanceRootId)}:${encodeURIComponent(sourceIdentity2)}`;
5862
+ }
5863
+
5864
+ // ../packages/models/src/members/packed-value-encoding.ts
5865
+ var PACKED_VALUE_ENTRY_KEY = "~packed";
5866
+ var PackedValueEncodingError = class extends Error {
5867
+ constructor(message) {
5868
+ super(message);
5869
+ this.name = "PackedValueEncodingError";
5870
+ }
5871
+ };
5872
+ var NO_CHILDREN = [];
5873
+ var NO_EDGES = /* @__PURE__ */ new Map();
5874
+ function isPackedValueEnvelope(value) {
5875
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
5876
+ return false;
5877
+ }
5878
+ return Object.hasOwn(value, PACKED_VALUE_ENTRY_KEY);
5879
+ }
5880
+ function rowCarriesPackedValueContent(content) {
5881
+ if (containerHoldsPackedEntry(content.value)) return true;
5882
+ return containerHoldsPackedEntry(content.constructorArgs);
5883
+ }
5884
+ function expandPackedValueRows(rows) {
5885
+ let firstPacked = -1;
5886
+ for (let index = 0; index < rows.length; index += 1) {
5887
+ const row = rows[index];
5888
+ if (row === void 0 || !rowCarriesPackedValueContent(row)) continue;
5889
+ firstPacked = index;
5890
+ break;
5891
+ }
5892
+ if (firstPacked < 0) return rows;
5893
+ const expanded = rows.slice(0, firstPacked);
5894
+ for (let index = firstPacked; index < rows.length; index += 1) {
5895
+ const row = rows[index];
5896
+ if (row === void 0) continue;
5897
+ const decoded = decodePackedValueRow(row);
5898
+ expanded.push(decoded.row, ...decoded.children);
5899
+ }
5900
+ return expanded;
5901
+ }
5902
+ function expandPackedDocumentValues(document2) {
5903
+ const stored = document2.values;
5904
+ const expanded = expandPackedValueRows(stored);
5905
+ if (expanded === stored) return document2;
5906
+ return { ...document2, values: expanded };
5907
+ }
5908
+ function decodePackedValueRow(row) {
5909
+ if (!rowCarriesPackedValueContent(row)) {
5910
+ return { row, children: NO_CHILDREN, packedChildIdsByParentId: NO_EDGES };
5911
+ }
5912
+ const state = {
5913
+ edges: /* @__PURE__ */ new Map(),
5914
+ seenIds: /* @__PURE__ */ new Set([row.id]),
5915
+ projectId: row.projectId,
5916
+ mapKey: row.mapKey
5917
+ };
5918
+ const children = [];
5919
+ const scope = {
5920
+ state,
5921
+ ownerId: row.id,
5922
+ ownerLabel: `value "${row.id}"`,
5923
+ constructionRootId: isCollapseStampedInstanceRoot(row) ? row.id : null
5924
+ };
5925
+ const value = decodeContentField(row.value, "value", scope, children);
5926
+ const constructorArgs = decodeContentField(
5927
+ isLiteralValueContent(row) ? row.constructorArgs : void 0,
5928
+ "constructorArgs",
5929
+ scope,
5930
+ children
5931
+ );
5932
+ return {
5933
+ row: withDecodedContent(row, value, constructorArgs),
5934
+ children,
5935
+ packedChildIdsByParentId: state.edges
5936
+ };
5937
+ }
5938
+ function canonicalPackedChildId(args) {
5939
+ if (args.constructionRootId === null) return null;
5940
+ if (typeof args.sourceValueId !== "string") return null;
5941
+ if (args.sourceValueId.length === 0) return null;
5942
+ return virtualValueId(args.constructionRootId, args.sourceValueId);
5943
+ }
5944
+ function decodeContentField(container, field, scope, children) {
5945
+ if (!containerHoldsPackedEntry(container)) return null;
5946
+ if (Array.isArray(container)) {
5947
+ return {
5948
+ content: container.map(
5949
+ (entry, index) => isPackedValueEnvelope(entry) ? decodeEnvelope(entry, `${field}[${index}]`, scope, children) : entry
5950
+ )
5951
+ };
5952
+ }
5953
+ const decoded = {};
5954
+ for (const [key, entry] of Object.entries(
5955
+ container
5956
+ )) {
5957
+ decoded[key] = isPackedValueEnvelope(entry) ? decodeEnvelope(
5958
+ entry,
5959
+ `${field}[${JSON.stringify(key)}]`,
5960
+ scope,
5961
+ children
5962
+ ) : entry;
5963
+ }
5964
+ return { content: decoded };
5965
+ }
5966
+ function decodeEnvelope(envelope, position, scope, children) {
5967
+ const label = `Packed value entry at ${scope.ownerLabel}.${position}`;
5968
+ const entry = envelope[PACKED_VALUE_ENTRY_KEY];
5969
+ assertDecodableEntry(entry, label);
5970
+ const id = packedEntryLogicalId(entry, label, scope.constructionRootId);
5971
+ if (scope.state.seenIds.has(id)) {
5972
+ throw new PackedValueEncodingError(
5973
+ `${label} resolves to id "${id}", which another row in the same packed payload already claims.`
5974
+ );
5975
+ }
5976
+ scope.state.seenIds.add(id);
5977
+ registerEdge(scope.state.edges, scope.ownerId, id);
5978
+ const childScope = {
5979
+ state: scope.state,
5980
+ ownerId: id,
5981
+ ownerLabel: `packed value "${id}"`,
5982
+ constructionRootId: isCollapseStampedInstanceRoot(entry) ? id : scope.constructionRootId
5983
+ };
5984
+ const nested = [];
5985
+ children.push(logicalChildRow(entry, id, childScope, nested));
5986
+ children.push(...nested);
5987
+ return id;
5988
+ }
5989
+ function logicalChildRow(entry, id, scope, children) {
5990
+ const rowFields = {
5991
+ id,
5992
+ projectId: scope.state.projectId,
5993
+ createdAt: entry.createdAt,
5994
+ updatedAt: entry.updatedAt,
5995
+ ...scope.state.mapKey === void 0 ? {} : { mapKey: scope.state.mapKey },
5996
+ ...entry.genericBindings === void 0 ? {} : { genericBindings: entry.genericBindings },
5997
+ ...entry.sourceValueId === void 0 ? {} : { sourceValueId: entry.sourceValueId }
5998
+ };
5999
+ if (isInitValueContent(entry)) return { ...rowFields, init: entry.init };
6000
+ const value = decodeContentField(entry.value, "value", scope, children);
6001
+ const constructorArgs = decodeContentField(
6002
+ entry.constructorArgs,
6003
+ "constructorArgs",
6004
+ scope,
6005
+ children
6006
+ );
6007
+ return {
6008
+ ...rowFields,
6009
+ ...literalContent(entry, value, constructorArgs)
6010
+ };
6011
+ }
6012
+ function packedEntryLogicalId(entry, label, constructionRootId) {
6013
+ const canonical = canonicalPackedChildId({
6014
+ constructionRootId,
6015
+ sourceValueId: entry.sourceValueId
6016
+ });
6017
+ const stored = entry.id;
6018
+ if (stored === void 0) {
6019
+ if (canonical === null) {
6020
+ throw new PackedValueEncodingError(
6021
+ `${label} stores no "id" and its position derives none: only a deterministic child of an enclosing construction root, stamped with a "sourceValueId", may omit its logical id.`
6022
+ );
6023
+ }
6024
+ return canonical;
6025
+ }
6026
+ if (typeof stored !== "string" || stored.length === 0) {
6027
+ throw new PackedValueEncodingError(
6028
+ `${label} stores an "id" that is not a non-empty string.`
6029
+ );
6030
+ }
6031
+ if (stored === canonical) {
6032
+ throw new PackedValueEncodingError(
6033
+ `${label} stores id "${stored}", which its position already derives; a derivable id must be omitted rather than repeated.`
6034
+ );
6035
+ }
6036
+ return stored;
6037
+ }
6038
+ var PACKED_ENTRY_FORBIDDEN_FIELDS = [
6039
+ "projectId",
6040
+ "containerId",
6041
+ "mapKey"
6042
+ ];
6043
+ function assertDecodableEntry(entry, label) {
6044
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
6045
+ throw new PackedValueEncodingError(`${label} is not an object.`);
6046
+ }
6047
+ for (const field of PACKED_ENTRY_FORBIDDEN_FIELDS) {
6048
+ if (!Object.hasOwn(entry, field)) continue;
6049
+ throw new PackedValueEncodingError(
6050
+ `${label} stores "${field}", which decoding derives from its owning row.`
6051
+ );
6052
+ }
6053
+ if (!("createdAt" in entry) || typeof entry.createdAt !== "number") {
6054
+ throw new PackedValueEncodingError(
6055
+ `${label} stores no numeric "createdAt".`
6056
+ );
6057
+ }
6058
+ if (!("updatedAt" in entry) || typeof entry.updatedAt !== "number") {
6059
+ throw new PackedValueEncodingError(
6060
+ `${label} stores no numeric "updatedAt".`
6061
+ );
6062
+ }
6063
+ const hasValue = Object.hasOwn(entry, "value");
6064
+ const hasInit = Object.hasOwn(entry, "init");
6065
+ if (hasValue && hasInit) {
6066
+ throw new PackedValueEncodingError(
6067
+ `${label} stores both "value" and "init"; a value container holds exactly one.`
6068
+ );
6069
+ }
6070
+ if (!hasValue && !hasInit) {
6071
+ throw new PackedValueEncodingError(
6072
+ `${label} stores neither "value" nor "init"; a value container holds exactly one.`
6073
+ );
6074
+ }
6075
+ if (hasInit && !isInitValueContent(entry)) {
6076
+ throw new PackedValueEncodingError(
6077
+ `${label} stores an "init" that is not a valid initializer body.`
6078
+ );
6079
+ }
6080
+ if (hasValue && !isLiteralValueContent(entry)) {
6081
+ throw new PackedValueEncodingError(
6082
+ `${label} stores a "value" whose class or construction stamp is malformed.`
6083
+ );
6084
+ }
6085
+ }
6086
+ function literalContent(content, value, constructorArgs) {
6087
+ if (!isLiteralValueContent(content)) {
6088
+ throw new PackedValueEncodingError(
6089
+ `Value container has no literal "value" to encode.`
6090
+ );
6091
+ }
6092
+ const provenance = pickInstanceProvenance(content);
6093
+ return {
6094
+ value: value === null ? content.value : value.content,
6095
+ ...Object.hasOwn(content, "classId") ? { classId: content.classId } : {},
6096
+ ...provenance,
6097
+ ...constructorArgs === null ? {} : { constructorArgs: asConstructorArgs(constructorArgs.content) }
6098
+ };
6099
+ }
6100
+ function withDecodedContent(row, value, constructorArgs) {
6101
+ if (value === null && constructorArgs === null) return row;
6102
+ return { ...row, ...literalContent(row, value, constructorArgs) };
6103
+ }
6104
+ function asConstructorArgs(content) {
6105
+ if (content === null) return null;
6106
+ if (typeof content !== "object" || Array.isArray(content)) {
6107
+ throw new PackedValueEncodingError(
6108
+ `Value container stores "constructorArgs" that is not a record.`
6109
+ );
6110
+ }
6111
+ return content;
6112
+ }
6113
+ function containerHoldsPackedEntry(container) {
6114
+ if (Array.isArray(container)) {
6115
+ return container.some((entry) => isPackedValueEnvelope(entry));
6116
+ }
6117
+ if (typeof container !== "object" || container === null) return false;
6118
+ for (const entry of Object.values(container)) {
6119
+ if (isPackedValueEnvelope(entry)) return true;
6120
+ }
6121
+ return false;
6122
+ }
6123
+ function registerEdge(edges, ownerId, childId) {
6124
+ const existing = edges.get(ownerId);
6125
+ if (existing === void 0) edges.set(ownerId, [childId]);
6126
+ else existing.push(childId);
6127
+ }
6128
+
6129
+ // ../packages/models/src/members/unordered-list-membership.ts
6130
+ function buildUnorderedListMembershipIndex(values) {
6131
+ const membersByContainerId = /* @__PURE__ */ new Map();
6132
+ for (const candidate of values) {
6133
+ const containerId = candidate.containerId;
6134
+ if (typeof containerId !== "string") continue;
6135
+ const bucket = membersByContainerId.get(containerId);
6136
+ if (bucket === void 0) {
6137
+ membersByContainerId.set(containerId, [candidate.id]);
6138
+ } else {
6139
+ bucket.push(candidate.id);
6140
+ }
6141
+ }
6142
+ for (const bucket of membersByContainerId.values()) {
6143
+ bucket.sort();
6144
+ }
6145
+ return membersByContainerId;
6146
+ }
6147
+
6148
+ // ../packages/models/src/members/member-storage-key.ts
6149
+ var MAIN_STORAGE_PARTITION = "main";
6150
+ var STORAGE_KEY_INHERIT = "inherit";
6151
+ var STORAGE_KEY_ALL = "all";
6152
+ var PARENT_CLASS_TEMPLATE_TOKEN = "$parentClass";
6153
+ function normalizeStorageKeyDeclaration(declaration) {
6154
+ if (declaration === void 0 || declaration === null) {
6155
+ return STORAGE_KEY_INHERIT;
6156
+ }
6157
+ if (declaration.length === 0) return STORAGE_KEY_INHERIT;
6158
+ if (declaration === STORAGE_KEY_ALL) {
6159
+ throw new Error(
6160
+ 'Storage key "all" is reserved for partition-scoped reads and cannot be declared on a member.'
6161
+ );
6162
+ }
6163
+ return declaration;
6164
+ }
6165
+ function storageKeyReferencesParentClass(declaration) {
6166
+ return declaration.includes(PARENT_CLASS_TEMPLATE_TOKEN);
6167
+ }
6168
+ function resolveMapKeyForCreatedValue(args) {
6169
+ const declaration = normalizeStorageKeyDeclaration(args.declaration);
6170
+ if (declaration === STORAGE_KEY_INHERIT) return args.parentMapKey;
6171
+ if (declaration === MAIN_STORAGE_PARTITION) return null;
6172
+ if (storageKeyReferencesParentClass(declaration)) {
6173
+ if (args.parentClassId === void 0) {
6174
+ throw new Error(
6175
+ `Storage key "${declaration}" references ${PARENT_CLASS_TEMPLATE_TOKEN}, but the placement parent value has no classId (only class-valued parents can anchor a ${PARENT_CLASS_TEMPLATE_TOKEN} partition).`
6176
+ );
6177
+ }
6178
+ return declaration.replaceAll(
6179
+ PARENT_CLASS_TEMPLATE_TOKEN,
6180
+ args.parentClassId
6181
+ );
6182
+ }
6183
+ return declaration;
6184
+ }
6185
+
6186
+ // ../packages/models/src/members/storage-partitions.ts
6187
+ function stampCreatedValuesMapKey(values, mapKey) {
6188
+ const normalized = mapKey === void 0 || mapKey === null || mapKey.length === 0 || mapKey === MAIN_STORAGE_PARTITION ? null : mapKey;
6189
+ for (const value of values) {
6190
+ if (normalized === null) {
6191
+ delete value.mapKey;
6192
+ } else {
6193
+ value.mapKey = normalized;
6194
+ }
6195
+ }
6196
+ }
6197
+ function applyDeclaredStorageKeyOverrides(args) {
6198
+ const boundaryValues = args.createdValues.filter(
6199
+ (value) => normalizeStorageKeyDeclaration(
6200
+ args.declarationByValueId.get(value.id)
6201
+ ) !== STORAGE_KEY_INHERIT
6202
+ );
6203
+ if (boundaryValues.length === 0) return;
6204
+ const createdById = new Map(
6205
+ args.createdValues.map((value) => [value.id, value])
6206
+ );
6207
+ const parentOf = /* @__PURE__ */ new Map();
6208
+ for (const value of args.createdValues) {
6209
+ for (const childId of referencedValueIdCandidates(value.value)) {
6210
+ if (createdById.has(childId)) parentOf.set(childId, value);
6211
+ }
6212
+ }
6213
+ for (const value of args.createdValues) {
6214
+ if (typeof value.containerId !== "string") continue;
6215
+ const container = createdById.get(value.containerId);
6216
+ if (container !== void 0) parentOf.set(value.id, container);
6217
+ }
6218
+ const depthOf = (value) => {
6219
+ let depth = 0;
6220
+ let current = value;
6221
+ const seen = /* @__PURE__ */ new Set();
6222
+ while (current !== void 0 && !seen.has(current.id)) {
6223
+ seen.add(current.id);
6224
+ current = parentOf.get(current.id);
6225
+ if (current !== void 0) depth += 1;
6226
+ }
6227
+ return depth;
6228
+ };
6229
+ const boundaries = boundaryValues.sort((left, right) => depthOf(left) - depthOf(right));
6230
+ for (const boundary of boundaries) {
6231
+ const parentCreated = parentOf.get(boundary.id);
6232
+ const parent = parentCreated !== void 0 ? {
6233
+ mapKey: parentCreated.mapKey ?? null,
6234
+ classId: parentCreated.classId ?? void 0
6235
+ } : args.existingParentContextById?.get(boundary.id);
6236
+ if (parent === void 0) {
6237
+ throw new Error(
6238
+ `Cannot resolve storage partition for created value "${boundary.id}": its placement parent is neither a created value nor supplied in existingParentContextById.`
6239
+ );
6240
+ }
6241
+ const mapKey = resolveMapKeyForCreatedValue({
6242
+ declaration: args.declarationByValueId.get(boundary.id),
6243
+ parentMapKey: parent.mapKey,
6244
+ parentClassId: parent.classId
6245
+ });
6246
+ for (const member of collectCreatedSubtreeValues(
6247
+ boundary,
6248
+ args.createdValues
6249
+ )) {
6250
+ if (mapKey === null || mapKey === MAIN_STORAGE_PARTITION) {
6251
+ delete member.mapKey;
6252
+ } else {
6253
+ member.mapKey = mapKey;
5841
6254
  }
5842
- ],
5843
- schemaFields: [
5844
- {
5845
- memberId: "system_02a01003-41ff-531c-a63c-1e905ca88d7d",
5846
- memberKind: "list",
5847
- access: 2 /* Private */,
5848
- modifier: 1 /* Sealed */,
6255
+ }
6256
+ }
6257
+ }
6258
+ function collectCreatedSubtreeValues(root, createdValues) {
6259
+ const createdById = new Map(createdValues.map((value) => [value.id, value]));
6260
+ const subtree = [];
6261
+ const visited = /* @__PURE__ */ new Set();
6262
+ const queue = [root];
6263
+ while (queue.length > 0) {
6264
+ const current = queue.shift();
6265
+ if (current === void 0) break;
6266
+ if (visited.has(current.id)) continue;
6267
+ visited.add(current.id);
6268
+ subtree.push(current);
6269
+ for (const childId of referencedValueIdCandidates(current.value)) {
6270
+ const child = createdById.get(childId);
6271
+ if (child !== void 0) queue.push(child);
6272
+ }
6273
+ for (const candidate of createdValues) {
6274
+ if (candidate.containerId === current.id) queue.push(candidate);
6275
+ }
6276
+ }
6277
+ return subtree;
6278
+ }
6279
+ function referencedValueIdCandidates(value) {
6280
+ if (Array.isArray(value)) {
6281
+ return value.filter((entry) => typeof entry === "string");
6282
+ }
6283
+ if (typeof value === "object" && value !== null) {
6284
+ return Object.values(value).filter(
6285
+ (entry) => typeof entry === "string"
6286
+ );
6287
+ }
6288
+ return [];
6289
+ }
6290
+
6291
+ // ../packages/models/src/core/auth-ownership-types.ts
6292
+ var ActorKind = {
6293
+ /**
6294
+ * `better-auth` user identities.
6295
+ */
6296
+ user: "user",
6297
+ /**
6298
+ * `better-auth` organization identities.
6299
+ */
6300
+ organization: "organization",
6301
+ /**
6302
+ * Used for denoting records created by a system.
6303
+ */
6304
+ system: "system"
6305
+ };
6306
+ function isActorIdentifier(value) {
6307
+ if (typeof value !== "object") return false;
6308
+ if (value === null) return false;
6309
+ const candidate = value;
6310
+ if (!isActorKind(candidate.kind)) return false;
6311
+ return typeof candidate.id === "string" && candidate.id.trim().length > 0;
6312
+ }
6313
+ function isActorKind(value) {
6314
+ return value === ActorKind.user || value === ActorKind.organization || value === ActorKind.system;
6315
+ }
6316
+
6317
+ // ../packages/models/src/members/member-change-listeners.ts
6318
+ function editChangeListenerSet(explicit, inherited, edit, options = { inheritedComplete: true }) {
6319
+ if (edit.kind === "reset") {
6320
+ return explicit === void 0 ? { changed: false } : { changed: true, targets: void 0 };
6321
+ }
6322
+ const current = explicit ?? inherited;
6323
+ let next;
6324
+ if (edit.kind === "replace") {
6325
+ next = edit.targets;
6326
+ } else {
6327
+ const identity = nsActionListenerIdentity(edit.target);
6328
+ const index = current.findIndex(
6329
+ (target) => nsActionListenerIdentity(target) === identity
6330
+ );
6331
+ if (edit.kind === "add") {
6332
+ if (index !== -1) return { changed: false };
6333
+ next = [...current, edit.target];
6334
+ } else {
6335
+ if (index === -1) return { changed: false };
6336
+ next = current.filter((_, i) => i !== index);
6337
+ }
6338
+ }
6339
+ const targets = [];
6340
+ const seen = /* @__PURE__ */ new Set();
6341
+ for (const target of next) {
6342
+ const identity = nsActionListenerIdentity(target);
6343
+ if (seen.has(identity))
6344
+ throw new Error("A listener set cannot repeat a handler identity.");
6345
+ seen.add(identity);
6346
+ targets.push({ memberId: target.memberId, valueId: target.valueId });
6347
+ }
6348
+ if (targets.length === 0 && inherited.length === 0 && options.inheritedComplete) {
6349
+ return explicit === void 0 ? { changed: false } : { changed: true, targets: void 0 };
6350
+ }
6351
+ if (explicit !== void 0 && sameChangeListeners(explicit, targets))
6352
+ return { changed: false };
6353
+ return { changed: true, targets };
6354
+ }
6355
+ function sameChangeListeners(left, right) {
6356
+ return left.length === right.length && left.every(
6357
+ (entry, index) => entry.memberId === right[index].memberId && entry.valueId === right[index].valueId
6358
+ );
6359
+ }
6360
+ function remapChangeListenerMap(map, identities, policy, internalEndpoints) {
6361
+ if (!map) return void 0;
6362
+ const result = {};
6363
+ for (const [ownerId, members] of Object.entries(map)) {
6364
+ const owner = identities.get(ownerId);
6365
+ if (owner === void 0) continue;
6366
+ const entry = {};
6367
+ for (const [memberId, targets] of Object.entries(members)) {
6368
+ const remapped = [];
6369
+ for (const target of targets) {
6370
+ const receiver = target.valueId === null ? null : identities.get(target.valueId);
6371
+ if (receiver === void 0 && (policy === "clone" || target.valueId !== null && internalEndpoints !== void 0 && internalEndpoints.has(target.valueId)))
6372
+ continue;
6373
+ remapped.push({
6374
+ memberId: target.memberId,
6375
+ valueId: receiver ?? target.valueId
6376
+ });
6377
+ }
6378
+ setOwnField(entry, memberId, remapped);
6379
+ }
6380
+ setOwnField(result, owner, entry);
6381
+ }
6382
+ return Object.keys(result).length === 0 ? void 0 : result;
6383
+ }
6384
+ var authoredListenerIndexes = /* @__PURE__ */ new WeakMap();
6385
+ function authoredChangeListenerOwners(rows) {
6386
+ const index = authoredListenerIndexes.get(rows);
6387
+ if (index !== void 0) return index;
6388
+ const owners = /* @__PURE__ */ new Map();
6389
+ for (const row of rows)
6390
+ for (const [ownerId, entry] of Object.entries(row.changeListeners ?? {})) {
6391
+ if (owners.has(ownerId))
6392
+ throw new Error(
6393
+ `Listener owner "${ownerId}" is declared on more than one binding root.`
6394
+ );
6395
+ owners.set(ownerId, entry);
6396
+ }
6397
+ authoredListenerIndexes.set(rows, owners);
6398
+ return owners;
6399
+ }
6400
+ var declarationListenerMetadata = /* @__PURE__ */ new WeakMap();
6401
+ function hasAuthoredChangeListenerMetadata(document2) {
6402
+ if (authoredChangeListenerOwners(document2.values).size !== 0) return true;
6403
+ let present = declarationListenerMetadata.get(document2.members);
6404
+ if (present === void 0) {
6405
+ present = document2.members.some(
6406
+ (member) => member.defaultValue?.changeListeners !== void 0
6407
+ );
6408
+ declarationListenerMetadata.set(document2.members, present);
6409
+ }
6410
+ return present;
6411
+ }
6412
+ function defaultSourceWithListeners(row, graph) {
6413
+ if (row === null || graph == null || graph.instanceRootId !== row.id)
6414
+ return row;
6415
+ const inherited = graph.listenerDefaultsByOwner;
6416
+ if (inherited === void 0 || inherited.size === 0) return row;
6417
+ const map = Object.fromEntries(inherited);
6418
+ for (const [id, entry] of Object.entries(row.changeListeners ?? {}))
6419
+ setOwnField(map, id, { ...map[id], ...entry });
6420
+ return { ...row, changeListeners: map };
6421
+ }
6422
+
6423
+ // ../packages/models/src/classes/world-system-classes.generated.ts
6424
+ var WORLD_SPRITE_MASK_INTERACTION_ENUM_ID = "system_4e6c4d6f-1d0b-402a-ad3a-be92242dceec";
6425
+ var WORLD_SPRITE_MASK_INTERACTION_NONE_OPTION_ID = "system_9d607a4f-60c3-4347-94fc-f24b538bf468";
6426
+ var WORLD_SPRITE_MASK_INTERACTION_VISIBLE_INSIDE_OPTION_ID = "system_4c670ac9-78a4-44e9-9833-94e1c69dca97";
6427
+ var WORLD_SPRITE_MASK_INTERACTION_VISIBLE_OUTSIDE_OPTION_ID = "system_a0aeb200-7216-49e2-aad2-e151ff35c336";
6428
+ var WORLD_ANIMATION_CHILD_OVERRIDE_ENTRY_PARAM_ID = "system_de23448a-45be-4e3f-8965-072a545e08f0";
6429
+ var WORLD_ANIMATION_FRAME_OVERRIDES_MEMBER_ID = "system_8ab7bb00-a475-43f0-8579-1b08f133d658";
6430
+ var WORLD_ANIMATION_FRAME_CHILD_OVERRIDES_MEMBER_ID = "system_a5905750-c472-46a8-89e9-f04f0bf66696";
6431
+ var WORLD_ANIMATION_FRAME_CHILD_OVERRIDES_ENTRY_MEMBER_ID = "system_86688965-6b26-529e-95f3-a4070f022582";
6432
+ var WORLD_ANIMATION_CHILD_OVERRIDE_OVERRIDES_MEMBER_ID = "system_819b3743-0c3d-4896-b679-9aeeb73255f4";
6433
+ var WORLD_PLAY_DIRECTION_ENUM_ID = "system_705ccc39-e46e-4c9f-af3e-3ec8fd818709";
6434
+ var WORLD_PLAY_DIRECTION_FORWARD_OPTION_ID = "system_2e4ca40e-f305-49c6-a91b-b99d56239ba0";
6435
+ var WORLD_PLAY_DIRECTION_REVERSE_OPTION_ID = "system_6478d195-3905-48db-befe-d276eb5478f0";
6436
+ var WORLD_SYSTEM_CLASS_DEFINITIONS = [
6437
+ {
6438
+ classId: "system_fb9c4080-0148-530e-b9c0-8cd1c17ff8e7",
6439
+ name: "NeoCellPattern",
6440
+ docsText: "An immutable ordered pattern of cell offsets, relative to an origin.\nHand-built patterns preserve order and duplicates; factories order cells nearest first.",
6441
+ modifier: 2 /* Sealed */,
6442
+ constructorIds: ["system_f68684d6-6ea0-5d57-9f96-d544b17bf369"],
6443
+ constructors: [
6444
+ {
6445
+ constructorId: "system_f68684d6-6ea0-5d57-9f96-d544b17bf369",
6446
+ argumentTypes: [
6447
+ {
6448
+ name: "offsets",
6449
+ type: 6,
6450
+ required: true,
6451
+ entryTypeInfo: { type: 15, required: true }
6452
+ }
6453
+ ],
6454
+ code: "this._offsets = offsets.Select((offset) => { return Vector2Int(offset.x, offset.y); });"
6455
+ }
6456
+ ],
6457
+ schemaFields: [
6458
+ {
6459
+ memberId: "system_02a01003-41ff-531c-a63c-1e905ca88d7d",
6460
+ memberKind: "list",
6461
+ access: 2 /* Private */,
6462
+ modifier: 1 /* Sealed */,
5849
6463
  defaultValue: [],
5850
6464
  entryMemberId: "system_1efcbead-df5b-5d09-b0ca-758039c06fca",
5851
6465
  requirement: 1 /* Required */,
@@ -7805,6 +8419,43 @@ function clonePlain(value, path, visiting) {
7805
8419
  }
7806
8420
  }
7807
8421
 
8422
+ // ../packages/models/src/classes/world-system-classes.ts
8423
+ var WORLD_SYSTEM_CLASS_DEFINITION_BY_KIND = new Map(
8424
+ WORLD_SYSTEM_CLASS_DEFINITIONS.map((definition) => [
8425
+ definition.worldKind,
8426
+ definition
8427
+ ])
8428
+ );
8429
+ function worldSystemSchemaFieldsForKind(worldKind) {
8430
+ return WORLD_SYSTEM_CLASS_DEFINITION_BY_KIND.get(worldKind)?.schemaFields ?? [];
8431
+ }
8432
+ var WORLD_SYSTEM_ANIMATION_KIND_MARKER = "animation";
8433
+ var WORLD_SYSTEM_ANIMATION_KINDS = new Set(
8434
+ WORLD_SYSTEM_CLASS_DEFINITIONS.map(
8435
+ (definition) => definition.worldKind
8436
+ ).filter(
8437
+ (worldKind) => worldKind.toLowerCase().includes(WORLD_SYSTEM_ANIMATION_KIND_MARKER)
8438
+ )
8439
+ );
8440
+ var GENERIC_WORLD_SYSTEM_CLASS_KINDS = new Set(
8441
+ WORLD_SYSTEM_CLASS_DEFINITIONS.filter(
8442
+ (definition) => (definition.genericParams?.length ?? 0) > 0
8443
+ ).map((definition) => definition.worldKind)
8444
+ );
8445
+ var WORLD_SYSTEM_ALL_KINDS = new Set(
8446
+ WORLD_SYSTEM_CLASS_DEFINITIONS.map((definition) => definition.worldKind)
8447
+ );
8448
+ var WORLD_SYSTEM_SCHEMA_FIELD_SITES_BY_MEMBER_ID = new Map(
8449
+ WORLD_SYSTEM_CLASS_DEFINITIONS.flatMap(
8450
+ (definition) => (definition.schemaFields ?? []).map(
8451
+ (field) => [
8452
+ field.memberId,
8453
+ { worldKind: definition.worldKind, schemaKey: field.schemaKey }
8454
+ ]
8455
+ )
8456
+ )
8457
+ );
8458
+
7808
8459
  // ../packages/models/src/classes/generics.ts
7809
8460
  var genericBindingsByClassIndex = /* @__PURE__ */ new WeakMap();
7810
8461
  function resolveGenericEnv(classId, classes, draft) {
@@ -8503,638 +9154,6 @@ function isAnimationChildOverrideEntrySlot(slotMember, members) {
8503
9154
  return false;
8504
9155
  }
8505
9156
 
8506
- // ../packages/models/src/members/instance-provenance.ts
8507
- var LITERAL_INSTANCE_IDENTITY_FIELDS = [
8508
- "classId",
8509
- "constructorArgs",
8510
- "instanceConstructorId",
8511
- "instanceVariantId",
8512
- "instanceVariantRowValueId",
8513
- "genericBindings"
8514
- ];
8515
- function replaceLiteralValueClass(value, classId) {
8516
- const next = { ...value, classId };
8517
- for (const field of LITERAL_INSTANCE_IDENTITY_FIELDS) {
8518
- if (field !== "classId") Reflect.deleteProperty(next, field);
8519
- }
8520
- return next;
8521
- }
8522
- function overlayLiteralValueContent(base, override) {
8523
- const merged = { ...base, ...override };
8524
- if (!("value" in override) || override.value !== null) return merged;
8525
- for (const field of LITERAL_INSTANCE_IDENTITY_FIELDS) {
8526
- if (!Object.hasOwn(override, field)) Reflect.deleteProperty(merged, field);
8527
- }
8528
- return merged;
8529
- }
8530
- function pickInstanceProvenance(source) {
8531
- return {
8532
- ...source.constructorArgs === void 0 ? {} : { constructorArgs: source.constructorArgs },
8533
- ...source.instanceConstructorId === void 0 ? {} : { instanceConstructorId: source.instanceConstructorId },
8534
- ...source.instanceVariantId === void 0 ? {} : { instanceVariantId: source.instanceVariantId },
8535
- ...source.instanceVariantRowValueId === void 0 ? {} : { instanceVariantRowValueId: source.instanceVariantRowValueId }
8536
- };
8537
- }
8538
- function isVirtualInstanceRootShape(value) {
8539
- if (value.instanceConstructorId !== void 0) return true;
8540
- return typeof value.instanceVariantId === "string";
8541
- }
8542
- function isCollapseStampedInstanceRoot(value) {
8543
- return isLiteralValueContent(value) && isVirtualInstanceRootShape(value);
8544
- }
8545
-
8546
- // ../packages/models/src/members/unordered-list-membership.ts
8547
- function buildUnorderedListMembershipIndex(values) {
8548
- const membersByContainerId = /* @__PURE__ */ new Map();
8549
- for (const candidate of values) {
8550
- const containerId = candidate.containerId;
8551
- if (typeof containerId !== "string") continue;
8552
- const bucket = membersByContainerId.get(containerId);
8553
- if (bucket === void 0) {
8554
- membersByContainerId.set(containerId, [candidate.id]);
8555
- } else {
8556
- bucket.push(candidate.id);
8557
- }
8558
- }
8559
- for (const bucket of membersByContainerId.values()) {
8560
- bucket.sort();
8561
- }
8562
- return membersByContainerId;
8563
- }
8564
-
8565
- // ../packages/models/src/members/member-value-id.ts
8566
- var NEO_MEMBER_VALUE_NAMESPACE = "7f2b9c14-58d6-5a07-b3e1-4c9d0a6f8b25";
8567
- var NEO_VIRTUAL_VALUE_NAMESPACE = "3e8ca0b3-e3f1-5d5f-bf2f-6ab5ee3896d0";
8568
- var virtualNamespaceBytes = parse_default(NEO_VIRTUAL_VALUE_NAMESPACE);
8569
- var virtualIdentityEncoder = new TextEncoder();
8570
- var SURROGATE_CODE_UNIT = /[\ud800-\udfff]/;
8571
- function derivedMemberValueId(memberId) {
8572
- return inSystemRecordNamespaceOf(
8573
- memberId,
8574
- v5_default(withoutSystemRecordIdPrefix(memberId), NEO_MEMBER_VALUE_NAMESPACE)
8575
- );
8576
- }
8577
- function virtualValueId(instanceRootId, sourceIdentity2) {
8578
- const identity = `${withoutSystemRecordIdPrefix(instanceRootId)}:${sourceIdentity2}`;
8579
- const bytes = SURROGATE_CODE_UNIT.test(identity) ? identity : virtualIdentityEncoder.encode(identity);
8580
- return inSystemRecordNamespaceOf(
8581
- instanceRootId,
8582
- v5_default(bytes, virtualNamespaceBytes)
8583
- );
8584
- }
8585
- function virtualSourceIdentityHead(sourceIdentity2) {
8586
- const pathStart = sourceIdentity2.indexOf(":$");
8587
- return pathStart < 0 ? sourceIdentity2 : sourceIdentity2.slice(0, pathStart);
8588
- }
8589
- function hasPendingVirtualSourceIdentity(sourceIdentity2) {
8590
- const head = virtualSourceIdentityHead(sourceIdentity2);
8591
- return head.startsWith("path:__pending__:") || head.startsWith("__pending__:");
8592
- }
8593
- var PENDING_VIRTUAL_VALUE_PREFIX = "__pending__:virtual-value:";
8594
- function pendingVirtualValueId(pendingInstanceRootId, sourceIdentity2) {
8595
- return `${PENDING_VIRTUAL_VALUE_PREFIX}${encodeURIComponent(pendingInstanceRootId)}:${encodeURIComponent(sourceIdentity2)}`;
8596
- }
8597
-
8598
- // ../packages/models/src/members/packed-value-encoding.ts
8599
- var PACKED_VALUE_ENTRY_KEY = "~packed";
8600
- var PackedValueEncodingError = class extends Error {
8601
- constructor(message) {
8602
- super(message);
8603
- this.name = "PackedValueEncodingError";
8604
- }
8605
- };
8606
- var NO_CHILDREN = [];
8607
- var NO_EDGES = /* @__PURE__ */ new Map();
8608
- function isPackedValueEnvelope(value) {
8609
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
8610
- return false;
8611
- }
8612
- return Object.hasOwn(value, PACKED_VALUE_ENTRY_KEY);
8613
- }
8614
- function rowCarriesPackedValueContent(content) {
8615
- if (containerHoldsPackedEntry(content.value)) return true;
8616
- return containerHoldsPackedEntry(content.constructorArgs);
8617
- }
8618
- function expandPackedValueRows(rows) {
8619
- let firstPacked = -1;
8620
- for (let index = 0; index < rows.length; index += 1) {
8621
- const row = rows[index];
8622
- if (row === void 0 || !rowCarriesPackedValueContent(row)) continue;
8623
- firstPacked = index;
8624
- break;
8625
- }
8626
- if (firstPacked < 0) return rows;
8627
- const expanded = rows.slice(0, firstPacked);
8628
- for (let index = firstPacked; index < rows.length; index += 1) {
8629
- const row = rows[index];
8630
- if (row === void 0) continue;
8631
- const decoded = decodePackedValueRow(row);
8632
- expanded.push(decoded.row, ...decoded.children);
8633
- }
8634
- return expanded;
8635
- }
8636
- function expandPackedDocumentValues(document2) {
8637
- const stored = document2.values;
8638
- const expanded = expandPackedValueRows(stored);
8639
- if (expanded === stored) return document2;
8640
- return { ...document2, values: expanded };
8641
- }
8642
- function decodePackedValueRow(row) {
8643
- if (!rowCarriesPackedValueContent(row)) {
8644
- return { row, children: NO_CHILDREN, packedChildIdsByParentId: NO_EDGES };
8645
- }
8646
- const state = {
8647
- edges: /* @__PURE__ */ new Map(),
8648
- seenIds: /* @__PURE__ */ new Set([row.id]),
8649
- projectId: row.projectId,
8650
- mapKey: row.mapKey
8651
- };
8652
- const children = [];
8653
- const scope = {
8654
- state,
8655
- ownerId: row.id,
8656
- ownerLabel: `value "${row.id}"`,
8657
- constructionRootId: isCollapseStampedInstanceRoot(row) ? row.id : null
8658
- };
8659
- const value = decodeContentField(row.value, "value", scope, children);
8660
- const constructorArgs = decodeContentField(
8661
- isLiteralValueContent(row) ? row.constructorArgs : void 0,
8662
- "constructorArgs",
8663
- scope,
8664
- children
8665
- );
8666
- return {
8667
- row: withDecodedContent(row, value, constructorArgs),
8668
- children,
8669
- packedChildIdsByParentId: state.edges
8670
- };
8671
- }
8672
- function canonicalPackedChildId(args) {
8673
- if (args.constructionRootId === null) return null;
8674
- if (typeof args.sourceValueId !== "string") return null;
8675
- if (args.sourceValueId.length === 0) return null;
8676
- return virtualValueId(args.constructionRootId, args.sourceValueId);
8677
- }
8678
- function decodeContentField(container, field, scope, children) {
8679
- if (!containerHoldsPackedEntry(container)) return null;
8680
- if (Array.isArray(container)) {
8681
- return {
8682
- content: container.map(
8683
- (entry, index) => isPackedValueEnvelope(entry) ? decodeEnvelope(entry, `${field}[${index}]`, scope, children) : entry
8684
- )
8685
- };
8686
- }
8687
- const decoded = {};
8688
- for (const [key, entry] of Object.entries(
8689
- container
8690
- )) {
8691
- decoded[key] = isPackedValueEnvelope(entry) ? decodeEnvelope(
8692
- entry,
8693
- `${field}[${JSON.stringify(key)}]`,
8694
- scope,
8695
- children
8696
- ) : entry;
8697
- }
8698
- return { content: decoded };
8699
- }
8700
- function decodeEnvelope(envelope, position, scope, children) {
8701
- const label = `Packed value entry at ${scope.ownerLabel}.${position}`;
8702
- const entry = envelope[PACKED_VALUE_ENTRY_KEY];
8703
- assertDecodableEntry(entry, label);
8704
- const id = packedEntryLogicalId(entry, label, scope.constructionRootId);
8705
- if (scope.state.seenIds.has(id)) {
8706
- throw new PackedValueEncodingError(
8707
- `${label} resolves to id "${id}", which another row in the same packed payload already claims.`
8708
- );
8709
- }
8710
- scope.state.seenIds.add(id);
8711
- registerEdge(scope.state.edges, scope.ownerId, id);
8712
- const childScope = {
8713
- state: scope.state,
8714
- ownerId: id,
8715
- ownerLabel: `packed value "${id}"`,
8716
- constructionRootId: isCollapseStampedInstanceRoot(entry) ? id : scope.constructionRootId
8717
- };
8718
- const nested = [];
8719
- children.push(logicalChildRow(entry, id, childScope, nested));
8720
- children.push(...nested);
8721
- return id;
8722
- }
8723
- function logicalChildRow(entry, id, scope, children) {
8724
- const rowFields = {
8725
- id,
8726
- projectId: scope.state.projectId,
8727
- createdAt: entry.createdAt,
8728
- updatedAt: entry.updatedAt,
8729
- ...scope.state.mapKey === void 0 ? {} : { mapKey: scope.state.mapKey },
8730
- ...entry.genericBindings === void 0 ? {} : { genericBindings: entry.genericBindings },
8731
- ...entry.sourceValueId === void 0 ? {} : { sourceValueId: entry.sourceValueId }
8732
- };
8733
- if (isInitValueContent(entry)) return { ...rowFields, init: entry.init };
8734
- const value = decodeContentField(entry.value, "value", scope, children);
8735
- const constructorArgs = decodeContentField(
8736
- entry.constructorArgs,
8737
- "constructorArgs",
8738
- scope,
8739
- children
8740
- );
8741
- return {
8742
- ...rowFields,
8743
- ...literalContent(entry, value, constructorArgs)
8744
- };
8745
- }
8746
- function packedEntryLogicalId(entry, label, constructionRootId) {
8747
- const canonical = canonicalPackedChildId({
8748
- constructionRootId,
8749
- sourceValueId: entry.sourceValueId
8750
- });
8751
- const stored = entry.id;
8752
- if (stored === void 0) {
8753
- if (canonical === null) {
8754
- throw new PackedValueEncodingError(
8755
- `${label} stores no "id" and its position derives none: only a deterministic child of an enclosing construction root, stamped with a "sourceValueId", may omit its logical id.`
8756
- );
8757
- }
8758
- return canonical;
8759
- }
8760
- if (typeof stored !== "string" || stored.length === 0) {
8761
- throw new PackedValueEncodingError(
8762
- `${label} stores an "id" that is not a non-empty string.`
8763
- );
8764
- }
8765
- if (stored === canonical) {
8766
- throw new PackedValueEncodingError(
8767
- `${label} stores id "${stored}", which its position already derives; a derivable id must be omitted rather than repeated.`
8768
- );
8769
- }
8770
- return stored;
8771
- }
8772
- var PACKED_ENTRY_FORBIDDEN_FIELDS = [
8773
- "projectId",
8774
- "containerId",
8775
- "mapKey"
8776
- ];
8777
- function assertDecodableEntry(entry, label) {
8778
- if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
8779
- throw new PackedValueEncodingError(`${label} is not an object.`);
8780
- }
8781
- for (const field of PACKED_ENTRY_FORBIDDEN_FIELDS) {
8782
- if (!Object.hasOwn(entry, field)) continue;
8783
- throw new PackedValueEncodingError(
8784
- `${label} stores "${field}", which decoding derives from its owning row.`
8785
- );
8786
- }
8787
- if (!("createdAt" in entry) || typeof entry.createdAt !== "number") {
8788
- throw new PackedValueEncodingError(
8789
- `${label} stores no numeric "createdAt".`
8790
- );
8791
- }
8792
- if (!("updatedAt" in entry) || typeof entry.updatedAt !== "number") {
8793
- throw new PackedValueEncodingError(
8794
- `${label} stores no numeric "updatedAt".`
8795
- );
8796
- }
8797
- const hasValue = Object.hasOwn(entry, "value");
8798
- const hasInit = Object.hasOwn(entry, "init");
8799
- if (hasValue && hasInit) {
8800
- throw new PackedValueEncodingError(
8801
- `${label} stores both "value" and "init"; a value container holds exactly one.`
8802
- );
8803
- }
8804
- if (!hasValue && !hasInit) {
8805
- throw new PackedValueEncodingError(
8806
- `${label} stores neither "value" nor "init"; a value container holds exactly one.`
8807
- );
8808
- }
8809
- if (hasInit && !isInitValueContent(entry)) {
8810
- throw new PackedValueEncodingError(
8811
- `${label} stores an "init" that is not a valid initializer body.`
8812
- );
8813
- }
8814
- if (hasValue && !isLiteralValueContent(entry)) {
8815
- throw new PackedValueEncodingError(
8816
- `${label} stores a "value" whose class or construction stamp is malformed.`
8817
- );
8818
- }
8819
- }
8820
- function literalContent(content, value, constructorArgs) {
8821
- if (!isLiteralValueContent(content)) {
8822
- throw new PackedValueEncodingError(
8823
- `Value container has no literal "value" to encode.`
8824
- );
8825
- }
8826
- const provenance = pickInstanceProvenance(content);
8827
- return {
8828
- value: value === null ? content.value : value.content,
8829
- ...Object.hasOwn(content, "classId") ? { classId: content.classId } : {},
8830
- ...provenance,
8831
- ...constructorArgs === null ? {} : { constructorArgs: asConstructorArgs(constructorArgs.content) }
8832
- };
8833
- }
8834
- function withDecodedContent(row, value, constructorArgs) {
8835
- if (value === null && constructorArgs === null) return row;
8836
- return { ...row, ...literalContent(row, value, constructorArgs) };
8837
- }
8838
- function asConstructorArgs(content) {
8839
- if (content === null) return null;
8840
- if (typeof content !== "object" || Array.isArray(content)) {
8841
- throw new PackedValueEncodingError(
8842
- `Value container stores "constructorArgs" that is not a record.`
8843
- );
8844
- }
8845
- return content;
8846
- }
8847
- function containerHoldsPackedEntry(container) {
8848
- if (Array.isArray(container)) {
8849
- return container.some((entry) => isPackedValueEnvelope(entry));
8850
- }
8851
- if (typeof container !== "object" || container === null) return false;
8852
- for (const entry of Object.values(container)) {
8853
- if (isPackedValueEnvelope(entry)) return true;
8854
- }
8855
- return false;
8856
- }
8857
- function registerEdge(edges, ownerId, childId) {
8858
- const existing = edges.get(ownerId);
8859
- if (existing === void 0) edges.set(ownerId, [childId]);
8860
- else existing.push(childId);
8861
- }
8862
-
8863
- // ../packages/models/src/members/member-storage-key.ts
8864
- var MAIN_STORAGE_PARTITION = "main";
8865
- var STORAGE_KEY_INHERIT = "inherit";
8866
- var STORAGE_KEY_ALL = "all";
8867
- var PARENT_CLASS_TEMPLATE_TOKEN = "$parentClass";
8868
- function normalizeStorageKeyDeclaration(declaration) {
8869
- if (declaration === void 0 || declaration === null) {
8870
- return STORAGE_KEY_INHERIT;
8871
- }
8872
- if (declaration.length === 0) return STORAGE_KEY_INHERIT;
8873
- if (declaration === STORAGE_KEY_ALL) {
8874
- throw new Error(
8875
- 'Storage key "all" is reserved for partition-scoped reads and cannot be declared on a member.'
8876
- );
8877
- }
8878
- return declaration;
8879
- }
8880
- function storageKeyReferencesParentClass(declaration) {
8881
- return declaration.includes(PARENT_CLASS_TEMPLATE_TOKEN);
8882
- }
8883
- function resolveMapKeyForCreatedValue(args) {
8884
- const declaration = normalizeStorageKeyDeclaration(args.declaration);
8885
- if (declaration === STORAGE_KEY_INHERIT) return args.parentMapKey;
8886
- if (declaration === MAIN_STORAGE_PARTITION) return null;
8887
- if (storageKeyReferencesParentClass(declaration)) {
8888
- if (args.parentClassId === void 0) {
8889
- throw new Error(
8890
- `Storage key "${declaration}" references ${PARENT_CLASS_TEMPLATE_TOKEN}, but the placement parent value has no classId (only class-valued parents can anchor a ${PARENT_CLASS_TEMPLATE_TOKEN} partition).`
8891
- );
8892
- }
8893
- return declaration.replaceAll(
8894
- PARENT_CLASS_TEMPLATE_TOKEN,
8895
- args.parentClassId
8896
- );
8897
- }
8898
- return declaration;
8899
- }
8900
-
8901
- // ../packages/models/src/members/storage-partitions.ts
8902
- function stampCreatedValuesMapKey(values, mapKey) {
8903
- const normalized = mapKey === void 0 || mapKey === null || mapKey.length === 0 || mapKey === MAIN_STORAGE_PARTITION ? null : mapKey;
8904
- for (const value of values) {
8905
- if (normalized === null) {
8906
- delete value.mapKey;
8907
- } else {
8908
- value.mapKey = normalized;
8909
- }
8910
- }
8911
- }
8912
- function applyDeclaredStorageKeyOverrides(args) {
8913
- const boundaryValues = args.createdValues.filter(
8914
- (value) => normalizeStorageKeyDeclaration(
8915
- args.declarationByValueId.get(value.id)
8916
- ) !== STORAGE_KEY_INHERIT
8917
- );
8918
- if (boundaryValues.length === 0) return;
8919
- const createdById = new Map(
8920
- args.createdValues.map((value) => [value.id, value])
8921
- );
8922
- const parentOf = /* @__PURE__ */ new Map();
8923
- for (const value of args.createdValues) {
8924
- for (const childId of referencedValueIdCandidates(value.value)) {
8925
- if (createdById.has(childId)) parentOf.set(childId, value);
8926
- }
8927
- }
8928
- for (const value of args.createdValues) {
8929
- if (typeof value.containerId !== "string") continue;
8930
- const container = createdById.get(value.containerId);
8931
- if (container !== void 0) parentOf.set(value.id, container);
8932
- }
8933
- const depthOf = (value) => {
8934
- let depth = 0;
8935
- let current = value;
8936
- const seen = /* @__PURE__ */ new Set();
8937
- while (current !== void 0 && !seen.has(current.id)) {
8938
- seen.add(current.id);
8939
- current = parentOf.get(current.id);
8940
- if (current !== void 0) depth += 1;
8941
- }
8942
- return depth;
8943
- };
8944
- const boundaries = boundaryValues.sort((left, right) => depthOf(left) - depthOf(right));
8945
- for (const boundary of boundaries) {
8946
- const parentCreated = parentOf.get(boundary.id);
8947
- const parent = parentCreated !== void 0 ? {
8948
- mapKey: parentCreated.mapKey ?? null,
8949
- classId: parentCreated.classId ?? void 0
8950
- } : args.existingParentContextById?.get(boundary.id);
8951
- if (parent === void 0) {
8952
- throw new Error(
8953
- `Cannot resolve storage partition for created value "${boundary.id}": its placement parent is neither a created value nor supplied in existingParentContextById.`
8954
- );
8955
- }
8956
- const mapKey = resolveMapKeyForCreatedValue({
8957
- declaration: args.declarationByValueId.get(boundary.id),
8958
- parentMapKey: parent.mapKey,
8959
- parentClassId: parent.classId
8960
- });
8961
- for (const member of collectCreatedSubtreeValues(
8962
- boundary,
8963
- args.createdValues
8964
- )) {
8965
- if (mapKey === null || mapKey === MAIN_STORAGE_PARTITION) {
8966
- delete member.mapKey;
8967
- } else {
8968
- member.mapKey = mapKey;
8969
- }
8970
- }
8971
- }
8972
- }
8973
- function collectCreatedSubtreeValues(root, createdValues) {
8974
- const createdById = new Map(createdValues.map((value) => [value.id, value]));
8975
- const subtree = [];
8976
- const visited = /* @__PURE__ */ new Set();
8977
- const queue = [root];
8978
- while (queue.length > 0) {
8979
- const current = queue.shift();
8980
- if (current === void 0) break;
8981
- if (visited.has(current.id)) continue;
8982
- visited.add(current.id);
8983
- subtree.push(current);
8984
- for (const childId of referencedValueIdCandidates(current.value)) {
8985
- const child = createdById.get(childId);
8986
- if (child !== void 0) queue.push(child);
8987
- }
8988
- for (const candidate of createdValues) {
8989
- if (candidate.containerId === current.id) queue.push(candidate);
8990
- }
8991
- }
8992
- return subtree;
8993
- }
8994
- function referencedValueIdCandidates(value) {
8995
- if (Array.isArray(value)) {
8996
- return value.filter((entry) => typeof entry === "string");
8997
- }
8998
- if (typeof value === "object" && value !== null) {
8999
- return Object.values(value).filter(
9000
- (entry) => typeof entry === "string"
9001
- );
9002
- }
9003
- return [];
9004
- }
9005
-
9006
- // ../packages/models/src/core/auth-ownership-types.ts
9007
- var ActorKind = {
9008
- /**
9009
- * `better-auth` user identities.
9010
- */
9011
- user: "user",
9012
- /**
9013
- * `better-auth` organization identities.
9014
- */
9015
- organization: "organization",
9016
- /**
9017
- * Used for denoting records created by a system.
9018
- */
9019
- system: "system"
9020
- };
9021
- function isActorIdentifier(value) {
9022
- if (typeof value !== "object") return false;
9023
- if (value === null) return false;
9024
- const candidate = value;
9025
- if (!isActorKind(candidate.kind)) return false;
9026
- return typeof candidate.id === "string" && candidate.id.trim().length > 0;
9027
- }
9028
- function isActorKind(value) {
9029
- return value === ActorKind.user || value === ActorKind.organization || value === ActorKind.system;
9030
- }
9031
-
9032
- // ../packages/models/src/members/member-change-listeners.ts
9033
- function editChangeListenerSet(explicit, inherited, edit, options = { inheritedComplete: true }) {
9034
- if (edit.kind === "reset") {
9035
- return explicit === void 0 ? { changed: false } : { changed: true, targets: void 0 };
9036
- }
9037
- const current = explicit ?? inherited;
9038
- let next;
9039
- if (edit.kind === "replace") {
9040
- next = edit.targets;
9041
- } else {
9042
- const identity = nsActionListenerIdentity(edit.target);
9043
- const index = current.findIndex(
9044
- (target) => nsActionListenerIdentity(target) === identity
9045
- );
9046
- if (edit.kind === "add") {
9047
- if (index !== -1) return { changed: false };
9048
- next = [...current, edit.target];
9049
- } else {
9050
- if (index === -1) return { changed: false };
9051
- next = current.filter((_, i) => i !== index);
9052
- }
9053
- }
9054
- const targets = [];
9055
- const seen = /* @__PURE__ */ new Set();
9056
- for (const target of next) {
9057
- const identity = nsActionListenerIdentity(target);
9058
- if (seen.has(identity))
9059
- throw new Error("A listener set cannot repeat a handler identity.");
9060
- seen.add(identity);
9061
- targets.push({ memberId: target.memberId, valueId: target.valueId });
9062
- }
9063
- if (targets.length === 0 && inherited.length === 0 && options.inheritedComplete) {
9064
- return explicit === void 0 ? { changed: false } : { changed: true, targets: void 0 };
9065
- }
9066
- if (explicit !== void 0 && sameChangeListeners(explicit, targets))
9067
- return { changed: false };
9068
- return { changed: true, targets };
9069
- }
9070
- function sameChangeListeners(left, right) {
9071
- return left.length === right.length && left.every(
9072
- (entry, index) => entry.memberId === right[index].memberId && entry.valueId === right[index].valueId
9073
- );
9074
- }
9075
- function remapChangeListenerMap(map, identities, policy, internalEndpoints) {
9076
- if (!map) return void 0;
9077
- const result = {};
9078
- for (const [ownerId, members] of Object.entries(map)) {
9079
- const owner = identities.get(ownerId);
9080
- if (owner === void 0) continue;
9081
- const entry = {};
9082
- for (const [memberId, targets] of Object.entries(members)) {
9083
- const remapped = [];
9084
- for (const target of targets) {
9085
- const receiver = target.valueId === null ? null : identities.get(target.valueId);
9086
- if (receiver === void 0 && (policy === "clone" || target.valueId !== null && internalEndpoints !== void 0 && internalEndpoints.has(target.valueId)))
9087
- continue;
9088
- remapped.push({
9089
- memberId: target.memberId,
9090
- valueId: receiver ?? target.valueId
9091
- });
9092
- }
9093
- setOwnField(entry, memberId, remapped);
9094
- }
9095
- setOwnField(result, owner, entry);
9096
- }
9097
- return Object.keys(result).length === 0 ? void 0 : result;
9098
- }
9099
- var authoredListenerIndexes = /* @__PURE__ */ new WeakMap();
9100
- function authoredChangeListenerOwners(rows) {
9101
- const index = authoredListenerIndexes.get(rows);
9102
- if (index !== void 0) return index;
9103
- const owners = /* @__PURE__ */ new Map();
9104
- for (const row of rows)
9105
- for (const [ownerId, entry] of Object.entries(row.changeListeners ?? {})) {
9106
- if (owners.has(ownerId))
9107
- throw new Error(
9108
- `Listener owner "${ownerId}" is declared on more than one binding root.`
9109
- );
9110
- owners.set(ownerId, entry);
9111
- }
9112
- authoredListenerIndexes.set(rows, owners);
9113
- return owners;
9114
- }
9115
- var declarationListenerMetadata = /* @__PURE__ */ new WeakMap();
9116
- function hasAuthoredChangeListenerMetadata(document2) {
9117
- if (authoredChangeListenerOwners(document2.values).size !== 0) return true;
9118
- let present = declarationListenerMetadata.get(document2.members);
9119
- if (present === void 0) {
9120
- present = document2.members.some(
9121
- (member) => member.defaultValue?.changeListeners !== void 0
9122
- );
9123
- declarationListenerMetadata.set(document2.members, present);
9124
- }
9125
- return present;
9126
- }
9127
- function defaultSourceWithListeners(row, graph) {
9128
- if (row === null || graph == null || graph.instanceRootId !== row.id)
9129
- return row;
9130
- const inherited = graph.listenerDefaultsByOwner;
9131
- if (inherited === void 0 || inherited.size === 0) return row;
9132
- const map = Object.fromEntries(inherited);
9133
- for (const [id, entry] of Object.entries(row.changeListeners ?? {}))
9134
- setOwnField(map, id, { ...map[id], ...entry });
9135
- return { ...row, changeListeners: map };
9136
- }
9137
-
9138
9157
  // ../packages/models/src/constructors/constructors.ts
9139
9158
  var REJECTED_CONSTRUCTOR_KEYS = [
9140
9159
  "bodyMode",
@@ -9320,7 +9339,7 @@ function constructionMembers(classId, context) {
9320
9339
  const { document: document2, memberById, env } = context;
9321
9340
  if (firstUnboundParamId(env) !== null) return [];
9322
9341
  const result = [];
9323
- for (const entry of mergeStoredInstanceSchema(
9342
+ for (const entry of mergeInstanceSurfaceSchema(
9324
9343
  classId,
9325
9344
  document2.classes,
9326
9345
  document2.members
@@ -9338,7 +9357,6 @@ function constructionMembers(classId, context) {
9338
9357
  id: raw.id
9339
9358
  };
9340
9359
  if (isAbstractMember(member)) continue;
9341
- if (isReadOnlyMember(member)) continue;
9342
9360
  if (!memberKindOwnsStoredValue(member.kind)) continue;
9343
9361
  if ("payload" in member && member.payload === 1 /* Partial */)
9344
9362
  continue;
@@ -10569,7 +10587,7 @@ function withIndexedDefaultValueDocument(document2, options = {}) {
10569
10587
  classId,
10570
10588
  document2.classes,
10571
10589
  document2.members
10572
- ).stored;
10590
+ ).surface;
10573
10591
  cache.storedSchemaByClassId.set(classId, schema);
10574
10592
  return schema;
10575
10593
  },
@@ -10649,26 +10667,219 @@ function buildDefaultClassMaterializationPlan(document2, classId, instanceEnv) {
10649
10667
  ...document2,
10650
10668
  constructors: document2.constructors ?? []
10651
10669
  });
10652
- const merged = document2.storedInstanceSchema?.(classId) ?? mergeStoredInstanceSchema(classId, document2.classes, document2.members);
10653
- return merged.flatMap((entry) => {
10654
- if (entry.memberId === null) return [];
10655
- const childMember = findMemberInDocument(document2, entry.memberId);
10656
- if (!memberKindOwnsStoredValue(childMember.kind)) return [];
10657
- const member = substituteMember(
10658
- childMember,
10659
- instanceEnv,
10660
- document2.members,
10661
- document2.resolvedMember?.(childMember)
10662
- );
10663
- return [
10664
- {
10665
- schemaKey: entry.schemaKey,
10666
- member,
10667
- defaultSettlesConstruction: settlesConstruction(member, instanceEnv),
10668
- directScalarBody: directScalarDefaultBody(document2, member)
10670
+ return storedSchemaOf(document2, classId).flatMap(
10671
+ (entry) => {
10672
+ if (entry.memberId === null) return [];
10673
+ const childMember = findMemberInDocument(document2, entry.memberId);
10674
+ if (!memberKindOwnsStoredValue(childMember.kind)) return [];
10675
+ if (instanceEnv.size === 0 && isConstantMember(document2, resolvedInDocument(document2, childMember)))
10676
+ return [];
10677
+ const member = substituteMember(
10678
+ childMember,
10679
+ instanceEnv,
10680
+ document2.members,
10681
+ document2.resolvedMember?.(childMember)
10682
+ );
10683
+ return [
10684
+ {
10685
+ schemaKey: entry.schemaKey,
10686
+ member,
10687
+ defaultSettlesConstruction: settlesConstruction(member, instanceEnv),
10688
+ directScalarBody: directScalarDefaultBody(document2, member)
10689
+ }
10690
+ ];
10691
+ }
10692
+ );
10693
+ }
10694
+ function isConstantMember(document2, resolved) {
10695
+ if (isStaticMember(resolved)) return false;
10696
+ const fixedness = fixednessOf(resolved, 0 /* Writable */);
10697
+ if (fixedness === 0 /* Writable */) return false;
10698
+ const declared = resolved.defaultValue;
10699
+ if (declared == null) return false;
10700
+ if (fixedness === 1 /* ReadOnly */ && (isMemberListBase(resolved) || isMemberDictionaryBase(resolved)))
10701
+ return false;
10702
+ return !declarationVaries(
10703
+ {
10704
+ document: document2,
10705
+ rows: /* @__PURE__ */ new Set(),
10706
+ declarations: /* @__PURE__ */ new Set(),
10707
+ classes: /* @__PURE__ */ new Set()
10708
+ },
10709
+ resolved,
10710
+ declared,
10711
+ null,
10712
+ { fixedness, ownsReads: true }
10713
+ );
10714
+ }
10715
+ function fixednessOf(resolved, parent) {
10716
+ const storage = resolved.storage ?? 0 /* Inherit */;
10717
+ if (storage === 1 /* Immutable */) return 2 /* Immutable */;
10718
+ if (storage === 0 /* Inherit */ && parent === 2 /* Immutable */)
10719
+ return 2 /* Immutable */;
10720
+ return isReadOnlyMember(resolved) ? 1 /* ReadOnly */ : 0 /* Writable */;
10721
+ }
10722
+ function scopeKey(id, scope) {
10723
+ return `${id}:${scope.fixedness}:${scope.ownsReads}`;
10724
+ }
10725
+ function resolvedInDocument(document2, member) {
10726
+ return document2.resolvedMember?.(member) ?? resolveMember(member, document2.members);
10727
+ }
10728
+ function declarationVaries(walk, member, body, rowId, scope) {
10729
+ const { document: document2 } = walk;
10730
+ const { ownsReads } = scope;
10731
+ const immutable2 = scope.fixedness === 2 /* Immutable */;
10732
+ if (documentHasInitValueContent(document2, body)) {
10733
+ if (!immutable2) return true;
10734
+ if (ownsReads) {
10735
+ const compiled = body.init.compiled;
10736
+ if (compiled === void 0) return true;
10737
+ if (initializerReadsInstance(compiled)) return true;
10738
+ }
10739
+ return typeHoldsWritable(walk, member, 2 /* Immutable */);
10740
+ }
10741
+ if (!isLiteralValueContent(body)) return true;
10742
+ if (!immutable2 && body.instanceConstructorId !== void 0) return true;
10743
+ if (!immutable2 && body.constructorArgs != null) return true;
10744
+ if (ownsReads && irReadsInstance(body.constructorArgs, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set()))
10745
+ return true;
10746
+ const value = body.value;
10747
+ if (isMemberClassBase(member)) {
10748
+ if (value === null) return false;
10749
+ if (!isStringRecord(value)) return true;
10750
+ const classId = typeof body.classId === "string" ? body.classId : member.classId;
10751
+ let owned = 0;
10752
+ for (const entry of storedSchemaOf(document2, classId)) {
10753
+ if (entry.memberId === null) continue;
10754
+ const child = resolvedInDocument(
10755
+ document2,
10756
+ findMemberInDocument(document2, entry.memberId)
10757
+ );
10758
+ const childId = value[entry.schemaKey];
10759
+ if (childId !== void 0) owned++;
10760
+ else if (!memberKindOwnsStoredValue(child.kind) || isStaticMember(child))
10761
+ continue;
10762
+ const fixedness = fixednessOf(child, scope.fixedness);
10763
+ if (fixedness === 0 /* Writable */) return true;
10764
+ if (childId !== void 0) {
10765
+ if (rowVaries(walk, child, childId, { fixedness, ownsReads }))
10766
+ return true;
10767
+ continue;
10669
10768
  }
10670
- ];
10671
- });
10769
+ const declared = child.defaultValue;
10770
+ if (declared == null) continue;
10771
+ const childScope = { fixedness, ownsReads: false };
10772
+ const key = scopeKey(entry.memberId, childScope);
10773
+ if (walk.declarations.has(key)) continue;
10774
+ walk.declarations.add(key);
10775
+ if (declarationVaries(walk, child, declared, null, childScope))
10776
+ return true;
10777
+ }
10778
+ return owned !== Object.keys(value).length;
10779
+ }
10780
+ if (isMemberListBase(member)) {
10781
+ const entryIds = listKindOf(member) !== 1 /* Unordered */ ? value : rowId === null ? [] : document2.unorderedListEntryIds?.(rowId) ?? (walk.membership ??= buildUnorderedListMembershipIndex(
10782
+ document2.values
10783
+ )).get(rowId) ?? [];
10784
+ if (entryIds === null) return false;
10785
+ if (!Array.isArray(entryIds)) return true;
10786
+ return entriesVary(walk, member.entryMemberId, entryIds, scope);
10787
+ }
10788
+ if (isMemberDictionaryBase(member)) {
10789
+ if (value === null) return false;
10790
+ if (!isStringRecord(value)) return true;
10791
+ return entriesVary(walk, member.entryMemberId, Object.values(value), scope);
10792
+ }
10793
+ if (member.kind === 21 /* Generic */) return true;
10794
+ return ownsReads && irReadsInstance(value, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set());
10795
+ }
10796
+ function entriesVary(walk, entryMemberId, entryIds, scope) {
10797
+ if (entryIds.length === 0) return false;
10798
+ const entryMember = resolvedInDocument(
10799
+ walk.document,
10800
+ findMemberInDocument(walk.document, entryMemberId)
10801
+ );
10802
+ const fixedness = fixednessOf(entryMember, scope.fixedness);
10803
+ if (fixedness === 0 /* Writable */) return true;
10804
+ const entryScope = { fixedness, ownsReads: scope.ownsReads };
10805
+ return entryIds.some(
10806
+ (entryId) => typeof entryId !== "string" || rowVaries(walk, entryMember, entryId, entryScope)
10807
+ );
10808
+ }
10809
+ function rowVaries(walk, member, valueId, scope) {
10810
+ const key = scopeKey(valueId, scope);
10811
+ if (walk.rows.has(key)) return false;
10812
+ walk.rows.add(key);
10813
+ const { document: document2 } = walk;
10814
+ const row = document2.valueById?.(valueId) ?? (walk.rowById ??= new Map(
10815
+ document2.values.map((value) => [value.id, value])
10816
+ )).get(valueId);
10817
+ if (row === void 0 || row === null) return true;
10818
+ return declarationVaries(walk, member, row, row.id, scope);
10819
+ }
10820
+ function typeHoldsWritable(walk, member, fixedness) {
10821
+ if (isMemberClassBase(member)) {
10822
+ const { classes } = walk.document;
10823
+ if (!classIndexFor(classes).has(member.classId)) return true;
10824
+ if (classHoldsWritable(walk, member.classId, fixedness)) return true;
10825
+ for (const classId of descendantClassIds(member.classId, classes)) {
10826
+ if (classHoldsWritable(walk, classId, fixedness)) return true;
10827
+ }
10828
+ return false;
10829
+ }
10830
+ if (isMemberListBase(member) || isMemberDictionaryBase(member)) {
10831
+ const entryMember = resolvedInDocument(
10832
+ walk.document,
10833
+ findMemberInDocument(walk.document, member.entryMemberId)
10834
+ );
10835
+ const entryFixedness = fixednessOf(entryMember, fixedness);
10836
+ return entryFixedness === 0 /* Writable */ || typeHoldsWritable(walk, entryMember, entryFixedness);
10837
+ }
10838
+ return member.kind === 21 /* Generic */;
10839
+ }
10840
+ function classHoldsWritable(walk, classId, fixedness) {
10841
+ const key = `${classId}:${fixedness}`;
10842
+ if (walk.classes.has(key)) return false;
10843
+ walk.classes.add(key);
10844
+ const { document: document2 } = walk;
10845
+ for (const entry of storedSchemaOf(document2, classId)) {
10846
+ if (entry.memberId === null) continue;
10847
+ const child = resolvedInDocument(
10848
+ document2,
10849
+ findMemberInDocument(document2, entry.memberId)
10850
+ );
10851
+ if (!memberKindOwnsStoredValue(child.kind) || isStaticMember(child))
10852
+ continue;
10853
+ const childFixedness = fixednessOf(child, fixedness);
10854
+ if (childFixedness === 0 /* Writable */) return true;
10855
+ if (typeHoldsWritable(walk, child, childFixedness)) return true;
10856
+ }
10857
+ return false;
10858
+ }
10859
+ function storedSchemaOf(document2, classId) {
10860
+ return document2.storedInstanceSchema?.(classId) ?? resolvedClassSchema(classId, document2.classes, document2.members).surface;
10861
+ }
10862
+ function initializerReadsInstance(compiled) {
10863
+ const instanceParameters = /* @__PURE__ */ new Set();
10864
+ for (const parameter3 of compiled.parameters) {
10865
+ if (parameter3.id !== "__root__") instanceParameters.add(parameter3.id);
10866
+ }
10867
+ return irReadsInstance(compiled.instructions, instanceParameters, /* @__PURE__ */ new Set());
10868
+ }
10869
+ function irReadsInstance(value, instanceParameters, visited) {
10870
+ if (typeof value !== "object" || value === null) return false;
10871
+ if (visited.has(value)) return false;
10872
+ visited.add(value);
10873
+ if (isMemberDelegateTarget(value) && value.valueId === null) return true;
10874
+ if (Reflect.get(value, "type") === "variable" /* variable */) {
10875
+ const variableId = Reflect.get(value, "variableId");
10876
+ if (typeof variableId === "string" && instanceParameters.has(variableId))
10877
+ return true;
10878
+ }
10879
+ for (const child of Object.values(value)) {
10880
+ if (irReadsInstance(child, instanceParameters, visited)) return true;
10881
+ }
10882
+ return false;
10672
10883
  }
10673
10884
  function assertLookupInitializerLiteral(member, literal3) {
10674
10885
  if (!isMemberLookupBase(member)) return;
@@ -11515,7 +11726,7 @@ function formatDefaultReferenceLocation(memberName, key) {
11515
11726
  function getSchemaEntryMap(document2, classId) {
11516
11727
  const node = resolvedClassSchema(classId, document2.classes, document2.members);
11517
11728
  const entries = document2.storedInstanceSchema?.(classId);
11518
- return entries === void 0 || entries === node.stored ? node.storedByKey : new Map(entries.map((entry) => [entry.schemaKey, entry]));
11729
+ return entries === void 0 || entries === node.surface ? node.surfaceByKey : new Map(entries.map((entry) => [entry.schemaKey, entry]));
11519
11730
  }
11520
11731
  function cloneMemberValueBase(body) {
11521
11732
  return {
@@ -12662,6 +12873,50 @@ function buildNeoScriptConstructorSignature(classId, members, memberDescriptor)
12662
12873
  parameters
12663
12874
  };
12664
12875
  }
12876
+ function buildNeoScriptConstructionSignatures(classId, members, memberDescriptor, immutableOnly) {
12877
+ const descriptors = /* @__PURE__ */ new Map();
12878
+ const describe = (memberId) => {
12879
+ let descriptor = descriptors.get(memberId);
12880
+ if (descriptor === void 0) {
12881
+ descriptor = memberDescriptor(memberId);
12882
+ descriptors.set(memberId, descriptor);
12883
+ }
12884
+ return descriptor;
12885
+ };
12886
+ const replay = buildNeoScriptConstructorSignature(classId, members, describe);
12887
+ if (immutableOnly) {
12888
+ return {
12889
+ storedConstructionReplaySignature: replay,
12890
+ constructorUnavailableReason: "immutableOnly"
12891
+ };
12892
+ }
12893
+ let hasImmutableMember = false;
12894
+ for (const descriptor of descriptors.values()) {
12895
+ if (descriptor?.immutable !== true) continue;
12896
+ if (constructorParameterIsRequired(
12897
+ descriptor.required,
12898
+ descriptor.defaultValue
12899
+ )) {
12900
+ return {
12901
+ storedConstructionReplaySignature: replay,
12902
+ constructorUnavailableReason: "requiredImmutableMember"
12903
+ };
12904
+ }
12905
+ hasImmutableMember = true;
12906
+ }
12907
+ if (!hasImmutableMember) return { constructorSignature: replay };
12908
+ return {
12909
+ constructorSignature: buildNeoScriptConstructorSignature(
12910
+ classId,
12911
+ members,
12912
+ (memberId) => {
12913
+ const descriptor = describe(memberId);
12914
+ return descriptor?.immutable === true ? null : descriptor;
12915
+ }
12916
+ ),
12917
+ storedConstructionReplaySignature: replay
12918
+ };
12919
+ }
12665
12920
  function isNeoScriptTypeAssignable(source, target, project) {
12666
12921
  if (isUnknownType(source) || isUnknownType(target)) return false;
12667
12922
  if (isNullType(source)) return isNullableType2(target);
@@ -13340,7 +13595,7 @@ function resolveOwnerMembersForValues(document2, targetValueIds, additionalRoots
13340
13595
  function storedSchema(classId) {
13341
13596
  const cached = storedSchemaByClassId.get(classId);
13342
13597
  if (cached !== void 0) return cached;
13343
- const created = mergeStoredInstanceSchema(
13598
+ const created = mergeInstanceSurfaceSchema(
13344
13599
  classId,
13345
13600
  document2.classes,
13346
13601
  document2.members
@@ -15308,15 +15563,15 @@ function classImplementsInterface(classId, interfaceId, classes, interfaces) {
15308
15563
  function readClassMember(args) {
15309
15564
  const { member, schemaKey } = args;
15310
15565
  const declaration = member.kind !== 10 /* NSProperty */ && member.defaultValue != null ? member.defaultValue : void 0;
15311
- if (args.mode !== "partial" && isReadOnlyMember(member) && declaration !== void 0)
15312
- return { kind: "declaration", content: declaration };
15313
15566
  if (Object.prototype.hasOwnProperty.call(args.record, schemaKey))
15314
15567
  return { kind: "value", value: Reflect.get(args.record, schemaKey) };
15315
15568
  if (args.mode === "partial") return { kind: "missing" };
15316
15569
  const expanded = args.expandedRecord();
15317
15570
  if (expanded !== null && Object.prototype.hasOwnProperty.call(expanded, schemaKey))
15318
15571
  return { kind: "value", value: Reflect.get(expanded, schemaKey) };
15319
- if (args.mode !== "resolved" && declaration !== void 0)
15572
+ if (args.mode === "resolved")
15573
+ return declaration !== void 0 && args.isConstant() ? { kind: "declaration", content: declaration } : { kind: "missing" };
15574
+ if (declaration !== void 0)
15320
15575
  return { kind: "declaration", content: declaration };
15321
15576
  if (args.mode === "runtime" && !isRequiredMember(member))
15322
15577
  return { kind: "null" };
@@ -16822,6 +17077,7 @@ function withEvaluationRuntime(ctx, writes) {
16822
17077
  constructionTimestamp: Date.now(),
16823
17078
  ownedValueAttachments: /* @__PURE__ */ new Map(),
16824
17079
  constructionStack: [],
17080
+ openConstructions: /* @__PURE__ */ new Map(),
16825
17081
  loopIterations: 0,
16826
17082
  budgetedConstructedRowIds: /* @__PURE__ */ new Set(),
16827
17083
  budgetedProducedEntriesByRowId: /* @__PURE__ */ new Map(),
@@ -17957,14 +18213,16 @@ function evalInstructions(instructions, scope, ctx, options) {
17957
18213
  };
17958
18214
  }
17959
18215
  const assignedReferenceValueId = targetTypeInfo.type === 7 /* Class */ || targetTypeInfo.type === 6 /* List */ || targetTypeInfo.type === 5 /* Dictionary */ ? findKnownRowIdByValueReference(value, ctx) : null;
17960
- applyOverlayAssignment(
17961
- ins.target.pointer,
17962
- targetTypeInfo,
17963
- value,
17964
- scope,
17965
- ctx,
17966
- destination
17967
- );
18216
+ if (!bindOmittedConstantSlot(destination, member, value, ctx)) {
18217
+ applyOverlayAssignment(
18218
+ ins.target.pointer,
18219
+ targetTypeInfo,
18220
+ value,
18221
+ scope,
18222
+ ctx,
18223
+ destination
18224
+ );
18225
+ }
17968
18226
  const unorderedReplacement = assignedReferenceValueId === null && member !== null && isMemberListBase(member) && listKindOf(member) === 1 /* Unordered */ && Array.isArray(value) ? unorderedReplacementProjection(
17969
18227
  ins.target.pointer,
17970
18228
  destination,
@@ -18580,7 +18838,6 @@ function evalActionListenerInstruction(ins, scope, ctx, options) {
18580
18838
  scope,
18581
18839
  ctx,
18582
18840
  target.optional === true,
18583
- target.memberId,
18584
18841
  (resolved) => {
18585
18842
  destination = resolved;
18586
18843
  }
@@ -18820,6 +19077,36 @@ function applyOverlayStaticAssignment(memberId, value, ctx) {
18820
19077
  bindings.set(member.id, row.id);
18821
19078
  invalidateEvaluatorIndexes(ctx);
18822
19079
  }
19080
+ function bindOmittedConstantSlot(destination, member, value, ctx) {
19081
+ if (destination === void 0 || member === null) return false;
19082
+ const { receiver } = destination;
19083
+ if (typeof receiver !== "object" || receiver === null) return false;
19084
+ const construction = ctx.__executionState?.openConstructions.get(receiver);
19085
+ if (construction === void 0) return false;
19086
+ const key = String(destination.key);
19087
+ if (Object.prototype.hasOwnProperty.call(receiver, key)) return false;
19088
+ if (isMemberClassBase(member) || isMemberListBase(member) || isMemberDictionaryBase(member))
19089
+ return false;
19090
+ const resolved = resolveMember(member, ctx.vm.members);
19091
+ if (!isConstantMember(constructorDefaultValueDocument(ctx, member), resolved))
19092
+ return false;
19093
+ const { createdValues } = construction;
19094
+ const staged = createdValues.length;
19095
+ const row = materializeConstructorArgumentValue({
19096
+ member: resolved,
19097
+ value,
19098
+ // A constant has no instance environment.
19099
+ genericEnv: /* @__PURE__ */ new Map(),
19100
+ ctx,
19101
+ createdValues,
19102
+ createdById: /* @__PURE__ */ new Map(),
19103
+ storageKeyDeclarations: construction.storageKeyDeclarations
19104
+ });
19105
+ stageConstructedRows(createdValues.slice(staged), ctx);
19106
+ Reflect.set(receiver, key, row.id);
19107
+ invalidateEvaluatorIndexes(ctx, receiver);
19108
+ return true;
19109
+ }
18823
19110
  function touchUnknown(_ins) {
18824
19111
  void _ins;
18825
19112
  }
@@ -19580,13 +19867,7 @@ function evalPointerCore(pointer, scope, ctx, resultUsage = "value") {
19580
19867
  case "staticMember" /* staticMember */:
19581
19868
  return evalStaticMember(pointer.memberId, ctx);
19582
19869
  case "keyOf" /* keyOf */:
19583
- return evalKeyOf(
19584
- pointer.keyOf,
19585
- scope,
19586
- ctx,
19587
- pointer.optional === true,
19588
- pointer.memberId
19589
- );
19870
+ return evalKeyOf(pointer.keyOf, scope, ctx, pointer.optional === true);
19590
19871
  case "operation" /* operation */:
19591
19872
  return evalOperation(pointer.operation, scope, ctx);
19592
19873
  case "function" /* function */:
@@ -20217,7 +20498,6 @@ function readActionWithOwner(pointer, scope, ctx) {
20217
20498
  scope,
20218
20499
  ctx,
20219
20500
  pointer.optional === true,
20220
- pointer.memberId,
20221
20501
  (destination) => {
20222
20502
  owner = destination.receiver;
20223
20503
  }
@@ -21030,7 +21310,7 @@ function isRuntimeSpriteValue(value) {
21030
21310
  const sliceIndex = value.sliceIndex;
21031
21311
  return typeof sliceIndex === "number" && Number.isInteger(sliceIndex) && sliceIndex >= 0;
21032
21312
  }
21033
- function evalKeyOf(keyOf, scope, ctx, optional2 = false, memberId, onDestination) {
21313
+ function evalKeyOf(keyOf, scope, ctx, optional2 = false, onDestination) {
21034
21314
  const receiver = evalPointer(keyOf.pointer, scope, ctx);
21035
21315
  if (optional2 && (receiver === null || receiver === void 0)) {
21036
21316
  return null;
@@ -21089,11 +21369,6 @@ function evalKeyOf(keyOf, scope, ctx, optional2 = false, memberId, onDestination
21089
21369
  if (assetMember.kind === "ok") return assetMember.value;
21090
21370
  const dispatched = dispatchSchemaMember(receiver, k, ctx);
21091
21371
  if (dispatched.kind === "ok") return dispatched.value;
21092
- if (!dispatched.matchedMember && memberId !== void 0) {
21093
- const member = evalMemberById(ctx.vm, memberId);
21094
- const defaultValue = isReadOnlyMember(member) ? readDeclarationDefault(member, ctx) : { matched: false };
21095
- if (defaultValue.matched) return defaultValue.value;
21096
- }
21097
21372
  if (Object.prototype.hasOwnProperty.call(receiver, k)) {
21098
21373
  const at2 = receiver[k];
21099
21374
  return resolveValueIfId(at2, ctx);
@@ -21196,16 +21471,36 @@ function ensureVirtualExpansionIndexed(rows, ctx, existingIndexes) {
21196
21471
  );
21197
21472
  indexes3.indexedVirtualRowSets.add(rows);
21198
21473
  }
21474
+ var constantDeclarationRoots = /* @__PURE__ */ new WeakMap();
21199
21475
  function readDeclarationDefault(member, ctx) {
21200
21476
  if (member?.defaultValue === void 0 || member.defaultValue === null) {
21201
21477
  return { matched: false };
21202
21478
  }
21203
21479
  if (isInitValueContent(member.defaultValue) || isMemberClassBase(member) || isMemberListBase(member) || isMemberDictionaryBase(member)) {
21480
+ const session = ctx.__runtimeSessionValues;
21481
+ let shared;
21482
+ if (session !== void 0) {
21483
+ shared = constantDeclarationRoots.get(session);
21484
+ if (shared === void 0) {
21485
+ shared = /* @__PURE__ */ new Map();
21486
+ constantDeclarationRoots.set(session, shared);
21487
+ }
21488
+ }
21489
+ const known = shared?.get(member.id);
21490
+ if (typeof known === "string" && session?.has(known) === true) {
21491
+ return {
21492
+ matched: true,
21493
+ value: resolveValueIfIdForMember(known, member, ctx)
21494
+ };
21495
+ }
21496
+ const document2 = constructorDefaultValueDocument(ctx, member);
21497
+ const constant = shared !== void 0 && known !== false && (known !== void 0 || isConstantMember(document2, member));
21498
+ if (shared !== void 0 && !constant) shared.set(member.id, false);
21204
21499
  const created = [];
21205
21500
  const closeFrame = pushConstructionFrame(ctx, `${member.name} declaration`);
21206
21501
  try {
21207
21502
  const root = buildDefaultMemberValue({
21208
- document: constructorDefaultValueDocument(ctx, member),
21503
+ document: document2,
21209
21504
  projectId: ctx.vm.project.id,
21210
21505
  member,
21211
21506
  createdValues: created,
@@ -21226,6 +21521,7 @@ function readDeclarationDefault(member, ctx) {
21226
21521
  )
21227
21522
  });
21228
21523
  stageConstructedRows([root, ...created], ctx);
21524
+ if (constant) shared?.set(member.id, root.id);
21229
21525
  return {
21230
21526
  matched: true,
21231
21527
  value: resolveValueIfIdForMember(root.id, member, ctx)
@@ -23342,12 +23638,6 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
23342
23638
  }
23343
23639
  seenSchemaKeys.add(field.schemaKey);
23344
23640
  seenMemberIds.add(field.memberId);
23345
- assertConstructorFieldSlotWritable({
23346
- schemaKey: field.schemaKey,
23347
- settledClassId: classId,
23348
- schemaClassName: schemaClass2.name,
23349
- ctx
23350
- });
23351
23641
  const schemaEntry = schemaByKey.get(field.schemaKey);
23352
23642
  if (schemaEntry === void 0) {
23353
23643
  throw new NSGetterRuntimeError(
@@ -23402,21 +23692,6 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
23402
23692
  }
23403
23693
  return cacheDescriptor({ schemaClass: schemaClass2, fields, instanceEnv, classArguments: classArguments2 });
23404
23694
  }
23405
- function assertConstructorFieldSlotWritable(args) {
23406
- const index = evaluatorSchemaIndex(args.ctx);
23407
- const surfaceEntry = resolvedClassSchemaFromIndexes(
23408
- args.settledClassId,
23409
- index.classesById,
23410
- index.membersById
23411
- ).surfaceByKey.get(args.schemaKey);
23412
- if (surfaceEntry === void 0) return;
23413
- if (isReadOnlyMember(evalMemberById(args.ctx.vm, surfaceEntry.memberId)) !== true) {
23414
- return;
23415
- }
23416
- throw new NSGetterRuntimeError(
23417
- `Constructor field '${args.schemaKey}' on '${args.schemaClassName}' is a read-only declaration member and cannot have an instance value.`
23418
- );
23419
- }
23420
23695
  function validateConstructorFieldSlot(args) {
23421
23696
  const { schemaKey, ctx } = args;
23422
23697
  const rawMember = evalMemberById(ctx.vm, args.memberId);
@@ -23436,6 +23711,11 @@ function validateConstructorFieldSlot(args) {
23436
23711
  `Constructor field '${schemaKey}' on '${args.schemaClassName}' is not a stored concrete member.`
23437
23712
  );
23438
23713
  }
23714
+ if (member.storage === 1 /* Immutable */ && ctx.storedConstructionReplay !== true) {
23715
+ throw new NSGetterRuntimeError(
23716
+ `Constructor field '${schemaKey}' on '${args.schemaClassName}' is Immutable; runtime construction cannot set it.`
23717
+ );
23718
+ }
23439
23719
  const typeInfo = runtimeTypeInfoForMember(
23440
23720
  rawMember,
23441
23721
  args.instanceEnv,
@@ -24315,7 +24595,7 @@ function evaluateBaseInitializerFields(args) {
24315
24595
  )
24316
24596
  );
24317
24597
  const instanceSchema = new Map(
24318
- mergeStoredInstanceSchema(
24598
+ mergeInstanceSurfaceSchema(
24319
24599
  args.constructedClassId,
24320
24600
  ctx.vm.classes,
24321
24601
  ctx.vm.members
@@ -24339,12 +24619,6 @@ function evaluateBaseInitializerFields(args) {
24339
24619
  `Constructor '${record4.id}' settles base member '${field.name}', which the constructed instance does not store.`
24340
24620
  );
24341
24621
  }
24342
- assertConstructorFieldSlotWritable({
24343
- schemaKey: field.name,
24344
- settledClassId: args.constructedClassId,
24345
- schemaClassName: owningClass.name,
24346
- ctx
24347
- });
24348
24622
  const validated = validateConstructorFieldSlot({
24349
24623
  schemaKey: field.name,
24350
24624
  memberId: entry.memberId,
@@ -25727,39 +26001,50 @@ function constructDeclaredClassValueWithinFrame(descriptor, record4, info, scope
25727
26001
  stageConstructedRows(createdValues, ctx);
25728
26002
  bindConstructedDelegateTargets(createdValues, ctx);
25729
26003
  if (record4 !== null) {
25730
- runDeclaredConstructorChain({
25731
- record: record4,
25732
- argumentValues,
25733
- preparedArgumentScopes,
25734
- thisValue: root.value,
25735
- ctx,
25736
- visitedConstructorIds: /* @__PURE__ */ new Set(),
25737
- applyBaseInitializerBlock: (chainRecord, chainArguments, chainThisValue) => {
25738
- const supplied2 = evaluateBaseInitializerFields({
25739
- record: chainRecord,
25740
- argumentValues: chainArguments,
25741
- thisValue: chainThisValue,
25742
- constructedClassId: classId,
25743
- instanceEnv: descriptor.instanceEnv,
25744
- ctx
25745
- });
25746
- if (supplied2.length === 0) return;
25747
- applyConstructorFields({
25748
- supplied: supplied2,
25749
- root,
25750
- rootRecord,
25751
- schemaClass: schemaClass2,
25752
- instanceEnv: descriptor.instanceEnv,
25753
- createdValues,
25754
- createdById: new Map(createdValues.map((row) => [row.id, row])),
25755
- storageKeyDeclarations,
25756
- // §1.5 base blocks are assignments, not omissions: an explicit null
25757
- // clears the slot exactly as a call-site block entry does.
25758
- nullMeansOmit: false,
25759
- ctx
25760
- });
25761
- }
26004
+ const openConstructions = ctx.__executionState?.openConstructions;
26005
+ openConstructions?.set(rootRecord, {
26006
+ createdValues,
26007
+ storageKeyDeclarations
25762
26008
  });
26009
+ try {
26010
+ runDeclaredConstructorChain({
26011
+ record: record4,
26012
+ argumentValues,
26013
+ preparedArgumentScopes,
26014
+ thisValue: root.value,
26015
+ ctx,
26016
+ visitedConstructorIds: /* @__PURE__ */ new Set(),
26017
+ applyBaseInitializerBlock: (chainRecord, chainArguments, chainThisValue) => {
26018
+ const supplied2 = evaluateBaseInitializerFields({
26019
+ record: chainRecord,
26020
+ argumentValues: chainArguments,
26021
+ thisValue: chainThisValue,
26022
+ constructedClassId: classId,
26023
+ instanceEnv: descriptor.instanceEnv,
26024
+ ctx
26025
+ });
26026
+ if (supplied2.length === 0) return;
26027
+ const staged = createdValues.length;
26028
+ applyConstructorFields({
26029
+ supplied: supplied2,
26030
+ root,
26031
+ rootRecord,
26032
+ schemaClass: schemaClass2,
26033
+ instanceEnv: descriptor.instanceEnv,
26034
+ createdValues,
26035
+ createdById: new Map(createdValues.map((row) => [row.id, row])),
26036
+ storageKeyDeclarations,
26037
+ // §1.5 base blocks are assignments, not omissions: an explicit null
26038
+ // clears the slot exactly as a call-site block entry does.
26039
+ nullMeansOmit: false,
26040
+ ctx
26041
+ });
26042
+ stageConstructedRows(createdValues.slice(staged), ctx);
26043
+ }
26044
+ });
26045
+ } finally {
26046
+ openConstructions?.delete(rootRecord);
26047
+ }
25763
26048
  }
25764
26049
  const supplied = evaluateConstructorFields(descriptor, scope, ctx);
25765
26050
  try {
@@ -27212,7 +27497,7 @@ function createStoredValuePlacementTraversal(args, trackReferences = false) {
27212
27497
  const storedSchema = (classId) => {
27213
27498
  const cached = storedSchemaByClassId.get(classId);
27214
27499
  if (cached !== void 0) return cached;
27215
- const schema = mergeStoredInstanceSchema(
27500
+ const schema = mergeInstanceSurfaceSchema(
27216
27501
  classId,
27217
27502
  args.classes,
27218
27503
  args.members
@@ -27909,7 +28194,7 @@ function collectSoftOwnedConstructorArgumentValueIds(index, ownerValueId, preser
27909
28194
  const effectiveClassId = row.classId ?? (typeInfo.type === 7 /* Class */ ? typeInfo.classId : void 0);
27910
28195
  if (effectiveClassId === void 0) return;
27911
28196
  const env = rowGenericEnvironment(index.document, row);
27912
- const merged = mergeStoredInstanceSchema(
28197
+ const merged = mergeInstanceSurfaceSchema(
27913
28198
  effectiveClassId,
27914
28199
  index.document.classes,
27915
28200
  index.document.members
@@ -30771,7 +31056,7 @@ function resolveVirtualInstanceGraph(args) {
30771
31056
  classId,
30772
31057
  args.document.classes,
30773
31058
  args.document.members
30774
- ).stored;
31059
+ ).surface;
30775
31060
  for (const entry of schema) {
30776
31061
  const childPath = appendVirtualValuePath(pathKey, {
30777
31062
  kind: "class",
@@ -31522,7 +31807,7 @@ function indexExpansion(args) {
31522
31807
  classId,
31523
31808
  args.document.classes,
31524
31809
  args.document.members
31525
- ).stored;
31810
+ ).surface;
31526
31811
  for (const entry of schema) {
31527
31812
  const childId = record4[entry.schemaKey];
31528
31813
  const childMember = membersById.get(entry.memberId);
@@ -34344,6 +34629,12 @@ var WRITE_TARGET_DESCRIPTIONS = {
34344
34629
  unknown: "something other than `this` or a local"
34345
34630
  };
34346
34631
  var ON_CHANGED_OPERATIONS_ERROR = "OnChanged supports only '+=', '-=', and Clear().";
34632
+ function immutableRuntimeConstructionError(name) {
34633
+ return `Runtime construction cannot set Immutable member '${name}'; it reads its declared initializer.`;
34634
+ }
34635
+ function readonlyWriteError(name) {
34636
+ return `Member '${name}' is readonly; set it in its initializer, a constructor, or an object initializer.`;
34637
+ }
34347
34638
  var FALLTHROUGH_LABELS = {
34348
34639
  function: "NSFunction",
34349
34640
  getter: "getter",
@@ -36087,7 +36378,12 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
36087
36378
  scope
36088
36379
  );
36089
36380
  const target = statement.op === "=" ? { ...resolvedTarget, type: storageType } : resolvedTarget;
36090
- const writability = local?.writability ?? target.writability;
36381
+ const initSlot = target.initWritability !== void 0 ? {
36382
+ pointer: target.pointer,
36383
+ initWritability: target.initWritability
36384
+ } : target.readonlyCollection;
36385
+ const initializing = initSlot !== void 0 && this.constructsSlot(initSlot.pointer, assignmentContext);
36386
+ const writability = initializing ? initSlot.initWritability : local?.writability ?? target.writability;
36091
36387
  if (target.symbol?.computed === true && target.symbol.writable !== true) {
36092
36388
  throw new CompileError(
36093
36389
  `Cannot assign to NeoScript property '${target.symbol.name}' because it does not declare a setter.`,
@@ -36100,9 +36396,15 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
36100
36396
  statement.pos
36101
36397
  );
36102
36398
  }
36103
- if (target.symbol?.readonlyDeclaration === true) {
36399
+ if (target.symbol?.readonlyDeclaration === true && !initializing) {
36104
36400
  throw new CompileError(
36105
- `Member '${target.symbol.name}' is readonly and can only be changed through its class default.`,
36401
+ readonlyWriteError(target.symbol.name),
36402
+ statement.pos
36403
+ );
36404
+ }
36405
+ if (target.readonlyCollection !== void 0 && !initializing) {
36406
+ throw new CompileError(
36407
+ readonlyWriteError(target.readonlyCollection.name),
36106
36408
  statement.pos
36107
36409
  );
36108
36410
  }
@@ -36121,7 +36423,15 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
36121
36423
  statement.pos
36122
36424
  );
36123
36425
  }
36124
- if (writability === "immutable" /* Immutable */ && assignmentContext !== "initializer") {
36426
+ if (writability === "immutable" /* Immutable */ && assignmentContext === "initializer") {
36427
+ throw new CompileError(
36428
+ immutableRuntimeConstructionError(
36429
+ target.symbol?.name ?? this.describe(target.type)
36430
+ ),
36431
+ statement.pos
36432
+ );
36433
+ }
36434
+ if (writability === "immutable" /* Immutable */) {
36125
36435
  throw new CompileError(
36126
36436
  "Cannot assign because the target's effective storage is immutable.",
36127
36437
  statement.pos
@@ -37016,8 +37326,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
37016
37326
  );
37017
37327
  }
37018
37328
  const declared = declaredTarget?.declaredConstructors ?? [];
37019
- const requiredConstructor = neoScriptRequiredConstructor(declaredTarget);
37020
- const generatedPositionalCall = requiredConstructor === null && declaredTarget?.constructorSignature !== void 0 && expression.argumentNames === void 0 && callHasPositionalArguments(expression);
37329
+ const generatedPositionalCall = declaredTarget !== void 0 && isGeneratedPositionalCall(declaredTarget, expression);
37021
37330
  if (!generatedPositionalCall && (declared.length > 0 || this.context.storedConstructionReplay === true && expression.args.length === 0)) {
37022
37331
  return this.resolveDeclaredConstructor(
37023
37332
  className,
@@ -38510,10 +38819,12 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38510
38819
  } : {}
38511
38820
  };
38512
38821
  }
38513
- const writability = this.memberWritability(member, receiver);
38514
- const entryWritability = member.lookup ? this.lookupEntryWritability(member, receiver) : void 0;
38822
+ const readonlySlot = member.readonlyDeclaration === true;
38823
+ const storageWritability = this.memberWritability(member, receiver);
38824
+ const writability = readonlySlot ? "readOnly" /* ReadOnly */ : storageWritability;
38825
+ const entryWritability = member.lookup ? this.lookupEntryWritability(member, receiver) : readonlySlot ? storageWritability : void 0;
38515
38826
  const userData = this.memberUserData(member, receiver);
38516
- const entryUserData = member.lookup ? this.lookupEntryUserData(member) : false;
38827
+ const entryUserData = member.lookup ? this.lookupEntryUserData(member) : readonlySlot && userData;
38517
38828
  const lookupWire = member.lookup?.multiselect === true && memberType2.kind === "set" ? {
38518
38829
  type: 9 /* Lookup */,
38519
38830
  required: !isNullable(memberType2),
@@ -38536,6 +38847,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38536
38847
  ...writability ? { writability } : {},
38537
38848
  ...lookupWire ? { wireType: lookupWire } : {},
38538
38849
  ...entryWritability ? { entryWritability } : {},
38850
+ ...readonlySlot && storageWritability ? { initWritability: storageWritability } : {},
38539
38851
  userData,
38540
38852
  entryUserData
38541
38853
  };
@@ -38627,7 +38939,8 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38627
38939
  if (member.writability && !member.lookup) {
38628
38940
  return toWritability(member.writability, this.writesUserData);
38629
38941
  }
38630
- if (!member.writable) return void 0;
38942
+ if (!member.writable && member.readonlyDeclaration !== true)
38943
+ return void 0;
38631
38944
  if (!member.lookup) {
38632
38945
  return member.writability ? toWritability(member.writability, this.writesUserData) : receiver.entryWritability ?? receiver.writability ?? "save" /* Save */;
38633
38946
  }
@@ -38719,6 +39032,11 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38719
39032
  writability: "readOnly" /* ReadOnly */
38720
39033
  };
38721
39034
  }
39035
+ const readonlyCollection = receiver.symbol?.readonlyDeclaration === true && receiver.initWritability !== void 0 ? {
39036
+ name: receiver.symbol.name,
39037
+ pointer: receiver.pointer,
39038
+ initWritability: receiver.initWritability
39039
+ } : void 0;
38722
39040
  let keyType;
38723
39041
  let valueType;
38724
39042
  let resolvedIndex;
@@ -38735,7 +39053,10 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38735
39053
  type: nullPropagating ? { ...receiver.type.elementType, nullable: true } : receiver.type.elementType,
38736
39054
  ...nullPropagating ? { optionalChainType: receiver.type.elementType } : {},
38737
39055
  ...receiver.writability ? { writability: receiver.writability } : {},
38738
- ...receiver.userData ? { userData: true } : {}
39056
+ ...receiver.entryWritability ? { entryWritability: receiver.entryWritability } : {},
39057
+ ...receiver.userData ? { userData: true } : {},
39058
+ ...receiver.entryUserData ? { entryUserData: true } : {},
39059
+ ...readonlyCollection ? { readonlyCollection } : {}
38739
39060
  };
38740
39061
  }
38741
39062
  keyType = { kind: "primitive", name: "int" };
@@ -38770,7 +39091,10 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38770
39091
  type: nullPropagating ? { ...valueType, nullable: true } : valueType,
38771
39092
  ...nullPropagating ? { optionalChainType: valueType } : {},
38772
39093
  ...receiver.writability ? { writability: receiver.writability } : {},
38773
- ...receiver.userData ? { userData: true } : {}
39094
+ ...receiver.entryWritability ? { entryWritability: receiver.entryWritability } : {},
39095
+ ...receiver.userData ? { userData: true } : {},
39096
+ ...receiver.entryUserData ? { entryUserData: true } : {},
39097
+ ...readonlyCollection ? { readonlyCollection } : {}
38774
39098
  };
38775
39099
  }
38776
39100
  resolveDictionaryKey(expectedKey, keyAst, scope, pos, requireNonOptional, dictionaryLiteral = false) {
@@ -39658,7 +39982,17 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39658
39982
  };
39659
39983
  }
39660
39984
  resolveExecutableObjectInitializer(schemaClass2, expression, scope, expected) {
39661
- const constructed = this.resolveExpression(
39985
+ const settling = this.generatedConstructorSettlingEntries(
39986
+ schemaClass2,
39987
+ expression
39988
+ );
39989
+ const constructed = settling.length > 0 ? this.resolveClassConstructor(
39990
+ schemaClass2.name,
39991
+ { ...expression, initializer: settling },
39992
+ scope,
39993
+ expression.pos,
39994
+ expected
39995
+ ) : this.resolveExpression(
39662
39996
  { ...expression, className: schemaClass2.name, initializer: [] },
39663
39997
  scope,
39664
39998
  expected
@@ -39684,6 +40018,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39684
40018
  const assignments = [];
39685
40019
  const seen = /* @__PURE__ */ new Set();
39686
40020
  for (const entry of expression.initializer ?? []) {
40021
+ if (settling.includes(entry)) continue;
39687
40022
  const key = entry.name.toLowerCase();
39688
40023
  if (seen.has(key)) {
39689
40024
  throw new CompileError(
@@ -39727,6 +40062,23 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39727
40062
  writeRoot: "local"
39728
40063
  };
39729
40064
  }
40065
+ /** Block entries naming a required parameter the positional arguments skip. */
40066
+ generatedConstructorSettlingEntries(schemaClass2, expression) {
40067
+ const signature = schemaClass2.constructorSignature;
40068
+ if (signature === void 0) return [];
40069
+ const generated = isGeneratedPositionalCall(schemaClass2, expression) || (schemaClass2.declaredConstructors?.length ?? 0) === 0 && expression.argumentNames === void 0;
40070
+ if (!generated) return [];
40071
+ const required = new Set(
40072
+ requiredMembersAfterArguments(
40073
+ schemaClass2,
40074
+ signature.parameters,
40075
+ expression.args.length
40076
+ ).map((name) => name.toLowerCase())
40077
+ );
40078
+ return (expression.initializer ?? []).filter(
40079
+ (entry) => required.has(entry.name.toLowerCase())
40080
+ );
40081
+ }
39730
40082
  resolveClassConstructor(className, expression, scope, pos, expected) {
39731
40083
  const schemaClass2 = this.project.typeByName.get(className);
39732
40084
  if (!schemaClass2 || schemaClass2.kind !== "class") {
@@ -39748,7 +40100,13 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39748
40100
  pos
39749
40101
  );
39750
40102
  }
39751
- const signature = schemaClass2.constructorSignature ?? (replayingStoredConstruction ? schemaClass2.storedConstructionReplaySignature : void 0);
40103
+ if (schemaClass2.constructorUnavailableReason === "requiredImmutableMember" && !replayingStoredConstruction) {
40104
+ throw new CompileError(
40105
+ `Cannot construct Class '${className}' at runtime; it has a required Immutable member, which only authored values can supply.`,
40106
+ pos
40107
+ );
40108
+ }
40109
+ const signature = replayingStoredConstruction ? schemaClass2.storedConstructionReplaySignature ?? schemaClass2.constructorSignature : schemaClass2.constructorSignature;
39752
40110
  if (!signature) {
39753
40111
  const open = (schemaClass2.typeParameters?.length ?? 0) > 0;
39754
40112
  throw new CompileError(
@@ -39781,16 +40139,21 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39781
40139
  pos
39782
40140
  );
39783
40141
  }
39784
- const requiredCount = signature.parameters.filter(
39785
- (parameter3) => parameter3.required
39786
- ).length;
39787
- if (expression.argumentNames === void 0 && argumentsList2.length < requiredCount) {
40142
+ const blockKeys = new Set(
40143
+ (expression.initializer ?? []).map((entry) => entry.name.toLowerCase())
40144
+ );
40145
+ const unsettled = requiredMembersAfterArguments(
40146
+ schemaClass2,
40147
+ parameters,
40148
+ argumentsList2.length
40149
+ ).filter((name) => !blockKeys.has(name.toLowerCase()));
40150
+ if (unsettled.length > 0) {
39788
40151
  throw new CompileError(
39789
- `${className} constructor requires ${requiredCount} argument${requiredCount === 1 ? "" : "s"} but got ${argumentsList2.length}.`,
40152
+ `${className} construction does not set required ${unsettled.length === 1 ? "member" : "members"} ${unsettled.map((name) => `'${name}'`).join(", ")}. Pass each as a constructor argument or set it in an initializer block.`,
39790
40153
  pos
39791
40154
  );
39792
40155
  }
39793
- if (expression.argumentNames === void 0 && argumentsList2.length > parameters.length) {
40156
+ if (argumentsList2.length > parameters.length) {
39794
40157
  throw new CompileError(
39795
40158
  `${className} constructor accepts at most ${parameters.length} argument${parameters.length === 1 ? "" : "s"} but got ${argumentsList2.length}.`,
39796
40159
  pos
@@ -40106,9 +40469,9 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
40106
40469
  entry.pos
40107
40470
  );
40108
40471
  }
40109
- if (member.readonlyDeclaration === true) {
40472
+ if (member.writability === "immutable" && this.context.storedConstructionReplay !== true) {
40110
40473
  throw new CompileError(
40111
- `'${schemaClass2.name}.${member.name}' is readonly and can only be changed through its class default.`,
40474
+ immutableRuntimeConstructionError(member.name),
40112
40475
  entry.pos
40113
40476
  );
40114
40477
  }
@@ -41802,7 +42165,11 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
41802
42165
  pos
41803
42166
  );
41804
42167
  }
41805
- const writability = receiver.writability;
42168
+ const initializing = receiver.initWritability !== void 0 && this.constructsSlot(receiver.pointer, "ordinary");
42169
+ if (receiver.symbol?.readonlyDeclaration === true && !initializing) {
42170
+ throw new CompileError(readonlyWriteError(receiver.symbol.name), pos);
42171
+ }
42172
+ const writability = initializing ? receiver.initWritability : receiver.writability;
41806
42173
  const readOnlyCollection = (receiver.type.kind === "list" || receiver.type.kind === "dictionary" || receiver.type.kind === "set") && receiver.type.readOnly === true;
41807
42174
  if (!writability || writability === "readOnly" /* ReadOnly */ || writability === "immutable" /* Immutable */ || readOnlyCollection) {
41808
42175
  if (receiver.indexDefinition) {
@@ -41895,7 +42262,11 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
41895
42262
  pos
41896
42263
  );
41897
42264
  }
41898
- const writability = receiver.writability;
42265
+ const initializing = receiver.initWritability !== void 0 && this.constructsSlot(receiver.pointer, "ordinary");
42266
+ if (receiver.symbol?.readonlyDeclaration === true && !initializing) {
42267
+ throw new CompileError(readonlyWriteError(receiver.symbol.name), pos);
42268
+ }
42269
+ const writability = initializing ? receiver.initWritability : receiver.writability;
41899
42270
  if (writability === "immutable" /* Immutable */) {
41900
42271
  throw new CompileError(
41901
42272
  "Cannot clear an action whose effective storage is immutable.",
@@ -42287,6 +42658,19 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
42287
42658
  pos
42288
42659
  );
42289
42660
  }
42661
+ /**
42662
+ * Whether a write to this member slot happens while its instance is
42663
+ * constructed: an object initializer entry, or `this.X` directly in a
42664
+ * constructor body.
42665
+ */
42666
+ constructsSlot(pointer, assignmentContext) {
42667
+ if (assignmentContext === "initializer") return true;
42668
+ if (this.context.kind !== "constructor") return false;
42669
+ if (this.lambdaDepth > 0) return false;
42670
+ if (pointer.type !== "keyOf" /* KeyOf */) return false;
42671
+ const receiver = pointer.keyOf.pointer;
42672
+ return receiver.type === "variable" /* Variable */ && receiver.variableId === this.thisVariable.id;
42673
+ }
42290
42674
  writeTargetRoot(pointer, scope) {
42291
42675
  switch (pointer.type) {
42292
42676
  case "variable" /* Variable */:
@@ -42708,6 +43092,20 @@ function variable(id, type, pointer, project) {
42708
43092
  }
42709
43093
  };
42710
43094
  }
43095
+ function isGeneratedPositionalCall(target, expression) {
43096
+ return neoScriptRequiredConstructor(target) === null && target.constructorSignature !== void 0 && expression.argumentNames === void 0 && callHasPositionalArguments(expression);
43097
+ }
43098
+ function requiredMembersAfterArguments(schemaClass2, parameters, positionalCount) {
43099
+ const names = [];
43100
+ for (const parameter3 of parameters.slice(positionalCount)) {
43101
+ if (!parameter3.required) continue;
43102
+ const member = schemaClass2.members.find(
43103
+ (candidate) => candidate.id === parameter3.memberId
43104
+ );
43105
+ names.push(member?.name ?? parameter3.name);
43106
+ }
43107
+ return names;
43108
+ }
42711
43109
  function callHasPositionalArguments(expression) {
42712
43110
  return expression.args.some(
42713
43111
  (_, index) => (expression.argumentNames?.[index] ?? null) === null
@@ -44463,31 +44861,29 @@ function attachConstructorSignature(type, environment) {
44463
44861
  for (const binding of genericEnvironment.values()) {
44464
44862
  if (binding.kind === "unbound") return type;
44465
44863
  }
44466
- const constructorSignature2 = buildNeoScriptConstructorSignature(
44467
- type.id,
44468
- type.members,
44469
- (memberId) => {
44470
- const declarationMember = environment.members.get(memberId);
44471
- if (declarationMember?.isReadOnly === true) return null;
44472
- const member = effectiveConstructorMember(
44473
- memberId,
44474
- genericEnvironment,
44475
- environment
44476
- );
44477
- return member ? {
44478
- required: boolean(member.required, `member ${memberId}.required`),
44479
- defaultValue: member.defaultValue
44480
- } : null;
44481
- }
44482
- );
44483
- if (resolvedAllowedStorage(type.id, environment) === "immutable") {
44484
- return {
44485
- ...type,
44486
- storedConstructionReplaySignature: constructorSignature2,
44487
- constructorUnavailableReason: "immutableOnly"
44488
- };
44489
- }
44490
- return { ...type, constructorSignature: constructorSignature2 };
44864
+ return {
44865
+ ...type,
44866
+ ...buildNeoScriptConstructionSignatures(
44867
+ type.id,
44868
+ type.members,
44869
+ (memberId) => {
44870
+ const member = effectiveConstructorMember(
44871
+ memberId,
44872
+ genericEnvironment,
44873
+ environment
44874
+ );
44875
+ return member ? {
44876
+ required: boolean(member.required, `member ${memberId}.required`),
44877
+ defaultValue: member.defaultValue,
44878
+ immutable: declaredStorage(
44879
+ environment.members.get(memberId),
44880
+ environment.members
44881
+ ) === "immutable"
44882
+ } : null;
44883
+ },
44884
+ resolvedAllowedStorage(type.id, environment) === "immutable"
44885
+ )
44886
+ };
44491
44887
  }
44492
44888
  function resolvedAllowedStorage(classId, environment) {
44493
44889
  const visited = /* @__PURE__ */ new Set();
@@ -44570,6 +44966,20 @@ function inferRootMemberIds(members) {
44570
44966
  user: unique("user")
44571
44967
  };
44572
44968
  }
44969
+ function declaredStorage(member, members) {
44970
+ const seen = /* @__PURE__ */ new Set();
44971
+ let current = member;
44972
+ while (current !== void 0 && !seen.has(current)) {
44973
+ seen.add(current);
44974
+ const storage = current.storage;
44975
+ if (storage === "immutable" || storage === "save" || storage === "session" || storage === "writable" || storage === "user") {
44976
+ return storage;
44977
+ }
44978
+ if (typeof current.overrideOf !== "string") return null;
44979
+ current = members.get(current.overrideOf);
44980
+ }
44981
+ return null;
44982
+ }
44573
44983
  function effectiveMemberWritability(members, classes, roots) {
44574
44984
  const memberById = /* @__PURE__ */ new Map();
44575
44985
  for (const member of members) {
@@ -44583,16 +44993,6 @@ function effectiveMemberWritability(members, classes, roots) {
44583
44993
  classById.set(schemaClass2.id, schemaClass2);
44584
44994
  }
44585
44995
  }
44586
- const declaredStorage = (memberId, seen = /* @__PURE__ */ new Set()) => {
44587
- if (seen.has(memberId)) return null;
44588
- seen.add(memberId);
44589
- const member = memberById.get(memberId);
44590
- if (!member) return null;
44591
- if (member.storage === "immutable" || member.storage === "save" || member.storage === "session" || member.storage === "writable" || member.storage === "user") {
44592
- return member.storage;
44593
- }
44594
- return typeof member.overrideOf === "string" ? declaredStorage(member.overrideOf, seen) : null;
44595
- };
44596
44996
  const classExtends = (candidateId, baseId) => {
44597
44997
  const seen = /* @__PURE__ */ new Set();
44598
44998
  let currentId = candidateId;
@@ -44658,7 +45058,7 @@ function effectiveMemberWritability(members, classes, roots) {
44658
45058
  }
44659
45059
  if (typeof roots.user === "string") rootStorage.set(roots.user, "user");
44660
45060
  for (const [memberId, member] of memberById) {
44661
- const declared = rootStorage.get(memberId) ?? declaredStorage(memberId);
45061
+ const declared = rootStorage.get(memberId) ?? declaredStorage(member, memberById);
44662
45062
  if (declared === "writable") {
44663
45063
  writable.add(memberId);
44664
45064
  continue;
@@ -44816,10 +45216,9 @@ function memberSymbol(member, schemaKey, environment, field) {
44816
45216
  };
44817
45217
  }
44818
45218
  const writable = isReadOnly ? false : kind === "computed" ? computedHasSetter(member, field) : true;
44819
- const storage = typeof member.storage === "string" ? member.storage : void 0;
45219
+ const storage = declaredStorage(member, environment.members) ?? void 0;
44820
45220
  let writability;
44821
- if (!writable) writability = "readOnly";
44822
- else if (kind === "computed") writability = "setter";
45221
+ if (kind === "computed") writability = writable ? "setter" : "readOnly";
44823
45222
  else {
44824
45223
  writability = declaredStorageWritability(
44825
45224
  storage,
@@ -46753,35 +47152,7 @@ function constructorSignature(schemaClass2, members, context, genericEnvironment
46753
47152
  if (!isClosedClass(schemaClass2.id, context.vm.classes)) {
46754
47153
  return {};
46755
47154
  }
46756
- if (resolveAllowedStorage(schemaClass2.id, context.vm.classes) === 1 /* Immutable */) {
46757
- const signature2 = buildNeoScriptConstructorSignature(
46758
- schemaClass2.id,
46759
- members,
46760
- (memberId) => {
46761
- const record4 = analyzerMemberById(context, memberId);
46762
- if (!record4) return null;
46763
- try {
46764
- const resolved = substituteMember(
46765
- record4,
46766
- genericEnvironment,
46767
- context.vm.members,
46768
- resolveAnalyzerMember(context, record4)
46769
- );
46770
- return {
46771
- required: isRequiredMember(resolved),
46772
- defaultValue: "defaultValue" in resolved ? resolved.defaultValue : void 0
46773
- };
46774
- } catch {
46775
- return null;
46776
- }
46777
- }
46778
- );
46779
- return {
46780
- storedConstructionReplaySignature: signature2,
46781
- constructorUnavailableReason: "immutableOnly"
46782
- };
46783
- }
46784
- const signature = buildNeoScriptConstructorSignature(
47155
+ return buildNeoScriptConstructionSignatures(
46785
47156
  schemaClass2.id,
46786
47157
  members,
46787
47158
  (memberId) => {
@@ -46796,14 +47167,15 @@ function constructorSignature(schemaClass2, members, context, genericEnvironment
46796
47167
  );
46797
47168
  return {
46798
47169
  required: isRequiredMember(resolved),
46799
- defaultValue: "defaultValue" in resolved ? resolved.defaultValue : void 0
47170
+ defaultValue: "defaultValue" in resolved ? resolved.defaultValue : void 0,
47171
+ immutable: declaredMemberStorage(record4.id, context.vm.members) === 1 /* Immutable */
46800
47172
  };
46801
47173
  } catch {
46802
47174
  return null;
46803
47175
  }
46804
- }
47176
+ },
47177
+ resolveAllowedStorage(schemaClass2.id, context.vm.classes) === 1 /* Immutable */
46805
47178
  );
46806
- return { constructorSignature: signature };
46807
47179
  }
46808
47180
  function declaredConstructors(schemaClass2, context) {
46809
47181
  const requiredConstructorId2 = schemaClass2.requiredConstructorId;
@@ -46888,6 +47260,7 @@ function memberToSymbol(record4, schemaKey, containingClass, ownerClassId, index
46888
47260
  ...scriptDefinitionLocations2(record4.id, context),
46889
47261
  documentation: getOptionalString(resolved, "docsText") ?? `${record4.name} (${record4.id})`,
46890
47262
  writable: !isReadOnlyMember(record4),
47263
+ ...isReadOnlyMember(record4) ? { readonlyDeclaration: true } : {},
46891
47264
  ...isStaticMember(record4) === true ? { static: true } : {},
46892
47265
  ...symbolWritability(
46893
47266
  record4.id,
@@ -49489,7 +49862,7 @@ async function loadMemberDefaultValueClosure(args) {
49489
49862
  const classId = source.classId ?? member.classId;
49490
49863
  classFields = classSchemas.get(classId);
49491
49864
  if (classFields === void 0) {
49492
- classFields = mergeStoredInstanceSchema(classId, classes, members);
49865
+ classFields = mergeInstanceSurfaceSchema(classId, classes, members);
49493
49866
  classSchemas.set(classId, classFields);
49494
49867
  }
49495
49868
  env = withStamp(
@@ -50777,6 +51150,11 @@ var BODY_CHILD_PAYLOAD = canonicalJsonStringify({
50777
51150
  });
50778
51151
 
50779
51152
  // ../src/models/project/world-content-sidecar-validation.ts
51153
+ var TILE_CLASS_LEVEL_KEYS = worldSystemSchemaFieldsForKind(
51154
+ NeoWorldSystemClassKind.Tile
51155
+ ).flatMap(
51156
+ (field) => field.mutability === 1 /* ReadOnly */ ? [field.schemaKey] : []
51157
+ );
50780
51158
  var WORLD_PLACEMENT_ASSET_KIND = /* @__PURE__ */ new Map([[NeoWorldSystemClassKind.Object, NeoWorldSystemClassKind.Object]]);
50781
51159
 
50782
51160
  // ../src/database/general-function-call-ir-source-recompile.ts
@@ -50794,7 +51172,7 @@ var STRING_TYPE_INFO = {
50794
51172
  };
50795
51173
 
50796
51174
  // ../src/database/project-version-whole-graph-validation.ts
50797
- import { ConvexError as ConvexError4 } from "convex/values";
51175
+ import { ConvexError as ConvexError3 } from "convex/values";
50798
51176
 
50799
51177
  // ../src/models/exports/unity-static-members.ts
50800
51178
  var nativePatternMembers = new Set(
@@ -50802,7 +51180,6 @@ var nativePatternMembers = new Set(
50802
51180
  );
50803
51181
 
50804
51182
  // ../convex/projectInterfaceValidation.ts
50805
- import { ConvexError as ConvexError3 } from "convex/values";
50806
51183
  var MEMBER_REQUIREMENT_KINDS = [
50807
51184
  0 /* Optional */,
50808
51185
  1 /* Required */
@@ -55720,7 +56097,7 @@ var SPECIALIZED_RELATION_KINDS = /* @__PURE__ */ new Set([
55720
56097
 
55721
56098
  // ../packages/manifest/schema-contract/registry.mjs
55722
56099
  var PROJECT_SCHEMA_CONTRACT = Object.freeze({
55723
- cliVersion: "0.75.2",
56100
+ cliVersion: "0.76.1",
55724
56101
  projectFileUploadBatchSize: 32,
55725
56102
  documentRecords: {
55726
56103
  member: {
@@ -57398,7 +57775,7 @@ function buildRootValue(document2, lookups) {
57398
57775
  var MAX_SOURCE_BYTES = 32 * 1024 * 1024;
57399
57776
 
57400
57777
  // ../src/database/client-commit-submit.ts
57401
- import { ConvexError as ConvexError5 } from "convex/values";
57778
+ import { ConvexError as ConvexError4 } from "convex/values";
57402
57779
 
57403
57780
  // ../src/common/client-commit-transport.ts
57404
57781
  var INLINE_COMMIT_MAX_PAYLOAD_BYTES = 512 * 1024;
@@ -57482,7 +57859,7 @@ var WORLD_OBJECT_CONTRACT_WORLD_KINDS = /* @__PURE__ */ new Set([
57482
57859
  ]);
57483
57860
 
57484
57861
  // ../src/models/exports/unity-codegen-revision.ts
57485
- var UNITY_CODEGEN_REVISION = "e4a632a177c87244e19da71c9840b8007735773ae5f81578f58ce246ec6cb03d";
57862
+ var UNITY_CODEGEN_REVISION = "ac7f9812e3b16cc37d09ba5006316dda6bac23884c83b368a10880bc3f2c765b";
57486
57863
 
57487
57864
  // src/export-cache.ts
57488
57865
  var CACHE_BUILD = JSON.stringify([