prostgles-client 4.0.304 → 4.0.306
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/getDbHandler.d.ts +2 -2
- package/dist/getDbHandler.d.ts.map +1 -1
- package/dist/getDbHandler.js +12 -12
- package/dist/hooks/useProstglesClient.d.ts +6 -17
- package/dist/hooks/useProstglesClient.d.ts.map +1 -1
- package/dist/hooks/useProstglesClient.js +9 -19
- package/dist/index.js +1 -1
- package/dist/index.no-sync.js +1 -1
- package/dist/prostgles-full.d.ts +2 -2
- package/dist/prostgles-full.d.ts.map +1 -1
- package/dist/prostgles.d.ts +28 -34
- package/dist/prostgles.d.ts.map +1 -1
- package/dist/prostgles.js +12 -25
- package/package.json +2 -2
package/dist/getDbHandler.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ type Args = {
|
|
|
12
12
|
syncHandler: ReturnType<typeof getSyncHandler>;
|
|
13
13
|
subscriptionHandler: ReturnType<typeof getSubscriptionHandler>;
|
|
14
14
|
};
|
|
15
|
-
export declare const
|
|
16
|
-
|
|
15
|
+
export declare const getDB: <DBSchema = void>({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscriptionHandler, socket, }: Args) => {
|
|
16
|
+
db: Partial<DBHandlerClient<DBSchema>>;
|
|
17
17
|
};
|
|
18
18
|
export {};
|
|
19
19
|
//# sourceMappingURL=getDbHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDbHandler.d.ts","sourceRoot":"","sources":["../lib/getDbHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAMlB,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,WAAW,EAE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OAAO,sBAAsB,CAAC,CAAC;CAChE,CAAC;AAIF,eAAO,MAAM,KAAK,8GAQf,IAAI;;CAwNN,CAAC"}
|
package/dist/getDbHandler.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getDB = void 0;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const SyncedTable_1 = require("./SyncedTable/SyncedTable");
|
|
6
6
|
const useSubscribe_1 = require("./hooks/useSubscribe");
|
|
7
7
|
const useSync_1 = require("./hooks/useSync");
|
|
8
8
|
const useFetch_1 = require("./hooks/useFetch");
|
|
9
9
|
const preffix = prostgles_types_1.CHANNELS._preffix;
|
|
10
|
-
const
|
|
11
|
-
/* Building
|
|
10
|
+
const getDB = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscriptionHandler, socket, }) => {
|
|
11
|
+
/* Building DB object */
|
|
12
12
|
const checkSubscriptionArgs = (basicFilter, options, onChange, onError) => {
|
|
13
13
|
if ((basicFilter !== undefined && !(0, prostgles_types_1.isObject)(basicFilter)) ||
|
|
14
14
|
(options !== undefined && !(0, prostgles_types_1.isObject)(options)) ||
|
|
@@ -18,12 +18,12 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
const subscribeCommands = ["subscribe", "subscribeOne"];
|
|
21
|
-
const
|
|
21
|
+
const db = {};
|
|
22
22
|
const schemaClone = (0, SyncedTable_1.quickClone)(schema);
|
|
23
23
|
(0, prostgles_types_1.getObjectEntries)(schemaClone).forEach(([tableName, methods]) => {
|
|
24
24
|
const allowedCommands = (0, prostgles_types_1.getKeys)(methods);
|
|
25
|
-
|
|
26
|
-
const dboTable =
|
|
25
|
+
db[tableName] = {};
|
|
26
|
+
const dboTable = db[tableName];
|
|
27
27
|
allowedCommands
|
|
28
28
|
.sort((a, b) => Number((0, prostgles_types_1.includes)(subscribeCommands, a)) - Number((0, prostgles_types_1.includes)(subscribeCommands, b)))
|
|
29
29
|
.forEach((command) => {
|
|
@@ -41,7 +41,7 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
|
|
|
41
41
|
name: tableName,
|
|
42
42
|
onDebug: onDebug,
|
|
43
43
|
filter,
|
|
44
|
-
db:
|
|
44
|
+
db: db,
|
|
45
45
|
...params,
|
|
46
46
|
});
|
|
47
47
|
};
|
|
@@ -53,7 +53,7 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
|
|
|
53
53
|
onDebug: onDebug,
|
|
54
54
|
name: tableName,
|
|
55
55
|
filter: basicFilter,
|
|
56
|
-
db:
|
|
56
|
+
db: db,
|
|
57
57
|
onError,
|
|
58
58
|
}));
|
|
59
59
|
syncHandler.syncedTables[syncName] = syncedTableHandler;
|
|
@@ -109,7 +109,7 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
|
|
|
109
109
|
data: { param1, param2, onChange, onError },
|
|
110
110
|
}));
|
|
111
111
|
checkSubscriptionArgs(param1, param2, onChange, onError);
|
|
112
|
-
return subscriptionHandler.addSub(
|
|
112
|
+
return subscriptionHandler.addSub(db, { tableName, command, param1, param2 }, onChange, onError);
|
|
113
113
|
};
|
|
114
114
|
dboTable[command] = subFunc;
|
|
115
115
|
const SUBONE = "subscribeOne";
|
|
@@ -136,7 +136,7 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
|
|
|
136
136
|
const onChangeOne = (rows) => {
|
|
137
137
|
onChange(rows[0]);
|
|
138
138
|
};
|
|
139
|
-
return subscriptionHandler.addSub(
|
|
139
|
+
return subscriptionHandler.addSub(db, { tableName, command, param1, param2 }, onChangeOne, onError);
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
}
|
|
@@ -179,6 +179,6 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
|
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
181
|
});
|
|
182
|
-
return {
|
|
182
|
+
return { db: db };
|
|
183
183
|
};
|
|
184
|
-
exports.
|
|
184
|
+
exports.getDB = getDB;
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import { type DBSchema, type
|
|
2
|
-
import type { ManagerOptions,
|
|
3
|
-
import type
|
|
4
|
-
import { type DBHandlerClient, type InitOptions } from "../prostgles";
|
|
5
|
-
import type { ClientFunctionHandler } from "lib/getMethods";
|
|
1
|
+
import { type DBSchema, type UserLike } from "prostgles-types";
|
|
2
|
+
import type { ManagerOptions, SocketOptions } from "socket.io-client";
|
|
3
|
+
import { type InitOptions, type ClientOnReadyParams } from "../prostgles";
|
|
6
4
|
export declare const getIO: (throwError?: boolean) => typeof import("socket.io-client").io;
|
|
7
|
-
export type OnReadyParams<DBSchema, FunctionSchema extends ClientFunctionHandler = ClientFunctionHandler, U extends UserLike = UserLike> = {
|
|
8
|
-
dbo: DBHandlerClient<DBSchema>;
|
|
9
|
-
methods: FunctionSchema | undefined;
|
|
10
|
-
methodSchema: ServerFunctionHandler | undefined;
|
|
11
|
-
tableSchema: DBSchemaTable[] | undefined;
|
|
12
|
-
auth: AuthHandler<U>;
|
|
13
|
-
isReconnect: boolean;
|
|
14
|
-
socket: Socket;
|
|
15
|
-
};
|
|
16
5
|
type SocketPathOrOptions = Partial<ManagerOptions & SocketOptions>;
|
|
17
6
|
export type UseProstglesClientProps = Omit<InitOptions<DBSchema>, "onReady" | "socket"> & {
|
|
18
7
|
/**
|
|
@@ -24,17 +13,17 @@ export type UseProstglesClientProps = Omit<InitOptions<DBSchema>, "onReady" | "s
|
|
|
24
13
|
};
|
|
25
14
|
export type ProstglesClientState<PGC> = {
|
|
26
15
|
isLoading: true;
|
|
27
|
-
hasError
|
|
16
|
+
hasError: false;
|
|
28
17
|
error?: undefined;
|
|
29
18
|
} | ({
|
|
30
19
|
isLoading: false;
|
|
31
|
-
hasError
|
|
20
|
+
hasError: false;
|
|
32
21
|
error?: undefined;
|
|
33
22
|
} & PGC) | {
|
|
34
23
|
isLoading: false;
|
|
35
24
|
hasError: true;
|
|
36
25
|
error: unknown;
|
|
37
26
|
};
|
|
38
|
-
export declare const useProstglesClient: <DBSchema_1, FuncSchema extends Partial<Record<string, import("lib/getMethods").FunctionHandle>> = Partial<Record<string, import("lib/getMethods").FunctionHandle>>, U extends UserLike = UserLike>({ skip, socketOptions: socketPathOrOptions, endpoint, token, ...initOpts }?: UseProstglesClientProps) => ProstglesClientState<
|
|
27
|
+
export declare const useProstglesClient: <DBSchema_1, FuncSchema extends Partial<Record<string, import("lib/getMethods").FunctionHandle>> = Partial<Record<string, import("lib/getMethods").FunctionHandle>>, U extends UserLike = UserLike>({ skip, socketOptions: socketPathOrOptions, endpoint, token, ...initOpts }?: UseProstglesClientProps) => ProstglesClientState<ClientOnReadyParams<DBSchema_1, FuncSchema, U>>;
|
|
39
28
|
export {};
|
|
40
29
|
//# sourceMappingURL=useProstglesClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../../lib/hooks/useProstglesClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useProstglesClient.d.ts","sourceRoot":"","sources":["../../lib/hooks/useProstglesClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG/D,OAAO,KAAK,EAAE,cAAc,EAAU,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAOrF,eAAO,MAAM,KAAK,gEAQjB,CAAC;AAEF,KAAK,mBAAmB,GAAG,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAAC;AAEnE,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,mRAU5B,uBAAuB,yEAwEzB,CAAC"}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Stefan L. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License. See LICENSE in the project root for license information.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
3
|
exports.useProstglesClient = exports.getIO = void 0;
|
|
8
|
-
const SyncedTable_1 = require("../SyncedTable/SyncedTable");
|
|
9
4
|
const prostgles_1 = require("../prostgles");
|
|
5
|
+
const SyncedTable_1 = require("../SyncedTable/SyncedTable");
|
|
10
6
|
const reactImports_1 = require("./reactImports");
|
|
11
|
-
const useIsMounted_1 = require("./useIsMounted");
|
|
12
7
|
const useAsyncEffectQueue_1 = require("./useAsyncEffectQueue");
|
|
8
|
+
const useIsMounted_1 = require("./useIsMounted");
|
|
13
9
|
const getIO = (throwError = false) => {
|
|
14
10
|
try {
|
|
15
11
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
@@ -26,6 +22,7 @@ const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, endpoint
|
|
|
26
22
|
const { useRef, useState } = (0, reactImports_1.getReact)(true);
|
|
27
23
|
const [onReadyArgs, setOnReadyArgs] = useState({
|
|
28
24
|
isLoading: true,
|
|
25
|
+
hasError: false,
|
|
29
26
|
});
|
|
30
27
|
const getIsMounted = (0, useIsMounted_1.useIsMounted)();
|
|
31
28
|
const socketRef = useRef();
|
|
@@ -54,24 +51,17 @@ const useProstglesClient = ({ skip, socketOptions: socketPathOrOptions, endpoint
|
|
|
54
51
|
socket,
|
|
55
52
|
endpoint,
|
|
56
53
|
...initOpts,
|
|
57
|
-
onReady: (
|
|
54
|
+
onReady: (onReadyArgs) => {
|
|
58
55
|
var _a, _b;
|
|
59
|
-
const [dbo, methods, methodSchema, tableSchema, auth, isReconnect] = args;
|
|
60
|
-
const onReadyArgs = {
|
|
61
|
-
dbo,
|
|
62
|
-
methods,
|
|
63
|
-
methodSchema,
|
|
64
|
-
tableSchema,
|
|
65
|
-
auth,
|
|
66
|
-
isReconnect,
|
|
67
|
-
socket,
|
|
68
|
-
};
|
|
69
56
|
if (!getIsMounted()) {
|
|
70
|
-
(_a = initOpts.onDebug) === null || _a === void 0 ? void 0 : _a.call(initOpts, {
|
|
57
|
+
(_a = initOpts.onDebug) === null || _a === void 0 ? void 0 : _a.call(initOpts, {
|
|
58
|
+
type: "onReady.notMounted",
|
|
59
|
+
data: onReadyArgs,
|
|
60
|
+
});
|
|
71
61
|
return;
|
|
72
62
|
}
|
|
73
63
|
(_b = initOpts.onDebug) === null || _b === void 0 ? void 0 : _b.call(initOpts, { type: "onReady", data: onReadyArgs });
|
|
74
|
-
setOnReadyArgs({ ...onReadyArgs, isLoading: false });
|
|
64
|
+
setOnReadyArgs({ ...onReadyArgs, hasError: false, isLoading: false });
|
|
75
65
|
},
|
|
76
66
|
}, SyncedTable_1.SyncedTable).catch((error) => {
|
|
77
67
|
if (!getIsMounted())
|