prostgles-client 4.0.211 → 4.0.212

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,8 +1,8 @@
1
1
  import { type DBSchemaTable, type TableSchemaForClient } from "prostgles-types";
2
- import { type InitOptions, type DBHandlerClient } from "./prostgles";
3
- import { type SyncedTable } from "./SyncedTable/SyncedTable";
4
- import type { getSyncHandler } from "./getSyncHandler";
5
2
  import type { getSubscriptionHandler } from "./getSubscriptionHandler";
3
+ import type { getSyncHandler } from "./getSyncHandler";
4
+ import { type DBHandlerClient, type InitOptions } from "./prostgles";
5
+ import { type SyncedTable } from "./SyncedTable/SyncedTable";
6
6
  type Args = {
7
7
  schema: TableSchemaForClient;
8
8
  tableSchema: DBSchemaTable[] | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"getDbHandler.d.ts","sourceRoot":"","sources":["../lib/getDbHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAKlB,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,WAAW,EAGhB,KAAK,eAAe,EAIrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,oBAAoB,CAAC;IAC7B,WAAW,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC;IACzC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,WAAW,EAAE,OAAO,WAAW,GAAG,SAAS,CAAC;IAC5C,WAAW,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;IAC/C,mBAAmB,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;CAChE,CAAC;AAIF,eAAO,MAAM,MAAM,6FAQhB,IAAI;;CAuNN,CAAC"}
1
+ {"version":3,"file":"getDbHandler.d.ts","sourceRoot":"","sources":["../lib/getDbHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAKlB,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,EAKjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,2BAA2B,CAAC;AAEnC,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,oBAAoB,CAAC;IAC7B,WAAW,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC;IACzC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,WAAW,EAAE,OAAO,WAAW,GAAG,SAAS,CAAC;IAC5C,WAAW,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;IAC/C,mBAAmB,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;CAChE,CAAC;AAIF,eAAO,MAAM,MAAM,6FAQhB,IAAI;;CAwNN,CAAC"}
@@ -81,11 +81,12 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
81
81
  };
82
82
  dboTable.sync = sync;
83
83
  dboTable.syncOne = syncOne;
84
+ dboTable.useSync = (basicFilter, options, hookOptions) =>
84
85
  // eslint-disable-next-line react-hooks/rules-of-hooks
85
- dboTable.useSync = (basicFilter, options) => (0, prostgles_1.useSync)(sync, basicFilter, options);
86
- dboTable.useSyncOne = (basicFilter, options) =>
86
+ (0, prostgles_1.useSync)(sync, basicFilter, options, hookOptions);
87
+ dboTable.useSyncOne = (basicFilter, options, hookOptions) =>
87
88
  // eslint-disable-next-line react-hooks/rules-of-hooks
88
- (0, prostgles_1.useSync)(syncOne, basicFilter, options);
89
+ (0, prostgles_1.useSync)(syncOne, basicFilter, options, hookOptions);
89
90
  }
