Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arancini/core

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arancini/core - npm Package Compare versions

Comparing version 6.3.2 to 6.4.0

dist/entity-collection.d.ts

4

dist/index.d.ts

@@ -1,3 +0,3 @@

export { EntityContainer } from './entity-container';
export { Query, QueryBuilder, type QueryConditions, type QueryDescription, type With, type Without, } from './query';
export { EntityCollection as EntityContainer } from './entity-collection';
export { Query, QueryBuilder, type QueryConditions, type QueryFn, type With, type Without, } from './query';
export { World, type AnyEntity } from './world';

@@ -1,2 +0,2 @@

class t{listeners=new Set;add(t){return this.listeners.add(t),()=>this.remove(t)}remove(t){this.listeners.delete(t)}emit(...t){for(const e of this.listeners)e(...t)}clear(){this.listeners.clear()}}class e{entities=[];version=0;onEntityAdded=new t;onEntityRemoved=new t;_entityPositions=new Map;_entitySet=new Set;get first(){return this.entities[0]||void 0}[Symbol.iterator](){let t=this.entities.length;const e={value:void 0,done:!1};return{next:()=>(e.value=this.entities[--t],e.done=t<0,e)}}has(t){return this._entitySet.has(t)}}const s=(t,e)=>{e&&!t.has(e)&&(t.entities.push(e),t._entityPositions.set(e,t.entities.length-1),t._entitySet.add(e),t.version++,t.onEntityAdded.emit(e))},i=(t,e)=>{if(!t.has(e))return;const s=t._entityPositions.get(e);t._entityPositions.delete(e),t._entitySet.delete(e);const i=t.entities[t.entities.length-1];i!==e&&(t.entities[s]=i,t._entityPositions.set(i,s)),t.entities.pop(),t.version++,t.onEntityRemoved.emit(e)};class n extends e{world;key;conditions;constructor(t,e,s){super(),this.world=t,this.key=e,this.conditions=s}destroy(){this.world.destroyQuery(this)}}const o=(t,e)=>{const s=[];for(const i of e)r(t,i)&&s.push(i);return s},r=(t,e)=>{for(const s of t){if("all"===s.type&&!s.components.every((t=>void 0!==e[t])))return!1;if("any"===s.type&&!s.components.some((t=>void 0!==e[t])))return!1;if("not"===s.type&&s.components.some((t=>void 0!==e[t])))return!1}return!0},h=t=>{const e=new a;t(e);const s=e.conditions;if(s.length<=0)throw new Error("Query must have at least one condition");if(s.some((t=>t.components.length<=0)))throw new Error("Query conditions must have at least one component");const i={type:"all",components:[]},n=[];for(const t of s)"all"===t.type?i.components.push(...t.components):n.push(t);return[i,...n]},d=t=>t.map((({type:t,components:e})=>"all"===t?e.sort().join(","):[`${t}:${e.sort().join(",")}`])).sort().join("&");class a{T;conditions=[];all=(...t)=>(this.conditions.push({type:"all",components:t}),this);any=(...t)=>(this.conditions.push({type:"any",components:t}),this);not=(...t)=>(this.conditions.push({type:"not",components:t}),this);with=this.all;have=this.all;has=this.all;every=this.all;is=this.all;some=this.any;one=this.any;none=this.not;without=this.not;get and(){return this}get but(){return this}get where(){return this}get are(){return this}}const l=Symbol("standalone");class c extends e{queries=new Map;queryUsages=new Map;idToEntity=new Map;entityToId=new WeakMap;entityIdCounter=0;reset(){this.entities.forEach((t=>this.destroy(t))),this.entityIdCounter=0,this.idToEntity.clear(),this._entityPositions.clear()}id(t){if(!this.has(t))return;let e=this.entityToId.get(t);return void 0===e&&(e=this.entityIdCounter++,this.entityToId.set(t,e),this.idToEntity.set(e,t)),e}entity(t){return this.idToEntity.get(t)}create(t){return this.has(t)||(s(this,t),this.index(t)),t}destroy(t){i(this,t),this.queries.forEach((e=>i(e,t)))}add(t,e,s){return void 0!==t[e]||(t[e]=s,this.index(t)),this}remove(t,e){if(void 0!==t[e]){if(this.has(t)){const s={...t};delete s[e],this.index(t,s)}delete t[e]}}update(t,e){const s={...t};if("function"==typeof e){e(s)}else Object.assign(s,e);const i=Object.keys(s).filter((e=>void 0===t[e])),n=Object.keys(t).filter((t=>void 0===s[t]));for(const e of i)t[e]=s[e];this.index(t,s);for(const e of n)delete t[e];Object.assign(t,s)}query(t,e){const i=h(t),r=d(i),a=e?.handle??l,c=this.queryUsages.get(r);c?c.push(a):this.queryUsages.set(r,[a]);let y=this.queries.get(r);if(y)return y;y=new n(this,r,i);const u=o(y.conditions,this.entities.values());for(const t of u)s(y,t);return this.queries.set(r,y),y}destroyQuery(t,e){if(!this.queries.has(t.key))return;const s=e?.handle??l;let i=this.queryUsages.get(t.key)??[];i=i.filter((t=>t!==s)),i.length>0?this.queryUsages.set(t.key,i):(this.queries.delete(t.key),this.queryUsages.delete(t.key),t.onEntityAdded.clear(),t.onEntityRemoved.clear())}filter(t){const e=h(t),s=d(e),i=this.queries.get(s);return i?i.entities:o(e,this.entities)}find(t){const e=h(t),s=d(e),i=this.queries.get(s);return i?i.first:((t,e)=>{for(const s of e)if(r(t,s))return s})(e,this.entities)}index(t,e=t){if(this.has(t))for(const n of this.queries.values()){const o=r(n.conditions,e),h=n.has(t);o&&!h?s(n,t):!o&&h&&i(n,t)}}}export{e as EntityContainer,n as Query,a as QueryBuilder,c as World};
class t{listeners=new Set;add(t){return this.listeners.add(t),()=>this.remove(t)}remove(t){this.listeners.delete(t)}emit(...t){for(const e of this.listeners)e(...t)}clear(){this.listeners.clear()}}class e{entities=[];version=0;onEntityAdded=new t;onEntityRemoved=new t;_entityPositions=new Map;get first(){return this.entities[0]||void 0}[Symbol.iterator](){let t=this.entities.length;const e={value:void 0,done:!1};return{next:()=>(e.value=this.entities[--t],e.done=t<0,e)}}has(t){return this._entityPositions.has(t)}}const s=(t,e)=>{t.entities.push(e),t._entityPositions.set(e,t.entities.length-1),t.version++,t.onEntityAdded.emit(e)},i=(t,e)=>{const s=t._entityPositions.get(e);t._entityPositions.delete(e);const i=t.entities[t.entities.length-1];i!==e&&(t.entities[s]=i,t._entityPositions.set(i,s)),t.entities.pop(),t.version++,t.onEntityRemoved.emit(e)};class n extends e{world;key;conditions;constructor(t,e,s){super(),this.world=t,this.key=e,this.conditions=s}destroy(){this.world.destroyQuery(this)}}const o=(t,e)=>{const s=[];for(const i of e)r(t,i)&&s.push(i);return s},r=(t,e)=>{for(let s=0;s<t.length;s++){const i=t[s];if("all"===i.type&&!i.components.every((t=>void 0!==e[t]))||"any"===i.type&&!i.components.some((t=>void 0!==e[t]))||"not"===i.type&&i.components.some((t=>void 0!==e[t])))return!1}return!0},h=t=>{const e=new d;t(e);const s=e.conditions;if(s.length<=0)throw new Error("Query must have at least one condition");if(s.some((t=>t.components.length<=0)))throw new Error("Query conditions must have at least one component");const i={type:"all",components:[]},n=[];for(const t of s)"all"===t.type?i.components.push(...t.components):n.push(t);return[i,...n]},c=t=>t.map((({type:t,components:e})=>"all"===t?e.sort().join(","):[`${t}:${e.sort().join(",")}`])).sort().join("&");class d{T;conditions=[];all=(...t)=>(this.conditions.push({type:"all",components:t}),this);any=(...t)=>(this.conditions.push({type:"any",components:t}),this);not=(...t)=>(this.conditions.push({type:"not",components:t}),this);with=this.all;have=this.all;has=this.all;every=this.all;is=this.all;some=this.any;one=this.any;none=this.not;without=this.not;get and(){return this}get but(){return this}get where(){return this}get are(){return this}}const l=Symbol("standalone");class a extends e{queries=new Map;queryReferences=new Map;idToEntity=new Map;entityToId=new Map;entityIdCounter=0;clear(){const t=[...this.entities];for(const e of t)this.destroy(e);this.idToEntity.clear(),this._entityPositions.clear()}id(t){if(!this.has(t))return;let e=this.entityToId.get(t);return void 0===e&&(e=this.entityIdCounter++,this.entityToId.set(t,e),this.idToEntity.set(e,t)),e}entity(t){return this.idToEntity.get(t)}create(t){return this.has(t)||(s(this,t),this.index(t)),t}destroy(t){this.has(t)&&(i(this,t),this.queries.forEach((e=>{e.has(t)&&i(e,t)})))}add(t,e,s){void 0===t[e]&&(t[e]=s,this.index(t))}remove(t,e){if(void 0!==t[e]){if(this.has(t)){const s={...t};delete s[e],this.index(t,s)}delete t[e]}}update(t,e){const s={...t};"function"==typeof e?e(s):Object.assign(s,e);const i=Object.keys(s).filter((e=>void 0===t[e])),n=Object.keys(t).filter((t=>void 0===s[t]));for(const e of i)t[e]=s[e];this.index(t,s);for(const e of n)delete t[e];Object.assign(t,s)}query(t,e){const i=h(t),r=c(i),d=e?.handle??l,a=this.queryReferences.get(r);a?a.push(d):this.queryReferences.set(r,[d]);let y=this.queries.get(r);if(y)return y;y=new n(this,r,i);const u=o(y.conditions,this.entities.values());for(const t of u)s(y,t);return this.queries.set(r,y),y}destroyQuery(t,e){if(!this.queries.has(t.key))return;const s=e?.handle??l;let i=this.queryReferences.get(t.key)??[];i=i.filter((t=>t!==s)),i.length>0?this.queryReferences.set(t.key,i):(this.queries.delete(t.key),this.queryReferences.delete(t.key),t.onEntityAdded.clear(),t.onEntityRemoved.clear())}filter(t){const e=h(t),s=c(e),i=this.queries.get(s);return i?[...i.entities]:o(e,this.entities)}find(t){const e=h(t),s=c(e),i=this.queries.get(s);if(i)return i.first;for(const t of this.entities)if(r(e,t))return t}index(t,e=t){if(this.has(t))for(const n of this.queries.values()){const o=r(n.conditions,e),h=n.has(t);o&&!h?s(n,t):!o&&h&&i(n,t)}}}export{e as EntityContainer,n as Query,d as QueryBuilder,a as World};
//# sourceMappingURL=index.es.js.map

