prostgles-client 4.0.331 → 4.0.333

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,10 +1,9 @@
1
- import { type DBSchemaTable, type TableSchemaForClient } from "prostgles-types";
1
+ import { type DBSchemaTable } from "prostgles-types";
2
2
  import type { getSubscriptionHandler } from "./getSubscriptionHandler";
3
3
  import type { getSyncHandler } from "./getSyncHandler";
4
4
  import { type DBHandlerClient, type InitOptions } from "./prostgles";
5
5
  import { type SyncedTable } from "./SyncedTable/SyncedTable";
6
6
  type Args = {
7
- schema: TableSchemaForClient;
8
7
  tableSchema: DBSchemaTable[] | undefined;
9
8
  onDebug: InitOptions["onDebug"];
10
9
  socket: InitOptions["socket"];
@@ -12,7 +11,7 @@ type Args = {
12
11
  syncHandler: ReturnType<typeof getSyncHandler>;
13
12
  subscriptionHandler: ReturnType<typeof getSubscriptionHandler>;
14
13
  };
15
- export declare const getDB: <DBSchema = void>({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscriptionHandler, socket, }: Args) => {
14
+ export declare const getDB: <DBSchema = void>({ tableSchema, onDebug, syncedTable, syncHandler, subscriptionHandler, socket, }: Args) => {
16
15
  db: Partial<DBHandlerClient<DBSchema>>;
17
16
  };
18
17
  export {};
@@ -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,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,2BAA2B,CAAC;AAKnC,KAAK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;AAIF,eAAO,MAAM,KAAK,GAAI,QAAQ,GAAG,IAAI,EAAE,kFAOpC,IAAI;QAuNc,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;CACtD,CAAC"}
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDB = void 0;
4
4
  const prostgles_types_1 = require("prostgles-types");
5
- const SyncedTable_1 = require("./SyncedTable/SyncedTable");
5
+ const useFetch_1 = require("./hooks/useFetch");
6
6
  const useSubscribe_1 = require("./hooks/useSubscribe");
7
7
  const useSync_1 = require("./hooks/useSync");
8
- const useFetch_1 = require("./hooks/useFetch");
8
+ const SyncedTable_1 = require("./SyncedTable/SyncedTable");
9
9
  const preffix = prostgles_types_1.CHANNELS._preffix;
10
- const getDB = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscriptionHandler, socket, }) => {
10
+ const getDB = ({ tableSchema, onDebug, syncedTable, syncHandler, subscriptionHandler, socket, }) => {
11
+ var _a;
11
12
  /* Building DB object */
12
13
  const checkSubscriptionArgs = (basicFilter, options, onChange, onError) => {
13
14
  if ((basicFilter !== undefined && !(0, prostgles_types_1.isObject)(basicFilter)) ||
@@ -19,16 +20,17 @@ const getDB = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscri
19
20
  };
20
21
  const subscribeCommands = ["subscribe", "subscribeOne"];
21
22
  const db = {};
22
- const schemaClone = (0, SyncedTable_1.quickClone)(schema);
23
- (0, prostgles_types_1.getObjectEntries)(schemaClone).forEach(([tableName, methods]) => {
24
- const allowedCommands = (0, prostgles_types_1.getKeys)(methods);
23
+ const schemaClone = (_a = (0, SyncedTable_1.quickClone)(tableSchema)) !== null && _a !== void 0 ? _a : [];
24
+ schemaClone.forEach(({ name: tableName, publishInfo }) => {
25
+ // const allowedCommands = getKeys(methods);
26
+ const allowedCommands = (0, prostgles_types_1.getAllowedTableMethods)({ publishInfo });
25
27
  db[tableName] = {};
26
28
  const dboTable = db[tableName];
27
29
  allowedCommands
28
30
  .sort((a, b) => Number((0, prostgles_types_1.includes)(subscribeCommands, a)) - Number((0, prostgles_types_1.includes)(subscribeCommands, b)))
29
31
  .forEach((command) => {
30
32
  if (command === "sync") {
31
- dboTable._syncInfo = { ...methods[command] };
33
+ dboTable._syncInfo = { ...publishInfo[command] };
32
34
  if (syncedTable) {
33
35
  dboTable.getSync = async (filter, params = {}) => {
34
36
  await (onDebug === null || onDebug === void 0 ? void 0 : onDebug({
@@ -166,13 +168,13 @@ const getDB = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscri
166
168
  });
167
169
  };
168
170
  dboTable[command] = method;
169
- const methodName = command === "findOne" ? "useFindOne"
171
+ const reactHookName = command === "findOne" ? "useFindOne"
170
172
  : command === "find" ? "useFind"
171
173
  : command === "count" ? "useCount"
172
174
  : command === "size" ? "useSize"
173
175
  : undefined;
174
- if (methodName) {
175
- dboTable[methodName] = (param1, param2, hookOptions) =>
176
+ if (reactHookName) {
177
+ dboTable[reactHookName] = (param1, param2, hookOptions) =>
176
178
  // eslint-disable-next-line react-hooks/rules-of-hooks
177
179
  (0, useFetch_1.useFetch)(method, [param1, param2], hookOptions);
178
180
  }