@carbonorm/carbonreact 4.0.12 → 4.0.14

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,12 +1,11 @@
1
1
  import CarbonReact, { iCarbonReactState } from "CarbonReact";
2
- import { tC6Tables, tC6RestApi } from "@carbonorm/carbonnode";
2
+ import { iC6Object } from "@carbonorm/carbonnode";
3
3
  export interface iCarbonWebSocketProps<P, S extends iCarbonReactState> {
4
4
  url?: string;
5
5
  timeoutSeconds?: number;
6
6
  heartbeatSeconds?: number;
7
7
  instance: CarbonReact<P, S>;
8
- TABLES?: tC6Tables;
9
- WsLiveUpdates?: tC6RestApi;
8
+ C6?: iC6Object;
10
9
  }
11
10
  /**
12
11
  * @function connect
package/dist/index.cjs.js CHANGED
@@ -4066,7 +4066,8 @@ const useEffectOnce = (effect) => {
4066
4066
  * This function establishes a connection with the websocket and also ensures constant reconnection if connection closes
4067
4067
  **/
4068
4068
  function initiateWebsocket(props) {
4069
- let { instance, TABLES = undefined, WsLiveUpdates = undefined, url = 'ws' + (window.location.protocol === 'https:' ? 's' : '') + '://' + window.location.host + '/carbonorm/websocket', timeoutSeconds = 250, heartbeatSeconds = 60 } = props;
4069
+ let { instance, url = 'ws' + (window.location.protocol === 'https:' ? 's' : '') + '://' + window.location.host + '/carbonorm/websocket', timeoutSeconds = 250, heartbeatSeconds = 60, C6 } = props;
4070
+ const { TABLES = undefined, IMPORT = undefined, } = C6 ?? {};
4070
4071
  const { websocket } = instance.state;
4071
4072
  if (!("WebSocket" in window)) {
4072
4073
  // todo - store that this has been shown in the state
@@ -4113,10 +4114,6 @@ function initiateWebsocket(props) {
4113
4114
  console.log('WebSocket updates without the TABLES property passed will not automatically update the state.');
4114
4115
  return;
4115
4116
  }
4116
- if (undefined === WsLiveUpdates) {
4117
- console.log('WebSocket updates without the WsLiveUpdates property passed will not automatically update the state.');
4118
- return;
4119
- }
4120
4117
  if (parsedData?.REST) {
4121
4118
  const TABLE_NAME = parsedData?.REST?.TABLE_NAME;
4122
4119
  const TABLE_PREFIX = parsedData?.REST?.TABLE_PREFIX;
@@ -4138,7 +4135,8 @@ function initiateWebsocket(props) {
4138
4135
  return;
4139
4136
  }
4140
4137
  const primaryKeyKeys = Object.keys(REQUEST_PRIMARY_KEY);
4141
- const elementsToUpdate = currentCache.filter((row) => {
4138
+ // todo - which direction should we filter
4139
+ const elementsToUpdate = currentCache?.filter((row) => {
4142
4140
  for (const element of primaryKeyKeys) {
4143
4141
  // remove the table name from the column name
4144
4142
  const column = element.split('.')[1];
@@ -4148,7 +4146,7 @@ function initiateWebsocket(props) {
4148
4146
  }
4149
4147
  }
4150
4148
  return true;
4151
- });
4149
+ }) ?? [];
4152
4150
  console.log('elementsToUpdate', elementsToUpdate);
4153
4151
  if (elementsToUpdate.length === 0) {
4154
4152
  console.error('Could not find any elements to update in the cache.', elementsToUpdate, primaryKeyKeys, REQUEST_PRIMARY_KEY, currentCache);
@@ -4160,8 +4158,22 @@ function initiateWebsocket(props) {
4160
4158
  ...REQUEST
4161
4159
  };
4162
4160
  });
4163
- updatedElements.forEach((row) => {
4164
- WsLiveUpdates[TABLE_NAME_SHORT][METHOD]({}, row);
4161
+ updatedElements.forEach(async (row) => {
4162
+ const RestRequests = await IMPORT?.(TABLE_NAME_SHORT);
4163
+ const { postState, deleteState, putState, } = RestRequests;
4164
+ switch (METHOD) {
4165
+ case 'POST':
4166
+ postState({}, row);
4167
+ break;
4168
+ case 'DELETE':
4169
+ deleteState({}, row);
4170
+ break;
4171
+ case 'PUT':
4172
+ putState({}, row);
4173
+ break;
4174
+ default:
4175
+ console.error('Method not supported', METHOD);
4176
+ }
4165
4177
  });
4166
4178
  }
4167
4179
  });