@hf-chimera/store 0.0.10 → 0.0.12

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +121 -150
  3. package/dist/adapters/react.cjs +4 -3
  4. package/dist/adapters/react.cjs.map +1 -0
  5. package/dist/adapters/react.d.cts +2 -2
  6. package/dist/adapters/react.d.cts.map +1 -1
  7. package/dist/adapters/react.d.ts +2 -2
  8. package/dist/adapters/react.d.ts.map +1 -1
  9. package/dist/adapters/react.js +2 -2
  10. package/dist/defaults-Bg1kIemd.cjs +2 -1
  11. package/dist/defaults-Bg1kIemd.cjs.map +1 -0
  12. package/dist/defaults.cjs +2 -1
  13. package/dist/defaults.cjs.map +1 -0
  14. package/dist/defaults.d.cts +1 -1
  15. package/dist/defaults.d.cts.map +1 -1
  16. package/dist/defaults.d.ts +1 -1
  17. package/dist/defaults.d.ts.map +1 -1
  18. package/dist/{index-aFqSzWq5.d.ts → index-B6sY7hiW.d.ts} +2 -2
  19. package/dist/index-B6sY7hiW.d.ts.map +1 -0
  20. package/dist/{index-BcCVbW9M.d.cts → index-CTTQ1Hr3.d.ts} +35 -31
  21. package/dist/index-CTTQ1Hr3.d.ts.map +1 -0
  22. package/dist/{index-sjIP2TCu.d.cts → index-CiER0sxG.d.cts} +2 -2
  23. package/dist/index-CiER0sxG.d.cts.map +1 -0
  24. package/dist/{index-O42il7qa.d.ts → index-CkaYmEhA.d.cts} +35 -31
  25. package/dist/index-CkaYmEhA.d.cts.map +1 -0
  26. package/dist/index.cjs +3 -2
  27. package/dist/index.d.cts +2 -2
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.js +2 -2
  30. package/dist/{qb-pl8eUjYV.cjs → qb-PXzZgo2H.cjs} +3 -2
  31. package/dist/qb-PXzZgo2H.cjs.map +1 -0
  32. package/dist/{qb-DNcihcMP.js → qb-pchs-vdM.js} +2 -2
  33. package/dist/qb-pchs-vdM.js.map +1 -0
  34. package/dist/qb.cjs +2 -2
  35. package/dist/qb.d.cts +2 -2
  36. package/dist/qb.d.ts +2 -2
  37. package/dist/qb.js +2 -2
  38. package/dist/{src-BTo-wGWx.js → src-C74sq0jQ.js} +8 -2
  39. package/dist/src-C74sq0jQ.js.map +1 -0
  40. package/dist/{src-FCZZKq4W.cjs → src-TJG6k3Nr.cjs} +16 -3
  41. package/dist/src-TJG6k3Nr.cjs.map +1 -0
  42. package/package.json +11 -12
  43. package/dist/index-BcCVbW9M.d.cts.map +0 -1
  44. package/dist/index-O42il7qa.d.ts.map +0 -1
  45. package/dist/index-aFqSzWq5.d.ts.map +0 -1
  46. package/dist/index-sjIP2TCu.d.cts.map +0 -1
  47. package/dist/qb-DNcihcMP.js.map +0 -1
  48. package/dist/src-BTo-wGWx.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"qb-DNcihcMP.js","names":[],"sources":["../packages/qb/index.ts"],"sourcesContent":["import type {\n\tAnyChimeraStore,\n\tChimeraConjunctionDescriptor,\n\tChimeraConjunctionOperation,\n\tChimeraConjunctionType,\n\tChimeraFilterDescriptor,\n\tChimeraOrderDescriptor,\n\tChimeraPropertyGetter,\n\tChimeraStoreEntities,\n\tChimeraStoreOperatorMap,\n} from \"../../src\";\nimport {\n\tChimeraOrderNulls,\n\tchimeraCreateConjunction,\n\tchimeraCreateNot,\n\tchimeraCreateOperator,\n\tchimeraCreateOrderBy,\n} from \"../../src\";\nimport type { KeysOfType } from \"../../src/shared/types\";\n\nexport type QueryBuilderCreator<\n\tStore extends AnyChimeraStore,\n\tEntity extends ChimeraStoreEntities<Store>,\n\tOperatorsMap extends ChimeraStoreOperatorMap<Store> = ChimeraStoreOperatorMap<Store>,\n> = (q: ChimeraQueryBuilder<Store, Entity, OperatorsMap>) => any;\n\nexport class ChimeraQueryBuilder<\n\tStore extends AnyChimeraStore,\n\tEntity extends ChimeraStoreEntities<Store>,\n\tOperatorsMap extends ChimeraStoreOperatorMap<Store> = ChimeraStoreOperatorMap<Store>,\n> {\n\tprivate orderRules: ChimeraOrderDescriptor<Entity>[] = [];\n\n\torderBy(\n\t\tkey: ChimeraPropertyGetter<Entity> | (keyof Entity & string),\n\t\tdesc = false,\n\t\tnulls: ChimeraOrderNulls = ChimeraOrderNulls.Last,\n\t): this {\n\t\tthis.orderRules.push(chimeraCreateOrderBy<Entity>(key, desc, nulls));\n\t\treturn this;\n\t}\n\n\tprivate filters: ChimeraConjunctionOperation<OperatorsMap, Entity>[] = [];\n\tprivate rootConjunction: Exclude<ChimeraConjunctionType, \"not\"> = \"and\";\n\n\tprivate conjunction(type: Exclude<ChimeraConjunctionType, \"not\">) {\n\t\tthis.rootConjunction = type;\n\t}\n\n\tprivate buildFilter(): ChimeraConjunctionDescriptor<OperatorsMap, Entity> | null {\n\t\treturn this.filters.length\n\t\t\t? chimeraCreateConjunction<Entity, OperatorsMap>(this.rootConjunction, this.filters)\n\t\t\t: null;\n\t}\n\n\twhere<Op extends keyof OperatorsMap & string>(\n\t\tvalue:\n\t\t\t| ChimeraPropertyGetter<Entity, Parameters<OperatorsMap[Op]>[0]>\n\t\t\t| (KeysOfType<Entity, Parameters<OperatorsMap[Op]>[0]> & string),\n\t\top: Op,\n\t\ttest: Parameters<OperatorsMap[Op]>[1],\n\t): this {\n\t\tthis.filters.push(chimeraCreateOperator<Entity, OperatorsMap, Op>(op, value, test));\n\t\treturn this;\n\t}\n\n\tgroup(conjunction: ChimeraConjunctionType, builder: QueryBuilderCreator<Store, Entity, OperatorsMap>): this {\n\t\tconst isNot = conjunction === \"not\";\n\t\tconst nestedBuilder = new ChimeraQueryBuilder<Store, Entity, OperatorsMap>();\n\n\t\t!isNot && nestedBuilder.conjunction(conjunction);\n\n\t\tbuilder(nestedBuilder);\n\n\t\tconst nestedQuery = nestedBuilder.buildFilter();\n\t\tnestedQuery && this.filters.push(isNot ? chimeraCreateNot<Entity, OperatorsMap>(nestedQuery) : nestedQuery);\n\n\t\treturn this;\n\t}\n\n\twhereNot<Op extends keyof OperatorsMap & string>(\n\t\tvalue:\n\t\t\t| ChimeraPropertyGetter<Entity, Parameters<OperatorsMap[Op]>[0]>\n\t\t\t| (KeysOfType<Entity, Parameters<OperatorsMap[Op]>[0]> & string),\n\t\top: Op,\n\t\ttest: Parameters<OperatorsMap[Op]>[1],\n\t): this {\n\t\tthis.filters.push(\n\t\t\tchimeraCreateNot<Entity, OperatorsMap>(chimeraCreateOperator<Entity, OperatorsMap, Op>(op, value, test)),\n\t\t);\n\t\treturn this;\n\t}\n\n\tbuild(): {\n\t\tfilter: ChimeraFilterDescriptor<OperatorsMap, Entity> | null;\n\t\torder: ChimeraOrderDescriptor<Entity>[] | null;\n\t} {\n\t\treturn {\n\t\t\tfilter: this.buildFilter(),\n\t\t\torder: this.orderRules.length ? this.orderRules : null,\n\t\t};\n\t}\n}\n"],"mappings":";;;AA0BA,IAAa,sBAAb,MAAa,oBAIX;CACD,AAAQ,aAA+C,EAAE;CAEzD,QACC,KACA,OAAO,OACP,QAA2B,kBAAkB,MACtC;AACP,OAAK,WAAW,KAAK,qBAA6B,KAAK,MAAM,MAAM,CAAC;AACpE,SAAO;;CAGR,AAAQ,UAA+D,EAAE;CACzE,AAAQ,kBAA0D;CAElE,AAAQ,YAAY,MAA8C;AACjE,OAAK,kBAAkB;;CAGxB,AAAQ,cAAyE;AAChF,SAAO,KAAK,QAAQ,SACjB,yBAA+C,KAAK,iBAAiB,KAAK,QAAQ,GAClF;;CAGJ,MACC,OAGA,IACA,MACO;AACP,OAAK,QAAQ,KAAK,sBAAgD,IAAI,OAAO,KAAK,CAAC;AACnF,SAAO;;CAGR,MAAM,aAAqC,SAAiE;EAC3G,MAAM,QAAQ,gBAAgB;EAC9B,MAAM,gBAAgB,IAAI,qBAAkD;AAE5E,GAAC,SAAS,cAAc,YAAY,YAAY;AAEhD,UAAQ,cAAc;EAEtB,MAAM,cAAc,cAAc,aAAa;AAC/C,iBAAe,KAAK,QAAQ,KAAK,QAAQ,iBAAuC,YAAY,GAAG,YAAY;AAE3G,SAAO;;CAGR,SACC,OAGA,IACA,MACO;AACP,OAAK,QAAQ,KACZ,iBAAuC,sBAAgD,IAAI,OAAO,KAAK,CAAC,CACxG;AACD,SAAO;;CAGR,QAGE;AACD,SAAO;GACN,QAAQ,KAAK,aAAa;GAC1B,OAAO,KAAK,WAAW,SAAS,KAAK,aAAa;GAClD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"src-BTo-wGWx.js","names":["keys","length","clone","Events","#clearEvent","#addListener","#config","#idGetter","#params","#order","#filter","#items","#readyItems","#emit","#setItems","#promise","#deleteAtIndex","#getById","#replaceItem","#deleteItem","#addItem","#setOne","#apply","#state","#lastError","#setNewItems","#validate","#setError","#prepareRequestParams","#setPromise","#watchPromise","#deleteById","#setNewOne","#params","#config","#idGetter","#promise","#item","#state","#readyItem","#mutable","#setMutable","#emit","#resetMutable","#setItem","#lastError","#setNewItem","#setError","#prepareRequestParams","#setPromise","#watchPromise","#deleteItem","#mutableItem","#updateItem","#requestDelete","#map","#registry","#cleanupScheduled","#cleanup","#emit","#scheduleCleanup","#entityConfig","#filterConfig","#orderConfig","#idGetter","#itemsMap","#collectionQueryMap","#itemQueryMap","#emit","#registerUpdate","#registerDelete","#propagateUpdateOne","#propagateDeleteOne","#itemUpdateHandler","#itemDeleteHandler","#propagateUpdateMany","#getCollectionKey","#collectionUpdateHandler","#collectionCreateHandler","#collectionItemUpdated","#collectionItemDeleted","#propagateDeleteMany","#prepareItemQuery","#simplifyCollectionParams","#prepareCollectionQuery","#getParentQuery","#reposMap","#queryConfig","#filterConfig","#orderConfig","#debugConfig","#initialConfig","#emit","#addRepository"],"sources":["../src/filter/errors.ts","../src/shared/shared.ts","../src/filter/constants.ts","../src/filter/filter.ts","../src/order/types.ts","../src/order/order.ts","../src/shared/ChimeraEventEmitter/ChimeraEventEmitter.ts","../src/query/types.ts","../src/query/constants.ts","../src/query/ChimeraCollectionQuery.ts","../src/query/ChimeraItemQuery.ts","../src/shared/ChimeraWeakValueMap/ChimeraWeakValueMap.ts","../src/store/ChimeraEntityRepository.ts","../src/store/ChimeraStore.ts"],"sourcesContent":["import { ChimeraError } from \"../shared/errors.ts\";\n\nexport class ChimeraFilterError extends ChimeraError {}\n\nexport class ChimeraFilterOperatorError extends ChimeraFilterError {\n\tconstructor(operator: string, message: string) {\n\t\tsuper(`Operator \"${operator}\" ${message}`);\n\t}\n}\n\nexport class ChimeraFilterOperatorNotFoundError extends ChimeraFilterOperatorError {\n\tconstructor(operator: string) {\n\t\tsuper(operator, \"not found\");\n\t}\n}\n","import type {\n\tAnyObject,\n\tChimeraCancellablePromise,\n\tChimeraEntityGetter,\n\tChimeraPropertyGetter,\n\tConstructable,\n} from \"./types.ts\";\n\nexport const deepObjectAssign = <T>(dst: AnyObject, srcObj: AnyObject, visited = new WeakSet()): T => {\n\tfor (const { 0: key, 1: srcVal } of Object.entries(srcObj)) {\n\t\tif (srcVal === null || typeof srcVal !== \"object\" || Array.isArray(srcVal)) {\n\t\t\tdst[key] = srcVal;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Check for circular references\n\t\tif (visited.has(srcVal)) {\n\t\t\tdst[key] = srcVal;\n\t\t\tcontinue;\n\t\t}\n\n\t\tvisited.add(srcVal);\n\t\tconst destVal = dst[key];\n\t\tdst[key] = destVal === null || typeof destVal !== \"object\" || Array.isArray(destVal) ? {} : destVal;\n\t\tdeepObjectAssign(dst[key], srcVal, visited);\n\t\tvisited.delete(srcVal);\n\t}\n\n\treturn dst as T;\n};\n\nexport const deepObjectFreeze = <T>(obj: T, frozenObjects = new WeakSet()): T => {\n\tif (obj === null || typeof obj !== \"object\" || Object.isFrozen(obj) || frozenObjects.has(obj)) return obj;\n\n\tfrozenObjects.add(obj);\n\tfor (const value of Object.values(obj))\n\t\tif (value && typeof value === \"object\") deepObjectFreeze(value, frozenObjects);\n\treturn Object.freeze(obj);\n};\n\nconst TypedArray = Object.getPrototypeOf(Int8Array);\n\nexport const deepObjectClone = <T>(value: T, refs?: Map<any, any>): T => {\n\tif (value === null) return null as T;\n\tif (value === undefined) return undefined as T;\n\tif (typeof value !== \"object\") return value;\n\n\tif (refs) {\n\t\tconst ref = refs.get(value);\n\t\tif (ref !== undefined) return ref;\n\t}\n\n\tif (value.constructor === Object) {\n\t\tconst keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value) as unknown as string[]);\n\t\tconst length = keys.length;\n\t\tconst clone = {} as T;\n\t\trefs ??= new Map();\n\t\trefs.set(value, clone);\n\t\tfor (let i = 0; i < length; i++) clone[keys[i] as keyof T] = deepObjectClone(value[keys[i] as keyof T], refs);\n\t\treturn clone;\n\t}\n\tif (Array.isArray(value)) {\n\t\tconst length = value.length;\n\t\tconst clone = new Array(length) as T;\n\t\trefs ??= new Map();\n\t\trefs.set(value, clone);\n\t\tfor (let i = 0; i < length; i++) clone[i as keyof T] = deepObjectClone(value[i], refs);\n\t\treturn clone;\n\t}\n\tif (value instanceof Date) return new (value.constructor as Constructable)(value.valueOf());\n\tif (value instanceof RegExp) return value.constructor as Constructable as T;\n\tif (value instanceof Map) {\n\t\tconst clone = new (value.constructor as Constructable)();\n\t\trefs ??= new Map();\n\t\trefs.set(value, clone);\n\t\tfor (const entry of value.entries()) clone.set(entry[0], deepObjectClone(entry[1], refs));\n\t\treturn clone;\n\t}\n\tif (value instanceof Set) {\n\t\tconst clone = new (value.constructor as Constructable)();\n\t\trefs ??= new Map();\n\t\trefs.set(value, clone);\n\t\tfor (const entry of value.values()) clone.add(deepObjectClone(entry, refs));\n\t\treturn clone;\n\t}\n\tif (value instanceof Error) {\n\t\tconst clone = new (value.constructor as Constructable)(value.message);\n\t\tconst keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value) as unknown as string[]);\n\t\tconst length = keys.length;\n\t\trefs ??= new Map();\n\t\trefs.set(value, clone);\n\t\tfor (let i = 0; i < length; i++) clone[keys[i] as keyof T] = deepObjectClone(value[keys[i] as keyof T], refs);\n\t\treturn clone;\n\t}\n\tif (value instanceof ArrayBuffer) return value.slice() as T;\n\tif (value instanceof TypedArray) return (value as unknown as Int8Array).slice() as T;\n\tif (value instanceof DataView) return new DataView(value.buffer.slice()) as T;\n\tif (value instanceof WeakMap) return value;\n\tif (value instanceof WeakSet) return value;\n\n\tconst clone = Object.create(value.constructor.prototype) as T;\n\tconst keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value) as unknown as string[]);\n\tconst length = keys.length;\n\trefs ??= new Map();\n\trefs.set(value, clone);\n\tfor (let i = 0; i < length; i++) clone[keys[i] as keyof T] = deepObjectClone(value[keys[i] as keyof T], refs);\n\treturn clone;\n};\n\nexport const compilePropertyGetter = <Entity>({ get }: ChimeraPropertyGetter<Entity>): ChimeraEntityGetter<Entity> =>\n\ttypeof get === \"function\" ? get : (e: Entity) => e[get];\n\nexport const simplifyPropertyGetter = <Entity>({ key }: ChimeraPropertyGetter<Entity>): string => key;\n\nexport const makeCancellablePromise = <Result>(\n\tpromise: Promise<Result> | ChimeraCancellablePromise<Result>,\n\tcontroller = new AbortController(),\n): ChimeraCancellablePromise<Result> => {\n\tconst signal = controller.signal;\n\n\tconst newPromise = promise.then(\n\t\t(v) => (signal.aborted ? new Promise(() => null) : v),\n\t\t(err) => {\n\t\t\treturn signal.aborted ? new Promise(() => null) : Promise.reject(err);\n\t\t},\n\t) as ChimeraCancellablePromise<Result>;\n\n\tnewPromise.cancel = () => controller.abort();\n\tnewPromise.cancelled = (cb) => (signal.aborted ? queueMicrotask(cb) : signal.addEventListener(\"abort\", cb));\n\n\tif (\"cancelled\" in promise) {\n\t\tpromise.cancelled(() => newPromise.cancel());\n\t\tcontroller.signal.addEventListener(\"abort\", () => promise.cancel());\n\t}\n\treturn newPromise;\n};\n","export const ChimeraOperatorSymbol = Symbol(\"ChimeraOperatorSymbol\");\nexport const ChimeraConjunctionSymbol = Symbol(\"ChimeraConjunctionSymbol\");\n","import { ChimeraInternalError } from \"../shared/errors.ts\";\nimport { compilePropertyGetter, simplifyPropertyGetter } from \"../shared/shared.ts\";\nimport type { ChimeraPropertyGetter, KeysOfType } from \"../shared/types.ts\";\nimport { ChimeraConjunctionSymbol, ChimeraOperatorSymbol } from \"./constants.ts\";\nimport { ChimeraFilterOperatorNotFoundError } from \"./errors.ts\";\nimport type {\n\tChimeraConjunctionDescriptor,\n\tChimeraConjunctionOperation,\n\tChimeraConjunctionType,\n\tChimeraFilterChecker,\n\tChimeraFilterConfig,\n\tChimeraFilterDescriptor,\n\tChimeraFilterOperatorDescriptor,\n\tChimeraKeyFromOperatorGetter,\n\tChimeraOperatorMap,\n\tChimeraSimplifiedFilter,\n\tChimeraSimplifiedOperator,\n\tConjunctionMap,\n\tSimplifiedConjunction,\n} from \"./types.ts\";\n\nconst filterConjunctions = {\n\tand: (operations) => operations.every((op) => op()),\n\tnot: (operations) => !operations.every((op) => op()),\n\tor: (operations) => operations.some((op) => op()),\n} satisfies ConjunctionMap;\n\nconst compileOperator = <OperatorsMap extends ChimeraOperatorMap, Entity>(\n\tconfig: ChimeraFilterConfig<OperatorsMap>,\n\t{ op, value, test }: ChimeraFilterOperatorDescriptor<OperatorsMap, Entity>,\n): ChimeraFilterChecker<Entity> => {\n\tconst operatorFunc = config.operators[op];\n\tif (!operatorFunc) throw new ChimeraFilterOperatorNotFoundError(op);\n\tconst getter = compilePropertyGetter(value);\n\treturn (entity) => operatorFunc(getter(entity), test);\n};\n\nexport const compileConjunction = <OperatorsMap extends ChimeraOperatorMap, Entity>(\n\tconfig: ChimeraFilterConfig<OperatorsMap>,\n\t{ kind, operations }: ChimeraConjunctionDescriptor<OperatorsMap, Entity>,\n): ChimeraFilterChecker<Entity> => {\n\tconst conjunction = filterConjunctions[kind];\n\n\tconst compiledOperations = operations\n\t\t.map((operation) => {\n\t\t\tswitch (operation.type) {\n\t\t\t\tcase ChimeraOperatorSymbol:\n\t\t\t\t\treturn compileOperator(config, operation);\n\t\t\t\tcase ChimeraConjunctionSymbol:\n\t\t\t\t\treturn compileConjunction(config, operation);\n\t\t\t\tdefault:\n\t\t\t\t\t// @ts-expect-error: `operation.type` should always be type `never` here\n\t\t\t\t\tthrow new ChimeraInternalError(`Invalid filter operation ${operation.type}`);\n\t\t\t}\n\t\t})\n\t\t.filter(Boolean);\n\n\treturn (entity) => conjunction(compiledOperations.map((op) => () => op(entity)));\n};\n\nexport const simplifyOperator = <OperatorsMap extends ChimeraOperatorMap, Entity>({\n\top,\n\tvalue,\n\ttest,\n}: ChimeraFilterOperatorDescriptor<OperatorsMap, Entity>): ChimeraSimplifiedOperator<OperatorsMap> => ({\n\tkey: simplifyPropertyGetter(value),\n\top,\n\ttest,\n\ttype: ChimeraOperatorSymbol,\n});\n\nconst compareSimplifiedOperator = <OperatorsMap extends ChimeraOperatorMap>(\n\ta: ChimeraSimplifiedOperator<OperatorsMap>,\n\tb: ChimeraSimplifiedOperator<OperatorsMap>,\n): number =>\n\ta.key.localeCompare(b.key) ||\n\ta.op.localeCompare(b.op) ||\n\tJSON.stringify(a.test).localeCompare(JSON.stringify(b.test));\n\nconst compareSimplifiedOperation = <OperatorsMap extends ChimeraOperatorMap>(\n\ta: ChimeraSimplifiedOperator<OperatorsMap> | SimplifiedConjunction<OperatorsMap>,\n\tb: ChimeraSimplifiedOperator<OperatorsMap> | SimplifiedConjunction<OperatorsMap>,\n): number => {\n\tif (a.type !== b.type) return a.type === ChimeraOperatorSymbol ? -1 : 1;\n\tif (a.type === ChimeraOperatorSymbol && b.type === ChimeraOperatorSymbol) return compareSimplifiedOperator(a, b);\n\tif (a.type === ChimeraConjunctionSymbol && b.type === ChimeraConjunctionSymbol)\n\t\treturn compareSimplifiedConjunction(a, b);\n\treturn 0;\n};\n\nconst compareSimplifiedConjunction = <OperatorsMap extends ChimeraOperatorMap>(\n\ta: SimplifiedConjunction<OperatorsMap>,\n\tb: SimplifiedConjunction<OperatorsMap>,\n): number => {\n\tconst kindCompare = a.kind.localeCompare(b.kind);\n\tif (kindCompare !== 0) return kindCompare;\n\n\tconst aOps = a.operations;\n\tconst bOps = b.operations;\n\tconst minLength = Math.min(aOps.length, bOps.length);\n\n\tfor (let i = 0; i < minLength; i++) {\n\t\tconst aOp = aOps[i];\n\t\tconst bOp = bOps[i];\n\t\tif (aOp && bOp) {\n\t\t\tconst compare = compareSimplifiedOperation(aOp, bOp);\n\t\t\tif (compare !== 0) return compare;\n\t\t}\n\t}\n\n\treturn aOps.length - bOps.length;\n};\n\nexport const simplifyConjunction = <OperatorsMap extends ChimeraOperatorMap, Entity>({\n\tkind,\n\toperations,\n}: ChimeraConjunctionDescriptor<OperatorsMap, Entity>): SimplifiedConjunction<OperatorsMap> => {\n\treturn {\n\t\tkind,\n\t\toperations: operations\n\t\t\t.map((op) => {\n\t\t\t\tswitch (op.type) {\n\t\t\t\t\tcase ChimeraOperatorSymbol:\n\t\t\t\t\t\treturn simplifyOperator(op);\n\t\t\t\t\tcase ChimeraConjunctionSymbol:\n\t\t\t\t\t\treturn simplifyConjunction(op);\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// @ts-expect-error: `op.type` should always be type `never` here\n\t\t\t\t\t\tthrow new ChimeraInternalError(`Invalid filter operation ${op.type}`);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.filter(Boolean)\n\t\t\t.sort((a, b) => compareSimplifiedOperation(a, b)),\n\t\ttype: ChimeraConjunctionSymbol,\n\t};\n};\n\nexport const chimeraCreateOperator = <\n\tEntity,\n\tOperatorsMap extends ChimeraOperatorMap,\n\tOp extends keyof OperatorsMap & string,\n>(\n\top: Op,\n\tvalue:\n\t\t| ChimeraPropertyGetter<Entity, Parameters<OperatorsMap[Op]>[0]>\n\t\t| (KeysOfType<Entity, Parameters<OperatorsMap[Op]>[0]> & string),\n\ttest: Parameters<OperatorsMap[Op]>[1],\n): ChimeraFilterOperatorDescriptor<OperatorsMap, Entity, Op> => ({\n\top,\n\ttest,\n\ttype: ChimeraOperatorSymbol,\n\tvalue: (typeof value === \"string\"\n\t\t? {\n\t\t\t\tget: value,\n\t\t\t\tkey: value,\n\t\t\t}\n\t\t: value) as ChimeraPropertyGetter<Entity, Parameters<OperatorsMap[Op]>[0]>,\n});\n\nexport const chimeraCreateConjunction = <\n\tEntity,\n\tOperatorsMap extends ChimeraOperatorMap,\n\tConj extends Exclude<ChimeraConjunctionType, \"not\"> = Exclude<ChimeraConjunctionType, \"not\">,\n>(\n\tkind: Conj,\n\toperations: ChimeraConjunctionOperation<OperatorsMap, Entity>[],\n): ChimeraConjunctionDescriptor<OperatorsMap, Entity, Conj> => ({\n\tkind,\n\toperations,\n\ttype: ChimeraConjunctionSymbol,\n});\n\nexport const chimeraCreateNot = <Entity, OperatorsMap extends ChimeraOperatorMap>(\n\toperation: ChimeraConjunctionOperation<OperatorsMap, Entity>,\n): ChimeraConjunctionDescriptor<OperatorsMap, Entity, \"not\"> => ({\n\tkind: \"not\",\n\toperations: [operation],\n\ttype: ChimeraConjunctionSymbol,\n});\n\nexport const compileFilter = <Entity, OperatorsMap extends ChimeraOperatorMap>(\n\tconfig: ChimeraFilterConfig<OperatorsMap>,\n\tdescriptor?: ChimeraFilterDescriptor<OperatorsMap, Entity> | null,\n): ChimeraFilterChecker<Entity> => (descriptor ? compileConjunction(config, descriptor) : () => true);\n\nexport const simplifyFilter = <Entity, OperatorsMap extends ChimeraOperatorMap>(\n\tdescriptor?: ChimeraFilterDescriptor<OperatorsMap, Entity> | null,\n): ChimeraSimplifiedFilter<OperatorsMap> => (descriptor ? simplifyConjunction(descriptor) : null);\n\nconst isOperationSubset = <OperatorsMap extends ChimeraOperatorMap>(\n\tcandidateOp: ChimeraSimplifiedOperator<OperatorsMap> | SimplifiedConjunction<OperatorsMap>,\n\ttargetOp: ChimeraSimplifiedOperator<OperatorsMap> | SimplifiedConjunction<OperatorsMap>,\n\tgetOperatorKey: ChimeraKeyFromOperatorGetter,\n): boolean => {\n\tif (candidateOp.type !== targetOp.type) return false;\n\n\tif (candidateOp.type === ChimeraOperatorSymbol && targetOp.type === ChimeraOperatorSymbol) {\n\t\t// For operators: must have the same key, op, and stringified value\n\t\treturn (\n\t\t\tcandidateOp.key === targetOp.key &&\n\t\t\tcandidateOp.op === targetOp.op &&\n\t\t\tgetOperatorKey(candidateOp) === getOperatorKey(targetOp)\n\t\t);\n\t}\n\n\tif (candidateOp.type === ChimeraConjunctionSymbol && targetOp.type === ChimeraConjunctionSymbol) {\n\t\t// For conjunctions: recursively check subset relationship\n\t\treturn isConjunctionSubset(candidateOp, targetOp, getOperatorKey);\n\t}\n\n\treturn false;\n};\n\nconst isConjunctionSubset = <OperatorsMap extends ChimeraOperatorMap>(\n\tcandidate: SimplifiedConjunction<OperatorsMap>,\n\ttarget: SimplifiedConjunction<OperatorsMap>,\n\tgetOperatorKey: ChimeraKeyFromOperatorGetter,\n): boolean => {\n\tif (candidate.kind !== target.kind) return false;\n\n\tswitch (candidate.kind) {\n\t\tcase \"and\":\n\t\tcase \"not\":\n\t\t\treturn candidate.operations.every((candidateOp) =>\n\t\t\t\ttarget.operations.some((targetOp) => isOperationSubset(candidateOp, targetOp, getOperatorKey)),\n\t\t\t);\n\t\tcase \"or\":\n\t\t\treturn target.operations.every((targetOp) =>\n\t\t\t\tcandidate.operations.some((candidateOp) => isOperationSubset(candidateOp, targetOp, getOperatorKey)),\n\t\t\t);\n\t}\n};\n\nexport const isFilterSubset = <OperatorsMap extends ChimeraOperatorMap>(\n\tcandidate: ChimeraSimplifiedFilter<OperatorsMap>,\n\ttarget: ChimeraSimplifiedFilter<OperatorsMap>,\n\tgetOperatorKey: ChimeraKeyFromOperatorGetter,\n): boolean => {\n\t// If a candidate is null, it's always a subset (matches everything)\n\tif (candidate === null) return true;\n\t// If the target is null but a candidate is not, a candidate is never a subset\n\tif (target === null) return false;\n\n\treturn isConjunctionSubset(candidate, target, getOperatorKey);\n};\n","import type { ChimeraEntityGetter, ChimeraPropertyGetter } from \"../shared/types.ts\";\n\nexport enum ChimeraOrderNulls {\n\tFirst = \"first\",\n\tLast = \"last\",\n}\n\nexport type ChimeraOrderDescriptor<Entity> = {\n\tkey: ChimeraPropertyGetter<Entity>;\n\tdesc: boolean;\n\tnulls: ChimeraOrderNulls;\n};\n\nexport type ChimeraOrderPriority<Entity> = ChimeraOrderDescriptor<Entity>[];\n\nexport type ChimeraOrderByComparator<Entity> = (a: Entity, b: Entity) => number;\n\nexport type ChimeraPrimitiveComparator = (a: unknown, b: unknown) => number;\n\nexport type CompiledOrderDescriptor<Entity> = {\n\tget: ChimeraEntityGetter<Entity>;\n\tdesc: boolean;\n\tnulls: ChimeraOrderNulls;\n};\n\nexport type ChimeraSimplifiedOrderDescriptor<Keys extends string = string> = {\n\tfield: Keys | string;\n\tdesc: boolean;\n\tnulls: ChimeraOrderNulls;\n};\n\nexport type ChimeraKeyFromOrderGetter = (order: ChimeraSimplifiedOrderDescriptor[] | null) => string;\n\nexport type ChimeraOrderConfig = {\n\tprimitiveComparator?: ChimeraPrimitiveComparator;\n\tgetKey?: ChimeraKeyFromOrderGetter;\n};\n","import { compilePropertyGetter } from \"../shared/shared.ts\";\nimport type { ChimeraPropertyGetter } from \"../shared/types.ts\";\nimport type {\n\tChimeraOrderByComparator,\n\tChimeraOrderDescriptor,\n\tChimeraOrderPriority,\n\tChimeraPrimitiveComparator,\n\tChimeraSimplifiedOrderDescriptor,\n\tCompiledOrderDescriptor,\n} from \"./types.ts\";\nimport { ChimeraOrderNulls } from \"./types.ts\";\n\nexport const compileOrderDescriptor = <Entity>({\n\tkey,\n\tdesc,\n\tnulls,\n}: ChimeraOrderDescriptor<Entity>): CompiledOrderDescriptor<Entity> => ({\n\tdesc,\n\tget: compilePropertyGetter(key),\n\tnulls,\n});\n\nexport const chimeraCreateOrderBy = <Entity>(\n\tkey: ChimeraPropertyGetter<Entity> | (keyof Entity & string),\n\tdesc = false,\n\tnulls: ChimeraOrderNulls = ChimeraOrderNulls.Last,\n): ChimeraOrderDescriptor<Entity> => ({\n\tdesc,\n\tkey: (typeof key === \"string\" ? { get: key, key } : key) as ChimeraPropertyGetter<Entity>,\n\tnulls,\n});\n\nconst nullsComparator = (a: unknown, b: unknown, nulls: ChimeraOrderNulls): number => {\n\t// biome-ignore lint/suspicious/noDoubleEquals: At least one of the operands should be null or undefined. If one of them is null and the other is undefined, we should get true.\n\treturn a == b ? 0 : (a == null ? -1 : 1) * (nulls === ChimeraOrderNulls.First ? 1 : -1);\n};\n\nexport const buildComparator = <Entity>(\n\tcomparator: ChimeraPrimitiveComparator,\n\torderBy?: ChimeraOrderPriority<Entity> | null,\n): ChimeraOrderByComparator<Entity> => {\n\tif (!orderBy) return () => 0;\n\n\tconst compiledPriority = orderBy.map((ob) => compileOrderDescriptor(ob));\n\treturn (a: Entity, b: Entity) => {\n\t\tlet result = 0;\n\t\tfor (const descriptor of compiledPriority) {\n\t\t\tconst vA = descriptor.get(a);\n\t\t\tconst vB = descriptor.get(b);\n\t\t\tif (vA == null || vB == null) {\n\t\t\t\tresult = nullsComparator(vA, vB, descriptor.nulls);\n\t\t\t\tif (result) break;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tresult = comparator(descriptor.get(a), descriptor.get(b));\n\t\t\tdescriptor.desc && (result *= -1);\n\t\t\tif (result) break;\n\t\t}\n\t\treturn result;\n\t};\n};\n\nexport const simplifyOrderBy = <Entity>(\n\torderBy?: ChimeraOrderPriority<Entity> | null,\n): ChimeraSimplifiedOrderDescriptor<keyof Entity & string>[] | null =>\n\torderBy ? orderBy.map((ob) => ({ desc: ob.desc, field: ob.key.key, nulls: ob.nulls })) : null;\n","type ValidEventTypes = string | object;\n\nexport type EventNames<T extends ValidEventTypes> = T extends string ? T : keyof T;\n\ntype ArgumentMap<T extends object> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => void ? Parameters<T[K]>[0] : T[K] extends any[] ? T[K][0] : T[K];\n};\n\ntype EventListener<T extends ValidEventTypes, K extends EventNames<T>> = T extends string\n\t? (arg: any) => void\n\t: (arg: ArgumentMap<Exclude<T, string | symbol>>[Extract<K, keyof T>]) => void;\n\nexport type EventArgs<T extends ValidEventTypes, K extends EventNames<T>> = Parameters<EventListener<T, K>>[0];\n\ntype EventRecord<T extends ValidEventTypes, K extends EventNames<T>> = {\n\tfn: EventListener<T, K>;\n\tonce: boolean;\n};\n\ntype EventRecordMap<T extends ValidEventTypes> = {\n\t[K in EventNames<T>]?: EventRecord<T, K> | EventRecord<T, K>[];\n};\n\nvar Events = function Events() {} as unknown as { new (): EventRecordMap<any> };\nEvents.prototype = Object.create(null);\n\nexport class ChimeraEventEmitter<EventTypes extends ValidEventTypes = string> {\n\t_events: EventRecordMap<EventTypes>;\n\t_eventsCount;\n\n\tconstructor() {\n\t\tthis._events = new Events();\n\t\tthis._eventsCount = 0;\n\t}\n\n\t#addListener<T extends EventNames<EventTypes>>(event: T, fn: EventListener<EventTypes, T>, once: boolean): this {\n\t\tvar listener = { fn, once };\n\n\t\tif (!this._events[event]) {\n\t\t\tthis._events[event] = listener;\n\t\t\tthis._eventsCount++;\n\t\t} else if (!(this._events[event] as EventRecord<EventTypes, T>).fn)\n\t\t\t(this._events[event] as EventRecord<EventTypes, T>[]).push(listener);\n\t\telse this._events[event] = [this._events[event] as EventRecord<EventTypes, T>, listener];\n\n\t\treturn this;\n\t}\n\n\t#clearEvent<T extends EventNames<EventTypes>>(event: T) {\n\t\tif (--this._eventsCount === 0) this._events = new Events();\n\t\telse delete this._events[event];\n\t}\n\n\teventNames(): EventNames<EventTypes>[] {\n\t\treturn Object.keys(this._events) as EventNames<EventTypes>[];\n\t}\n\n\tlisteners<T extends EventNames<EventTypes>>(event: T): EventListener<EventTypes, T>[] {\n\t\tvar handlers = this._events[event];\n\n\t\tif (!handlers) return [];\n\t\tif ((handlers as EventRecord<EventTypes, T>).fn) return [(handlers as EventRecord<EventTypes, T>).fn];\n\n\t\tfor (var i = 0, l = (handlers as EventRecord<EventTypes, T>[]).length, ee = new Array(l); i < l; i++) {\n\t\t\tee[i] = (handlers as [EventRecord<EventTypes, T>])[i as 0].fn;\n\t\t}\n\n\t\treturn ee;\n\t}\n\n\tlistenerCount(event: EventNames<EventTypes>): number {\n\t\tvar listeners = this._events[event];\n\n\t\tif (!listeners) return 0;\n\t\tif ((listeners as EventRecord<EventTypes, EventNames<EventTypes>>).fn) return 1;\n\t\treturn (listeners as []).length;\n\t}\n\n\tremoveListener<T extends EventNames<EventTypes>>(event: T, fn?: EventListener<EventTypes, T>, once?: boolean): this {\n\t\tif (!this._events[event]) return this;\n\t\tif (!fn) {\n\t\t\tthis.#clearEvent(event);\n\t\t\treturn this;\n\t\t}\n\n\t\tvar listeners = this._events[event];\n\n\t\tif ((listeners as EventRecord<EventTypes, T>).fn) {\n\t\t\tif (\n\t\t\t\t(listeners as EventRecord<EventTypes, T>).fn === fn &&\n\t\t\t\t(!once || (listeners as EventRecord<EventTypes, T>).once)\n\t\t\t) {\n\t\t\t\tthis.#clearEvent(event);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (var i = 0, events = [], length = (listeners as EventRecord<EventTypes, T>[]).length; i < length; i++) {\n\t\t\t\tif (\n\t\t\t\t\t(listeners as [EventRecord<EventTypes, T>])[i as 0].fn !== fn ||\n\t\t\t\t\t(once && !(listeners as [EventRecord<EventTypes, T>])[i as 0].once)\n\t\t\t\t) {\n\t\t\t\t\tevents.push((listeners as [EventRecord<EventTypes, T>])[i as 0]);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t//\n\t\t\t// Reset the array or remove it completely if we have no more listeners.\n\t\t\t//\n\t\t\tif (events.length) this._events[event] = events.length === 1 ? events[0] : events;\n\t\t\telse this.#clearEvent(event);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\temit<T extends EventNames<EventTypes>>(event: T, arg?: EventArgs<EventTypes, T>): boolean {\n\t\tif (!this._events[event]) return false;\n\n\t\tvar listeners = this._events[event];\n\n\t\tif ((listeners as EventRecord<EventTypes, T>).fn) {\n\t\t\tif ((listeners as EventRecord<EventTypes, T>).once)\n\t\t\t\tthis.removeListener(event, (listeners as EventRecord<EventTypes, T>).fn, true);\n\t\t\t(listeners as EventRecord<any, any>).fn.call(this, arg);\n\t\t} else {\n\t\t\tfor (var i = 0, length = (listeners as []).length; i < length; i++) {\n\t\t\t\tif ((listeners as [EventRecord<EventTypes, T>])[i as 0].once)\n\t\t\t\t\tthis.removeListener(event, (listeners as [EventRecord<EventTypes, T>])[i as 0].fn, true);\n\t\t\t\t(listeners as [EventRecord<any, any>])[i as 0].fn.call(this, arg);\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\ton<T extends EventNames<EventTypes>>(event: T, fn: EventListener<EventTypes, T>): this {\n\t\treturn this.#addListener(event, fn, false);\n\t}\n\n\tonce<T extends EventNames<EventTypes>>(event: T, fn: EventListener<EventTypes, T>): this {\n\t\treturn this.#addListener(event, fn, true);\n\t}\n\n\tremoveAllListeners(event?: EventNames<EventTypes>): this {\n\t\tif (event) {\n\t\t\tif (this._events[event]) this.#clearEvent(event);\n\t\t} else {\n\t\t\tthis._events = new Events();\n\t\t\tthis._eventsCount = 0;\n\t\t}\n\n\t\treturn this;\n\t}\n\n\toff = this.removeListener;\n\taddListener = this.on;\n}\n","import type { ChimeraOperatorMap, ChimeraSimplifiedFilter } from \"../filter/types.ts\";\nimport type { ChimeraSimplifiedOrderDescriptor } from \"../order/types.ts\";\nimport type { ChimeraEntityId, ChimeraEntityMap, ChimeraIdGetterFunc, DeepPartial, StrKeys } from \"../shared/types.ts\";\n\nexport enum ChimeraQueryFetchingState {\n\t/** Query just initialized. */\n\tInitialized = \"initialized\",\n\n\t/** Not used yet. */\n\tScheduled = \"scheduled\",\n\n\t/** Fetching in progress. */\n\tFetching = \"fetching\",\n\n\t/** Creating in progress */\n\tCreating = \"creating\",\n\n\t/** Updating in progress. */\n\tUpdating = \"updating\",\n\n\t/** Deleting in progress. */\n\tDeleting = \"deleting\",\n\n\t/** Fetch requested after reaching the Fetched, Errored, or Prefetched states. */\n\tRefetching = \"refetching\",\n\n\t/** Data retrieved from existing queries without initiating a fetch. */\n\tPrefetched = \"prefetched\",\n\n\t/** Fetch ended successfully; data is ready for use. */\n\tFetched = \"fetched\",\n\n\t/** Fetch ended with an error; no data is available. */\n\tErrored = \"errored\",\n\n\t/** Refetch ended with an error, but old data is still available. */\n\tReErrored = \"reErrored\",\n\n\t/**\n\t * Only for the item query, data is deleted, but the local value is still present,\n\t * no longer allows updates, but `refetch` still works (in case of strange errors, allows recovering state)\n\t */\n\tDeleted = \"deleted\",\n\n\t/** Only for the item query, data was actualized from an external event */\n\tActualized = \"actualized\",\n}\n\nexport interface ChimeraQueryFetchingStatable {\n\tget state(): ChimeraQueryFetchingState;\n\n\tget inProgress(): boolean;\n\n\tget ready(): boolean;\n}\n\n/**\n * Id getter types\n */\n\nexport type ChimeraQueryEntityIdGetter<Entity> = keyof Entity | ChimeraIdGetterFunc<Entity>;\n\nexport type ChimeraQueryDefaultEntityIdGetterFunction<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tname: EntityName,\n\tnewEntity: EntityMap[EntityName],\n) => ChimeraEntityId;\nexport type ChimeraQueryDefaultEntityIdGetter<EntityMap extends ChimeraEntityMap> =\n\t| keyof EntityMap[keyof EntityMap]\n\t| ChimeraQueryDefaultEntityIdGetterFunction<EntityMap>;\n\n/**\n * Response types\n */\n\nexport type ChimeraQueryCollectionFetcherResponse<Entity, Meta = any> = {\n\tdata: Entity[];\n\tmeta?: Meta;\n};\n\nexport type ChimeraQueryItemFetcherResponse<Entity, Meta = any> = {\n\tdata: Entity;\n\tmeta?: Meta;\n};\n\nexport type ChimeraQueryDeletionResult<Success extends boolean = boolean> = {\n\tid: ChimeraEntityId;\n\tsuccess: Success;\n};\n\nexport type ChimeraQueryItemDeleteResponse<Meta = any> = {\n\tresult: ChimeraQueryDeletionResult;\n\tmeta?: Meta;\n};\n\nexport type ChimeraQueryBatchedDeleteResponse<Meta = any> = {\n\tresult: ChimeraQueryDeletionResult[];\n\tmeta?: Meta;\n};\n\n/**\n * Fetcher types\n */\n\nexport type ChimeraQueryEntityFetcherRequestParams = {\n\tsignal: AbortSignal;\n};\n\nexport type ChimeraQueryEntityCollectionFetcherParams<Entity, OperatorsMap extends ChimeraOperatorMap, Meta = any> = {\n\torder: ChimeraSimplifiedOrderDescriptor<keyof Entity & string>[] | null;\n\tfilter: ChimeraSimplifiedFilter<OperatorsMap, keyof Entity & string> | null;\n\tmeta: Meta;\n};\n\n// biome-ignore lint/correctness/noUnusedVariables: May be required later\nexport type ChimeraQueryEntityItemFetcherParams<Entity, Meta = any> = {\n\tid: ChimeraEntityId;\n\tmeta: Meta;\n};\n\nexport type ChimeraQueryEntityCollectionFetcher<Entity, OperatorsMap extends ChimeraOperatorMap, Meta = any> = (\n\tparams: ChimeraQueryEntityCollectionFetcherParams<Entity, OperatorsMap, Meta>,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryCollectionFetcherResponse<Entity>>;\n\nexport type ChimeraQueryEntityItemFetcher<Entity> = (\n\tparams: ChimeraQueryEntityItemFetcherParams<Entity>,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemFetcherResponse<Entity>>;\n\nexport type ChimeraQueryDefaultCollectionFetcher<\n\tEntityMap extends ChimeraEntityMap,\n\tOperatorsMap extends ChimeraOperatorMap,\n> = <EntityName extends StrKeys<EntityMap>>(\n\tentityName: EntityName,\n\tparams: ChimeraQueryEntityCollectionFetcherParams<EntityMap[EntityName], OperatorsMap>,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryCollectionFetcherResponse<EntityMap[EntityName]>>;\n\nexport type ChimeraQueryDefaultItemFetcher<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tentityName: EntityName,\n\tparams: ChimeraQueryEntityItemFetcherParams<EntityMap[EntityName]>,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemFetcherResponse<EntityMap[EntityName]>>;\n\n/**\n * Updater types\n */\n\nexport type ChimeraQueryEntityItemUpdater<Entity> = (\n\tupdatedEntity: Entity,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemFetcherResponse<Entity>>;\n\nexport type ChimeraQueryEntityBatchedUpdater<Entity> = (\n\tupdatedEntities: Entity[],\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryCollectionFetcherResponse<Entity>>;\n\nexport type ChimeraQueryDefaultItemUpdater<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tentityName: EntityName,\n\tupdatedEntity: EntityMap[EntityName],\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemFetcherResponse<EntityMap[EntityName]>>;\n\nexport type ChimeraQueryDefaultBatchedUpdater<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tentityName: EntityName,\n\tupdatedEntities: EntityMap[EntityName][],\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryCollectionFetcherResponse<EntityMap[EntityName]>>;\n\n/**\n * Deleter types\n */\n\nexport type ChimeraQueryEntityItemDeleter = (\n\tdeleteId: ChimeraEntityId,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemDeleteResponse>;\n\nexport type ChimeraQueryEntityBatchedDeleter = (\n\tdeletedIds: ChimeraEntityId[],\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryBatchedDeleteResponse>;\n\nexport type ChimeraQueryDefaultItemDeleter<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tentityName: EntityName,\n\tdeleteId: ChimeraEntityId,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemDeleteResponse>;\n\nexport type ChimeraQueryDefaultBatchedDeleter<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tentityName: EntityName,\n\tdeletedIds: ChimeraEntityId[],\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryBatchedDeleteResponse>;\n\n/**\n * Creator type\n */\n\nexport type ChimeraQueryEntityItemCreator<Entity> = (\n\titem: DeepPartial<Entity>,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemFetcherResponse<Entity>>;\n\nexport type ChimeraQueryEntityBatchedCreator<Entity> = (\n\titems: DeepPartial<Entity>[],\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryCollectionFetcherResponse<Entity>>;\n\nexport type ChimeraQueryDefaultItemCreator<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tentityName: EntityName,\n\titem: DeepPartial<EntityMap[EntityName]>,\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryItemFetcherResponse<EntityMap[EntityName]>>;\n\nexport type ChimeraQueryDefaultBatchedCreator<EntityMap extends ChimeraEntityMap> = <\n\tEntityName extends StrKeys<EntityMap>,\n>(\n\tentityName: EntityName,\n\titems: DeepPartial<EntityMap[EntityName]>[],\n\trequestParams: ChimeraQueryEntityFetcherRequestParams,\n) => Promise<ChimeraQueryCollectionFetcherResponse<EntityMap[EntityName]>>;\n\n/**\n * Config types\n */\n\nexport type QueryEntityConfig<Entity extends object, OperatorsMap extends ChimeraOperatorMap> = {\n\tname: string;\n\n\tdevMode: boolean;\n\ttrustQuery: boolean;\n\tupdateDebounceTimeout: number;\n\n\tidGetter: ChimeraIdGetterFunc<Entity>;\n\n\tcollectionFetcher: ChimeraQueryEntityCollectionFetcher<Entity, OperatorsMap>;\n\titemFetcher: ChimeraQueryEntityItemFetcher<Entity>;\n\n\titemUpdater: ChimeraQueryEntityItemUpdater<Entity>;\n\tbatchedUpdater: ChimeraQueryEntityBatchedUpdater<Entity>;\n\n\titemDeleter: ChimeraQueryEntityItemDeleter;\n\tbatchedDeleter: ChimeraQueryEntityBatchedDeleter;\n\n\titemCreator: ChimeraQueryEntityItemCreator<Entity>;\n\tbatchedCreator: ChimeraQueryEntityBatchedCreator<Entity>;\n};\n\nexport type ChimeraQueryEntityConfig<Entity, OperatorsMap extends ChimeraOperatorMap, Meta = any> = {\n\ttrustQuery?: boolean;\n\tupdateDebounceTimeout?: number;\n\n\tidGetter?: ChimeraQueryEntityIdGetter<Entity>;\n\n\tcollectionFetcher?: ChimeraQueryEntityCollectionFetcher<Entity, OperatorsMap, Meta>;\n\titemFetcher?: ChimeraQueryEntityItemFetcher<Entity>;\n\n\titemUpdater?: ChimeraQueryEntityItemUpdater<Entity>;\n\tbatchedUpdater?: ChimeraQueryEntityBatchedUpdater<Entity>;\n\n\titemDeleter?: ChimeraQueryEntityItemDeleter;\n\tbatchedDeleter?: ChimeraQueryEntityBatchedDeleter;\n\n\titemCreator?: ChimeraQueryEntityItemCreator<Entity>;\n\tbatchedCreator?: ChimeraQueryEntityBatchedCreator<Entity>;\n};\n\nexport type ChimeraQueryDefaultsConfig<EntityMap extends ChimeraEntityMap, OperatorsMap extends ChimeraOperatorMap> = {\n\ttrustQuery?: boolean; // Disable extra filtering and sorting while creating a new query\n\tupdateDebounceTimeout?: number; // If set, will debounce updates with specified timeout in ms\n\n\tidGetter?: ChimeraQueryDefaultEntityIdGetter<EntityMap>;\n\n\tcollectionFetcher?: ChimeraQueryDefaultCollectionFetcher<EntityMap, OperatorsMap>;\n\titemFetcher?: ChimeraQueryDefaultItemFetcher<EntityMap>;\n\n\titemUpdater?: ChimeraQueryDefaultItemUpdater<EntityMap>;\n\tbatchedUpdater?: ChimeraQueryDefaultBatchedUpdater<EntityMap>;\n\n\titemDeleter?: ChimeraQueryDefaultItemDeleter<EntityMap>;\n\tbatchedDeleter?: ChimeraQueryDefaultBatchedDeleter<EntityMap>;\n\n\titemCreator?: ChimeraQueryDefaultItemCreator<EntityMap>;\n\tbatchedCreator?: ChimeraQueryDefaultBatchedCreator<EntityMap>;\n};\n\nexport type ChimeraEntityConfigMap<EntityMap extends ChimeraEntityMap, OperatorsMap extends ChimeraOperatorMap> = {\n\t[K in keyof EntityMap]: ChimeraQueryEntityConfig<EntityMap[K], OperatorsMap>;\n};\n\nexport type ChimeraQueryConfig<EntityMap extends ChimeraEntityMap, OperatorsMap extends ChimeraOperatorMap> = {\n\tdefaults: ChimeraQueryDefaultsConfig<EntityMap, OperatorsMap>;\n\tentities: ChimeraEntityConfigMap<EntityMap, OperatorsMap>;\n};\n","import { ChimeraQueryFetchingState } from \"./types.ts\";\n\nexport const ChimeraGetParamsSym = Symbol(\"ChimeraGetParamsSym\");\nexport const ChimeraSetOneSym = Symbol(\"ChimeraSetOneSym\");\nexport const ChimeraSetManySym = Symbol(\"ChimeraSetManySym\");\nexport const ChimeraDeleteOneSym = Symbol(\"ChimeraDeleteOneSym\");\nexport const ChimeraDeleteManySym = Symbol(\"ChimeraDeleteManySym\");\nexport const ChimeraUpdateMixedSym = Symbol(\"ChimeraUpdateMixedSym\");\n\nexport const IN_PROGRESS_STATES = [\n\tChimeraQueryFetchingState.Scheduled,\n\tChimeraQueryFetchingState.Creating,\n\tChimeraQueryFetchingState.Fetching,\n\tChimeraQueryFetchingState.Refetching,\n\tChimeraQueryFetchingState.Updating,\n\tChimeraQueryFetchingState.Deleting,\n];\n","import type { ChimeraFilterChecker, ChimeraOperatorMap } from \"../filter/types.ts\";\nimport type { ChimeraOrderByComparator } from \"../order/types.ts\";\nimport type { EventArgs, EventNames } from \"../shared/ChimeraEventEmitter\";\nimport { ChimeraEventEmitter } from \"../shared/ChimeraEventEmitter\";\nimport { ChimeraInternalError } from \"../shared/errors.ts\";\nimport { deepObjectClone, deepObjectFreeze, makeCancellablePromise } from \"../shared/shared.ts\";\nimport type { ChimeraCancellablePromise, ChimeraEntityId, ChimeraIdGetterFunc, DeepPartial } from \"../shared/types.ts\";\nimport {\n\tChimeraDeleteManySym,\n\tChimeraDeleteOneSym,\n\tChimeraGetParamsSym,\n\tChimeraSetManySym,\n\tChimeraSetOneSym,\n\tChimeraUpdateMixedSym,\n\tIN_PROGRESS_STATES,\n} from \"./constants.ts\";\nimport {\n\tChimeraQueryAlreadyRunningError,\n\tChimeraQueryDeletingError,\n\ttype ChimeraQueryError,\n\tChimeraQueryFetchingError,\n\tChimeraQueryNotReadyError,\n\tChimeraQueryTrustFetchedCollectionError,\n\tChimeraQueryTrustIdMismatchError,\n\tChimeraQueryUnsuccessfulDeletionError,\n} from \"./errors.ts\";\nimport {\n\ttype ChimeraQueryBatchedDeleteResponse,\n\ttype ChimeraQueryCollectionFetcherResponse,\n\ttype ChimeraQueryEntityCollectionFetcherParams,\n\ttype ChimeraQueryFetchingStatable,\n\tChimeraQueryFetchingState,\n\ttype ChimeraQueryItemDeleteResponse,\n\ttype ChimeraQueryItemFetcherResponse,\n\ttype QueryEntityConfig,\n} from \"./types.ts\";\n\nexport type ChimeraCollectionQueryEventMap<Item extends object, OperatorsMap extends ChimeraOperatorMap> = {\n\t/** Once the query is initialized */\n\tinitialized: { instance: ChimeraCollectionQuery<Item, OperatorsMap> };\n\n\t/** Once the query data is ready (will be followed by 'update') */\n\tready: { instance: ChimeraCollectionQuery<Item, OperatorsMap> };\n\n\t/** Each time the query was updated */\n\tupdated: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; items: Item[]; oldItems: Item[] | null };\n\t/** Each time the query was an initiator of update */\n\tselfUpdated: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; items: Item[]; oldItems: Item[] | null };\n\n\t/** Each time item created */\n\tselfItemCreated: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; item: Item };\n\n\t/** Each time item added */\n\titemAdded: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; item: Item };\n\n\t/** Each time item updated */\n\titemUpdated: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; oldItem: Item; newItem: Item };\n\t/** Each time the query was an initiator of an item update */\n\tselfItemUpdated: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; item: Item };\n\n\t/** Each time item deleted */\n\titemDeleted: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; item: Item };\n\t/** Each time the query was an initiator of item deletion */\n\tselfItemDeleted: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; id: ChimeraEntityId };\n\n\t/** Each time the fetcher produces an error */\n\terror: { instance: ChimeraCollectionQuery<Item, OperatorsMap>; error: unknown };\n};\n\nexport class ChimeraCollectionQuery<Item extends object, OperatorsMap extends ChimeraOperatorMap>\n\textends ChimeraEventEmitter<ChimeraCollectionQueryEventMap<Item, OperatorsMap>>\n\timplements ChimeraQueryFetchingStatable\n{\n\t#state: ChimeraQueryFetchingState;\n\t#promise: ChimeraCancellablePromise | null;\n\t#lastError: unknown;\n\t#items: Item[] | null;\n\treadonly #config: QueryEntityConfig<Item, OperatorsMap>;\n\treadonly #idGetter: ChimeraIdGetterFunc<Item>;\n\treadonly #params: ChimeraQueryEntityCollectionFetcherParams<Item, OperatorsMap>;\n\treadonly #order: ChimeraOrderByComparator<Item>;\n\treadonly #filter: ChimeraFilterChecker<Item>;\n\n\t#emit<T extends EventNames<ChimeraCollectionQueryEventMap<Item, OperatorsMap>>>(\n\t\tevent: T,\n\t\targ: EventArgs<ChimeraCollectionQueryEventMap<Item, OperatorsMap>, T>,\n\t) {\n\t\tqueueMicrotask(() => super.emit(event, arg));\n\t}\n\n\toverride emit(): never {\n\t\tthrow new ChimeraInternalError(\"External events dispatching is not supported.\");\n\t}\n\n\t#prepareRequestParams() {\n\t\treturn {\n\t\t\tcontroller: new AbortController(),\n\t\t};\n\t}\n\n\t#readyItems(internalMessage?: string): Item[] {\n\t\tif (this.#items) return this.#items;\n\t\tthrow internalMessage\n\t\t\t? new ChimeraInternalError(internalMessage)\n\t\t\t: new ChimeraQueryNotReadyError(this.#config.name);\n\t}\n\n\t#addItem(item: Item) {\n\t\tconst items = this.#readyItems(\"Trying to update not ready collection\");\n\t\tconst foundIndex = items.findIndex((el) => this.#order(el, item) > 0);\n\t\titems.splice(foundIndex !== -1 ? foundIndex : items.length, 0, item);\n\t\tthis.#emit(\"itemAdded\", { instance: this, item });\n\t}\n\n\t#setItems(items: Item[]) {\n\t\t!this.#items && this.#emit(\"ready\", { instance: this });\n\t\tconst oldItems = this.#items;\n\t\tthis.#items = items;\n\t\tthis.#emit(\"updated\", { instance: this, items, oldItems });\n\t}\n\n\t#setNewItems(items: Item[]) {\n\t\titems.forEach((i) => void deepObjectFreeze(i));\n\t\tthis.#emit(\"selfUpdated\", { instance: this, items, oldItems: this.#items });\n\t\tthis.#setItems(items);\n\t}\n\n\t#setPromise<P extends ChimeraCancellablePromise>(promise: P): P {\n\t\tthis.#promise?.cancel();\n\t\tthis.#promise = promise;\n\t\treturn promise;\n\t}\n\n\t#deleteAtIndex(index: number) {\n\t\tif (index === -1) return;\n\t\tconst { 0: old } = this.#readyItems(\"Trying to update not ready collection\").splice(index, 1);\n\t\tthis.#emit(\"itemDeleted\", { instance: this, item: old as Item });\n\t}\n\n\t#deleteItem(item: Item) {\n\t\tthis.#deleteAtIndex(this.#readyItems(\"Trying to update not ready collection\").indexOf(item));\n\t}\n\n\t#deleteById(id: ChimeraEntityId) {\n\t\tthis.#deleteAtIndex(\n\t\t\tthis.#readyItems(\"Trying to update not ready collection\").findIndex((item) => this.#idGetter(item) === id),\n\t\t);\n\t}\n\n\t#replaceItem(oldItem: Item, newItem: Item) {\n\t\tconst items = this.#readyItems(\"Trying to update not ready collection\");\n\t\tconst index = items.indexOf(oldItem);\n\t\tconst old = items[index];\n\t\titems[index] = newItem;\n\t\tthis.#emit(\"itemUpdated\", { instance: this, newItem: newItem, oldItem: old as Item });\n\t}\n\n\t#getById(id: ChimeraEntityId) {\n\t\treturn this.#readyItems(\"Trying to update not ready collection\").find((item) => this.#idGetter(item) === id);\n\t}\n\n\t#setOne(item: Item) {\n\t\tconst existingItem = this.#getById(this.#idGetter(item));\n\t\tconst nowMatches = this.#filter(item);\n\n\t\tif (!(nowMatches || existingItem)) return;\n\n\t\tif (existingItem) {\n\t\t\tif (this.#order(existingItem, item) === 0) {\n\t\t\t\tthis.#replaceItem(existingItem, item);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#deleteItem(existingItem);\n\t\t}\n\n\t\tnowMatches && this.#addItem(item);\n\t}\n\n\t#setNewOne(item: Item) {\n\t\tdeepObjectFreeze(item);\n\t\tthis.#setOne(item);\n\t}\n\n\t#apply(input: Item[]): Item[] {\n\t\treturn input.filter((item: Item) => this.#filter(item)).sort((a, b) => this.#order(a, b));\n\t}\n\n\t#validate(input: Item[]): Item[] {\n\t\tif (this.#config.trustQuery && !this.#config.devMode) return input;\n\n\t\tconst prepared = this.#apply(input);\n\t\tif (!this.#config.trustQuery) return prepared;\n\n\t\tif (this.#config.devMode) {\n\t\t\tfor (let i = 0; i < input.length; i++) {\n\t\t\t\tif (input[i] !== prepared[i]) {\n\t\t\t\t\tconsole.warn(new ChimeraQueryTrustFetchedCollectionError(this.#config.name, input, prepared));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn input;\n\t}\n\n\t#setError(error: unknown, source: ChimeraQueryError): never {\n\t\tthis.#state = this.#items ? ChimeraQueryFetchingState.ReErrored : ChimeraQueryFetchingState.Errored;\n\t\tthis.#lastError = error;\n\t\tthis.#emit(\"error\", { error, instance: this });\n\t\tthrow source;\n\t}\n\n\t#watchPromise(\n\t\tpromise: ChimeraCancellablePromise<ChimeraQueryCollectionFetcherResponse<Item>>,\n\t\tcontroller: AbortController,\n\t): ChimeraCancellablePromise<ChimeraQueryCollectionFetcherResponse<Item>> {\n\t\treturn makeCancellablePromise(\n\t\t\tpromise\n\t\t\t\t.then((response) => {\n\t\t\t\t\tthis.#setNewItems(this.#validate(response.data));\n\t\t\t\t\tthis.#state = ChimeraQueryFetchingState.Fetched;\n\t\t\t\t\treturn response;\n\t\t\t\t})\n\t\t\t\t.catch((error) => this.#setError(error, new ChimeraQueryFetchingError(this.#config.name, error))),\n\t\t\tcontroller,\n\t\t);\n\t}\n\n\tconstructor(\n\t\tconfig: QueryEntityConfig<Item, OperatorsMap>,\n\t\tparams: ChimeraQueryEntityCollectionFetcherParams<Item, any>,\n\t\texistingItems: Iterable<Item> | null,\n\t\torder: ChimeraOrderByComparator<Item>,\n\t\tfilter: ChimeraFilterChecker<Item>,\n\t\talreadyValid: boolean,\n\t) {\n\t\tsuper();\n\n\t\tthis.#config = config;\n\t\tthis.#params = params;\n\t\tthis.#promise = null;\n\t\tthis.#items = null;\n\t\tthis.#state = ChimeraQueryFetchingState.Initialized;\n\t\tthis.#idGetter = config.idGetter;\n\t\tthis.#filter = filter;\n\t\tthis.#order = order;\n\n\t\tif (existingItems) {\n\t\t\tconst input = Array.from(existingItems);\n\t\t\tthis.#setItems(alreadyValid ? this.#validate(input) : this.#apply(input));\n\t\t\tthis.#state = ChimeraQueryFetchingState.Prefetched;\n\t\t} else {\n\t\t\tthis.#state = ChimeraQueryFetchingState.Fetching;\n\t\t\tconst { controller } = this.#prepareRequestParams();\n\t\t\tthis.#setPromise(\n\t\t\t\tthis.#watchPromise(\n\t\t\t\t\tmakeCancellablePromise(config.collectionFetcher(params, { signal: controller.signal }), controller),\n\t\t\t\t\tcontroller,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tthis.#emit(\"initialized\", { instance: this });\n\t}\n\n\tget [ChimeraGetParamsSym](): ChimeraQueryEntityCollectionFetcherParams<Item, OperatorsMap> {\n\t\treturn this.#params;\n\t}\n\n\t[ChimeraSetOneSym](item: Item) {\n\t\tthis.#items && this.#setOne(item);\n\t}\n\n\t[ChimeraDeleteOneSym](id: ChimeraEntityId) {\n\t\tthis.#items && this.#deleteById(id);\n\t}\n\n\t[ChimeraSetManySym](items: Iterable<Item>) {\n\t\tif (this.#items) for (const item of items) this.#setOne(item);\n\t}\n\n\t[ChimeraDeleteManySym](ids: Iterable<ChimeraEntityId>) {\n\t\tif (this.#items) for (const id of ids) this.#deleteById(id);\n\t}\n\n\t[ChimeraUpdateMixedSym](toAdd: Iterable<Item>, toDelete: Iterable<ChimeraEntityId>) {\n\t\tif (this.#items) {\n\t\t\tfor (const id of toDelete) this.#deleteById(id);\n\t\t\tfor (const item of toAdd) this.#setOne(item);\n\t\t}\n\t}\n\n\tget state(): ChimeraQueryFetchingState {\n\t\treturn this.#state;\n\t}\n\n\tget inProgress(): boolean {\n\t\treturn IN_PROGRESS_STATES.includes(this.#state);\n\t}\n\n\tget ready(): boolean {\n\t\treturn this.#items !== null;\n\t}\n\n\tget lastError(): unknown {\n\t\treturn this.#lastError;\n\t}\n\n\t/**\n\t * Wait for the current progress process to complete (both success or error)\n\t */\n\tget progress(): Promise<void> {\n\t\treturn new Promise((res) => {\n\t\t\tconst resolve = () => queueMicrotask(() => res());\n\t\t\tif (this.#promise) {\n\t\t\t\tthis.#promise.then(resolve, resolve);\n\t\t\t\tthis.#promise.cancelled(() => this.progress.then(resolve, resolve));\n\t\t\t} else resolve();\n\t\t});\n\t}\n\n\t/**\n\t * Wait for the current progress process to complete, throw an error if it fails\n\t */\n\tget result(): Promise<void> {\n\t\treturn new Promise((res, rej) => {\n\t\t\tconst resolve = () => queueMicrotask(() => res());\n\t\t\tif (this.#promise) {\n\t\t\t\tthis.#promise.then(resolve, rej);\n\t\t\t\tthis.#promise.cancelled(() => (this.#promise ? this.result.then(res, rej) : rej(\"cancelled\")));\n\t\t\t} else resolve();\n\t\t});\n\t}\n\n\t/** Return an item if it is ready, throw error otherwise */\n\tgetById(id: ChimeraEntityId): Item | undefined {\n\t\treturn this.#readyItems().find((item) => this.#idGetter(item) === id);\n\t}\n\n\t/** Return mutable ref to item by idx if it is ready, throw error otherwise */\n\tmutableAt(idx: number): Item | undefined {\n\t\treturn deepObjectClone(this.#readyItems().at(idx));\n\t}\n\n\t/** Return mutable ref to item by [id] if it is ready, throw error otherwise */\n\tmutableGetById(id: ChimeraEntityId): Item | undefined {\n\t\treturn deepObjectClone(this.#readyItems().find((item) => this.#idGetter(item) === id));\n\t}\n\n\t/**\n\t * Trigger refetch, return existing refetch promise if already running\n\t * @param force If true cancels any running process and starts a new one\n\t * @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress\n\t */\n\trefetch(force = false): Promise<ChimeraQueryCollectionFetcherResponse<Item>> {\n\t\tif (\n\t\t\t!force &&\n\t\t\tthis.#promise &&\n\t\t\t[ChimeraQueryFetchingState.Fetching, ChimeraQueryFetchingState.Refetching].includes(this.#state)\n\t\t)\n\t\t\treturn this.#promise as Promise<ChimeraQueryCollectionFetcherResponse<Item>>;\n\n\t\tif (!force && [ChimeraQueryFetchingState.Updating, ChimeraQueryFetchingState.Deleting].includes(this.#state))\n\t\t\tthrow new ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);\n\n\t\tthis.#state = ChimeraQueryFetchingState.Refetching;\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#setPromise(\n\t\t\tthis.#watchPromise(\n\t\t\t\tmakeCancellablePromise(this.#config.collectionFetcher(this.#params, { signal: controller.signal }), controller),\n\t\t\t\tcontroller,\n\t\t\t),\n\t\t);\n\t}\n\n\t/**\n\t * Update item using updated copy\n\t * @param newItem new item to update\n\t */\n\tupdate(newItem: Item): Promise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#config.itemUpdater(newItem, { signal: controller.signal }).then((response) => {\n\t\t\tconst { data } = response;\n\t\t\tthis.#items && this.#setNewOne(data);\n\t\t\tthis.#emit(\"selfItemUpdated\", { instance: this, item: data });\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * Update item using updated copy\n\t * @param newItems array of items to update\n\t */\n\tbatchedUpdate(newItems: Iterable<Item>): Promise<ChimeraQueryCollectionFetcherResponse<Item>> {\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#config.batchedUpdater(Array.from(newItems), { signal: controller.signal }).then((response) => {\n\t\t\tconst ready = this.ready;\n\t\t\tresponse.data.forEach((item) => {\n\t\t\t\tready && this.#setNewOne(item);\n\t\t\t\tthis.#emit(\"selfItemUpdated\", { instance: this, item });\n\t\t\t});\n\t\t\treturn response;\n\t\t});\n\t}\n\n\t/**\n\t * Delete item using its [id]\n\t * @param id id of item to delete\n\t */\n\tdelete(id: ChimeraEntityId): Promise<ChimeraQueryItemDeleteResponse> {\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#config.itemDeleter(id, { signal: controller.signal }).then(\n\t\t\t(response) => {\n\t\t\t\tconst {\n\t\t\t\t\tresult: { id: newId, success },\n\t\t\t\t} = response;\n\t\t\t\tif (!this.#items) {\n\t\t\t\t\tsuccess && this.#emit(\"selfItemDeleted\", { id: newId, instance: this });\n\t\t\t\t\treturn response;\n\t\t\t\t}\n\n\t\t\t\tif (this.#config.trustQuery && !this.#config.devMode && success) {\n\t\t\t\t\tthis.#deleteById(newId);\n\t\t\t\t\tthis.#emit(\"selfItemDeleted\", { id: newId, instance: this });\n\t\t\t\t\treturn response;\n\t\t\t\t}\n\n\t\t\t\tif (id !== newId) {\n\t\t\t\t\tthis.#config.devMode &&\n\t\t\t\t\t\tthis.#config.trustQuery &&\n\t\t\t\t\t\tconsole.warn(new ChimeraQueryTrustIdMismatchError(this.#config.name, id, newId));\n\n\t\t\t\t\tif (!this.#config.trustQuery) {\n\t\t\t\t\t\tsuccess && this.#emit(\"selfItemDeleted\", { id: newId, instance: this });\n\t\t\t\t\t\tthrow new ChimeraQueryTrustIdMismatchError(this.#config.name, id, newId);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (success) {\n\t\t\t\t\tthis.#deleteById(newId);\n\t\t\t\t\tthis.#emit(\"selfItemDeleted\", { id: newId, instance: this });\n\t\t\t\t\treturn response;\n\t\t\t\t}\n\t\t\t\tconst error = new ChimeraQueryUnsuccessfulDeletionError(this.#config.name, id);\n\t\t\t\tthis.#state = ChimeraQueryFetchingState.ReErrored;\n\t\t\t\tthis.#lastError = error;\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t\t(error) => this.#setError(error, new ChimeraQueryDeletingError(this.#config.name, error)),\n\t\t);\n\t}\n\n\t/**\n\t * Delete a list of items by their [id]s\n\t * @param ids array of items to delete\n\t */\n\tbatchedDelete(ids: Iterable<ChimeraEntityId>): Promise<ChimeraQueryBatchedDeleteResponse> {\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#config.batchedDeleter(Array.from(ids), { signal: controller.signal }).then(\n\t\t\t(response) => {\n\t\t\t\tthis.#items &&\n\t\t\t\t\tresponse.result.forEach(({ id: newId, success }) => {\n\t\t\t\t\t\tif (success) {\n\t\t\t\t\t\t\tthis.#deleteById(newId);\n\t\t\t\t\t\t\tthis.#emit(\"selfItemDeleted\", { id: newId, instance: this });\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst error = new ChimeraQueryUnsuccessfulDeletionError(this.#config.name, newId);\n\t\t\t\t\t\t\tthis.#state = ChimeraQueryFetchingState.ReErrored;\n\t\t\t\t\t\t\tthis.#lastError = error;\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\t(error) => this.#setError(error, new ChimeraQueryDeletingError(this.#config.name, error)),\n\t\t);\n\t}\n\n\t/**\n\t * Create new item using partial data\n\t * @param item partial item data to create new item\n\t */\n\tcreate(item: DeepPartial<Item>): Promise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#config.itemCreator(item, { signal: controller.signal }).then(\n\t\t\t(response) => {\n\t\t\t\tconst { data } = response;\n\t\t\t\tthis.#items && this.#setNewOne(data);\n\t\t\t\tthis.#emit(\"selfItemCreated\", { instance: this, item: data });\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\t(error) => this.#setError(error, new ChimeraQueryFetchingError(this.#config.name, error)),\n\t\t);\n\t}\n\n\t/**\n\t * Create multiple items using partial data\n\t * @param items array of partial item data to create new items\n\t */\n\tbatchedCreate(items: Iterable<DeepPartial<Item>>): Promise<ChimeraQueryCollectionFetcherResponse<Item>> {\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#config.batchedCreator(Array.from(items), { signal: controller.signal }).then(\n\t\t\t(response) => {\n\t\t\t\tthis.#items &&\n\t\t\t\t\tresponse.data.forEach((item) => {\n\t\t\t\t\t\tthis.#setNewOne(item);\n\t\t\t\t\t\tthis.#emit(\"selfItemCreated\", { instance: this, item });\n\t\t\t\t\t});\n\t\t\t\treturn response;\n\t\t\t},\n\t\t\t(error) => this.#setError(error, new ChimeraQueryFetchingError(this.#config.name, error)),\n\t\t);\n\t}\n\n\t/**\n\t * Standard Array API without mutations\n\t */\n\n\tget length(): number {\n\t\treturn this.#readyItems().length;\n\t}\n\n\t[Symbol.iterator](): Iterator<Item> {\n\t\treturn this.#readyItems()[Symbol.iterator]();\n\t}\n\n\tat(idx: number): Item | undefined {\n\t\treturn this.#readyItems().at(idx);\n\t}\n\n\tentries(): ArrayIterator<[number, Item]> {\n\t\treturn this.#readyItems().entries();\n\t}\n\n\tvalues(): ArrayIterator<Item> {\n\t\treturn this.#readyItems().values();\n\t}\n\n\tkeys(): ArrayIterator<number> {\n\t\treturn this.#readyItems().keys();\n\t}\n\n\tevery<S extends Item>(\n\t\tpredicate: (value: Item, index: number, query: this) => value is S,\n\t): this is ChimeraCollectionQuery<S, OperatorsMap>;\n\tevery(predicate: (value: Item, index: number, query: this) => unknown): boolean;\n\tevery(predicate: (value: Item, index: number, query: this) => unknown): boolean {\n\t\treturn this.#readyItems().every((item, idx) => predicate(item, idx, this));\n\t}\n\n\tsome(predicate: (value: Item, index: number, query: this) => unknown): boolean {\n\t\treturn this.#readyItems().some((item, idx) => predicate(item, idx, this));\n\t}\n\n\tfilter<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): S[];\n\tfilter(predicate: (value: Item, index: number, query: this) => boolean): Item[];\n\tfilter<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): S[] {\n\t\treturn this.#readyItems().filter((item, idx) => predicate(item, idx, this));\n\t}\n\n\tfind<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): S | undefined;\n\tfind(predicate: (value: Item, index: number, query: this) => unknown): Item | undefined;\n\tfind<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): S | undefined {\n\t\treturn this.#readyItems().find((item, idx) => predicate(item, idx, this));\n\t}\n\n\tfindIndex<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): number;\n\tfindIndex(predicate: (value: Item, index: number, query: this) => boolean): number;\n\tfindIndex<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): number {\n\t\treturn this.#readyItems().findIndex((item, idx) => predicate(item, idx, this));\n\t}\n\n\tfindLast<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): S | undefined;\n\tfindLast(predicate: (value: Item, index: number, query: this) => boolean): Item | undefined;\n\tfindLast<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): S | undefined {\n\t\treturn this.#readyItems().findLast((item, idx) => predicate(item, idx, this));\n\t}\n\n\tfindLastIndex<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): number;\n\tfindLastIndex(predicate: (value: Item, index: number, query: this) => boolean): number;\n\tfindLastIndex<S extends Item>(predicate: (value: Item, index: number, query: this) => value is S): number {\n\t\treturn this.#readyItems().findLastIndex((item, idx) => predicate(item, idx, this));\n\t}\n\n\tforEach(cb: (value: Item, index: number, query: this) => void) {\n\t\tthis.#readyItems().forEach((item, idx) => void cb(item, idx, this));\n\t}\n\n\tincludes(item: Item): boolean {\n\t\treturn this.#readyItems().includes(item);\n\t}\n\n\tindexOf(item: Item): number {\n\t\treturn this.#readyItems().indexOf(item);\n\t}\n\n\tmap<U>(cb: (value: Item, index: number, query: this) => U) {\n\t\treturn this.#readyItems().map((item, idx) => cb(item, idx, this));\n\t}\n\n\treduce<U>(cb: (previousValue: U, currentValue: Item, currentIndex: number, query: this) => U, initialValue?: U) {\n\t\treturn this.#readyItems().reduce((prev, cur, idx) => cb(prev as U, cur, idx, this), initialValue);\n\t}\n\n\treduceRight<U>(cb: (previousValue: U, currentValue: Item, currentIndex: number, query: this) => U, initialValue?: U) {\n\t\treturn this.#readyItems().reduceRight((prev, cur, idx) => cb(prev as U, cur, idx, this), initialValue);\n\t}\n\n\tslice(start?: number, end?: number): Item[] {\n\t\treturn this.#readyItems().slice(start, end);\n\t}\n\n\ttoSorted(compareFn?: (a: Item, b: Item) => number): Item[] {\n\t\treturn this.#readyItems().toSorted(compareFn);\n\t}\n\n\ttoSpliced(start: number, deleteCount: number, ...items: Item[]): Item[] {\n\t\treturn this.#readyItems().toSpliced(start, deleteCount, ...items);\n\t}\n\n\ttoJSON() {\n\t\treturn Array.from(this.#readyItems());\n\t}\n\n\toverride toString(): string {\n\t\treturn this.#readyItems().toString();\n\t}\n}\n","import type { ChimeraOperatorMap } from \"../filter\";\nimport type { EventArgs, EventNames } from \"../shared/ChimeraEventEmitter\";\nimport { ChimeraEventEmitter } from \"../shared/ChimeraEventEmitter\";\nimport { ChimeraInternalError } from \"../shared/errors.ts\";\nimport { deepObjectAssign, deepObjectClone, deepObjectFreeze, makeCancellablePromise } from \"../shared/shared.ts\";\nimport type {\n\tAnyObject,\n\tChimeraCancellablePromise,\n\tChimeraEntityId,\n\tChimeraIdGetterFunc,\n\tDeepPartial,\n} from \"../shared/types.ts\";\nimport { ChimeraDeleteOneSym, ChimeraGetParamsSym, ChimeraSetOneSym, IN_PROGRESS_STATES } from \"./constants.ts\";\nimport {\n\tChimeraQueryAlreadyRunningError,\n\tChimeraQueryDeletedItemError,\n\tChimeraQueryDeletingError,\n\ttype ChimeraQueryError,\n\tChimeraQueryFetchingError,\n\tChimeraQueryIdMismatchError,\n\tChimeraQueryNotCreatedError,\n\tChimeraQueryNotReadyError,\n\tChimeraQueryTrustIdMismatchError,\n\tChimeraQueryUnsuccessfulDeletionError,\n} from \"./errors.ts\";\nimport {\n\ttype ChimeraQueryEntityItemFetcherParams,\n\ttype ChimeraQueryFetchingStatable,\n\tChimeraQueryFetchingState,\n\ttype ChimeraQueryItemDeleteResponse,\n\ttype ChimeraQueryItemFetcherResponse,\n\ttype QueryEntityConfig,\n} from \"./types.ts\";\n\nexport type ChimeraItemQueryEventMap<Item extends object> = {\n\t/** Once the query is initialized */\n\tinitialized: [{ instance: ChimeraItemQuery<Item> }];\n\n\t/** Once the query data was created */\n\tselfCreated: [{ instance: ChimeraItemQuery<Item>; item: Item }];\n\n\t/** Once the query data is ready (will be followed by 'update') */\n\tready: [{ instance: ChimeraItemQuery<Item> }];\n\n\t/** Each time the query was updated */\n\tupdated: [{ instance: ChimeraItemQuery<Item>; item: Item; oldItem: Item | null }];\n\t/** Each time the query was an initiator of update */\n\tselfUpdated: [{ instance: ChimeraItemQuery<Item>; item: Item; oldItem: Item | null }];\n\n\t/** Once the query data was deleted */\n\tdeleted: [{ instance: ChimeraItemQuery<Item>; id: ChimeraEntityId }];\n\t/** Once the query was an initiator of deletion */\n\tselfDeleted: [{ instance: ChimeraItemQuery<Item>; id: ChimeraEntityId }];\n\n\t/** Each time the fetcher produces an error */\n\terror: [{ instance: ChimeraItemQuery<Item>; error: unknown }];\n};\n\nexport class ChimeraItemQuery<Item extends object>\n\textends ChimeraEventEmitter<ChimeraItemQueryEventMap<Item>>\n\timplements ChimeraQueryFetchingStatable\n{\n\t#item: Item | null;\n\t#mutable: Item | null;\n\t#state: ChimeraQueryFetchingState;\n\t#promise: ChimeraCancellablePromise | null;\n\t#lastError: unknown;\n\treadonly #params: ChimeraQueryEntityItemFetcherParams<Item>;\n\treadonly #config: QueryEntityConfig<Item, ChimeraOperatorMap>;\n\treadonly #idGetter: ChimeraIdGetterFunc<Item>;\n\n\t#emit<T extends EventNames<ChimeraItemQueryEventMap<Item>>>(\n\t\tevent: T,\n\t\targ: EventArgs<ChimeraItemQueryEventMap<Item>, T>,\n\t) {\n\t\tqueueMicrotask(() => super.emit(event, arg));\n\t}\n\n\toverride emit(): never {\n\t\tthrow new ChimeraInternalError(\"External events dispatching is not supported.\");\n\t}\n\n\t#prepareRequestParams() {\n\t\treturn {\n\t\t\tcontroller: new AbortController(),\n\t\t};\n\t}\n\n\t#setPromise<P extends ChimeraCancellablePromise>(promise: P): P {\n\t\tthis.#promise?.cancel();\n\t\tthis.#promise = promise;\n\t\treturn promise;\n\t}\n\n\t#readyItem(internalMessage?: string): Item {\n\t\tif (this.#item) return this.#item;\n\t\tthrow internalMessage\n\t\t\t? new ChimeraInternalError(internalMessage)\n\t\t\t: new ChimeraQueryNotReadyError(this.#config.name);\n\t}\n\n\t#mutableItem(internalMessage?: string): Item {\n\t\tif (this.#state === ChimeraQueryFetchingState.Deleted) {\n\t\t\tthrow internalMessage\n\t\t\t\t? new ChimeraInternalError(internalMessage)\n\t\t\t\t: new ChimeraQueryDeletedItemError(this.#config.name, this.#params.id);\n\t\t}\n\t\treturn this.#readyItem(internalMessage);\n\t}\n\n\t#setMutable(item: Item) {\n\t\tif (item != null) {\n\t\t\tif (this.#mutable) {\n\t\t\t\tdeepObjectAssign(this.#mutable as AnyObject, item as AnyObject);\n\t\t\t} else {\n\t\t\t\tthis.#mutable = deepObjectClone(item);\n\t\t\t}\n\t\t} else this.#mutable = item;\n\t}\n\n\t#resetMutable() {\n\t\tthis.#setMutable(\n\t\t\tthis.#readyItem(`Trying to reset mutable ref for empty item (${this.#config.name}[${this.#params.id}])`),\n\t\t);\n\t}\n\n\t#setItem(item: Item) {\n\t\t!this.#item && this.#emit(\"ready\", { instance: this });\n\t\tconst oldItem = this.#item;\n\t\tthis.#item = item;\n\t\tthis.#resetMutable();\n\t\tthis.#emit(\"updated\", { instance: this, item, oldItem });\n\t}\n\n\t#setNewItem(item: Item) {\n\t\tdeepObjectFreeze(item);\n\t\tconst oldItem = this.#item;\n\t\tthis.#setItem(item);\n\t\tthis.#emit(\"selfUpdated\", { instance: this, item, oldItem });\n\t}\n\n\t#deleteItem() {\n\t\tthis.#state = ChimeraQueryFetchingState.Deleted;\n\t\tthis.#emit(\"deleted\", { id: this.#params.id, instance: this });\n\t}\n\n\t#setError(error: unknown, source: ChimeraQueryError): never {\n\t\tthis.#state = this.#item ? ChimeraQueryFetchingState.ReErrored : ChimeraQueryFetchingState.Errored;\n\t\tthis.#lastError = error;\n\t\tthis.#emit(\"error\", { error, instance: this });\n\t\tthrow source;\n\t}\n\n\t#watchPromise(\n\t\tpromise: Promise<ChimeraQueryItemFetcherResponse<Item>>,\n\t\tcontroller: AbortController,\n\t): ChimeraCancellablePromise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\treturn makeCancellablePromise(\n\t\t\tpromise\n\t\t\t\t.then(({ data }) => {\n\t\t\t\t\tif (this.#config.trustQuery && !this.#config.devMode) {\n\t\t\t\t\t\tthis.#setNewItem(data);\n\t\t\t\t\t\tthis.#state = ChimeraQueryFetchingState.Fetched;\n\t\t\t\t\t\treturn { data };\n\t\t\t\t\t}\n\n\t\t\t\t\tconst localId = this.#params.id;\n\t\t\t\t\tconst newId = this.#idGetter(data);\n\n\t\t\t\t\tif (localId === newId || this.#state === ChimeraQueryFetchingState.Creating) {\n\t\t\t\t\t\tthis.#setNewItem(data);\n\t\t\t\t\t\tif (this.#state === ChimeraQueryFetchingState.Creating) {\n\t\t\t\t\t\t\tthis.#emit(\"selfCreated\", { instance: this, item: data });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#state = ChimeraQueryFetchingState.Fetched;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.#config.devMode &&\n\t\t\t\t\t\t\tthis.#config.trustQuery &&\n\t\t\t\t\t\t\tconsole.warn(new ChimeraQueryTrustIdMismatchError(this.#config.name, localId, newId));\n\n\t\t\t\t\t\tif (!this.#config.trustQuery) {\n\t\t\t\t\t\t\tthrow new ChimeraQueryTrustIdMismatchError(this.#config.name, localId, newId);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#setNewItem(data);\n\t\t\t\t\t\tthis.#params.id = newId;\n\t\t\t\t\t\tthis.#state = ChimeraQueryFetchingState.Fetched;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn { data };\n\t\t\t\t})\n\t\t\t\t.catch((error) => this.#setError(error, new ChimeraQueryFetchingError(this.#config.name, error))),\n\t\t\tcontroller,\n\t\t);\n\t}\n\n\t#updateItem(newItem: Item): Promise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\tconst newId = this.#idGetter(newItem);\n\t\tconst oldId = this.#idGetter(\n\t\t\tthis.#readyItem(`Trying to update not ready item (${this.#config.name}[${this.#params.id}])`),\n\t\t);\n\t\tif (newId !== oldId && !this.#config.trustQuery) {\n\t\t\tthis.#resetMutable();\n\t\t\tthrow new ChimeraQueryIdMismatchError(this.#config.name, oldId, newId);\n\t\t}\n\n\t\tthis.#state = ChimeraQueryFetchingState.Updating;\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#setPromise(\n\t\t\tthis.#watchPromise(\n\t\t\t\tmakeCancellablePromise(this.#config.itemUpdater(newItem, { signal: controller.signal }), controller),\n\t\t\t\tcontroller,\n\t\t\t),\n\t\t);\n\t}\n\n\t#requestDelete(): Promise<ChimeraQueryItemDeleteResponse> {\n\t\tthis.#state = ChimeraQueryFetchingState.Deleting;\n\t\tconst { controller } = this.#prepareRequestParams();\n\n\t\treturn this.#setPromise(\n\t\t\tmakeCancellablePromise(\n\t\t\t\tmakeCancellablePromise(\n\t\t\t\t\tthis.#config.itemDeleter(this.#params.id, { signal: controller.signal }),\n\t\t\t\t\tcontroller,\n\t\t\t\t).then(\n\t\t\t\t\t({ result }) => {\n\t\t\t\t\t\tconst { id, success } = result;\n\t\t\t\t\t\tif (this.#config.trustQuery && !this.#config.devMode && success) {\n\t\t\t\t\t\t\tthis.#deleteItem();\n\t\t\t\t\t\t\treturn { result };\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst localId = this.#params.id;\n\n\t\t\t\t\t\tif (localId !== id) {\n\t\t\t\t\t\t\tthis.#config.devMode &&\n\t\t\t\t\t\t\t\tthis.#config.trustQuery &&\n\t\t\t\t\t\t\t\tconsole.warn(new ChimeraQueryTrustIdMismatchError(this.#config.name, localId, id));\n\n\t\t\t\t\t\t\tif (!this.#config.trustQuery) throw new ChimeraQueryTrustIdMismatchError(this.#config.name, localId, id);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (success) {\n\t\t\t\t\t\t\tthis.#deleteItem();\n\t\t\t\t\t\t\tthis.#emit(\"selfDeleted\", { id, instance: this });\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst error = new ChimeraQueryUnsuccessfulDeletionError(this.#config.name, this.#params.id);\n\t\t\t\t\t\t\tthis.#state = ChimeraQueryFetchingState.ReErrored;\n\t\t\t\t\t\t\tthis.#lastError = error;\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn { result };\n\t\t\t\t\t},\n\t\t\t\t\t(error) => this.#setError(error, new ChimeraQueryDeletingError(this.#config.name, error)),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t}\n\n\tconstructor(\n\t\tconfig: QueryEntityConfig<Item, ChimeraOperatorMap>,\n\t\tparams: ChimeraQueryEntityItemFetcherParams<Item>,\n\t\texistingItem: Item | null,\n\t\ttoCreateItem: DeepPartial<Item> | null,\n\t) {\n\t\tsuper();\n\n\t\tthis.#config = config;\n\t\tthis.#idGetter = config.idGetter;\n\t\tthis.#params = params;\n\t\tthis.#promise = null;\n\t\tthis.#item = null;\n\t\tthis.#mutable = null;\n\t\tthis.#state = ChimeraQueryFetchingState.Initialized;\n\n\t\tif (existingItem) {\n\t\t\tconst item = existingItem;\n\n\t\t\tthis.#setItem(item);\n\n\t\t\tif (config.devMode && this.#idGetter(item) !== params.id) {\n\t\t\t\tthis.#state = ChimeraQueryFetchingState.Errored;\n\t\t\t\tthrow new ChimeraInternalError(\n\t\t\t\t\t`Invalid item query [id] (changed from \"${params.id}\" to \"${this.#idGetter(item)}\")`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.#state = ChimeraQueryFetchingState.Prefetched;\n\t\t} else if (toCreateItem) {\n\t\t\tthis.#state = ChimeraQueryFetchingState.Creating;\n\t\t\tconst { controller } = this.#prepareRequestParams();\n\t\t\tthis.#setPromise(\n\t\t\t\tthis.#watchPromise(\n\t\t\t\t\tmakeCancellablePromise(config.itemCreator(toCreateItem, { signal: controller.signal }), controller).then(\n\t\t\t\t\t\t({ data }) => {\n\t\t\t\t\t\t\tthis.#params.id = this.#idGetter(data);\n\t\t\t\t\t\t\treturn { data };\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t\tcontroller,\n\t\t\t\t),\n\t\t\t);\n\t\t} else {\n\t\t\tthis.#state = ChimeraQueryFetchingState.Fetching;\n\t\t\tconst { controller } = this.#prepareRequestParams();\n\t\t\tthis.#setPromise(\n\t\t\t\tthis.#watchPromise(\n\t\t\t\t\tmakeCancellablePromise(config.itemFetcher(params, { signal: controller.signal }), controller),\n\t\t\t\t\tcontroller,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tthis.#emit(\"initialized\", { instance: this });\n\t}\n\n\tget [ChimeraGetParamsSym](): ChimeraQueryEntityItemFetcherParams<Item> {\n\t\treturn this.#params;\n\t}\n\n\t[ChimeraSetOneSym](item: Item) {\n\t\tthis.#setItem(item);\n\t\t!this.inProgress && (this.#state = ChimeraQueryFetchingState.Actualized);\n\t}\n\n\t[ChimeraDeleteOneSym](id: ChimeraEntityId) {\n\t\tif (id === this.#params.id) {\n\t\t\tthis.#promise?.cancel();\n\t\t\tthis.#promise = null;\n\t\t\tthis.#deleteItem();\n\t\t}\n\t}\n\n\tget state(): ChimeraQueryFetchingState {\n\t\treturn this.#state;\n\t}\n\n\tget inProgress(): boolean {\n\t\treturn IN_PROGRESS_STATES.includes(this.#state);\n\t}\n\n\tget ready(): boolean {\n\t\treturn this.#item !== null;\n\t}\n\n\tget lastError(): unknown {\n\t\treturn this.#lastError;\n\t}\n\n\tget id(): ChimeraEntityId {\n\t\treturn this.#params.id;\n\t}\n\n\t/** Return an item if it is ready, throw error otherwise */\n\tget data(): Item {\n\t\treturn this.#readyItem();\n\t}\n\n\t/** Get ref for an item that can be changed as a regular object. To send changes to updater, use <commit> method */\n\tget mutable(): Item {\n\t\tthis.#readyItem();\n\t\treturn this.#mutable as Item;\n\t}\n\n\tget promise(): Promise<unknown> | null {\n\t\treturn this.#promise;\n\t}\n\n\t/**\n\t * Wait for the current progress process to complete (both success or error)\n\t */\n\tget progress(): Promise<void> {\n\t\treturn new Promise((res) => {\n\t\t\tconst resolve = () => queueMicrotask(() => res());\n\t\t\tif (this.#promise) {\n\t\t\t\tthis.#promise.then(resolve, resolve);\n\t\t\t\tthis.#promise.cancelled(() => this.progress.then(resolve, resolve));\n\t\t\t} else resolve();\n\t\t});\n\t}\n\n\t/**\n\t * Wait for the current progress process to complete, throw an error if it fails\n\t */\n\tget result(): Promise<void> {\n\t\treturn new Promise((res, rej) => {\n\t\t\tconst resolve = () => queueMicrotask(() => res());\n\t\t\tif (this.#promise) {\n\t\t\t\tthis.#promise.then(resolve, rej);\n\t\t\t\tthis.#promise.cancelled(() => (this.#promise ? this.result.then(res, rej) : rej(\"cancelled\")));\n\t\t\t} else resolve();\n\t\t});\n\t}\n\n\t/**\n\t * Trigger refetch, return existing refetch promise if already running\n\t * @param force If true cancels any running process and starts a new one\n\t * @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress\n\t */\n\trefetch(force = false): Promise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\tif (\n\t\t\t!force &&\n\t\t\tthis.#promise &&\n\t\t\t[ChimeraQueryFetchingState.Fetching, ChimeraQueryFetchingState.Refetching].includes(this.#state)\n\t\t)\n\t\t\treturn this.#promise as Promise<ChimeraQueryItemFetcherResponse<Item>>;\n\n\t\tif (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#config.name);\n\n\t\tif (!force && [ChimeraQueryFetchingState.Updating, ChimeraQueryFetchingState.Deleting].includes(this.#state))\n\t\t\tthrow new ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);\n\n\t\tthis.#state = ChimeraQueryFetchingState.Refetching;\n\t\tconst { controller } = this.#prepareRequestParams();\n\t\treturn this.#setPromise(\n\t\t\tthis.#watchPromise(\n\t\t\t\tmakeCancellablePromise(this.#config.itemFetcher(this.#params, { signal: controller.signal }), controller),\n\t\t\t\tcontroller,\n\t\t\t),\n\t\t);\n\t}\n\n\t/**\n\t * Update item using updated copy, a running update process will be cancelled\n\t * @param newItem new item to replace existing\n\t * @param force if true cancels any running process including fetch and delete\n\t * @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress\n\t */\n\tupdate(newItem: Item, force = false): Promise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\tif (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#config.name);\n\n\t\tif (\n\t\t\t!force &&\n\t\t\t[\n\t\t\t\tChimeraQueryFetchingState.Fetching,\n\t\t\t\tChimeraQueryFetchingState.Refetching,\n\t\t\t\tChimeraQueryFetchingState.Deleting,\n\t\t\t].includes(this.#state)\n\t\t)\n\t\t\tthrow new ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);\n\n\t\tthis.#mutableItem();\n\t\treturn this.#updateItem(newItem);\n\t}\n\n\t/**\n\t * Update item using function with draft item as argument\n\t * that can be used to patch item in place or return a patched value,\n\t * a running update process will be cancelled\n\t * @param mutator mutator function\n\t * @param force if true cancels any running process including fetch and delete\n\t * @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress\n\t */\n\tmutate(mutator: (draft: Item) => Item, force = false): Promise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\tif (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#config.name);\n\n\t\tif (\n\t\t\t!force &&\n\t\t\t[\n\t\t\t\tChimeraQueryFetchingState.Fetching,\n\t\t\t\tChimeraQueryFetchingState.Refetching,\n\t\t\t\tChimeraQueryFetchingState.Deleting,\n\t\t\t].includes(this.#state)\n\t\t)\n\t\t\tthrow new ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);\n\n\t\tconst item = deepObjectClone(this.#mutableItem());\n\t\treturn this.#updateItem(mutator(item) ?? item);\n\t}\n\n\t/**\n\t * Commit updated value from mutable ref, a running update process will be canceled\n\t * @param force if true cancels any running process including fetch and delete\n\t * @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress\n\t */\n\tcommit(force = false): Promise<ChimeraQueryItemFetcherResponse<Item>> {\n\t\tif (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#config.name);\n\n\t\tif (\n\t\t\t!force &&\n\t\t\t[\n\t\t\t\tChimeraQueryFetchingState.Fetching,\n\t\t\t\tChimeraQueryFetchingState.Refetching,\n\t\t\t\tChimeraQueryFetchingState.Deleting,\n\t\t\t].includes(this.#state)\n\t\t)\n\t\t\tthrow new ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);\n\n\t\tthis.#mutableItem();\n\t\treturn this.#updateItem(this.#mutable as Item);\n\t}\n\n\t/**\n\t * Request to delete the value.\n\t * Local copy will still be available if it was present.\n\t * A running delete process will be canceled\n\t * @param force if true cancels any running process including fetch and update\n\t * @throws {ChimeraQueryAlreadyRunningError} If deleting or updating already in progress\n\t */\n\tdelete(force = false): Promise<ChimeraQueryItemDeleteResponse> {\n\t\tif (this.#state === ChimeraQueryFetchingState.Creating) throw new ChimeraQueryNotCreatedError(this.#config.name);\n\n\t\tif (\n\t\t\t!force &&\n\t\t\t[\n\t\t\t\tChimeraQueryFetchingState.Fetching,\n\t\t\t\tChimeraQueryFetchingState.Refetching,\n\t\t\t\tChimeraQueryFetchingState.Updating,\n\t\t\t].includes(this.#state)\n\t\t)\n\t\t\tthrow new ChimeraQueryAlreadyRunningError(this.#config.name, this.#state);\n\n\t\treturn this.#requestDelete();\n\t}\n\n\ttoJSON() {\n\t\treturn this.#readyItem();\n\t}\n\n\toverride toString(): string {\n\t\treturn `${this.#readyItem()}`;\n\t}\n}\n","import type { EventArgs, EventNames } from \"../ChimeraEventEmitter\";\nimport { ChimeraEventEmitter } from \"../ChimeraEventEmitter\";\nimport { ChimeraInternalError } from \"../errors.ts\";\n\nexport type ChimeraWeakValueMapEventMap<K, V extends object> = {\n\t/** An item was added to the map */\n\tset: { key: K; value: V; instance: ChimeraWeakValueMap<K, V> };\n\n\t/** An item was removed from the map */\n\tdelete: { key: K; value: V; instance: ChimeraWeakValueMap<K, V> };\n\n\t/** Weak reference was automatically collected */\n\tfinalize: { key: K; instance: ChimeraWeakValueMap<K, V> };\n\n\t/** All items were removed from the map */\n\tclear: { instance: ChimeraWeakValueMap<K, V> };\n};\n\nexport class ChimeraWeakValueMap<K, V extends object> extends ChimeraEventEmitter<ChimeraWeakValueMapEventMap<K, V>> {\n\treadonly #map: Map<K, WeakRef<V>>;\n\treadonly #registry: FinalizationRegistry<K>;\n\t#cleanupScheduled = false;\n\n\t#emit<T extends EventNames<ChimeraWeakValueMapEventMap<K, V>>>(\n\t\tevent: T,\n\t\targ: EventArgs<ChimeraWeakValueMapEventMap<K, V>, T>,\n\t) {\n\t\tqueueMicrotask(() => super.emit(event, arg));\n\t}\n\n\toverride emit(): never {\n\t\tthrow new ChimeraInternalError(\"External events dispatching is not supported.\");\n\t}\n\n\t#scheduleCleanup() {\n\t\tif (this.#cleanupScheduled) return;\n\t\tthis.#cleanupScheduled = true;\n\n\t\tconst scheduler =\n\t\t\ttypeof requestIdleCallback !== \"undefined\" ? requestIdleCallback : (cb: () => void) => setTimeout(cb, 0);\n\n\t\tscheduler(() => {\n\t\t\tthis.#cleanup();\n\t\t\tthis.#cleanupScheduled = false;\n\t\t});\n\t}\n\n\t#cleanup() {\n\t\tfor (const [key, weakRef] of this.#map.entries()) {\n\t\t\tif (weakRef.deref() === undefined) {\n\t\t\t\tthis.#map.delete(key);\n\t\t\t\tthis.#emit(\"finalize\", { instance: this, key });\n\t\t\t}\n\t\t}\n\t}\n\n\tconstructor(values?: readonly (readonly [K, V])[] | null) {\n\t\tsuper();\n\n\t\tthis.#registry = new FinalizationRegistry<K>((key) => {\n\t\t\tconst weakRef = this.#map.get(key);\n\t\t\tif (weakRef && weakRef.deref() === undefined) {\n\t\t\t\tthis.#map.delete(key);\n\t\t\t\tthis.#emit(\"finalize\", { instance: this, key });\n\t\t\t}\n\t\t});\n\n\t\tthis.#map = new Map(\n\t\t\tvalues\n\t\t\t\t? values.map(([k, v]): [K, WeakRef<V>] => {\n\t\t\t\t\t\tthis.#registry.register(v, k, v);\n\t\t\t\t\t\treturn [k, new WeakRef(v)];\n\t\t\t\t\t})\n\t\t\t\t: null,\n\t\t);\n\t}\n\n\tset(key: K, value: V): this {\n\t\tconst existingRef = this.#map.get(key);\n\t\tif (existingRef) {\n\t\t\tconst existingValue = existingRef.deref();\n\t\t\tif (existingValue) {\n\t\t\t\tthis.#registry.unregister(existingValue);\n\t\t\t}\n\t\t}\n\n\t\tthis.#registry.register(value, key, value);\n\t\tthis.#map.set(key, new WeakRef(value));\n\t\tthis.#emit(\"set\", { instance: this, key, value });\n\t\treturn this;\n\t}\n\n\tdelete(key: K): boolean {\n\t\tif (!this.#map.has(key)) return false;\n\t\tconst weakRef = this.#map.get(key);\n\t\tconst value = weakRef?.deref();\n\n\t\tif (value === undefined) {\n\t\t\tthis.#map.delete(key);\n\t\t\tthis.#emit(\"finalize\", { instance: this, key });\n\t\t\treturn true;\n\t\t}\n\n\t\tthis.#map.delete(key);\n\t\tthis.#registry.unregister(value);\n\t\tthis.#emit(\"delete\", { instance: this, key, value });\n\t\treturn true;\n\t}\n\n\thas(key: K): boolean {\n\t\tconst weakRef = this.#map.get(key);\n\t\tconst value = weakRef?.deref();\n\n\t\tif (value === undefined && weakRef) {\n\t\t\tthis.#map.delete(key);\n\t\t\tthis.#emit(\"finalize\", { instance: this, key });\n\t\t\tthis.#scheduleCleanup();\n\t\t}\n\n\t\treturn value !== undefined;\n\t}\n\n\tforEach(callbackFn: (value: V, key: K, map: ChimeraWeakValueMap<K, V>) => void, thisArg?: any): void {\n\t\tthis.#map.forEach((weakRef, k) => {\n\t\t\tconst value = weakRef.deref();\n\t\t\tif (value !== undefined) {\n\t\t\t\tcallbackFn.call(thisArg, value, k, this);\n\t\t\t} else {\n\t\t\t\tthis.#map.delete(k);\n\t\t\t\tthis.#emit(\"finalize\", { instance: this, key: k });\n\t\t\t}\n\t\t});\n\n\t\tif (this.#map.size > 0) {\n\t\t\tthis.#scheduleCleanup();\n\t\t}\n\t}\n\n\tget(key: K): V | undefined {\n\t\tconst weakRef = this.#map.get(key);\n\t\tconst value = weakRef?.deref();\n\n\t\tif (value === undefined && weakRef) {\n\t\t\tthis.#map.delete(key);\n\t\t\tthis.#emit(\"finalize\", { instance: this, key });\n\t\t\tthis.#scheduleCleanup();\n\t\t}\n\n\t\treturn value;\n\t}\n\n\tget size(): number {\n\t\tthis.#cleanup();\n\t\treturn this.#map.size;\n\t}\n\n\t*entries(): IterableIterator<[K, V]> {\n\t\tfor (const [k, weakRef] of this.#map.entries()) {\n\t\t\tconst value = weakRef.deref();\n\t\t\tif (value !== undefined) {\n\t\t\t\tyield [k, value];\n\t\t\t} else {\n\t\t\t\tthis.#map.delete(k);\n\t\t\t\tthis.#emit(\"finalize\", { instance: this, key: k });\n\t\t\t}\n\t\t}\n\n\t\tif (this.#map.size > 0) {\n\t\t\tthis.#scheduleCleanup();\n\t\t}\n\t}\n\n\t*keys(): IterableIterator<K> {\n\t\tfor (const [k, weakRef] of this.#map.entries()) {\n\t\t\tif (weakRef.deref() !== undefined) {\n\t\t\t\tyield k;\n\t\t\t} else {\n\t\t\t\tthis.#map.delete(k);\n\t\t\t\tthis.#emit(\"finalize\", { instance: this, key: k });\n\t\t\t}\n\t\t}\n\n\t\tif (this.#map.size > 0) {\n\t\t\tthis.#scheduleCleanup();\n\t\t}\n\t}\n\n\t*values(): IterableIterator<V> {\n\t\tfor (const weakRef of this.#map.values()) {\n\t\t\tconst value = weakRef.deref();\n\t\t\tif (value !== undefined) {\n\t\t\t\tyield value;\n\t\t\t}\n\t\t}\n\n\t\tthis.#cleanup();\n\t}\n\n\t*[Symbol.iterator](): IterableIterator<[K, V]> {\n\t\tyield* this.entries();\n\t}\n\n\tclear(): void {\n\t\tfor (const weakRef of this.#map.values()) {\n\t\t\tconst value = weakRef.deref();\n\t\t\tif (value !== undefined) {\n\t\t\t\tthis.#registry.unregister(value);\n\t\t\t}\n\t\t}\n\n\t\tthis.#map.clear();\n\t\tthis.#emit(\"clear\", { instance: this });\n\t}\n\n\tcleanup(): void {\n\t\tthis.#cleanup();\n\t}\n\n\tget rawSize(): number {\n\t\treturn this.#map.size;\n\t}\n}\n","import { compileFilter, isFilterSubset, simplifyFilter } from \"../filter/filter.ts\";\nimport type { ChimeraFilterConfig, ChimeraOperatorMap, ChimeraSimplifiedFilter } from \"../filter/types.ts\";\nimport { buildComparator, simplifyOrderBy } from \"../order/order.ts\";\nimport type { ChimeraOrderConfig } from \"../order/types.ts\";\nimport { ChimeraCollectionQuery } from \"../query/ChimeraCollectionQuery.ts\";\nimport { ChimeraItemQuery } from \"../query/ChimeraItemQuery.ts\";\nimport {\n\tChimeraDeleteManySym,\n\tChimeraDeleteOneSym,\n\tChimeraGetParamsSym,\n\tChimeraSetManySym,\n\tChimeraSetOneSym,\n\tChimeraUpdateMixedSym,\n} from \"../query/constants.ts\";\nimport type { ChimeraQueryEntityCollectionFetcherParams, QueryEntityConfig } from \"../query/types.ts\";\nimport type { EventArgs, EventNames } from \"../shared/ChimeraEventEmitter\";\nimport { ChimeraEventEmitter } from \"../shared/ChimeraEventEmitter\";\nimport { ChimeraWeakValueMap } from \"../shared/ChimeraWeakValueMap\";\nimport { ChimeraInternalError } from \"../shared/errors.ts\";\nimport type { ChimeraEntityId, ChimeraIdGetterFunc, DeepPartial } from \"../shared/types.ts\";\nimport type { ChimeraCollectionParams } from \"./types.ts\";\n\nexport type ChimeraEntityRepositoryEventMap<Item extends object, OperatorsMap extends ChimeraOperatorMap> = {\n\t/** Once the repository is initialized */\n\tinitialized: { instance: ChimeraEntityRepository<Item, OperatorsMap> };\n\n\t/** Each time item added */\n\titemAdded: [{ instance: ChimeraEntityRepository<Item, OperatorsMap>; item: Item }];\n\n\t/** Each time many items updated */\n\tupdated: [{ instance: ChimeraEntityRepository<Item, OperatorsMap>; items: Item[] }];\n\t/** Each time item updated */\n\titemUpdated: [{ instance: ChimeraEntityRepository<Item, OperatorsMap>; item: Item; oldItem: Item | null }];\n\n\t/** Each time many items deleted */\n\tdeleted: [{ instance: ChimeraEntityRepository<Item, OperatorsMap>; ids: ChimeraEntityId[] }];\n\t/** Each time item deleted */\n\titemDeleted: [{ instance: ChimeraEntityRepository<Item, OperatorsMap>; oldItem: Item | null }];\n};\n\ntype SkipParams<Item extends object, OperatorsMap extends ChimeraOperatorMap> = {\n\titem?: ChimeraItemQuery<Item>;\n\tcollection?: ChimeraCollectionQuery<Item, OperatorsMap>;\n};\n\nexport class ChimeraEntityRepository<\n\tItem extends object,\n\tOperatorsMap extends ChimeraOperatorMap,\n> extends ChimeraEventEmitter<ChimeraEntityRepositoryEventMap<Item, OperatorsMap>> {\n\treadonly #entityConfig: QueryEntityConfig<Item, OperatorsMap>;\n\treadonly #filterConfig: Required<ChimeraFilterConfig<OperatorsMap>>;\n\treadonly #orderConfig: Required<ChimeraOrderConfig>;\n\treadonly #idGetter: ChimeraIdGetterFunc<Item>;\n\n\treadonly #itemsMap: ChimeraWeakValueMap<ChimeraEntityId, Item>;\n\n\treadonly #collectionQueryMap: ChimeraWeakValueMap<string, ChimeraCollectionQuery<Item, OperatorsMap>>;\n\treadonly #itemQueryMap: ChimeraWeakValueMap<ChimeraEntityId, ChimeraItemQuery<Item>>;\n\n\t#emit<T extends EventNames<ChimeraEntityRepositoryEventMap<Item, OperatorsMap>>>(\n\t\tevent: T,\n\t\targ: EventArgs<ChimeraEntityRepositoryEventMap<Item, OperatorsMap>, T>,\n\t) {\n\t\tqueueMicrotask(() => super.emit(event, arg));\n\t}\n\n\toverride emit(): never {\n\t\tthrow new ChimeraInternalError(\"External events dispatching is not supported.\");\n\t}\n\n\t#registerUpdate(item: Item, skipItem?: ChimeraItemQuery<Item>) {\n\t\tconst id = this.#idGetter(item);\n\t\tconst oldItem = this.#itemsMap.get(id);\n\t\tthis.#itemsMap.set(id, item);\n\n\t\tconst itemQuery = this.#itemQueryMap.get(id);\n\t\titemQuery && skipItem !== itemQuery && itemQuery[ChimeraSetOneSym](item);\n\n\t\t!oldItem && this.#emit(\"itemAdded\", { instance: this, item });\n\t\tthis.#emit(\"itemUpdated\", { instance: this, item, oldItem: oldItem ?? null });\n\t}\n\t#registerDelete(id: ChimeraEntityId, skipItem?: ChimeraItemQuery<Item>) {\n\t\tconst oldItem = this.#itemsMap.get(id);\n\t\tif (!oldItem) return;\n\t\tthis.#itemsMap.delete(id);\n\n\t\tconst itemQuery = this.#itemQueryMap.get(id);\n\t\titemQuery && skipItem !== itemQuery && itemQuery[ChimeraDeleteOneSym](id);\n\n\t\tthis.#emit(\"itemDeleted\", { instance: this, oldItem: oldItem ?? null });\n\t}\n\n\t#propagateUpdateOne(item: Item, { item: skipItem, collection: skipCollection }: SkipParams<Item, OperatorsMap> = {}) {\n\t\tthis.#registerUpdate(item, skipItem);\n\t\tfor (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraSetOneSym](item);\n\t}\n\t#propagateDeleteOne(\n\t\tid: ChimeraEntityId,\n\t\t{ item: skipItem, collection: skipCollection }: SkipParams<Item, OperatorsMap> = {},\n\t) {\n\t\tthis.#registerDelete(id, skipItem);\n\t\tfor (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraDeleteOneSym](id);\n\t}\n\n\t#propagateUpdateMany(\n\t\titems: Item[],\n\t\t{ item: skipItem, collection: skipCollection }: SkipParams<Item, OperatorsMap> = {},\n\t) {\n\t\tfor (const item of items) this.#registerUpdate(item, skipItem);\n\t\tthis.#emit(\"updated\", { instance: this, items });\n\t\tfor (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraSetManySym](items);\n\t}\n\n\t#propagateDeleteMany(\n\t\tids: ChimeraEntityId[],\n\t\t{ item: skipItem, collection: skipCollection }: SkipParams<Item, OperatorsMap> = {},\n\t) {\n\t\tfor (const id of ids) this.#registerDelete(id, skipItem);\n\t\tthis.#emit(\"deleted\", { ids, instance: this });\n\t\tfor (const c of this.#collectionQueryMap.values()) c !== skipCollection && c[ChimeraDeleteManySym](ids);\n\t}\n\n\t#itemUpdateHandler(query: ChimeraItemQuery<Item>, item: Item) {\n\t\tthis.#propagateUpdateOne(item, { item: query });\n\t}\n\t#itemDeleteHandler(query: ChimeraItemQuery<Item>, id: ChimeraEntityId) {\n\t\tthis.#itemQueryMap.delete(id);\n\t\tthis.#propagateDeleteOne(id, { item: query });\n\t}\n\t#prepareItemQuery(query: ChimeraItemQuery<Item>): ChimeraItemQuery<Item> {\n\t\tif (query.id !== \"\") this.#itemQueryMap.set(query.id, query);\n\t\tquery.on(\"selfCreated\", ({ instance }) => this.#itemQueryMap.set(instance.id, instance));\n\t\tquery.on(\"selfUpdated\", ({ instance, item }) => this.#itemUpdateHandler(instance, item));\n\t\tquery.on(\"selfDeleted\", ({ instance, id }) => this.#itemDeleteHandler(instance, id));\n\t\treturn query;\n\t}\n\n\t#simplifyCollectionParams(\n\t\tparams: ChimeraCollectionParams<OperatorsMap, Item>,\n\t): ChimeraQueryEntityCollectionFetcherParams<Item, OperatorsMap> {\n\t\treturn {\n\t\t\tfilter: simplifyFilter(params.filter),\n\t\t\tmeta: params.meta,\n\t\t\torder: simplifyOrderBy(params.order),\n\t\t};\n\t}\n\t#getCollectionKey({ order, filter }: ChimeraQueryEntityCollectionFetcherParams<Item, OperatorsMap>): string {\n\t\treturn `ORDER<${order ? this.#orderConfig.getKey(order) : \"\"}>\\nFILTER<${filter ? this.#filterConfig.getFilterKey(filter) : \"\"}>`;\n\t}\n\n\t#collectionUpdateHandler(query: ChimeraCollectionQuery<Item, OperatorsMap>, items: Item[]) {\n\t\tthis.#propagateUpdateMany(items, { collection: query });\n\t}\n\t#collectionCreateHandler(query: ChimeraCollectionQuery<Item, OperatorsMap>, item: Item) {\n\t\tthis.#propagateUpdateOne(item, { collection: query });\n\t}\n\t#collectionItemUpdated(query: ChimeraCollectionQuery<Item, OperatorsMap>, item: Item) {\n\t\tthis.#propagateUpdateOne(item, { collection: query });\n\t}\n\t#collectionItemDeleted(query: ChimeraCollectionQuery<Item, OperatorsMap>, id: ChimeraEntityId) {\n\t\tthis.#propagateDeleteOne(id, { collection: query });\n\t}\n\n\t#prepareCollectionQuery(\n\t\tquery: ChimeraCollectionQuery<Item, OperatorsMap>,\n\t): ChimeraCollectionQuery<Item, OperatorsMap> {\n\t\tthis.#collectionQueryMap.set(this.#getCollectionKey(query[ChimeraGetParamsSym]), query);\n\t\tquery.on(\"selfUpdated\", ({ instance, items }) => this.#collectionUpdateHandler(instance, items));\n\t\tquery.on(\"selfItemCreated\", ({ instance, item }) => this.#collectionCreateHandler(instance, item));\n\t\tquery.on(\"selfItemUpdated\", ({ instance, item }) => this.#collectionItemUpdated(instance, item));\n\t\tquery.on(\"selfItemDeleted\", ({ instance, id }) => this.#collectionItemDeleted(instance, id));\n\t\treturn query;\n\t}\n\n\t#getParentQuery(\n\t\tfilter: ChimeraSimplifiedFilter<OperatorsMap, keyof Item & string>,\n\t): ChimeraCollectionQuery<Item, OperatorsMap> | null {\n\t\tfor (const q of this.#collectionQueryMap.values())\n\t\t\tif (q.ready && isFilterSubset(q[ChimeraGetParamsSym].filter, filter, this.#filterConfig.getOperatorKey)) return q;\n\t\treturn null;\n\t}\n\n\tconstructor(\n\t\tconfig: QueryEntityConfig<Item, OperatorsMap>,\n\t\tfilterConfig: Required<ChimeraFilterConfig<OperatorsMap>>,\n\t\torderConfig: Required<ChimeraOrderConfig>,\n\t) {\n\t\tsuper();\n\n\t\tthis.#entityConfig = config;\n\t\tthis.#filterConfig = filterConfig;\n\t\tthis.#orderConfig = orderConfig;\n\t\tthis.#idGetter = config.idGetter;\n\n\t\tthis.#itemsMap = new ChimeraWeakValueMap();\n\t\tthis.#collectionQueryMap = new ChimeraWeakValueMap();\n\t\tthis.#itemQueryMap = new ChimeraWeakValueMap();\n\n\t\tthis.#emit(\"initialized\", { instance: this });\n\t}\n\n\t[ChimeraSetOneSym](item: Item) {\n\t\tthis.#propagateUpdateOne(item);\n\t}\n\t[ChimeraDeleteOneSym](id: ChimeraEntityId) {\n\t\tthis.#propagateDeleteOne(id);\n\t}\n\n\t[ChimeraSetManySym](items: Item[]) {\n\t\tthis.#propagateUpdateMany(items);\n\t}\n\n\t[ChimeraDeleteManySym](ids: ChimeraEntityId[]) {\n\t\tthis.#propagateDeleteMany(ids);\n\t}\n\n\t[ChimeraUpdateMixedSym](toAdd: Item[], toDelete: ChimeraEntityId[]) {\n\t\tthis.#propagateUpdateMany(toAdd);\n\t\tthis.#propagateDeleteMany(toDelete);\n\t}\n\n\tcreateItem(item: DeepPartial<Item>, meta?: any): ChimeraItemQuery<Item> {\n\t\treturn this.#prepareItemQuery(new ChimeraItemQuery(this.#entityConfig, { id: \"\", meta }, null, item));\n\t}\n\n\tgetItem(id: ChimeraEntityId, meta?: any): ChimeraItemQuery<Item> {\n\t\tconst query = this.#itemQueryMap.get(id);\n\t\tif (query) return query;\n\n\t\treturn this.#prepareItemQuery(\n\t\t\tnew ChimeraItemQuery(this.#entityConfig, { id, meta }, this.#itemsMap.get(id) ?? null, null),\n\t\t);\n\t}\n\n\tgetCollection(params: ChimeraCollectionParams<OperatorsMap, Item>): ChimeraCollectionQuery<Item, OperatorsMap> {\n\t\tconst simplifiedParams = this.#simplifyCollectionParams(params);\n\t\tconst key = this.#getCollectionKey(simplifiedParams);\n\t\tconst query = this.#collectionQueryMap.get(key);\n\t\tif (query) return query;\n\n\t\treturn this.#prepareCollectionQuery(\n\t\t\tnew ChimeraCollectionQuery(\n\t\t\t\tthis.#entityConfig,\n\t\t\t\tsimplifiedParams,\n\t\t\t\tthis.#getParentQuery(simplifiedParams.filter),\n\t\t\t\tbuildComparator(this.#orderConfig.primitiveComparator, params.order),\n\t\t\t\tcompileFilter(this.#filterConfig, params.filter),\n\t\t\t\tfalse,\n\t\t\t),\n\t\t);\n\t}\n}\n","import { chimeraDefaultDebugConfig } from \"../debug/defaults.ts\";\nimport type { ChimeraDebugConfig } from \"../debug/types.ts\";\nimport { chimeraDefaultFilterConfig, type chimeraDefaultFilterOperators } from \"../filter/defaults.ts\";\nimport type { ChimeraFilterConfig, ChimeraOperatorMap } from \"../filter/types.ts\";\nimport { chimeraDefaultOrderConfig } from \"../order/defaults.ts\";\nimport type { ChimeraOrderConfig } from \"../order/types.ts\";\nimport {\n\tChimeraDeleteManySym,\n\tChimeraDeleteOneSym,\n\tChimeraSetManySym,\n\tChimeraSetOneSym,\n\tChimeraUpdateMixedSym,\n} from \"../query/constants.ts\";\nimport { chimeraDefaultQueryConfig } from \"../query/defaults.ts\";\nimport type {\n\tChimeraQueryDefaultEntityIdGetter,\n\tChimeraQueryDefaultsConfig,\n\tChimeraQueryEntityConfig,\n\tChimeraQueryEntityIdGetter,\n\tQueryEntityConfig,\n} from \"../query/types.ts\";\nimport { ChimeraInternalError } from \"../shared\";\nimport { ChimeraEventEmitter, type EventArgs, type EventNames } from \"../shared/ChimeraEventEmitter\";\nimport { deepObjectAssign, deepObjectClone, deepObjectFreeze } from \"../shared/shared.ts\";\nimport type { ChimeraEntityId, ChimeraEntityMap, ChimeraIdGetterFunc, StrKeys } from \"../shared/types.ts\";\nimport { ChimeraEntityRepository } from \"./ChimeraEntityRepository.ts\";\nimport type { ChimeraStoreConfig, RepositoryConfigMap, RepositoryMap } from \"./types.ts\";\n\nconst resolveIdGetter = <EntityMap extends ChimeraEntityMap>(\n\tkey: string,\n\tdef: ChimeraQueryDefaultEntityIdGetter<EntityMap>,\n\tval?: ChimeraQueryEntityIdGetter<object>,\n): ChimeraIdGetterFunc<object> => {\n\tif (val) return typeof val === \"function\" ? val : (v) => v[val as keyof typeof v] as unknown as ChimeraEntityId;\n\treturn typeof def === \"function\"\n\t\t? (v) => def(key, v as keyof typeof def)\n\t\t: (v) => v[def as keyof typeof v] as unknown as ChimeraEntityId;\n};\n\ntype ItemEvent<EntityMap extends ChimeraEntityMap> = {\n\t[K in StrKeys<EntityMap>]: {\n\t\tentityName: K;\n\t\titem: EntityMap[K];\n\t};\n}[StrKeys<EntityMap>];\n\ntype ManyItemEvent<EntityMap extends ChimeraEntityMap> = {\n\t[K in StrKeys<EntityMap>]: {\n\t\tentityName: K;\n\t\titems: EntityMap[K][];\n\t};\n}[StrKeys<EntityMap>];\n\ntype ItemDeleteEvent<EntityMap extends ChimeraEntityMap> = {\n\t[K in StrKeys<EntityMap>]: {\n\t\tentityName: K;\n\t\tid: ChimeraEntityId;\n\t};\n}[StrKeys<EntityMap>];\n\ntype ManyDeleteEvent<EntityMap extends ChimeraEntityMap> = {\n\t[K in StrKeys<EntityMap>]: {\n\t\tentityName: K;\n\t\tids: ChimeraEntityId[];\n\t};\n}[StrKeys<EntityMap>];\n\ntype RepositoryEvent<EntityMap extends ChimeraEntityMap, OperatorsMap extends ChimeraOperatorMap> = {\n\t[K in StrKeys<EntityMap>]: {\n\t\tentityName: K;\n\t\trepository: ChimeraEntityRepository<EntityMap[K], OperatorsMap>;\n\t};\n}[StrKeys<EntityMap>];\n\ntype ChimeraStoreEventMap<EntityMap extends ChimeraEntityMap, OperatorsMap extends ChimeraOperatorMap> = {\n\t/** Once the store is initialized */\n\tinitialized: [{ instance: ChimeraStore<EntityMap, OperatorsMap> }];\n\n\trepositoryInitialized: [\n\t\t{ instance: ChimeraStore<EntityMap, OperatorsMap> } & RepositoryEvent<EntityMap, OperatorsMap>,\n\t];\n\n\t/** Each time item added */\n\titemAdded: [\n\t\t{ instance: ChimeraStore<EntityMap, OperatorsMap> } & RepositoryEvent<EntityMap, OperatorsMap> &\n\t\t\tItemEvent<EntityMap>,\n\t];\n\n\t/** Each time many items updated */\n\tupdated: [\n\t\t{ instance: ChimeraStore<EntityMap, OperatorsMap> } & RepositoryEvent<EntityMap, OperatorsMap> &\n\t\t\tManyItemEvent<EntityMap>,\n\t];\n\t/** Each time item updated */\n\titemUpdated: [\n\t\t{ instance: ChimeraStore<EntityMap, OperatorsMap> } & RepositoryEvent<EntityMap, OperatorsMap> &\n\t\t\tItemEvent<EntityMap>,\n\t];\n\n\t/** Each time many items deleted */\n\tdeleted: [\n\t\t{ instance: ChimeraStore<EntityMap, OperatorsMap> } & RepositoryEvent<EntityMap, OperatorsMap> &\n\t\t\tManyDeleteEvent<EntityMap>,\n\t];\n\t/** Each time item deleted */\n\titemDeleted: [\n\t\t{ instance: ChimeraStore<EntityMap, OperatorsMap> } & RepositoryEvent<EntityMap, OperatorsMap> &\n\t\t\tItemDeleteEvent<EntityMap>,\n\t];\n};\n\nexport class ChimeraStore<\n\tEntityMap extends ChimeraEntityMap,\n\tOperatorsMap extends ChimeraOperatorMap = typeof chimeraDefaultFilterOperators,\n\tConfig extends ChimeraStoreConfig<EntityMap, OperatorsMap> = ChimeraStoreConfig<EntityMap, OperatorsMap>,\n> extends ChimeraEventEmitter<ChimeraStoreEventMap<EntityMap, OperatorsMap>> {\n\treadonly #reposMap: RepositoryMap<EntityMap, OperatorsMap>;\n\treadonly #queryConfig: RepositoryConfigMap<EntityMap, OperatorsMap>;\n\treadonly #filterConfig: Required<ChimeraFilterConfig<OperatorsMap>>;\n\treadonly #orderConfig: Required<ChimeraOrderConfig>;\n\treadonly #debugConfig: Required<ChimeraDebugConfig>;\n\treadonly #initialConfig: Config;\n\n\t#emit<T extends EventNames<ChimeraStoreEventMap<EntityMap, OperatorsMap>>>(\n\t\tevent: T,\n\t\targ: EventArgs<ChimeraStoreEventMap<EntityMap, OperatorsMap>, T>,\n\t) {\n\t\tqueueMicrotask(() => super.emit(event, arg));\n\t}\n\n\toverride emit(): never {\n\t\tthrow new ChimeraInternalError(\"External events dispatching is not supported.\");\n\t}\n\n\t#addRepository<EntityName extends StrKeys<EntityMap>>(\n\t\tentityName: EntityName,\n\t): ChimeraEntityRepository<EntityMap[EntityName], OperatorsMap> {\n\t\tconst repo = (this.#reposMap[entityName] = new ChimeraEntityRepository(\n\t\t\tthis.#queryConfig[entityName],\n\t\t\tthis.#filterConfig,\n\t\t\tthis.#orderConfig,\n\t\t));\n\n\t\trepo.once(\"initialized\", (e) =>\n\t\t\tthis.#emit(\"repositoryInitialized\", {\n\t\t\t\tentityName: entityName,\n\t\t\t\tinstance: this,\n\t\t\t\trepository: e.instance as unknown as ChimeraEntityRepository<EntityMap[StrKeys<EntityMap>], OperatorsMap>,\n\t\t\t}),\n\t\t);\n\n\t\treturn repo;\n\t}\n\n\tconstructor(config: Config) {\n\t\tsuper();\n\n\t\tthis.#initialConfig = deepObjectFreeze(deepObjectClone(config));\n\t\tconst { query: queryConfig, order: orderConfig, filter: filterConfig, debug: debugConfig } = config;\n\n\t\tthis.#filterConfig = deepObjectAssign<Required<ChimeraFilterConfig<OperatorsMap>>>(\n\t\t\tdeepObjectClone(chimeraDefaultFilterConfig),\n\t\t\tfilterConfig ?? {},\n\t\t);\n\t\tthis.#orderConfig = deepObjectAssign<Required<ChimeraOrderConfig>>(\n\t\t\tdeepObjectClone(chimeraDefaultOrderConfig),\n\t\t\torderConfig ?? {},\n\t\t);\n\t\tthis.#debugConfig = deepObjectAssign<Required<ChimeraDebugConfig>>(\n\t\t\tdeepObjectClone(chimeraDefaultDebugConfig),\n\t\t\tdebugConfig ?? {},\n\t\t);\n\n\t\tconst query = deepObjectAssign<Required<ChimeraQueryDefaultsConfig<Record<string, object>, ChimeraOperatorMap>>>(\n\t\t\tdeepObjectClone(chimeraDefaultQueryConfig),\n\t\t\tqueryConfig?.defaults ?? {},\n\t\t);\n\t\tthis.#queryConfig = Object.fromEntries(\n\t\t\t(\n\t\t\t\tObject.entries(queryConfig?.entities ?? chimeraDefaultQueryConfig.entities) as [\n\t\t\t\t\tstring,\n\t\t\t\t\tChimeraQueryEntityConfig<object, OperatorsMap>,\n\t\t\t\t][]\n\t\t\t).map(([key, value]) => [\n\t\t\t\tkey,\n\t\t\t\t{\n\t\t\t\t\tbatchedCreator: value.batchedCreator ? value.batchedCreator : (...args) => query.batchedCreator(key, ...args),\n\t\t\t\t\tbatchedDeleter: value.batchedDeleter ? value.batchedDeleter : (...args) => query.batchedDeleter(key, ...args),\n\t\t\t\t\tbatchedUpdater: value.batchedUpdater ? value.batchedUpdater : (...args) => query.batchedUpdater(key, ...args),\n\n\t\t\t\t\tcollectionFetcher: value.collectionFetcher\n\t\t\t\t\t\t? value.collectionFetcher\n\t\t\t\t\t\t: (...args) => query.collectionFetcher(key, ...args),\n\n\t\t\t\t\tdevMode: this.#debugConfig.devMode,\n\n\t\t\t\t\tidGetter: resolveIdGetter(key, query.idGetter, value.idGetter),\n\n\t\t\t\t\titemCreator: value.itemCreator ? value.itemCreator : (...args) => query.itemCreator(key, ...args),\n\t\t\t\t\titemDeleter: value.itemDeleter ? value.itemDeleter : (...args) => query.itemDeleter(key, ...args),\n\t\t\t\t\titemFetcher: value.itemFetcher ? value.itemFetcher : (...args) => query.itemFetcher(key, ...args),\n\t\t\t\t\titemUpdater: value.itemUpdater ? value.itemUpdater : (...args) => query.itemUpdater(key, ...args),\n\t\t\t\t\tname: key,\n\t\t\t\t\ttrustQuery: value.trustQuery ?? query.trustQuery,\n\t\t\t\t\tupdateDebounceTimeout: value.updateDebounceTimeout ?? query.updateDebounceTimeout,\n\t\t\t\t} satisfies QueryEntityConfig<any, any>,\n\t\t\t]),\n\t\t) as unknown as RepositoryConfigMap<EntityMap, OperatorsMap>;\n\n\t\tthis.#reposMap = {};\n\n\t\tthis.#emit(\"initialized\", { instance: this });\n\t}\n\n\tget config(): Config {\n\t\treturn this.#initialConfig;\n\t}\n\n\tfrom<EntityName extends StrKeys<EntityMap>>(\n\t\tentityName: EntityName,\n\t): ChimeraEntityRepository<EntityMap[EntityName], OperatorsMap> {\n\t\treturn this.#reposMap[entityName] ?? this.#addRepository(entityName);\n\t}\n\n\tupdateOne<EntityName extends StrKeys<EntityMap>>(entityName: EntityName, item: EntityMap[EntityName]) {\n\t\tconst repo = this.#reposMap[entityName];\n\t\tif (repo) {\n\t\t\trepo[ChimeraSetOneSym](item);\n\t\t\tthis.#emit(\"itemUpdated\", {\n\t\t\t\tentityName,\n\t\t\t\tinstance: this,\n\t\t\t\titem,\n\t\t\t\trepository: repo as unknown as ChimeraEntityRepository<EntityMap[StrKeys<EntityMap>], OperatorsMap>,\n\t\t\t});\n\t\t}\n\t}\n\n\tupdateMany<EntityName extends StrKeys<EntityMap>>(entityName: EntityName, items: EntityMap[EntityName][]) {\n\t\tconst repo = this.#reposMap[entityName];\n\t\tif (repo) {\n\t\t\trepo[ChimeraSetManySym](items);\n\t\t\tthis.#emit(\"updated\", {\n\t\t\t\tentityName,\n\t\t\t\tinstance: this,\n\t\t\t\titems,\n\t\t\t\trepository: repo as unknown as ChimeraEntityRepository<EntityMap[StrKeys<EntityMap>], OperatorsMap>,\n\t\t\t});\n\t\t}\n\t}\n\n\tdeleteOne<EntityName extends StrKeys<EntityMap>>(entityName: EntityName, id: ChimeraEntityId) {\n\t\tconst repo = this.#reposMap[entityName];\n\t\tif (repo) {\n\t\t\trepo[ChimeraDeleteOneSym](id);\n\t\t\tthis.#emit(\"itemDeleted\", {\n\t\t\t\tentityName,\n\t\t\t\tid,\n\t\t\t\tinstance: this,\n\t\t\t\trepository: repo as unknown as ChimeraEntityRepository<EntityMap[StrKeys<EntityMap>], OperatorsMap>,\n\t\t\t});\n\t\t}\n\t}\n\n\tdeleteMany<EntityName extends StrKeys<EntityMap>>(entityName: EntityName, ids: ChimeraEntityId[]) {\n\t\tconst repo = this.#reposMap[entityName];\n\t\tif (repo) {\n\t\t\trepo[ChimeraDeleteManySym](ids);\n\t\t\tthis.#emit(\"deleted\", {\n\t\t\t\tentityName,\n\t\t\t\tids,\n\t\t\t\tinstance: this,\n\t\t\t\trepository: repo as unknown as ChimeraEntityRepository<EntityMap[StrKeys<EntityMap>], OperatorsMap>,\n\t\t\t});\n\t\t}\n\t}\n\n\tupdateMixed<EntityName extends StrKeys<EntityMap>>(\n\t\tentityName: EntityName,\n\t\ttoAdd: EntityMap[EntityName][],\n\t\ttoDelete: ChimeraEntityId[],\n\t) {\n\t\tconst repo = this.#reposMap[entityName];\n\t\tif (repo) {\n\t\t\trepo[ChimeraUpdateMixedSym](toAdd, toDelete);\n\t\t\tthis.#emit(\"deleted\", {\n\t\t\t\tentityName,\n\t\t\t\tids: toDelete,\n\t\t\t\tinstance: this,\n\t\t\t\trepository: repo as unknown as ChimeraEntityRepository<EntityMap[StrKeys<EntityMap>], OperatorsMap>,\n\t\t\t});\n\t\t\tthis.#emit(\"updated\", {\n\t\t\t\tentityName,\n\t\t\t\tinstance: this,\n\t\t\t\titems: toAdd,\n\t\t\t\trepository: repo as unknown as ChimeraEntityRepository<EntityMap[StrKeys<EntityMap>], OperatorsMap>,\n\t\t\t});\n\t\t}\n\t}\n}\n\n// Utility types\nexport type AnyChimeraStore = ChimeraStore<any, any>;\ntype ExtractsStoreGenerics<T extends AnyChimeraStore> = T extends ChimeraStore<infer E, infer O>\n\t? { entityMap: E; operatorMap: O }\n\t: never;\nexport type ChimeraStoreEntityMap<T extends AnyChimeraStore> = ExtractsStoreGenerics<T>[\"entityMap\"];\nexport type ChimeraStoreOperatorMap<T extends AnyChimeraStore> = ExtractsStoreGenerics<T>[\"operatorMap\"];\nexport type ChimeraStoreEntities<T extends AnyChimeraStore> = keyof ChimeraStoreEntityMap<T> & string;\nexport type ChimeraStoreOperator<T extends AnyChimeraStore> = keyof ChimeraStoreOperatorMap<T> & string;\nexport type ChimeraStoreEntityType<\n\tT extends AnyChimeraStore,\n\tK extends ChimeraStoreEntities<T>,\n> = ChimeraStoreEntityMap<T>[K];\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