@hf-chimera/store 0.0.15 → 0.1.0

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 (51) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/adapters/react.cjs +40 -92
  3. package/dist/adapters/react.cjs.map +1 -1
  4. package/dist/adapters/react.d.cts +8 -32
  5. package/dist/adapters/react.d.cts.map +1 -1
  6. package/dist/adapters/react.d.ts +8 -32
  7. package/dist/adapters/react.d.ts.map +1 -1
  8. package/dist/adapters/react.js +38 -61
  9. package/dist/adapters/react.js.map +1 -1
  10. package/dist/adapters/vue.cjs +92 -0
  11. package/dist/adapters/vue.cjs.map +1 -0
  12. package/dist/adapters/vue.d.cts +19 -0
  13. package/dist/adapters/vue.d.cts.map +1 -0
  14. package/dist/adapters/vue.d.ts +19 -0
  15. package/dist/adapters/vue.d.ts.map +1 -0
  16. package/dist/adapters/vue.js +91 -0
  17. package/dist/adapters/vue.js.map +1 -0
  18. package/dist/{defaults-Bg1kIemd.cjs → defaults-C48gY1ow.cjs} +1 -1
  19. package/dist/{defaults-Bg1kIemd.cjs.map → defaults-C48gY1ow.cjs.map} +1 -1
  20. package/dist/defaults.cjs +1 -1
  21. package/dist/defaults.d.cts +1 -1
  22. package/dist/defaults.d.ts +1 -1
  23. package/dist/{index-B6sY7hiW.d.ts → index-BuYMaiND.d.ts} +2 -2
  24. package/dist/{index-B6sY7hiW.d.ts.map → index-BuYMaiND.d.ts.map} +1 -1
  25. package/dist/{index-CTTQ1Hr3.d.ts → index-C45y61aH.d.ts} +57 -57
  26. package/dist/index-C45y61aH.d.ts.map +1 -0
  27. package/dist/{index-CkaYmEhA.d.cts → index-DP6-nR2O.d.cts} +57 -57
  28. package/dist/index-DP6-nR2O.d.cts.map +1 -0
  29. package/dist/{index-CiER0sxG.d.cts → index-FQNcJwA7.d.cts} +2 -2
  30. package/dist/{index-CiER0sxG.d.cts.map → index-FQNcJwA7.d.cts.map} +1 -1
  31. package/dist/index.cjs +2 -2
  32. package/dist/index.d.cts +1 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/params-B-wurzdZ.d.ts +8 -0
  35. package/dist/params-B-wurzdZ.d.ts.map +1 -0
  36. package/dist/params-C5dnCvJr.cjs +47 -0
  37. package/dist/params-C5dnCvJr.cjs.map +1 -0
  38. package/dist/params-DmOyCS2B.js +13 -0
  39. package/dist/params-DmOyCS2B.js.map +1 -0
  40. package/dist/params-uxNE-e4a.d.cts +8 -0
  41. package/dist/params-uxNE-e4a.d.cts.map +1 -0
  42. package/dist/{qb-PXzZgo2H.cjs → qb-D6vPK6P0.cjs} +2 -2
  43. package/dist/{qb-PXzZgo2H.cjs.map → qb-D6vPK6P0.cjs.map} +1 -1
  44. package/dist/qb.cjs +3 -3
  45. package/dist/qb.d.cts +2 -2
  46. package/dist/qb.d.ts +2 -2
  47. package/dist/{src-TJG6k3Nr.cjs → src-YxpDmKvq.cjs} +2 -2
  48. package/dist/{src-TJG6k3Nr.cjs.map → src-YxpDmKvq.cjs.map} +1 -1
  49. package/package.json +11 -2
  50. package/dist/index-CTTQ1Hr3.d.ts.map +0 -1
  51. package/dist/index-CkaYmEhA.d.cts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hf-chimera/store
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add Vue adapter
8
+
3
9
  ## 0.0.15
4
10
 
5
11
  ### Patch Changes
@@ -1,46 +1,11 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- require('../defaults-Bg1kIemd.cjs');
25
- require('../src-TJG6k3Nr.cjs');
26
- const require_qb = require('../qb-PXzZgo2H.cjs');
1
+ const require_params = require('../params-C5dnCvJr.cjs');
2
+ require('../defaults-C48gY1ow.cjs');
3
+ require('../src-YxpDmKvq.cjs');
4
+ require('../qb-D6vPK6P0.cjs');
27
5
  let react = require("react");
28
- react = __toESM(react);
29
-
30
- //#region packages/adapters/react/context.tsx
31
- const ChimeraStoreContext = (0, react.createContext)(null);
32
- const ChimeraStoreProvider = ({ children, store }) => <ChimeraStoreContext.Provider value={(0, react.useMemo)(() => ({ store }), [store])}>{children}</ChimeraStoreContext.Provider>;
6
+ react = require_params.__toESM(react);
33
7
 
34
- //#endregion
35
8
  //#region packages/adapters/react/hooks.ts
