@neocompose/cli 0.76.2 → 0.77.0

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.
@@ -879,6 +879,351 @@ var require_ignore = __commonJS({
879
879
  // src/test-worker.ts
880
880
  import { parentPort } from "node:worker_threads";
881
881
 
882
+ // ../node_modules/uuid/dist-node/regex.js
883
+ var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
884
+
885
+ // ../node_modules/uuid/dist-node/validate.js
886
+ function validate(uuid) {
887
+ return typeof uuid === "string" && regex_default.test(uuid);
888
+ }
889
+ var validate_default = validate;
890
+
891
+ // ../node_modules/uuid/dist-node/parse.js
892
+ function parse(uuid) {
893
+ if (!validate_default(uuid)) {
894
+ throw TypeError("Invalid UUID");
895
+ }
896
+ let v;
897
+ return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, v >>> 16 & 255, v >>> 8 & 255, v & 255, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255, v / 4294967296 & 255, v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255);
898
+ }
899
+ var parse_default = parse;
900
+
901
+ // ../node_modules/uuid/dist-node/stringify.js
902
+ var byteToHex = [];
903
+ for (let i = 0; i < 256; ++i) {
904
+ byteToHex.push((i + 256).toString(16).slice(1));
905
+ }
906
+ function unsafeStringify(arr, offset = 0) {
907
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
908
+ }
909
+
910
+ // ../node_modules/uuid/dist-node/rng.js
911
+ var rnds8 = new Uint8Array(16);
912
+ function rng() {
913
+ return crypto.getRandomValues(rnds8);
914
+ }
915
+
916
+ // ../node_modules/uuid/dist-node/v35.js
917
+ function stringToBytes(str) {
918
+ str = unescape(encodeURIComponent(str));
919
+ const bytes = new Uint8Array(str.length);
920
+ for (let i = 0; i < str.length; ++i) {
921
+ bytes[i] = str.charCodeAt(i);
922
+ }
923
+ return bytes;
924
+ }
925
+ var DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
926
+ var URL2 = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
927
+ function v35(version, hash, value, namespace, buf, offset) {
928
+ const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
929
+ const namespaceBytes = typeof namespace === "string" ? parse_default(namespace) : namespace;
930
+ if (typeof namespace === "string") {
931
+ namespace = parse_default(namespace);
932
+ }
933
+ if (namespace?.length !== 16) {
934
+ throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
935
+ }
936
+ let bytes = new Uint8Array(16 + valueBytes.length);
937
+ bytes.set(namespaceBytes);
938
+ bytes.set(valueBytes, namespaceBytes.length);
939
+ bytes = hash(bytes);
940
+ bytes[6] = bytes[6] & 15 | version;
941
+ bytes[8] = bytes[8] & 63 | 128;
942
+ if (buf) {
943
+ offset ??= 0;
944
+ if (offset < 0 || offset + 16 > buf.length) {
945
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
946
+ }
947
+ for (let i = 0; i < 16; ++i) {
948
+ buf[offset + i] = bytes[i];
949
+ }
950
+ return buf;
951
+ }
952
+ return unsafeStringify(bytes);
953
+ }
954
+
955
+ // ../node_modules/uuid/dist-node/v4.js
956
+ function v4(options, buf, offset) {
957
+ if (!buf && !options && crypto.randomUUID) {
958
+ return crypto.randomUUID();
959
+ }
960
+ return _v4(options, buf, offset);
961
+ }
962
+ function _v4(options, buf, offset) {
963
+ options = options || {};
964
+ const rnds = options.random ?? options.rng?.() ?? rng();
965
+ if (rnds.length < 16) {
966
+ throw new Error("Random bytes length must be >= 16");
967
+ }
968
+ rnds[6] = rnds[6] & 15 | 64;
969
+ rnds[8] = rnds[8] & 63 | 128;
970
+ if (buf) {
971
+ offset = offset || 0;
972
+ if (offset < 0 || offset + 16 > buf.length) {
973
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
974
+ }
975
+ for (let i = 0; i < 16; ++i) {
976
+ buf[offset + i] = rnds[i];
977
+ }
978
+ return buf;
979
+ }
980
+ return unsafeStringify(rnds);
981
+ }
982
+ var v4_default = v4;
983
+
984
+ // ../node_modules/uuid/dist-node/sha1.js
985
+ import { createHash } from "node:crypto";
986
+ function sha1(bytes) {
987
+ if (Array.isArray(bytes)) {
988
+ bytes = Buffer.from(bytes);
989
+ } else if (typeof bytes === "string") {
990
+ bytes = Buffer.from(bytes, "utf8");
991
+ }
992
+ return createHash("sha1").update(bytes).digest();
993
+ }
994
+ var sha1_default = sha1;
995
+
996
+ // ../node_modules/uuid/dist-node/v5.js
997
+ function v5(value, namespace, buf, offset) {
998
+ return v35(80, sha1_default, value, namespace, buf, offset);
999
+ }
1000
+ v5.DNS = DNS;
1001
+ v5.URL = URL2;
1002
+ var v5_default = v5;
1003
+
1004
+ // ../packages/models/src/core/world-system-kinds.generated.ts
1005
+ var NeoWorldSystemClassKind = {
1006
+ CellPattern: "cellPattern",
1007
+ TileGrid: "tileGrid",
1008
+ SortingLayer: "sortingLayer",
1009
+ TileLayer: "tileLayer",
1010
+ ObjectLayer: "objectLayer",
1011
+ Tile: "tile",
1012
+ ObjectBase: "objectBase",
1013
+ ObjectCollider: "objectCollider",
1014
+ SortingGroup: "sortingGroup",
1015
+ LayerGroupBase: "layerGroupBase",
1016
+ SpriteObject: "spriteObject",
1017
+ PlacementTile: "placementTile",
1018
+ TileLayerLink: "tileLayerLink",
1019
+ ObjectLayerLink: "objectLayerLink",
1020
+ Object: "object",
1021
+ SmartTile: "smartTile",
1022
+ SmartTileRule: "smartTileRule",
1023
+ SmartTileNeighbor: "smartTileNeighbor",
1024
+ AnimationFrameBase: "animationFrameBase",
1025
+ AnimationClip: "animationClip",
1026
+ AnimationFrame: "animationFrame",
1027
+ AnimationSegmentFrame: "animationSegmentFrame",
1028
+ AnimationSegment: "animationSegment",
1029
+ SpriteAnimationSegment: "spriteAnimationSegment",
1030
+ AnimationChildOverride: "animationChildOverride",
1031
+ AnimationTrack: "animationTrack",
1032
+ AnimationChildTrack: "animationChildTrack",
1033
+ AnimationSegmentTrack: "animationSegmentTrack",
1034
+ SpriteAnimationSegmentTrack: "spriteAnimationSegmentTrack",
1035
+ Variant: "variant",
1036
+ VariantFolder: "variantFolder",
1037
+ LookupVariant: "lookupVariant",
1038
+ LookupVariantFolder: "lookupVariantFolder"
1039
+ };
1040
+ var NEO_WORLD_SYSTEM_CLASS_KIND_VALUES = new Set(
1041
+ Object.values(NeoWorldSystemClassKind)
1042
+ );
1043
+ function isNeoWorldSystemClassKind(value) {
1044
+ if (typeof value !== "string") return false;
1045
+ return NEO_WORLD_SYSTEM_CLASS_KIND_VALUES.has(value);
1046
+ }
1047
+
1048
+ // ../packages/models/src/core/core-types.ts
1049
+ var SystemDisallowedOperation = {
1050
+ /**
1051
+ * Blocks project-author edits to the record's schema/configuration.
1052
+ */
1053
+ EditRecord: "editRecord",
1054
+ /**
1055
+ * Blocks project-author deletion of the record.
1056
+ */
1057
+ DeleteRecord: "deleteRecord",
1058
+ /**
1059
+ * Removes the record from normal creation/selection affordances.
1060
+ */
1061
+ SelectRecord: "selectRecord",
1062
+ /**
1063
+ * Blocks replacing the value row attached to a member as a whole.
1064
+ */
1065
+ ReplaceValue: "replaceValue"
1066
+ };
1067
+ var SystemProtectionKind = {
1068
+ WorldAuthoring: "worldAuthoring",
1069
+ DialogueMemorySchema: "dialogueMemorySchema",
1070
+ DialogueMemoryContainer: "dialogueMemoryContainer",
1071
+ DialoguePriorityDefault: "dialoguePriorityDefault",
1072
+ PolicyImmutable: "policyImmutable",
1073
+ PolicyDeleteBlocked: "policyDeleteBlocked",
1074
+ ScriptRuntime: "scriptRuntime"
1075
+ };
1076
+ function isWithId(value) {
1077
+ return typeof value?.id === "string";
1078
+ }
1079
+ function isIWithTimestamps(value) {
1080
+ const v = value;
1081
+ if (v === null || v === void 0) {
1082
+ return false;
1083
+ }
1084
+ return isEpochMillis(v.createdAt) && isEpochMillis(v.updatedAt);
1085
+ }
1086
+ function isEpochMillis(value) {
1087
+ if (typeof value !== "number") return false;
1088
+ return Number.isFinite(value);
1089
+ }
1090
+ function isSystemProtectionKind(value) {
1091
+ return value === SystemProtectionKind.WorldAuthoring || value === SystemProtectionKind.DialogueMemorySchema || value === SystemProtectionKind.DialogueMemoryContainer || value === SystemProtectionKind.DialoguePriorityDefault || value === SystemProtectionKind.PolicyImmutable || value === SystemProtectionKind.PolicyDeleteBlocked || value === SystemProtectionKind.ScriptRuntime;
1092
+ }
1093
+ function isSystemMetadata(value) {
1094
+ const v = value;
1095
+ if (typeof v !== "object") return false;
1096
+ if (v === null) return false;
1097
+ if (!isSystemProtectionKind(v.kind)) return false;
1098
+ if (v.worldKind !== void 0 && v.worldKind !== null) {
1099
+ return isNeoWorldSystemClassKind(v.worldKind);
1100
+ }
1101
+ return true;
1102
+ }
1103
+ function isWithName(value) {
1104
+ return typeof value?.name === "string";
1105
+ }
1106
+
1107
+ // ../packages/models/src/core/auth-ownership-types.ts
1108
+ var ActorKind = {
1109
+ /**
1110
+ * `better-auth` user identities.
1111
+ */
1112
+ user: "user",
1113
+ /**
1114
+ * `better-auth` organization identities.
1115
+ */
1116
+ organization: "organization",
1117
+ /**
1118
+ * Used for denoting records created by a system.
1119
+ */
1120
+ system: "system"
1121
+ };
1122
+ function isActorIdentifier(value) {
1123
+ if (typeof value !== "object") return false;
1124
+ if (value === null) return false;
1125
+ const candidate = value;
1126
+ if (!isActorKind(candidate.kind)) return false;
1127
+ return typeof candidate.id === "string" && candidate.id.trim().length > 0;
1128
+ }
1129
+ function isActorKind(value) {
1130
+ return value === ActorKind.user || value === ActorKind.organization || value === ActorKind.system;
1131
+ }
1132
+
1133
+ // ../packages/models/src/core/structural-narrow.ts
1134
+ function isObject(value) {
1135
+ if (typeof value !== "object") return false;
1136
+ return value !== null;
1137
+ }
1138
+ function hasField(value, field) {
1139
+ if (!isObject(value)) return false;
1140
+ return field in value;
1141
+ }
1142
+ function getOptionalString(value, field) {
1143
+ if (!hasField(value, field)) return void 0;
1144
+ const v = value[field];
1145
+ if (typeof v !== "string") return void 0;
1146
+ return v;
1147
+ }
1148
+ function getField(value, field) {
1149
+ if (!hasField(value, field)) return void 0;
1150
+ return value[field];
1151
+ }
1152
+ function isOptionalNullableType(value, isType) {
1153
+ if (value === null || value === void 0) return true;
1154
+ return isType(value);
1155
+ }
1156
+ function isNullableType(value, isType) {
1157
+ if (value === null) return true;
1158
+ return isType(value);
1159
+ }
1160
+ function isRequiredType(value, isType) {
1161
+ if (value === null || value === void 0) return false;
1162
+ return isType(value);
1163
+ }
1164
+ function isString(value) {
1165
+ return typeof value === "string";
1166
+ }
1167
+ function isNumber(value) {
1168
+ return typeof value === "number";
1169
+ }
1170
+ function isFiniteNumberGreaterThanOrEqualToZero(value) {
1171
+ if (!isNumber(value)) return false;
1172
+ if (!Number.isFinite(value)) return false;
1173
+ return value >= 0;
1174
+ }
1175
+ function isBoolean(value) {
1176
+ return typeof value === "boolean";
1177
+ }
1178
+ function isOptionalNullableString(value) {
1179
+ return isOptionalNullableType(value, isString);
1180
+ }
1181
+ function isNullableFiniteNumberGreaterThanOrEqualToZero(value) {
1182
+ return isNullableType(value, isFiniteNumberGreaterThanOrEqualToZero);
1183
+ }
1184
+ function setOwnField(record4, key, value) {
1185
+ Object.defineProperty(record4, key, {
1186
+ value,
1187
+ enumerable: true,
1188
+ configurable: true,
1189
+ writable: true
1190
+ });
1191
+ }
1192
+
1193
+ // ../packages/models/src/common/collections.ts
1194
+ function indexById(records2) {
1195
+ const indexed = /* @__PURE__ */ new Map();
1196
+ for (const record4 of records2) indexed.set(record4.id, record4);
1197
+ return indexed;
1198
+ }
1199
+ function setsEqual(left, right) {
1200
+ if (left === right) return true;
1201
+ if (left.size !== right.size) return false;
1202
+ for (const value of left) {
1203
+ if (!right.has(value)) return false;
1204
+ }
1205
+ return true;
1206
+ }
1207
+ async function forEachConcurrently(items, limit, work) {
1208
+ const queue = items[Symbol.iterator]();
1209
+ await Promise.all(
1210
+ Array.from({ length: limit }, async () => {
1211
+ for (let next = queue.next(); next.done !== true; next = queue.next()) {
1212
+ await work(next.value);
1213
+ }
1214
+ })
1215
+ );
1216
+ }
1217
+
1218
+ // ../packages/models/src/docs-text.ts
1219
+ var DOCS_TEXT_MAX_UTF8_BYTES = 16384;
1220
+ var textEncoder = new TextEncoder();
1221
+ function isValidDocsText(value) {
1222
+ if (value === void 0) return true;
1223
+ if (typeof value !== "string") return false;
1224
+ return textEncoder.encode(value).byteLength <= DOCS_TEXT_MAX_UTF8_BYTES;
1225
+ }
1226
+
882
1227
  // ../packages/models/src/members/member-storage.ts
883
1228
  function isMemberStorageKind(value) {
884
1229
  return value === 0 /* Inherit */ || value === 1 /* Immutable */ || value === 2 /* Save */ || value === 3 /* Session */ || value === 4 /* Writable */ || value === 5 /* User */;
@@ -923,6 +1268,198 @@ function createWritableAncestorLookup(memberById) {
923
1268
  return lookup;
924
1269
  }
925
1270
 
1271
+ // ../packages/models/src/classes/classes.ts
1272
+ function isAbstractClass(value) {
1273
+ return value?.modifier === 1 /* Abstract */;
1274
+ }
1275
+ function isGenericParamConstraint(value) {
1276
+ const v = value;
1277
+ if (!v || typeof v !== "object") return false;
1278
+ if (v.kind === void 0 || v.kind === 0 /* Class */) {
1279
+ if (typeof v.classId !== "string") return false;
1280
+ if (v.classId.length === 0) return false;
1281
+ if (v.enumId !== void 0) return false;
1282
+ const argumentsValue = v.classArguments;
1283
+ return argumentsValue === void 0 || isGenericBindingsRecord(argumentsValue);
1284
+ }
1285
+ if (v.kind === 1 /* Enum */) {
1286
+ if (typeof v.enumId !== "string") return false;
1287
+ if (v.enumId.length === 0) return false;
1288
+ return v.classId === void 0;
1289
+ }
1290
+ return false;
1291
+ }
1292
+ function isClassGenericConstraint(value) {
1293
+ return value.kind === void 0 || value.kind === 0 /* Class */;
1294
+ }
1295
+ function isEnumGenericConstraint(value) {
1296
+ return value.kind === 1 /* Enum */;
1297
+ }
1298
+ function isGenericParamDeclaration(value) {
1299
+ const v = value;
1300
+ if (!v || typeof v !== "object") return false;
1301
+ if (typeof v.id !== "string") return false;
1302
+ if (v.id.length === 0) return false;
1303
+ if (typeof v.name !== "string") return false;
1304
+ if (v.name.length === 0) return false;
1305
+ if (v.constraint === void 0) return true;
1306
+ return isGenericParamConstraint(v.constraint);
1307
+ }
1308
+ function isGenericBinding(value) {
1309
+ const v = value;
1310
+ if (!v || typeof v !== "object") return false;
1311
+ if (Object.hasOwn(v, "defaultValue")) return false;
1312
+ if (v.kind === void 0 || v.kind === 0 /* Generic */) {
1313
+ if (typeof v.genericParamId !== "string") return false;
1314
+ if (v.genericParamId.length === 0) return false;
1315
+ return v.memberId === void 0;
1316
+ }
1317
+ if (v.kind === 1 /* Member */) {
1318
+ if (typeof v.memberId !== "string") return false;
1319
+ if (v.memberId.length === 0) return false;
1320
+ return v.genericParamId === void 0;
1321
+ }
1322
+ return false;
1323
+ }
1324
+ function isForwardedGenericBinding(value) {
1325
+ return value.kind === void 0 || value.kind === 0 /* Generic */;
1326
+ }
1327
+ function isMemberGenericBinding(value) {
1328
+ return value.kind === 1 /* Member */;
1329
+ }
1330
+ function isGenericBindingsRecord(value) {
1331
+ if (value === null) return false;
1332
+ if (typeof value !== "object") return false;
1333
+ if (Array.isArray(value)) return false;
1334
+ return Object.values(value).every(isGenericBinding);
1335
+ }
1336
+ var RETIRED_CONSTRUCTOR_PROJECTIONS_FIELD = "constructorProjections";
1337
+ function hasRetiredConstructorProjectionsTombstone(value) {
1338
+ return value !== null && typeof value === "object" && Object.hasOwn(value, RETIRED_CONSTRUCTOR_PROJECTIONS_FIELD);
1339
+ }
1340
+ function isNeoSchemaClassBase(value) {
1341
+ if (hasRetiredConstructorProjectionsTombstone(value)) {
1342
+ return false;
1343
+ }
1344
+ const v = value;
1345
+ return typeof v?.name === "string" && isValidDocsText(v.docsText) && isClassSchema(v?.schema) && isOptionalSchemaKeyOrder(v?.schemaKeyOrder) && (v.implementsInterfaceIds === void 0 || Array.isArray(v.implementsInterfaceIds) && v.implementsInterfaceIds.every(
1346
+ (interfaceId) => typeof interfaceId === "string" && interfaceId.length > 0
1347
+ )) && (v.uiVisibility === void 0 || v.uiVisibility === 0 /* Visible */ || v.uiVisibility === 1 /* Hidden */) && (v.modifier === void 0 || v.modifier === 0 /* Open */ || v.modifier === 1 /* Abstract */ || v.modifier === 2 /* Sealed */) && (v.allowedStorage === void 0 || isClassAllowedStorage(v.allowedStorage)) && (v.allowedStorageKeys === void 0 || Array.isArray(v.allowedStorageKeys) && v.allowedStorageKeys.every((key) => typeof key === "string")) && (v.genericParams === void 0 || Array.isArray(v.genericParams) && v.genericParams.every(isGenericParamDeclaration)) && (v.extendsGenericBindings === void 0 || isGenericBindingsRecord(v.extendsGenericBindings)) && (v.constructorIds === void 0 || Array.isArray(v.constructorIds) && v.constructorIds.every(
1348
+ (constructorId) => typeof constructorId === "string" && constructorId.length > 0
1349
+ ) && new Set(v.constructorIds).size === v.constructorIds.length) && (v.requiredConstructorId === void 0 || typeof v.requiredConstructorId === "string" && v.requiredConstructorId.length > 0 && (v.constructorIds ?? []).length === 0) && (v.targetMemberId === void 0 || typeof v.targetMemberId === "string" && v.targetMemberId.length > 0) && (v.system === void 0 || isSystemMetadata(v.system));
1350
+ }
1351
+ function resolveAllowedStorage(classId, classes, draft) {
1352
+ const visited = /* @__PURE__ */ new Set();
1353
+ const lookup = (id) => draft && draft.id === id ? draft : classes.find((candidate) => candidate.id === id);
1354
+ let current = lookup(classId);
1355
+ while (current) {
1356
+ if (visited.has(current.id)) return null;
1357
+ visited.add(current.id);
1358
+ if (current.allowedStorage != null) return current.allowedStorage;
1359
+ if (!current.extendsClassId) return null;
1360
+ current = lookup(current.extendsClassId);
1361
+ }
1362
+ return null;
1363
+ }
1364
+ function classInheritsWorldKind(classId, expectedKind, classesById) {
1365
+ let current = classesById.get(classId);
1366
+ for (let remaining = classesById.size; current !== void 0 && remaining > 0; remaining--) {
1367
+ if (current.system?.worldKind === expectedKind) return true;
1368
+ current = current.extendsClassId ? classesById.get(current.extendsClassId) : void 0;
1369
+ }
1370
+ return false;
1371
+ }
1372
+ function resolveWorldSystemClassKind(classId, classes, draft) {
1373
+ const visited = /* @__PURE__ */ new Set();
1374
+ const lookup = (id) => draft && draft.id === id ? draft : classes.find((candidate) => candidate.id === id);
1375
+ let current = lookup(classId);
1376
+ while (current) {
1377
+ if (visited.has(current.id)) return null;
1378
+ visited.add(current.id);
1379
+ if (current.system?.worldKind != null) return current.system.worldKind;
1380
+ if (!current.extendsClassId) return null;
1381
+ current = lookup(current.extendsClassId);
1382
+ }
1383
+ return null;
1384
+ }
1385
+ function indexWorldSystemClassKinds(classes, classesById = indexById(classes)) {
1386
+ const kinds = /* @__PURE__ */ new Map();
1387
+ for (const schemaClass2 of classes) {
1388
+ if (schemaClass2.system?.worldKind != null) {
1389
+ kinds.set(schemaClass2.id, schemaClass2.system.worldKind);
1390
+ } else if (schemaClass2.extendsClassId === void 0) {
1391
+ kinds.set(schemaClass2.id, null);
1392
+ }
1393
+ }
1394
+ const resolving = /* @__PURE__ */ new Set();
1395
+ for (const schemaClass2 of classes) {
1396
+ if (kinds.has(schemaClass2.id)) continue;
1397
+ const path = [];
1398
+ let current = schemaClass2;
1399
+ let resolved = null;
1400
+ while (current !== void 0) {
1401
+ if (kinds.has(current.id)) {
1402
+ resolved = kinds.get(current.id) ?? null;
1403
+ break;
1404
+ }
1405
+ if (resolving.has(current.id)) {
1406
+ resolved = null;
1407
+ break;
1408
+ }
1409
+ resolving.add(current.id);
1410
+ path.push(current);
1411
+ current = current.extendsClassId === void 0 ? void 0 : classesById.get(current.extendsClassId);
1412
+ }
1413
+ for (const candidate of path) {
1414
+ resolving.delete(candidate.id);
1415
+ kinds.set(candidate.id, resolved);
1416
+ }
1417
+ }
1418
+ return kinds;
1419
+ }
1420
+ function dedupeSchemaKeyOrder(order) {
1421
+ const seen = /* @__PURE__ */ new Set();
1422
+ const result = [];
1423
+ for (const schemaKey of order) {
1424
+ if (seen.has(schemaKey)) continue;
1425
+ seen.add(schemaKey);
1426
+ result.push(schemaKey);
1427
+ }
1428
+ return result;
1429
+ }
1430
+ function getClassSchemaKeyOrder(schemaClass2) {
1431
+ const schemaKeys = Object.keys(schemaClass2.schema);
1432
+ if (schemaClass2.schemaKeyOrder === void 0) return schemaKeys;
1433
+ const orderedKeys2 = dedupeSchemaKeyOrder(schemaClass2.schemaKeyOrder);
1434
+ const seen = new Set(orderedKeys2);
1435
+ for (const schemaKey of schemaKeys) {
1436
+ if (seen.has(schemaKey)) continue;
1437
+ seen.add(schemaKey);
1438
+ orderedKeys2.push(schemaKey);
1439
+ }
1440
+ return orderedKeys2;
1441
+ }
1442
+ function isClassSchema(value) {
1443
+ if (value === null) return false;
1444
+ if (typeof value !== "object") return false;
1445
+ if (Array.isArray(value)) return false;
1446
+ return Object.values(value).every(
1447
+ (schemaValue) => typeof schemaValue === "string"
1448
+ );
1449
+ }
1450
+ function isOptionalSchemaKeyOrder(value) {
1451
+ if (value === void 0) return true;
1452
+ if (!Array.isArray(value)) return false;
1453
+ return value.every((key) => typeof key === "string");
1454
+ }
1455
+ function isNeoSchemaClassProps(value) {
1456
+ const v = value;
1457
+ return isNeoSchemaClassBase(value) && typeof v?.id === "string" && isEpochMillis(v?.createdAt) && isEpochMillis(v?.updatedAt) && typeof v?.projectId === "string";
1458
+ }
1459
+ function isNeoSchemaClass(value) {
1460
+ return isNeoSchemaClassProps(value);
1461
+ }
1462
+
926
1463
  // ../packages/models/src/members/member-kind-enum.ts
927
1464
  var MemberKind = /* @__PURE__ */ ((MemberKind8) => {
928
1465
  MemberKind8[MemberKind8["Null"] = 0] = "Null";
@@ -1125,128 +1662,6 @@ function memberKindSupportsDistribution(kind) {
1125
1662
  return memberKindSupportsStorage(kind);
1126
1663
  }
1127
1664
 
1128
- // ../node_modules/uuid/dist-node/regex.js
1129
- var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
1130
-
1131
- // ../node_modules/uuid/dist-node/validate.js
1132
- function validate(uuid) {
1133
- return typeof uuid === "string" && regex_default.test(uuid);
1134
- }
1135
- var validate_default = validate;
1136
-
1137
- // ../node_modules/uuid/dist-node/parse.js
1138
- function parse(uuid) {
1139
- if (!validate_default(uuid)) {
1140
- throw TypeError("Invalid UUID");
1141
- }
1142
- let v;
1143
- return Uint8Array.of((v = parseInt(uuid.slice(0, 8), 16)) >>> 24, v >>> 16 & 255, v >>> 8 & 255, v & 255, (v = parseInt(uuid.slice(9, 13), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(14, 18), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(19, 23), 16)) >>> 8, v & 255, (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255, v / 4294967296 & 255, v >>> 24 & 255, v >>> 16 & 255, v >>> 8 & 255, v & 255);
1144
- }
1145
- var parse_default = parse;
1146
-
1147
- // ../node_modules/uuid/dist-node/stringify.js
1148
- var byteToHex = [];
1149
- for (let i = 0; i < 256; ++i) {
1150
- byteToHex.push((i + 256).toString(16).slice(1));
1151
- }
1152
- function unsafeStringify(arr, offset = 0) {
1153
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
1154
- }
1155
-
1156
- // ../node_modules/uuid/dist-node/rng.js
1157
- var rnds8 = new Uint8Array(16);
1158
- function rng() {
1159
- return crypto.getRandomValues(rnds8);
1160
- }
1161
-
1162
- // ../node_modules/uuid/dist-node/v35.js
1163
- function stringToBytes(str) {
1164
- str = unescape(encodeURIComponent(str));
1165
- const bytes = new Uint8Array(str.length);
1166
- for (let i = 0; i < str.length; ++i) {
1167
- bytes[i] = str.charCodeAt(i);
1168
- }
1169
- return bytes;
1170
- }
1171
- var DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
1172
- var URL2 = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
1173
- function v35(version, hash, value, namespace, buf, offset) {
1174
- const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
1175
- const namespaceBytes = typeof namespace === "string" ? parse_default(namespace) : namespace;
1176
- if (typeof namespace === "string") {
1177
- namespace = parse_default(namespace);
1178
- }
1179
- if (namespace?.length !== 16) {
1180
- throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
1181
- }
1182
- let bytes = new Uint8Array(16 + valueBytes.length);
1183
- bytes.set(namespaceBytes);
1184
- bytes.set(valueBytes, namespaceBytes.length);
1185
- bytes = hash(bytes);
1186
- bytes[6] = bytes[6] & 15 | version;
1187
- bytes[8] = bytes[8] & 63 | 128;
1188
- if (buf) {
1189
- offset ??= 0;
1190
- if (offset < 0 || offset + 16 > buf.length) {
1191
- throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
1192
- }
1193
- for (let i = 0; i < 16; ++i) {
1194
- buf[offset + i] = bytes[i];
1195
- }
1196
- return buf;
1197
- }
1198
- return unsafeStringify(bytes);
1199
- }
1200
-
1201
- // ../node_modules/uuid/dist-node/v4.js
1202
- function v4(options, buf, offset) {
1203
- if (!buf && !options && crypto.randomUUID) {
1204
- return crypto.randomUUID();
1205
- }
1206
- return _v4(options, buf, offset);
1207
- }
1208
- function _v4(options, buf, offset) {
1209
- options = options || {};
1210
- const rnds = options.random ?? options.rng?.() ?? rng();
1211
- if (rnds.length < 16) {
1212
- throw new Error("Random bytes length must be >= 16");
1213
- }
1214
- rnds[6] = rnds[6] & 15 | 64;
1215
- rnds[8] = rnds[8] & 63 | 128;
1216
- if (buf) {
1217
- offset = offset || 0;
1218
- if (offset < 0 || offset + 16 > buf.length) {
1219
- throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
1220
- }
1221
- for (let i = 0; i < 16; ++i) {
1222
- buf[offset + i] = rnds[i];
1223
- }
1224
- return buf;
1225
- }
1226
- return unsafeStringify(rnds);
1227
- }
1228
- var v4_default = v4;
1229
-
1230
- // ../node_modules/uuid/dist-node/sha1.js
1231
- import { createHash } from "node:crypto";
1232
- function sha1(bytes) {
1233
- if (Array.isArray(bytes)) {
1234
- bytes = Buffer.from(bytes);
1235
- } else if (typeof bytes === "string") {
1236
- bytes = Buffer.from(bytes, "utf8");
1237
- }
1238
- return createHash("sha1").update(bytes).digest();
1239
- }
1240
- var sha1_default = sha1;
1241
-
1242
- // ../node_modules/uuid/dist-node/v5.js
1243
- function v5(value, namespace, buf, offset) {
1244
- return v35(80, sha1_default, value, namespace, buf, offset);
1245
- }
1246
- v5.DNS = DNS;
1247
- v5.URL = URL2;
1248
- var v5_default = v5;
1249
-
1250
1665
  // ../packages/models/src/project/project-root-members.ts
1251
1666
  var PROJECT_ROOTS = [
1252
1667
  {
@@ -1295,178 +1710,6 @@ function projectRootMembersInDisplayOrder(project) {
1295
1710
  }));
1296
1711
  }
1297
1712
 
1298
- // ../packages/models/src/core/structural-narrow.ts
1299
- function isObject(value) {
1300
- if (typeof value !== "object") return false;
1301
- return value !== null;
1302
- }
1303
- function hasField(value, field) {
1304
- if (!isObject(value)) return false;
1305
- return field in value;
1306
- }
1307
- function getOptionalString(value, field) {
1308
- if (!hasField(value, field)) return void 0;
1309
- const v = value[field];
1310
- if (typeof v !== "string") return void 0;
1311
- return v;
1312
- }
1313
- function getField(value, field) {
1314
- if (!hasField(value, field)) return void 0;
1315
- return value[field];
1316
- }
1317
- function isOptionalNullableType(value, isType) {
1318
- if (value === null || value === void 0) return true;
1319
- return isType(value);
1320
- }
1321
- function isNullableType(value, isType) {
1322
- if (value === null) return true;
1323
- return isType(value);
1324
- }
1325
- function isRequiredType(value, isType) {
1326
- if (value === null || value === void 0) return false;
1327
- return isType(value);
1328
- }
1329
- function isString(value) {
1330
- return typeof value === "string";
1331
- }
1332
- function isNumber(value) {
1333
- return typeof value === "number";
1334
- }
1335
- function isFiniteNumberGreaterThanOrEqualToZero(value) {
1336
- if (!isNumber(value)) return false;
1337
- if (!Number.isFinite(value)) return false;
1338
- return value >= 0;
1339
- }
1340
- function isBoolean(value) {
1341
- return typeof value === "boolean";
1342
- }
1343
- function isOptionalNullableString(value) {
1344
- return isOptionalNullableType(value, isString);
1345
- }
1346
- function isNullableFiniteNumberGreaterThanOrEqualToZero(value) {
1347
- return isNullableType(value, isFiniteNumberGreaterThanOrEqualToZero);
1348
- }
1349
- function setOwnField(record4, key, value) {
1350
- Object.defineProperty(record4, key, {
1351
- value,
1352
- enumerable: true,
1353
- configurable: true,
1354
- writable: true
1355
- });
1356
- }
1357
-
1358
- // ../packages/models/src/core/world-system-kinds.generated.ts
1359
- var NeoWorldSystemClassKind = {
1360
- CellPattern: "cellPattern",
1361
- TileGrid: "tileGrid",
1362
- SortingLayer: "sortingLayer",
1363
- TileLayer: "tileLayer",
1364
- ObjectLayer: "objectLayer",
1365
- Tile: "tile",
1366
- ObjectBase: "objectBase",
1367
- ObjectCollider: "objectCollider",
1368
- SortingGroup: "sortingGroup",
1369
- LayerGroupBase: "layerGroupBase",
1370
- SpriteObject: "spriteObject",
1371
- PlacementTile: "placementTile",
1372
- TileLayerLink: "tileLayerLink",
1373
- ObjectLayerLink: "objectLayerLink",
1374
- Object: "object",
1375
- SmartTile: "smartTile",
1376
- SmartTileRule: "smartTileRule",
1377
- SmartTileNeighbor: "smartTileNeighbor",
1378
- AnimationFrameBase: "animationFrameBase",
1379
- AnimationClip: "animationClip",
1380
- AnimationFrame: "animationFrame",
1381
- AnimationSegmentFrame: "animationSegmentFrame",
1382
- AnimationSegment: "animationSegment",
1383
- SpriteAnimationSegment: "spriteAnimationSegment",
1384
- AnimationChildOverride: "animationChildOverride",
1385
- AnimationTrack: "animationTrack",
1386
- AnimationChildTrack: "animationChildTrack",
1387
- AnimationSegmentTrack: "animationSegmentTrack",
1388
- SpriteAnimationSegmentTrack: "spriteAnimationSegmentTrack",
1389
- Variant: "variant",
1390
- VariantFolder: "variantFolder",
1391
- LookupVariant: "lookupVariant",
1392
- LookupVariantFolder: "lookupVariantFolder"
1393
- };
1394
- var NEO_WORLD_SYSTEM_CLASS_KIND_VALUES = new Set(
1395
- Object.values(NeoWorldSystemClassKind)
1396
- );
1397
- function isNeoWorldSystemClassKind(value) {
1398
- if (typeof value !== "string") return false;
1399
- return NEO_WORLD_SYSTEM_CLASS_KIND_VALUES.has(value);
1400
- }
1401
-
1402
- // ../packages/models/src/core/core-types.ts
1403
- var SystemDisallowedOperation = {
1404
- /**
1405
- * Blocks project-author edits to the record's schema/configuration.
1406
- */
1407
- EditRecord: "editRecord",
1408
- /**
1409
- * Blocks project-author deletion of the record.
1410
- */
1411
- DeleteRecord: "deleteRecord",
1412
- /**
1413
- * Removes the record from normal creation/selection affordances.
1414
- */
1415
- SelectRecord: "selectRecord",
1416
- /**
1417
- * Blocks replacing the value row attached to a member as a whole.
1418
- */
1419
- ReplaceValue: "replaceValue"
1420
- };
1421
- var SystemProtectionKind = {
1422
- WorldAuthoring: "worldAuthoring",
1423
- DialogueMemorySchema: "dialogueMemorySchema",
1424
- DialogueMemoryContainer: "dialogueMemoryContainer",
1425
- DialoguePriorityDefault: "dialoguePriorityDefault",
1426
- PolicyImmutable: "policyImmutable",
1427
- PolicyDeleteBlocked: "policyDeleteBlocked",
1428
- ScriptRuntime: "scriptRuntime"
1429
- };
1430
- function isWithId(value) {
1431
- return typeof value?.id === "string";
1432
- }
1433
- function isIWithTimestamps(value) {
1434
- const v = value;
1435
- if (v === null || v === void 0) {
1436
- return false;
1437
- }
1438
- return isEpochMillis(v.createdAt) && isEpochMillis(v.updatedAt);
1439
- }
1440
- function isEpochMillis(value) {
1441
- if (typeof value !== "number") return false;
1442
- return Number.isFinite(value);
1443
- }
1444
- function isSystemProtectionKind(value) {
1445
- return value === SystemProtectionKind.WorldAuthoring || value === SystemProtectionKind.DialogueMemorySchema || value === SystemProtectionKind.DialogueMemoryContainer || value === SystemProtectionKind.DialoguePriorityDefault || value === SystemProtectionKind.PolicyImmutable || value === SystemProtectionKind.PolicyDeleteBlocked || value === SystemProtectionKind.ScriptRuntime;
1446
- }
1447
- function isSystemMetadata(value) {
1448
- const v = value;
1449
- if (typeof v !== "object") return false;
1450
- if (v === null) return false;
1451
- if (!isSystemProtectionKind(v.kind)) return false;
1452
- if (v.worldKind !== void 0 && v.worldKind !== null) {
1453
- return isNeoWorldSystemClassKind(v.worldKind);
1454
- }
1455
- return true;
1456
- }
1457
- function isWithName(value) {
1458
- return typeof value?.name === "string";
1459
- }
1460
-
1461
- // ../packages/models/src/docs-text.ts
1462
- var DOCS_TEXT_MAX_UTF8_BYTES = 16384;
1463
- var textEncoder = new TextEncoder();
1464
- function isValidDocsText(value) {
1465
- if (value === void 0) return true;
1466
- if (typeof value !== "string") return false;
1467
- return textEncoder.encode(value).byteLength <= DOCS_TEXT_MAX_UTF8_BYTES;
1468
- }
1469
-
1470
1713
  // ../packages/models/src/members/float32.ts
1471
1714
  function isFloat32(value) {
1472
1715
  return typeof value === "number" && Number.isFinite(value) && Math.fround(value) === value;
@@ -3896,223 +4139,6 @@ function typeInfosInvariantlyEqual(left, right) {
3896
4139
  return true;
3897
4140
  }
3898
4141
 
3899
- // ../packages/models/src/common/collections.ts
3900
- function indexById(records2) {
3901
- const indexed = /* @__PURE__ */ new Map();
3902
- for (const record4 of records2) indexed.set(record4.id, record4);
3903
- return indexed;
3904
- }
3905
- function setsEqual(left, right) {
3906
- if (left === right) return true;
3907
- if (left.size !== right.size) return false;
3908
- for (const value of left) {
3909
- if (!right.has(value)) return false;
3910
- }
3911
- return true;
3912
- }
3913
- async function forEachConcurrently(items, limit, work) {
3914
- const queue = items[Symbol.iterator]();
3915
- await Promise.all(
3916
- Array.from({ length: limit }, async () => {
3917
- for (let next = queue.next(); next.done !== true; next = queue.next()) {
3918
- await work(next.value);
3919
- }
3920
- })
3921
- );
3922
- }
3923
-
3924
- // ../packages/models/src/classes/classes.ts
3925
- function isAbstractClass(value) {
3926
- return value?.modifier === 1 /* Abstract */;
3927
- }
3928
- function isGenericParamConstraint(value) {
3929
- const v = value;
3930
- if (!v || typeof v !== "object") return false;
3931
- if (v.kind === void 0 || v.kind === 0 /* Class */) {
3932
- if (typeof v.classId !== "string") return false;
3933
- if (v.classId.length === 0) return false;
3934
- if (v.enumId !== void 0) return false;
3935
- const argumentsValue = v.classArguments;
3936
- return argumentsValue === void 0 || isGenericBindingsRecord(argumentsValue);
3937
- }
3938
- if (v.kind === 1 /* Enum */) {
3939
- if (typeof v.enumId !== "string") return false;
3940
- if (v.enumId.length === 0) return false;
3941
- return v.classId === void 0;
3942
- }
3943
- return false;
3944
- }
3945
- function isClassGenericConstraint(value) {
3946
- return value.kind === void 0 || value.kind === 0 /* Class */;
3947
- }
3948
- function isEnumGenericConstraint(value) {
3949
- return value.kind === 1 /* Enum */;
3950
- }
3951
- function isGenericParamDeclaration(value) {
3952
- const v = value;
3953
- if (!v || typeof v !== "object") return false;
3954
- if (typeof v.id !== "string") return false;
3955
- if (v.id.length === 0) return false;
3956
- if (typeof v.name !== "string") return false;
3957
- if (v.name.length === 0) return false;
3958
- if (v.constraint === void 0) return true;
3959
- return isGenericParamConstraint(v.constraint);
3960
- }
3961
- function isGenericBinding(value) {
3962
- const v = value;
3963
- if (!v || typeof v !== "object") return false;
3964
- if (Object.hasOwn(v, "defaultValue")) return false;
3965
- if (v.kind === void 0 || v.kind === 0 /* Generic */) {
3966
- if (typeof v.genericParamId !== "string") return false;
3967
- if (v.genericParamId.length === 0) return false;
3968
- return v.memberId === void 0;
3969
- }
3970
- if (v.kind === 1 /* Member */) {
3971
- if (typeof v.memberId !== "string") return false;
3972
- if (v.memberId.length === 0) return false;
3973
- return v.genericParamId === void 0;
3974
- }
3975
- return false;
3976
- }
3977
- function isForwardedGenericBinding(value) {
3978
- return value.kind === void 0 || value.kind === 0 /* Generic */;
3979
- }
3980
- function isMemberGenericBinding(value) {
3981
- return value.kind === 1 /* Member */;
3982
- }
3983
- function isGenericBindingsRecord(value) {
3984
- if (value === null) return false;
3985
- if (typeof value !== "object") return false;
3986
- if (Array.isArray(value)) return false;
3987
- return Object.values(value).every(isGenericBinding);
3988
- }
3989
- var RETIRED_CONSTRUCTOR_PROJECTIONS_FIELD = "constructorProjections";
3990
- function hasRetiredConstructorProjectionsTombstone(value) {
3991
- return value !== null && typeof value === "object" && Object.hasOwn(value, RETIRED_CONSTRUCTOR_PROJECTIONS_FIELD);
3992
- }
3993
- function isNeoSchemaClassBase(value) {
3994
- if (hasRetiredConstructorProjectionsTombstone(value)) {
3995
- return false;
3996
- }
3997
- const v = value;
3998
- return typeof v?.name === "string" && isValidDocsText(v.docsText) && isClassSchema(v?.schema) && isOptionalSchemaKeyOrder(v?.schemaKeyOrder) && (v.implementsInterfaceIds === void 0 || Array.isArray(v.implementsInterfaceIds) && v.implementsInterfaceIds.every(
3999
- (interfaceId) => typeof interfaceId === "string" && interfaceId.length > 0
4000
- )) && (v.uiVisibility === void 0 || v.uiVisibility === 0 /* Visible */ || v.uiVisibility === 1 /* Hidden */) && (v.modifier === void 0 || v.modifier === 0 /* Open */ || v.modifier === 1 /* Abstract */ || v.modifier === 2 /* Sealed */) && (v.allowedStorage === void 0 || isClassAllowedStorage(v.allowedStorage)) && (v.allowedStorageKeys === void 0 || Array.isArray(v.allowedStorageKeys) && v.allowedStorageKeys.every((key) => typeof key === "string")) && (v.genericParams === void 0 || Array.isArray(v.genericParams) && v.genericParams.every(isGenericParamDeclaration)) && (v.extendsGenericBindings === void 0 || isGenericBindingsRecord(v.extendsGenericBindings)) && (v.constructorIds === void 0 || Array.isArray(v.constructorIds) && v.constructorIds.every(
4001
- (constructorId) => typeof constructorId === "string" && constructorId.length > 0
4002
- ) && new Set(v.constructorIds).size === v.constructorIds.length) && (v.requiredConstructorId === void 0 || typeof v.requiredConstructorId === "string" && v.requiredConstructorId.length > 0 && (v.constructorIds ?? []).length === 0) && (v.targetMemberId === void 0 || typeof v.targetMemberId === "string" && v.targetMemberId.length > 0) && (v.system === void 0 || isSystemMetadata(v.system));
4003
- }
4004
- function resolveAllowedStorage(classId, classes, draft) {
4005
- const visited = /* @__PURE__ */ new Set();
4006
- const lookup = (id) => draft && draft.id === id ? draft : classes.find((candidate) => candidate.id === id);
4007
- let current = lookup(classId);
4008
- while (current) {
4009
- if (visited.has(current.id)) return null;
4010
- visited.add(current.id);
4011
- if (current.allowedStorage != null) return current.allowedStorage;
4012
- if (!current.extendsClassId) return null;
4013
- current = lookup(current.extendsClassId);
4014
- }
4015
- return null;
4016
- }
4017
- function classInheritsWorldKind(classId, expectedKind, classesById) {
4018
- let current = classesById.get(classId);
4019
- for (let remaining = classesById.size; current !== void 0 && remaining > 0; remaining--) {
4020
- if (current.system?.worldKind === expectedKind) return true;
4021
- current = current.extendsClassId ? classesById.get(current.extendsClassId) : void 0;
4022
- }
4023
- return false;
4024
- }
4025
- function resolveWorldSystemClassKind(classId, classes, draft) {
4026
- const visited = /* @__PURE__ */ new Set();
4027
- const lookup = (id) => draft && draft.id === id ? draft : classes.find((candidate) => candidate.id === id);
4028
- let current = lookup(classId);
4029
- while (current) {
4030
- if (visited.has(current.id)) return null;
4031
- visited.add(current.id);
4032
- if (current.system?.worldKind != null) return current.system.worldKind;
4033
- if (!current.extendsClassId) return null;
4034
- current = lookup(current.extendsClassId);
4035
- }
4036
- return null;
4037
- }
4038
- function indexWorldSystemClassKinds(classes, classesById = indexById(classes)) {
4039
- const kinds = /* @__PURE__ */ new Map();
4040
- for (const schemaClass2 of classes) {
4041
- if (schemaClass2.system?.worldKind != null) {
4042
- kinds.set(schemaClass2.id, schemaClass2.system.worldKind);
4043
- } else if (schemaClass2.extendsClassId === void 0) {
4044
- kinds.set(schemaClass2.id, null);
4045
- }
4046
- }
4047
- const resolving = /* @__PURE__ */ new Set();
4048
- for (const schemaClass2 of classes) {
4049
- if (kinds.has(schemaClass2.id)) continue;
4050
- const path = [];
4051
- let current = schemaClass2;
4052
- let resolved = null;
4053
- while (current !== void 0) {
4054
- if (kinds.has(current.id)) {
4055
- resolved = kinds.get(current.id) ?? null;
4056
- break;
4057
- }
4058
- if (resolving.has(current.id)) {
4059
- resolved = null;
4060
- break;
4061
- }
4062
- resolving.add(current.id);
4063
- path.push(current);
4064
- current = current.extendsClassId === void 0 ? void 0 : classesById.get(current.extendsClassId);
4065
- }
4066
- for (const candidate of path) {
4067
- resolving.delete(candidate.id);
4068
- kinds.set(candidate.id, resolved);
4069
- }
4070
- }
4071
- return kinds;
4072
- }
4073
- function dedupeSchemaKeyOrder(order) {
4074
- const seen = /* @__PURE__ */ new Set();
4075
- const result = [];
4076
- for (const schemaKey of order) {
4077
- if (seen.has(schemaKey)) continue;
4078
- seen.add(schemaKey);
4079
- result.push(schemaKey);
4080
- }
4081
- return result;
4082
- }
4083
- function getClassSchemaKeyOrder(schemaClass2) {
4084
- const schemaKeys = Object.keys(schemaClass2.schema);
4085
- if (schemaClass2.schemaKeyOrder === void 0) return schemaKeys;
4086
- const orderedKeys2 = dedupeSchemaKeyOrder(schemaClass2.schemaKeyOrder);
4087
- const seen = new Set(orderedKeys2);
4088
- for (const schemaKey of schemaKeys) {
4089
- if (seen.has(schemaKey)) continue;
4090
- seen.add(schemaKey);
4091
- orderedKeys2.push(schemaKey);
4092
- }
4093
- return orderedKeys2;
4094
- }
4095
- function isClassSchema(value) {
4096
- if (value === null) return false;
4097
- if (typeof value !== "object") return false;
4098
- if (Array.isArray(value)) return false;
4099
- return Object.values(value).every(
4100
- (schemaValue) => typeof schemaValue === "string"
4101
- );
4102
- }
4103
- function isOptionalSchemaKeyOrder(value) {
4104
- if (value === void 0) return true;
4105
- if (!Array.isArray(value)) return false;
4106
- return value.every((key) => typeof key === "string");
4107
- }
4108
- function isNeoSchemaClassProps(value) {
4109
- const v = value;
4110
- return isNeoSchemaClassBase(value) && typeof v?.id === "string" && isEpochMillis(v?.createdAt) && isEpochMillis(v?.updatedAt) && typeof v?.projectId === "string";
4111
- }
4112
- function isNeoSchemaClass(value) {
4113
- return isNeoSchemaClassProps(value);
4114
- }
4115
-
4116
4142
  // ../packages/models/src/members/structured-leaf-fields.ts
4117
4143
  var STRUCTURED_LEAF_FIELDS = {
4118
4144
  [11 /* Sprite */]: [
@@ -4561,7 +4587,10 @@ function isMemberEnum(value) {
4561
4587
  if (!isWithId(value)) return false;
4562
4588
  return isWithId(value);
4563
4589
  }
4564
- function isMemberLookupBase(value) {
4590
+ function isLookupSelection(selection) {
4591
+ return selection === void 0 || selection === 0 /* Single */ || selection === 1 /* Multi */;
4592
+ }
4593
+ function isMemberCollectionLookupBase(value) {
4565
4594
  const v = asMemberBaseForKind(value, 9 /* Lookup */);
4566
4595
  if (v === null) return false;
4567
4596
  if (typeof v.collectionMemberId !== "string") return false;
@@ -4572,7 +4601,22 @@ function isMemberLookupBase(value) {
4572
4601
  if (v.declaredTypeInfo !== void 0 && v.declaredTypeInfo !== null && !isNSTypeInfo(v.declaredTypeInfo)) {
4573
4602
  return false;
4574
4603
  }
4575
- return v.selection === void 0 || v.selection === 0 /* Single */ || v.selection === 1 /* Multi */;
4604
+ return isLookupSelection(v.selection);
4605
+ }
4606
+ function isMemberTypeLookupBase(value) {
4607
+ const v = asMemberBaseForKind(value, 9 /* Lookup */);
4608
+ if (v === null) return false;
4609
+ if (v.collectionMemberId !== void 0) return false;
4610
+ if (v.collectionValueId !== void 0) return false;
4611
+ if (!isLookupTargetTypeInfo(v.declaredTypeInfo)) return false;
4612
+ return isLookupSelection(v.selection);
4613
+ }
4614
+ function isLookupTargetTypeInfo(value) {
4615
+ if (!isNSTypeInfo(value)) return false;
4616
+ return value.type === 7 /* Class */ || value.type === 21 /* Generic */;
4617
+ }
4618
+ function isMemberLookupBase(value) {
4619
+ return isMemberCollectionLookupBase(value) || isMemberTypeLookupBase(value);
4576
4620
  }
4577
4621
  function isMemberLookup(value) {
4578
4622
  if (!isMemberLookupBase(value)) return false;
@@ -6408,32 +6452,6 @@ function referencedValueIdCandidates(value) {
6408
6452
  return [];
6409
6453
  }
6410
6454
 
6411
- // ../packages/models/src/core/auth-ownership-types.ts
6412
- var ActorKind = {
6413
- /**
6414
- * `better-auth` user identities.
6415
- */
6416
- user: "user",
6417
- /**
6418
- * `better-auth` organization identities.
6419
- */
6420
- organization: "organization",
6421
- /**
6422
- * Used for denoting records created by a system.
6423
- */
6424
- system: "system"
6425
- };
6426
- function isActorIdentifier(value) {
6427
- if (typeof value !== "object") return false;
6428
- if (value === null) return false;
6429
- const candidate = value;
6430
- if (!isActorKind(candidate.kind)) return false;
6431
- return typeof candidate.id === "string" && candidate.id.trim().length > 0;
6432
- }
6433
- function isActorKind(value) {
6434
- return value === ActorKind.user || value === ActorKind.organization || value === ActorKind.system;
6435
- }
6436
-
6437
6455
  // ../packages/models/src/members/member-change-listeners.ts
6438
6456
  function editChangeListenerSet(explicit, inherited, edit, options = { inheritedComplete: true }) {
6439
6457
  if (edit.kind === "reset") {
@@ -8654,6 +8672,16 @@ function firstUnboundParamId(env) {
8654
8672
  }
8655
8673
  return null;
8656
8674
  }
8675
+ function findGenericParamDeclaration(genericParamId, classes) {
8676
+ for (const schemaClass2 of classes) {
8677
+ for (const param of schemaClass2.genericParams ?? []) {
8678
+ if (param.id === genericParamId) {
8679
+ return { param, declaringClass: schemaClass2 };
8680
+ }
8681
+ }
8682
+ }
8683
+ return null;
8684
+ }
8657
8685
  function referencedGenericParams(member, members, seen = /* @__PURE__ */ new Set()) {
8658
8686
  const result = /* @__PURE__ */ new Set();
8659
8687
  collectReferencedGenericParams(member, members, seen, result);
@@ -8885,6 +8913,88 @@ function substituteNestedTypeInfo(typeInfo, env, members) {
8885
8913
  );
8886
8914
  });
8887
8915
  }
8916
+ function substituteInheritedCallableTypeInfo(typeInfo, env, classes, members) {
8917
+ return mapGenericTypeInfo(typeInfo, (generic) => {
8918
+ const entry = env.get(generic.genericParamId);
8919
+ if (entry === void 0) return generic;
8920
+ if (entry.kind === "unbound") {
8921
+ const forwarded = forwardedParamTypeInfo(entry.paramId, classes);
8922
+ return forwarded === null ? generic : { ...forwarded, required: generic.required };
8923
+ }
8924
+ const bound = openBindingTypeInfo(
8925
+ callableBindingMember(entry.memberId, generic.genericParamId, members),
8926
+ env,
8927
+ classes,
8928
+ members
8929
+ );
8930
+ return { ...bound, required: bound.required && generic.required };
8931
+ });
8932
+ }
8933
+ function forwardedParamTypeInfo(genericParamId, classes) {
8934
+ const declaration = findGenericParamDeclaration(genericParamId, classes);
8935
+ if (declaration === null) return null;
8936
+ return {
8937
+ type: 21 /* Generic */,
8938
+ required: true,
8939
+ ownerClassId: declaration.declaringClass.id,
8940
+ genericParamId
8941
+ };
8942
+ }
8943
+ function openBindingTypeInfo(member, env, classes, members) {
8944
+ const resolved = resolveMember(member, members);
8945
+ const nested = (memberId) => openBindingTypeInfo(
8946
+ callableBindingMember(memberId, resolved.name, members),
8947
+ env,
8948
+ classes,
8949
+ members
8950
+ );
8951
+ const param = (genericParamId) => {
8952
+ const entry = env.get(genericParamId);
8953
+ if (entry?.kind === "member") return nested(entry.memberId);
8954
+ if (entry?.kind === "unbound") {
8955
+ return forwardedParamTypeInfo(entry.paramId, classes);
8956
+ }
8957
+ return null;
8958
+ };
8959
+ if (isMemberGenericBase(resolved)) {
8960
+ return param(resolved.genericParamId) ?? genericBindingTypeInfo(resolved, env, members);
8961
+ }
8962
+ const required = isRequiredMember(resolved);
8963
+ if (isMemberClassBase(resolved)) {
8964
+ const typeArguments = {};
8965
+ for (const [parameterId, argument2] of Object.entries(
8966
+ resolved.classArguments ?? {}
8967
+ )) {
8968
+ const argumentType = isForwardedGenericBinding(argument2) ? param(argument2.genericParamId) : nested(argument2.memberId);
8969
+ if (argumentType === null) {
8970
+ return genericBindingTypeInfo(resolved, env, members);
8971
+ }
8972
+ typeArguments[parameterId] = argumentType;
8973
+ }
8974
+ return {
8975
+ type: 7 /* Class */,
8976
+ required,
8977
+ classId: resolved.classId,
8978
+ ...Object.keys(typeArguments).length === 0 ? {} : { typeArguments }
8979
+ };
8980
+ }
8981
+ if (isMemberListBase(resolved)) {
8982
+ return {
8983
+ type: 6 /* List */,
8984
+ required,
8985
+ entryTypeInfo: nested(resolved.entryMemberId)
8986
+ };
8987
+ }
8988
+ if (isMemberDictionaryBase(resolved)) {
8989
+ return {
8990
+ type: 5 /* Dictionary */,
8991
+ required,
8992
+ entryTypeInfo: nested(resolved.entryMemberId),
8993
+ ...resolved.keyEnumId == null ? {} : { keyEnumId: resolved.keyEnumId }
8994
+ };
8995
+ }
8996
+ return genericBindingTypeInfo(resolved, env, members);
8997
+ }
8888
8998
  function callableBindingMember(memberId, slotName, members) {
8889
8999
  const binding = memberIndexFor(members).get(memberId);
8890
9000
  if (binding === void 0) {
@@ -9486,13 +9596,16 @@ function constructionMembers(classId, context) {
9486
9596
  }
9487
9597
  function createMemberDefaultConstructionChecker(document2) {
9488
9598
  const context = contextFor(document2);
9489
- return (member, genericEnv = /* @__PURE__ */ new Map()) => {
9599
+ return (member, genericEnv = /* @__PURE__ */ new Map(), readValueIds) => {
9490
9600
  const previousEnv = context.env;
9601
+ const previousReads = context.readValueIds;
9491
9602
  context.env = genericEnv;
9603
+ context.readValueIds = readValueIds;
9492
9604
  try {
9493
9605
  return defaultSettlesConstruction(member, context, /* @__PURE__ */ new Set());
9494
9606
  } finally {
9495
9607
  context.env = previousEnv;
9608
+ context.readValueIds = previousReads;
9496
9609
  }
9497
9610
  };
9498
9611
  }
@@ -9603,6 +9716,7 @@ function valueSettlesConstruction(member, body, context, path, storedRow = false
9603
9716
  }
9604
9717
  function suppliedValueSettlesConstruction(member, value, context, path) {
9605
9718
  if (typeof value === "string") {
9719
+ context.readValueIds?.add(value);
9606
9720
  let row;
9607
9721
  if (context.document.valueById !== void 0) {
9608
9722
  row = context.document.valueById(value);
@@ -10668,74 +10782,84 @@ function recordStorageKeyDeclaration(sink, valueId, member) {
10668
10782
  if (declaration === STORAGE_KEY_INHERIT) return;
10669
10783
  sink.set(valueId, declaration);
10670
10784
  }
10671
- function createDefaultValueResolutionCache() {
10785
+ function createDefaultSchemaResolutionCache() {
10672
10786
  return {
10673
10787
  memberByIdIndex: null,
10674
10788
  instanceEnvironmentByKey: /* @__PURE__ */ new Map(),
10675
- materializationPlanByClassAndEnvironment: /* @__PURE__ */ new Map(),
10676
10789
  resolvedMemberById: /* @__PURE__ */ new Map(),
10677
10790
  storedSchemaByClassId: /* @__PURE__ */ new Map(),
10678
- validatedInitializerContainers: /* @__PURE__ */ new WeakSet(),
10791
+ validatedInitializerContainers: /* @__PURE__ */ new WeakSet()
10792
+ };
10793
+ }
10794
+ function createDefaultValueResolutionCache(schema = createDefaultSchemaResolutionCache()) {
10795
+ return {
10796
+ schema,
10797
+ materializationPlanByClassAndEnvironment: /* @__PURE__ */ new Map(),
10679
10798
  memberDefaultConstructionChecker: null
10680
10799
  };
10681
10800
  }
10682
10801
  function withIndexedDefaultValueDocument(document2, options = {}) {
10683
10802
  const cache = options.cache ?? createDefaultValueResolutionCache();
10684
- if (cache.memberByIdIndex === null && options.memberById === void 0 && document2.memberById === void 0) {
10685
- cache.memberByIdIndex = new Map(
10803
+ const schemaCache = cache.schema;
10804
+ if (schemaCache.memberByIdIndex === null && options.memberById === void 0 && document2.memberById === void 0) {
10805
+ schemaCache.memberByIdIndex = new Map(
10686
10806
  document2.members.map((member) => [member.id, member])
10687
10807
  );
10688
10808
  }
10689
10809
  const indexed = {
10690
10810
  ...document2,
10691
- memberById: (id) => options.memberById?.(id) ?? document2.memberById?.(id) ?? cache.memberByIdIndex?.get(id) ?? null,
10811
+ memberById: (id) => options.memberById?.(id) ?? document2.memberById?.(id) ?? schemaCache.memberByIdIndex?.get(id) ?? null,
10692
10812
  resolvedMember: (member) => {
10693
10813
  const memberId = "id" in member ? member.id : void 0;
10694
10814
  if (typeof memberId !== "string") {
10695
10815
  return resolveMember(member, document2.members);
10696
10816
  }
10697
- const cached = cache.resolvedMemberById.get(memberId);
10817
+ const cached = schemaCache.resolvedMemberById.get(memberId);
10698
10818
  if (cached !== void 0) return cached;
10699
10819
  const resolved = resolveMember(member, document2.members);
10700
- cache.resolvedMemberById.set(memberId, resolved);
10820
+ schemaCache.resolvedMemberById.set(memberId, resolved);
10701
10821
  return resolved;
10702
10822
  },
10703
10823
  storedInstanceSchema: (classId) => {
10704
- const cached = cache.storedSchemaByClassId.get(classId);
10824
+ const cached = schemaCache.storedSchemaByClassId.get(classId);
10705
10825
  if (cached !== void 0) return cached;
10706
10826
  const schema = resolvedClassSchema(
10707
10827
  classId,
10708
10828
  document2.classes,
10709
10829
  document2.members
10710
10830
  ).surface;
10711
- cache.storedSchemaByClassId.set(classId, schema);
10831
+ schemaCache.storedSchemaByClassId.set(classId, schema);
10712
10832
  return schema;
10713
10833
  },
10714
10834
  instanceEnv: (classId, classArguments2) => {
10715
10835
  const key = `${classId}:${JSON.stringify(classArguments2 ?? null)}`;
10716
- const cached = cache.instanceEnvironmentByKey.get(key);
10836
+ const cached = schemaCache.instanceEnvironmentByKey.get(key);
10717
10837
  if (cached !== void 0) return cached;
10718
10838
  const environment = resolveInstanceEnv(
10719
10839
  classId,
10720
10840
  classArguments2,
10721
10841
  document2.classes
10722
10842
  );
10723
- cache.instanceEnvironmentByKey.set(key, environment);
10843
+ schemaCache.instanceEnvironmentByKey.set(key, environment);
10724
10844
  return environment;
10725
10845
  },
10726
10846
  isInitValueContent: (value) => {
10727
10847
  if (typeof value !== "object" || value === null) return false;
10728
- if (cache.validatedInitializerContainers.has(value)) return true;
10848
+ if (schemaCache.validatedInitializerContainers.has(value)) return true;
10729
10849
  if (!isInitValueContent(value)) return false;
10730
- cache.validatedInitializerContainers.add(value);
10850
+ schemaCache.validatedInitializerContainers.add(value);
10731
10851
  return true;
10732
10852
  },
10733
- memberDefaultSettlesConstruction: (member, environment) => {
10853
+ memberDefaultSettlesConstruction: (member, environment, readValueIds) => {
10734
10854
  cache.memberDefaultConstructionChecker ??= createMemberDefaultConstructionChecker({
10735
10855
  ...indexed,
10736
10856
  constructors: document2.constructors ?? []
10737
10857
  });
10738
- return cache.memberDefaultConstructionChecker(member, environment);
10858
+ return cache.memberDefaultConstructionChecker(
10859
+ member,
10860
+ environment,
10861
+ readValueIds
10862
+ );
10739
10863
  },
10740
10864
  createValueRow: options.createValueRow ?? document2.createValueRow
10741
10865
  };
@@ -10787,12 +10911,20 @@ function buildDefaultClassMaterializationPlan(document2, classId, instanceEnv) {
10787
10911
  ...document2,
10788
10912
  constructors: document2.constructors ?? []
10789
10913
  });
10790
- return storedSchemaOf(document2, classId).flatMap(
10914
+ const reads = {
10915
+ valueIds: /* @__PURE__ */ new Set(),
10916
+ containerIds: /* @__PURE__ */ new Set()
10917
+ };
10918
+ const entries = storedSchemaOf(document2, classId).flatMap(
10791
10919
  (entry) => {
10792
10920
  if (entry.memberId === null) return [];
10793
10921
  const childMember = findMemberInDocument(document2, entry.memberId);
10794
10922
  if (!memberKindOwnsStoredValue(childMember.kind)) return [];
10795
- if (instanceEnv.size === 0 && isConstantMember(document2, resolvedInDocument(document2, childMember)))
10923
+ if (instanceEnv.size === 0 && isConstantMember(
10924
+ document2,
10925
+ resolvedInDocument(document2, childMember),
10926
+ reads
10927
+ ))
10796
10928
  return [];
10797
10929
  const member = substituteMember(
10798
10930
  childMember,
@@ -10804,14 +10936,19 @@ function buildDefaultClassMaterializationPlan(document2, classId, instanceEnv) {
10804
10936
  {
10805
10937
  schemaKey: entry.schemaKey,
10806
10938
  member,
10807
- defaultSettlesConstruction: settlesConstruction(member, instanceEnv),
10939
+ defaultSettlesConstruction: settlesConstruction(
10940
+ member,
10941
+ instanceEnv,
10942
+ reads.valueIds
10943
+ ),
10808
10944
  directScalarBody: directScalarDefaultBody(document2, member)
10809
10945
  }
10810
10946
  ];
10811
10947
  }
10812
10948
  );
10949
+ return { entries, reads };
10813
10950
  }
10814
- function isConstantMember(document2, resolved) {
10951
+ function isConstantMember(document2, resolved, reads) {
10815
10952
  if (isStaticMember(resolved)) return false;
10816
10953
  const fixedness = fixednessOf(resolved, 0 /* Writable */);
10817
10954
  if (fixedness === 0 /* Writable */) return false;
@@ -10824,7 +10961,8 @@ function isConstantMember(document2, resolved) {
10824
10961
  document: document2,
10825
10962
  rows: /* @__PURE__ */ new Set(),
10826
10963
  declarations: /* @__PURE__ */ new Set(),
10827
- classes: /* @__PURE__ */ new Set()
10964
+ classes: /* @__PURE__ */ new Set(),
10965
+ reads
10828
10966
  },
10829
10967
  resolved,
10830
10968
  declared,
@@ -10898,6 +11036,8 @@ function declarationVaries(walk, member, body, rowId, scope) {
10898
11036
  return owned !== Object.keys(value).length;
10899
11037
  }
10900
11038
  if (isMemberListBase(member)) {
11039
+ if (rowId !== null && listKindOf(member) === 1 /* Unordered */)
11040
+ walk.reads?.containerIds.add(rowId);
10901
11041
  const entryIds = listKindOf(member) !== 1 /* Unordered */ ? value : rowId === null ? [] : document2.unorderedListEntryIds?.(rowId) ?? (walk.membership ??= buildUnorderedListMembershipIndex(
10902
11042
  document2.values
10903
11043
  )).get(rowId) ?? [];
@@ -10930,6 +11070,7 @@ function rowVaries(walk, member, valueId, scope) {
10930
11070
  const key = scopeKey(valueId, scope);
10931
11071
  if (walk.rows.has(key)) return false;
10932
11072
  walk.rows.add(key);
11073
+ walk.reads?.valueIds.add(valueId);
10933
11074
  const { document: document2 } = walk;
10934
11075
  const row = document2.valueById?.(valueId) ?? (walk.rowById ??= new Map(
10935
11076
  document2.values.map((value) => [value.id, value])
@@ -11233,6 +11374,7 @@ function buildDefaultMemberValueCore(args, resolvedMember) {
11233
11374
  effectiveClassId,
11234
11375
  childEnv
11235
11376
  );
11377
+ args.document.recordPlanReads?.(materializationPlan.reads);
11236
11378
  const record4 = member.payload === 1 /* Partial */ ? {} : cloneDefaultClassRecord({
11237
11379
  document: args.document,
11238
11380
  projectId: args.projectId,
@@ -11426,7 +11568,7 @@ function completeDefaultClassRecord(args) {
11426
11568
  member: resolvedChildMember,
11427
11569
  defaultSettlesConstruction: defaultSettlesConstruction2,
11428
11570
  directScalarBody
11429
- } of args.member.payload === 1 /* Partial */ ? [] : args.materializationPlan) {
11571
+ } of args.member.payload === 1 /* Partial */ ? [] : args.materializationPlan.entries) {
11430
11572
  if (storageKeyReferencesParentClass(
11431
11573
  normalizeStorageKeyDeclaration(resolvedChildMember.storageKey)
11432
11574
  )) {
@@ -11746,6 +11888,7 @@ function cloneDefaultValueForMemberCore(args, sourceValue) {
11746
11888
  effectiveClassId,
11747
11889
  childEnv
11748
11890
  );
11891
+ args.document.recordPlanReads?.(materializationPlan.reads);
11749
11892
  const anchorsParentClassPartition = sourceValue.constructorArgs == null && completeDefaultClassRecord({
11750
11893
  ...args,
11751
11894
  member,
@@ -12630,6 +12773,230 @@ var EffectiveStorageResolver = class {
12630
12773
  }
12631
12774
  };
12632
12775
 
12776
+ // ../packages/models/src/interfaces/interface-graph.ts
12777
+ var CircularInterfaceExtensionError = class extends Error {
12778
+ constructor(interfaceId, chain) {
12779
+ super(
12780
+ `Circular interface extension detected at "${interfaceId}"; chain: ${chain.join(" -> ")}`
12781
+ );
12782
+ this.interfaceId = interfaceId;
12783
+ this.chain = chain;
12784
+ this.name = "CircularInterfaceExtensionError";
12785
+ }
12786
+ interfaceId;
12787
+ chain;
12788
+ };
12789
+ function resolveInterfaceClosure(interfaceId, interfaces) {
12790
+ const byId = new Map(
12791
+ interfaces.map((neoInterface) => [neoInterface.id, neoInterface])
12792
+ );
12793
+ const result = [];
12794
+ const emitted = /* @__PURE__ */ new Set();
12795
+ const visiting = [];
12796
+ const visitingSet = /* @__PURE__ */ new Set();
12797
+ const visit = (id) => {
12798
+ if (visitingSet.has(id)) {
12799
+ throw new CircularInterfaceExtensionError(id, [...visiting, id]);
12800
+ }
12801
+ if (emitted.has(id)) return;
12802
+ const neoInterface = byId.get(id);
12803
+ if (!neoInterface) return;
12804
+ visiting.push(id);
12805
+ visitingSet.add(id);
12806
+ result.push(neoInterface);
12807
+ emitted.add(id);
12808
+ for (const parentId of neoInterface.extendsInterfaceIds ?? []) {
12809
+ visit(parentId);
12810
+ }
12811
+ visiting.pop();
12812
+ visitingSet.delete(id);
12813
+ };
12814
+ visit(interfaceId);
12815
+ return result;
12816
+ }
12817
+ function resolveImplementedInterfaces(classId, classes, interfaces) {
12818
+ const result = [];
12819
+ const seen = /* @__PURE__ */ new Set();
12820
+ for (const schemaClass2 of resolveInheritanceChain(classId, classes)) {
12821
+ for (const interfaceId of schemaClass2.implementsInterfaceIds ?? []) {
12822
+ for (const neoInterface of resolveInterfaceClosure(
12823
+ interfaceId,
12824
+ interfaces
12825
+ )) {
12826
+ if (seen.has(neoInterface.id)) continue;
12827
+ seen.add(neoInterface.id);
12828
+ result.push(neoInterface);
12829
+ }
12830
+ }
12831
+ }
12832
+ return result;
12833
+ }
12834
+ function classImplementsInterface(classId, interfaceId, classes, interfaces) {
12835
+ return resolveImplementedInterfaces(classId, classes, interfaces).some(
12836
+ (neoInterface) => neoInterface.id === interfaceId
12837
+ );
12838
+ }
12839
+
12840
+ // ../packages/manifest/src/value-comparison.ts
12841
+ function isObjectRecord(value) {
12842
+ return typeof value === "object" && value !== null && !Array.isArray(value);
12843
+ }
12844
+
12845
+ // ../packages/neoscript-runtime/src/values/canonical-json.ts
12846
+ function canonicalJsonStringify(value) {
12847
+ return JSON.stringify(toCanonicalJsonValue(value));
12848
+ }
12849
+ function toCanonicalJsonValue(value) {
12850
+ if (value === null) return null;
12851
+ if (value === void 0) return void 0;
12852
+ if (value instanceof Date) return value.toISOString();
12853
+ if (typeof value === "string") return value;
12854
+ if (typeof value === "boolean") return value;
12855
+ if (typeof value === "number") {
12856
+ if (!Number.isFinite(value)) {
12857
+ throw new Error("Cannot canonicalize a non-finite number.");
12858
+ }
12859
+ return value;
12860
+ }
12861
+ if (typeof value === "bigint") {
12862
+ throw new Error("Cannot canonicalize bigint values.");
12863
+ }
12864
+ if (typeof value === "symbol") {
12865
+ throw new Error("Cannot canonicalize symbol values.");
12866
+ }
12867
+ if (typeof value === "function") {
12868
+ throw new Error("Cannot canonicalize function values.");
12869
+ }
12870
+ if (Array.isArray(value)) {
12871
+ return value.map((item) => {
12872
+ const canonicalItem = toCanonicalJsonValue(item);
12873
+ if (canonicalItem === void 0) return null;
12874
+ return canonicalItem;
12875
+ });
12876
+ }
12877
+ const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
12878
+ const canonicalObject = {};
12879
+ for (const [key, entryValue] of entries) {
12880
+ const canonicalValue = toCanonicalJsonValue(entryValue);
12881
+ if (canonicalValue === void 0) continue;
12882
+ canonicalObject[key] = canonicalValue;
12883
+ }
12884
+ return canonicalObject;
12885
+ }
12886
+
12887
+ // ../src/database/compiled-construction-types.ts
12888
+ function compiledConstructionTypeMembers(members, bodies, projectId) {
12889
+ const created = [];
12890
+ let existingIds;
12891
+ const byType = /* @__PURE__ */ new Map();
12892
+ const key = (type) => canonicalJsonStringify(type);
12893
+ const intern = (type) => {
12894
+ const signature = key(type);
12895
+ const existing = byType.get(signature);
12896
+ if (existing !== void 0) return existing;
12897
+ if (type.type === 21 /* Generic */ || type.type === NS_TYPE_UNKNOWN)
12898
+ return null;
12899
+ const id = v5_default(
12900
+ `neo:compiled-construction-type:${projectId}:${signature}`,
12901
+ v5_default.URL
12902
+ );
12903
+ existingIds ??= new Set(members.map((member) => member.id));
12904
+ if (existingIds.has(id)) {
12905
+ byType.set(signature, id);
12906
+ return id;
12907
+ }
12908
+ const common = {
12909
+ id,
12910
+ projectId,
12911
+ createdAt: 0,
12912
+ updatedAt: 0,
12913
+ name: "Type argument",
12914
+ kind: type.type,
12915
+ requirement: type.required ? 1 /* Required */ : 0 /* Optional */
12916
+ };
12917
+ const fields = (() => {
12918
+ if (type.type === 6 /* List */ || type.type === 5 /* Dictionary */) {
12919
+ const entryMemberId = intern(type.entryTypeInfo);
12920
+ if (entryMemberId === null) return null;
12921
+ return {
12922
+ entryMemberId,
12923
+ ...type.keyEnumId === void 0 ? {} : { keyKind: 1 /* Enum */, keyEnumId: type.keyEnumId }
12924
+ };
12925
+ } else if (type.type === 7 /* Class */) {
12926
+ const classArguments2 = {};
12927
+ for (const [parameter3, argument2] of Object.entries(
12928
+ type.typeArguments ?? {}
12929
+ )) {
12930
+ const memberId = intern(argument2);
12931
+ if (memberId === null) return null;
12932
+ classArguments2[parameter3] = {
12933
+ kind: 1 /* Member */,
12934
+ memberId
12935
+ };
12936
+ }
12937
+ return {
12938
+ classId: type.classId,
12939
+ ...Object.keys(classArguments2).length === 0 ? {} : { classArguments: classArguments2 }
12940
+ };
12941
+ } else if (type.type === 8 /* Enum */) {
12942
+ return { enumId: type.enumId };
12943
+ } else if (type.type === 25 /* NSDelegate */) {
12944
+ return {
12945
+ returnTypeInfo: type.returnTypeInfo,
12946
+ argumentTypes: type.argumentTypes
12947
+ };
12948
+ } else if (type.type === 26 /* NSAction */) {
12949
+ return { argumentTypes: type.argumentTypes };
12950
+ } else if (type.type === 22 /* Interface */ || type.type === 9 /* Lookup */ || type.type === 18 /* DialogueLookup */) {
12951
+ return null;
12952
+ } else {
12953
+ return {};
12954
+ }
12955
+ })();
12956
+ if (fields === null) return null;
12957
+ created.push({ ...common, ...fields });
12958
+ existingIds.add(id);
12959
+ byType.set(signature, id);
12960
+ return id;
12961
+ };
12962
+ const visited = /* @__PURE__ */ new Set();
12963
+ const visit = (value) => {
12964
+ if (value === null || typeof value !== "object" || visited.has(value))
12965
+ return;
12966
+ visited.add(value);
12967
+ const argumentsValue = getField(
12968
+ getField(value, "schemaClassInfo"),
12969
+ "typeArguments"
12970
+ );
12971
+ if (argumentsValue !== null && typeof argumentsValue === "object") {
12972
+ for (const type of Object.values(argumentsValue))
12973
+ if (isNSTypeInfo(type)) intern(type);
12974
+ }
12975
+ for (const child of Object.values(value)) visit(child);
12976
+ };
12977
+ for (const body of bodies) visit(body);
12978
+ return created;
12979
+ }
12980
+ function withCompiledConstructionTypes(document2, body) {
12981
+ const members = document2.members;
12982
+ const projectId = getField(document2.project, "id");
12983
+ if (!Array.isArray(members)) {
12984
+ throw new Error("Construction type descriptors require a member array.");
12985
+ }
12986
+ if (!members.every(
12987
+ (member) => typeof getField(member, "id") === "string"
12988
+ )) {
12989
+ throw new Error(
12990
+ "Construction type descriptors require an ID on every member record."
12991
+ );
12992
+ }
12993
+ if (typeof projectId !== "string") {
12994
+ throw new Error("Construction type descriptors require a project ID.");
12995
+ }
12996
+ const created = compiledConstructionTypeMembers(members, [body], projectId);
12997
+ return created.length === 0 ? document2 : { ...document2, members: [...members, ...created] };
12998
+ }
12999
+
12633
13000
  // ../packages/neoscript-runtime/src/neoscript/debug.ts
12634
13001
  function snapshotNeoScriptFrames(state) {
12635
13002
  const frames = state.frames.slice(-64).reverse().map((frame) => Object.freeze({ ...frame }));
@@ -13595,8 +13962,7 @@ var PendingInitializerDependency = class extends NSGetterRuntimeError {
13595
13962
  var OWNERSHIP_CHAIN_PREFIXES = [
13596
13963
  "generic-parent-resolution:",
13597
13964
  "member-owner-resolution:",
13598
- "owned-value-parents:",
13599
- "declaration-owner-resolution:"
13965
+ "owned-value-parents:"
13600
13966
  ];
13601
13967
  var CONTAINER_ENTRIES_PREFIX = "container-entries:";
13602
13968
  function ownershipChainRead(kind, rowId) {
@@ -13605,10 +13971,6 @@ function ownershipChainRead(kind, rowId) {
13605
13971
  function containerEntriesRead(containerId) {
13606
13972
  return `${CONTAINER_ENTRIES_PREFIX}${containerId}`;
13607
13973
  }
13608
- var OWNERSHIP_CHAIN_READ = ownershipChainRead(
13609
- "member-owner-resolution",
13610
- "*"
13611
- );
13612
13974
  function classifyUnattributableRead(reason) {
13613
13975
  for (const prefix of OWNERSHIP_CHAIN_PREFIXES) {
13614
13976
  if (reason.startsWith(prefix)) {
@@ -13639,12 +14001,13 @@ function valueIdsWithSourceChains(targetValueIds, valuesById) {
13639
14001
  }
13640
14002
  return result;
13641
14003
  }
13642
- function initializerOwnerContext(document2, valueId, rootOwners, valuesById) {
14004
+ function initializerOwnerContext(document2, valueId, rootOwners, valuesById, recordValueRead) {
13643
14005
  const visited = /* @__PURE__ */ new Set();
13644
14006
  let currentId = valueId;
13645
14007
  let lexicalRoot = rootOwners.get(valueId);
13646
14008
  while (currentId !== null && !visited.has(currentId)) {
13647
14009
  visited.add(currentId);
14010
+ recordValueRead?.(currentId);
13648
14011
  const sourceValueId = valuesById.get(currentId)?.sourceValueId;
13649
14012
  if (typeof sourceValueId !== "string") break;
13650
14013
  currentId = sourceValueId;
@@ -14840,9 +15203,8 @@ var InitializerReadSet = class {
14840
15203
  /**
14841
15204
  * The unattributable reads by scope, for a fork of the same document to
14842
15205
  * re-attribute; see {@link classifyUnattributableRead}. Ownership-chain
14843
- * reads collapse to one flag: their inputs are already in `valueIds`.
15206
+ * reads need no record: their inputs are already in `valueIds`.
14844
15207
  */
14845
- hasOwnershipChainRead = false;
14846
15208
  containerEntryReadIds = /* @__PURE__ */ new Set();
14847
15209
  corpusReadReasons = /* @__PURE__ */ new Set();
14848
15210
  recordUnattributableValueRead = (reason) => {
@@ -14850,7 +15212,6 @@ var InitializerReadSet = class {
14850
15212
  const read = classifyUnattributableRead(reason);
14851
15213
  switch (read.scope) {
14852
15214
  case "ownership-chain" /* OwnershipChain */:
14853
- this.hasOwnershipChainRead = true;
14854
15215
  return;
14855
15216
  case "container" /* Container */:
14856
15217
  this.containerEntryReadIds.add(read.containerId);
@@ -14895,17 +15256,61 @@ function getWorldGridQueryIndex(source) {
14895
15256
  building.delete(source.cacheKey);
14896
15257
  }
14897
15258
  }
15259
+ function readsAny(reads, ids) {
15260
+ for (const id of ids) if (reads.has(id)) return true;
15261
+ return false;
15262
+ }
14898
15263
  var WorldGridQueryIndex = class {
14899
- constructor(grids, placements, geometryReads, metrics) {
15264
+ constructor(grids, placements, geometryReads, kinds, placedRecordIds, metrics) {
14900
15265
  this.grids = grids;
14901
15266
  this.placements = placements;
14902
15267
  this.geometryReads = geometryReads;
15268
+ this.kinds = kinds;
15269
+ this.placedRecordIds = placedRecordIds;
14903
15270
  this.metrics = metrics;
14904
15271
  }
14905
15272
  grids;
14906
15273
  placements;
14907
15274
  geometryReads;
15275
+ kinds;
15276
+ placedRecordIds;
14908
15277
  metrics;
15278
+ /**
15279
+ * Whether edits to these rows can change the index. Ownership-chain reads
15280
+ * need no flag: every ancestor they visit is in `geometryReads.valueIds`.
15281
+ * Discovery checks every row's effective class without recording a read,
15282
+ * so a changed row it could now index as a grid counts as well. A record it
15283
+ * classed by placement keeps that placement through its own writes, so only
15284
+ * its stamp can change.
15285
+ */
15286
+ readsValues(valueIds, classIdOf, stampOf) {
15287
+ const reads = this.geometryReads;
15288
+ if (reads.corpusReadReasons.size > 0) return true;
15289
+ for (const id of valueIds) {
15290
+ if (reads.valueIds.has(id)) return true;
15291
+ const classId = this.placedRecordIds.has(id) ? stampOf(id) : classIdOf(id);
15292
+ if (classId !== null && this.kinds.get(classId) === NeoWorldSystemClassKind.TileGrid)
15293
+ return true;
15294
+ }
15295
+ return false;
15296
+ }
15297
+ /** Whether entry changes in these containers can change the index. */
15298
+ readsContainers(containerIds) {
15299
+ const reads = this.geometryReads;
15300
+ for (const id of containerIds) {
15301
+ if (reads.containerIds.has(id)) return true;
15302
+ if (reads.containerEntryReadIds.has(id)) return true;
15303
+ }
15304
+ return false;
15305
+ }
15306
+ /** Whether edits to these localized texts can change the index. */
15307
+ readsLocalizedTexts(textIds) {
15308
+ return readsAny(this.geometryReads.localizedTextIds, textIds);
15309
+ }
15310
+ /** Whether edits to these variants can change the index. */
15311
+ readsVariants(variantIds) {
15312
+ return readsAny(this.geometryReads.variantIds, variantIds);
15313
+ }
14909
15314
  placement(valueId, reads) {
14910
15315
  reads?.add({ kind: "placement", valueId });
14911
15316
  const matches = this.placements.get(valueId) ?? [];
@@ -15069,8 +15474,13 @@ function buildIndex(source) {
15069
15474
  occupiedCells += 1;
15070
15475
  };
15071
15476
  const discoveryReads = new InitializerReadSet();
15477
+ const placedRecordIds = /* @__PURE__ */ new Set();
15072
15478
  for (const root of source.rows) {
15073
- const grid = typeof root.classId !== "string" ? source.readRow(root.id, discoveryReads) : root;
15479
+ let grid = root;
15480
+ if (typeof root.classId !== "string") {
15481
+ if (record(root.value) !== null) placedRecordIds.add(root.id);
15482
+ grid = source.readRow(root.id, discoveryReads);
15483
+ }
15074
15484
  if (typeof grid?.classId !== "string" || kinds.get(grid.classId) !== NeoWorldSystemClassKind.TileGrid)
15075
15485
  continue;
15076
15486
  const effectiveGrid = readRow(root.id);
@@ -15163,11 +15573,18 @@ function buildIndex(source) {
15163
15573
  }
15164
15574
  }
15165
15575
  }
15166
- return new WorldGridQueryIndex(grids, placements, reads, {
15167
- rowsScanned: source.rows.length,
15168
- placementsIndexed,
15169
- occupiedCells
15170
- });
15576
+ return new WorldGridQueryIndex(
15577
+ grids,
15578
+ placements,
15579
+ reads,
15580
+ kinds,
15581
+ placedRecordIds,
15582
+ {
15583
+ rowsScanned: source.rows.length,
15584
+ placementsIndexed,
15585
+ occupiedCells
15586
+ }
15587
+ );
15171
15588
  }
15172
15589
  function record(value) {
15173
15590
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
@@ -15615,70 +16032,6 @@ function floatFromDecimalString(value) {
15615
16032
  return Number(value);
15616
16033
  }
15617
16034
 
15618
- // ../packages/models/src/interfaces/interface-graph.ts
15619
- var CircularInterfaceExtensionError = class extends Error {
15620
- constructor(interfaceId, chain) {
15621
- super(
15622
- `Circular interface extension detected at "${interfaceId}"; chain: ${chain.join(" -> ")}`
15623
- );
15624
- this.interfaceId = interfaceId;
15625
- this.chain = chain;
15626
- this.name = "CircularInterfaceExtensionError";
15627
- }
15628
- interfaceId;
15629
- chain;
15630
- };
15631
- function resolveInterfaceClosure(interfaceId, interfaces) {
15632
- const byId = new Map(
15633
- interfaces.map((neoInterface) => [neoInterface.id, neoInterface])
15634
- );
15635
- const result = [];
15636
- const emitted = /* @__PURE__ */ new Set();
15637
- const visiting = [];
15638
- const visitingSet = /* @__PURE__ */ new Set();
15639
- const visit = (id) => {
15640
- if (visitingSet.has(id)) {
15641
- throw new CircularInterfaceExtensionError(id, [...visiting, id]);
15642
- }
15643
- if (emitted.has(id)) return;
15644
- const neoInterface = byId.get(id);
15645
- if (!neoInterface) return;
15646
- visiting.push(id);
15647
- visitingSet.add(id);
15648
- result.push(neoInterface);
15649
- emitted.add(id);
15650
- for (const parentId of neoInterface.extendsInterfaceIds ?? []) {
15651
- visit(parentId);
15652
- }
15653
- visiting.pop();
15654
- visitingSet.delete(id);
15655
- };
15656
- visit(interfaceId);
15657
- return result;
15658
- }
15659
- function resolveImplementedInterfaces(classId, classes, interfaces) {
15660
- const result = [];
15661
- const seen = /* @__PURE__ */ new Set();
15662
- for (const schemaClass2 of resolveInheritanceChain(classId, classes)) {
15663
- for (const interfaceId of schemaClass2.implementsInterfaceIds ?? []) {
15664
- for (const neoInterface of resolveInterfaceClosure(
15665
- interfaceId,
15666
- interfaces
15667
- )) {
15668
- if (seen.has(neoInterface.id)) continue;
15669
- seen.add(neoInterface.id);
15670
- result.push(neoInterface);
15671
- }
15672
- }
15673
- }
15674
- return result;
15675
- }
15676
- function classImplementsInterface(classId, interfaceId, classes, interfaces) {
15677
- return resolveImplementedInterfaces(classId, classes, interfaces).some(
15678
- (neoInterface) => neoInterface.id === interfaceId
15679
- );
15680
- }
15681
-
15682
16035
  // ../packages/models/src/members/read-class-member.ts
15683
16036
  function readClassMember(args) {
15684
16037
  const { member, schemaKey } = args;
@@ -16697,8 +17050,8 @@ function evaluatorResolutionCache(ctx) {
16697
17050
  compiledFunctionByMemberId: /* @__PURE__ */ new Map(),
16698
17051
  compiledGetterByMemberId: /* @__PURE__ */ new Map(),
16699
17052
  compiledSetterByMemberId: /* @__PURE__ */ new Map(),
16700
- defaultValueResolutionCache: createDefaultValueResolutionCache(),
16701
- validatedConstructorDescriptorByInfo: /* @__PURE__ */ new WeakMap(),
17053
+ defaultSchema: createDefaultSchemaResolutionCache(),
17054
+ valueGenerations: /* @__PURE__ */ new WeakMap(),
16702
17055
  effectiveStorageResolver: void 0
16703
17056
  };
16704
17057
  resolutionCacheByMembers.set(members, {
@@ -16737,6 +17090,24 @@ function cachedInstanceEnv(classId, classArguments2, ctx) {
16737
17090
  function cachedIsInitValueContent(value, ctx) {
16738
17091
  return evaluatorDefaultValueDocument(ctx).isInitValueContent(value);
16739
17092
  }
17093
+ function evaluatorValueGeneration(ctx) {
17094
+ const { values, databaseVM } = ctx.vm;
17095
+ const valueGeneration = databaseVM?.valueGeneration;
17096
+ const resolution = evaluatorResolutionCache(ctx);
17097
+ const key = databaseVM ?? values;
17098
+ const entry = resolution.valueGenerations.get(key);
17099
+ if (entry !== void 0 && entry.values === values && entry.valueGeneration === valueGeneration) {
17100
+ return entry;
17101
+ }
17102
+ const generation = {
17103
+ values,
17104
+ valueGeneration,
17105
+ defaults: createDefaultValueResolutionCache(resolution.defaultSchema),
17106
+ constructorDescriptors: /* @__PURE__ */ new WeakMap()
17107
+ };
17108
+ resolution.valueGenerations.set(key, generation);
17109
+ return generation;
17110
+ }
16740
17111
  function evaluatorDefaultValueDocument(ctx) {
16741
17112
  if (ctx.__defaultValueDocument !== void 0) {
16742
17113
  return ctx.__defaultValueDocument;
@@ -16757,7 +17128,7 @@ function evaluatorDefaultValueDocument(ctx) {
16757
17128
  projectFiles: ctx.vm.projectFiles ?? [],
16758
17129
  textureTemplates: ctx.vm.textureTemplates ?? []
16759
17130
  },
16760
- { cache: evaluatorResolutionCache(ctx).defaultValueResolutionCache }
17131
+ { cache: evaluatorValueGeneration(ctx).defaults }
16761
17132
  );
16762
17133
  ctx.__defaultValueDocument = document2;
16763
17134
  return document2;
@@ -18324,7 +18695,11 @@ function evalInstructions(instructions, scope, ctx, options) {
18324
18695
  }
18325
18696
  let targetTypeInfo = ins.target.typeInfo;
18326
18697
  if (lookupAssignment && targetTypeInfo.type !== 9 /* Lookup */ && targetTypeInfo.type !== 18 /* DialogueLookup */) {
18327
- targetTypeInfo = {
18698
+ targetTypeInfo = member.collectionMemberId === void 0 ? {
18699
+ type: 9 /* Lookup */,
18700
+ required: targetTypeInfo.required,
18701
+ entryTypeInfo: targetTypeInfo
18702
+ } : {
18328
18703
  type: 9 /* Lookup */,
18329
18704
  required: targetTypeInfo.required,
18330
18705
  entryTypeInfo: targetTypeInfo,
@@ -19208,8 +19583,12 @@ function bindOmittedConstantSlot(destination, member, value, ctx) {
19208
19583
  if (isMemberClassBase(member) || isMemberListBase(member) || isMemberDictionaryBase(member))
19209
19584
  return false;
19210
19585
  const resolved = resolveMember(member, ctx.vm.members);
19211
- if (!isConstantMember(constructorDefaultValueDocument(ctx, member), resolved))
19212
- return false;
19586
+ const decision = constantMemberDecision(
19587
+ constructorDefaultValueDocument(ctx, member),
19588
+ resolved
19589
+ );
19590
+ recordDeclarationReads(ctx, decision.reads);
19591
+ if (!decision.constant) return false;
19213
19592
  const { createdValues } = construction;
19214
19593
  const staged = createdValues.length;
19215
19594
  const row = materializeConstructorArgumentValue({
@@ -21005,6 +21384,13 @@ function runtimeTypeInfoForMember(rawMember, env, ctx, seen) {
21005
21384
  };
21006
21385
  }
21007
21386
  if (isMemberLookup(member)) {
21387
+ if (member.collectionMemberId === void 0) {
21388
+ const entryTypeInfo2 = {
21389
+ ...substituteRuntimeTypeInfo(member.declaredTypeInfo, env, ctx),
21390
+ required: isMultiSelectionMember(member) ? true : false
21391
+ };
21392
+ return isMultiSelectionMember(member) ? { type: 9 /* Lookup */, required, entryTypeInfo: entryTypeInfo2 } : entryTypeInfo2;
21393
+ }
21008
21394
  const collection = evalMemberById(ctx.vm, member.collectionMemberId);
21009
21395
  if (collection === null) {
21010
21396
  throw new NSGetterRuntimeError(
@@ -21592,6 +21978,17 @@ function ensureVirtualExpansionIndexed(rows, ctx, existingIndexes) {
21592
21978
  indexes3.indexedVirtualRowSets.add(rows);
21593
21979
  }
21594
21980
  var constantDeclarationRoots = /* @__PURE__ */ new WeakMap();
21981
+ function recordDeclarationReads(ctx, reads) {
21982
+ for (const id of reads.valueIds) ctx.valueDependencies?.add(id);
21983
+ for (const id of reads.containerIds) ctx.containerDependencies?.add(id);
21984
+ }
21985
+ function constantMemberDecision(document2, member) {
21986
+ const reads = {
21987
+ valueIds: /* @__PURE__ */ new Set(),
21988
+ containerIds: /* @__PURE__ */ new Set()
21989
+ };
21990
+ return { constant: isConstantMember(document2, member, reads), reads };
21991
+ }
21595
21992
  function readDeclarationDefault(member, ctx) {
21596
21993
  if (member?.defaultValue === void 0 || member.defaultValue === null) {
21597
21994
  return { matched: false };
@@ -21606,16 +22003,20 @@ function readDeclarationDefault(member, ctx) {
21606
22003
  constantDeclarationRoots.set(session, shared);
21607
22004
  }
21608
22005
  }
21609
- const known = shared?.get(member.id);
21610
- if (typeof known === "string" && session?.has(known) === true) {
22006
+ let known = shared?.get(member.id);
22007
+ if (known !== void 0) recordDeclarationReads(ctx, known.reads);
22008
+ if (known?.root !== void 0 && session?.has(known.root) === true) {
21611
22009
  return {
21612
22010
  matched: true,
21613
- value: resolveValueIfIdForMember(known, member, ctx)
22011
+ value: resolveValueIfIdForMember(known.root, member, ctx)
21614
22012
  };
21615
22013
  }
21616
22014
  const document2 = constructorDefaultValueDocument(ctx, member);
21617
- const constant = shared !== void 0 && known !== false && (known !== void 0 || isConstantMember(document2, member));
21618
- if (shared !== void 0 && !constant) shared.set(member.id, false);
22015
+ if (shared !== void 0 && known === void 0) {
22016
+ known = constantMemberDecision(document2, member);
22017
+ recordDeclarationReads(ctx, known.reads);
22018
+ shared.set(member.id, known);
22019
+ }
21619
22020
  const created = [];
21620
22021
  const closeFrame = pushConstructionFrame(ctx, `${member.name} declaration`);
21621
22022
  try {
@@ -21641,7 +22042,7 @@ function readDeclarationDefault(member, ctx) {
21641
22042
  )
21642
22043
  });
21643
22044
  stageConstructedRows([root, ...created], ctx);
21644
- if (constant) shared?.set(member.id, root.id);
22045
+ if (known?.constant === true) known.root = root.id;
21645
22046
  return {
21646
22047
  matched: true,
21647
22048
  value: resolveValueIfIdForMember(root.id, member, ctx)
@@ -21965,6 +22366,10 @@ function resolveMemberForValueRow(row, ctx, visited) {
21965
22366
  function worldGridQueryIndexForContext(context) {
21966
22367
  const ctx = withEvaluationRuntime(context, []);
21967
22368
  const vm = ctx.vm;
22369
+ const database = vm.databaseVM;
22370
+ const overlayRevision = ctx.__valueOverlay instanceof LazyValueOverlay ? ctx.__valueOverlay.worldRevision : 0;
22371
+ if (overlayRevision === 0 && database?.worldGridQueryIndex !== void 0)
22372
+ return database.worldGridQueryIndex();
21968
22373
  const readContexts = /* @__PURE__ */ new WeakMap();
21969
22374
  let geometryOverlay;
21970
22375
  const readContext = (reads) => {
@@ -21987,24 +22392,26 @@ function worldGridQueryIndexForContext(context) {
21987
22392
  readContexts.set(reads, next);
21988
22393
  return next;
21989
22394
  };
21990
- const overlayRevision = ctx.__valueOverlay instanceof LazyValueOverlay ? ctx.__valueOverlay.worldRevision : 0;
22395
+ const recording = (reads, read) => database?.recordVirtualInstanceReads === void 0 ? read() : database.recordVirtualInstanceReads(reads, read);
22396
+ const host = vm.worldQueryCache;
21991
22397
  return getWorldGridQueryIndex({
21992
- cacheKey: overlayRevision > 0 && ctx.__valueOverlay !== void 0 ? ctx.__valueOverlay : vm.worldQueryCache?.key ?? vm.databaseVM?.evaluatorIndexes ?? vm.values,
22398
+ cacheKey: overlayRevision > 0 && ctx.__valueOverlay !== void 0 ? ctx.__valueOverlay : host?.key ?? vm.databaseVM?.evaluatorIndexes ?? vm.values,
21993
22399
  revision: [
21994
- ...vm.worldQueryCache?.revision ?? vm.databaseVM?.worldQueryRevision ?? [],
21995
- vm.values,
21996
- vm.classes,
21997
- vm.members,
21998
- vm.internalRecordRelations,
21999
- vm.variants,
22000
- vm.variantFolders,
22001
- vm.schemaRevision,
22400
+ ...host?.revision ?? [
22401
+ vm.values,
22402
+ vm.classes,
22403
+ vm.members,
22404
+ vm.internalRecordRelations,
22405
+ vm.variants,
22406
+ vm.variantFolders,
22407
+ vm.schemaRevision
22408
+ ],
22002
22409
  ...overlayRevision === 0 ? [] : [ctx.__valueOverlay, overlayRevision]
22003
22410
  ],
22004
22411
  rows: vm.values,
22005
22412
  classes: vm.classes,
22006
22413
  relations: vm.internalRecordRelations ?? [],
22007
- readRow(id, reads) {
22414
+ readRow: (id, reads) => recording(reads, () => {
22008
22415
  const current = readContext(reads);
22009
22416
  const row = evalValueById(
22010
22417
  current,
@@ -22015,8 +22422,8 @@ function worldGridQueryIndexForContext(context) {
22015
22422
  if (row === null || typeof row.classId === "string") return row;
22016
22423
  const classId = classIdForValueRow(row, current);
22017
22424
  return classId === void 0 ? row : { ...row, classId };
22018
- },
22019
- readField(id, key, reads) {
22425
+ }),
22426
+ readField: (id, key, reads) => recording(reads, () => {
22020
22427
  const current = readContext(reads);
22021
22428
  const row = evalValueById(
22022
22429
  current,
@@ -22035,8 +22442,8 @@ function worldGridQueryIndexForContext(context) {
22035
22442
  thisValue: row.value,
22036
22443
  thisValueRowId: row.id
22037
22444
  });
22038
- },
22039
- valueId(value, reads) {
22445
+ }),
22446
+ valueId: (value, reads) => recording(reads, () => {
22040
22447
  const current = readContext(reads);
22041
22448
  if (typeof value === "string" && evalValueById(
22042
22449
  current,
@@ -22046,7 +22453,7 @@ function worldGridQueryIndexForContext(context) {
22046
22453
  ) !== null)
22047
22454
  return value;
22048
22455
  return trackedRowForValueReference(value, current)?.id ?? null;
22049
- }
22456
+ })
22050
22457
  });
22051
22458
  }
22052
22459
  function readSystemNativeField(value, key, ctx) {
@@ -23685,7 +24092,7 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
23685
24092
  }
23686
24093
  const genericSlot = ctx.__constructionGenericSlots?.toReversed().find((slot) => slot.classId === classId) ?? ctx.__storedConstructionReplaySlot;
23687
24094
  const slotArguments = genericSlot?.classId === classId ? genericSlot.classArguments : void 0;
23688
- const descriptorCache = evaluatorResolutionCache(ctx).validatedConstructorDescriptorByInfo;
24095
+ const descriptorCache = evaluatorValueGeneration(ctx).constructorDescriptors;
23689
24096
  const descriptorCacheKey = `${requireEveryRequiredField}:${ctx.storedConstructionReplay === true}:${JSON.stringify(slotArguments ?? info.schemaClassInfo.typeArguments ?? null)}`;
23690
24097
  const cachedDescriptor = descriptorCache.get(info)?.get(descriptorCacheKey);
23691
24098
  if (cachedDescriptor !== void 0) return cachedDescriptor;
@@ -24303,6 +24710,8 @@ function constructClassValue(info, scope, ctx) {
24303
24710
  }
24304
24711
  }
24305
24712
  function constructorDefaultValueDocument(ctx, syntheticMember) {
24713
+ const database = ctx.vm.databaseVM;
24714
+ const entryIdsOf = database?.unorderedListEntryIds?.bind(database);
24306
24715
  return {
24307
24716
  listenerDefaultCapture: ctx.listenerDefaultCapture,
24308
24717
  beforeValueAllocation: ctx.beforeValueAllocation,
@@ -24315,11 +24724,24 @@ function constructorDefaultValueDocument(ctx, syntheticMember) {
24315
24724
  // immutable base plus its indexes avoids copying and linearly scanning
24316
24725
  // the entire project for every constructor replay.
24317
24726
  values: ctx.vm.values,
24318
- memberById: ctx.vm.databaseVM?.memberById,
24319
- valueById: ctx.vm.databaseVM?.defaultValueById ?? ctx.vm.databaseVM?.valueById,
24727
+ memberById: database?.memberById,
24728
+ // The declaration rows a default clones are reads of this evaluation.
24729
+ ...database === void 0 ? {} : {
24730
+ valueById: (id) => {
24731
+ ctx.valueDependencies?.add(id);
24732
+ return database.defaultValueById !== void 0 ? database.defaultValueById(id) : database.valueById(id);
24733
+ }
24734
+ },
24735
+ ...entryIdsOf === void 0 ? {} : {
24736
+ unorderedListEntryIds: (containerId) => {
24737
+ ctx.containerDependencies?.add(containerId);
24738
+ return entryIdsOf(containerId);
24739
+ }
24740
+ },
24320
24741
  resolvedMember: (member) => member === syntheticMember ? syntheticMember : cachedResolvedMember(member, ctx),
24321
24742
  storedInstanceSchema: (nestedClassId) => cachedStoredInstanceSchema(nestedClassId, ctx),
24322
24743
  storedInstanceMaterializationPlan: (nestedClassId, instanceEnv) => cachedStoredInstanceMaterializationPlan(nestedClassId, instanceEnv, ctx),
24744
+ recordPlanReads: (reads) => recordDeclarationReads(ctx, reads),
24323
24745
  instanceEnv: (nestedClassId, classArguments2) => cachedInstanceEnv(nestedClassId, classArguments2, ctx),
24324
24746
  isInitValueContent: (value) => cachedIsInitValueContent(value, ctx),
24325
24747
  createValueRow: (projectId, body) => buildNewValue(
@@ -27832,17 +28254,21 @@ function projectListenerEndpoint(args) {
27832
28254
 
27833
28255
  // ../packages/models/src/members/lookup-declared-type.ts
27834
28256
  function lookupDeclaredTypeInfo(member, collectionTypeInfo) {
27835
- if (collectionTypeInfo === null) return null;
27836
- if (collectionTypeInfo.type !== 6 /* List */ && collectionTypeInfo.type !== 5 /* Dictionary */) {
27837
- return null;
27838
- }
27839
- const entryTypeInfo = member.declaredTypeInfo ?? collectionTypeInfo.entryTypeInfo;
28257
+ const entryTypeInfo = lookupEntryTypeInfo(member, collectionTypeInfo);
28258
+ if (entryTypeInfo === null) return null;
27840
28259
  if (isMultiSelectionMember(member) !== true) {
27841
28260
  return {
27842
28261
  ...entryTypeInfo,
27843
28262
  required: isRequiredMember(member)
27844
28263
  };
27845
28264
  }
28265
+ if (member.collectionMemberId === void 0) {
28266
+ return {
28267
+ type: 9 /* Lookup */,
28268
+ required: isRequiredMember(member),
28269
+ entryTypeInfo
28270
+ };
28271
+ }
27846
28272
  return {
27847
28273
  type: 9 /* Lookup */,
27848
28274
  required: isRequiredMember(member),
@@ -27851,12 +28277,26 @@ function lookupDeclaredTypeInfo(member, collectionTypeInfo) {
27851
28277
  collectionValueId: member.collectionValueId ?? null
27852
28278
  };
27853
28279
  }
28280
+ function lookupEntryTypeInfo(member, collectionTypeInfo) {
28281
+ if (member.collectionMemberId === void 0) return member.declaredTypeInfo;
28282
+ const collection = collectionTypeInfo(member.collectionMemberId);
28283
+ if (collection === null) return null;
28284
+ if (collection.type !== 6 /* List */ && collection.type !== 5 /* Dictionary */) {
28285
+ return null;
28286
+ }
28287
+ return member.declaredTypeInfo ?? collection.entryTypeInfo;
28288
+ }
27854
28289
 
27855
28290
  // ../packages/neoscript-runtime/src/values/member-declared-type-info.ts
27856
- function resolveMemberDeclaredTypeInfo(member, members) {
27857
- return resolveMemberDeclaredTypeInfoInternal(member, members, /* @__PURE__ */ new Set());
28291
+ function resolveMemberDeclaredTypeInfo(member, members, ownerClass = null) {
28292
+ return resolveMemberDeclaredTypeInfoInternal(
28293
+ member,
28294
+ members,
28295
+ /* @__PURE__ */ new Set(),
28296
+ ownerClass
28297
+ );
27858
28298
  }
27859
- function resolveMemberDeclaredTypeInfoInternal(member, members, seen) {
28299
+ function resolveMemberDeclaredTypeInfoInternal(member, members, seen, ownerClass) {
27860
28300
  const resolved = resolveMember(member, members);
27861
28301
  const memberId = getField(resolved, "id");
27862
28302
  if (typeof memberId === "string" && seen.has(memberId)) return null;
@@ -27874,7 +28314,8 @@ function resolveMemberDeclaredTypeInfoInternal(member, members, seen) {
27874
28314
  const argumentType = resolveMemberDeclaredTypeInfoInternal(
27875
28315
  argumentMember,
27876
28316
  members,
27877
- nextSeen
28317
+ nextSeen,
28318
+ ownerClass
27878
28319
  );
27879
28320
  return argumentType === null ? [] : [[genericParamId, argumentType]];
27880
28321
  }
@@ -27940,7 +28381,8 @@ function resolveMemberDeclaredTypeInfoInternal(member, members, seen) {
27940
28381
  const entryTypeInfo = resolveMemberDeclaredTypeInfoInternal(
27941
28382
  entry,
27942
28383
  members,
27943
- nextSeen
28384
+ nextSeen,
28385
+ ownerClass
27944
28386
  );
27945
28387
  if (entryTypeInfo === null) return null;
27946
28388
  return {
@@ -27951,18 +28393,34 @@ function resolveMemberDeclaredTypeInfoInternal(member, members, seen) {
27951
28393
  };
27952
28394
  }
27953
28395
  if (isMemberLookupBase(resolved)) {
27954
- const collection = members.find(
27955
- (candidate) => candidate.id === resolved.collectionMemberId
27956
- );
27957
- if (collection === void 0) return null;
27958
- return lookupDeclaredTypeInfo(
27959
- resolved,
27960
- resolveMemberDeclaredTypeInfoInternal(collection, members, nextSeen)
27961
- );
28396
+ return lookupDeclaredTypeInfo(resolved, (collectionMemberId) => {
28397
+ const collection = members.find(
28398
+ (candidate) => candidate.id === collectionMemberId
28399
+ );
28400
+ if (collection === void 0) return null;
28401
+ return resolveMemberDeclaredTypeInfoInternal(
28402
+ collection,
28403
+ members,
28404
+ nextSeen,
28405
+ ownerClass
28406
+ );
28407
+ });
27962
28408
  }
27963
28409
  if (resolved.kind === 9 /* Lookup */) return null;
27964
28410
  if (!memberKindSupportsStorage(resolved.kind)) return null;
27965
- if (resolved.kind === 21 /* Generic */) return null;
28411
+ if (isMemberGenericBase(resolved)) {
28412
+ if (ownerClass === null) return null;
28413
+ const declaration = ownerClass.genericParams?.find(
28414
+ (parameter3) => parameter3.id === resolved.genericParamId
28415
+ );
28416
+ if (declaration === void 0) return null;
28417
+ return {
28418
+ type: 21 /* Generic */,
28419
+ required: isRequiredMember(resolved),
28420
+ ownerClassId: ownerClass.id,
28421
+ genericParamId: declaration.id
28422
+ };
28423
+ }
27966
28424
  return {
27967
28425
  type: resolved.kind,
27968
28426
  required: isRequiredMember(resolved)
@@ -30648,6 +31106,41 @@ function declarationInitializerContext(document2) {
30648
31106
  });
30649
31107
  return created;
30650
31108
  }
31109
+ var defaultValuePlansByDocument = /* @__PURE__ */ new WeakMap();
31110
+ function defaultValuePlans(document2) {
31111
+ const key = document2.databaseVM ?? initializerEvaluatorCacheKey(document2);
31112
+ const revision = initializerEvaluatorCacheRevision(document2);
31113
+ const valueGeneration = document2.databaseVM?.valueGeneration;
31114
+ const cached = defaultValuePlansByDocument.get(key);
31115
+ if (cached !== void 0 && (revision === void 0 ? cached.members === document2.members && cached.classes === document2.classes && cached.values === document2.values && cached.constructors === document2.constructors : cached.revision === revision && cached.valueGeneration === valueGeneration)) {
31116
+ return cached.plans;
31117
+ }
31118
+ const lookups = initializerEvaluatorLookups(document2);
31119
+ const plans = withIndexedDefaultValueDocument({
31120
+ project: document2.project,
31121
+ members: document2.members,
31122
+ classes: document2.classes,
31123
+ enums: document2.enums,
31124
+ values: document2.values,
31125
+ constructors: document2.constructors,
31126
+ projectFiles: document2.projectFiles,
31127
+ textureTemplates: document2.textureTemplates,
31128
+ memberById: lookups.memberById,
31129
+ valueById: lookups.defaultValueById ?? lookups.valueById,
31130
+ // A host database without list membership falls back to `values`.
31131
+ unorderedListEntryIds: document2.databaseVM?.unorderedListEntryIds === void 0 && document2.databaseVM !== void 0 ? void 0 : lookups.unorderedListEntryIds
31132
+ });
31133
+ defaultValuePlansByDocument.set(key, {
31134
+ members: document2.members,
31135
+ classes: document2.classes,
31136
+ values: document2.values,
31137
+ constructors: document2.constructors,
31138
+ revision,
31139
+ valueGeneration,
31140
+ plans
31141
+ });
31142
+ return plans;
31143
+ }
30651
31144
  function evaluateInitializerMaterialization(args) {
30652
31145
  const createdValues = [];
30653
31146
  const storageKeyDeclarations = /* @__PURE__ */ new Map();
@@ -30755,9 +31248,6 @@ function materializeInitializerValue(args) {
30755
31248
  function materializeMemberDefaultValue(args) {
30756
31249
  const createdValues = [];
30757
31250
  const storageKeyDeclarations = /* @__PURE__ */ new Map();
30758
- args.readTracking?.recordUnattributableValueRead(
30759
- ownershipChainRead("declaration-owner-resolution", args.envelope.id)
30760
- );
30761
31251
  const declarationArguments = (member, init, sourceValueId) => {
30762
31252
  const { valuesById, rootOwners } = declarationInitializerContext(
30763
31253
  args.document
@@ -30766,7 +31256,8 @@ function materializeMemberDefaultValue(args) {
30766
31256
  args.document,
30767
31257
  sourceValueId,
30768
31258
  rootOwners,
30769
- valuesById
31259
+ valuesById,
31260
+ (id) => args.readTracking?.valueIds.add(id)
30770
31261
  ).ownerClass : typeof Reflect.get(member, "id") === "string" ? findSchemaPlacement(
30771
31262
  String(Reflect.get(member, "id")),
30772
31263
  args.document.classes
@@ -30788,15 +31279,38 @@ function materializeMemberDefaultValue(args) {
30788
31279
  );
30789
31280
  };
30790
31281
  let lookups;
31282
+ const evaluatorLookups = () => lookups ??= initializerEvaluatorLookups(args.document, args.readTracking);
31283
+ const plans = args.readTracking !== void 0 && args.document.databaseVM === void 0 ? void 0 : defaultValuePlans(args.document);
30791
31284
  const built = buildDefaultMemberValue({
30792
31285
  document: {
30793
31286
  ...args.document,
31287
+ // The declaration rows a default clones are reads of this
31288
+ // materialization, like any row its initializers read.
30794
31289
  valueById: (id) => {
30795
- lookups ??= initializerEvaluatorLookups(
30796
- args.document,
30797
- args.readTracking
30798
- );
30799
- return (lookups.defaultValueById ?? lookups.valueById)(id);
31290
+ args.readTracking?.valueIds.add(id);
31291
+ const database = evaluatorLookups();
31292
+ return database.defaultValueById !== void 0 ? database.defaultValueById(id) : database.valueById(id);
31293
+ },
31294
+ unorderedListEntryIds: (containerId) => {
31295
+ args.readTracking?.containerIds.add(containerId);
31296
+ const entryIds = evaluatorLookups().unorderedListEntryIds?.(containerId);
31297
+ if (entryIds === void 0) {
31298
+ throw new Error(
31299
+ `Initializer lookups resolve no unordered-list membership for container "${containerId}".`
31300
+ );
31301
+ }
31302
+ return entryIds;
31303
+ },
31304
+ // Not `resolvedMember`: its id-keyed cache would answer for the
31305
+ // caller's rewritten copy of a member with the stored original.
31306
+ ...plans === void 0 ? {} : {
31307
+ instanceEnv: plans.instanceEnv,
31308
+ storedInstanceMaterializationPlan: plans.storedInstanceMaterializationPlan
31309
+ },
31310
+ recordPlanReads: (reads) => {
31311
+ for (const id of reads.valueIds) args.readTracking?.valueIds.add(id);
31312
+ for (const id of reads.containerIds)
31313
+ args.readTracking?.containerIds.add(id);
30800
31314
  }
30801
31315
  },
30802
31316
  projectId: args.envelope.projectId,
@@ -30875,10 +31389,6 @@ function buildVirtualInstanceMaterializedIndex(args) {
30875
31389
  })
30876
31390
  };
30877
31391
  }
30878
- var CORPUS_SCANNING_MEMBER_KINDS = /* @__PURE__ */ new Set([
30879
- 9 /* Lookup */,
30880
- 18 /* DialogueLookup */
30881
- ]);
30882
31392
  function derivesContentFromMemberDefault(args) {
30883
31393
  const member = args.member;
30884
31394
  if (!isMemberClassBase(member)) return false;
@@ -30942,43 +31452,50 @@ var VirtualExpansionUnsupportedError = class extends Error {
30942
31452
  this.name = "VirtualExpansionUnsupportedError";
30943
31453
  }
30944
31454
  };
30945
- function expandStoredInstance(args) {
30946
- const recorder = args.readRecorder ?? null;
30947
- const readTracking = recorder === null ? void 0 : new InitializerReadSet();
30948
- const trackMaterialization = readTracking === void 0 ? (materialize) => materialize() : (materialize) => {
31455
+ function materializationReadTracking(recorder) {
31456
+ if (recorder === void 0)
31457
+ return { readTracking: void 0, trackMaterialization: (m) => m() };
31458
+ const readTracking = new InitializerReadSet();
31459
+ const trackMaterialization = (materialize) => {
30949
31460
  try {
30950
31461
  return materialize();
30951
31462
  } finally {
30952
31463
  for (const valueId of readTracking.valueIds) {
30953
- recorder?.recordValueRead(valueId);
31464
+ recorder.recordValueRead(valueId);
30954
31465
  }
30955
31466
  for (const textId of readTracking.localizedTextIds) {
30956
- recorder?.recordLocalizedTextRead(textId);
31467
+ recorder.recordLocalizedTextRead(textId);
30957
31468
  }
30958
31469
  for (const variantId of readTracking.variantIds) {
30959
- recorder?.recordVariantRead(variantId);
31470
+ recorder.recordVariantRead(variantId);
30960
31471
  }
30961
31472
  for (const memberId of readTracking.staticMemberIds) {
30962
- recorder?.recordStaticMemberRead(memberId);
31473
+ recorder.recordStaticMemberRead(memberId);
30963
31474
  }
30964
31475
  for (const containerId of readTracking.containerIds) {
30965
- recorder?.recordContainerMembershipRead(containerId);
31476
+ recorder.recordContainerMembershipRead(containerId);
30966
31477
  }
30967
31478
  for (const read of readTracking.worldQueries) {
30968
- recorder?.recordWorldQueryRead?.(read);
31479
+ recorder.recordWorldQueryRead?.(read);
30969
31480
  }
30970
- if (readTracking.hasOwnershipChainRead) {
30971
- recorder?.recordGlobalRead(OWNERSHIP_CHAIN_READ);
31481
+ if (readTracking.hasValuePlacementRead) {
31482
+ recorder.recordValuePlacementRead();
30972
31483
  }
30973
31484
  for (const containerId of readTracking.containerEntryReadIds) {
30974
- recorder?.recordGlobalRead(containerEntriesRead(containerId));
31485
+ recorder.recordContainerMembershipRead(containerId);
30975
31486
  }
30976
31487
  for (const reason of readTracking.corpusReadReasons) {
30977
- recorder?.recordGlobalRead(reason);
31488
+ recorder.recordGlobalRead(reason);
30978
31489
  }
30979
31490
  }
30980
31491
  };
30981
- recorder?.recordValueRead(args.instanceRoot.id);
31492
+ return { readTracking, trackMaterialization };
31493
+ }
31494
+ function expandStoredInstance(args) {
31495
+ const { readTracking, trackMaterialization } = materializationReadTracking(
31496
+ args.readRecorder
31497
+ );
31498
+ args.readRecorder?.recordValueRead(args.instanceRoot.id);
30982
31499
  const rootMember = resolveMember(args.rootMember, args.document.members);
30983
31500
  if (!isMemberClassBase(rootMember)) {
30984
31501
  throw new Error(
@@ -31014,11 +31531,6 @@ function expandStoredInstance(args) {
31014
31531
  `Virtual expansion root "${args.instanceRoot.id}" is missing required constructor arguments.`
31015
31532
  );
31016
31533
  }
31017
- const constructorArguments = storedConstructorReplayArguments(
31018
- requiredConstructor,
31019
- storedArgs,
31020
- instanceRoot.id
31021
- );
31022
31534
  const {
31023
31535
  value: _value,
31024
31536
  classId: _classId,
@@ -31039,6 +31551,34 @@ function expandStoredInstance(args) {
31039
31551
  instanceRoot
31040
31552
  );
31041
31553
  const replayMember = closedRootMember === rootMember ? rootMember : { ...closedRootMember, classId };
31554
+ let environment;
31555
+ const constructorArguments = storedConstructorReplayArguments(
31556
+ requiredConstructor === null ? null : {
31557
+ ...requiredConstructor,
31558
+ argumentTypes: requiredConstructor.argumentTypes.map((argument2) => {
31559
+ if (argument2.type !== 21 /* Generic */) return argument2;
31560
+ environment ??= resolveInstanceEnv(
31561
+ classId,
31562
+ replayMember.classArguments,
31563
+ args.document.classes
31564
+ );
31565
+ const type = substituteInheritedCallableTypeInfo(
31566
+ argument2,
31567
+ environment,
31568
+ args.document.classes,
31569
+ args.document.members
31570
+ );
31571
+ if (type.type === NS_TYPE_VOID) {
31572
+ throw new Error(
31573
+ `Constructor parameter "${argument2.name}" on "${classId}" cannot have type void.`
31574
+ );
31575
+ }
31576
+ return { ...type, name: argument2.name };
31577
+ })
31578
+ },
31579
+ storedArgs,
31580
+ instanceRoot.id
31581
+ );
31042
31582
  const replay = (fields) => {
31043
31583
  const init = storedConstructorReplayInitializer({
31044
31584
  classId,
@@ -31103,11 +31643,7 @@ function expandStoredInstance(args) {
31103
31643
  function resolveVirtualInstanceGraph(args) {
31104
31644
  const expansion = args.expansionIndex ?? indexExpansion(args);
31105
31645
  const recorder = args.readRecorder ?? null;
31106
- if (recorder !== null) {
31107
- recorder.recordValueRead(args.instanceRoot.id);
31108
- const unattributable = firstUnattributableExpansionMember(expansion);
31109
- if (unattributable !== null) recorder.recordGlobalRead(unattributable);
31110
- }
31646
+ recorder?.recordValueRead(args.instanceRoot.id);
31111
31647
  const materializedById = args.materializedIndex?.rowsById ?? new Map(
31112
31648
  (args.materializedRows ?? args.document.values).map((row) => [
31113
31649
  row.id,
@@ -31662,15 +32198,6 @@ function mergeExpandedAndMaterializedRow(expanded, materialized) {
31662
32198
  if (merged.sourceValueId === materialized.id) delete merged.sourceValueId;
31663
32199
  return merged;
31664
32200
  }
31665
- function firstUnattributableExpansionMember(expansion) {
31666
- for (const node of expansion.nodesByPath.values()) {
31667
- const member = node.member;
31668
- if (CORPUS_SCANNING_MEMBER_KINDS.has(member.kind)) {
31669
- return `corpus-scanning-member-kind:${node.memberId}`;
31670
- }
31671
- }
31672
- return null;
31673
- }
31674
32201
  function prepareStoredClassValueResolution(args) {
31675
32202
  let listenerDefaults;
31676
32203
  let copiedListeners;
@@ -31682,9 +32209,10 @@ function prepareStoredClassValueResolution(args) {
31682
32209
  ...args.document,
31683
32210
  // Construction checks share the existing schema index across every nested default.
31684
32211
  memberById: args.document.memberById ?? ((id) => schema.member(id) ?? null),
31685
- evaluatorCache: {
31686
- key: initializerEvaluatorCacheKey(args.document),
31687
- revision: initializerEvaluatorCacheRevision(args.document)
32212
+ // The same rows under a fresh object: share its evaluator caches.
32213
+ evaluatorCache: args.document.evaluatorCache ?? {
32214
+ key: args.document,
32215
+ revision: void 0
31688
32216
  },
31689
32217
  listenerDefaultCapture: {
31690
32218
  begin: () => {
@@ -31760,27 +32288,32 @@ function expandStoredClassValue(args) {
31760
32288
  }
31761
32289
  const classId = root.classId ?? member.classId;
31762
32290
  args.readRecorder?.recordValueRead(root.id);
31763
- args.readRecorder?.recordGlobalRead("declaration-default");
31764
- const materialized = materializeMemberDefaultValue({
31765
- saveStaticBindings: args.saveStaticBindings,
31766
- sessionStaticBindings: args.sessionStaticBindings,
31767
- evaluateInitializer: args.evaluateInitializer,
31768
- document: args.document,
31769
- member: closeClassArgumentsFromRowStamp(
31770
- {
31771
- ...member,
31772
- classId,
31773
- defaultValue: derivesContentFromMemberDefault({
31774
- member,
31775
- instanceRoot: root,
31776
- effectiveClassId: classId
31777
- }) ? member.defaultValue : void 0
31778
- },
31779
- root
31780
- ),
31781
- envelope: root,
31782
- declarationRoot: true
31783
- });
32291
+ const { readTracking, trackMaterialization } = materializationReadTracking(
32292
+ args.readRecorder
32293
+ );
32294
+ const materialized = trackMaterialization(
32295
+ () => materializeMemberDefaultValue({
32296
+ ...readTracking === void 0 ? {} : { readTracking },
32297
+ saveStaticBindings: args.saveStaticBindings,
32298
+ sessionStaticBindings: args.sessionStaticBindings,
32299
+ evaluateInitializer: args.evaluateInitializer,
32300
+ document: args.document,
32301
+ member: closeClassArgumentsFromRowStamp(
32302
+ {
32303
+ ...member,
32304
+ classId,
32305
+ defaultValue: derivesContentFromMemberDefault({
32306
+ member,
32307
+ instanceRoot: root,
32308
+ effectiveClassId: classId
32309
+ }) ? member.defaultValue : void 0
32310
+ },
32311
+ root
32312
+ ),
32313
+ envelope: root,
32314
+ declarationRoot: true
32315
+ })
32316
+ );
31784
32317
  return {
31785
32318
  root: { ...root, classId, value: materialized.root.value },
31786
32319
  rows: materialized.createdValues,
@@ -32535,6 +33068,17 @@ function variantSwapDeclaredMember(document2, rootValueId) {
32535
33068
  if (placement === void 0) return void 0;
32536
33069
  return document2.members.find((member) => member.id === placement.memberId);
32537
33070
  }
33071
+ function emptyExpansionReads() {
33072
+ return {
33073
+ valueIds: /* @__PURE__ */ new Set(),
33074
+ containerIds: /* @__PURE__ */ new Set(),
33075
+ localizedTextIds: /* @__PURE__ */ new Set(),
33076
+ variantIds: /* @__PURE__ */ new Set(),
33077
+ staticMemberIds: /* @__PURE__ */ new Set(),
33078
+ global: false,
33079
+ merged: /* @__PURE__ */ new WeakSet()
33080
+ };
33081
+ }
32538
33082
  function createHeadlessVirtualInstanceResolver(args) {
32539
33083
  const { document: document2 } = args;
32540
33084
  const membersById = args.membersById ?? new Map(document2.members.map((member) => [member.id, member]));
@@ -32558,16 +33102,22 @@ function createHeadlessVirtualInstanceResolver(args) {
32558
33102
  const emptyRows = [];
32559
33103
  const graphByValueId = /* @__PURE__ */ new Map();
32560
33104
  const failedRootIds = /* @__PURE__ */ new Set();
33105
+ const expandingRootIds = /* @__PURE__ */ new Set();
32561
33106
  const expandedRowById = /* @__PURE__ */ new Map();
32562
33107
  const expandedRowByRecord = /* @__PURE__ */ new WeakMap();
32563
33108
  const readsByRootId = /* @__PURE__ */ new Map();
32564
33109
  const activeReads = [];
32565
33110
  const sharedByReceiverId = /* @__PURE__ */ new Map();
33111
+ const callerReads = /* @__PURE__ */ new WeakMap();
32566
33112
  const mergeReads = (reads) => {
32567
33113
  for (const active of activeReads) {
32568
- if (active === reads) continue;
33114
+ if (active === reads || active.merged.has(reads)) continue;
33115
+ active.merged.add(reads);
32569
33116
  for (const id of reads.valueIds) active.valueIds.add(id);
32570
33117
  for (const id of reads.containerIds) active.containerIds.add(id);
33118
+ for (const id of reads.localizedTextIds) active.localizedTextIds.add(id);
33119
+ for (const id of reads.variantIds) active.variantIds.add(id);
33120
+ for (const id of reads.staticMemberIds) active.staticMemberIds.add(id);
32571
33121
  if (reads.global) active.global = true;
32572
33122
  }
32573
33123
  };
@@ -32576,9 +33126,18 @@ function createHeadlessVirtualInstanceResolver(args) {
32576
33126
  for (const active of activeReads) active.valueIds.add(id);
32577
33127
  args.readRecorder?.recordValueRead(id);
32578
33128
  },
32579
- recordLocalizedTextRead: (id) => args.readRecorder?.recordLocalizedTextRead(id),
32580
- recordVariantRead: (id) => args.readRecorder?.recordVariantRead(id),
32581
- recordStaticMemberRead: (id) => args.readRecorder?.recordStaticMemberRead(id),
33129
+ recordLocalizedTextRead: (id) => {
33130
+ for (const active of activeReads) active.localizedTextIds.add(id);
33131
+ args.readRecorder?.recordLocalizedTextRead(id);
33132
+ },
33133
+ recordVariantRead: (id) => {
33134
+ for (const active of activeReads) active.variantIds.add(id);
33135
+ args.readRecorder?.recordVariantRead(id);
33136
+ },
33137
+ recordStaticMemberRead: (id) => {
33138
+ for (const active of activeReads) active.staticMemberIds.add(id);
33139
+ args.readRecorder?.recordStaticMemberRead(id);
33140
+ },
32582
33141
  recordContainerMembershipRead: (id) => {
32583
33142
  for (const active of activeReads) active.containerIds.add(id);
32584
33143
  args.readRecorder?.recordContainerMembershipRead(id);
@@ -32624,6 +33183,7 @@ function createHeadlessVirtualInstanceResolver(args) {
32624
33183
  if (reads2 !== void 0) mergeReads(reads2);
32625
33184
  return cached;
32626
33185
  }
33186
+ if (expandingRootIds.has(rootId)) return emptyRows;
32627
33187
  if (failedRootIds.has(rootId)) return emptyRows;
32628
33188
  const instanceRoot = rawById.get(rootId);
32629
33189
  if (instanceRoot === void 0 || declaredMember === void 0) {
@@ -32639,12 +33199,9 @@ function createHeadlessVirtualInstanceResolver(args) {
32639
33199
  failedRootIds.add(rootId);
32640
33200
  return emptyRows;
32641
33201
  }
32642
- const reads = {
32643
- valueIds: /* @__PURE__ */ new Set(),
32644
- containerIds: /* @__PURE__ */ new Set(),
32645
- global: false
32646
- };
33202
+ const reads = emptyExpansionReads();
32647
33203
  activeReads.push(reads);
33204
+ expandingRootIds.add(rootId);
32648
33205
  try {
32649
33206
  const resolverDocument = resolverDocumentOnce();
32650
33207
  materializedIndex ??= buildVirtualInstanceMaterializedIndex({
@@ -32668,6 +33225,7 @@ function createHeadlessVirtualInstanceResolver(args) {
32668
33225
  failedRootIds.add(rootId);
32669
33226
  return emptyRows;
32670
33227
  } finally {
33228
+ expandingRootIds.delete(rootId);
32671
33229
  activeReads.pop();
32672
33230
  mergeReads(reads);
32673
33231
  }
@@ -32686,9 +33244,15 @@ function createHeadlessVirtualInstanceResolver(args) {
32686
33244
  share.containerChanged
32687
33245
  );
32688
33246
  if (shared === null) return null;
33247
+ recorder.recordValuePlacementRead();
32689
33248
  for (const id of shared.reads.valueIds) recorder.recordValueRead(id);
32690
33249
  for (const id of shared.reads.containerIds)
32691
33250
  recorder.recordContainerMembershipRead(id);
33251
+ for (const id of shared.reads.localizedTextIds)
33252
+ recorder.recordLocalizedTextRead(id);
33253
+ for (const id of shared.reads.variantIds) recorder.recordVariantRead(id);
33254
+ for (const id of shared.reads.staticMemberIds)
33255
+ recorder.recordStaticMemberRead(id);
32692
33256
  if (graphRowsByRootId.get(shared.graph.instanceRootId) === void 0) {
32693
33257
  readsByRootId.set(shared.graph.instanceRootId, shared.reads);
32694
33258
  remember(shared.graph, shared.rows);
@@ -32732,7 +33296,16 @@ function createHeadlessVirtualInstanceResolver(args) {
32732
33296
  return graph?.instanceRootId === rootId ? graph : null;
32733
33297
  },
32734
33298
  virtualInstanceRowsForValue,
32735
- valueById: (id) => expandedRowById.get(id) ?? null,
33299
+ valueById: (id) => {
33300
+ const row = expandedRowById.get(id);
33301
+ if (row === void 0) return null;
33302
+ if (activeReads.length > 0) {
33303
+ const rootId = graphByValueId.get(id)?.instanceRootId;
33304
+ const reads = rootId === void 0 ? void 0 : readsByRootId.get(rootId);
33305
+ if (reads !== void 0) mergeReads(reads);
33306
+ }
33307
+ return row;
33308
+ },
32736
33309
  rowForValueReference: (value) => expandedRowByRecord.get(value) ?? null,
32737
33310
  virtualInstanceGraphForValue: (valueId) => {
32738
33311
  const known = graphByValueId.get(valueId);
@@ -32744,11 +33317,7 @@ function createHeadlessVirtualInstanceResolver(args) {
32744
33317
  return graphByValueId.get(valueId) ?? null;
32745
33318
  },
32746
33319
  shareExpansion: (receiverValueId, masked, containerChanged) => {
32747
- const reads = {
32748
- valueIds: /* @__PURE__ */ new Set(),
32749
- containerIds: /* @__PURE__ */ new Set(),
32750
- global: false
32751
- };
33320
+ const reads = emptyExpansionReads();
32752
33321
  activeReads.push(reads);
32753
33322
  let rows;
32754
33323
  try {
@@ -32769,6 +33338,29 @@ function createHeadlessVirtualInstanceResolver(args) {
32769
33338
  );
32770
33339
  }
32771
33340
  return { graph, rows, reads };
33341
+ },
33342
+ recordReads: (target, read) => {
33343
+ let reads = callerReads.get(target);
33344
+ if (reads === void 0) {
33345
+ reads = {
33346
+ valueIds: target.valueIds,
33347
+ containerIds: target.containerIds,
33348
+ localizedTextIds: target.localizedTextIds,
33349
+ variantIds: target.variantIds,
33350
+ staticMemberIds: target.staticMemberIds,
33351
+ global: false,
33352
+ merged: /* @__PURE__ */ new WeakSet()
33353
+ };
33354
+ callerReads.set(target, reads);
33355
+ }
33356
+ activeReads.push(reads);
33357
+ try {
33358
+ return read();
33359
+ } finally {
33360
+ activeReads.pop();
33361
+ if (reads.global)
33362
+ target.recordUnattributableValueRead("virtual-instance-expansion");
33363
+ }
32772
33364
  }
32773
33365
  };
32774
33366
  }
@@ -32818,6 +33410,10 @@ function initializerEvaluatorLookups(document2, readTracking) {
32818
33410
  ...databaseVM.changeListenerDefaultsForOwner === void 0 ? {} : {
32819
33411
  changeListenerDefaultsForOwner: (id) => databaseVM.changeListenerDefaultsForOwner(id)
32820
33412
  },
33413
+ // Read live: this wrapper outlives a scalar's nullness change.
33414
+ get valueGeneration() {
33415
+ return databaseVM.valueGeneration;
33416
+ },
32821
33417
  memberById: (id) => databaseVM.memberById(id),
32822
33418
  valueById: (id) => databaseVM.valueById(id),
32823
33419
  defaultValueById: (id) => databaseVM.defaultValueById?.(id) ?? databaseVM.valueById(id),
@@ -32844,6 +33440,7 @@ function initializerEvaluatorLookups(document2, readTracking) {
32844
33440
  return resolved;
32845
33441
  },
32846
33442
  virtualInstanceRowsForValue: (receiverValueId) => databaseVM.virtualInstanceRowsForValue(receiverValueId),
33443
+ ...databaseVM.worldGridQueryIndex === void 0 ? {} : { worldGridQueryIndex: () => databaseVM.worldGridQueryIndex() },
32847
33444
  rowForValueReference: (value) => databaseVM.rowForValueReference?.(value) ?? null,
32848
33445
  resolveVariantInstanceGraph: (args) => {
32849
33446
  const resolver = databaseVM.resolveVariantInstanceGraph;
@@ -32872,88 +33469,45 @@ function initializerEvaluatorLookups(document2, readTracking) {
32872
33469
  indexKey,
32873
33470
  revision
32874
33471
  );
32875
- const shareFrom = document2.databaseVM === void 0 && document2.evaluatorOverlay !== void 0 ? sharedHeadlessResolver(document2.evaluatorOverlay) : void 0;
33472
+ const shareFrom = document2.evaluatorOverlay === void 0 ? void 0 : sharedHeadlessResolver(document2.evaluatorOverlay);
32876
33473
  let hasListenerMetadata;
32877
- const headlessVirtualResolver = document2.databaseVM === void 0 ? createHeadlessVirtualInstanceResolver({
33474
+ const headlessVirtualResolver = createHeadlessVirtualInstanceResolver({
32878
33475
  evaluateInitializer: evaluateMemberInitializer,
32879
33476
  document: document2,
32880
33477
  resolverLookups: () => lookups,
32881
33478
  ...shareFrom === void 0 ? {} : { shareFrom },
32882
33479
  ...readTracking === void 0 ? {} : { readRecorder: virtualReadRecorder(readTracking) }
32883
- }) : null;
33480
+ });
32884
33481
  const lookups = {
32885
33482
  ...indexedLookups,
32886
- ...document2.databaseVM === void 0 && headlessVirtualResolver !== null ? {
32887
- changeListenerDefaultsForOwner: (id) => {
32888
- if (!(hasListenerMetadata ??= hasAuthoredChangeListenerMetadata(document2)))
32889
- return void 0;
32890
- const inherited = headlessVirtualResolver.virtualInstanceGraphForValue(id)?.listenerDefaultsByOwner?.get(id);
32891
- const authored = authoredChangeListenerOwners(document2.values).get(
32892
- id
32893
- );
32894
- return inherited === void 0 ? authored : { ...inherited, ...authored };
32895
- },
32896
- defaultValueById: (id) => declarationDefaultSource(
32897
- id,
32898
- indexedLookups.valueById(id),
32899
- headlessVirtualResolver.virtualInstanceGraphForValue
32900
- ),
32901
- valueById: (id) => indexedLookups.valueById(id) ?? headlessVirtualResolver.valueById(id),
32902
- rowForValueReference: (value) => indexedLookups.rowForValueReference?.(value) ?? headlessVirtualResolver.rowForValueReference(value),
32903
- virtualInstanceRowsForValue: (receiverValueId) => headlessVirtualResolver.virtualInstanceRowsForValue(
32904
- receiverValueId
32905
- ),
32906
- // Headless hosts still evaluate `ToVariant` during
32907
- // stored-construction replay — production's variant-constructed
32908
- // placements collapse through exactly this path. The shared core
32909
- // resolves against the plain document, with these lookups as the
32910
- // nested resolver.
32911
- resolveVariantInstanceGraph: (args) => resolveVariantInstanceGraphForDocument({
32912
- evaluateInitializer: evaluateMemberInitializer,
32913
- document: document2,
32914
- resolverLookups: lookups,
32915
- ...readTracking === void 0 ? {} : { readRecorder: virtualReadRecorder(readTracking) },
32916
- ...args
32917
- })
32918
- } : {
32919
- get worldQueryRevision() {
32920
- return document2.databaseVM?.worldQueryRevision;
32921
- },
32922
- memberById: (id) => document2.databaseVM?.memberById(id) ?? null,
32923
- valueById: (id) => document2.databaseVM?.valueById(id) ?? null,
32924
- variantById: (id) => document2.databaseVM?.variantById?.(id) ?? null,
32925
- // The VM's `valueById` answers EXPANDED-first: a collapse-stamped
32926
- // root resolves to a record the VM minted, an object the raw value
32927
- // index has never seen. Reference-identity dispatch (`.Id`, `is`,
32928
- // lookup selection) must reach the VM's reverse map for those
32929
- // records — dropping to the raw index alone made every lookup
32930
- // variant's initializer report "produced a value with no backing
32931
- // row" once P75 expansion started succeeding.
32932
- rowForValueReference: (value) => indexedLookups.rowForValueReference?.(value) ?? document2.databaseVM?.rowForValueReference?.(value) ?? null,
32933
- unorderedListEntryIds: (containerValueId) => {
32934
- const resolved = document2.databaseVM?.unorderedListEntryIds?.(containerValueId) ?? indexedLookups.unorderedListEntryIds?.(containerValueId);
32935
- if (resolved === void 0) {
32936
- throw new Error(
32937
- `Evaluator database resolves no unordered-list membership for container "${containerValueId}".`
32938
- );
32939
- }
32940
- return resolved;
32941
- },
32942
- virtualInstanceRowsForValue: (receiverValueId) => {
32943
- const databaseVM = document2.databaseVM;
32944
- if (databaseVM === void 0) return [];
32945
- return databaseVM.virtualInstanceRowsForValue(receiverValueId);
32946
- },
32947
- resolveVariantInstanceGraph: (args) => {
32948
- const resolver = document2.databaseVM?.resolveVariantInstanceGraph;
32949
- if (resolver === void 0) {
32950
- throw new Error(
32951
- "Evaluator database has no virtual variant resolver."
32952
- );
32953
- }
32954
- return resolver.call(document2.databaseVM, args);
32955
- }
32956
- }
33483
+ changeListenerDefaultsForOwner: (id) => {
33484
+ if (!(hasListenerMetadata ??= hasAuthoredChangeListenerMetadata(document2)))
33485
+ return void 0;
33486
+ const inherited = headlessVirtualResolver.virtualInstanceGraphForValue(id)?.listenerDefaultsByOwner?.get(id);
33487
+ const authored = authoredChangeListenerOwners(document2.values).get(id);
33488
+ return inherited === void 0 ? authored : { ...inherited, ...authored };
33489
+ },
33490
+ defaultValueById: (id) => declarationDefaultSource(
33491
+ id,
33492
+ indexedLookups.valueById(id),
33493
+ headlessVirtualResolver.virtualInstanceGraphForValue
33494
+ ),
33495
+ valueById: (id) => indexedLookups.valueById(id) ?? headlessVirtualResolver.valueById(id),
33496
+ rowForValueReference: (value) => indexedLookups.rowForValueReference?.(value) ?? headlessVirtualResolver.rowForValueReference(value),
33497
+ virtualInstanceRowsForValue: (receiverValueId) => headlessVirtualResolver.virtualInstanceRowsForValue(receiverValueId),
33498
+ recordVirtualInstanceReads: (reads, read) => headlessVirtualResolver.recordReads(reads, read),
33499
+ // Headless hosts still evaluate `ToVariant` during
33500
+ // stored-construction replay — production's variant-constructed
33501
+ // placements collapse through exactly this path. The shared core
33502
+ // resolves against the plain document, with these lookups as the
33503
+ // nested resolver.
33504
+ resolveVariantInstanceGraph: (args) => resolveVariantInstanceGraphForDocument({
33505
+ evaluateInitializer: evaluateMemberInitializer,
33506
+ document: document2,
33507
+ resolverLookups: lookups,
33508
+ ...readTracking === void 0 ? {} : { readRecorder: virtualReadRecorder(readTracking) },
33509
+ ...args
33510
+ })
32957
33511
  };
32958
33512
  if (!trackedHeadless) {
32959
33513
  evaluatorLookupsByDocument.set(lookupKey, {
@@ -32962,8 +33516,7 @@ function initializerEvaluatorLookups(document2, readTracking) {
32962
33516
  revision,
32963
33517
  lookups
32964
33518
  });
32965
- if (headlessVirtualResolver !== null)
32966
- headlessResolversByLookupKey.set(lookupKey, headlessVirtualResolver);
33519
+ headlessResolversByLookupKey.set(lookupKey, headlessVirtualResolver);
32967
33520
  }
32968
33521
  return lookups;
32969
33522
  }
@@ -33283,53 +33836,6 @@ function memoizeFrozenJsonGuard(isValid) {
33283
33836
  };
33284
33837
  }
33285
33838
 
33286
- // ../packages/manifest/src/value-comparison.ts
33287
- function isObjectRecord(value) {
33288
- return typeof value === "object" && value !== null && !Array.isArray(value);
33289
- }
33290
-
33291
- // ../packages/neoscript-runtime/src/values/canonical-json.ts
33292
- function canonicalJsonStringify(value) {
33293
- return JSON.stringify(toCanonicalJsonValue(value));
33294
- }
33295
- function toCanonicalJsonValue(value) {
33296
- if (value === null) return null;
33297
- if (value === void 0) return void 0;
33298
- if (value instanceof Date) return value.toISOString();
33299
- if (typeof value === "string") return value;
33300
- if (typeof value === "boolean") return value;
33301
- if (typeof value === "number") {
33302
- if (!Number.isFinite(value)) {
33303
- throw new Error("Cannot canonicalize a non-finite number.");
33304
- }
33305
- return value;
33306
- }
33307
- if (typeof value === "bigint") {
33308
- throw new Error("Cannot canonicalize bigint values.");
33309
- }
33310
- if (typeof value === "symbol") {
33311
- throw new Error("Cannot canonicalize symbol values.");
33312
- }
33313
- if (typeof value === "function") {
33314
- throw new Error("Cannot canonicalize function values.");
33315
- }
33316
- if (Array.isArray(value)) {
33317
- return value.map((item) => {
33318
- const canonicalItem = toCanonicalJsonValue(item);
33319
- if (canonicalItem === void 0) return null;
33320
- return canonicalItem;
33321
- });
33322
- }
33323
- const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
33324
- const canonicalObject = {};
33325
- for (const [key, entryValue] of entries) {
33326
- const canonicalValue = toCanonicalJsonValue(entryValue);
33327
- if (canonicalValue === void 0) continue;
33328
- canonicalObject[key] = canonicalValue;
33329
- }
33330
- return canonicalObject;
33331
- }
33332
-
33333
33839
  // ../packages/neoscript-language/src/syntax-index.ts
33334
33840
  var OPEN_TO_CLOSE = /* @__PURE__ */ new Map([
33335
33841
  ["(", ")"],
@@ -35608,7 +36114,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
35608
36114
  local,
35609
36115
  localType,
35610
36116
  "local" /* Local */,
35611
- initial.writability ?? "local" /* Local */,
36117
+ localOwnership(initial),
35612
36118
  this.localWriteTargetRoot(initial, scope)
35613
36119
  )
35614
36120
  );
@@ -38861,6 +39367,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38861
39367
  } : {}
38862
39368
  };
38863
39369
  }
39370
+ const writability = member.writability ? toWritability(member.writability, this.writesUserData) : void 0;
38864
39371
  return {
38865
39372
  pointer: {
38866
39373
  type: "staticMember" /* StaticMember */,
@@ -38868,8 +39375,10 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
38868
39375
  },
38869
39376
  type: member.type,
38870
39377
  symbol: member,
38871
- ...member.writability ? {
38872
- writability: toWritability(member.writability, this.writesUserData)
39378
+ ...writability ? { writability } : {},
39379
+ ...member.lookup ? {
39380
+ entryWritability: this.lookupEntryWritability(member, writability),
39381
+ entryUserData: this.lookupEntryUserData(member)
38873
39382
  } : {}
38874
39383
  };
38875
39384
  }
@@ -39169,7 +39678,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39169
39678
  const readonlySlot = member.readonlyDeclaration === true;
39170
39679
  const storageWritability = this.memberWritability(member, receiver);
39171
39680
  const writability = readonlySlot ? "readOnly" /* ReadOnly */ : storageWritability;
39172
- const entryWritability = member.lookup ? this.lookupEntryWritability(member, receiver) : readonlySlot ? storageWritability : void 0;
39681
+ const entryWritability = member.lookup ? this.lookupEntryWritability(member, receiver.writability) : readonlySlot ? storageWritability : void 0;
39173
39682
  const userData = this.memberUserData(member, receiver);
39174
39683
  const entryUserData = member.lookup ? this.lookupEntryUserData(member) : readonlySlot && userData;
39175
39684
  const lookupWire = member.lookup?.multiselect === true && memberType2.kind === "set" ? {
@@ -39179,7 +39688,7 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39179
39688
  { ...memberType2.elementType, nullable: false },
39180
39689
  this.project
39181
39690
  ),
39182
- collectionMemberId: member.lookup.collectionMemberId,
39691
+ ...member.lookup.collectionMemberId !== void 0 ? { collectionMemberId: member.lookup.collectionMemberId } : {},
39183
39692
  ...member.lookup.collectionValueId !== void 0 ? { collectionValueId: member.lookup.collectionValueId } : {}
39184
39693
  } : void 0;
39185
39694
  return {
@@ -39303,16 +39812,18 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
39303
39812
  }
39304
39813
  lookupEntryUserData(member) {
39305
39814
  if (!member.lookup) return false;
39306
- const collectionWritability = member.lookup.collectionWritability ?? this.project.symbolById.get(member.lookup.collectionMemberId)?.writability;
39815
+ const collectionMemberId = member.lookup.collectionMemberId;
39816
+ if (collectionMemberId === void 0) return false;
39817
+ const collectionWritability = member.lookup.collectionWritability ?? this.project.symbolById.get(collectionMemberId)?.writability;
39307
39818
  return collectionWritability === "user";
39308
39819
  }
39309
- lookupEntryWritability(member, receiver) {
39820
+ lookupEntryWritability(member, receiverWritability) {
39310
39821
  if (!member.lookup) return "readOnly" /* ReadOnly */;
39311
- const target = this.project.symbolById.get(
39312
- member.lookup.collectionMemberId
39313
- );
39822
+ const collectionMemberId = member.lookup.collectionMemberId;
39823
+ if (collectionMemberId === void 0) return "runtime" /* Runtime */;
39824
+ const target = this.project.symbolById.get(collectionMemberId);
39314
39825
  const targetWritability = member.lookup.collectionWritability ? toWritability(member.lookup.collectionWritability, this.writesUserData) : target?.writability ? toWritability(target.writability, this.writesUserData) : target?.writable ? "runtime" /* Runtime */ : "readOnly" /* ReadOnly */;
39315
- if (receiver.writability === "immutable" /* Immutable */) {
39826
+ if (receiverWritability === "immutable" /* Immutable */) {
39316
39827
  if (targetWritability === "save" /* Save */) {
39317
39828
  return "immutableToSaveLookup" /* ImmutableToSaveLookup */;
39318
39829
  }
@@ -40272,7 +40783,10 @@ var StrictNeoScriptResolver = class _StrictNeoScriptResolver {
40272
40783
  const resolved = this.resolveIdentifier(callee.name, scope, callee.pos);
40273
40784
  return resolved.type.kind === "delegate" || resolved.type.kind === "action" ? resolved : null;
40274
40785
  }
40275
- if (callee.kind !== "member") return null;
40786
+ if (callee.kind !== "member") {
40787
+ const resolved = this.resolveExpression(callee, scope);
40788
+ return resolved.type.kind === "delegate" ? resolved : null;
40789
+ }
40276
40790
  try {
40277
40791
  const resolved = this.resolveMember(
40278
40792
  callee.receiver,
@@ -43506,6 +44020,12 @@ function bindConstructorArgumentNames(className, declared, argumentNames, pos) {
43506
44020
  return parameter3.name;
43507
44021
  });
43508
44022
  }
44023
+ function localOwnership(initial) {
44024
+ if (initial.entryWritability !== void 0 && (initial.type.kind === "named" || initial.type.kind === "typeParameter")) {
44025
+ return initial.entryWritability;
44026
+ }
44027
+ return initial.writability ?? "local" /* Local */;
44028
+ }
43509
44029
  function scopeVariable(name, value, sourceType, writability, ownership, writeRoot, readonlyBinding) {
43510
44030
  return {
43511
44031
  name,
@@ -45587,12 +46107,10 @@ function memberSymbol(member, schemaKey, environment, field) {
45587
46107
  environment
45588
46108
  );
45589
46109
  }
45590
- const lookupCollectionMemberId = kind === "lookup" ? string(member.collectionMemberId, `${field}.collectionMemberId`) : null;
45591
- const lookupCollectionWritability = lookupCollectionMemberId === null ? void 0 : environment.effectiveWritabilityByMemberId.get(
45592
- lookupCollectionMemberId
45593
- );
46110
+ const lookupCollection = kind === "lookup" ? lookupCollectionMemberId(member, field) : null;
46111
+ const lookupCollectionWritability = lookupCollection === null ? void 0 : environment.effectiveWritabilityByMemberId.get(lookupCollection);
45594
46112
  const lookup = kind === "lookup" ? {
45595
- collectionMemberId: lookupCollectionMemberId,
46113
+ ...lookupCollection === null ? {} : { collectionMemberId: lookupCollection },
45596
46114
  ...member.collectionValueId === null || typeof member.collectionValueId === "string" ? { collectionValueId: member.collectionValueId } : {},
45597
46115
  multiselect: boolean(member.multiselect, `${field}.multiselect`),
45598
46116
  ...lookupCollectionWritability === void 0 ? {} : { collectionWritability: lookupCollectionWritability }
@@ -45606,6 +46124,10 @@ function memberSymbol(member, schemaKey, environment, field) {
45606
46124
  ...lookup ? { lookup } : {}
45607
46125
  };
45608
46126
  }
46127
+ function lookupCollectionMemberId(member, field) {
46128
+ if (member.collectionMemberId === null) return null;
46129
+ return string(member.collectionMemberId, `${field}.collectionMemberId`);
46130
+ }
45609
46131
  function interfaceType(value, environment, field) {
45610
46132
  const id = string(value.id, `${field}.id`);
45611
46133
  return {
@@ -46074,9 +46596,8 @@ function memberType(member, environment, visiting, field) {
46074
46596
  };
46075
46597
  }
46076
46598
  if (kind === "lookup") {
46077
- const collection = environment.members.get(
46078
- string(member.collectionMemberId, `${field}.collectionMemberId`)
46079
- );
46599
+ const collectionMemberId = lookupCollectionMemberId(member, field);
46600
+ const collection = collectionMemberId === null ? void 0 : environment.members.get(collectionMemberId);
46080
46601
  const collectionType = collection ? memberType(collection, environment, next, `${field}.collection`) : unknownType();
46081
46602
  const declared = optionalRecord(member.declaredType);
46082
46603
  const declaredType = declared ? manifestType(declared, environment, `${field}.declaredType`) : null;
@@ -47691,6 +48212,13 @@ function memberToSymbol(record4, schemaKey, containingClass, ownerClassId, index
47691
48212
  };
47692
48213
  }
47693
48214
  if (isMemberLookupBase(resolved)) {
48215
+ if (resolved.collectionMemberId === void 0) {
48216
+ return {
48217
+ ...common,
48218
+ kind: "property",
48219
+ lookup: { multiselect: isMultiSelectionMember(resolved) }
48220
+ };
48221
+ }
47694
48222
  const collectionWritability = uniqueEffectiveWritability(
47695
48223
  resolved.collectionMemberId,
47696
48224
  context
@@ -48052,12 +48580,12 @@ function memberRuntimeType(record4, context, seen = /* @__PURE__ */ new Set(), g
48052
48580
  if (!isMemberLookupBase(member)) return UNKNOWN_TYPE;
48053
48581
  const declared = member.declaredTypeInfo ? toLanguageType(member.declaredTypeInfo, context, genericEnvironment) : null;
48054
48582
  const narrowed = declared && !isUnknownType3(declared) ? declared : null;
48055
- const entry = narrowed ?? lookupCollectionEntryType(
48583
+ const entry = narrowed ?? (member.collectionMemberId === void 0 ? null : lookupCollectionEntryType(
48056
48584
  member.collectionMemberId,
48057
48585
  context,
48058
48586
  nextSeen,
48059
48587
  genericEnvironment
48060
- );
48588
+ ));
48061
48589
  if (!entry) return UNKNOWN_TYPE;
48062
48590
  return isMultiSelectionMember(member) ? {
48063
48591
  kind: "set",
@@ -48910,6 +49438,8 @@ function compileDelegateClosureValue(code, signature) {
48910
49438
  variants: [...signature.variants ?? []],
48911
49439
  variantFolders: [...signature.variantFolders ?? []],
48912
49440
  thisClass: signature.thisClass,
49441
+ implicitMemberAccess: true,
49442
+ staticMember: signature.staticMember,
48913
49443
  returnTypeInfo: {
48914
49444
  type: 25 /* NSDelegate */,
48915
49445
  required: true,
@@ -48979,7 +49509,11 @@ function compileMemberInitializerBody(args) {
48979
49509
  );
48980
49510
  }
48981
49511
  const members = replaceMember(args.members, args.member);
48982
- const returnTypeInfo = resolveMemberDeclaredTypeInfo(args.member, members) ?? initializerGenericTypeInfo(args.member, args.thisClass);
49512
+ const returnTypeInfo = resolveMemberDeclaredTypeInfo(
49513
+ args.member,
49514
+ members,
49515
+ args.thisClass
49516
+ );
48983
49517
  if (returnTypeInfo === null) {
48984
49518
  throw new Error(
48985
49519
  `Member "${args.member.name}" has an initializer but no resolvable declared type.`
@@ -49013,19 +49547,6 @@ function compileMemberInitializerBody(args) {
49013
49547
  }
49014
49548
  Object.assign(defaultValue.init, { compiled });
49015
49549
  }
49016
- function initializerGenericTypeInfo(member, ownerClass) {
49017
- if (!isMemberGenericBase(member) || ownerClass === null) return null;
49018
- const declaration = ownerClass.genericParams?.find(
49019
- (parameter3) => parameter3.id === member.genericParamId
49020
- );
49021
- if (declaration === void 0) return null;
49022
- return {
49023
- type: 21 /* Generic */,
49024
- required: isRequiredMember(member),
49025
- ownerClassId: ownerClass.id,
49026
- genericParamId: declaration.id
49027
- };
49028
- }
49029
49550
  function compileValueRowInitializerBody(args) {
49030
49551
  const container = args.valueRow;
49031
49552
  if (!isInitValueContent(container)) return;
@@ -53695,12 +54216,23 @@ var schemaMemberSchema = variant("kind", [
53695
54216
  enumId: nonEmptyString,
53696
54217
  multiselect: boolean2()
53697
54218
  }),
53698
- memberSchema("lookup", {
53699
- collectionMemberId: nonEmptyString,
53700
- collectionValueId: nullableId,
53701
- multiselect: boolean2(),
53702
- declaredType: nullable(schemaTypeSchema)
53703
- }),
54219
+ pipe(
54220
+ memberSchema("lookup", {
54221
+ /** `null` on an unbound `Reference<T>` (P107), typed by `declaredType`. */
54222
+ collectionMemberId: nullable(nonEmptyString),
54223
+ collectionValueId: nullableId,
54224
+ multiselect: boolean2(),
54225
+ declaredType: nullable(schemaTypeSchema)
54226
+ }),
54227
+ check(
54228
+ (member) => member.collectionMemberId !== null || member.collectionValueId === null,
54229
+ "A lookup collection value requires a collection member."
54230
+ ),
54231
+ check(
54232
+ (member) => member.collectionMemberId !== null || member.declaredType?.kind === "class" || member.declaredType?.kind === "generic",
54233
+ "A lookup without a collection needs a class or generic declared type."
54234
+ )
54235
+ ),
53704
54236
  memberSchema("dialogueLookup", {
53705
54237
  dialogueGroupId: nullableId,
53706
54238
  multiselect: boolean2()
@@ -54098,10 +54630,8 @@ function memberFromDocument(record4, members, owners, classNames, context) {
54098
54630
  return {
54099
54631
  ...common,
54100
54632
  kind: "lookup",
54101
- collectionMemberId: requiredStringValue(
54102
- field("collectionMemberId", void 0),
54103
- record4,
54104
- "collectionMemberId"
54633
+ collectionMemberId: optionalStringOrNull(
54634
+ field("collectionMemberId", null)
54105
54635
  ),
54106
54636
  collectionValueId: optionalStringOrNull(field("collectionValueId", null)),
54107
54637
  multiselect: ordinalValue(
@@ -54419,7 +54949,9 @@ function memberToDocumentFields(member, baseData) {
54419
54949
  }
54420
54950
  }
54421
54951
  if (member.kind === "lookup") {
54422
- fields.collectionMemberId = member.collectionMemberId;
54952
+ if (member.collectionMemberId !== null) {
54953
+ fields.collectionMemberId = member.collectionMemberId;
54954
+ }
54423
54955
  if (member.collectionValueId !== null) {
54424
54956
  fields.collectionValueId = member.collectionValueId;
54425
54957
  }
@@ -56408,7 +56940,7 @@ var INITIALIZER_KEY_PLACEHOLDER = new RegExp(
56408
56940
 
56409
56941
  // ../packages/manifest/schema-contract/registry.mjs
56410
56942
  var PROJECT_SCHEMA_CONTRACT = Object.freeze({
56411
- cliVersion: "0.76.2",
56943
+ cliVersion: "0.77.0",
56412
56944
  projectFileUploadBatchSize: 32,
56413
56945
  documentRecords: {
56414
56946
  member: {
@@ -58594,6 +59126,7 @@ function validateRegistrationAction(action, allowRegistration) {
58594
59126
  }
58595
59127
  }
58596
59128
  function registerSpec(spec, document2) {
59129
+ document2 = withCompiledConstructionTypes(document2, spec.action);
58597
59130
  validateRegistrationAction(spec.action, true);
58598
59131
  const root = {
58599
59132
  name: "",
@@ -58674,7 +59207,7 @@ function registerSpec(spec, document2) {
58674
59207
  makeEvaluatorContext(document2, interceptor),
58675
59208
  []
58676
59209
  );
58677
- return { spec, root, tests };
59210
+ return { spec, root, tests, document: document2 };
58678
59211
  }
58679
59212
  function mockResponse(environment, mock, selected, call) {
58680
59213
  if (selected === null) {
@@ -59097,13 +59630,13 @@ function prepareTestEvaluator(document2) {
59097
59630
  async function executeTestFile(spec, document2, selected, timeoutMs, interrupted2 = () => false) {
59098
59631
  return executeRegisteredSpec(
59099
59632
  registerSpec(spec, document2),
59100
- document2,
59101
59633
  selected,
59102
59634
  timeoutMs,
59103
59635
  interrupted2
59104
59636
  );
59105
59637
  }
59106
- async function executeRegisteredSpec(registered, document2, selected, timeoutMs, interrupted2) {
59638
+ async function executeRegisteredSpec(registered, selected, timeoutMs, interrupted2) {
59639
+ const document2 = registered.document;
59107
59640
  let restoredRuntimeSources = false;
59108
59641
  const reportFailure = (error, position, member = null) => {
59109
59642
  if (error instanceof NSGetterRuntimeError && error.node !== void 0 && (error.source === void 0 || error.callerNode !== void 0 && runtimeSource(error.callerNode) === void 0)) {