koota 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3,10 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __typeError = (msg) => {
7
- throw TypeError(msg);
8
- };
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
6
  var __export = (target, all) => {
11
7
  for (var name in all)
12
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,19 +16,6 @@ var __copyProps = (to, from, except, desc) => {
20
16
  return to;
21
17
  };
22
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
25
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
26
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
27
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
28
- var __privateWrapper = (obj, member, setter, getter) => ({
29
- set _(value) {
30
- __privateSet(obj, member, value, setter);
31
- },
32
- get _() {
33
- return __privateGet(obj, member, getter);
34
- }
35
- });
36
19
 
37
20
  // src/index.ts
38
21
  var index_exports = {};
@@ -109,7 +92,7 @@ var universe = {
109
92
  cachedQueries: /* @__PURE__ */ new Map(),
110
93
  worldIndex: createWorldIndex(),
111
94
  reset: () => {
112
- universe.worlds = new Array(WORLD_ID_BITS ** 2);
95
+ universe.worlds = new Array(WORLD_ID_BITS ** 2).fill(null);
113
96
  universe.cachedQueries = /* @__PURE__ */ new Map();
114
97
  universe.worldIndex = createWorldIndex();
115
98
  }
@@ -121,9 +104,9 @@ var ModifierData = class {
121
104
  this.type = type;
122
105
  this.id = id;
123
106
  this.traits = traits;
124
- __publicField(this, "traitIds");
125
107
  this.traitIds = traits.map((trait2) => trait2[$internal].id);
126
108
  }
109
+ traitIds;
127
110
  };
128
111
 
129
112
  // ../core/src/query/utils/tracking-cursor.ts
@@ -153,7 +136,7 @@ function createChanged() {
153
136
  const id = createTrackingId();
154
137
  for (const world of universe.worlds) {
155
138
  if (!world) continue;
156
- setTrackingMasks(world, id);
139
+ setTrackingMasks(world.deref(), id);
157
140
  }
158
141
  return (...traits) => new ModifierData(`changed-${id}`, id, traits);
159
142
  }
@@ -216,8 +199,9 @@ function getRelationTrait(relation2, traitFactory, pairsMap, target) {
216
199
  }
217
200
  var getRelationTargets = (world, relation2, entity) => {
218
201
  const ctx = world[$internal];
219
- const traits = ctx.entityTraits.get(entity) || [];
202
+ const traits = ctx.entityTraits.get(entity);
220
203
  const targets = [];
204
+ if (!traits) return targets;
221
205
  for (const trait2 of traits) {
222
206
  const traitCtx = trait2[$internal];
223
207
  if (traitCtx.relation === relation2 && traitCtx.pairTarget !== Wildcard) {
@@ -249,15 +233,15 @@ var incrementWorldBitflag = (world) => {
249
233
 
250
234
  // ../core/src/trait/trait-data.ts
251
235
  var TraitData = class {
236
+ generationId;
237
+ bitflag;
238
+ trait;
239
+ store;
240
+ queries;
241
+ notQueries;
242
+ schema;
243
+ changedSubscriptions;
252
244
  constructor(world, trait2) {
253
- __publicField(this, "generationId");
254
- __publicField(this, "bitflag");
255
- __publicField(this, "trait");
256
- __publicField(this, "store");
257
- __publicField(this, "queries");
258
- __publicField(this, "notQueries");
259
- __publicField(this, "schema");
260
- __publicField(this, "changedSubscriptions");
261
245
  const ctx = world[$internal];
262
246
  const traitCtx = trait2[$internal];
263
247
  this.generationId = ctx.entityMasks.length - 1;
@@ -590,47 +574,47 @@ var getAliveEntities = (index) => {
590
574
  // ../core/src/entity/entity-methods-patch.ts
591
575
  Number.prototype.add = function(...traits) {
592
576
  const worldId = this >>> WORLD_ID_SHIFT;
593
- const world = universe.worlds[worldId];
577
+ const world = universe.worlds[worldId].deref();
594
578
  return addTrait(world, this, ...traits);
595
579
  };
596
580
  Number.prototype.remove = function(...traits) {
597
581
  const worldId = this >>> WORLD_ID_SHIFT;
598
- const world = universe.worlds[worldId];
582
+ const world = universe.worlds[worldId].deref();
599
583
  return removeTrait(world, this, ...traits);
600
584
  };
601
585
  Number.prototype.has = function(trait2) {
602
586
  const worldId = this >>> WORLD_ID_SHIFT;
603
- const world = universe.worlds[worldId];
587
+ const world = universe.worlds[worldId].deref();
604
588
  return hasTrait(world, this, trait2);
605
589
  };
606
590
  Number.prototype.destroy = function() {
607
591
  const worldId = this >>> WORLD_ID_SHIFT;
608
- const world = universe.worlds[worldId];
592
+ const world = universe.worlds[worldId].deref();
609
593
  return destroyEntity(world, this);
610
594
  };
611
595
  Number.prototype.changed = function(trait2) {
612
596
  const worldId = this >>> WORLD_ID_SHIFT;
613
- const world = universe.worlds[worldId];
597
+ const world = universe.worlds[worldId].deref();
614
598
  return setChanged(world, this, trait2);
615
599
  };
616
600
  Number.prototype.get = function(trait2) {
617
601
  const worldId = this >>> WORLD_ID_SHIFT;
618
- const world = universe.worlds[worldId];
602
+ const world = universe.worlds[worldId].deref();
619
603
  return getTrait(world, this, trait2);
620
604
  };
621
605
  Number.prototype.set = function(trait2, value, triggerChanged = true) {
622
606
  const worldId = this >>> WORLD_ID_SHIFT;
623
- const world = universe.worlds[worldId];
607
+ const world = universe.worlds[worldId].deref();
624
608
  setTrait(world, this, trait2, value, triggerChanged);
625
609
  };
626
610
  Number.prototype.targetsFor = function(relation2) {
627
611
  const worldId = this >>> WORLD_ID_SHIFT;
628
- const world = universe.worlds[worldId];
612
+ const world = universe.worlds[worldId].deref();
629
613
  return getRelationTargets(world, relation2, this);
630
614
  };
631
615
  Number.prototype.targetFor = function(relation2) {
632
616
  const worldId = this >>> WORLD_ID_SHIFT;
633
- const world = universe.worlds[worldId];
617
+ const world = universe.worlds[worldId].deref();
634
618
  return getRelationTargets(world, relation2, this)[0];
635
619
  };
636
620
  Number.prototype.id = function() {
@@ -639,7 +623,7 @@ Number.prototype.id = function() {
639
623
  };
640
624
  Number.prototype.isAlive = function() {
641
625
  const worldId = this >>> WORLD_ID_SHIFT;
642
- const world = universe.worlds[worldId];
626
+ const world = universe.worlds[worldId].deref();
643
627
  return isEntityAlive(world[$internal].entityIndex, this);
644
628
  };
645
629
 
@@ -705,57 +689,51 @@ function destroyEntity(world, entity) {
705
689
  }
706
690
 
707
691
  // ../core/src/utils/sparse-set.ts
708
- var _dense, _sparse, _cursor;
709
692
  var SparseSet = class {
710
- constructor() {
711
- __privateAdd(this, _dense, []);
712
- __privateAdd(this, _sparse, []);
713
- __privateAdd(this, _cursor, 0);
714
- }
693
+ #dense = [];
694
+ #sparse = [];
695
+ #cursor = 0;
715
696
  has(val) {
716
- const index = __privateGet(this, _sparse)[val];
717
- return index < __privateGet(this, _cursor) && __privateGet(this, _dense)[index] === val;
697
+ const index = this.#sparse[val];
698
+ return index < this.#cursor && this.#dense[index] === val;
718
699
  }
719
700
  add(val) {
720
701
  if (this.has(val)) return;
721
- __privateGet(this, _sparse)[val] = __privateGet(this, _cursor);
722
- __privateGet(this, _dense)[__privateWrapper(this, _cursor)._++] = val;
702
+ this.#sparse[val] = this.#cursor;
703
+ this.#dense[this.#cursor++] = val;
723
704
  }
724
705
  remove(val) {
725
706
  if (!this.has(val)) return;
726
- const index = __privateGet(this, _sparse)[val];
727
- __privateWrapper(this, _cursor)._--;
728
- const swapped = __privateGet(this, _dense)[__privateGet(this, _cursor)];
707
+ const index = this.#sparse[val];
708
+ this.#cursor--;
709
+ const swapped = this.#dense[this.#cursor];
729
710
  if (swapped !== val) {
730
- __privateGet(this, _dense)[index] = swapped;
731
- __privateGet(this, _sparse)[swapped] = index;
711
+ this.#dense[index] = swapped;
712
+ this.#sparse[swapped] = index;
732
713
  }
733
714
  }
734
715
  clear() {
735
- for (let i = 0; i < __privateGet(this, _cursor); i++) {
736
- __privateGet(this, _sparse)[__privateGet(this, _dense)[i]] = 0;
716
+ for (let i = 0; i < this.#cursor; i++) {
717
+ this.#sparse[this.#dense[i]] = 0;
737
718
  }
738
- __privateSet(this, _cursor, 0);
719
+ this.#cursor = 0;
739
720
  }
740
721
  sort() {
741
- __privateGet(this, _dense).sort((a, b) => a - b);
742
- for (let i = 0; i < __privateGet(this, _dense).length; i++) {
743
- __privateGet(this, _sparse)[__privateGet(this, _dense)[i]] = i;
722
+ this.#dense.sort((a, b) => a - b);
723
+ for (let i = 0; i < this.#dense.length; i++) {
724
+ this.#sparse[this.#dense[i]] = i;
744
725
  }
745
726
  }
746
727
  getIndex(val) {
747
- return __privateGet(this, _sparse)[val];
728
+ return this.#sparse[val];
748
729
  }
749
730
  get dense() {
750
- return __privateGet(this, _dense).slice(0, __privateGet(this, _cursor));
731
+ return this.#dense.slice(0, this.#cursor);
751
732
  }
752
733
  get sparse() {
753
- return __privateGet(this, _sparse);
734
+ return this.#sparse;
754
735
  }
755
736
  };
756
- _dense = new WeakMap();
757
- _sparse = new WeakMap();
758
- _cursor = new WeakMap();
759
737
 
760
738
  // ../core/src/query/utils/create-query-hash.ts
761
739
  var sortedIDs = new Float32Array(1024);
@@ -785,22 +763,22 @@ var createQueryHash = (parameters) => {
785
763
  // ../core/src/query/query.ts
786
764
  var IsExcluded = trait();
787
765
  var Query = class {
766
+ version = 0;
767
+ world;
768
+ parameters;
769
+ hash;
770
+ traits = [];
771
+ traitData = { required: [], forbidden: [], or: [], added: [], removed: [], changed: [], all: [] };
772
+ bitmasks = [];
773
+ generations;
774
+ entities = new SparseSet();
775
+ isTracking = false;
776
+ hasChangedModifiers = false;
777
+ changedTraits = /* @__PURE__ */ new Set();
778
+ toRemove = new SparseSet();
779
+ addSubscriptions = /* @__PURE__ */ new Set();
780
+ removeSubscriptions = /* @__PURE__ */ new Set();
788
781
  constructor(world, parameters = []) {
789
- __publicField(this, "version", 0);
790
- __publicField(this, "world");
791
- __publicField(this, "parameters");
792
- __publicField(this, "hash");
793
- __publicField(this, "traits", []);
794
- __publicField(this, "traitData", { required: [], forbidden: [], or: [], added: [], removed: [], changed: [], all: [] });
795
- __publicField(this, "bitmasks", []);
796
- __publicField(this, "generations");
797
- __publicField(this, "entities", new SparseSet());
798
- __publicField(this, "isTracking", false);
799
- __publicField(this, "hasChangedModifiers", false);
800
- __publicField(this, "changedTraits", /* @__PURE__ */ new Set());
801
- __publicField(this, "toRemove", new SparseSet());
802
- __publicField(this, "addSubscriptions", /* @__PURE__ */ new Set());
803
- __publicField(this, "removeSubscriptions", /* @__PURE__ */ new Set());
804
782
  this.world = world;
805
783
  this.parameters = parameters;
806
784
  const ctx = world[$internal];
@@ -1210,6 +1188,10 @@ function createQueryResult(query, world, params) {
1210
1188
  stores.length = 0;
1211
1189
  getQueryStores(params2, traits, stores, world);
1212
1190
  return results;
1191
+ },
1192
+ sort(callback = (a, b) => getEntityId(a) - getEntityId(b)) {
1193
+ Array.prototype.sort.call(entities, callback);
1194
+ return results;
1213
1195
  }
1214
1196
  });
1215
1197
  return results;
@@ -1234,50 +1216,50 @@ function getQueryStores(params, traits, stores, world) {
1234
1216
  }
1235
1217
 
1236
1218
  // ../core/src/world/world.ts
1237
- var _a, _id, _isInitialized;
1238
- _a = $internal;
1239
1219
  var World = class {
1240
- constructor(...traits) {
1241
- __privateAdd(this, _id, allocateWorldId(universe.worldIndex));
1242
- __publicField(this, _a, {
1243
- entityIndex: createEntityIndex(__privateGet(this, _id)),
1244
- entityMasks: [[]],
1245
- entityTraits: /* @__PURE__ */ new Map(),
1246
- bitflag: 1,
1247
- traitData: /* @__PURE__ */ new Map(),
1248
- queries: /* @__PURE__ */ new Set(),
1249
- queriesHashMap: /* @__PURE__ */ new Map(),
1250
- notQueries: /* @__PURE__ */ new Set(),
1251
- dirtyQueries: /* @__PURE__ */ new Set(),
1252
- relationTargetEntities: /* @__PURE__ */ new Set(),
1253
- dirtyMasks: /* @__PURE__ */ new Map(),
1254
- trackingSnapshots: /* @__PURE__ */ new Map(),
1255
- changedMasks: /* @__PURE__ */ new Map(),
1256
- worldEntity: null,
1257
- trackedTraits: /* @__PURE__ */ new Set()
1258
- });
1259
- __privateAdd(this, _isInitialized, false);
1260
- __publicField(this, "traits", /* @__PURE__ */ new Set());
1261
- this.init(...traits);
1262
- }
1220
+ #id = allocateWorldId(universe.worldIndex);
1221
+ [$internal] = {
1222
+ entityIndex: createEntityIndex(this.#id),
1223
+ entityMasks: [[]],
1224
+ entityTraits: /* @__PURE__ */ new Map(),
1225
+ bitflag: 1,
1226
+ traitData: /* @__PURE__ */ new Map(),
1227
+ queries: /* @__PURE__ */ new Set(),
1228
+ queriesHashMap: /* @__PURE__ */ new Map(),
1229
+ notQueries: /* @__PURE__ */ new Set(),
1230
+ dirtyQueries: /* @__PURE__ */ new Set(),
1231
+ relationTargetEntities: /* @__PURE__ */ new Set(),
1232
+ dirtyMasks: /* @__PURE__ */ new Map(),
1233
+ trackingSnapshots: /* @__PURE__ */ new Map(),
1234
+ changedMasks: /* @__PURE__ */ new Map(),
1235
+ worldEntity: null,
1236
+ trackedTraits: /* @__PURE__ */ new Set(),
1237
+ resetSubscriptions: /* @__PURE__ */ new Set()
1238
+ };
1263
1239
  get id() {
1264
- return __privateGet(this, _id);
1240
+ return this.#id;
1265
1241
  }
1242
+ #isInitialized = false;
1266
1243
  get isInitialized() {
1267
- return __privateGet(this, _isInitialized);
1244
+ return this.#isInitialized;
1268
1245
  }
1269
1246
  get entities() {
1270
1247
  return getAliveEntities(this[$internal].entityIndex);
1271
1248
  }
1249
+ traits = /* @__PURE__ */ new Set();
1250
+ constructor(...traits) {
1251
+ this.init(...traits);
1252
+ }
1272
1253
  init(...traits) {
1273
1254
  const ctx = this[$internal];
1274
- if (__privateGet(this, _isInitialized)) return;
1275
- __privateSet(this, _isInitialized, true);
1276
- universe.worlds[__privateGet(this, _id)] = this;
1255
+ if (this.#isInitialized) return;
1256
+ this.#isInitialized = true;
1257
+ universe.worlds[this.#id] = new WeakRef(this);
1277
1258
  const cursor2 = getTrackingCursor();
1278
1259
  for (let i = 0; i < cursor2; i++) {
1279
1260
  setTrackingMasks(this, i);
1280
1261
  }
1262
+ if (!ctx.traitData.has(IsExcluded)) registerTrait(this, IsExcluded);
1281
1263
  for (const [hash, parameters] of universe.cachedQueries) {
1282
1264
  const query = new Query(this, parameters);
1283
1265
  ctx.queriesHashMap.set(hash, query);
@@ -1307,15 +1289,15 @@ var World = class {
1307
1289
  this[$internal].worldEntity = null;
1308
1290
  this.entities.forEach((entity) => destroyEntity(this, entity));
1309
1291
  this.reset();
1310
- __privateSet(this, _isInitialized, false);
1311
- releaseWorldId(universe.worldIndex, __privateGet(this, _id));
1312
- universe.worlds.splice(universe.worlds.indexOf(this), 1);
1292
+ this.#isInitialized = false;
1293
+ releaseWorldId(universe.worldIndex, this.#id);
1294
+ universe.worlds[this.#id] = null;
1313
1295
  }
1314
1296
  reset() {
1315
1297
  const ctx = this[$internal];
1316
- ctx.entityIndex = createEntityIndex(__privateGet(this, _id));
1298
+ this.entities.forEach((entity) => destroyEntity(this, entity));
1299
+ ctx.entityIndex = createEntityIndex(this.#id);
1317
1300
  ctx.entityTraits.clear();
1318
- ctx.notQueries.clear();
1319
1301
  ctx.entityMasks = [[]];
1320
1302
  ctx.bitflag = 1;
1321
1303
  ctx.traitData.clear();
@@ -1323,12 +1305,16 @@ var World = class {
1323
1305
  ctx.queries.clear();
1324
1306
  ctx.queriesHashMap.clear();
1325
1307
  ctx.dirtyQueries.clear();
1308
+ ctx.notQueries.clear();
1326
1309
  ctx.relationTargetEntities.clear();
1327
1310
  ctx.trackingSnapshots.clear();
1328
1311
  ctx.dirtyMasks.clear();
1329
1312
  ctx.changedMasks.clear();
1330
1313
  ctx.trackedTraits.clear();
1331
1314
  ctx.worldEntity = createEntity(this, IsExcluded);
1315
+ for (const sub of ctx.resetSubscriptions) {
1316
+ sub(this);
1317
+ }
1332
1318
  }
1333
1319
  query(...args) {
1334
1320
  const ctx = this[$internal];
@@ -1380,14 +1366,18 @@ var World = class {
1380
1366
  ctx.trackedTraits.add(trait2);
1381
1367
  return () => {
1382
1368
  data.changedSubscriptions.delete(callback);
1383
- ctx.trackedTraits.delete(trait2);
1369
+ if (data.changedSubscriptions.size === 0) ctx.trackedTraits.delete(trait2);
1384
1370
  };
1385
1371
  }
1386
1372
  };
1387
- _id = new WeakMap();
1388
- _isInitialized = new WeakMap();
1373
+ var worldFinalizer = new FinalizationRegistry((worldId) => {
1374
+ universe.worlds[worldId] = null;
1375
+ releaseWorldId(universe.worldIndex, worldId);
1376
+ });
1389
1377
  function createWorld(...traits) {
1390
- return new World(...traits);
1378
+ const world = new World(...traits);
1379
+ worldFinalizer.register(world, world.id);
1380
+ return world;
1391
1381
  }
1392
1382
 
1393
1383
  // ../core/src/query/modifiers/added.ts
@@ -1395,7 +1385,7 @@ function createAdded() {
1395
1385
  const id = createTrackingId();
1396
1386
  for (const world of universe.worlds) {
1397
1387
  if (!world) continue;
1398
- setTrackingMasks(world, id);
1388
+ setTrackingMasks(world.deref(), id);
1399
1389
  }
1400
1390
  return (...traits) => new ModifierData(`added-${id}`, id, traits);
1401
1391
  }
@@ -1405,7 +1395,7 @@ function createRemoved() {
1405
1395
  const id = createTrackingId();
1406
1396
  for (const world of universe.worlds) {
1407
1397
  if (!world) continue;
1408
- setTrackingMasks(world, id);
1398
+ setTrackingMasks(world.deref(), id);
1409
1399
  }
1410
1400
  return (...traits) => new ModifierData(`removed-${id}`, id, traits);
1411
1401
  }
@@ -1419,8 +1409,9 @@ var Or = (...traits) => new ModifierData("or", 2, traits);
1419
1409
  // ../core/src/query/utils/cache-query.ts
1420
1410
  function cacheQuery(...parameters) {
1421
1411
  const hash = createQueryHash(parameters);
1422
- for (const world of universe.worlds) {
1423
- if (!world) continue;
1412
+ for (const worldRef of universe.worlds) {
1413
+ if (!worldRef) continue;
1414
+ const world = worldRef.deref();
1424
1415
  const ctx = world[$internal];
1425
1416
  if (!ctx.queriesHashMap.has(hash)) {
1426
1417
  const query = new Query(world, parameters);
@@ -1433,21 +1424,24 @@ function cacheQuery(...parameters) {
1433
1424
 
1434
1425
  // ../core/src/actions/create-actions.ts
1435
1426
  var actionCache = /* @__PURE__ */ new WeakMap();
1436
- function createActions(actionSet) {
1427
+ function createActions(initializer) {
1437
1428
  return (world) => {
1438
1429
  let worldCache = actionCache.get(world);
1439
1430
  if (!worldCache) {
1440
1431
  worldCache = /* @__PURE__ */ new Map();
1441
1432
  actionCache.set(world, worldCache);
1442
1433
  }
1443
- let actions = worldCache.get(actionSet);
1434
+ let actions = worldCache.get(initializer);
1444
1435
  if (!actions) {
1445
- actions = actionSet(world);
1446
- worldCache.set(actionSet, actions);
1436
+ actions = initializer(world);
1437
+ worldCache.set(initializer, actions);
1447
1438
  }
1448
1439
  return actions;
1449
1440
  };
1450
1441
  }
1442
+
1443
+ // ../core/src/query/types.ts
1444
+ var $parameters = Symbol();
1451
1445
  // Annotate the CommonJS export names for ESM import in node:
1452
1446
  0 && (module.exports = {
1453
1447
  $internal,
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
- import { S as Schema, T as Trait, N as Norm, M as ModifierData, W as World, Q as QueryParameter, R as Relation, a as RelationTarget, b as WildcardRelation } from './world-CHO2npCL.cjs';
2
- export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, k as Entity, j as ExtractIsTag, E as ExtractSchema, i as ExtractStore, q as InstancesFromParameters, r as IsNotModifier, I as IsTag, l as QueryModifier, o as QueryResult, n as QueryResultOptions, m as QuerySubscriber, h as Store, p as StoresFromParameters, g as TraitInstance, f as TraitTuple, d as TraitType, e as TraitValue, c as createWorld } from './world-CHO2npCL.cjs';
1
+ import { T as Trait, S as Schema, N as Norm, M as ModifierData, W as World, Q as QueryParameter, a as QueryHash, R as Relation, b as RelationTarget, c as WildcardRelation } from './world-BYe3z9dR.cjs';
2
+ export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, l as Entity, k as ExtractIsTag, E as ExtractSchema, j as ExtractStore, r as InstancesFromParameters, s as IsNotModifier, I as IsTag, m as QueryModifier, p as QueryResult, o as QueryResultOptions, n as QuerySubscriber, i as Store, q as StoresFromParameters, h as TraitInstance, g as TraitTuple, e as TraitType, f as TraitValue, d as createWorld } from './world-BYe3z9dR.cjs';
3
3
 
4
- declare function defineTrait<S extends Schema = {}>(schema?: S): Trait<Norm<S>>;
4
+ declare function defineTrait(): Trait<{}>;
5
+ declare function defineTrait<S extends Schema>(schema: S): Trait<Norm<S>>;
5
6
  declare const trait: typeof defineTrait;
6
7
 
7
8
  declare function createAdded(): <T extends Trait[] = Trait[]>(...traits: T) => ModifierData<T, string>;
@@ -21,13 +22,13 @@ type WorldIndex = {
21
22
  };
22
23
 
23
24
  declare const universe: {
24
- worlds: World[];
25
+ worlds: (WeakRef<World> | null)[];
25
26
  cachedQueries: Map<string, QueryParameter[]>;
26
27
  worldIndex: WorldIndex;
27
28
  reset: () => void;
28
29
  };
29
30
 
30
- declare function cacheQuery(...parameters: QueryParameter[]): string;
31
+ declare function cacheQuery<T extends QueryParameter[]>(...parameters: T): QueryHash<T>;
31
32
 
32
33
  declare function defineRelation<S extends Schema = any>(definition?: {
33
34
  exclusive?: boolean;
@@ -38,6 +39,10 @@ declare const relation: typeof defineRelation;
38
39
  declare const Pair: <T extends Trait>(relation: Relation<T>, target: RelationTarget) => T;
39
40
  declare const Wildcard: WildcardRelation;
40
41
 
41
- declare function createActions<T extends Record<string, (...args: any[]) => any>>(actionSet: (world: World) => T): (world: World) => T;
42
+ type Actions = Record<string, (...args: any[]) => void>;
43
+ type ActionInitializer<T extends Actions> = (world: World) => T;
44
+ type ActionGetter<T extends Actions> = (world: World) => T;
42
45
 
43
- export { Norm, Not, Or, Pair, QueryParameter, Relation, RelationTarget, Schema, Trait, Wildcard, WildcardRelation, World, cacheQuery, createActions, createAdded, createChanged, createRemoved, relation, trait, universe };
46
+ declare function createActions<T extends Actions>(initializer: ActionInitializer<T>): ActionGetter<T>;
47
+
48
+ export { type ActionGetter, type ActionInitializer, type Actions, Norm, Not, Or, Pair, QueryHash, QueryParameter, Relation, RelationTarget, Schema, Trait, Wildcard, WildcardRelation, World, cacheQuery, createActions, createAdded, createChanged, createRemoved, relation, trait, universe };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { S as Schema, T as Trait, N as Norm, M as ModifierData, W as World, Q as QueryParameter, R as Relation, a as RelationTarget, b as WildcardRelation } from './world-CHO2npCL.js';
2
- export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, k as Entity, j as ExtractIsTag, E as ExtractSchema, i as ExtractStore, q as InstancesFromParameters, r as IsNotModifier, I as IsTag, l as QueryModifier, o as QueryResult, n as QueryResultOptions, m as QuerySubscriber, h as Store, p as StoresFromParameters, g as TraitInstance, f as TraitTuple, d as TraitType, e as TraitValue, c as createWorld } from './world-CHO2npCL.js';
1
+ import { T as Trait, S as Schema, N as Norm, M as ModifierData, W as World, Q as QueryParameter, a as QueryHash, R as Relation, b as RelationTarget, c as WildcardRelation } from './world-BYe3z9dR.js';
2
+ export { $ as $internal, A as AoSFactory, C as ConfigurableTrait, l as Entity, k as ExtractIsTag, E as ExtractSchema, j as ExtractStore, r as InstancesFromParameters, s as IsNotModifier, I as IsTag, m as QueryModifier, p as QueryResult, o as QueryResultOptions, n as QuerySubscriber, i as Store, q as StoresFromParameters, h as TraitInstance, g as TraitTuple, e as TraitType, f as TraitValue, d as createWorld } from './world-BYe3z9dR.js';
3
3
 
4
- declare function defineTrait<S extends Schema = {}>(schema?: S): Trait<Norm<S>>;
4
+ declare function defineTrait(): Trait<{}>;
5
+ declare function defineTrait<S extends Schema>(schema: S): Trait<Norm<S>>;
5
6
  declare const trait: typeof defineTrait;
6
7
 
7
8
  declare function createAdded(): <T extends Trait[] = Trait[]>(...traits: T) => ModifierData<T, string>;
@@ -21,13 +22,13 @@ type WorldIndex = {
21
22
  };
22
23
 
23
24
  declare const universe: {
24
- worlds: World[];
25
+ worlds: (WeakRef<World> | null)[];
25
26
  cachedQueries: Map<string, QueryParameter[]>;
26
27
  worldIndex: WorldIndex;
27
28
  reset: () => void;
28
29
  };
29
30
 
30
- declare function cacheQuery(...parameters: QueryParameter[]): string;
31
+ declare function cacheQuery<T extends QueryParameter[]>(...parameters: T): QueryHash<T>;
31
32
 
32
33
  declare function defineRelation<S extends Schema = any>(definition?: {
33
34
  exclusive?: boolean;
@@ -38,6 +39,10 @@ declare const relation: typeof defineRelation;
38
39
  declare const Pair: <T extends Trait>(relation: Relation<T>, target: RelationTarget) => T;
39
40
  declare const Wildcard: WildcardRelation;
40
41
 
41
- declare function createActions<T extends Record<string, (...args: any[]) => any>>(actionSet: (world: World) => T): (world: World) => T;
42
+ type Actions = Record<string, (...args: any[]) => void>;
43
+ type ActionInitializer<T extends Actions> = (world: World) => T;
44
+ type ActionGetter<T extends Actions> = (world: World) => T;
42
45
 
43
- export { Norm, Not, Or, Pair, QueryParameter, Relation, RelationTarget, Schema, Trait, Wildcard, WildcardRelation, World, cacheQuery, createActions, createAdded, createChanged, createRemoved, relation, trait, universe };
46
+ declare function createActions<T extends Actions>(initializer: ActionInitializer<T>): ActionGetter<T>;
47
+
48
+ export { type ActionGetter, type ActionInitializer, type Actions, Norm, Not, Or, Pair, QueryHash, QueryParameter, Relation, RelationTarget, Schema, Trait, Wildcard, WildcardRelation, World, cacheQuery, createActions, createAdded, createChanged, createRemoved, relation, trait, universe };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  relation,
14
14
  trait,
15
15
  universe
16
- } from "./chunk-ZHBGFPP2.js";
16
+ } from "./chunk-OAPTAVXT.js";
17
17
  export {
18
18
  $internal,
19
19
  Not,