@hortiview/modulebase 0.0.12119 → 0.0.12333

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.
@@ -1,20 +1,22 @@
1
- import { u as m } from "../useQuery-znAyMQW1.js";
2
- import { useBasePropsStore as i } from "../stores/BasePropsStore.js";
3
- import { universalSelector as n } from "../types/Requests.js";
4
- import { d as p } from "../fetches-DUCQo_6B.js";
5
- const d = ({
1
+ import { u as i } from "../useQuery-DtzakC1A.js";
2
+ import { useBasePropsStore as n } from "../stores/BasePropsStore.js";
3
+ import { universalSelector as p } from "../types/Requests.js";
4
+ import { fetchFromCustomApi as a } from "../utils/fetches.js";
5
+ const l = ({
6
6
  endpoint: e,
7
7
  queryKey: t,
8
- token: s,
9
- selector: o
8
+ token: u,
9
+ selector: o,
10
+ enabled: m = !0
10
11
  }) => {
11
- const u = i((r) => r.organizationId);
12
- return m({
13
- queryKey: [...t, u],
14
- queryFn: () => p(e, s),
15
- select: (r) => o ? o(r) : n(r)
12
+ const s = n((r) => r.organizationId);
13
+ return i({
14
+ queryKey: [...t, s],
15
+ queryFn: () => a(e, u),
16
+ select: (r) => o ? o(r) : p(r),
17
+ enabled: m
16
18
  });
17
19
  };
18
20
  export {
19
- d as useCustom
21
+ l as useCustom
20
22
  };
@@ -0,0 +1,8 @@
1
+ import { UseMutationResult } from '@tanstack/react-query';
2
+ import { BaseResponse, httpMethod } from '../types/Requests';
3
+ export declare const useCustomMutation: <Input, Output>({ endpoint, method, token, headers, }: {
4
+ endpoint: string;
5
+ method: Omit<httpMethod, "GET">;
6
+ token?: string;
7
+ headers?: Headers;
8
+ }) => UseMutationResult<BaseResponse<Output>, Error, Input, unknown>;
@@ -0,0 +1,112 @@
1
+ import * as o from "react";
2
+ import { g as m } from "../ModuleBase-brrfWM_W.js";
3
+ import { S as p, s as l, h as a, n as h, u as d } from "../QueryClientProvider-QWqHaM3I.js";
4
+ import { n as b, s as f } from "../useQuery-DtzakC1A.js";
5
+ import "../stores/BasePropsStore.js";
6
+ import "../provider/SignalR/SignalRProvider.js";
7
+ import "../omit-B7MWDtHq.js";
8
+ import "../stores/EnvironmentStore.js";
9
+ import { mutateOnCustomApi as O } from "../utils/fetches.js";
10
+ import "./useEntity.js";
11
+ import "../api-D9Lmqe6S.js";
12
+ var v = class extends p {
13
+ #e;
14
+ #i = void 0;
15
+ #t;
16
+ #s;
17
+ constructor(t, s) {
18
+ super(), this.#e = t, this.setOptions(s), this.bindMethods(), this.#r();
19
+ }
20
+ bindMethods() {
21
+ this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this);
22
+ }
23
+ setOptions(t) {
24
+ const s = this.options;
25
+ this.options = this.#e.defaultMutationOptions(t), l(this.options, s) || this.#e.getMutationCache().notify({
26
+ type: "observerOptionsUpdated",
27
+ mutation: this.#t,
28
+ observer: this
29
+ }), s?.mutationKey && this.options.mutationKey && a(s.mutationKey) !== a(this.options.mutationKey) ? this.reset() : this.#t?.state.status === "pending" && this.#t.setOptions(this.options);
30
+ }
31
+ onUnsubscribe() {
32
+ this.hasListeners() || this.#t?.removeObserver(this);
33
+ }
34
+ onMutationUpdate(t) {
35
+ this.#r(), this.#o(t);
36
+ }
37
+ getCurrentResult() {
38
+ return this.#i;
39
+ }
40
+ reset() {
41
+ this.#t?.removeObserver(this), this.#t = void 0, this.#r(), this.#o();
42
+ }
43
+ mutate(t, s) {
44
+ return this.#s = s, this.#t?.removeObserver(this), this.#t = this.#e.getMutationCache().build(this.#e, this.options), this.#t.addObserver(this), this.#t.execute(t);
45
+ }
46
+ #r() {
47
+ const t = this.#t?.state ?? m();
48
+ this.#i = {
49
+ ...t,
50
+ isPending: t.status === "pending",
51
+ isSuccess: t.status === "success",
52
+ isError: t.status === "error",
53
+ isIdle: t.status === "idle",
54
+ mutate: this.mutate,
55
+ reset: this.reset
56
+ };
57
+ }
58
+ #o(t) {
59
+ h.batch(() => {
60
+ if (this.#s && this.hasListeners()) {
61
+ const s = this.#i.variables, i = this.#i.context;
62
+ t?.type === "success" ? (this.#s.onSuccess?.(t.data, s, i), this.#s.onSettled?.(t.data, null, s, i)) : t?.type === "error" && (this.#s.onError?.(t.error, s, i), this.#s.onSettled?.(
63
+ void 0,
64
+ t.error,
65
+ s,
66
+ i
67
+ ));
68
+ }
69
+ this.listeners.forEach((s) => {
70
+ s(this.#i);
71
+ });
72
+ });
73
+ }
74
+ };
75
+ function y(t, s) {
76
+ const i = d(), [e] = o.useState(
77
+ () => new v(
78
+ i,
79
+ t
80
+ )
81
+ );
82
+ o.useEffect(() => {
83
+ e.setOptions(t);
84
+ }, [e, t]);
85
+ const r = o.useSyncExternalStore(
86
+ o.useCallback(
87
+ (u) => e.subscribe(h.batchCalls(u)),
88
+ [e]
89
+ ),
90
+ () => e.getCurrentResult(),
91
+ () => e.getCurrentResult()
92
+ ), n = o.useCallback(
93
+ (u, c) => {
94
+ e.mutate(u, c).catch(b);
95
+ },
96
+ [e]
97
+ );
98
+ if (r.error && f(e.options.throwOnError, [r.error]))
99
+ throw r.error;
100
+ return { ...r, mutate: n, mutateAsync: r.mutate };
101
+ }
102
+ const k = ({
103
+ endpoint: t,
104
+ method: s,
105
+ token: i,
106
+ headers: e
107
+ }) => y({
108
+ mutationFn: (r, n) => O(n ?? t, r, s, i, e)
109
+ });
110
+ export {
111
+ k as useCustomMutation
112
+ };
@@ -26,7 +26,7 @@ export declare const AllEntitiesTypeResultMap: {
26
26
  farm_organizations: string;
27
27
  alert_rules: string;
28
28
  };
