From 535b9f24b68ce4c309b24cfdf75febf5375341ab Mon Sep 17 00:00:00 2001 From: Six <23470032+6ixfalls@users.noreply.github.com> Date: Fri, 1 Aug 2025 22:44:21 -0700 Subject: [PATCH 1/2] feat: retype archetype columns_map based on query --- jecs.d.ts | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/jecs.d.ts b/jecs.d.ts index 9bdc31f..6264ec7 100755 --- a/jecs.d.ts +++ b/jecs.d.ts @@ -43,35 +43,35 @@ type InferComponents = { [K in keyof A]: InferComponent }; type ArchetypeId = number; export type Column = T[]; -export type Archetype = { +export type Archetype = { id: number; types: number[]; type: string; entities: number[]; columns: Column[]; - columns_map: Record> + columns_map: { [K in T[number]]: Column> }; }; type Iter = IterableFunction>; -export type CachedQuery = { +export type CachedQuery = { /** * Returns an iterator that produces a tuple of [Entity, ...queriedComponents]. */ - iter(): Iter; + iter(): Iter>; /** * Returns the matched archetypes of the query * @returns An array of archetypes of the query */ archetypes(): Archetype[]; -} & Iter; +} & Iter>; -export type Query = { +export type Query = { /** * Returns an iterator that produces a tuple of [Entity, ...queriedComponents]. */ - iter(): Iter; + iter(): Iter>; /** * Creates and returns a cached version of this query for efficient reuse. @@ -99,7 +99,7 @@ export type Query = { * @returns An array of archetypes of the query */ archetypes(): Archetype[]; -} & Iter; +} & Iter>; export class World { /** @@ -246,11 +246,11 @@ export class World { * @param components The list of components to query. * @returns A Query object to iterate over results. */ - query(...components: T): Query>; + query(...components: T): Query; - added(component: Entity, listener: (e: Entity, id: Id, value: T) => void): () => void - changed(component: Entity, listener: (e: Entity, id: Id, value: T) => void): () => void - removed(component: Entity, listener: (e: Entity, id: Id) => void): () => void + added(component: Entity, listener: (e: Entity, id: Id, value: T) => void): () => void; + changed(component: Entity, listener: (e: Entity, id: Id, value: T) => void): () => void; + removed(component: Entity, listener: (e: Entity, id: Id) => void): () => void; } export function world(): World; @@ -297,11 +297,11 @@ export function ECS_PAIR_FIRST(pair: Pair): number; export function ECS_PAIR_SECOND(pair: Pair): number; type StatefulHook = Entity<(e: Entity, id: Id, data: T) => void> & { - readonly __nominal_StatefulHook: unique symbol, -} + readonly __nominal_StatefulHook: unique symbol; +}; type StatelessHook = Entity<(e: Entity, id: Id) => void> & { - readonly __nominal_StatelessHook: unique symbol, -} + readonly __nominal_StatelessHook: unique symbol; +}; export declare const OnAdd: StatefulHook; export declare const OnRemove: StatelessHook; @@ -319,12 +319,17 @@ export declare const Exclusive: Tag; export declare const Rest: Entity; export type ComponentRecord = { - records: Map, - counts: Map, - size: number, -} + records: Map; + counts: Map; + size: number; +}; -export function component_record(world: World, id: Id): ComponentRecord +export function component_record(world: World, id: Id): ComponentRecord; -export function bulk_insert(world: World, entity: Entity, ids: C, values: InferComponents): void -export function bulk_remove(world: World, entity: Entity, ids: Id[]): void +export function bulk_insert( + world: World, + entity: Entity, + ids: C, + values: InferComponents, +): void; +export function bulk_remove(world: World, entity: Entity, ids: Id[]): void; From 2b9c04c90a84d06c03a1d613e8da1e9e2fa5b94a Mon Sep 17 00:00:00 2001 From: Six <23470032+6ixfalls@users.noreply.github.com> Date: Fri, 1 Aug 2025 22:46:19 -0700 Subject: [PATCH 2/2] feat: move InferComponents into Iter --- jecs.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jecs.d.ts b/jecs.d.ts index 6264ec7..6972f36 100755 --- a/jecs.d.ts +++ b/jecs.d.ts @@ -52,26 +52,26 @@ export type Archetype = { columns_map: { [K in T[number]]: Column> }; }; -type Iter = IterableFunction>; +type Iter = IterableFunction]>>; export type CachedQuery = { /** * Returns an iterator that produces a tuple of [Entity, ...queriedComponents]. */ - iter(): Iter>; + iter(): Iter; /** * Returns the matched archetypes of the query * @returns An array of archetypes of the query */ archetypes(): Archetype[]; -} & Iter>; +} & Iter; export type Query = { /** * Returns an iterator that produces a tuple of [Entity, ...queriedComponents]. */ - iter(): Iter>; + iter(): Iter; /** * Creates and returns a cached version of this query for efficient reuse. @@ -99,7 +99,7 @@ export type Query = { * @returns An array of archetypes of the query */ archetypes(): Archetype[]; -} & Iter>; +} & Iter; export class World { /**