@arcote.tech/arc-react 0.7.14 → 0.7.16
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 +28 -71
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -305,8 +305,7 @@ import {
|
|
|
305
305
|
QueryWire,
|
|
306
306
|
StreamingEventPublisher,
|
|
307
307
|
StreamingQueryCache,
|
|
308
|
-
buildContextAccessor
|
|
309
|
-
resolveQueryChange
|
|
308
|
+
buildContextAccessor
|
|
310
309
|
} from "@arcote.tech/arc";
|
|
311
310
|
import {
|
|
312
311
|
createContext as createContext4,
|
|
@@ -321,7 +320,9 @@ import { jsx as jsx5 } from "react/jsx-runtime";
|
|
|
321
320
|
var modelProviderFactory = (context, options) => {
|
|
322
321
|
const ModelContext = createContext4(null);
|
|
323
322
|
const commandWire = options.remoteUrl ? new CommandWire(options.remoteUrl) : undefined;
|
|
324
|
-
const eventWire = options.remoteUrl ? new EventWire(options.remoteUrl
|
|
323
|
+
const eventWire = options.remoteUrl ? new EventWire(options.remoteUrl, {
|
|
324
|
+
enableEventSync: !!options.dbAdapterFactory
|
|
325
|
+
}) : undefined;
|
|
325
326
|
const queryWire = options.remoteUrl ? new QueryWire(options.remoteUrl) : undefined;
|
|
326
327
|
const authAdapter = new AuthAdapter;
|
|
327
328
|
authAdapter.loadPersisted();
|
|
@@ -447,31 +448,8 @@ Event payload:`, event.payload);
|
|
|
447
448
|
}
|
|
448
449
|
} else if (eventWire && queryWire) {
|
|
449
450
|
streamingCache = new StreamingQueryCache;
|
|
450
|
-
|
|
451
|
-
eventPublisher = new StreamingEventPublisher(streamingCache, eventWire);
|
|
451
|
+
eventPublisher = new StreamingEventPublisher(eventWire);
|
|
452
452
|
eventPublisher.registerViews(views);
|
|
453
|
-
const processedEvents = new Set;
|
|
454
|
-
let eventQueue = Promise.resolve();
|
|
455
|
-
eventWire.onEvent((event) => {
|
|
456
|
-
eventQueue = eventQueue.then(async () => {
|
|
457
|
-
try {
|
|
458
|
-
if (processedEvents.has(event.hostId)) {
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
processedEvents.add(event.hostId);
|
|
462
|
-
await streamingCache.applyEvent({
|
|
463
|
-
id: event.hostId,
|
|
464
|
-
type: event.type,
|
|
465
|
-
payload: event.payload,
|
|
466
|
-
createdAt: new Date(event.createdAt),
|
|
467
|
-
authContext: event.authContext ?? null
|
|
468
|
-
});
|
|
469
|
-
} catch (error) {
|
|
470
|
-
console.error(`[Arc] Failed to process event ${event.hostId} (${event.type}):`, error);
|
|
471
|
-
processedEvents.delete(event.hostId);
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
453
|
if (authAdapter.isAuthenticated()) {
|
|
476
454
|
eventWire.connect();
|
|
477
455
|
}
|
|
@@ -536,7 +514,7 @@ Event payload:`, event.payload);
|
|
|
536
514
|
authAdapter.setToken(token, name);
|
|
537
515
|
if (cachedModel) {
|
|
538
516
|
cachedModel.scope(name).setToken(token);
|
|
539
|
-
cachedModel.getAdapters().streamingCache?.invalidateScope(name);
|
|
517
|
+
cachedModel.getAdapters().streamingCache?.invalidateScope(name, eventWire);
|
|
540
518
|
} else {
|
|
541
519
|
eventWire?.setScopeToken(name, token);
|
|
542
520
|
if (eventWire && token && eventWire.getState() === "disconnected") {
|
|
@@ -590,51 +568,30 @@ Event payload:`, event.payload);
|
|
|
590
568
|
return;
|
|
591
569
|
const unsubs = [];
|
|
592
570
|
const element = model.context.get(desc.element);
|
|
593
|
-
const qCtx = element?.queryContext?.(adapters);
|
|
594
|
-
const method = qCtx?.[desc.method];
|
|
595
|
-
const reExecute = async () => {
|
|
596
|
-
if (!method)
|
|
597
|
-
return;
|
|
598
|
-
try {
|
|
599
|
-
const result = await method(...desc.args);
|
|
600
|
-
setData(result);
|
|
601
|
-
setLoading(false);
|
|
602
|
-
} catch (err) {
|
|
603
|
-
console.error(`[Arc] Query error:`, err);
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
571
|
if (adapters.streamingCache) {
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
current = newResult;
|
|
622
|
-
changed = true;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
if (!changed)
|
|
626
|
-
return;
|
|
627
|
-
cachedResult = current;
|
|
628
|
-
reExecute();
|
|
572
|
+
const sub = adapters.streamingCache.subscribe(desc, name, adapters.eventWire, () => {
|
|
573
|
+
const snap = sub.read();
|
|
574
|
+
setData(snap.result);
|
|
575
|
+
setLoading(snap.loading);
|
|
576
|
+
});
|
|
577
|
+
unsubs.push(sub.unsubscribe);
|
|
578
|
+
const initial = sub.read();
|
|
579
|
+
setData(initial.result);
|
|
580
|
+
setLoading(initial.loading);
|
|
581
|
+
} else {
|
|
582
|
+
const qCtx = element?.queryContext?.(adapters);
|
|
583
|
+
const method = qCtx?.[desc.method];
|
|
584
|
+
const reExecute = async () => {
|
|
585
|
+
if (!method)
|
|
629
586
|
return;
|
|
587
|
+
try {
|
|
588
|
+
const result = await method(...desc.args);
|
|
589
|
+
setData(result);
|
|
590
|
+
setLoading(false);
|
|
591
|
+
} catch (err) {
|
|
592
|
+
console.error(`[Arc] Query error:`, err);
|
|
630
593
|
}
|
|
631
|
-
|
|
632
|
-
}));
|
|
633
|
-
unsubs.push(adapters.streamingCache.subscribeQuery(desc, adapters.eventWire, name));
|
|
634
|
-
if (store.hasData()) {
|
|
635
|
-
reExecute();
|
|
636
|
-
}
|
|
637
|
-
} else {
|
|
594
|
+
};
|
|
638
595
|
if (adapters.eventPublisher) {
|
|
639
596
|
const aggregateName = element?.name;
|
|
640
597
|
const eventTypes = element?.getElements?.()?.map((e) => aggregateName ? `${aggregateName}.${e.name}` : e.name) ?? [];
|
|
@@ -721,4 +678,4 @@ export {
|
|
|
721
678
|
Form
|
|
722
679
|
};
|
|
723
680
|
|
|
724
|
-
//# debugId=
|
|
681
|
+
//# debugId=966C03CA44E269FA64756E2164756E21
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.16",
|
|
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.",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"typescript": "^5.2.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@arcote.tech/arc": "^0.7.
|
|
35
|
+
"@arcote.tech/arc": "^0.7.16",
|
|
36
36
|
"react": "^18.0.0 || ^19.0.0",
|
|
37
37
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
38
38
|
"typescript": "^5.0.0"
|