prostgles-client 4.0.263 → 4.0.265

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,31 +1,8 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.__prglReactInstalled = exports.useFetch = exports.useSync = exports.useSubscribe = exports.usePromise = exports.useIsMounted = exports.useEffectAsync = exports.useAsyncEffectQueue = exports.useEffectDeep = exports.useMemoDeep = exports.useDeepCompareMemoize = exports.getIO = exports.getReact = void 0;
3
+ exports.__prglReactInstalled = exports.useFetch = exports.useSync = exports.usePromise = exports.useIsMounted = exports.useEffectAsync = exports.useAsyncEffectQueue = exports.useEffectDeep = exports.useMemoDeep = exports.useDeepCompareMemoize = exports.getIO = void 0;
5
4
  const prostgles_types_1 = require("prostgles-types");
6
- let React;
7
- const alertNoReact = (...args) => {
8
- throw "Must install react";
9
- };
10
- const alertNoReactT = (...args) => {
11
- throw "Must install react";
12
- };
13
- const getReact = (throwError) => {
14
- try {
15
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-require-imports
16
- React !== null && React !== void 0 ? React : (React = require("react"));
17
- }
18
- catch (err) { }
19
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
20
- if (throwError && !React)
21
- throw new Error("Must install react");
22
- return React;
23
- };
24
- exports.getReact = getReact;
25
- (0, exports.getReact)();
26
- const { useEffect = alertNoReact, useCallback = alertNoReact, useRef, useState = alertNoReactT,
27
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
28
- } = (_a = React) !== null && _a !== void 0 ? _a : {};
5
+ const reactImports_1 = require("./reactImports");
29
6
  const getIO = (throwError = false) => {
30
7
  try {
31
8
  // eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -39,7 +16,7 @@ const getIO = (throwError = false) => {
39
16
  };
40
17
  exports.getIO = getIO;
41
18
  const useDeepCompareMemoize = (value) => {
42
- const ref = useRef();
19
+ const ref = (0, reactImports_1.useRef)();
43
20
  if (!(0, prostgles_types_1.isEqual)(value, ref.current)) {
44
21
  ref.current = value;
45
22
  }
@@ -48,19 +25,19 @@ const useDeepCompareMemoize = (value) => {
48
25
  exports.useDeepCompareMemoize = useDeepCompareMemoize;
49
26
  exports.useMemoDeep = ((callback, deps) => {
50
27
  // eslint-disable-next-line react-hooks/exhaustive-deps
51
- return React.useMemo(callback, deps === null || deps === void 0 ? void 0 : deps.map(exports.useDeepCompareMemoize));
28
+ return reactImports_1.React.useMemo(callback, deps === null || deps === void 0 ? void 0 : deps.map(exports.useDeepCompareMemoize));
52
29
  });
53
30
  exports.useEffectDeep = ((callback, deps) => {
54
31
  // eslint-disable-next-line react-hooks/exhaustive-deps
55
- useEffect(callback, deps === null || deps === void 0 ? void 0 : deps.map(exports.useDeepCompareMemoize));
32
+ (0, reactImports_1.useEffect)(callback, deps === null || deps === void 0 ? void 0 : deps.map(exports.useDeepCompareMemoize));
56
33
  });
57
34
  /**
58
35
  * Debounce with execute first
59
36
  * Used to ensure subscriptions are always cleaned up
60
37
  */
61
38
  const useAsyncEffectQueue = (effect, deps) => {
62
- const newEffect = useRef();
63
- const activeEffect = useRef();
39
+ const newEffect = (0, reactImports_1.useRef)();
40
+ const activeEffect = (0, reactImports_1.useRef)();
64
41
  const onRender = async () => {
65
42
  var _a;
66
43
  /**
@@ -81,9 +58,7 @@ const useAsyncEffectQueue = (effect, deps) => {
81
58
  activeEffect.current = { state: "resolving", effect };
82
59
  const cleanup = await effect()
83
60
  .then((run) => {
84
- /**
85
- * Wrapped in a promise to ensure cleanup is awaited
86
- */
61
+ /* Wrapped in a promise to ensure cleanup is awaited */
87
62
  return async () => {
88
63
  await (run === null || run === void 0 ? void 0 : run());
89
64
  };
@@ -109,7 +84,7 @@ const useAsyncEffectQueue = (effect, deps) => {
109
84
  };
110
85
  exports.useAsyncEffectQueue = useAsyncEffectQueue;
111
86
  const useEffectAsync = (effect, inputs) => {
112
- const onCleanup = useRef({
87
+ const onCleanup = (0, reactImports_1.useRef)({
113
88
  cleanup: undefined,
114
89
  effect,
115
90
  cleanupEffect: undefined,
@@ -134,9 +109,9 @@ const useEffectAsync = (effect, inputs) => {
134
109
  };
135
110
  exports.useEffectAsync = useEffectAsync;
136
111
  const useIsMounted = () => {
137
- const isMountedRef = useRef(true);
138
- const isMounted = useCallback(() => isMountedRef.current, []);
139
- useEffect(() => {
112
+ const isMountedRef = (0, reactImports_1.useRef)(true);
113
+ const isMounted = (0, reactImports_1.useCallback)(() => isMountedRef.current, []);
114
+ (0, reactImports_1.useEffect)(() => {
140
115
  /** React 18 Strict Mode fix (new strict mode restores the previous state on the second mount) */
141
116
  isMountedRef.current = true;
142
117
  return () => {
@@ -179,7 +154,7 @@ const usePromise = (f, deps = []) => {
179
154
  }
180
155
  return data;
181
156
  };
182
- const [result, setResult] = useState(isNamedObj(f) ? {} : undefined);
157
+ const [result, setResult] = (0, reactImports_1.useState)(isNamedObj(f) ? {} : undefined);
183
158
  const getIsMounted = (0, exports.useIsMounted)();
184
159
  (0, exports.useAsyncEffectQueue)(async () => {
185
160
  let promiseResult;
@@ -206,49 +181,10 @@ const usePromise = (f, deps = []) => {
206
181
  return result;
207
182
  };
208
183
  exports.usePromise = usePromise;
209
- const useSubscribe = (subFunc, expectsOne, filter, options, hookOptions) => {
210
- const { skip } = hookOptions !== null && hookOptions !== void 0 ? hookOptions : {};
211
- const defaultLoadingResult = { data: undefined, error: undefined, isLoading: true };
212
- const [hookResult, setHookResult] = useState(defaultLoadingResult);
213
- const hookResultRef = useRef(hookResult);
214
- hookResultRef.current = hookResult;
215
- const getIsMounted = (0, exports.useIsMounted)();
216
- (0, exports.useAsyncEffectQueue)(async () => {
217
- if (!getIsMounted() || skip)
218
- return;
219
- if (!(0, prostgles_types_1.isEqual)(hookResultRef.current, defaultLoadingResult)) {
220
- setHookResult(defaultLoadingResult);
221
- }
222
- const setError = (newError) => {
223
- if (!getIsMounted())
224
- return;
225
- setHookResult({ data: undefined, error: newError, isLoading: false });
226
- };
227
- try {
228
- const sub = await subFunc(filter, options, (newData) => {
229
- if (!getIsMounted())
230
- return;
231
- setHookResult({
232
- data: expectsOne ? newData[0] : newData,
233
- error: undefined,
234
- isLoading: false,
235
- });
236
- }, setError);
237
- return () => {
238
- sub.unsubscribe();
239
- };
240
- }
241
- catch (error) {
242
- setError(error);
243
- }
244
- }, [subFunc, filter, options, skip]);
245
- return hookResult;
246
- };
247
- exports.useSubscribe = useSubscribe;
248
184
  const useSync = (syncFunc, basicFilter, syncOptions, hookOptions) => {
249
185
  const { skip } = hookOptions !== null && hookOptions !== void 0 ? hookOptions : {};
250
186
  const defaultLoadingResult = { data: undefined, error: undefined, isLoading: true };
251
- const [{ data, error, isLoading }, setResult] = useState(defaultLoadingResult);
187
+ const [{ data, error, isLoading }, setResult] = (0, reactImports_1.useState)(defaultLoadingResult);
252
188
  const getIsMounted = (0, exports.useIsMounted)();
253
189
  (0, exports.useAsyncEffectQueue)(async () => {
254
190
  if (!getIsMounted() || skip)
@@ -276,7 +212,7 @@ exports.useSync = useSync;
276
212
  const useFetch = (fetchFunc, args = [], hookOptions) => {
277
213
  const { skip, deps = [] } = hookOptions !== null && hookOptions !== void 0 ? hookOptions : {};
278
214
  const defaultLoadingResult = { data: undefined, error: undefined, isLoading: true };
279
- const [{ data, error, isLoading }, setResult] = useState(defaultLoadingResult);
215
+ const [{ data, error, isLoading }, setResult] = (0, reactImports_1.useState)(defaultLoadingResult);
280
216
  const getIsMounted = (0, exports.useIsMounted)();
281
217
  (0, exports.useAsyncEffectQueue)(async () => {
282
218
  if (!getIsMounted() || skip)
@@ -297,5 +233,5 @@ const useFetch = (fetchFunc, args = [], hookOptions) => {
297
233
  return { data, error, isLoading };
298
234
  };
299
235
  exports.useFetch = useFetch;
300
- const __prglReactInstalled = () => Boolean(React && useRef);
236
+ const __prglReactInstalled = () => Boolean(reactImports_1.React && reactImports_1.useRef);
301
237
  exports.__prglReactInstalled = __prglReactInstalled;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ export type ReactT = typeof import("react");
3
+ declare let React: ReactT;
4
+ export declare const getReact: (throwError?: boolean) => ReactT;
5
+ declare const useEffect: typeof import("react").useEffect, useCallback: typeof import("react").useCallback, useRef: typeof import("react").useRef, useState: typeof import("react").useState;
6
+ export { useEffect, useCallback, useRef, useState, React };
7
+ //# sourceMappingURL=reactImports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactImports.d.ts","sourceRoot":"","sources":["../../lib/hooks/reactImports.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,MAAM,GAAG,cAAc,OAAO,CAAC,CAAC;AAC5C,QAAA,IAAI,KAAK,EAAE,MAAM,CAAC;AAQlB,eAAO,MAAM,QAAQ,gBAAiB,OAAO,KAAG,MAQ/C,CAAC;AAEF,QAAA,MACE,SAAS,oCACT,WAAW,sCACX,MAAM,iCACN,QAAQ,iCAEM,CAAC;AAEjB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.React = exports.useState = exports.useRef = exports.useCallback = exports.useEffect = exports.getReact = void 0;
5
+ let React;
6
+ const alertNoReact = (...args) => {
7
+ throw "Must install react";
8
+ };
9
+ const alertNoReactT = (...args) => {
10
+ throw "Must install react";
11
+ };
12
+ const getReact = (throwError) => {
13
+ try {
14
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-require-imports
15
+ React !== null && React !== void 0 ? React : (exports.React = React = require("react"));
16
+ }
17
+ catch (err) { }
18
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
19
+ if (throwError && !React)
20
+ throw new Error("Must install react");
21
+ return React;
22
+ };
23
+ exports.getReact = getReact;
24
+ (0, exports.getReact)();
25
+ const { useEffect = alertNoReact, useCallback = alertNoReact, useRef, useState = alertNoReactT,
26
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
27
+ } = (_a = React) !== null && _a !== void 0 ? _a : {};
28
+ exports.useEffect = useEffect;
29
+ exports.useCallback = useCallback;
30
+ exports.useRef = useRef;
31
+ exports.useState = useState;
@@ -1,8 +1,8 @@
1
1
  import { type DBSchema, type DBSchemaTable, type MethodHandler, type UserLike } from "prostgles-types";
2
2
  import type { ManagerOptions, Socket, SocketOptions } from "socket.io-client";
3
- import type { AuthHandler } from "./getAuthHandler";
4
- import { type DBHandlerClient, type InitOptions } from "./prostgles";
5
- type OnReadyParams<DBSchema, U extends UserLike = UserLike> = {
3
+ import type { AuthHandler } from "../getAuthHandler";
4
+ import { type DBHandlerClient, type InitOptions } from "../prostgles";
5
+ export type OnReadyParams<DBSchema, U extends UserLike = UserLike> = {
6
6
  dbo: DBHandlerClient<DBSchema>;
7
7
  methods: MethodHandler | undefined;
8
8
  tableSchema: DBSchemaTable[] | undefined;
@@ -20,7 +20,7 @@ export type UseProstglesClientProps = Omit<InitOptions<DBSchema>, "onReady" | "s
20
20
  socketOptions?: SocketPathOrOptions;
21
21
  skip?: boolean;
22
22
  };
23
- type ProstglesClientState<PGC> = {
23
+ export type ProstglesClientState<PGC> = {
24
24
  isLoading: true;
25
25
  hasError?: undefined;
26
26
  error?: undefined;
@@ -31,7 +31,7 @@ type ProstglesClientState<PGC> = {
31
31
  } & PGC) | {
32
32
  isLoading: false;
33
33
  hasError: true;
34
- error: any;
34
+ error: unknown;
35
35
  };
36
36
  export declare const useProstglesClient: <DBSchema_1, U extends UserLike = UserLike>({ skip, socketOptions: socketPathOrOptions, ...initOpts }?: UseProstglesClientProps) => ProstglesClientState<OnReadyParams<DBSchema_1, U>>;
37
37
  export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../../lib/hooks/useProstglesClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK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AAK,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,GAAG,CAAC,GACjE;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzD,eAAO,MAAM,kBAAkB,0GAI5B,uBAAuB,uDA2DzB,CAAC"}
@@ -6,11 +6,12 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.useProstglesClient = void 0;
8
8
  const prostgles_types_1 = require("prostgles-types");
9
- const SyncedTable_1 = require("./SyncedTable/SyncedTable");
10
- const prostgles_1 = require("./prostgles");
9
+ const SyncedTable_1 = require("../SyncedTable/SyncedTable");
10
+ const prostgles_1 = require("../prostgles");
11
11
  const react_hooks_1 = require("./react-hooks");
12
+ const reactImports_1 = require("./reactImports");
12
13
  const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, ...initOpts } = {}) => {
13
- const { useRef, useState } = (0, react_hooks_1.getReact)(true);
14
+ const { useRef, useState } = (0, reactImports_1.getReact)(true);
14
15
  const [onReadyArgs, setOnReadyArgs] = useState({
15
16
  isLoading: true,
16
17
  });
@@ -58,6 +59,9 @@ const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, ...initO
58
59
  });
59
60
  return () => {
60
61
  socket.disconnect();
62
+ socket.emit = () => {
63
+ throw "Socket disconnected";
64
+ };
61
65
  };
62
66
  }, [initOpts, socketPathOrOptions, skip]);
63
67
  return onReadyArgs;
@@ -0,0 +1,5 @@
1
+ import type { HookOptions } from "../prostgles";
2
+ import { type DataFetchHookResult } from "./react-hooks";
3
+ import { type SubscriptionHandler } from "prostgles-types";
4
+ export declare const useSubscribe: (subFunc: (filter: any, options: any, onData: any, onError: any) => Promise<SubscriptionHandler>, expectsOne: boolean, filter: any, options: any, hookOptions?: HookOptions) => DataFetchHookResult;
5
+ //# sourceMappingURL=useSubscribe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSubscribe.d.ts","sourceRoot":"","sources":["../../lib/hooks/useSubscribe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAqC,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAW,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGpE,eAAO,MAAM,YAAY,qBACL,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,KAAK,QAAQ,mBAAmB,CAAC,cACnF,OAAO,UACX,GAAG,WACF,GAAG,gBACE,WAAW,wBAyC1B,CAAC"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSubscribe = void 0;
4
+ const react_hooks_1 = require("./react-hooks");
5
+ const prostgles_types_1 = require("prostgles-types");
6
+ const reactImports_1 = require("./reactImports");
7
+ const useSubscribe = (subFunc, expectsOne, filter, options, hookOptions) => {
8
+ const { skip } = hookOptions !== null && hookOptions !== void 0 ? hookOptions : {};
9
+ const defaultLoadingResult = { data: undefined, error: undefined, isLoading: true };
10
+ const [hookResult, setHookResult] = (0, reactImports_1.useState)(defaultLoadingResult);
11
+ const hookResultRef = (0, reactImports_1.useRef)(hookResult);
12
+ hookResultRef.current = hookResult;
13
+ const getIsMounted = (0, react_hooks_1.useIsMounted)();
14
+ (0, react_hooks_1.useAsyncEffectQueue)(async () => {
15
+ if (!getIsMounted() || skip)
16
+ return;
17
+ if (!(0, prostgles_types_1.isEqual)(hookResultRef.current, defaultLoadingResult)) {
18
+ setHookResult(defaultLoadingResult);
19
+ }
20
+ const setError = (newError) => {
21
+ if (!getIsMounted())
22
+ return;
23
+ setHookResult({ data: undefined, error: newError, isLoading: false });
24
+ };
25
+ try {
26
+ const sub = await subFunc(filter, options, (newData) => {
27
+ if (!getIsMounted())
28
+ return;
29
+ setHookResult({
30
+ data: expectsOne ? newData[0] : newData,
31
+ error: undefined,
32
+ isLoading: false,
33
+ });
34
+ }, setError);
35
+ return () => {
36
+ sub.unsubscribe();
37
+ };
38
+ }
39
+ catch (error) {
40
+ setError(error);
41
+ }
42
+ }, [subFunc, filter, options, skip]);
43
+ return hookResult;
44
+ };
45
+ exports.useSubscribe = useSubscribe;