@carbonorm/carbonreact 6.0.2 → 6.0.4
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.cjs +34 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +34 -55
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/WebSocket/CarbonWebSocket.tsx +45 -65
- package/src/core/CarbonReact.tsx +0 -1
|
@@ -125,21 +125,11 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
|
|
|
125
125
|
|
|
126
126
|
const REQUEST_PRIMARY_KEY: {
|
|
127
127
|
[key: string]: string
|
|
128
|
-
} = parsedData?.REST?.REQUEST_PRIMARY_KEY ?? null;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.log('WebSocket updates without a primary key are not yet supported.');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return;
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (verbose) {
|
|
141
|
-
console.log('todo - going to impl REST', TABLE_NAME, METHOD, REQUEST_PRIMARY_KEY, parsedData?.REST);
|
|
142
|
-
}
|
|
128
|
+
} | null = parsedData?.REST?.REQUEST_PRIMARY_KEY ?? null;
|
|
129
|
+
const RESPONSE_PRIMARY_KEY: {
|
|
130
|
+
[key: string]: string
|
|
131
|
+
} | null = parsedData?.REST?.RESPONSE_PRIMARY_KEY ?? null;
|
|
132
|
+
const RESPONSE = parsedData?.REST?.RESPONSE ?? null;
|
|
143
133
|
|
|
144
134
|
const TABLE_NAME_SHORT = TABLE_NAME.startsWith(TABLE_PREFIX)
|
|
145
135
|
? TABLE_NAME.substring(TABLE_PREFIX.length)
|
|
@@ -175,19 +165,28 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
|
|
|
175
165
|
return normalized;
|
|
176
166
|
};
|
|
177
167
|
|
|
178
|
-
const normalizedPrimaryKey = normalizeRecord(REQUEST_PRIMARY_KEY);
|
|
179
|
-
const
|
|
168
|
+
const normalizedPrimaryKey = normalizeRecord(REQUEST_PRIMARY_KEY ?? {});
|
|
169
|
+
const normalizedResponsePrimaryKey = normalizeRecord(RESPONSE_PRIMARY_KEY ?? {});
|
|
170
|
+
const primaryKeyKeys = Object.keys(
|
|
171
|
+
Object.keys(normalizedPrimaryKey).length
|
|
172
|
+
? normalizedPrimaryKey
|
|
173
|
+
: normalizedResponsePrimaryKey
|
|
174
|
+
);
|
|
180
175
|
|
|
181
176
|
if (primaryKeyKeys.length === 0) {
|
|
182
177
|
if (verbose) {
|
|
183
|
-
console.error('WebSocket update could not map primary keys for', TABLE_NAME_SHORT, REQUEST_PRIMARY_KEY);
|
|
178
|
+
console.error('WebSocket update could not map primary keys for', TABLE_NAME_SHORT, REQUEST_PRIMARY_KEY, RESPONSE_PRIMARY_KEY);
|
|
184
179
|
}
|
|
185
180
|
return;
|
|
186
181
|
}
|
|
187
182
|
|
|
188
183
|
// todo - which direction should we filter
|
|
189
184
|
const elementsToUpdate = currentCache?.filter((row: any) =>
|
|
190
|
-
primaryKeyKeys.every((key) =>
|
|
185
|
+
primaryKeyKeys.every((key) => {
|
|
186
|
+
const expected =
|
|
187
|
+
normalizedPrimaryKey[key] ?? normalizedResponsePrimaryKey[key];
|
|
188
|
+
return expected === row[key];
|
|
189
|
+
})
|
|
191
190
|
) ?? []
|
|
192
191
|
|
|
193
192
|
if (verbose) {
|
|
@@ -195,6 +194,17 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
|
|
|
195
194
|
}
|
|
196
195
|
|
|
197
196
|
if (elementsToUpdate.length === 0) {
|
|
197
|
+
if (RESPONSE) {
|
|
198
|
+
const responseRows = Array.isArray(RESPONSE) ? RESPONSE : [RESPONSE];
|
|
199
|
+
const normalizedResponseRows = responseRows.map((row) => normalizeRecord(row as any));
|
|
200
|
+
instance.updateRestfulObjectArrays({
|
|
201
|
+
dataOrCallback: normalizedResponseRows,
|
|
202
|
+
stateKey: TABLE_NAME_SHORT as any,
|
|
203
|
+
uniqueObjectId: c6Table.PRIMARY_SHORT as any,
|
|
204
|
+
});
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
198
208
|
if (verbose) {
|
|
199
209
|
console.error('Could not find any elements to update in the cache.', elementsToUpdate, primaryKeyKeys, REQUEST_PRIMARY_KEY, currentCache);
|
|
200
210
|
}
|
|
@@ -258,61 +268,34 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
|
|
|
258
268
|
|
|
259
269
|
}
|
|
260
270
|
|
|
261
|
-
|
|
271
|
+
if (event.code === 1000) {
|
|
272
|
+
console.log("WebSocket: closed cleanly");
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
262
276
|
switch (event.code) {
|
|
263
|
-
case 1000:
|
|
264
|
-
reason = "Normal closure, meaning that the purpose for which the connection was established has been fulfilled.";
|
|
265
|
-
break;
|
|
266
|
-
case 1001:
|
|
267
|
-
retry(); //call check function after timeout
|
|
268
|
-
reason = "An endpoint is \"going away\", such as a server going down or a browser having navigated away from a page.";
|
|
269
|
-
break;
|
|
270
|
-
case 1002:
|
|
271
|
-
reason = "An endpoint is terminating the connection due to a protocol error";
|
|
272
|
-
break;
|
|
273
|
-
case 1003:
|
|
274
|
-
reason = "An endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message).";
|
|
275
|
-
break;
|
|
276
|
-
case 1004:
|
|
277
|
-
reason = "Reserved. The specific meaning might be defined in the future.";
|
|
278
|
-
break;
|
|
279
|
-
case 1005:
|
|
280
|
-
reason = "No status code was actually present.";
|
|
281
|
-
break;
|
|
282
277
|
case 1006:
|
|
283
|
-
|
|
284
|
-
reason = "The connection was closed abnormally, e.g., without sending or receiving a close control frame";
|
|
278
|
+
reason = "Abnormal closure";
|
|
285
279
|
break;
|
|
286
|
-
case
|
|
287
|
-
reason = "
|
|
288
|
-
break;
|
|
289
|
-
case 1008:
|
|
290
|
-
reason = "An endpoint is terminating the connection because it has received a message that \"violates its policy\". This reason is given either if there is no other suitable reason, or if there is a need to hide specific details about the policy.";
|
|
291
|
-
break;
|
|
292
|
-
case 1009:
|
|
293
|
-
reason = "An endpoint is terminating the connection because it has received a message that is too big for it to process.";
|
|
294
|
-
break;
|
|
295
|
-
case 1010:
|
|
296
|
-
reason = "An endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. <br /> Specifically, the extensions that are needed are: " + event.reason;
|
|
280
|
+
case 1001:
|
|
281
|
+
reason = "Going away";
|
|
297
282
|
break;
|
|
298
283
|
case 1011:
|
|
299
|
-
reason = "
|
|
300
|
-
break;
|
|
301
|
-
case 1015:
|
|
302
|
-
reason = "The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).";
|
|
284
|
+
reason = "Internal server error";
|
|
303
285
|
break;
|
|
304
286
|
default:
|
|
305
|
-
reason = "Unknown
|
|
287
|
+
reason = "Unknown";
|
|
306
288
|
}
|
|
307
289
|
|
|
308
|
-
console.log(
|
|
290
|
+
console.log(`WebSocket: closed with code ${event.code} (${reason})`)
|
|
291
|
+
|
|
292
|
+
retry();
|
|
309
293
|
|
|
310
294
|
});
|
|
311
295
|
|
|
312
296
|
// websocket onerror event listener
|
|
313
297
|
connection.addEventListener('websocket error', (e: Event) => {
|
|
314
|
-
console.error("
|
|
315
|
-
connection.close();
|
|
298
|
+
console.error("WebSocket error observed:", e);
|
|
316
299
|
});
|
|
317
300
|
|
|
318
301
|
});
|
|
@@ -322,11 +305,8 @@ export function initiateWebsocket<P, S extends iCarbonReactState>(props: iCarbon
|
|
|
322
305
|
export default function <P, S extends iCarbonReactState>(props: iCarbonWebSocketProps<P, S>) {
|
|
323
306
|
|
|
324
307
|
useEffectOnce(() => {
|
|
325
|
-
|
|
326
|
-
initiateWebsocket(props)
|
|
327
|
-
|
|
308
|
+
initiateWebsocket(props);
|
|
328
309
|
})
|
|
329
310
|
|
|
330
|
-
return null
|
|
331
|
-
|
|
311
|
+
return null;
|
|
332
312
|
}
|
package/src/core/CarbonReact.tsx
CHANGED
|
@@ -132,7 +132,6 @@ abstract class CarbonReact<P = {}, S extends iCarbonReactState = iCarbonReactSta
|
|
|
132
132
|
|
|
133
133
|
this.target = new.target;
|
|
134
134
|
this.stateAdapter = props.stateAdapter;
|
|
135
|
-
console.log('CarbonORM TSX CONSTRUCTOR');
|
|
136
135
|
|
|
137
136
|
Object.assign(this.target, {
|
|
138
137
|
_instance: this
|