36
- function useChimeraStore() {
37
- const context = (0, react.useContext)(ChimeraStoreContext);
38
- if (!context) throw new Error("useChimeraStore must be used within a ChimeraStoreProvider");
39
- return context.store;
40
- }
41
- function useChimeraRepository(entityName) {
42
- return useChimeraStore().from(entityName);
43
- }
44
9
  const CHIMERA_COLLECTION_UPDATE_EVENTS = [
45
10
  "ready",
46
11
  "updated",
@@ -53,28 +18,6 @@ const CHIMERA_COLLECTION_UPDATE_EVENTS = [
53
18
  "selfItemDeleted",
54
19
  "error"
55
20
  ];
56
- const useChimeraCollection = (entityName, params, deps) => {
57
- const [, trigger] = (0, react.useState)(() => ({}));
58
- const repository = useChimeraRepository(entityName);
59
- const oldDeps = (0, react.useRef)(deps);
60
- if (oldDeps.current && !deps || !oldDeps.current && deps) console.warn("useChimeraCollection deps is not a reactive param!\nUse deps if you want to control dependencies manually.\nOmit it if you already have a stable reference to params");
61
- oldDeps.current = deps;
62
- const memeParams = (0, react.useMemo)(() => {
63
- if (typeof params !== "function") return params;
64
- const q = new require_qb.ChimeraQueryBuilder();
65
- params(q);
66
- return q.build();
67
- }, deps ? deps : [params]);
68
- const collection = (0, react.useMemo)(() => repository.getCollection(memeParams), [repository, memeParams]);
69
- (0, react.useEffect)(() => {
70
- const handler = () => trigger({});
71
- for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.on(event, handler);
72
- return () => {
73
- for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.off(event, handler);
74
- };
75
- }, [collection]);
76
- return collection;
77
- };
78
21
  const CHIMERA_ITEM_UPDATE_EVENTS = [
79
22
  "initialized",
80
23
  "selfCreated",
@@ -85,38 +28,43 @@ const CHIMERA_ITEM_UPDATE_EVENTS = [
85
28
  "selfDeleted",
86
29
  "error"
87
30
  ];
88
- const useChimeraItem = (entityName, id, meta) => {
89
- const [, trigger] = (0, react.useState)(() => ({}));
90
- const item = useChimeraRepository(entityName).getItem(id, meta);
91
- (0, react.useEffect)(() => {
92
- const handler = () => trigger({});
93
- for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.on(event, handler);
94
- return () => {
95
- for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.off(event, handler);
96
- };
97
- }, [item]);
98
- return item;
99
- };
100
- function getChimeraTypedHooks(withoutPrefix) {
101
- return withoutPrefix ? {
102
- useCollection: useChimeraCollection,
103
- useItem: useChimeraItem,
104
- useRepository: useChimeraRepository,
105
- useStore: useChimeraStore
106
- } : {
107
- useChimeraCollection,
108
- useChimeraItem,
31
+ const createChimeraHooks = (store) => {
32
+ const useChimeraRepository = (entityName) => (0, react.useMemo)(() => store.from(entityName), [entityName]);
33
+ return {
34
+ useChimeraStore: () => store,
109
35
  useChimeraRepository,
110
- useChimeraStore
36
+ useChimeraCollection: (entityName, params, deps) => {
37
+ const [, trigger] = (0, react.useState)(() => ({}));
38
+ const repository = useChimeraRepository(entityName);
39
+ const oldDeps = (0, react.useRef)(deps);
40
+ if (oldDeps.current && !deps || !oldDeps.current && deps) console.warn("useChimeraCollection deps is not a reactive param!\nUse deps if you want to control dependencies manually.\nOmit it if you already have a stable reference to params");
41
+ oldDeps.current = deps;
42
+ const memeParams = (0, react.useMemo)(() => require_params.normalizeParams(params), deps ? deps : [params]);
43
+ const collection = (0, react.useMemo)(() => repository.getCollection(memeParams), [repository, memeParams]);
44
+ (0, react.useEffect)(() => {
45
+ const handler = () => trigger({});
46
+ for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.on(event, handler);
47
+ return () => {
48
+ for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.off(event, handler);
49
+ };
50
+ }, [collection]);
51
+ return collection;
52
+ },
53
+ useChimeraItem: (entityName, id, meta) => {
54
+ const [, trigger] = (0, react.useState)(() => ({}));
55
+ const item = useChimeraRepository(entityName).getItem(id, meta);
56
+ (0, react.useEffect)(() => {
57
+ const handler = () => trigger({});
58
+ for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.on(event, handler);
59
+ return () => {
60
+ for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.off(event, handler);
61
+ };
62
+ }, [item]);
63
+ return item;
64
+ }
111
65
  };
112
- }
66
+ };
113
67
 
114
68
  //#endregion
115
- exports.ChimeraStoreContext = ChimeraStoreContext;
116
- exports.ChimeraStoreProvider = ChimeraStoreProvider;
117
- exports.getChimeraTypedHooks = getChimeraTypedHooks;
118
- exports.useChimeraCollection = useChimeraCollection;
119
- exports.useChimeraItem = useChimeraItem;
120
- exports.useChimeraRepository = useChimeraRepository;
121
- exports.useChimeraStore = useChimeraStore;
69
+ exports.createChimeraHooks = createChimeraHooks;
122
70
  //# sourceMappingURL=react.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.cjs","names":["ChimeraQueryBuilder"],"sources":["../../packages/adapters/react/context.tsx","../../packages/adapters/react/hooks.ts"],"sourcesContent":["import { createContext, type ReactNode, useMemo } from \"react\";\nimport type { AnyChimeraStore } from \"../../../src/store\";\n\nexport interface ChimeraStoreContextValue<T extends AnyChimeraStore> {\n\tstore: T;\n}\n\nexport interface ChimeraStoreProviderProps<T extends AnyChimeraStore> {\n\tchildren: ReactNode;\n\tstore: T;\n}\n\nexport const ChimeraStoreContext = createContext<ChimeraStoreContextValue<AnyChimeraStore> | null>(null);\n\nexport const ChimeraStoreProvider = <T extends AnyChimeraStore>({ children, store }: ChimeraStoreProviderProps<T>) => (\n\t<ChimeraStoreContext.Provider value={useMemo(() => ({ store }), [store])}>{children}</ChimeraStoreContext.Provider>\n);\n","import { useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ChimeraCollectionQuery } from \"../../../src/query/ChimeraCollectionQuery\";\nimport type { ChimeraItemQuery } from \"../../../src/query/ChimeraItemQuery\";\nimport type { ChimeraEntityId } from \"../../../src/shared/types\";\nimport type { ChimeraEntityRepository } from \"../../../src/store/ChimeraEntityRepository\";\nimport type {\n\tAnyChimeraStore,\n\tChimeraStoreEntities,\n\tChimeraStoreEntityType,\n\tChimeraStoreOperatorMap,\n} from \"../../../src/store/ChimeraStore\";\nimport type { ChimeraCollectionParams } from \"../../../src/store/types\";\nimport { ChimeraQueryBuilder, type QueryBuilderCreator } from \"../../qb\";\nimport { ChimeraStoreContext } from \"./context\";\n\nexport function useChimeraStore<T extends AnyChimeraStore>(): T {\n\tconst context = useContext(ChimeraStoreContext);\n\tif (!context) {\n\t\tthrow new Error(\"useChimeraStore must be used within a ChimeraStoreProvider\");\n\t}\n\treturn context.store as T;\n}\n\nexport function useChimeraRepository<T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>>(\n\tentityName: EntityName,\n): ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>> {\n\tconst store = useChimeraStore<T>();\n\treturn store.from(entityName);\n}\n\nconst CHIMERA_COLLECTION_UPDATE_EVENTS = [\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"selfItemCreated\",\n\t\"itemAdded\",\n\t\"itemUpdated\",\n\t\"selfItemUpdated\",\n\t\"itemDeleted\",\n\t\"selfItemDeleted\",\n\t\"error\",\n] as const;\nexport const useChimeraCollection = <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\tentityName: EntityName,\n\tparams:\n\t\t| ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>\n\t\t| QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>,\n\tdeps?: unknown[],\n): ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>> => {\n\tconst [, trigger] = useState(() => ({}));\n\n\tconst repository = useChimeraRepository<T, EntityName>(entityName);\n\n\tconst oldDeps = useRef(deps);\n\tif ((oldDeps.current && !deps) || (!oldDeps.current && deps)) {\n\t\tconsole.warn(\n\t\t\t\"useChimeraCollection deps is not a reactive param!\\n\" +\n\t\t\t\t\"Use deps if you want to control dependencies manually.\\n\" +\n\t\t\t\t\"Omit it if you already have a stable reference to params\",\n\t\t);\n\t}\n\toldDeps.current = deps;\n\n\tconst memeParams = useMemo(\n\t\t() => {\n\t\t\tif (typeof params !== \"function\") return params;\n\n\t\t\tconst q = new ChimeraQueryBuilder();\n\t\t\tparams(q);\n\t\t\treturn q.build();\n\t\t},\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: Very unlikely it will be changed over time, anyway warning for this already added.\n\t\tdeps ? deps : [params],\n\t);\n\tconst collection = useMemo(() => repository.getCollection(memeParams), [repository, memeParams]);\n\n\tuseEffect(() => {\n\t\tconst handler = () => trigger({});\n\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\tcollection.on(event, handler);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\t\tcollection.off(event, handler);\n\t\t\t}\n\t\t};\n\t}, [collection]);\n\n\treturn collection;\n};\n\nconst CHIMERA_ITEM_UPDATE_EVENTS = [\n\t\"initialized\",\n\t\"selfCreated\",\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"deleted\",\n\t\"selfDeleted\",\n\t\"error\",\n] as const;\nexport const useChimeraItem = <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\tentityName: EntityName,\n\tid: ChimeraEntityId,\n\tmeta?: Meta,\n): ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>> => {\n\tconst [, trigger] = useState(() => ({}));\n\n\tconst repository = useChimeraRepository<T, EntityName>(entityName);\n\tconst item = repository.getItem(id, meta);\n\n\tuseEffect(() => {\n\t\tconst handler = () => trigger({});\n\t\tfor (const event of CHIMERA_ITEM_UPDATE_EVENTS) {\n\t\t\titem.on(event, handler);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const event of CHIMERA_ITEM_UPDATE_EVENTS) {\n\t\t\t\titem.off(event, handler);\n\t\t\t}\n\t\t};\n\t}, [item]);\n\n\treturn item;\n};\n\nexport function getChimeraTypedHooks<T extends AnyChimeraStore>(\n\twithoutPrefix: true,\n): {\n\tuseStore: () => T;\n\tuseRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\tentityName: EntityName,\n\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tparams: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>,\n\t\tdeps?: unknown[],\n\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tid: ChimeraEntityId,\n\t\tmeta?: Meta,\n\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n};\nexport function getChimeraTypedHooks<T extends AnyChimeraStore>(\n\twithoutPrefix?: false,\n): {\n\tuseChimeraStore: () => T;\n\tuseChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\tentityName: EntityName,\n\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tparams:\n\t\t\t| ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>\n\t\t\t| QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>,\n\t\tdeps?: unknown[],\n\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tid: ChimeraEntityId,\n\t\tmeta?: Meta,\n\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n};\nexport function getChimeraTypedHooks<T extends AnyChimeraStore>(\n\twithoutPrefix?: boolean,\n):\n\t| {\n\t\t\tuseChimeraStore: () => T;\n\t\t\tuseChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\t\t\tentityName: EntityName,\n\t\t\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tparams: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>,\n\t\t\t\tdeps?: unknown[],\n\t\t\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tid: ChimeraEntityId,\n\t\t\t\tmeta?: Meta,\n\t\t\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n\t }\n\t| {\n\t\t\tuseStore: () => T;\n\t\t\tuseRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\t\t\tentityName: EntityName,\n\t\t\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tparams: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>,\n\t\t\t\tdeps?: unknown[],\n\t\t\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tid: ChimeraEntityId,\n\t\t\t\tmeta?: Meta,\n\t\t\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n\t } {\n\treturn (\n\t\twithoutPrefix\n\t\t\t? {\n\t\t\t\t\tuseCollection: useChimeraCollection,\n\t\t\t\t\tuseItem: useChimeraItem,\n\t\t\t\t\tuseRepository: useChimeraRepository,\n\t\t\t\t\tuseStore: useChimeraStore,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tuseChimeraCollection,\n\t\t\t\t\tuseChimeraItem,\n\t\t\t\t\tuseChimeraRepository,\n\t\t\t\t\tuseChimeraStore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AAM,6BAA6B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,MAAa,kBACZ,YACA,IACA,SAC6D;CAC7D,MAAM,GAAG,sCAA2B,EAAE,EAAE;CAGxC,MAAM,OADa,qBAAoC,WAAW,CAC1C,QAAQ,IAAI,KAAK;AAEzC,4BAAgB;EACf,MAAM,gBAAgB,QAAQ,EAAE,CAAC;AACjC,OAAK,MAAM,SAAS,2BACnB,MAAK,GAAG,OAAO,QAAQ;AAExB,eAAa;AACZ,QAAK,MAAM,SAAS,2BACnB,MAAK,IAAI,OAAO,QAAQ;;IAGxB,CAAC,KAAK,CAAC;AAEV,QAAO;;AAyCR,SAAgB,qBACf,eAiCI;AACJ,QACC,gBACG;EACA,eAAe;EACf,SAAS;EACT,eAAe;EACf,UAAU;EACV,GACA;EACA;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"react.cjs","names":["normalizeParams"],"sources":["../../packages/adapters/react/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ChimeraCollectionQuery } from \"../../../src/query/ChimeraCollectionQuery\";\nimport type { ChimeraItemQuery } from \"../../../src/query/ChimeraItemQuery\";\nimport type { ChimeraEntityId } from \"../../../src/shared/types\";\nimport type { ChimeraEntityRepository } from \"../../../src/store/ChimeraEntityRepository\";\nimport type {\n\tAnyChimeraStore,\n\tChimeraStoreEntities,\n\tChimeraStoreEntityType,\n\tChimeraStoreOperatorMap,\n} from \"../../../src/store/ChimeraStore\";\nimport { type AnyChimeraParams, normalizeParams } from \"../shared/params\";\n\nconst CHIMERA_COLLECTION_UPDATE_EVENTS = [\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"selfItemCreated\",\n\t\"itemAdded\",\n\t\"itemUpdated\",\n\t\"selfItemUpdated\",\n\t\"itemDeleted\",\n\t\"selfItemDeleted\",\n\t\"error\",\n] as const;\n\nconst CHIMERA_ITEM_UPDATE_EVENTS = [\n\t\"initialized\",\n\t\"selfCreated\",\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"deleted\",\n\t\"selfDeleted\",\n\t\"error\",\n] as const;\n\nexport const createChimeraHooks = <T extends AnyChimeraStore>(\n\tstore: T,\n): {\n\tuseChimeraStore: () => T;\n\tuseChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\tentityName: EntityName,\n\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tparams: AnyChimeraParams<T, EntityName, Meta>,\n\t\tdeps?: unknown[],\n\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tid: ChimeraEntityId,\n\t\tmeta?: Meta,\n\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n} => {\n\tconst useChimeraRepository = <EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName) =>\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: this hook is generated for a specific store so it never changes\n\t\tuseMemo(() => store.from(entityName), [entityName]);\n\n\treturn {\n\t\tuseChimeraStore: () => store,\n\t\tuseChimeraRepository,\n\t\tuseChimeraCollection: (entityName, params, deps?) => {\n\t\t\tconst [, trigger] = useState(() => ({}));\n\n\t\t\tconst repository = useChimeraRepository(entityName);\n\n\t\t\tconst oldDeps = useRef(deps);\n\t\t\tif ((oldDeps.current && !deps) || (!oldDeps.current && deps)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"useChimeraCollection deps is not a reactive param!\\n\" +\n\t\t\t\t\t\t\"Use deps if you want to control dependencies manually.\\n\" +\n\t\t\t\t\t\t\"Omit it if you already have a stable reference to params\",\n\t\t\t\t);\n\t\t\t}\n\t\t\toldDeps.current = deps;\n\n\t\t\tconst memeParams = useMemo(\n\t\t\t\t() => normalizeParams(params),\n\t\t\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: Very unlikely it will be changed over time, anyway warning for this already added.\n\t\t\t\tdeps ? deps : [params],\n\t\t\t);\n\t\t\tconst collection = useMemo(() => repository.getCollection(memeParams), [repository, memeParams]);\n\n\t\t\tuseEffect(() => {\n\t\t\t\tconst handler = () => trigger({});\n\t\t\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\t\t\tcollection.on(event, handler);\n\t\t\t\t}\n\t\t\t\treturn () => {\n\t\t\t\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\t\t\t\tcollection.off(event, handler);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}, [collection]);\n\n\t\t\treturn collection;\n\t\t},\n\t\tuseChimeraItem: (entityName, id, meta?) => {\n\t\t\tconst [, trigger] = useState(() => ({}));\n\n\t\t\tconst repository = useChimeraRepository(entityName);\n\t\t\tconst item = repository.getItem(id, meta);\n\n\t\t\tuseEffect(() => {\n\t\t\t\tconst handler = () => trigger({});\n\t\t\t\tfor (const event of CHIMERA_ITEM_UPDATE_EVENTS) {\n\t\t\t\t\titem.on(event, handler);\n\t\t\t\t}\n\t\t\t\treturn () => {\n\t\t\t\t\tfor (const event of CHIMERA_ITEM_UPDATE_EVENTS) {\n\t\t\t\t\t\titem.off(event, handler);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}, [item]);\n\n\t\t\treturn item;\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;AAaA,MAAM,mCAAmC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAED,MAAM,6BAA6B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAED,MAAa,sBACZ,UAgBI;CACJ,MAAM,wBAAoE,wCAE3D,MAAM,KAAK,WAAW,EAAE,CAAC,WAAW,CAAC;AAEpD,QAAO;EACN,uBAAuB;EACvB;EACA,uBAAuB,YAAY,QAAQ,SAAU;GACpD,MAAM,GAAG,sCAA2B,EAAE,EAAE;GAExC,MAAM,aAAa,qBAAqB,WAAW;GAEnD,MAAM,4BAAiB,KAAK;AAC5B,OAAK,QAAQ,WAAW,CAAC,QAAU,CAAC,QAAQ,WAAW,KACtD,SAAQ,KACP,uKAGA;AAEF,WAAQ,UAAU;GAElB,MAAM,sCACCA,+BAAgB,OAAO,EAE7B,OAAO,OAAO,CAAC,OAAO,CACtB;GACD,MAAM,sCAA2B,WAAW,cAAc,WAAW,EAAE,CAAC,YAAY,WAAW,CAAC;AAEhG,8BAAgB;IACf,MAAM,gBAAgB,QAAQ,EAAE,CAAC;AACjC,SAAK,MAAM,SAAS,iCACnB,YAAW,GAAG,OAAO,QAAQ;AAE9B,iBAAa;AACZ,UAAK,MAAM,SAAS,iCACnB,YAAW,IAAI,OAAO,QAAQ;;MAG9B,CAAC,WAAW,CAAC;AAEhB,UAAO;;EAER,iBAAiB,YAAY,IAAI,SAAU;GAC1C,MAAM,GAAG,sCAA2B,EAAE,EAAE;GAGxC,MAAM,OADa,qBAAqB,WAAW,CAC3B,QAAQ,IAAI,KAAK;AAEzC,8BAAgB;IACf,MAAM,gBAAgB,QAAQ,EAAE,CAAC;AACjC,SAAK,MAAM,SAAS,2BACnB,MAAK,GAAG,OAAO,QAAQ;AAExB,iBAAa;AACZ,UAAK,MAAM,SAAS,2BACnB,MAAK,IAAI,OAAO,QAAQ;;MAGxB,CAAC,KAAK,CAAC;AAEV,UAAO;;EAER"}
@@ -1,39 +1,15 @@
1
- import { C as ChimeraItemQuery, F as ChimeraCollectionQuery, Ut as ChimeraEntityId, _ as ChimeraStoreEntityType, b as ChimeraEntityRepository, h as ChimeraStoreEntities, p as AnyChimeraStore, x as ChimeraCollectionParams, y as ChimeraStoreOperatorMap } from "../index-CkaYmEhA.cjs";
2
- import { n as QueryBuilderCreator } from "../index-CiER0sxG.cjs";
3
- import * as react0 from "react";
4
- import { ReactNode } from "react";
1
+ import { D as ChimeraItemQuery, Ut as ChimeraEntityId, _ as ChimeraStoreEntityType, h as ChimeraStoreEntities, p as AnyChimeraStore, w as ChimeraEntityRepository, y as ChimeraStoreOperatorMap, z as ChimeraCollectionQuery } from "../index-DP6-nR2O.cjs";
2
+ import "../index-FQNcJwA7.cjs";
3
+ import { t as AnyChimeraParams } from "../params-uxNE-e4a.cjs";
5
4
 
6
- //#region packages/adapters/react/context.d.ts
7
- interface ChimeraStoreContextValue<T extends AnyChimeraStore> {
8
- store: T;
9
- }
10
- interface ChimeraStoreProviderProps<T extends AnyChimeraStore> {
11
- children: ReactNode;
12
- store: T;
13
- }
14
- declare const ChimeraStoreContext: react0.Context<ChimeraStoreContextValue<AnyChimeraStore> | null>;
15
- declare const ChimeraStoreProvider: <T extends AnyChimeraStore>({
16
- children,
17
- store
18
- }: ChimeraStoreProviderProps<T>) => react0.JSX.Element;
19
- //#endregion
20
5
  //#region packages/adapters/react/hooks.d.ts
21
- declare function useChimeraStore<T extends AnyChimeraStore>(): T;
22
- declare function useChimeraRepository<T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName): ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
23
- declare const useChimeraCollection: <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta> | QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
24
- declare const useChimeraItem: <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
25
- declare function getChimeraTypedHooks<T extends AnyChimeraStore>(withoutPrefix: true): {
26
- useStore: () => T;
27
- useRepository: <EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
28
- useCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
29
- useItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
30
- };
31
- declare function getChimeraTypedHooks<T extends AnyChimeraStore>(withoutPrefix?: false): {
6
+
7
+ declare const createChimeraHooks: <T extends AnyChimeraStore>(store: T) => {
32
8
  useChimeraStore: () => T;
33
9
  useChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
34
- useChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta> | QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
35
- useChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
10
+ useChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: AnyChimeraParams<T, EntityName, Meta>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
11
+ useChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta_1 = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta_1) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
36
12
  };
37
13
  //#endregion
38
- export { ChimeraStoreContext, ChimeraStoreContextValue, ChimeraStoreProvider, ChimeraStoreProviderProps, getChimeraTypedHooks, useChimeraCollection, useChimeraItem, useChimeraRepository, useChimeraStore };
14
+ export { createChimeraHooks };
39
15
  //# sourceMappingURL=react.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.cts","names":[],"sources":["../../packages/adapters/react/context.tsx","../../packages/adapters/react/hooks.ts"],"sourcesContent":[],"mappings":";;;;;;UAGiB,mCAAmC;SAC5C;;UAGS,oCAAoC;EAJpC,QAAA,EAKN,SALM;EAIA,KAAA,EAET,CAFS;;AACN,cAIE,mBAJF,EAIqB,MAAA,CAAA,OAJrB,CAIqB,wBAJrB,CAIqB,eAJrB,CAAA,GAAA,IAAA,CAAA;AACH,cAKK,oBALL,EAAA,CAAA,UAKuC,eALvC,CAAA,CAAA;EAAA,QAAA;EAAA;AAAA,CAAA,EAK6E,yBAL7E,CAKuG,CALvG,CAAA,EAAA,GAKyG,MAAA,CAAA,GAAA,CAAA,OALzG;;;AAFS,iBCQD,eDR0B,CAAA,UCQA,eDRA,CAAA,CAAA,CAAA,ECQoB,CDRpB;AAAW,iBCgBrC,oBDhBqC,CAAA,UCgBN,eDhBM,EAAA,mBCgB8B,oBDhB9B,CCgBmD,CDhBnD,CAAA,CAAA,CAAA,UAAA,ECiBxC,UDjBwC,CAAA,ECkBlD,uBDlBkD,CCkB1B,sBDlB0B,CCkBH,CDlBG,ECkBA,UDlBA,CAAA,ECkBa,uBDlBb,CCkBqC,CDlBrC,CAAA,CAAA;AAC1C,c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AKlC,UALkC,EAKtB,IALsB,CAAA,EAAA,IAAA,CAAA,EAAA,OAAA,EAAA,EAAA,GAO1D,sBAP0D,CAOnC,sBAPmC,CAOZ,CAPY,EAOT,UAPS,CAAA,EAOI,uBAPJ,CAO4B,CAP5B,CAAA,CAAA;EAArB,cAAA,EAAA,CAAA,mBAQN,oBARM,CAQe,CARf,CAAA,EAAA,SAAA,GAAA,CAAA,CAAA,UAAA,EAS7B,UAT6B,EAAA,EAAA,EAUrC,eAVqC,EAAA,IAAA,CAAA,EAWlC,MAXkC,EAAA,GAYrC,gBAZqC,CAYpB,sBAZoB,CAYG,CAZH,EAYM,UAZN,CAAA,CAAA;CAC7B"}
@@ -1,39 +1,15 @@
1
- import { C as ChimeraItemQuery, F as ChimeraCollectionQuery, Ut as ChimeraEntityId, _ as ChimeraStoreEntityType, b as ChimeraEntityRepository, h as ChimeraStoreEntities, p as AnyChimeraStore, x as ChimeraCollectionParams, y as ChimeraStoreOperatorMap } from "../index-CTTQ1Hr3.js";
2
- import { n as QueryBuilderCreator } from "../index-B6sY7hiW.js";
3
- import * as react0 from "react";
4
- import { ReactNode } from "react";
1
+ import { D as ChimeraItemQuery, Ut as ChimeraEntityId, _ as ChimeraStoreEntityType, h as ChimeraStoreEntities, p as AnyChimeraStore, w as ChimeraEntityRepository, y as ChimeraStoreOperatorMap, z as ChimeraCollectionQuery } from "../index-C45y61aH.js";
2
+ import "../index-BuYMaiND.js";
3
+ import { t as AnyChimeraParams } from "../params-B-wurzdZ.js";
5
4
 
6
- //#region packages/adapters/react/context.d.ts
7
- interface ChimeraStoreContextValue<T extends AnyChimeraStore> {
8
- store: T;
9
- }
10
- interface ChimeraStoreProviderProps<T extends AnyChimeraStore> {
11
- children: ReactNode;
12
- store: T;
13
- }
14
- declare const ChimeraStoreContext: react0.Context<ChimeraStoreContextValue<AnyChimeraStore> | null>;
15
- declare const ChimeraStoreProvider: <T extends AnyChimeraStore>({
16
- children,
17
- store
18
- }: ChimeraStoreProviderProps<T>) => react0.JSX.Element;
19
- //#endregion
20
5
  //#region packages/adapters/react/hooks.d.ts
21
- declare function useChimeraStore<T extends AnyChimeraStore>(): T;
22
- declare function useChimeraRepository<T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName): ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
23
- declare const useChimeraCollection: <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta> | QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
24
- declare const useChimeraItem: <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
25
- declare function getChimeraTypedHooks<T extends AnyChimeraStore>(withoutPrefix: true): {
26
- useStore: () => T;
27
- useRepository: <EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
28
- useCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
29
- useItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
30
- };
31
- declare function getChimeraTypedHooks<T extends AnyChimeraStore>(withoutPrefix?: false): {
6
+
7
+ declare const createChimeraHooks: <T extends AnyChimeraStore>(store: T) => {
32
8
  useChimeraStore: () => T;
33
9
  useChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
34
- useChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta> | QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
35
- useChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
10
+ useChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(entityName: EntityName, params: AnyChimeraParams<T, EntityName, Meta>, deps?: unknown[]) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;
11
+ useChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta_1 = any>(entityName: EntityName, id: ChimeraEntityId, meta?: Meta_1) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;
36
12
  };
37
13
  //#endregion
38
- export { ChimeraStoreContext, ChimeraStoreContextValue, ChimeraStoreProvider, ChimeraStoreProviderProps, getChimeraTypedHooks, useChimeraCollection, useChimeraItem, useChimeraRepository, useChimeraStore };
14
+ export { createChimeraHooks };
39
15
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","names":[],"sources":["../../packages/adapters/react/context.tsx","../../packages/adapters/react/hooks.ts"],"sourcesContent":[],"mappings":";;;;;;UAGiB,mCAAmC;SAC5C;;UAG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,gBDpJyG,CCoJxF,sBDpJwF,CCoJjE,CDpJiE,ECoJ9D,UDpJ8D,CAAA,CAAA;CAA1B"}
1
+ {"version":3,"file":"react.d.ts","names":[],"sources":["../../packages/adapters/react/hooks.ts"],"sourcesContent":[],"mappings":";;;;;;AAqC6C,cAAhC,kBAAgC,EAAA,CAAA,UAAA,eAAA,CAAA,CAAA,KAAA,EACrC,CADqC,EAAA,GAAA;EACrC,eAAA,EAAA,GAAA,GAEgB,CAFhB;EAEgB,oBAAA,EAAA,CAAA,mBACmB,oBADnB,CACwC,CADxC,CAAA,CAAA,CAAA,UAAA,EAEV,UAFU,EAAA,GAGlB,uBAHkB,CAGM,sBAHN,CAG6B,CAH7B,EAGgC,UAHhC,CAAA,EAG6C,uBAH7C,CAGqE,CAHrE,CAAA,CAAA;EACwC,oBAAA,EAAA,CAAA,mBAGrB,oBAHqB,CAGA,CAHA,CAAA,EAAA,OAAA,GAAA,CAAA,CAAA,UAAA,EAIlD,UAJkD,EAAA,MAAA,EAKtD,gBALsD,CAKrC,CALqC,EAKlC,UALkC,EAKtB,IALsB,CAAA,EAAA,IAAA,CAAA,EAAA,OAAA,EAAA,EAAA,GAO1D,sBAP0D,CAOnC,sBAPmC,CAOZ,CAPY,EAOT,UAPS,CAAA,EAOI,uBAPJ,CAO4B,CAP5B,CAAA,CAAA;EAArB,cAAA,EAAA,CAAA,mBAQN,oBARM,CAQe,CARf,CAAA,EAAA,SAAA,GAAA,CAAA,CAAA,UAAA,EAS7B,UAT6B,EAAA,EAAA,EAUrC,eAVqC,EAAA,IAAA,CAAA,EAWlC,MAXkC,EAAA,GAYrC,gBAZqC,CAYpB,sBAZoB,CAYG,CAZH,EAYM,UAZN,CAAA,CAAA;CAC7B"}
@@ -1,22 +1,10 @@
1
1
  import "../defaults-CLUQg2zK.js";
2
2
  import "../src-C74sq0jQ.js";
3
- import { t as ChimeraQueryBuilder } from "../qb-pchs-vdM.js";
4
- import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
3
+ import "../qb-pchs-vdM.js";
4
+ import { t as normalizeParams } from "../params-DmOyCS2B.js";
5
+ import { useEffect, useMemo, useRef, useState } from "react";
5
6
 
6
- //#region packages/adapters/react/context.tsx
7
- const ChimeraStoreContext = createContext(null);
8
- const ChimeraStoreProvider = ({ children, store }) => <ChimeraStoreContext.Provider value={useMemo(() => ({ store }), [store])}>{children}</ChimeraStoreContext.Provider>;
9
-
10
- //#endregion
11
7
  //#region packages/adapters/react/hooks.ts
12
- function useChimeraStore() {
13
- const context = useContext(ChimeraStoreContext);
14
- if (!context) throw new Error("useChimeraStore must be used within a ChimeraStoreProvider");
15
- return context.store;
16
- }
17
- function useChimeraRepository(entityName) {
18
- return useChimeraStore().from(entityName);
19
- }
20
8
  const CHIMERA_COLLECTION_UPDATE_EVENTS = [
21
9
  "ready",
22
10
  "updated",
@@ -29,28 +17,6 @@ const CHIMERA_COLLECTION_UPDATE_EVENTS = [
29
17
  "selfItemDeleted",
30
18
  "error"
31
19
  ];
32
- const useChimeraCollection = (entityName, params, deps) => {
33
- const [, trigger] = useState(() => ({}));
34
- const repository = useChimeraRepository(entityName);
35
- const oldDeps = useRef(deps);
36
- if (oldDeps.current && !deps || !oldDeps.current && deps) console.warn("useChimeraCollection deps is not a reactive param!\nUse deps if you want to control dependencies manually.\nOmit it if you already have a stable reference to params");
37
- oldDeps.current = deps;
38
- const memeParams = useMemo(() => {
39
- if (typeof params !== "function") return params;
40
- const q = new ChimeraQueryBuilder();
41
- params(q);
42
- return q.build();
43
- }, deps ? deps : [params]);
44
- const collection = useMemo(() => repository.getCollection(memeParams), [repository, memeParams]);
45
- useEffect(() => {
46
- const handler = () => trigger({});
47
- for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.on(event, handler);
48
- return () => {
49
- for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.off(event, handler);
50
- };
51
- }, [collection]);
52
- return collection;
53
- };
54
20
  const CHIMERA_ITEM_UPDATE_EVENTS = [
55
21
  "initialized",
56
22
  "selfCreated",
@@ -61,32 +27,43 @@ const CHIMERA_ITEM_UPDATE_EVENTS = [
61
27
  "selfDeleted",
62
28
  "error"
63
29
  ];
64
- const useChimeraItem = (entityName, id, meta) => {
65
- const [, trigger] = useState(() => ({}));
66
- const item = useChimeraRepository(entityName).getItem(id, meta);
67
- useEffect(() => {
68
- const handler = () => trigger({});
69
- for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.on(event, handler);
70
- return () => {
71
- for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.off(event, handler);
72
- };
73
- }, [item]);
74
- return item;
75
- };
76
- function getChimeraTypedHooks(withoutPrefix) {
77
- return withoutPrefix ? {
78
- useCollection: useChimeraCollection,
79
- useItem: useChimeraItem,
80
- useRepository: useChimeraRepository,
81
- useStore: useChimeraStore
82
- } : {
83
- useChimeraCollection,
84
- useChimeraItem,
30
+ const createChimeraHooks = (store) => {
31
+ const useChimeraRepository = (entityName) => useMemo(() => store.from(entityName), [entityName]);
32
+ return {
33
+ useChimeraStore: () => store,
85
34
  useChimeraRepository,
86
- useChimeraStore
35
+ useChimeraCollection: (entityName, params, deps) => {
36
+ const [, trigger] = useState(() => ({}));
37
+ const repository = useChimeraRepository(entityName);
38
+ const oldDeps = useRef(deps);
39
+ if (oldDeps.current && !deps || !oldDeps.current && deps) console.warn("useChimeraCollection deps is not a reactive param!\nUse deps if you want to control dependencies manually.\nOmit it if you already have a stable reference to params");
40
+ oldDeps.current = deps;
41
+ const memeParams = useMemo(() => normalizeParams(params), deps ? deps : [params]);
42
+ const collection = useMemo(() => repository.getCollection(memeParams), [repository, memeParams]);
43
+ useEffect(() => {
44
+ const handler = () => trigger({});
45
+ for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.on(event, handler);
46
+ return () => {
47
+ for (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) collection.off(event, handler);
48
+ };
49
+ }, [collection]);
50
+ return collection;
51
+ },
52
+ useChimeraItem: (entityName, id, meta) => {
53
+ const [, trigger] = useState(() => ({}));
54
+ const item = useChimeraRepository(entityName).getItem(id, meta);
55
+ useEffect(() => {
56
+ const handler = () => trigger({});
57
+ for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.on(event, handler);
58
+ return () => {
59
+ for (const event of CHIMERA_ITEM_UPDATE_EVENTS) item.off(event, handler);
60
+ };
61
+ }, [item]);
62
+ return item;
63
+ }
87
64
  };
88
- }
65
+ };
89
66
 
90
67
  //#endregion
91
- export { ChimeraStoreContext, ChimeraStoreProvider, getChimeraTypedHooks, useChimeraCollection, useChimeraItem, useChimeraRepository, useChimeraStore };
68
+ export { createChimeraHooks };
92
69
  //# sourceMappingURL=react.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.js","names":[],"sources":["../../packages/adapters/react/context.tsx","../../packages/adapters/react/hooks.ts"],"sourcesContent":["import { createContext, type ReactNode, useMemo } from \"react\";\nimport type { AnyChimeraStore } from \"../../../src/store\";\n\nexport interface ChimeraStoreContextValue<T extends AnyChimeraStore> {\n\tstore: T;\n}\n\nexport interface ChimeraStoreProviderProps<T extends AnyChimeraStore> {\n\tchildren: ReactNode;\n\tstore: T;\n}\n\nexport const ChimeraStoreContext = createContext<ChimeraStoreContextValue<AnyChimeraStore> | null>(null);\n\nexport const ChimeraStoreProvider = <T extends AnyChimeraStore>({ children, store }: ChimeraStoreProviderProps<T>) => (\n\t<ChimeraStoreContext.Provider value={useMemo(() => ({ store }), [store])}>{children}</ChimeraStoreContext.Provider>\n);\n","import { useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ChimeraCollectionQuery } from \"../../../src/query/ChimeraCollectionQuery\";\nimport type { ChimeraItemQuery } from \"../../../src/query/ChimeraItemQuery\";\nimport type { ChimeraEntityId } from \"../../../src/shared/types\";\nimport type { ChimeraEntityRepository } from \"../../../src/store/ChimeraEntityRepository\";\nimport type {\n\tAnyChimeraStore,\n\tChimeraStoreEntities,\n\tChimeraStoreEntityType,\n\tChimeraStoreOperatorMap,\n} from \"../../../src/store/ChimeraStore\";\nimport type { ChimeraCollectionParams } from \"../../../src/store/types\";\nimport { ChimeraQueryBuilder, type QueryBuilderCreator } from \"../../qb\";\nimport { ChimeraStoreContext } from \"./context\";\n\nexport function useChimeraStore<T extends AnyChimeraStore>(): T {\n\tconst context = useContext(ChimeraStoreContext);\n\tif (!context) {\n\t\tthrow new Error(\"useChimeraStore must be used within a ChimeraStoreProvider\");\n\t}\n\treturn context.store as T;\n}\n\nexport function useChimeraRepository<T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>>(\n\tentityName: EntityName,\n): ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>> {\n\tconst store = useChimeraStore<T>();\n\treturn store.from(entityName);\n}\n\nconst CHIMERA_COLLECTION_UPDATE_EVENTS = [\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"selfItemCreated\",\n\t\"itemAdded\",\n\t\"itemUpdated\",\n\t\"selfItemUpdated\",\n\t\"itemDeleted\",\n\t\"selfItemDeleted\",\n\t\"error\",\n] as const;\nexport const useChimeraCollection = <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\tentityName: EntityName,\n\tparams:\n\t\t| ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>\n\t\t| QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>,\n\tdeps?: unknown[],\n): ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>> => {\n\tconst [, trigger] = useState(() => ({}));\n\n\tconst repository = useChimeraRepository<T, EntityName>(entityName);\n\n\tconst oldDeps = useRef(deps);\n\tif ((oldDeps.current && !deps) || (!oldDeps.current && deps)) {\n\t\tconsole.warn(\n\t\t\t\"useChimeraCollection deps is not a reactive param!\\n\" +\n\t\t\t\t\"Use deps if you want to control dependencies manually.\\n\" +\n\t\t\t\t\"Omit it if you already have a stable reference to params\",\n\t\t);\n\t}\n\toldDeps.current = deps;\n\n\tconst memeParams = useMemo(\n\t\t() => {\n\t\t\tif (typeof params !== \"function\") return params;\n\n\t\t\tconst q = new ChimeraQueryBuilder();\n\t\t\tparams(q);\n\t\t\treturn q.build();\n\t\t},\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: Very unlikely it will be changed over time, anyway warning for this already added.\n\t\tdeps ? deps : [params],\n\t);\n\tconst collection = useMemo(() => repository.getCollection(memeParams), [repository, memeParams]);\n\n\tuseEffect(() => {\n\t\tconst handler = () => trigger({});\n\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\tcollection.on(event, handler);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\t\tcollection.off(event, handler);\n\t\t\t}\n\t\t};\n\t}, [collection]);\n\n\treturn collection;\n};\n\nconst CHIMERA_ITEM_UPDATE_EVENTS = [\n\t\"initialized\",\n\t\"selfCreated\",\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"deleted\",\n\t\"selfDeleted\",\n\t\"error\",\n] as const;\nexport const useChimeraItem = <T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\tentityName: EntityName,\n\tid: ChimeraEntityId,\n\tmeta?: Meta,\n): ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>> => {\n\tconst [, trigger] = useState(() => ({}));\n\n\tconst repository = useChimeraRepository<T, EntityName>(entityName);\n\tconst item = repository.getItem(id, meta);\n\n\tuseEffect(() => {\n\t\tconst handler = () => trigger({});\n\t\tfor (const event of CHIMERA_ITEM_UPDATE_EVENTS) {\n\t\t\titem.on(event, handler);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const event of CHIMERA_ITEM_UPDATE_EVENTS) {\n\t\t\t\titem.off(event, handler);\n\t\t\t}\n\t\t};\n\t}, [item]);\n\n\treturn item;\n};\n\nexport function getChimeraTypedHooks<T extends AnyChimeraStore>(\n\twithoutPrefix: true,\n): {\n\tuseStore: () => T;\n\tuseRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\tentityName: EntityName,\n\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tparams: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>,\n\t\tdeps?: unknown[],\n\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tid: ChimeraEntityId,\n\t\tmeta?: Meta,\n\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n};\nexport function getChimeraTypedHooks<T extends AnyChimeraStore>(\n\twithoutPrefix?: false,\n): {\n\tuseChimeraStore: () => T;\n\tuseChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\tentityName: EntityName,\n\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tparams:\n\t\t\t| ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>\n\t\t\t| QueryBuilderCreator<T, ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>,\n\t\tdeps?: unknown[],\n\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tid: ChimeraEntityId,\n\t\tmeta?: Meta,\n\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n};\nexport function getChimeraTypedHooks<T extends AnyChimeraStore>(\n\twithoutPrefix?: boolean,\n):\n\t| {\n\t\t\tuseChimeraStore: () => T;\n\t\t\tuseChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\t\t\tentityName: EntityName,\n\t\t\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tparams: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>,\n\t\t\t\tdeps?: unknown[],\n\t\t\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tid: ChimeraEntityId,\n\t\t\t\tmeta?: Meta,\n\t\t\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n\t }\n\t| {\n\t\t\tuseStore: () => T;\n\t\t\tuseRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\t\t\tentityName: EntityName,\n\t\t\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tparams: ChimeraCollectionParams<ChimeraStoreOperatorMap<T>, ChimeraStoreEntityType<T, EntityName>, Meta>,\n\t\t\t\tdeps?: unknown[],\n\t\t\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\t\t\tuseItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\t\t\tentityName: EntityName,\n\t\t\t\tid: ChimeraEntityId,\n\t\t\t\tmeta?: Meta,\n\t\t\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n\t } {\n\treturn (\n\t\twithoutPrefix\n\t\t\t? {\n\t\t\t\t\tuseCollection: useChimeraCollection,\n\t\t\t\t\tuseItem: useChimeraItem,\n\t\t\t\t\tuseRepository: useChimeraRepository,\n\t\t\t\t\tuseStore: useChimeraStore,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tuseChimeraCollection,\n\t\t\t\t\tuseChimeraItem,\n\t\t\t\t\tuseChimeraRepository,\n\t\t\t\t\tuseChimeraStore,\n\t\t\t\t}\n\t) as ReturnType<typeof getChimeraTypedHooks<T>>;\n}\n"],"mappings":";;;;;;AAYA,MAAa,sBAAsB,cAAgE,KAAK;AAExG,MAAa,wBAAmD,EAAE,UAAU,YAC3E,CAAC,oBAAoB,SAAS,OAAO,eAAe,EAAE,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,oBAAoB;;;;ACA3G,SAAgB,kBAAgD;CAC/D,MAAM,UAAU,WAAW,oBAAoB;AAC/C,KAAI,CAAC,QACJ,OAAM,IAAI,MAAM,6DAA6D;AAE9E,QAAO,QAAQ;;AAGhB,SAAgB,qBACf,YAC6F;AAE7F,QADc,iBAAoB,CACrB,KAAK,WAAW;;AAG9B,MAAM,mCAAmC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,MAAa,wBACZ,YACA,QAGA,SAC+F;CAC/F,MAAM,GAAG,WAAW,gBAAgB,EAAE,EAAE;CAExC,MAAM,aAAa,qBAAoC,WAAW;CAElE,MAAM,UAAU,OAAO,KAAK;AAC5B,KAAK,QAAQ,WAAW,CAAC,QAAU,CAAC,QAAQ,WAAW,KACtD,SAAQ,KACP,uKAGA;AAEF,SAAQ,UAAU;CAElB,MAAM,aAAa,cACZ;AACL,MAAI,OAAO,WAAW,WAAY,QAAO;EAEzC,MAAM,IAAI,IAAI,qBAAqB;AACnC,SAAO,EAAE;AACT,SAAO,EAAE,OAAO;IAGjB,OAAO,OAAO,CAAC,OAAO,CACtB;CACD,MAAM,aAAa,cAAc,WAAW,cAAc,WAAW,EAAE,CAAC,YAAY,WAAW,CAAC;AAEhG,iBAAgB;EACf,MAAM,gBAAgB,QAAQ,EAAE,CAAC;AACjC,OAAK,MAAM,SAAS,iCACnB,YAAW,GAAG,OAAO,QAAQ;AAE9B,eAAa;AACZ,QAAK,MAAM,SAAS,iCACnB,YAAW,IAAI,OAAO,QAAQ;;IAG9B,CAAC,WAAW,CAAC;AAEhB,QAAO;;AAGR,MAAM,6BAA6B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD,MAAa,kBACZ,YACA,IACA,SAC6D;CAC7D,MAAM,GAAG,WAAW,gBAAgB,EAAE,EAAE;CAGxC,MAAM,OADa,qBAAoC,WAAW,CAC1C,QAAQ,IAAI,KAAK;AAEzC,iBAAgB;EACf,MAAM,gBAAgB,QAAQ,EAAE,CAAC;AACjC,OAAK,MAAM,SAAS,2BACnB,MAAK,GAAG,OAAO,QAAQ;AAExB,eAAa;AACZ,QAAK,MAAM,SAAS,2BACnB,MAAK,IAAI,OAAO,QAAQ;;IAGxB,CAAC,KAAK,CAAC;AAEV,QAAO;;AAyCR,SAAgB,qBACf,eAiCI;AACJ,QACC,gBACG;EACA,eAAe;EACf,SAAS;EACT,eAAe;EACf,UAAU;EACV,GACA;EACA;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"react.js","names":[],"sources":["../../packages/adapters/react/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ChimeraCollectionQuery } from \"../../../src/query/ChimeraCollectionQuery\";\nimport type { ChimeraItemQuery } from \"../../../src/query/ChimeraItemQuery\";\nimport type { ChimeraEntityId } from \"../../../src/shared/types\";\nimport type { ChimeraEntityRepository } from \"../../../src/store/ChimeraEntityRepository\";\nimport type {\n\tAnyChimeraStore,\n\tChimeraStoreEntities,\n\tChimeraStoreEntityType,\n\tChimeraStoreOperatorMap,\n} from \"../../../src/store/ChimeraStore\";\nimport { type AnyChimeraParams, normalizeParams } from \"../shared/params\";\n\nconst CHIMERA_COLLECTION_UPDATE_EVENTS = [\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"selfItemCreated\",\n\t\"itemAdded\",\n\t\"itemUpdated\",\n\t\"selfItemUpdated\",\n\t\"itemDeleted\",\n\t\"selfItemDeleted\",\n\t\"error\",\n] as const;\n\nconst CHIMERA_ITEM_UPDATE_EVENTS = [\n\t\"initialized\",\n\t\"selfCreated\",\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"deleted\",\n\t\"selfDeleted\",\n\t\"error\",\n] as const;\n\nexport const createChimeraHooks = <T extends AnyChimeraStore>(\n\tstore: T,\n): {\n\tuseChimeraStore: () => T;\n\tuseChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\tentityName: EntityName,\n\t) => ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tparams: AnyChimeraParams<T, EntityName, Meta>,\n\t\tdeps?: unknown[],\n\t) => ChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>;\n\tuseChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: EntityName,\n\t\tid: ChimeraEntityId,\n\t\tmeta?: Meta,\n\t) => ChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>;\n} => {\n\tconst useChimeraRepository = <EntityName extends ChimeraStoreEntities<T>>(entityName: EntityName) =>\n\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: this hook is generated for a specific store so it never changes\n\t\tuseMemo(() => store.from(entityName), [entityName]);\n\n\treturn {\n\t\tuseChimeraStore: () => store,\n\t\tuseChimeraRepository,\n\t\tuseChimeraCollection: (entityName, params, deps?) => {\n\t\t\tconst [, trigger] = useState(() => ({}));\n\n\t\t\tconst repository = useChimeraRepository(entityName);\n\n\t\t\tconst oldDeps = useRef(deps);\n\t\t\tif ((oldDeps.current && !deps) || (!oldDeps.current && deps)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"useChimeraCollection deps is not a reactive param!\\n\" +\n\t\t\t\t\t\t\"Use deps if you want to control dependencies manually.\\n\" +\n\t\t\t\t\t\t\"Omit it if you already have a stable reference to params\",\n\t\t\t\t);\n\t\t\t}\n\t\t\toldDeps.current = deps;\n\n\t\t\tconst memeParams = useMemo(\n\t\t\t\t() => normalizeParams(params),\n\t\t\t\t// biome-ignore lint/correctness/useExhaustiveDependencies: Very unlikely it will be changed over time, anyway warning for this already added.\n\t\t\t\tdeps ? deps : [params],\n\t\t\t);\n\t\t\tconst collection = useMemo(() => repository.getCollection(memeParams), [repository, memeParams]);\n\n\t\t\tuseEffect(() => {\n\t\t\t\tconst handler = () => trigger({});\n\t\t\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\t\t\tcollection.on(event, handler);\n\t\t\t\t}\n\t\t\t\treturn () => {\n\t\t\t\t\tfor (const event of CHIMERA_COLLECTION_UPDATE_EVENTS) {\n\t\t\t\t\t\tcollection.off(event, handler);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}, [collection]);\n\n\t\t\treturn collection;\n\t\t},\n\t\tuseChimeraItem: (entityName, id, meta?) => {\n\t\t\tconst [, trigger] = useState(() => ({}));\n\n\t\t\tconst repository = useChimeraRepository(entityName);\n\t\t\tconst item = repository.getItem(id, meta);\n\n\t\t\tuseEffect(() => {\n\t\t\t\tconst handler = () => trigger({});\n\t\t\t\tfor (const event of CHIMERA_ITEM_UPDATE_EVENTS) {\n\t\t\t\t\titem.on(event, handler);\n\t\t\t\t}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;IACf,MAAM,gBAAgB,QAAQ,EAAE,CAAC;AACjC,SAAK,MAAM,SAAS,2BACnB,MAAK,GAAG,OAAO,QAAQ;AAExB,iBAAa;AACZ,UAAK,MAAM,SAAS,2BACnB,MAAK,IAAI,OAAO,QAAQ;;MAGxB,CAAC,KAAK,CAAC;AAEV,UAAO;;EAER"}
@@ -0,0 +1,92 @@
1
+ const require_params = require('../params-C5dnCvJr.cjs');
2
+ require('../defaults-C48gY1ow.cjs');
3
+ require('../src-YxpDmKvq.cjs');
4
+ require('../qb-D6vPK6P0.cjs');
5
+ let vue = require("vue");
6
+ vue = require_params.__toESM(vue);
7
+
8
+ //#region packages/adapters/vue/composables.ts
9
+ const isFunction = (value) => typeof value === "function";
10
+ const toValue = (value) => isFunction(value) ? value() : (0, vue.isRef)(value) ? value.value : value;
11
+ const CHIMERA_COLLECTION_UPDATE_EVENTS = [
12
+ "ready",
13
+ "updated",
14
+ "selfUpdated",
15
+ "selfItemCreated",
16
+ "itemAdded",
17
+ "itemUpdated",
18
+ "selfItemUpdated",
19
+ "itemDeleted",
20
+ "selfItemDeleted",
21
+ "error"
22
+ ];
23
+ const CHIMERA_ITEM_UPDATE_EVENTS = [
24
+ "initialized",
25
+ "selfCreated",
26
+ "ready",
27
+ "updated",
28
+ "selfUpdated",
29
+ "deleted",
30
+ "selfDeleted",
31
+ "error"
32
+ ];
33
+ const createChimeraComposables = (store) => {
34
+ const useChimeraRepository = (entityName) => (0, vue.computed)(() => store.from(toValue(entityName)));
35
+ return {
36
+ useChimeraStore: () => store,
37
+ useChimeraRepository,
38
+ useChimeraCollection: (entityName, params) => {
39
+ const repository = useChimeraRepository(entityName);
40
+ const normalizedParams = (0, vue.computed)(() => require_params.normalizeParams(toValue(params)));
41
+ const collection = (0, vue.computed)(() => repository.value.getCollection(normalizedParams.value));
42
+ return (0, vue.customRef)((track, trigger) => {
43
+ (0, vue.watch)(collection, (collection$1, _, onCleanup) => {
44
+ const handler = () => trigger();
45
+ CHIMERA_COLLECTION_UPDATE_EVENTS.forEach((event) => {
46
+ collection$1.on(event, handler);
47
+ });
48
+ onCleanup(() => CHIMERA_COLLECTION_UPDATE_EVENTS.forEach((event) => {
49
+ collection$1.off(event, handler);
50
+ }));
51
+ }, { immediate: true });
52
+ return {
53
+ get() {
54
+ track();
55
+ return collection.value;
56
+ },
57
+ set() {
58
+ console.warn("ChimeraCollectionRef is readonly");
59
+ }
60
+ };
61
+ });
62
+ },
63
+ useChimeraItem: (entityName, id, meta) => {
64
+ const repository = useChimeraRepository(entityName);
65
+ const item = (0, vue.computed)(() => repository.value.getItem(toValue(id), toValue(meta)));
66
+ return (0, vue.customRef)((track, trigger) => {
67
+ (0, vue.watch)(item, (item$1, _, onCleanup) => {
68
+ const handler = () => trigger();
69
+ CHIMERA_ITEM_UPDATE_EVENTS.forEach((event) => {
70
+ item$1.on(event, handler);
71
+ });
72
+ onCleanup(() => CHIMERA_ITEM_UPDATE_EVENTS.forEach((event) => {
73
+ item$1.off(event, handler);
74
+ }));
75
+ }, { immediate: true });
76
+ return {
77
+ get() {
78
+ track();
79
+ return item.value;
80
+ },
81
+ set() {
82
+ console.warn("ChimeraItemRef is readonly");
83
+ }
84
+ };
85
+ });
86
+ }
87
+ };
88
+ };
89
+
90
+ //#endregion
91
+ exports.createChimeraComposables = createChimeraComposables;
92
+ //# sourceMappingURL=vue.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.cjs","names":["normalizeParams"],"sources":["../../packages/adapters/vue/composables.ts"],"sourcesContent":["import { computed, customRef, isRef, type Ref, watch } from \"vue\";\nimport type {\n\tAnyChimeraStore,\n\tChimeraCollectionQuery,\n\tChimeraEntityId,\n\tChimeraItemQuery,\n\tChimeraStoreEntities,\n\tChimeraStoreEntityType,\n\tChimeraStoreOperatorMap,\n} from \"../../../src\";\nimport type { ChimeraEntityRepository } from \"../../../src/store/ChimeraEntityRepository\";\nimport { type AnyChimeraParams, normalizeParams } from \"../shared/params\";\n\ntype MaybeRef<T> = T | Ref<T>;\ntype MaybeRefOrGetter<T> = MaybeRef<T> | (() => T);\n\nconst isFunction = (value: any): value is () => any => typeof value === \"function\";\nconst toValue = <T>(value: MaybeRefOrGetter<T>): T =>\n\tisFunction(value) ? value() : isRef(value) ? value.value : value;\n\nconst CHIMERA_COLLECTION_UPDATE_EVENTS = [\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"selfItemCreated\",\n\t\"itemAdded\",\n\t\"itemUpdated\",\n\t\"selfItemUpdated\",\n\t\"itemDeleted\",\n\t\"selfItemDeleted\",\n\t\"error\",\n] as const;\n\nconst CHIMERA_ITEM_UPDATE_EVENTS = [\n\t\"initialized\",\n\t\"selfCreated\",\n\t\"ready\",\n\t\"updated\",\n\t\"selfUpdated\",\n\t\"deleted\",\n\t\"selfDeleted\",\n\t\"error\",\n] as const;\n\nexport type ChimeraCollectionRef<T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>> = Ref<\n\tChimeraCollectionQuery<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>\n>;\n\nexport type ChimeraItemRef<T extends AnyChimeraStore, EntityName extends ChimeraStoreEntities<T>> = Ref<\n\tChimeraItemQuery<ChimeraStoreEntityType<T, EntityName>>\n>;\n\nexport const createChimeraComposables = <T extends AnyChimeraStore>(\n\tstore: T,\n): {\n\tuseChimeraStore: () => T;\n\tuseChimeraRepository: <EntityName extends ChimeraStoreEntities<T>>(\n\t\tentityName: MaybeRefOrGetter<EntityName>,\n\t) => Ref<ChimeraEntityRepository<ChimeraStoreEntityType<T, EntityName>, ChimeraStoreOperatorMap<T>>>;\n\tuseChimeraCollection: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: MaybeRefOrGetter<EntityName>,\n\t\tparams: MaybeRefOrGetter<AnyChimeraParams<T, EntityName, Meta>>,\n\t) => ChimeraCollectionRef<T, EntityName>;\n\tuseChimeraItem: <EntityName extends ChimeraStoreEntities<T>, Meta = any>(\n\t\tentityName: MaybeRefOrGetter<EntityName>,\n\t\tid: MaybeRefOrGetter<ChimeraEntityId>,\n\t\tmeta?: MaybeRefOrGetter<Meta>,\n\t) => ChimeraItemRef<T, EntityName>;\n} => {\n\tconst useChimeraRepository = <EntityName extends ChimeraStoreEntities<T>>(entityName: MaybeRefOrGetter<EntityName>) =>\n\t\tcomputed(() => store.from(toValue(entityName)));\n\n\treturn {\n\t\tuseChimeraStore: () => store,\n\t\tuseChimeraRepository,\n\t\tuseChimeraCollection: (entityName, params) => {\n\t\t\tconst repository = useChimeraRepository(entityName);\n\t\t\tconst normalizedParams = computed(() => normalizeParams(toValue(params)));\n\t\t\tconst collection = computed(() => repository.value.getCollection(normalizedParams.value));\n\n\t\t\treturn customRef((track, trigger) => {\n\t\t\t\twatch(\n\t\t\t\t\tcollection,\n\t\t\t\t\t(collection, _, onCleanup) => {\n\t\t\t\t\t\tconst handler = () => trigger();\n\t\t\t\t\t\tCHIMERA_COLLECTION_UPDATE_EVENTS.forEach((event) => {\n\t\t\t\t\t\t\tcollection.on(event, handler);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tonCleanup(() =>\n\t\t\t\t\t\t\tCHIMERA_COLLECTION_UPDATE_EVENTS.forEach((event) => {\n\t\t\t\t\t\t\t\tcollection.off(event, handler);\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\t{ immediate: true },\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\tget() {\n\t\t\t\t\t\ttrack();\n\t\t\t\t\t\treturn collection.value;\n\t\t\t\t\t},\n\t\t\t\t\tset() {\n\t\t\t\t\t\tconsole.warn(\"ChimeraCollectionRef is readonly\");\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\tuseChimeraItem: (entityName, id, meta) => {\n\t\t\tconst repository = useChimeraRepository(entityName);\n\t\t\tconst item = computed(() => repository.value.getItem(toValue(id), toValue(meta)));\n\n\t\t\treturn customRef((track, trigger) => {\n\t\t\t\twatch(\n\t\t\t\t\titem,\n\t\t\t\t\t(item, _, onCleanup) => {\n\t\t\t\t\t\tconst handler = () => trigger();\n\t\t\t\t\t\tCHIMERA_ITEM_UPDATE_EVENTS.forEach((event) => {\n\t\t\t\t\t\t\titem.on(event, handler);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tonCleanup(() =>\n\t\t\t\t\t\t\tCHIMERA_ITEM_UPDATE_EVENTS.forEach((event) => {\n\t\t\t\t\t\t\t\titem.off(event, handler);\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\t{ immediate: true },\n\t\t\t\t);\n\n\t\t\t\treturn {\n\t\t\t\t\tget() {\n\t\t\t\t\t\ttrack();\n\t\t\t\t\t\treturn item.value;\n\t\t\t\t\t},\n\t\t\t\t\tset() {\n\t\t\t\t\t\tconsole.warn(\"ChimeraItemRef is readonly\");\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;AAgBA,MAAM,cAAc,UAAmC,OAAO,UAAU;AACxE,MAAM,WAAc,UACnB,WAAW,MAAM,GAAG,OAAO,kBAAS,MAAM,GAAG,MAAM,QAAQ;AAE5D,MAAM,mCAAmC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAED,MAAM,6BAA6B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAUD,MAAa,4BACZ,UAeI;CACJ,MAAM,wBAAoE,uCAC1D,MAAM,KAAK,QAAQ,WAAW,CAAC,CAAC;AAEhD,QAAO;EACN,uBAAuB;EACvB;EACA,uBAAuB,YAAY,WAAW;GAC7C,MAAM,aAAa,qBAAqB,WAAW;GACnD,MAAM,2CAAkCA,+BAAgB,QAAQ,OAAO,CAAC,CAAC;GACzE,MAAM,qCAA4B,WAAW,MAAM,cAAc,iBAAiB,MAAM,CAAC;AAEzF,8BAAkB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