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