prostgles-client 4.0.127 → 4.0.129
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.
- package/dist/index.js +1 -1
- package/dist/index.no-sync.js +1 -1
- package/dist/prostgles-full.d.ts +1 -1
- package/dist/prostgles-full.d.ts.map +1 -1
- package/dist/useProstglesClient.d.ts +2 -1
- package/dist/useProstglesClient.d.ts.map +1 -1
- package/dist/useProstglesClient.js +14 -5
- package/lib/prostgles-full.ts +1 -1
- package/lib/useProstglesClient.ts +19 -10
- package/package.json +1 -1
- package/tests/package-lock.json +1 -1
package/dist/prostgles-full.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitOptions } from "./prostgles";
|
|
1
|
+
import { type InitOptions } from "./prostgles";
|
|
2
2
|
declare function prostgles<DBSchema = void>(params: InitOptions<DBSchema>): Promise<unknown>;
|
|
3
3
|
declare namespace prostgles {
|
|
4
4
|
var SyncedTable: typeof import("./SyncedTable/SyncedTable").SyncedTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prostgles-full.d.ts","sourceRoot":"","sources":["../lib/prostgles-full.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"prostgles-full.d.ts","sourceRoot":"","sources":["../lib/prostgles-full.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAElE,iBAAS,SAAS,CAAC,QAAQ,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,oBAEhE;kBAFQ,SAAS;;;AAKlB,SAAS,SAAS,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DBSchema, type DBSchemaTable, type MethodHandler } from "prostgles-types";
|
|
2
|
-
import type { ManagerOptions, SocketOptions } from "socket.io-client";
|
|
2
|
+
import type { ManagerOptions, Socket, SocketOptions } from "socket.io-client";
|
|
3
3
|
import { type Auth, type DBHandlerClient, type InitOptions } from "./prostgles";
|
|
4
4
|
type OnReadyParams<DBSchema> = {
|
|
5
5
|
dbo: DBHandlerClient<DBSchema>;
|
|
@@ -7,6 +7,7 @@ type OnReadyParams<DBSchema> = {
|
|
|
7
7
|
tableSchema: DBSchemaTable[] | undefined;
|
|
8
8
|
auth: Auth | undefined;
|
|
9
9
|
isReconnect: boolean;
|
|
10
|
+
socket: Socket;
|
|
10
11
|
};
|
|
11
12
|
type HookInitOpts = Omit<InitOptions<DBSchema>, "onReady" | "socket"> & {
|
|
12
13
|
socketOptions?: Partial<ManagerOptions & SocketOptions> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../lib/useProstglesClient.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../lib/useProstglesClient.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAa,KAAK,IAAI,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAG3F,KAAK,aAAa,CAAC,QAAQ,IAAI;IAC7B,GAAG,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC/B,OAAO,EAAE,aAAa,GAAG,SAAS,CAAC;IACnC,WAAW,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC;IACzC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAA;AACD,KAAK,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IACtE,aAAa,CAAC,EAAE,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;KAAE,CAAC;IAC5E,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AACF,KAAK,oBAAoB,CAAC,GAAG,IAC3B;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAC;CAAE,GACvC;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAC;CAAE,GAAG,GAAG,GAC9C;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CAAE,CAAC;AAE/C,eAAO,MAAM,kBAAkB,sDAAoD,YAAY,oDAqD9F,CAAA"}
|
|
@@ -20,7 +20,9 @@ const useProstglesClient = ({ skip, socketOptions, ...initOpts } = {}) => {
|
|
|
20
20
|
var _a;
|
|
21
21
|
if (skip)
|
|
22
22
|
return undefined;
|
|
23
|
-
(_a = socketRef.current) === null || _a === void 0 ? void 0 : _a.
|
|
23
|
+
if ((_a = socketRef.current) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
24
|
+
socketRef.current.disconnect();
|
|
25
|
+
}
|
|
24
26
|
const io = (0, react_hooks_1.getIO)();
|
|
25
27
|
const opts = {
|
|
26
28
|
reconnectionDelay: 1000,
|
|
@@ -29,7 +31,6 @@ const useProstglesClient = ({ skip, socketOptions, ...initOpts } = {}) => {
|
|
|
29
31
|
};
|
|
30
32
|
const socket = typeof (socketOptions === null || socketOptions === void 0 ? void 0 : socketOptions.uri) === "string" ? io(socketOptions.uri, opts) : io(opts);
|
|
31
33
|
socketRef.current = socket;
|
|
32
|
-
//@ts-ignore
|
|
33
34
|
await (0, prostgles_1.prostgles)({
|
|
34
35
|
socket,
|
|
35
36
|
...initOpts,
|
|
@@ -37,14 +38,22 @@ const useProstglesClient = ({ skip, socketOptions, ...initOpts } = {}) => {
|
|
|
37
38
|
if (!getIsMounted())
|
|
38
39
|
return;
|
|
39
40
|
const [dbo, methods, tableSchema, auth, isReconnect] = args;
|
|
40
|
-
const onReadyArgs = {
|
|
41
|
+
const onReadyArgs = {
|
|
42
|
+
dbo,
|
|
43
|
+
methods,
|
|
44
|
+
tableSchema,
|
|
45
|
+
auth,
|
|
46
|
+
isReconnect,
|
|
47
|
+
socket
|
|
48
|
+
};
|
|
41
49
|
setOnReadyArgs({ ...onReadyArgs, isLoading: false });
|
|
42
50
|
}
|
|
43
51
|
}, SyncedTable_1.SyncedTable)
|
|
44
|
-
.catch(
|
|
52
|
+
.catch(err => {
|
|
45
53
|
if (!getIsMounted())
|
|
46
54
|
return;
|
|
47
|
-
|
|
55
|
+
const error = err instanceof Error ? err : new Error(err);
|
|
56
|
+
setOnReadyArgs({ isLoading: false, error });
|
|
48
57
|
});
|
|
49
58
|
return () => {
|
|
50
59
|
socket.disconnect();
|
package/lib/prostgles-full.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { prostgles as pgls, InitOptions } from "./prostgles";
|
|
1
|
+
import { prostgles as pgls, type InitOptions } from "./prostgles";
|
|
2
2
|
import { SyncedTable } from "./SyncedTable/SyncedTable";
|
|
3
3
|
function prostgles<DBSchema = void>(params: InitOptions<DBSchema>) {
|
|
4
4
|
return pgls(params as any, SyncedTable);
|
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
omitKeys,
|
|
8
9
|
type DBSchema,
|
|
9
10
|
type DBSchemaTable,
|
|
10
|
-
type MethodHandler
|
|
11
|
-
omitKeys,
|
|
12
|
-
type AnyObject
|
|
11
|
+
type MethodHandler
|
|
13
12
|
} from "prostgles-types";
|
|
14
13
|
|
|
15
14
|
import type { ManagerOptions, Socket, SocketOptions } from "socket.io-client";
|
|
@@ -23,6 +22,7 @@ type OnReadyParams<DBSchema> = {
|
|
|
23
22
|
tableSchema: DBSchemaTable[] | undefined;
|
|
24
23
|
auth: Auth | undefined;
|
|
25
24
|
isReconnect: boolean;
|
|
25
|
+
socket: Socket;
|
|
26
26
|
}
|
|
27
27
|
type HookInitOpts = Omit<InitOptions<DBSchema>, "onReady" | "socket"> & {
|
|
28
28
|
socketOptions?: Partial<ManagerOptions & SocketOptions> & { uri?: string; };
|
|
@@ -45,7 +45,9 @@ export const useProstglesClient = <DBSchema>({ skip, socketOptions, ...initOpts
|
|
|
45
45
|
useAsyncEffectQueue(async () => {
|
|
46
46
|
if(skip) return undefined;
|
|
47
47
|
|
|
48
|
-
socketRef.current?.
|
|
48
|
+
if(socketRef.current?.connected){
|
|
49
|
+
socketRef.current.disconnect();
|
|
50
|
+
}
|
|
49
51
|
const io = getIO();
|
|
50
52
|
const opts = {
|
|
51
53
|
reconnectionDelay: 1000,
|
|
@@ -54,20 +56,27 @@ export const useProstglesClient = <DBSchema>({ skip, socketOptions, ...initOpts
|
|
|
54
56
|
}
|
|
55
57
|
const socket = typeof socketOptions?.uri === "string" ? io(socketOptions.uri, opts) : io(opts);
|
|
56
58
|
socketRef.current = socket;
|
|
57
|
-
|
|
58
|
-
await prostgles({
|
|
59
|
+
await prostgles<DBSchema>({
|
|
59
60
|
socket,
|
|
60
61
|
...initOpts,
|
|
61
62
|
onReady: (...args) => {
|
|
62
63
|
if (!getIsMounted()) return;
|
|
63
64
|
const [dbo, methods, tableSchema, auth, isReconnect] = args;
|
|
64
|
-
const onReadyArgs = {
|
|
65
|
-
|
|
65
|
+
const onReadyArgs: OnReadyParams<DBSchema> = {
|
|
66
|
+
dbo,
|
|
67
|
+
methods,
|
|
68
|
+
tableSchema,
|
|
69
|
+
auth,
|
|
70
|
+
isReconnect,
|
|
71
|
+
socket
|
|
72
|
+
};
|
|
73
|
+
setOnReadyArgs({ ...onReadyArgs, isLoading: false });
|
|
66
74
|
}
|
|
67
75
|
}, SyncedTable)
|
|
68
|
-
.catch(
|
|
76
|
+
.catch(err => {
|
|
69
77
|
if (!getIsMounted()) return;
|
|
70
|
-
|
|
78
|
+
const error = err instanceof Error ? err : new Error(err);
|
|
79
|
+
setOnReadyArgs({ isLoading: false, error });
|
|
71
80
|
});
|
|
72
81
|
|
|
73
82
|
return () => {
|
package/package.json
CHANGED