90
91
  dboTable._sync = async function (param1, param2, syncHandles) {
91
92
  await (onDebug === null || onDebug === void 0 ? void 0 : onDebug({
@@ -117,9 +118,9 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
117
118
  : command === "subscribeOne" ? "useSubscribeOne"
118
119
  : undefined;
119
120
  if (handlerName) {
120
- dboTable[handlerName] = (filter, options) =>
121
+ dboTable[handlerName] = (filter, options, hookOptions) =>
121
122
  // eslint-disable-next-line react-hooks/rules-of-hooks
122
- (0, prostgles_1.useSubscribe)(subFunc, command === SUBONE, filter, options);
123
+ (0, prostgles_1.useSubscribe)(subFunc, command === SUBONE, filter, options, hookOptions);
123
124
  }
124
125
  if (command === SUBONE || !subscribeCommands.includes(SUBONE)) {
125
126
  dboTable[SUBONE] = async function (param1, param2, onChange, onError) {
@@ -169,9 +170,9 @@ const getDBO = ({ schema, tableSchema, onDebug, syncedTable, syncHandler, subscr
169
170
  : command === "size" ? "useSize"
170
171
  : undefined;
171
172
  if (methodName) {
172
- dboTable[methodName] = (param1, param2, param3) =>
173
+ dboTable[methodName] = (param1, param2, hookOptions) =>
173
174
  // eslint-disable-next-line react-hooks/rules-of-hooks
174
- (0, prostgles_1.useFetch)(method, [param1, param2, param3]);
175
+ (0, prostgles_1.useFetch)(method, [param1, param2], hookOptions);
175
176
  }
176
177
  }
177
178
  });
@@ -1,6 +1,6 @@
1
1
  import { type SubscriptionChannels, type SubscriptionHandler } from "prostgles-types";
2
2
  import { type AnyFunction, type CoreParams, type InitOptions } from "./prostgles";
3
- type Subscription = CoreParams & {
3
+ export type Subscription = CoreParams & {
4
4
  lastData: any;
5
5
  onCall: AnyFunction;
6
6
  handlers: AnyFunction[];
@@ -1 +1 @@
1
- {"version":3,"file":"getSubscriptionHandler.d.ts","sourceRoot":"","sources":["../lib/getSubscriptionHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAEzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAS,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAGzF,KAAK,YAAY,GAAG,UAAU,GAAG;IAC/B,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,aAAa,EAAE,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;CAC7B,CAAC;AAIF,eAAO,MAAM,sBAAsB,aAAc,KAAK,WAAW,EAAE,QAAQ,GAAG,SAAS,CAAC;kBAkF/E,GAAG,UACA,UAAU,YACR,WAAW,aACV,WAAW,KACrB,QAAQ,mBAAmB,CAAC;;4DA1B5B,UAAU,KAAG,QAAQ,oBAAoB,CAAC;gCAzC9B,MAAM,gBACL,MAAM,WACX,WAAW,KACnB,QAAQ,IAAI,CAAC;;CA0MjB,CAAC"}
1
+ {"version":3,"file":"getSubscriptionHandler.d.ts","sourceRoot":"","sources":["../lib/getSubscriptionHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAEzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAS,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAGzF,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IACtC,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,aAAa,EAAE,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;CAC7B,CAAC;AAIF,eAAO,MAAM,sBAAsB,aAAc,KAAK,WAAW,EAAE,QAAQ,GAAG,SAAS,CAAC;kBAkF/E,GAAG,UACA,UAAU,YACR,WAAW,aACV,WAAW,KACrB,QAAQ,mBAAmB,CAAC;;4DA1B5B,UAAU,KAAG,QAAQ,oBAAoB,CAAC;gCAzC9B,MAAM,gBACL,MAAM,WACX,WAAW,KACnB,QAAQ,IAAI,CAAC;;CA4MjB,CAAC"}
@@ -23,12 +23,18 @@ const getSubscriptionHandler = (initOpts) => {
23
23
  };
24
24
  function _unsubscribe(channelName, unsubChannel, handler) {
25
25
  (0, prostgles_1.debug)("_unsubscribe", { channelName, handler });
26
- return new Promise((resolve, reject) => {
26
+ return new Promise((resolve) => {
27
27
  const sub = subscriptions[channelName];
28
28
  if (sub) {
29
29
  sub.handlers = sub.handlers.filter((h) => h !== handler);
30
+ onDebug === null || onDebug === void 0 ? void 0 : onDebug({
31
+ type: "table",
32
+ command: "unsubscribe",
33
+ tableName: sub.tableName,
34
+ unsubChannel,
35
+ handlers: sub.handlers,
36
+ });
30
37
  if (!sub.handlers.length) {
31
- onDebug === null || onDebug === void 0 ? void 0 : onDebug({ type: "table", command: "unsubscribe", tableName: sub.tableName });
32
38
  removeServerSub(unsubChannel);
33
39
  socket.removeListener(channelName, sub.onCall);
34
40
  delete subscriptions[channelName];
@@ -36,12 +42,6 @@ const getSubscriptionHandler = (initOpts) => {
36
42
  resolve(true);
37
43
  }
38
44
  else {
39
- onDebug === null || onDebug === void 0 ? void 0 : onDebug({
40
- type: "table",
41
- command: "unsubscribe",
42
- tableName: sub.tableName,
43
- unsubChannel,
44
- });
45
45
  resolve(true);
46
46
  }
47
47
  }
@@ -178,6 +178,7 @@ const getSubscriptionHandler = (initOpts) => {
178
178
  * Used when connection is lost and re-established or schema changes
179
179
  */
180
180
  const reAttachAll = async () => {
181
+ await (onDebug === null || onDebug === void 0 ? void 0 : onDebug({ type: "subscriptions", command: "reAttachAll.start", subscriptions }));
181
182
  for await (const s of Object.values(subscriptions)) {
182
183
  try {
183
184
  await s.reAttach();
@@ -187,6 +188,7 @@ const getSubscriptionHandler = (initOpts) => {
187
188
  Object.values(s.errorHandlers).forEach((h) => h === null || h === void 0 ? void 0 : h(err));
188
189
  }
189
190
  }
191
+ await (onDebug === null || onDebug === void 0 ? void 0 : onDebug({ type: "subscriptions", command: "reAttachAll.end", subscriptions }));
190
192
  };
191
193
  return {
192
194
  addSub,