@casual-simulation/aux-common
Version:
Common library for AUX projects
40 lines • 1.35 kB
JavaScript
import { TEMPORARY_BOT_PARTITION_ID, COOKIE_BOT_PARTITION_ID, BOOTSTRAP_PARTITION_ID, TEMPORARY_SHARED_PARTITION_ID, REMOTE_TEMPORARY_SHARED_PARTITION_ID, } from '../bots';
import { sortBy } from 'es-toolkit/compat';
/**
* Gets the bots state from the given partition.
* @param partition The partition.
*/
export function getPartitionState(partition) {
return partition.state;
}
/**
* Iterates the given partitions.
* @param partitions The partitions to iterate.
*/
export function* iteratePartitions(partitions) {
const keys = Object.keys(partitions);
const sortedKeys = sortBy(keys, (k) => k === 'shared'
? 0
: k === TEMPORARY_BOT_PARTITION_ID
? 1
: k === COOKIE_BOT_PARTITION_ID
? 2
: k === TEMPORARY_SHARED_PARTITION_ID
? 3
: k === REMOTE_TEMPORARY_SHARED_PARTITION_ID
? 4
: k === BOOTSTRAP_PARTITION_ID
? 5
: 6);
for (let key of sortedKeys) {
if (!Object.prototype.hasOwnProperty.call(partitions, key)) {
continue;
}
const val = partitions[key];
if (!val) {
continue;
}
yield [key, val];
}
}
//# sourceMappingURL=AuxPartition.js.map