@@ -1,6 +0,6 @@

import { EntityContainer } from './entity-container';
import { EntityCollection } from './entity-collection';
import type { World } from './world';
export type With<E, P extends keyof E> = E & Required<Pick<E, P>>;
export type Without<E, P extends keyof E> = Pick<E, Exclude<keyof E, P>> & Partial<Pick<E, P>>;
export type Strict<E> = WithoutOptionalProperties<E>;
export type With<T, P extends keyof T> = T & Required<Pick<T, P>>;
export type Without<T, P extends keyof T> = Pick<T, Exclude<keyof T, P>> & Partial<Pick<T, P>>;
export type Strict<T> = WithoutOptionalProperties<T>;
type OptionalProperties<T> = {

@@ -11,35 +11,34 @@ [P in keyof T]-?: undefined extends T[P] ? P : never;

export type QueryConditionType = 'all' | 'any' | 'not';
export type QueryCondition<E> = {
export type QueryCondition<Entity> = {
type: QueryConditionType;
components: (keyof E)[];
components: (keyof Entity)[];
};
export type QueryConditions<E> = QueryCondition<E>[];
export type QueryDescription<E, R> = (q: QueryBuilder<E>) => QueryBuilder<R>;
export declare class Query<E> extends EntityContainer<E> {
export type QueryConditions<Entity> = QueryCondition<Entity>[];
export type QueryFn<Entity, ResultEntity> = (q: QueryBuilder<Entity>) => QueryBuilder<ResultEntity>;
export declare class Query<Entity> extends EntityCollection<Entity> {
world: World;
key: string;
conditions: QueryConditions<E>;
constructor(world: World, key: string, conditions: QueryConditions<E>);
conditions: QueryConditions<Entity>;
constructor(world: World, key: string, conditions: QueryConditions<Entity>);
destroy(): void;
}
export declare const getQueryResults: <E>(queryConditions: QueryConditions<E>, entities: Iterable<E>) => E[];
export declare const getFirstQueryResult: <E>(queryConditions: QueryConditions<E>, entities: Iterable<E>) => E | undefined;
export declare const evaluateQueryConditions: <E>(conditions: QueryConditions<E>, entity: E) => boolean;
export declare const getQueryConditions: (queryDescription: QueryDescription<any, any>) => QueryConditions<any>;
export declare const getQueryResults: <Entity>(queryConditions: QueryConditions<Entity>, entities: Iterable<Entity>) => Entity[];
export declare const evaluateQueryConditions: <Entity>(conditions: QueryConditions<Entity>, entity: Entity) => boolean;
export declare const getQueryConditions: (queryFn: QueryFn<any, any>) => QueryConditions<any>;
export declare const getQueryDedupeString: (queryConditions: QueryConditions<unknown>) => string;
export declare class QueryBuilder<E> {
T: E;
conditions: QueryConditions<E>;
all: <C extends keyof E>(...components: C[]) => QueryBuilder<With<E, C>>;
any: <C extends keyof E>(...components: C[]) => QueryBuilder<E>;
not: <C extends keyof E>(...components: C[]) => QueryBuilder<Without<E, C>>;
with: <C extends keyof E>(...components: C[]) => QueryBuilder<With<E, C>>;
have: <C extends keyof E>(...components: C[]) => QueryBuilder<With<E, C>>;
has: <C extends keyof E>(...components: C[]) => QueryBuilder<With<E, C>>;
every: <C extends keyof E>(...components: C[]) => QueryBuilder<With<E, C>>;
is: <C extends keyof E>(...components: C[]) => QueryBuilder<With<E, C>>;
some: <C extends keyof E>(...components: C[]) => QueryBuilder<E>;
one: <C extends keyof E>(...components: C[]) => QueryBuilder<E>;
none: <C extends keyof E>(...components: C[]) => QueryBuilder<Without<E, C>>;
without: <C extends keyof E>(...components: C[]) => QueryBuilder<Without<E, C>>;
export declare class QueryBuilder<Entity> {
T: Entity;
conditions: QueryConditions<Entity>;
all: <C extends keyof Entity>(...components: C[]) => QueryBuilder<With<Entity, C>>;
any: <C extends keyof Entity>(...components: C[]) => QueryBuilder<Entity>;
not: <C extends keyof Entity>(...components: C[]) => QueryBuilder<Without<Entity, C>>;
with: <C extends keyof Entity>(...components: C[]) => QueryBuilder<With<Entity, C>>;
have: <C extends keyof Entity>(...components: C[]) => QueryBuilder<With<Entity, C>>;
has: <C extends keyof Entity>(...components: C[]) => QueryBuilder<With<Entity, C>>;
every: <C extends keyof Entity>(...components: C[]) => QueryBuilder<With<Entity, C>>;
is: <C extends keyof Entity>(...components: C[]) => QueryBuilder<With<Entity, C>>;
some: <C extends keyof Entity>(...components: C[]) => QueryBuilder<Entity>;
one: <C extends keyof Entity>(...components: C[]) => QueryBuilder<Entity>;
none: <C extends keyof Entity>(...components: C[]) => QueryBuilder<Without<Entity, C>>;
without: <C extends keyof Entity>(...components: C[]) => QueryBuilder<Without<Entity, C>>;
get and(): this;

@@ -46,0 +45,0 @@ get but(): this;

@@ -1,10 +0,7 @@

import { EntityContainer } from './entity-container';
import { Query, QueryDescription } from './query';
export type ComponentRegistry = {
[name: string]: number;
};
import { EntityCollection } from './entity-collection';
import { Query, QueryFn } from './query';
export type AnyEntity = Record<string, any>;
export declare class World<E extends AnyEntity = any> extends EntityContainer<E> {
export declare class World<E extends AnyEntity = any> extends EntityCollection<E> {
queries: Map<string, Query<any>>;
private queryUsages;
private queryReferences;
private idToEntity;

@@ -14,5 +11,5 @@ private entityToId;

/**
* Removes all entities from the world. Components remain registered, and queries are not destroyed.
* Removes all entities from the world.
*/
reset(): void;
clear(): void;
/**

@@ -51,3 +48,3 @@ * Creates and returns an id for an entity

*/
create(entity: E): E;
create<Entity extends E>(entity: Entity): Entity;
/**

@@ -78,3 +75,3 @@ * Destroys an entity

*/
add<C extends keyof E>(entity: E, component: C, value: E[C]): this;
add<C extends keyof E>(entity: E, component: C, value: E[C]): void;
/**

@@ -118,4 +115,4 @@ * Removes a component from an entity

* Creates a query that updates with entity composition changes.
* @param queryDescription the query description
* @returns the query
* @param queryFn the query function
* @returns the query instance
*

@@ -137,3 +134,3 @@ * @example

*/
query<ResultEntity extends E>(queryDescription: QueryDescription<E, ResultEntity>, options?: {
query<ResultEntity extends E>(queryFn: QueryFn<E, ResultEntity>, options?: {
handle: unknown;

@@ -150,14 +147,14 @@ }): Query<ResultEntity>;

/**
* Filters entities that match a given query description.
* @param queryDescription the query conditions to match
* @returns entities matching the query description
* Filters entities that match a given query.
* @param queryFn the query to match
* @returns entities matching the query
*/
filter<ResultEntity>(queryDescription: QueryDescription<E, ResultEntity>): ResultEntity[];
filter<ResultEntity>(queryFn: QueryFn<E, ResultEntity>): ResultEntity[];
/**
* Finds an entity that matches a given query description.
* @param queryDescription the query conditions to match
* @returns the first entity matching the query description
* Finds an entity that matches a given query
* @param queryFn the query to match
* @returns the first entity matching the query
*/
find<ResultEntity>(queryDescription: QueryDescription<E, ResultEntity>): ResultEntity | undefined;
find<ResultEntity>(queryFn: QueryFn<E, ResultEntity>): ResultEntity | undefined;
private index;
}

@@ -12,3 +12,3 @@ {

"license": "MIT",
"version": "6.3.2",
"version": "6.4.0",
"homepage": "https://github.com/isaac-mason/arancini",

@@ -26,3 +26,3 @@ "bugs": {

"dependencies": {
"@arancini/events": "6.3.2"
"@arancini/events": "6.4.0"
},

@@ -29,0 +29,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc