New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@arancini/core

Package Overview
Dependencies
Maintainers
1
Versions
46
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.4.0 to 6.5.0

1

dist/entity-collection.d.ts

@@ -11,2 +11,3 @@ import { Topic } from '@arancini/events';

get first(): Entity | undefined;
get size(): number;
[Symbol.iterator](): {

@@ -13,0 +14,0 @@ next: () => {

2

dist/index.es.js

@@ -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;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};
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]}get size(){return this.entities.length}[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 n=(t,e)=>{t.entities.push(e),t._entityPositions.set(e,t.entities.length-1),t.version++,t.onEntityAdded.emit(e)},s=(t,e)=>{const n=t._entityPositions.get(e);t._entityPositions.delete(e);const s=t.entities[t.entities.length-1];s!==e&&(t.entities[n]=s,t._entityPositions.set(s,n)),t.entities.pop(),t.version++,t.onEntityRemoved.emit(e)};class i extends e{dedupe;conditions;references=new Set;constructor(t,e){super(),this.dedupe=t,this.conditions=e}}const o=t=>{const e=new h;t(e);const n=e.conditions;if(n.length<=0)throw new Error("Query must have at least one condition");if(n.some((t=>t.components.length<=0)))throw new Error("Query conditions must have at least one component");const s=[],i={type:"all",components:[]},o={type:"not",components:[]};for(const t of n)"all"===t.type?i.components.push(...t.components):"not"===t.type?o.components.push(...t.components):s.push(t);i.components.length>0&&s.push(i),o.components.length>0&&s.push(o);const r=s.map((({type:t,components:e})=>`${t}(${e.sort().join(", ")})`)).sort().join(" && ");return{conditions:s,dedupe:r}},r=(t,e)=>{for(let n=0;n<t.length;n++){const s=t[n];if("all"===s.type&&!s.components.every((t=>void 0!==e[t]))||"any"===s.type&&!s.components.some((t=>void 0!==e[t]))||"not"===s.type&&s.components.some((t=>void 0!==e[t])))return!1}return!0};class h{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 d=Symbol("standalone");class c extends e{queries=[];create(t){return this.has(t)||(n(this,t),this.index(t)),t}destroy(t){this.has(t)&&(s(this,t),this.queries.forEach((e=>{e.has(t)&&s(e,t)})))}add(t,e,n){void 0===t[e]&&(t[e]=n,this.index(t))}remove(t,e){if(void 0===t[e])return;const n={...t};delete n[e],this.index(t,n),delete t[e]}update(t,e){const n={...t};"function"==typeof e?e(n):Object.assign(n,e);const s=Object.keys(n).filter((e=>void 0===t[e])),i=Object.keys(t).filter((t=>void 0===n[t]));for(const e of s)t[e]=n[e];this.index(t,n);for(const e of i)delete t[e];Object.assign(t,n)}query(t,e){const{conditions:s,dedupe:h}=o(t),c=e?.handle??d;let l=this.queries.find((t=>t.dedupe===h));if(l)return l.references.add(c),l;l=new i(h,s),l.references.add(c),this.queries.push(l);const u=[];for(let t=0;t<this.entities.length;t++){const e=this.entities[t];r(l.conditions,e)&&u.push(e)}for(let t=0;t<u.length;t++)n(l,u[t]);return l}destroyQuery(t,e){if(!this.queries.includes(t))return;const n=e?.handle??d;if(t.references.delete(n),t.references.size>0)return;const s=this.queries.indexOf(t);this.queries.splice(s,1),t.onEntityAdded.clear(),t.onEntityRemoved.clear()}filter(t){const{conditions:e,dedupe:n}=o(t),s=this.queries.find((t=>t.dedupe===n));if(s)return[...s.entities];const i=[];for(let t=0;t<this.entities.length;t++){const n=this.entities[t];r(e,n)&&i.push(n)}return i}find(t){const{conditions:e,dedupe:n}=o(t),s=this.queries.find((t=>t.dedupe===n));if(s)return s.first;for(const t of this.entities)if(r(e,t))return t}clear(){const t=[...this.entities];for(let e=0;e<t.length;e++)this.destroy(t[e]);this._entityPositions.clear()}index(t,e=t){if(this.has(t))for(let i=0;i<this.queries.length;i++){const o=this.queries[i],h=r(o.conditions,e),d=o.has(t);h&&!d?n(o,t):!h&&d&&s(o,t)}}}export{e as EntityContainer,i as Query,h as QueryBuilder,c as World};
//# sourceMappingURL=index.es.js.map
import { EntityCollection } from './entity-collection';
import type { World } from './world';
export type With<T, P extends keyof T> = T & Required<Pick<T, P>>;

@@ -18,12 +17,12 @@ export type Without<T, P extends keyof T> = Pick<T, Exclude<keyof T, P>> & Partial<Pick<T, P>>;

export declare class Query<Entity> extends EntityCollection<Entity> {
world: World;
key: string;
dedupe: string;
conditions: QueryConditions<Entity>;
constructor(world: World, key: string, conditions: QueryConditions<Entity>);
destroy(): void;
references: Set<unknown>;
constructor(dedupe: string, conditions: QueryConditions<Entity>);
}
export declare const getQueryResults: <Entity>(queryConditions: QueryConditions<Entity>, entities: Iterable<Entity>) => Entity[];
export declare const prepareQuery: (queryFn: QueryFn<any, any>) => {
conditions: QueryConditions<any>;
dedupe: string;
};
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<Entity> {

@@ -30,0 +29,0 @@ T: Entity;

@@ -5,22 +5,4 @@ import { EntityCollection } from './entity-collection';

export declare class World<E extends AnyEntity = any> extends EntityCollection<E> {
queries: Map<string, Query<any>>;
private queryReferences;
private idToEntity;
private entityToId;
private entityIdCounter;
queries: Query<any>[];
/**
* Removes all entities from the world.
*/
clear(): void;
/**
* Creates and returns an id for an entity
*/
id(entity: E): number | undefined;
/**
* Returns an entity for an id
* @param id
* @returns
*/
entity(id: number): E | undefined;
/**
* Creates a new entity

@@ -48,3 +30,3 @@ * @param entity

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

@@ -155,3 +137,21 @@ * Destroys an entity

find<ResultEntity>(queryFn: QueryFn<E, ResultEntity>): ResultEntity | undefined;
private index;
/**
* Removes all entities from the world.
*/
clear(): void;
/**
* Indexes an entity.
*
* Avoid calling this method directly unless you know what you're doing.
*
* This is called automatically when:
* - an entity is created
* - a component is added or removed from an entity
* - an entity is destroyed
*
* @param entity the entity to index
* @param draft the draft entity that queries are evaluated against, defaults to entity
* @returns
*/
index(entity: E, draft?: E): void;
}

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

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

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

"dependencies": {
"@arancini/events": "6.4.0"
"@arancini/events": "6.5.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