tempest.games 0.2.73 → 0.2.75

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.
@@ -114,28 +114,9 @@ var $validatedKey = Symbol.for(`claim`);
114
114
  function simpleCompound(a, b) {
115
115
  return [a, b].sort().join(`\x1F`);
116
116
  }
117
- function decomposeCompound(compound) {
118
- if (typeof compound === `string` === false)
119
- return null;
120
- const [typeTag, components] = compound.split(`==`);
121
- if (!components)
122
- return null;
123
- const type = typeTag.slice(4);
124
- const [a, b] = components.split(`++`);
125
- if (type && a && b)
126
- return [
127
- type,
128
- a,
129
- b
130
- ];
131
- return null;
132
- }
133
117
  function selectorFamily(options) {
134
118
  return createSelectorFamily(IMPLICIT.STORE, options);
135
119
  }
136
- function transaction(options) {
137
- return createTransaction(IMPLICIT.STORE, options);
138
- }
139
120
 
140
121
  // ../../packages/atom.io/dist/json/index.js
141
122
  function parseJson(str) {
@@ -300,9 +281,6 @@ var UList = class UList2 extends Set {
300
281
  };
301
282
 
302
283
  // ../../packages/atom.io/dist/internal/index.js
303
- function arbitrary(random = Math.random) {
304
- return random().toString(36).slice(2);
305
- }
306
284
  function newest(scion) {
307
285
  while (scion.child !== null)
308
286
  scion = scion.child;
@@ -894,426 +872,12 @@ var Junction = class Junction2 {
894
872
  function isReservedIntrospectionKey(value) {
895
873
  return value.startsWith(`\uD83D\uDD0D `);
896
874
  }
897
- var abortTransaction = (target) => {
898
- target.logger.info(`\uD83E\uDE82`, `transaction`, target.transactionMeta.update.token.key, `Aborting transaction`);
899
- target.parent.child = null;
900
- };
901
- function actUponStore(store, token, id) {
902
- return (...parameters) => {
903
- return withdraw(store, token).run(parameters, id);
904
- };
905
- }
906
- function ingestAtomUpdateEvent(store, event, applying) {
907
- const { token, update: { newValue, oldValue } } = event;
908
- setIntoStore(store, token, applying === `newValue` ? newValue : oldValue);
909
- }
910
- function getTrace(error) {
911
- const { stack } = error;
912
- if (stack)
913
- return `
914
- ` + stack.split(`
915
- `)?.slice(1)?.join(`
916
- `);
917
- return ``;
918
- }
919
- function allocateIntoStore(store, provenance, key, dependsOn = `any`) {
920
- const origin = provenance;
921
- const stringKey = stringifyJson(key);
922
- const invalidKeys = [];
923
- const target = newest(store);
924
- if (Array.isArray(origin))
925
- for (const formerClaim of origin) {
926
- const claimString = stringifyJson(formerClaim);
927
- if (target.molecules.get(claimString))
928
- store.moleculeGraph.set(claimString, stringKey, { source: claimString });
929
- else
930
- invalidKeys.push(claimString);
931
- }
932
- else {
933
- const claimString = stringifyJson(origin);
934
- if (target.molecules.get(claimString))
935
- store.moleculeGraph.set(claimString, stringKey, { source: claimString });
936
- else
937
- invalidKeys.push(claimString);
938
- }
939
- const subject = new Subject;
940
- if (invalidKeys.length === 0)
941
- target.molecules.set(stringKey, {
942
- key,
943
- stringKey,
944
- dependsOn,
945
- subject
946
- });
947
- const creationEvent = {
948
- type: `molecule_creation`,
949
- key,
950
- provenance: origin,
951
- timestamp: Date.now()
952
- };
953
- if (isChildStore(target) && target.transactionMeta.phase === `building`)
954
- target.transactionMeta.update.subEvents.push(creationEvent);
955
- else
956
- target.on.moleculeCreation.next(creationEvent);
957
- for (const claim of invalidKeys) {
958
- const disposal = store.disposalTraces.buffer.find((item) => item?.key === claim);
959
- store.logger.error(`\u274C`, `key`, key, `allocation failed:`, `Could not allocate to ${claim} in store "${store.config.name}".`, disposal ? `
960
- ${claim} was most recently disposed
961
- ${disposal.trace}` : `No previous disposal trace for ${claim} was found.`);
962
- }
963
- return key;
964
- }
965
- function deallocateFromStore(target, claim) {
966
- const stringKey = stringifyJson(claim);
967
- const molecule = target.molecules.get(stringKey);
968
- if (!molecule) {
969
- const disposal = target.disposalTraces.buffer.find((item) => item?.key === stringKey);
970
- target.logger.error(`\u274C`, `key`, claim, `deallocation failed:`, `Could not find allocation for ${stringKey} in store "${target.config.name}".`, disposal ? `
971
- This state was most recently deallocated
972
- ${disposal.trace}` : `No previous disposal trace for ${stringKey} was found.`);
973
- return;
974
- }
975
- molecule.subject.next();
976
- const joinKeys = target.keyRefsInJoins.getRelatedKeys(stringKey);
977
- if (joinKeys)
978
- for (const joinKey of joinKeys) {
979
- const join$1 = target.joins.get(joinKey);
980
- if (join$1)
981
- join$1.relations.delete(claim);
982
- }
983
- else {
984
- const compound = decomposeCompound(claim);
985
- if (compound) {
986
- const [, a, b] = compound;
987
- const joinKey = target.keyRefsInJoins.getRelatedKey(simpleCompound(a, b));
988
- if (joinKey) {
989
- const join$1 = target.joins.get(joinKey);
990
- if (join$1)
991
- join$1.relations.delete(a, b);
992
- }
993
- }
994
- }
995
- target.keyRefsInJoins.delete(stringKey);
996
- const provenance = [];
997
- const values = [];
998
- const relatedMolecules = target.moleculeGraph.getRelationEntries({ downstreamMoleculeKey: stringKey });
999
- if (relatedMolecules)
1000
- for (const [relatedStringKey, { source }] of relatedMolecules)
1001
- if (source === stringKey)
1002
- deallocateFromStore(target, parseJson(relatedStringKey));
1003
- else
1004
- provenance.push(source);
1005
- const familyKeys = target.moleculeData.getRelatedKeys(molecule.stringKey);
1006
- if (familyKeys)
1007
- for (const familyKey of familyKeys) {
1008
- const family = target.families.get(familyKey);
1009
- const value = getFromStore(target, family, claim);
1010
- values.push([family.key, value]);
1011
- disposeFromStore(target, family, claim);
1012
- }
1013
- const disposalEvent = {
1014
- type: `molecule_disposal`,
1015
- key: molecule.key,
1016
- values,
1017
- provenance,
1018
- timestamp: Date.now()
1019
- };
1020
- target.molecules.delete(stringKey);
1021
- const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
1022
- if (isTransaction)
1023
- target.transactionMeta.update.subEvents.push(disposalEvent);
1024
- target.moleculeGraph.delete(molecule.stringKey);
1025
- target.keyRefsInJoins.delete(molecule.stringKey);
1026
- target.moleculeData.delete(molecule.stringKey);
1027
- if (!isTransaction)
1028
- target.on.moleculeDisposal.next(disposalEvent);
1029
- target.molecules.delete(molecule.stringKey);
1030
- const trace = getTrace(/* @__PURE__ */ new Error);
1031
- target.disposalTraces.add({
1032
- key: stringKey,
1033
- trace
1034
- });
1035
- }
1036
- function claimWithinStore(store, newProvenance, claim, exclusive) {
1037
- const stringKey = stringifyJson(claim);
1038
- const target = newest(store);
1039
- const molecule = target.molecules.get(stringKey);
1040
- if (!molecule) {
1041
- const disposal = store.disposalTraces.buffer.find((item) => item?.key === stringKey);
1042
- store.logger.error(`\u274C`, `key`, stringKey, `claim failed:`, `Could not allocate to ${stringKey} in store "${store.config.name}".`, disposal ? `
1043
- ${stringKey} was most recently disposed
1044
- ${disposal.trace}` : `No previous disposal trace for ${stringKey} was found.`);
1045
- return claim;
1046
- }
1047
- const newProvenanceKey = stringifyJson(newProvenance);
1048
- const newProvenanceMolecule = target.molecules.get(newProvenanceKey);
1049
- if (!newProvenanceMolecule) {
1050
- const disposal = store.disposalTraces.buffer.find((item) => item?.key === newProvenanceKey);
1051
- store.logger.error(`\u274C`, `key`, claim, `claim failed:`, `Could not allocate to ${newProvenanceKey} in store "${store.config.name}".`, disposal ? `
1052
- ${newProvenanceKey} was most recently disposed
1053
- ${disposal.trace}` : `No previous disposal trace for ${newProvenanceKey} was found.`);
1054
- return claim;
1055
- }
1056
- const priorProvenance = store.moleculeGraph.getRelationEntries({ downstreamMoleculeKey: molecule.stringKey }).filter(([, { source }]) => source !== stringKey).map(([key]) => parseJson(key));
1057
- if (exclusive)
1058
- target.moleculeGraph.delete(stringKey);
1059
- target.moleculeGraph.set({
1060
- upstreamMoleculeKey: newProvenanceMolecule.stringKey,
1061
- downstreamMoleculeKey: molecule.stringKey
1062
- }, { source: newProvenanceMolecule.stringKey });
1063
- const transferEvent = {
1064
- type: `molecule_transfer`,
1065
- key: molecule.key,
1066
- exclusive: Boolean(exclusive),
1067
- from: priorProvenance,
1068
- to: [newProvenanceMolecule.key],
1069
- timestamp: Date.now()
1070
- };
1071
- if (isChildStore(target) && target.transactionMeta.phase === `building`)
1072
- target.transactionMeta.update.subEvents.push(transferEvent);
1073
- return claim;
1074
- }
1075
- function ingestCreationEvent(store, event, applying) {
1076
- switch (applying) {
1077
- case `newValue`:
1078
- createInStore(store, event);
1079
- break;
1080
- case `oldValue`:
1081
- disposeFromStore(store, event.token);
1082
- break;
1083
- }
1084
- }
1085
- function ingestDisposalEvent(store, event, applying) {
1086
- switch (applying) {
1087
- case `newValue`:
1088
- disposeFromStore(store, event.token);
1089
- break;
1090
- case `oldValue`:
1091
- createInStore(store, event);
1092
- if (event.subType === `atom`)
1093
- store.valueMap.set(event.token.key, event.value);
1094
- break;
1095
- }
1096
- }
1097
- function createInStore(store, event) {
1098
- const { token } = event;
1099
- if (event.subType === `writable` && event.value)
1100
- setIntoStore(store, token, event.value);
1101
- else
1102
- getFromStore(store, token);
1103
- }
1104
- function ingestMoleculeCreationEvent(store, event, applying) {
1105
- switch (applying) {
1106
- case `newValue`:
1107
- allocateIntoStore(store, event.provenance, event.key);
1108
- break;
1109
- case `oldValue`:
1110
- deallocateFromStore(store, event.key);
1111
- break;
1112
- }
1113
- }
1114
- function ingestMoleculeDisposalEvent(store, event, applying) {
1115
- switch (applying) {
1116
- case `newValue`:
1117
- deallocateFromStore(store, event.key);
1118
- break;
1119
- case `oldValue`:
1120
- allocateIntoStore(store, event.provenance.map(parseJson), event.key);
1121
- for (const [familyKey, value] of event.values) {
1122
- const family = store.families.get(familyKey);
1123
- if (family) {
1124
- getFromStore(store, family, event.key);
1125
- const memberKey = `${familyKey}(${stringifyJson(event.key)})`;
1126
- store.valueMap.set(memberKey, value);
1127
- }
1128
- }
1129
- break;
1130
- }
1131
- }
1132
- function ingestMoleculeTransferEvent(store, event, applying) {
1133
- switch (applying) {
1134
- case `newValue`:
1135
- for (const newOwner of event.to)
1136
- claimWithinStore(store, newOwner, event.key, event.exclusive ? `exclusive` : undefined);
1137
- break;
1138
- case `oldValue`:
1139
- {
1140
- let exclusivity = `exclusive`;
1141
- for (const previousOwner of event.from) {
1142
- claimWithinStore(store, previousOwner, event.key, exclusivity);
1143
- exclusivity = undefined;
1144
- }
1145
- }
1146
- break;
1147
- }
1148
- }
1149
- function ingestTransactionOutcomeEvent(store, event, applying) {
1150
- const subEvents = applying === `newValue` ? event.subEvents : [...event.subEvents].reverse();
1151
- for (const subEvent of subEvents)
1152
- switch (subEvent.type) {
1153
- case `atom_update`:
1154
- ingestAtomUpdateEvent(store, subEvent, applying);
1155
- break;
1156
- case `state_creation`:
1157
- ingestCreationEvent(store, subEvent, applying);
1158
- break;
1159
- case `state_disposal`:
1160
- ingestDisposalEvent(store, subEvent, applying);
1161
- break;
1162
- case `molecule_creation`:
1163
- ingestMoleculeCreationEvent(store, subEvent, applying);
1164
- break;
1165
- case `molecule_disposal`:
1166
- ingestMoleculeDisposalEvent(store, subEvent, applying);
1167
- break;
1168
- case `molecule_transfer`:
1169
- ingestMoleculeTransferEvent(store, subEvent, applying);
1170
- break;
1171
- case `transaction_outcome`:
1172
- ingestTransactionOutcomeEvent(store, subEvent, applying);
1173
- break;
1174
- }
1175
- }
1176
875
  function isRootStore(store) {
1177
876
  return `epoch` in store.transactionMeta;
1178
877
  }
1179
878
  function isChildStore(store) {
1180
879
  return `phase` in store.transactionMeta;
1181
880
  }
1182
- function getContinuityKey(store, transactionKey) {
1183
- return store.transactionMeta.actionContinuities.getRelatedKey(transactionKey);
1184
- }
1185
- function getEpochNumberOfContinuity(store, continuityKey) {
1186
- return store.transactionMeta.epoch.get(continuityKey);
1187
- }
1188
- function getEpochNumberOfAction(store, transactionKey) {
1189
- const continuityKey = getContinuityKey(store, transactionKey);
1190
- if (continuityKey === undefined)
1191
- return;
1192
- return getEpochNumberOfContinuity(store, continuityKey);
1193
- }
1194
- function setEpochNumberOfAction(store, transactionKey, newEpoch) {
1195
- const continuityKey = getContinuityKey(store, transactionKey);
1196
- if (continuityKey !== undefined)
1197
- store.transactionMeta.epoch.set(continuityKey, newEpoch);
1198
- }
1199
- function applyTransaction(store, output) {
1200
- const child = newest(store);
1201
- const { parent } = child;
1202
- child.transactionMeta.phase = `applying`;
1203
- child.transactionMeta.update.output = output;
1204
- parent.child = null;
1205
- parent.on.transactionApplying.next(child.transactionMeta);
1206
- const { subEvents: updates } = child.transactionMeta.update;
1207
- store.logger.info(`\uD83D\uDEC4`, `transaction`, child.transactionMeta.update.token.key, `applying ${updates.length} subEvents:`, updates);
1208
- ingestTransactionOutcomeEvent(parent, child.transactionMeta.update, `newValue`);
1209
- if (isRootStore(parent)) {
1210
- setEpochNumberOfAction(parent, child.transactionMeta.update.token.key, child.transactionMeta.update.epoch);
1211
- withdraw(store, {
1212
- key: child.transactionMeta.update.token.key,
1213
- type: `transaction`
1214
- })?.subject.next(child.transactionMeta.update);
1215
- store.logger.info(`\uD83D\uDEEC`, `transaction`, child.transactionMeta.update.token.key, `applied`);
1216
- } else if (isChildStore(parent))
1217
- parent.transactionMeta.update.subEvents.push(child.transactionMeta.update);
1218
- parent.on.transactionApplying.next(null);
1219
- }
1220
- function getEnvironmentData(store) {
1221
- return { store };
1222
- }
1223
- var buildTransaction = (store, token, params, id) => {
1224
- const parent = newest(store);
1225
- const childBase = {
1226
- parent,
1227
- child: null,
1228
- on: parent.on,
1229
- loggers: parent.loggers,
1230
- logger: parent.logger,
1231
- config: parent.config,
1232
- atoms: new MapOverlay(parent.atoms),
1233
- atomsThatAreDefault: new Set(parent.atomsThatAreDefault),
1234
- families: new MapOverlay(parent.families),
1235
- joins: new MapOverlay(parent.joins),
1236
- operation: { open: false },
1237
- readonlySelectors: new MapOverlay(parent.readonlySelectors),
1238
- timelines: new MapOverlay(parent.timelines),
1239
- timelineTopics: parent.timelineTopics.overlay(),
1240
- trackers: /* @__PURE__ */ new Map,
1241
- transactions: new MapOverlay(parent.transactions),
1242
- selectorAtoms: parent.selectorAtoms.overlay(),
1243
- selectorGraph: parent.selectorGraph.overlay(),
1244
- writableSelectors: new MapOverlay(parent.writableSelectors),
1245
- valueMap: new MapOverlay(parent.valueMap),
1246
- defaults: parent.defaults,
1247
- disposalTraces: store.disposalTraces.copy(),
1248
- molecules: new MapOverlay(parent.molecules),
1249
- moleculeGraph: parent.moleculeGraph.overlay(),
1250
- moleculeData: parent.moleculeData.overlay(),
1251
- keyRefsInJoins: parent.keyRefsInJoins.overlay(),
1252
- miscResources: new MapOverlay(parent.miscResources)
1253
- };
1254
- const epoch = getEpochNumberOfAction(store, token.key);
1255
- const transactionMeta = {
1256
- phase: `building`,
1257
- update: {
1258
- type: `transaction_outcome`,
1259
- token,
1260
- id,
1261
- epoch: epoch === undefined ? NaN : epoch + 1,
1262
- timestamp: Date.now(),
1263
- subEvents: [],
1264
- params,
1265
- output: undefined
1266
- },
1267
- toolkit: {
1268
- get: (...ps) => getFromStore(child, ...ps),
1269
- set: (...ps) => {
1270
- setIntoStore(child, ...ps);
1271
- },
1272
- reset: (...ps) => {
1273
- resetInStore(child, ...ps);
1274
- },
1275
- run: (t, identifier = arbitrary()) => actUponStore(child, t, identifier),
1276
- find: (...ps) => findInStore(store, ...ps),
1277
- json: (t) => getJsonToken(child, t),
1278
- dispose: (...ps) => {
1279
- disposeFromStore(child, ...ps);
1280
- },
1281
- env: () => getEnvironmentData(child)
1282
- }
1283
- };
1284
- const child = Object.assign(childBase, { transactionMeta });
1285
- parent.child = child;
1286
- store.logger.info(`\uD83D\uDEEB`, `transaction`, token.key, `building with params:`, params);
1287
- return child;
1288
- };
1289
- function createTransaction(store, options) {
1290
- const { key } = options;
1291
- const transactionAlreadyExists = store.transactions.has(key);
1292
- const newTransaction = {
1293
- key,
1294
- type: `transaction`,
1295
- run: (params, id) => {
1296
- const target = buildTransaction(store, deposit(newTransaction), params, id);
1297
- try {
1298
- const { toolkit } = target.transactionMeta;
1299
- const output = options.do(toolkit, ...params);
1300
- applyTransaction(target, output);
1301
- return output;
1302
- } catch (thrown) {
1303
- abortTransaction(target);
1304
- store.logger.warn(`\uD83D\uDCA5`, `transaction`, key, `caught:`, thrown);
1305
- throw thrown;
1306
- }
1307
- },
1308
- install: (s) => createTransaction(s, options),
1309
- subject: new Subject
1310
- };
1311
- newest(store).transactions.set(key, newTransaction);
1312
- const token = deposit(newTransaction);
1313
- if (!transactionAlreadyExists)
1314
- store.on.transactionCreation.next(token);
1315
- return token;
1316
- }
1317
881
  var Store = class {
1318
882
  parent = null;
1319
883
  child = null;
@@ -1991,34 +1555,6 @@ function createSelectorFamily(store, options) {
1991
1555
  return createWritablePureSelectorFamily(store, options);
1992
1556
  return createReadonlyPureSelectorFamily(store, options);
1993
1557
  }
1994
- function disposeFromStore(store, ...params) {
1995
- let token;
1996
- if (params.length === 1)
1997
- token = params[0];
1998
- else {
1999
- const family = params[0];
2000
- const key = params[1];
2001
- token = findInStore(store, family, key);
2002
- }
2003
- try {
2004
- withdraw(store, token);
2005
- } catch (_) {
2006
- store.logger.error(`\u274C`, token.type, token.key, `could not be disposed because it was not found in the store "${store.config.name}".`);
2007
- return;
2008
- }
2009
- switch (token.type) {
2010
- case `atom`:
2011
- case `mutable_atom`:
2012
- disposeAtom(store, token);
2013
- break;
2014
- case `writable_pure_selector`:
2015
- case `readonly_pure_selector`:
2016
- case `writable_held_selector`:
2017
- case `readonly_held_selector`:
2018
- disposeSelector(store, token);
2019
- break;
2020
- }
2021
- }
2022
1558
  function openOperation(store, token) {
2023
1559
  if (store.operation.open) {
2024
1560
  const rejectionTime = performance.now();
@@ -2588,85 +2124,6 @@ function createStandaloneSelector(store, options) {
2588
2124
  store.on.selectorCreation.next(state);
2589
2125
  return state;
2590
2126
  }
2591
- function disposeSelector(store, selectorToken) {
2592
- const target = newest(store);
2593
- const { key, type, family: familyMeta } = selectorToken;
2594
- if (!familyMeta)
2595
- store.logger.error(`\u274C`, type, key, `Standalone selectors cannot be disposed.`);
2596
- else {
2597
- if (target.molecules.get(familyMeta.subKey))
2598
- target.moleculeData.delete(familyMeta.subKey, familyMeta.key);
2599
- let familyToken;
2600
- switch (selectorToken.type) {
2601
- case `writable_held_selector`:
2602
- target.writableSelectors.delete(key);
2603
- familyToken = {
2604
- key: familyMeta.key,
2605
- type: `writable_held_selector_family`
2606
- };
2607
- withdraw(store, familyToken).subject.next({
2608
- type: `state_disposal`,
2609
- subType: `selector`,
2610
- token: selectorToken,
2611
- timestamp: Date.now()
2612
- });
2613
- break;
2614
- case `writable_pure_selector`:
2615
- target.writableSelectors.delete(key);
2616
- familyToken = {
2617
- key: familyMeta.key,
2618
- type: `writable_pure_selector_family`
2619
- };
2620
- withdraw(store, familyToken).subject.next({
2621
- type: `state_disposal`,
2622
- subType: `selector`,
2623
- token: selectorToken,
2624
- timestamp: Date.now()
2625
- });
2626
- break;
2627
- case `readonly_held_selector`:
2628
- target.readonlySelectors.delete(key);
2629
- familyToken = {
2630
- key: familyMeta.key,
2631
- type: `readonly_held_selector_family`
2632
- };
2633
- withdraw(store, familyToken).subject.next({
2634
- type: `state_disposal`,
2635
- subType: `selector`,
2636
- token: selectorToken,
2637
- timestamp: Date.now()
2638
- });
2639
- break;
2640
- case `readonly_pure_selector`:
2641
- target.readonlySelectors.delete(key);
2642
- familyToken = {
2643
- key: familyMeta.key,
2644
- type: `readonly_pure_selector_family`
2645
- };
2646
- withdraw(store, familyToken).subject.next({
2647
- type: `state_disposal`,
2648
- subType: `selector`,
2649
- token: selectorToken,
2650
- timestamp: Date.now()
2651
- });
2652
- break;
2653
- }
2654
- target.valueMap.delete(key);
2655
- target.selectorAtoms.delete(key);
2656
- target.selectorGraph.delete(key);
2657
- target.moleculeData.delete(familyMeta.key, familyMeta.subKey);
2658
- store.logger.info(`\uD83D\uDD25`, selectorToken.type, key, `deleted`);
2659
- if (isChildStore(target) && target.transactionMeta.phase === `building`)
2660
- target.transactionMeta.update.subEvents.push({
2661
- type: `state_disposal`,
2662
- subType: `selector`,
2663
- token: selectorToken,
2664
- timestamp: Date.now()
2665
- });
2666
- else
2667
- store.on.selectorDisposal.next(selectorToken);
2668
- }
2669
- }
2670
2127
  var recallState = (store, state) => {
2671
2128
  const target = newest(store);
2672
2129
  if (target.operation.open)
@@ -3141,46 +2598,6 @@ function hasRole(atom, role) {
3141
2598
  return false;
3142
2599
  return atom.internalRoles.includes(role);
3143
2600
  }
3144
- function disposeAtom(store, atomToken) {
3145
- const target = newest(store);
3146
- const { key, family } = atomToken;
3147
- const atom = withdraw(target, atomToken);
3148
- if (!family)
3149
- store.logger.error(`\u274C`, `atom`, key, `Standalone atoms cannot be disposed.`);
3150
- else {
3151
- atom.cleanup?.();
3152
- const lastValue = store.valueMap.get(atom.key);
3153
- const subject = withdraw(store, getFamilyOfToken(store, atomToken)).subject;
3154
- const disposalEvent = {
3155
- type: `state_disposal`,
3156
- subType: `atom`,
3157
- token: atomToken,
3158
- value: lastValue,
3159
- timestamp: Date.now()
3160
- };
3161
- subject.next(disposalEvent);
3162
- const isChild = isChildStore(target);
3163
- target.atoms.delete(key);
3164
- target.valueMap.delete(key);
3165
- target.selectorAtoms.delete(key);
3166
- target.atomsThatAreDefault.delete(key);
3167
- target.moleculeData.delete(family.key, family.subKey);
3168
- store.timelineTopics.delete(key);
3169
- if (atomToken.type === `mutable_atom`) {
3170
- disposeAtom(store, getUpdateToken(atomToken));
3171
- store.trackers.delete(key);
3172
- }
3173
- store.logger.info(`\uD83D\uDD25`, `atom`, key, `deleted`);
3174
- if (isChild && target.transactionMeta.phase === `building`) {
3175
- const mostRecentUpdate = target.transactionMeta.update.subEvents.at(-1);
3176
- const updateAlreadyCaptured = mostRecentUpdate?.type === `molecule_disposal` && mostRecentUpdate.values.some(([k]) => k === atom.family?.key);
3177
- const isTracker = hasRole(atom, `tracker:signal`);
3178
- if (!updateAlreadyCaptured && !isTracker)
3179
- target.transactionMeta.update.subEvents.push(disposalEvent);
3180
- } else
3181
- store.on.atomDisposal.next(atomToken);
3182
- }
3183
- }
3184
2601
  function capitalize(string) {
3185
2602
  return string[0].toUpperCase() + string.slice(1);
3186
2603
  }
@@ -3523,11 +2940,10 @@ var SyncGroup = class SyncGroup2 {
3523
2940
  return this;
3524
2941
  }
3525
2942
  };
3526
- var usersInThisRoomIndex = mutableAtom({
3527
- key: `usersInRoomIndex`,
3528
- class: UList
3529
- });
3530
- var roomIndex = mutableAtom({
2943
+ var isSocketKey = (key) => key.startsWith(`socket::`);
2944
+ var isUserKey = (key) => key.startsWith(`user::`);
2945
+ var isRoomKey = (key) => key.startsWith(`room::`);
2946
+ var roomKeysAtom = mutableAtom({
3531
2947
  key: `roomIndex`,
3532
2948
  class: UList
3533
2949
  });
@@ -3535,8 +2951,8 @@ var usersInRooms = join({
3535
2951
  key: `usersInRooms`,
3536
2952
  between: [`room`, `user`],
3537
2953
  cardinality: `1:n`,
3538
- isAType: (input) => typeof input === `string`,
3539
- isBType: (input) => typeof input === `string`
2954
+ isAType: isRoomKey,
2955
+ isBType: isUserKey
3540
2956
  });
3541
2957
  var usersInMyRoomView = selectorFamily({
3542
2958
  key: `usersInMyRoomView`,
@@ -3887,54 +3303,15 @@ var ParentSocket = class extends CustomSocket {
3887
3303
  this.relayServices.push(attachServices);
3888
3304
  }
3889
3305
  };
3890
- var ROOMS = /* @__PURE__ */ new Map;
3891
- var joinRoomTX = transaction({
3892
- key: `joinRoom`,
3893
- do: (tools, roomId, userId, enteredAtEpoch) => {
3894
- const meta = { enteredAtEpoch };
3895
- editRelationsInStore(usersInRooms, (relations) => {
3896
- relations.set({
3897
- room: roomId,
3898
- user: userId
3899
- });
3900
- }, tools.env().store);
3901
- return meta;
3902
- }
3903
- });
3904
- var leaveRoomTX = transaction({
3905
- key: `leaveRoom`,
3906
- do: ({ env }, roomId, userId) => {
3907
- editRelationsInStore(usersInRooms, (relations) => {
3908
- relations.delete({
3909
- room: roomId,
3910
- user: userId
3911
- });
3912
- }, env().store);
3913
- }
3914
- });
3915
- var destroyRoomTX = transaction({
3916
- key: `destroyRoom`,
3917
- do: ({ set, env }, roomId) => {
3918
- editRelationsInStore(usersInRooms, (relations) => {
3919
- relations.delete({ room: roomId });
3920
- }, env().store);
3921
- set(roomIndex, (s) => (s.delete(roomId), s));
3922
- const room = ROOMS.get(roomId);
3923
- if (room) {
3924
- room.emit(`exit`);
3925
- ROOMS.delete(roomId);
3926
- }
3927
- }
3928
- });
3929
3306
  var socketAtoms = atomFamily({
3930
3307
  key: `sockets`,
3931
3308
  default: null
3932
3309
  });
3933
- var socketIndex = mutableAtom({
3310
+ var socketKeysAtom = mutableAtom({
3934
3311
  key: `socketsIndex`,
3935
3312
  class: UList
3936
3313
  });
3937
- var userIndex = mutableAtom({
3314
+ var userKeysAtom = mutableAtom({
3938
3315
  key: `usersIndex`,
3939
3316
  class: UList
3940
3317
  });
@@ -3942,15 +3319,14 @@ var usersOfSockets = join({
3942
3319
  key: `usersOfSockets`,
3943
3320
  between: [`user`, `socket`],
3944
3321
  cardinality: `1:1`,
3945
- isAType: (s) => s.startsWith(`user::`),
3946
- isBType: (s) => s.startsWith(`socket::`)
3322
+ isAType: isUserKey,
3323
+ isBType: isSocketKey
3947
3324
  });
3948
- var userMutualSituationalAwarenessIndexes = selectorFamily({
3949
- key: `userMutualSituationalAwarenessIndexes`,
3950
- get: (userId) => () => {
3951
- return [userId];
3952
- }
3325
+ var selfListSelectors = selectorFamily({
3326
+ key: `selfList`,
3327
+ get: (userId) => () => [userId]
3953
3328
  });
3329
+ var ROOMS = globalThis.ATOM_IO_REALTIME_SERVER_ROOMS ?? (globalThis.ATOM_IO_REALTIME_SERVER_ROOMS = /* @__PURE__ */ new Map);
3954
3330
 
3955
3331
  // src/backend.worker.game.bun.ts
3956
3332
  var parent = new ParentSocket(process);