bruce-models 7.1.44 → 7.1.46
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/bruce-models.es5.js +15399 -15043
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +15264 -14913
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/account/account-concept.js +1 -0
- package/dist/lib/account/account-concept.js.map +1 -1
- package/dist/lib/api/bruce-api.js +21 -2
- package/dist/lib/api/bruce-api.js.map +1 -1
- package/dist/lib/bruce-models.js +63 -62
- package/dist/lib/bruce-models.js.map +1 -1
- package/dist/lib/server/message-broker.js +10 -0
- package/dist/lib/server/message-broker.js.map +1 -1
- package/dist/lib/server/record-change-feed.js +332 -0
- package/dist/lib/server/record-change-feed.js.map +1 -0
- package/dist/types/account/account-concept.d.ts +1 -0
- package/dist/types/api/bruce-api.d.ts +14 -2
- package/dist/types/bruce-models.d.ts +63 -62
- package/dist/types/server/record-change-feed.d.ts +125 -0
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { AccountConcept } from "../account/account-concept";
|
|
2
|
+
import { Api } from "../api/api";
|
|
3
|
+
import { CacheControl } from "../common/cache";
|
|
4
|
+
import { MessageBroker } from "./message-broker";
|
|
5
|
+
/**
|
|
6
|
+
* Handles change events from Bruce API for various concepts.
|
|
7
|
+
* Apps/utils can subscribe to specific concept changes, eg: N Entity was updated so we should reload a panel.
|
|
8
|
+
*/
|
|
9
|
+
export declare namespace RecordChangeFeed {
|
|
10
|
+
type TAction = "C" | "U" | "D";
|
|
11
|
+
/**
|
|
12
|
+
* A parsed record-change event received from the server.
|
|
13
|
+
*/
|
|
14
|
+
interface IEvent {
|
|
15
|
+
topic?: string;
|
|
16
|
+
concept: AccountConcept.EConcept;
|
|
17
|
+
action: TAction;
|
|
18
|
+
data: unknown;
|
|
19
|
+
user?: string;
|
|
20
|
+
message: MessageBroker.IMessage;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Filtering criteria for a record-change subscription.
|
|
24
|
+
* All fields are optional, omitting a field means "match all values".
|
|
25
|
+
*/
|
|
26
|
+
interface ISubscribeParams {
|
|
27
|
+
concepts?: AccountConcept.EConcept[];
|
|
28
|
+
actions?: TAction[];
|
|
29
|
+
recordId?: string | number;
|
|
30
|
+
entityInternalId?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parses a raw broker message into a typed record-change event.
|
|
34
|
+
* Returns null if the message does not conform to the record-change format.
|
|
35
|
+
*/
|
|
36
|
+
const parseEvent: (message: MessageBroker.IMessage) => IEvent | null;
|
|
37
|
+
/**
|
|
38
|
+
* Returns true if the given Entity internal ID falls within the reported range string.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* isEntityInternalIdInRangeString("100-200,305,400-450", 150) // true
|
|
42
|
+
* isEntityInternalIdInRangeString("100-200,305,400-450", 301) // false
|
|
43
|
+
*/
|
|
44
|
+
const isEntityInternalIdInRangeString: (rangeString: string | null | undefined, entityInternalId: number) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if the given record ID appears in a comma-separated list string.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* isRecordIdInListString("abc,def,ghi", "def") // true
|
|
50
|
+
* isRecordIdInListString("abc,def,ghi", "xyz") // false
|
|
51
|
+
*/
|
|
52
|
+
const isRecordIdInListString: (listString: string | null | undefined, recordId: string | number) => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the set of {@link Api.ECacheKey} namespaces that should be
|
|
55
|
+
* invalidated when a record-change event arrives for the given concept.
|
|
56
|
+
*
|
|
57
|
+
* A concept can map to multiple cache namespaces (e.g. a tileset change
|
|
58
|
+
* also invalidates the publish-tileset and tileset-access caches).
|
|
59
|
+
*/
|
|
60
|
+
const getConceptCacheKeys: (concept: AccountConcept.EConcept) => string[];
|
|
61
|
+
/**
|
|
62
|
+
* Evicts relevant cache entries in response to a record-change event.
|
|
63
|
+
*/
|
|
64
|
+
const clearCachesForEvent: (event: IEvent, cache: CacheControl<any>) => void;
|
|
65
|
+
/**
|
|
66
|
+
* A typed, self-managing live feed for Bruce record-change events.
|
|
67
|
+
*
|
|
68
|
+
* Wraps a {@link MessageBroker.IBroker} and routes incoming WebSocket messages
|
|
69
|
+
* to strongly-typed, optionally-filtered subscriber callbacks.
|
|
70
|
+
*
|
|
71
|
+
* When a "cache" is provided (via the {@link BruceApi.Api} constructor),
|
|
72
|
+
* relevant cache entries are automatically evicted on every incoming event
|
|
73
|
+
* before subscribers are notified.
|
|
74
|
+
*
|
|
75
|
+
* Reconnection is handled by the underlying broker, subscribers do not need
|
|
76
|
+
* to re-register after a disconnect/reconnect cycle.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* const unsub = api.RecordChangeFeed.Subscribe(
|
|
80
|
+
* { concepts: [AccountConcept.EConcept.ENTITY_TYPE] },
|
|
81
|
+
* (event) => console.log("Entity type changed:", event)
|
|
82
|
+
* );
|
|
83
|
+
*
|
|
84
|
+
* // Later:
|
|
85
|
+
* unsub();
|
|
86
|
+
*/
|
|
87
|
+
class Client {
|
|
88
|
+
private readonly broker;
|
|
89
|
+
private readonly topic;
|
|
90
|
+
private readonly cache;
|
|
91
|
+
private readonly subscribers;
|
|
92
|
+
private readonly brokerCallback;
|
|
93
|
+
/**
|
|
94
|
+
* Initialize new instance. Done through a BruceAPI instance in all current uses.
|
|
95
|
+
* @param broker
|
|
96
|
+
* @param accountId
|
|
97
|
+
* @param env
|
|
98
|
+
* @param cache
|
|
99
|
+
*/
|
|
100
|
+
constructor(broker: MessageBroker.IBroker, accountId: string, env: Api.Env, cache?: CacheControl<any>);
|
|
101
|
+
/**
|
|
102
|
+
* Whether the underlying WebSocket connection is currently open.
|
|
103
|
+
*/
|
|
104
|
+
get IsConnected(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Forward the authenticated user ID to the underlying broker.
|
|
107
|
+
*/
|
|
108
|
+
SetUserId(userId: string): void;
|
|
109
|
+
private onBrokerMessage;
|
|
110
|
+
private matchesFilter;
|
|
111
|
+
/**
|
|
112
|
+
* Register a typed callback for record-change events.
|
|
113
|
+
*
|
|
114
|
+
* @param params Filtering criteria. All fields are optional.
|
|
115
|
+
* @param callback Invoked for each matching event.
|
|
116
|
+
* @returns An unsubscribe function. Call it to stop receiving events.
|
|
117
|
+
*/
|
|
118
|
+
Subscribe(params: ISubscribeParams, callback: (event: IEvent) => void): () => void;
|
|
119
|
+
/**
|
|
120
|
+
* Unsubscribes from the broker topic and clears all local subscribers.
|
|
121
|
+
* Call this when the owning API instance is being torn down.
|
|
122
|
+
*/
|
|
123
|
+
Destroy(): void;
|
|
124
|
+
}
|
|
125
|
+
}
|