@arcote.tech/arc-react 0.3.0 → 0.3.2
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.js +44 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -301,7 +301,10 @@ import {
|
|
|
301
301
|
EventWire,
|
|
302
302
|
LocalEventPublisher,
|
|
303
303
|
MasterDataStorage,
|
|
304
|
-
Model
|
|
304
|
+
Model,
|
|
305
|
+
QueryWire,
|
|
306
|
+
StreamingEventPublisher,
|
|
307
|
+
StreamingQueryCache
|
|
305
308
|
} from "@arcote.tech/arc";
|
|
306
309
|
import { createContext as createContext4, useContext as useContext3, useEffect as useEffect2, useState as useState3 } from "react";
|
|
307
310
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
@@ -309,6 +312,7 @@ var modelProviderFactory = (context, options) => {
|
|
|
309
312
|
const ModelContext = createContext4(null);
|
|
310
313
|
const commandWire = options.remoteUrl ? new CommandWire(options.remoteUrl) : undefined;
|
|
311
314
|
const eventWire = options.remoteUrl ? new EventWire(options.remoteUrl) : undefined;
|
|
315
|
+
const queryWire = options.remoteUrl ? new QueryWire(options.remoteUrl) : undefined;
|
|
312
316
|
const authAdapter = new AuthAdapter;
|
|
313
317
|
let initialized = false;
|
|
314
318
|
let cachedModel = null;
|
|
@@ -336,6 +340,8 @@ var modelProviderFactory = (context, options) => {
|
|
|
336
340
|
async function initializeModel() {
|
|
337
341
|
let dataStorage;
|
|
338
342
|
let eventPublisher;
|
|
343
|
+
let streamingCache;
|
|
344
|
+
const views = context.elements.filter((element) => ("getHandlers" in element) && ("databaseStoreSchema" in element) && ("schema" in element));
|
|
339
345
|
if (options.dbAdapterFactory) {
|
|
340
346
|
const databaseAdapter = await options.dbAdapterFactory(context);
|
|
341
347
|
if (cancelled)
|
|
@@ -344,7 +350,6 @@ var modelProviderFactory = (context, options) => {
|
|
|
344
350
|
dataStorage = new MasterDataStorage(databaseAdapter);
|
|
345
351
|
cachedDataStorage = dataStorage;
|
|
346
352
|
eventPublisher = new LocalEventPublisher(dataStorage);
|
|
347
|
-
const views = context.elements.filter((element) => ("getHandlers" in element) && ("databaseStoreSchema" in element) && ("schema" in element));
|
|
348
353
|
eventPublisher.registerViews(views);
|
|
349
354
|
if (eventWire && eventPublisher) {
|
|
350
355
|
const publisher = eventPublisher;
|
|
@@ -413,16 +418,48 @@ Event payload:`, event.payload);
|
|
|
413
418
|
}
|
|
414
419
|
}
|
|
415
420
|
}
|
|
421
|
+
} else if (eventWire && queryWire) {
|
|
422
|
+
streamingCache = new StreamingQueryCache;
|
|
423
|
+
streamingCache.registerViews(views);
|
|
424
|
+
eventPublisher = new StreamingEventPublisher(streamingCache, eventWire);
|
|
425
|
+
eventPublisher.registerViews(views);
|
|
426
|
+
const processedEvents = new Set;
|
|
427
|
+
let eventQueue = Promise.resolve();
|
|
428
|
+
eventWire.onEvent((event) => {
|
|
429
|
+
eventQueue = eventQueue.then(async () => {
|
|
430
|
+
try {
|
|
431
|
+
if (processedEvents.has(event.hostId)) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
processedEvents.add(event.hostId);
|
|
435
|
+
await streamingCache.applyEvent({
|
|
436
|
+
id: event.hostId,
|
|
437
|
+
type: event.type,
|
|
438
|
+
payload: event.payload,
|
|
439
|
+
createdAt: new Date(event.createdAt)
|
|
440
|
+
});
|
|
441
|
+
} catch (error) {
|
|
442
|
+
console.error(`[Arc] Failed to process event ${event.hostId} (${event.type}):`, error);
|
|
443
|
+
processedEvents.delete(event.hostId);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
if (authAdapter.isAuthenticated()) {
|
|
448
|
+
eventWire.connect();
|
|
449
|
+
}
|
|
416
450
|
}
|
|
417
451
|
if (cancelled)
|
|
418
452
|
return;
|
|
453
|
+
const modelEventWire = options.dbAdapterFactory ? eventWire : undefined;
|
|
419
454
|
const newModel = new Model(context, {
|
|
420
455
|
adapters: {
|
|
421
456
|
dataStorage,
|
|
422
457
|
commandWire,
|
|
423
458
|
eventPublisher,
|
|
424
|
-
eventWire,
|
|
425
|
-
authAdapter
|
|
459
|
+
eventWire: modelEventWire,
|
|
460
|
+
authAdapter,
|
|
461
|
+
queryWire,
|
|
462
|
+
streamingCache
|
|
426
463
|
},
|
|
427
464
|
environment: "client"
|
|
428
465
|
});
|
|
@@ -459,6 +496,7 @@ Event payload:`, event.payload);
|
|
|
459
496
|
function setAuthToken(token) {
|
|
460
497
|
authAdapter.setToken(token);
|
|
461
498
|
commandWire?.setAuthToken(token);
|
|
499
|
+
queryWire?.setAuthToken(token);
|
|
462
500
|
if (eventWire) {
|
|
463
501
|
eventWire.setAuthToken(token);
|
|
464
502
|
if (token && eventWire.getState() === "disconnected") {
|
|
@@ -476,6 +514,7 @@ Event payload:`, event.payload);
|
|
|
476
514
|
initialized = false;
|
|
477
515
|
authAdapter.setToken(null);
|
|
478
516
|
commandWire?.setAuthToken(null);
|
|
517
|
+
queryWire?.setAuthToken(null);
|
|
479
518
|
eventWire?.setAuthToken(null);
|
|
480
519
|
if (onResetCallback) {
|
|
481
520
|
onResetCallback();
|
|
@@ -557,4 +596,4 @@ export {
|
|
|
557
596
|
Form
|
|
558
597
|
};
|
|
559
598
|
|
|
560
|
-
//# debugId=
|
|
599
|
+
//# debugId=C47814C8000DC1A064756E2164756E21
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
7
7
|
"description": "React client for the Arc framework, providing utilities for querying data and executing commands, enhancing the development of reactive and efficient user interfaces.",
|