@astral/mobx-query 1.8.1 → 1.10.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 (58) hide show
  1. package/MobxQuery/MobxQuery.d.ts +44 -0
  2. package/MobxQuery/MobxQuery.js +48 -0
  3. package/README.md +1048 -287
  4. package/Sets/InfiniteQuerySet/InfiniteQuerySet.d.ts +60 -0
  5. package/Sets/InfiniteQuerySet/InfiniteQuerySet.js +71 -0
  6. package/Sets/InfiniteQuerySet/index.d.ts +1 -0
  7. package/Sets/InfiniteQuerySet/index.js +1 -0
  8. package/Sets/MutationSet/MutationSet.d.ts +32 -0
  9. package/Sets/MutationSet/MutationSet.js +31 -0
  10. package/Sets/MutationSet/index.d.ts +1 -0
  11. package/Sets/MutationSet/index.js +1 -0
  12. package/Sets/QuerySet/QuerySet.d.ts +64 -0
  13. package/Sets/QuerySet/QuerySet.js +72 -0
  14. package/Sets/QuerySet/index.d.ts +1 -0
  15. package/Sets/QuerySet/index.js +1 -0
  16. package/Sets/index.d.ts +3 -0
  17. package/Sets/index.js +3 -0
  18. package/Sets/utils/generateQuerySetBaseKey/generateQuerySetBaseKey.d.ts +4 -0
  19. package/Sets/utils/generateQuerySetBaseKey/generateQuerySetBaseKey.js +5 -0
  20. package/Sets/utils/generateQuerySetBaseKey/index.d.ts +1 -0
  21. package/Sets/utils/generateQuerySetBaseKey/index.js +1 -0
  22. package/Sets/utils/generateQuerySetKeys/generateQuerySetKeys.d.ts +9 -0
  23. package/Sets/utils/generateQuerySetKeys/generateQuerySetKeys.js +20 -0
  24. package/Sets/utils/generateQuerySetKeys/index.d.ts +1 -0
  25. package/Sets/utils/generateQuerySetKeys/index.js +1 -0
  26. package/Sets/utils/index.d.ts +2 -0
  27. package/Sets/utils/index.js +2 -0
  28. package/index.d.ts +2 -1
  29. package/index.js +1 -0
  30. package/node/MobxQuery/MobxQuery.d.ts +44 -0
  31. package/node/MobxQuery/MobxQuery.js +48 -0
  32. package/node/Sets/InfiniteQuerySet/InfiniteQuerySet.d.ts +60 -0
  33. package/node/Sets/InfiniteQuerySet/InfiniteQuerySet.js +75 -0
  34. package/node/Sets/InfiniteQuerySet/index.d.ts +1 -0
  35. package/node/Sets/InfiniteQuerySet/index.js +17 -0
  36. package/node/Sets/MutationSet/MutationSet.d.ts +32 -0
  37. package/node/Sets/MutationSet/MutationSet.js +35 -0
  38. package/node/Sets/MutationSet/index.d.ts +1 -0
  39. package/node/Sets/MutationSet/index.js +17 -0
  40. package/node/Sets/QuerySet/QuerySet.d.ts +64 -0
  41. package/node/Sets/QuerySet/QuerySet.js +76 -0
  42. package/node/Sets/QuerySet/index.d.ts +1 -0
  43. package/node/Sets/QuerySet/index.js +17 -0
  44. package/node/Sets/index.d.ts +3 -0
  45. package/node/Sets/index.js +19 -0
  46. package/node/Sets/utils/generateQuerySetBaseKey/generateQuerySetBaseKey.d.ts +4 -0
  47. package/node/Sets/utils/generateQuerySetBaseKey/generateQuerySetBaseKey.js +12 -0
  48. package/node/Sets/utils/generateQuerySetBaseKey/index.d.ts +1 -0
  49. package/node/Sets/utils/generateQuerySetBaseKey/index.js +17 -0
  50. package/node/Sets/utils/generateQuerySetKeys/generateQuerySetKeys.d.ts +9 -0
  51. package/node/Sets/utils/generateQuerySetKeys/generateQuerySetKeys.js +24 -0
  52. package/node/Sets/utils/generateQuerySetKeys/index.d.ts +1 -0
  53. package/node/Sets/utils/generateQuerySetKeys/index.js +17 -0
  54. package/node/Sets/utils/index.d.ts +2 -0
  55. package/node/Sets/utils/index.js +18 -0
  56. package/node/index.d.ts +2 -1
  57. package/node/index.js +3 -1
  58. package/package.json +5 -2
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfiniteQuerySet = void 0;
4
+ const utils_1 = require("../utils");
5
+ /**
6
+ * Набор infinite queries под одним ключем с целью повышения читаемости кода и удобства инвалидации по общему ключу
7
+ */
8
+ class InfiniteQuerySet {
9
+ constructor(_cache, _queryConfigurator, config) {
10
+ var _a;
11
+ this._cache = _cache;
12
+ this._queryConfigurator = _queryConfigurator;
13
+ /**
14
+ * Создает infinite query в кэше. Добавляет его в набор
15
+ * @returns InfiniteQuery объект
16
+ * @example
17
+ * const docListQuery = docFetcher.infiniteQueries.docList.create()
18
+ * // Получает данные
19
+ * docListQuery.sync()
20
+ */
21
+ this.create = (...params) => {
22
+ const { keys, execute } = this.configureQuery(...params);
23
+ return this._cache.createInfiniteQuery(keys, execute);
24
+ };
25
+ /**
26
+ * Создает infinite query в кэше с дополнительными параметрами конфигурации. Добавляет его в набор
27
+ * @param config - Параметры конфигурации infinite query. Например, fetchPolicy или incrementCount
28
+ * @param params - Параметры запроса
29
+ * @returns InfiniteQuery объект
30
+ * @example
31
+ * const docListQuery = docFetcher.infiniteQueries.docList.createWithConfig(
32
+ * { fetchPolicy: 'network-only', incrementCount: 10 },
33
+ * 'docId',
34
+ * )
35
+ * // Получает данные из query
36
+ * docListQuery.sync()
37
+ */
38
+ this.createWithConfig = (config, ...params) => {
39
+ const { keys, execute } = this.configureQuery(...params);
40
+ return this._cache.createInfiniteQuery(keys, execute, config);
41
+ };
42
+ /**
43
+ * Инвалидирует текущий набор infinite queries в кэше
44
+ * @param params - Параметры функции, переданной в createInfiniteQuerySet при создании набора. Если не указаны, то инвалидируется все query
45
+ * @example
46
+ * const docFetcher = {
47
+ * infiniteQueries: {
48
+ * docList: createInfiniteQuerySet('docList', (search: string) => ({
49
+ * execute: ({ count, offset }) => httpService.get(`/doc/${search}?count=${count}&offset=${offset}`),
50
+ * }),
51
+ * }
52
+ * };
53
+ *
54
+ * // Инвалидирует infinite query с конкретным переданным search
55
+ * docFetcher.infiniteQueries.docList.invalidate('документ1')
56
+ */
57
+ this.invalidate = (...params) => {
58
+ if (params.length === 0) {
59
+ this._cache.invalidate([this.baseKey]);
60
+ return;
61
+ }
62
+ const { keys } = this.configureQuery(...params);
63
+ this._cache.invalidate(keys, 'chain-match');
64
+ };
65
+ this.configureQuery = (...params) => {
66
+ const { keys, execute } = this._queryConfigurator(...params);
67
+ return {
68
+ keys: (0, utils_1.generateQuerySetKeys)(this.baseKey, keys !== null && keys !== void 0 ? keys : params),
69
+ execute,
70
+ };
71
+ };
72
+ this.baseKey = (_a = config === null || config === void 0 ? void 0 : config.name) !== null && _a !== void 0 ? _a : (0, utils_1.generateQuerySetBaseKey)(_queryConfigurator);
73
+ }
74
+ }
75
+ exports.InfiniteQuerySet = InfiniteQuerySet;
@@ -0,0 +1 @@
1
+ export * from './InfiniteQuerySet';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./InfiniteQuerySet"), exports);
@@ -0,0 +1,32 @@
1
+ import { type MobxQuery } from '../../MobxQuery';
2
+ import { type Mutation, type MutationExecutor } from '../../Mutation';
3
+ /**
4
+ * Налор мутаций. Цель: единый интерфейс создания и использования наборов Query и Mutation
5
+ * @example
6
+ * const docFetcher = {
7
+ * mutations: {
8
+ * editDoc: mobxQuery.createMutationSet((params: DocsEndpointsDTO.EditDocInput) => {
9
+ * return docsEndpoint.editDoc(params);
10
+ * }),
11
+ * },
12
+ * queries: {
13
+ * doc: mobxQuery.createQuerySet((id: string) => ({
14
+ * execute: () => docsEndpoint.getDoc(id).then(({ data }) => data),
15
+ * })),
16
+ * },
17
+ * }
18
+ */
19
+ export declare class MutationSet<TResponse, TParams = void, TDefaultError = unknown> {
20
+ private readonly _cache;
21
+ private readonly _executor;
22
+ constructor(_cache: MobxQuery, _executor: MutationExecutor<TResponse, TParams>);
23
+ /**
24
+ * Создает мутацию
25
+ * @returns Mutation объект
26
+ * @example
27
+ * const editDocMutation = docFetcher.mutations.editDoc.create();
28
+ * // Выполняет мутацию
29
+ * editDocMutation.sync({ params: { id: 'docId', content: 'Новое содержимое' } });
30
+ */
31
+ create: <TError = TDefaultError>() => Mutation<TResponse, TError, TParams>;
32
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MutationSet = void 0;
4
+ /**
5
+ * Налор мутаций. Цель: единый интерфейс создания и использования наборов Query и Mutation
6
+ * @example
7
+ * const docFetcher = {
8
+ * mutations: {
9
+ * editDoc: mobxQuery.createMutationSet((params: DocsEndpointsDTO.EditDocInput) => {
10
+ * return docsEndpoint.editDoc(params);
11
+ * }),
12
+ * },
13
+ * queries: {
14
+ * doc: mobxQuery.createQuerySet((id: string) => ({
15
+ * execute: () => docsEndpoint.getDoc(id).then(({ data }) => data),
16
+ * })),
17
+ * },
18
+ * }
19
+ */
20
+ class MutationSet {
21
+ constructor(_cache, _executor) {
22
+ this._cache = _cache;
23
+ this._executor = _executor;
24
+ /**
25
+ * Создает мутацию
26
+ * @returns Mutation объект
27
+ * @example
28
+ * const editDocMutation = docFetcher.mutations.editDoc.create();
29
+ * // Выполняет мутацию
30
+ * editDocMutation.sync({ params: { id: 'docId', content: 'Новое содержимое' } });
31
+ */
32
+ this.create = () => this._cache.createMutation(this._executor);
33
+ }
34
+ }
35
+ exports.MutationSet = MutationSet;
@@ -0,0 +1 @@
1
+ export * from './MutationSet';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./MutationSet"), exports);
@@ -0,0 +1,64 @@
1
+ import { type DeepPartial } from 'utility-types';
2
+ import { type CacheKey } from '../../types';
3
+ import { type Query } from '../../Query';
4
+ import { type CreateQueryParams, type MobxQuery } from '../../MobxQuery';
5
+ export type QuerySetConfig = {
6
+ name?: string;
7
+ };
8
+ export type QuerySetConfigurator<TParams extends any[], TResponse> = (...params: TParams) => {
9
+ keys?: CacheKey[];
10
+ execute: () => Promise<TResponse>;
11
+ };
12
+ /**
13
+ * Набор queries под одним ключем с целью повышения читаемости кода и удобства инвалидации по общему ключу
14
+ */
15
+ export declare class QuerySet<TParams extends any[], TResponse, TDefaultError = unknown> {
16
+ private readonly _cache;
17
+ private readonly _queryConfigurator;
18
+ /**
19
+ * Хэш от queryConfigurator
20
+ */
21
+ private readonly baseKey;
22
+ constructor(_cache: MobxQuery, _queryConfigurator: QuerySetConfigurator<TParams, TResponse>, config?: QuerySetConfig);
23
+ /**
24
+ * Создает query в кэше. Добавляет его в набор
25
+ * @returns Query объект
26
+ * @example
27
+ * const docQuery = docFetcher.queries.doc.create('docId')
28
+ * // Получает данные
29
+ * docQuery.sync()
30
+ */
31
+ create: <TError = TDefaultError>(...params: TParams) => Query<TResponse, TError>;
32
+ /**
33
+ * Создает query в кэше с дополнительными параметрами конфигурации. Добавляет его в набор
34
+ * @param config - Параметры конфигурации query. Например, fetchPolicy
35
+ * @param params - Параметры запроса
36
+ * @returns Query объект
37
+ * @example
38
+ * const docQuery = docFetcher.queries.doc.createWithConfig(
39
+ * { fetchPolicy: 'network-only' },
40
+ * 'docId',
41
+ * )
42
+ * // Получает данные из query
43
+ * docQuery.sync()
44
+ */
45
+ createWithConfig: <TError = TDefaultError, TIsBackground extends boolean = false>(config: CreateQueryParams<Awaited<TResponse>, TError, TIsBackground>, ...params: TParams) => Query<TResponse, TError, TIsBackground>;
46
+ /**
47
+ * Инвалидирует текущий query в кэше
48
+ * @param keys - Дополнительные ключи для инвалидации. Если не указаны, то инвалидируется весь набор query
49
+ * @example
50
+ * const docFetcher = {
51
+ * doc: mobxQuery.createQuerySet((id: string) => ({
52
+ * execute: () => httpService.get(`/doc/${id}?page=${page}`),
53
+ * })),
54
+ * };
55
+ *
56
+ * // Инвалидирует все query doc
57
+ * docFetcher.doc.invalidate()
58
+ *
59
+ * // Инвалидирует query doc с конкретным переданным id. Доступные ключи инвалидации зависят от указанных additionalKeys, переданных при определении query в фабрике createDataFetcher
60
+ * docFetcher.doc.invalidate('docId')
61
+ */
62
+ invalidate: (...params: DeepPartial<TParams>) => void;
63
+ private configureQuery;
64
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuerySet = void 0;
4
+ const utils_1 = require("../utils");
5
+ /**
6
+ * Набор queries под одним ключем с целью повышения читаемости кода и удобства инвалидации по общему ключу
7
+ */
8
+ class QuerySet {
9
+ constructor(_cache, _queryConfigurator, config) {
10
+ var _a;
11
+ this._cache = _cache;
12
+ this._queryConfigurator = _queryConfigurator;
13
+ /**
14
+ * Создает query в кэше. Добавляет его в набор
15
+ * @returns Query объект
16
+ * @example
17
+ * const docQuery = docFetcher.queries.doc.create('docId')
18
+ * // Получает данные
19
+ * docQuery.sync()
20
+ */
21
+ this.create = (...params) => {
22
+ const { keys, execute } = this.configureQuery(...params);
23
+ return this._cache.createQuery(keys, execute);
24
+ };
25
+ /**
26
+ * Создает query в кэше с дополнительными параметрами конфигурации. Добавляет его в набор
27
+ * @param config - Параметры конфигурации query. Например, fetchPolicy
28
+ * @param params - Параметры запроса
29
+ * @returns Query объект
30
+ * @example
31
+ * const docQuery = docFetcher.queries.doc.createWithConfig(
32
+ * { fetchPolicy: 'network-only' },
33
+ * 'docId',
34
+ * )
35
+ * // Получает данные из query
36
+ * docQuery.sync()
37
+ */
38
+ this.createWithConfig = (config, ...params) => {
39
+ const { keys, execute } = this.configureQuery(...params);
40
+ return this._cache.createQuery(keys, execute, config);
41
+ };
42
+ /**
43
+ * Инвалидирует текущий query в кэше
44
+ * @param keys - Дополнительные ключи для инвалидации. Если не указаны, то инвалидируется весь набор query
45
+ * @example
46
+ * const docFetcher = {
47
+ * doc: mobxQuery.createQuerySet((id: string) => ({
48
+ * execute: () => httpService.get(`/doc/${id}?page=${page}`),
49
+ * })),
50
+ * };
51
+ *
52
+ * // Инвалидирует все query doc
53
+ * docFetcher.doc.invalidate()
54
+ *
55
+ * // Инвалидирует query doc с конкретным переданным id. Доступные ключи инвалидации зависят от указанных additionalKeys, переданных при определении query в фабрике createDataFetcher
56
+ * docFetcher.doc.invalidate('docId')
57
+ */
58
+ this.invalidate = (...params) => {
59
+ if (params.length === 0) {
60
+ this._cache.invalidate([this.baseKey]);
61
+ return;
62
+ }
63
+ const { keys } = this.configureQuery(...params);
64
+ this._cache.invalidate(keys, 'chain-match');
65
+ };
66
+ this.configureQuery = (...params) => {
67
+ const { keys, execute } = this._queryConfigurator(...params);
68
+ return {
69
+ keys: (0, utils_1.generateQuerySetKeys)(this.baseKey, keys !== null && keys !== void 0 ? keys : params),
70
+ execute,
71
+ };
72
+ };
73
+ this.baseKey = (_a = config === null || config === void 0 ? void 0 : config.name) !== null && _a !== void 0 ? _a : (0, utils_1.generateQuerySetBaseKey)(_queryConfigurator);
74
+ }
75
+ }
76
+ exports.QuerySet = QuerySet;
@@ -0,0 +1 @@
1
+ export * from './QuerySet';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./QuerySet"), exports);
@@ -0,0 +1,3 @@
1
+ export * from './MutationSet';
2
+ export * from './QuerySet';
3
+ export * from './InfiniteQuerySet';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./MutationSet"), exports);
18
+ __exportStar(require("./QuerySet"), exports);
19
+ __exportStar(require("./InfiniteQuerySet"), exports);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Создает базовый ключ на основе хэша от configurator
3
+ */
4
+ export declare const generateQuerySetBaseKey: (configurator: Function) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateQuerySetBaseKey = void 0;
7
+ const hash_1 = __importDefault(require("@emotion/hash"));
8
+ /**
9
+ * Создает базовый ключ на основе хэша от configurator
10
+ */
11
+ const generateQuerySetBaseKey = (configurator) => (0, hash_1.default)(configurator.toString());
12
+ exports.generateQuerySetBaseKey = generateQuerySetBaseKey;
@@ -0,0 +1 @@
1
+ export * from './generateQuerySetBaseKey';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generateQuerySetBaseKey"), exports);
@@ -0,0 +1,9 @@
1
+ import { type CacheKey } from '../../../types';
2
+ /**
3
+ * Создает ключи на основе каждого параметра
4
+ * @param additionalKeys - Создает для каждого параметра отдельный ключ, чтобы по нему можно было инвалидировать query
5
+ * @example
6
+ * // Создаст ключи ['22f4', ['22f4', 'organizationID', '1'], ['22f4', 'employeeID', '2']]
7
+ * generateQuerySetKeys('22f4', params)
8
+ */
9
+ export declare const generateQuerySetKeys: (baseKey: string, params: CacheKey[]) => CacheKey[];
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateQuerySetKeys = void 0;
4
+ const utils_1 = require("@astral/utils");
5
+ /**
6
+ * Создает ключи на основе каждого параметра
7
+ * @param additionalKeys - Создает для каждого параметра отдельный ключ, чтобы по нему можно было инвалидировать query
8
+ * @example
9
+ * // Создаст ключи ['22f4', ['22f4', 'organizationID', '1'], ['22f4', 'employeeID', '2']]
10
+ * generateQuerySetKeys('22f4', params)
11
+ */
12
+ const generateQuerySetKeys = (baseKey, params) => {
13
+ const resultKeys = [];
14
+ params.forEach((param) => {
15
+ if ((0, utils_1.isPlainObject)(param)) {
16
+ resultKeys.push(...Object.entries(param).map(([key, value]) => [baseKey, key, value]));
17
+ }
18
+ else {
19
+ resultKeys.push(param);
20
+ }
21
+ });
22
+ return [baseKey, ...resultKeys];
23
+ };
24
+ exports.generateQuerySetKeys = generateQuerySetKeys;
@@ -0,0 +1 @@
1
+ export * from './generateQuerySetKeys';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generateQuerySetKeys"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './generateQuerySetKeys';
2
+ export * from './generateQuerySetBaseKey';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generateQuerySetKeys"), exports);
18
+ __exportStar(require("./generateQuerySetBaseKey"), exports);
package/node/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Mutation } from './Mutation';
2
2
  export { Query } from './Query';
3
- export { type InfiniteParams } from './InfiniteQuery';
3
+ export { type InfiniteParams, InfiniteQuery } from './InfiniteQuery';
4
4
  export { MobxQuery, type CreateQueryParams, type CreateInfiniteQueryParams, type CreateMutationParams, } from './MobxQuery';
5
+ export { type QuerySet, type InfiniteQuerySet, type MutationSet } from './Sets';
5
6
  export { type CacheKey, type FetchPolicy } from './types';
package/node/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MobxQuery = exports.Query = exports.Mutation = void 0;
3
+ exports.MobxQuery = exports.InfiniteQuery = exports.Query = exports.Mutation = void 0;
4
4
  var Mutation_1 = require("./Mutation");
5
5
  Object.defineProperty(exports, "Mutation", { enumerable: true, get: function () { return Mutation_1.Mutation; } });
6
6
  var Query_1 = require("./Query");
7
7
  Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return Query_1.Query; } });
8
+ var InfiniteQuery_1 = require("./InfiniteQuery");
9
+ Object.defineProperty(exports, "InfiniteQuery", { enumerable: true, get: function () { return InfiniteQuery_1.InfiniteQuery; } });
8
10
  var MobxQuery_1 = require("./MobxQuery");
9
11
  Object.defineProperty(exports, "MobxQuery", { enumerable: true, get: function () { return MobxQuery_1.MobxQuery; } });
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@astral/mobx-query",
3
- "version": "1.8.1",
3
+ "version": "1.10.0",
4
4
  "browser": "./index.js",
5
5
  "main": "./node/index.js",
6
6
  "dependencies": {
7
- "mobx": "^6.9.0"
7
+ "@astral/utils": "^1.6.1",
8
+ "@emotion/hash": "0.9.2",
9
+ "mobx": "^6.9.0",
10
+ "utility-types": "3.11.0"
8
11
  },
9
12
  "author": "Astral.Soft",
10
13
  "license": "MIT",