29
- export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E) => {
29
+ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E, enabled?: boolean) => {
30
30
  data: ResultMap<E>[];
31
31
  error: Error;
32
32
  isError: true;
@@ -1,9 +1,9 @@
1
- import { u as f } from "../useQuery-znAyMQW1.js";
1
+ import { u as l } from "../useQuery-DtzakC1A.js";
2
2
  import { useMemo as g } from "react";
3
- import { useBasePropsStore as l } from "../stores/BasePropsStore.js";
4
- import { universalSelector as p } from "../types/Requests.js";
5
- import { g as b, a as R } from "../fetches-DUCQo_6B.js";
6
- import { useOption as y, useModuleDependency as k } from "./useOption.js";
3
+ import { useBasePropsStore as p } from "../stores/BasePropsStore.js";
4
+ import { universalSelector as y } from "../types/Requests.js";
5
+ import { getModuleDependedEntities as R, getFarmOrgEntities as k } from "../utils/fetches.js";
6
+ import { useOption as E, useModuleDependency as D } from "./useOption.js";
7
7
  const F = {
8
8
  farms: "farm",
9
9
  fields: "field",
@@ -20,39 +20,45 @@ const F = {
20
20
  ...F,
21
21
  ...Q,
22
22
  ...q
23
- }, B = (t, e) => {
24
- const a = l((r) => r.moduleId), o = l((r) => r.organizationId), { data: i } = y("DataAreaGroup"), { data: u } = y("DataAreaEntity"), { data: n } = k(), d = t === "ModuleDepended", E = g(() => {
25
- if (d)
26
- return n ? n.find((s) => s.registeredEntityName === e)?.id : void 0;
27
- if (!i || !u) return;
28
- const r = i.find((s) => s.key === t)?.id;
29
- return r ? u.find((s) => s.description === r && s.value === e)?.id : void 0;
30
- }, [d, i, u, n, e, t]), c = D(a, E, o, d), M = (c.data ?? []).map((r) => {
31
- const m = A[e];
32
- return r[m];
23
+ }, K = (e, t, a = !0) => {
24
+ const o = p((r) => r.moduleId), d = p((r) => r.organizationId), { data: u } = E("DataAreaGroup"), { data: i } = E("DataAreaEntity"), { data: n } = D(e === "ModuleDepended"), m = e === "ModuleDepended", M = g(() => {
25
+ if (m)
26
+ return n ? n.find((s) => s.registeredEntityName === t)?.id : void 0;
27
+ if (!u || !i) return;
28
+ const r = u.find((s) => s.key === e)?.id;
29
+ return r ? i.find((s) => s.description === r && s.value === t)?.id : void 0;
30
+ }, [m, u, i, n, t, e]), f = O(
31
+ o,
32
+ M,
33
+ d,
34
+ m,
35
+ a
36
+ ), b = (f.data ?? []).map((r) => {
37
+ const c = A[t];
38
+ return r[c];
33
39
  });
34
40
  return {
35
- ...c,
36
- data: M
41
+ ...f,
42
+ data: b
37
43
  };
38
- }, D = (t, e, a, o) => {
39
- const i = f({
40
- queryKey: [t, a, e],
41
- queryFn: () => b(t ?? "", e ?? ""),
42
- enabled: o && !!t && !!e && !!a,
43
- select: (n) => p(n)
44
- }), u = f({
45
- queryKey: [t, a, e],
46
- queryFn: () => R(t ?? "", e ?? ""),
47
- enabled: !o && !!t && !!e && !!a,
48
- select: (n) => p(n)
44
+ }, O = (e, t, a, o, d = !0) => {
45
+ const u = l({
46
+ queryKey: [e, a, t],
47
+ queryFn: () => R(e ?? "", t ?? ""),
48
+ enabled: d && o && !!e && !!t && !!a,
49
+ select: (n) => y(n)
50
+ }), i = l({
51
+ queryKey: [e, a, t],
52
+ queryFn: () => k(e ?? "", t ?? ""),
53
+ enabled: d && !o && !!e && !!t && !!a,
54
+ select: (n) => y(n)
49
55
  });
50
- return o ? i : u;
56
+ return o ? u : i;
51
57
  };
52
58
  export {
53
59
  A as AllEntitiesTypeResultMap,
54
60
  Q as FarmMemberEntitiesTypeResultMap,
55
61
  F as FarmOrgEntitiesTypeResultMap,
56
62
  q as ModuleDependedEntityTypeResultMap,
57
- B as useEntity
63
+ K as useEntity
58
64
  };
@@ -14,4 +14,4 @@ import { RegisterOption } from '../types/ModuleApi';
14
14
  * or fetches it from the API. The result is then processed by a universal selector.
15
15
  */
16
16
  export declare const useOption: (dropdown: keyof typeof CommonOptionType) => UseQueryResult<CommonOption[], Error>;
17
- export declare const useModuleDependency: () => UseQueryResult<RegisterOption[], Error>;
17
+ export declare const useModuleDependency: (enabled?: boolean) => UseQueryResult<RegisterOption[], Error>;
@@ -1,23 +1,25 @@
1
- import { u as s } from "../useQuery-znAyMQW1.js";
2
- import { b as u, f as c, c as i } from "../fetches-DUCQo_6B.js";
3
- import { useBasePropsStore as t } from "../stores/BasePropsStore.js";
4
- import { universalSelector as m } from "../types/Requests.js";
5
- const y = (o) => {
6
- const r = t((n) => n.commonOptions), e = u(r, o);
7
- return s({
8
- queryKey: [o],
9
- queryFn: () => e ? Promise.resolve(e) : c(`${o}/dropdown`),
10
- select: (n) => m(n)
1
+ import { u as m } from "../useQuery-DtzakC1A.js";
2
+ import { g as u } from "../api-D9Lmqe6S.js";
3
+ import { useBasePropsStore as n } from "../stores/BasePropsStore.js";
4
+ import { universalSelector as s } from "../types/Requests.js";
5
+ import { fetchFromCommonApi as i, fetchFromModuleApi as c } from "../utils/fetches.js";
6
+ const f = (e) => {
7
+ const r = n((o) => o.commonOptions), t = u(r, e);
8
+ return m({
9
+ queryKey: [e],
10
+ queryFn: () => t ? Promise.resolve(t) : i(`${e}/dropdown`),
11
+ select: (o) => s(o)
11
12
  });
12
- }, f = () => {
13
- const o = t((e) => e.moduleId), r = t((e) => e.organizationId);
14
- return s({
15
- queryKey: [o, r],
16
- queryFn: () => i(`ModuleDependencies/${o}`),
17
- select: (e) => m(e)
13
+ }, g = (e = !0) => {
14
+ const r = n((o) => o.moduleId), t = n((o) => o.organizationId);
15
+ return m({
16
+ queryKey: [r, t],
17
+ queryFn: () => c(`ModuleDependencies/${r}`),
18
+ select: (o) => s(o),
19
+ enabled: e
18
20
  });
19
21
  };
20
22
  export {
21
- f as useModuleDependency,
22
- y as useOption
23
+ g as useModuleDependency,
24
+ f as useOption
23
25
  };