prostgles-client 4.0.385 → 4.0.387
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/README.md +8 -0
- package/dist/getAuthHandler.js +1 -1
- package/dist/getProstglesSocket.d.ts +10 -0
- package/dist/getProstglesSocket.d.ts.map +1 -0
- package/dist/getProstglesSocket.js +31 -0
- package/dist/hooks/useProstglesClient.d.ts +2 -4
- package/dist/hooks/useProstglesClient.d.ts.map +1 -1
- package/dist/hooks/useProstglesClient.js +10 -28
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.umd.d.ts +2 -2
- package/dist/index.umd.d.ts.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/prostgles.d.ts +8 -1
- package/dist/prostgles.d.ts.map +1 -1
- package/dist/prostgles.js +10 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,6 +41,14 @@ CDN
|
|
|
41
41
|
|
|
42
42
|
## Quick Start
|
|
43
43
|
|
|
44
|
+
### Node.js
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import prostgles from "prostgles-client";
|
|
48
|
+
|
|
49
|
+
const prostglesClient = await prostgles({ endpoint, token });
|
|
50
|
+
```
|
|
51
|
+
|
|
44
52
|
### React hooks
|
|
45
53
|
|
|
46
54
|
Subscribe to data changes with automatic re-renders:
|
package/dist/getAuthHandler.js
CHANGED
|
@@ -5,7 +5,7 @@ const prostgles_types_1 = require("prostgles-types");
|
|
|
5
5
|
const prostgles_1 = require("./prostgles");
|
|
6
6
|
const getAuthHandler = ({ authData: authConfig, socket, onReload, endpoint, ...authOpts }) => {
|
|
7
7
|
const urlWithEndpointAndSearch = (route) => {
|
|
8
|
-
const
|
|
8
|
+
const search = typeof window !== "undefined" ? window.location.search : "";
|
|
9
9
|
let url = route + search;
|
|
10
10
|
if (endpoint)
|
|
11
11
|
url = `${endpoint}${url}`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ManagerOptions, SocketOptions } from "socket.io-client";
|
|
2
|
+
export type SocketPathOrOptions = string | Partial<ManagerOptions & SocketOptions>;
|
|
3
|
+
export declare const getIO: (throwError?: boolean) => typeof import("socket.io-client").io;
|
|
4
|
+
export declare const getProstglesSocket: ({ endpoint, token, socketOptions: socketPathOrOptions, credentials, }: {
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
socketOptions?: SocketPathOrOptions;
|
|
8
|
+
credentials?: RequestCredentials;
|
|
9
|
+
}) => import("socket.io-client").Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap>;
|
|
10
|
+
//# sourceMappingURL=getProstglesSocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getProstglesSocket.d.ts","sourceRoot":"","sources":["../lib/getProstglesSocket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAItE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAAC;AAEnF,eAAO,MAAM,KAAK,GAAI,oBAAkB,yCAQvC,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,uEAKhC;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC,wJAiBA,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProstglesSocket = exports.getIO = void 0;
|
|
4
|
+
const getIO = (throwError = false) => {
|
|
5
|
+
try {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
7
|
+
const io = require("socket.io-client");
|
|
8
|
+
return io;
|
|
9
|
+
}
|
|
10
|
+
catch (err) { }
|
|
11
|
+
if (throwError)
|
|
12
|
+
throw new Error("Must install socket.io-client");
|
|
13
|
+
return {};
|
|
14
|
+
};
|
|
15
|
+
exports.getIO = getIO;
|
|
16
|
+
const getProstglesSocket = ({ endpoint, token, socketOptions: socketPathOrOptions, credentials, }) => {
|
|
17
|
+
const io = (0, exports.getIO)(true);
|
|
18
|
+
const socketOptions = typeof socketPathOrOptions === "string" ? { path: socketPathOrOptions } : socketPathOrOptions;
|
|
19
|
+
const socketOptionsWithDefaults = {
|
|
20
|
+
withCredentials: credentials !== undefined && credentials !== "omit",
|
|
21
|
+
...socketOptions,
|
|
22
|
+
reconnectionDelay: 1000,
|
|
23
|
+
reconnection: true,
|
|
24
|
+
};
|
|
25
|
+
socketOptionsWithDefaults.path ??= "/ws-api";
|
|
26
|
+
if (token) {
|
|
27
|
+
socketOptionsWithDefaults.auth = { token };
|
|
28
|
+
}
|
|
29
|
+
return endpoint ? io(endpoint, socketOptionsWithDefaults) : io(socketOptionsWithDefaults);
|
|
30
|
+
};
|
|
31
|
+
exports.getProstglesSocket = getProstglesSocket;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type DBSchema, type UserLike } from "prostgles-types";
|
|
2
2
|
import type { ClientFunctionHandler } from "../getMethods";
|
|
3
|
-
import type { ManagerOptions, SocketOptions } from "socket.io-client";
|
|
4
3
|
import { type InitOptions, type ClientOnReadyParams } from "../prostgles";
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { type SocketPathOrOptions } from "../getProstglesSocket";
|
|
5
|
+
export { getIO } from "../getProstglesSocket";
|
|
7
6
|
export type UseProstglesClientProps = Omit<InitOptions<DBSchema>, "onReady" | "socket"> & {
|
|
8
7
|
/**
|
|
9
8
|
* Websocket API token
|
|
@@ -26,5 +25,4 @@ export type ProstglesClientState<PGC> = {
|
|
|
26
25
|
error: unknown;
|
|
27
26
|
};
|
|
28
27
|
export declare const useProstglesClient: <S = void, FuncSchema extends ClientFunctionHandler = ClientFunctionHandler, U extends UserLike = UserLike>({ skip, socketOptions: socketPathOrOptions, endpoint, token, ...initOpts }?: UseProstglesClientProps) => ProstglesClientState<ClientOnReadyParams<S, FuncSchema, U>>;
|
|
29
|
-
export {};
|
|
30
28
|
//# sourceMappingURL=useProstglesClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../../lib/hooks/useProstglesClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../../lib/hooks/useProstglesClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAKrF,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IACxF;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AACF,MAAM,MAAM,oBAAoB,CAAC,GAAG,IAChC;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,KAAK,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GACvD,CAAC;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,KAAK,CAAC;IAAC,KAAK,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,GAAG,CAAC,GAChE;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzD,eAAO,MAAM,kBAAkB,GAC7B,CAAC,GAAG,IAAI,EACR,UAAU,SAAS,qBAAqB,GAAG,qBAAqB,EAChE,CAAC,SAAS,QAAQ,GAAG,QAAQ,EAC7B,6EAMC,uBAA4B,KAAG,oBAAoB,CAAC,mBAAmB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CA0D3F,CAAC"}
|
|
@@ -3,21 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useProstglesClient = exports.getIO = void 0;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const prostgles_1 = require("../prostgles");
|
|
6
|
+
const getProstglesSocket_1 = require("../getProstglesSocket");
|
|
6
7
|
const reactImports_1 = require("./reactImports");
|
|
7
8
|
const useAsyncEffectQueue_1 = require("./useAsyncEffectQueue");
|
|
8
9
|
const useIsMounted_1 = require("./useIsMounted");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
12
|
-
const io = require("socket.io-client");
|
|
13
|
-
return io;
|
|
14
|
-
}
|
|
15
|
-
catch (err) { }
|
|
16
|
-
if (throwError)
|
|
17
|
-
throw new Error("Must install socket.io-client");
|
|
18
|
-
return {};
|
|
19
|
-
};
|
|
20
|
-
exports.getIO = getIO;
|
|
10
|
+
var getProstglesSocket_2 = require("../getProstglesSocket");
|
|
11
|
+
Object.defineProperty(exports, "getIO", { enumerable: true, get: function () { return getProstglesSocket_2.getIO; } });
|
|
21
12
|
const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, endpoint, token, ...initOpts } = {}) => {
|
|
22
13
|
const { useRef, useState } = (0, reactImports_1.getReact)(true);
|
|
23
14
|
const [onReadyArgs, setOnReadyArgs] = useState({
|
|
@@ -30,21 +21,12 @@ const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, endpoint
|
|
|
30
21
|
if (skip)
|
|
31
22
|
return undefined;
|
|
32
23
|
socketRef.current?.disconnect();
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
: socketPathOrOptions
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...socketOptions,
|
|
40
|
-
reconnectionDelay: 1000,
|
|
41
|
-
reconnection: true,
|
|
42
|
-
};
|
|
43
|
-
socketOptionsWithDefaults.path ??= `/ws-api`;
|
|
44
|
-
if (token) {
|
|
45
|
-
socketOptionsWithDefaults.auth = { token };
|
|
46
|
-
}
|
|
47
|
-
const socket = endpoint ? io(endpoint, socketOptionsWithDefaults) : io(socketOptionsWithDefaults);
|
|
24
|
+
const socket = (0, getProstglesSocket_1.getProstglesSocket)({
|
|
25
|
+
endpoint,
|
|
26
|
+
token,
|
|
27
|
+
socketOptions: socketPathOrOptions,
|
|
28
|
+
credentials: initOpts.credentials,
|
|
29
|
+
});
|
|
48
30
|
socketRef.current = socket;
|
|
49
31
|
await (0, prostgles_1.prostgles)({
|
|
50
32
|
socket,
|
|
@@ -75,7 +57,7 @@ const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, endpoint
|
|
|
75
57
|
throw "Socket disconnected";
|
|
76
58
|
};
|
|
77
59
|
};
|
|
78
|
-
}, [initOpts, socketPathOrOptions, skip], 80);
|
|
60
|
+
}, [endpoint, initOpts, socketPathOrOptions, skip, token], 80);
|
|
79
61
|
return onReadyArgs;
|
|
80
62
|
};
|
|
81
63
|
exports.useProstglesClient = useProstglesClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { UserLike } from "prostgles-types";
|
|
2
|
-
import { type InitOptions } from "./prostgles";
|
|
2
|
+
import { prostgles as pgls, type InitOptions, type ProstglesInitOptions } from "./prostgles";
|
|
3
3
|
import type { ClientFunctionHandler } from "./getMethods";
|
|
4
|
-
declare function prostgles<DBSchema = void, FuncSchema extends ClientFunctionHandler = ClientFunctionHandler, U extends UserLike = UserLike>(params:
|
|
5
|
-
|
|
4
|
+
declare function prostgles<DBSchema = void, FuncSchema extends ClientFunctionHandler = ClientFunctionHandler, U extends UserLike = UserLike>(params: ProstglesInitOptions<DBSchema, FuncSchema, U>): ReturnType<typeof pgls<DBSchema, FuncSchema, U>>;
|
|
5
|
+
declare function prostgles<DBSchema = void, FuncSchema extends ClientFunctionHandler = ClientFunctionHandler, U extends UserLike = UserLike>(params: InitOptions<DBSchema, FuncSchema, U>): ReturnType<typeof pgls<DBSchema, FuncSchema, U>>;
|
|
6
|
+
export { type DBHandlerClient, type ClientOnReadyParams as OnReadyParams, type ProstglesClientState, type TableHandlerClient, type InitOptions, type ProstglesInitOptions, asName, } from "./prostgles";
|
|
6
7
|
export * from "./hooks/useSync";
|
|
7
8
|
export * from "./hooks/useSubscribe";
|
|
8
9
|
export * from "./hooks/useProstglesClient";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,IAAI,IAAI,EAAE,KAAK,WAAW,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,KAA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umd.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type InitOptions } from "./prostgles";
|
|
2
|
-
export declare function prostgles(params: InitOptions): Promise<unknown
|
|
1
|
+
import { type InitOptions, type ProstglesInitOptions } from "./prostgles";
|
|
2
|
+
export declare function prostgles(params: InitOptions | ProstglesInitOptions): Promise<import("./prostgles").ClientOnReadyParams<void, Partial<Record<string, import("./getMethods").FunctionHandle<any, unknown>>>, import("prostgles-types").UserLike>>;
|
|
3
3
|
//# sourceMappingURL=index.umd.d.ts.map
|
package/dist/index.umd.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.d.ts","sourceRoot":"","sources":["../lib/index.umd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.umd.d.ts","sourceRoot":"","sources":["../lib/index.umd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,WAAW,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7F,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,oBAAoB,8KAEnE"}
|