@luvio/environments 0.154.8 → 0.154.9
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/environments.js
CHANGED
|
@@ -278,7 +278,7 @@ class DurableTTLStore {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, redirects, additionalDurableStoreOperations = [], enableDurableMetadataRefresh = false) {
|
|
281
|
+
function flushInMemoryStoreValuesToDurableStore(store, durableStore, crossEnvironmentNotifier, durableStoreErrorHandler, redirects, additionalDurableStoreOperations = [], enableDurableMetadataRefresh = false) {
|
|
282
282
|
const durableRecords = create(null);
|
|
283
283
|
const refreshedDurableRecords = create(null);
|
|
284
284
|
const evictedRecords = create(null);
|
|
@@ -325,6 +325,14 @@ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStor
|
|
|
325
325
|
entries: refreshedDurableRecords,
|
|
326
326
|
segment: DefaultDurableSegment,
|
|
327
327
|
});
|
|
328
|
+
if (crossEnvironmentNotifier !== undefined) {
|
|
329
|
+
crossEnvironmentNotifier.notifyCrossEnvironments({
|
|
330
|
+
data: {
|
|
331
|
+
refreshedDurableRecords,
|
|
332
|
+
},
|
|
333
|
+
type: 'Update',
|
|
334
|
+
});
|
|
335
|
+
}
|
|
328
336
|
}
|
|
329
337
|
// redirects
|
|
330
338
|
redirects.forEach((value, key) => {
|
|
@@ -659,6 +667,15 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
|
|
|
659
667
|
}
|
|
660
668
|
}
|
|
661
669
|
});
|
|
670
|
+
let notifier;
|
|
671
|
+
const getCrossEnvironmentNotifier = function () {
|
|
672
|
+
validateNotDisposed();
|
|
673
|
+
return notifier;
|
|
674
|
+
};
|
|
675
|
+
const setCrossEnvironmentNotifier = function (crossEnvironmentNotifier) {
|
|
676
|
+
validateNotDisposed();
|
|
677
|
+
notifier = crossEnvironmentNotifier;
|
|
678
|
+
};
|
|
662
679
|
const dispose = function () {
|
|
663
680
|
validateNotDisposed();
|
|
664
681
|
disposed = true;
|
|
@@ -711,7 +728,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
|
|
|
711
728
|
if (stagingStore === null) {
|
|
712
729
|
return Promise.resolve();
|
|
713
730
|
}
|
|
714
|
-
const promise = flushInMemoryStoreValuesToDurableStore(stagingStore, durableStore, durableStoreErrorHandler, new Map(pendingStoreRedirects), additionalDurableStoreOperations, enableDurableMetadataRefresh);
|
|
731
|
+
const promise = flushInMemoryStoreValuesToDurableStore(stagingStore, durableStore, getCrossEnvironmentNotifier(), durableStoreErrorHandler, new Map(pendingStoreRedirects), additionalDurableStoreOperations, enableDurableMetadataRefresh);
|
|
715
732
|
pendingStoreRedirects.clear();
|
|
716
733
|
stagingStore = null;
|
|
717
734
|
return promise;
|
|
@@ -1081,7 +1098,13 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
|
|
|
1081
1098
|
handleErrorResponse: { value: handleErrorResponse },
|
|
1082
1099
|
getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
|
|
1083
1100
|
notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
|
|
1101
|
+
getCrossEnvironmentNotifier: { value: getCrossEnvironmentNotifier },
|
|
1102
|
+
setCrossEnvironmentNotifier: { value: setCrossEnvironmentNotifier },
|
|
1084
1103
|
});
|
|
1085
1104
|
}
|
|
1086
1105
|
|
|
1087
|
-
|
|
1106
|
+
function isUpdateNotification(notification) {
|
|
1107
|
+
return notification.type === 'Update';
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
export { DURABLE_METADATA_VERSION, DefaultDurableSegment, isDurableEnvironmentEvent, isUpdateNotification, makeDurable, publishDurableStoreEntries };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currently only Update is used, but other notification types will be added later.
|
|
3
|
+
*/
|
|
4
|
+
type NotificationType = 'Update';
|
|
5
|
+
/**
|
|
6
|
+
* Base notification definition on changes from one environment that it needs to notify other instances of.
|
|
7
|
+
*
|
|
8
|
+
* The environment runtime will define how to handle each EnvironmentChangeNotification when it defines its CrossEnvironmentNotifier.
|
|
9
|
+
*/
|
|
10
|
+
export interface EnvironmentChangeNotification<Data = unknown> {
|
|
11
|
+
data: Data;
|
|
12
|
+
type: NotificationType;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* This will be used when Data from one environment is updated and another environment instance needs to be notified of it changes.
|
|
16
|
+
* Example:
|
|
17
|
+
* UpdateEnvironmentChangeNotification<DurableStoreEntries>
|
|
18
|
+
* sends { [key: string]: DurableStoreEntry } which could contain an entry data and or its metadata that was updated.
|
|
19
|
+
*
|
|
20
|
+
* We can inform the other environment instances of changes without needing to read from the db
|
|
21
|
+
* in order to update the data their environment.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export interface UpdateEnvironmentChangeNotification<T> extends EnvironmentChangeNotification<T> {
|
|
25
|
+
type: 'Update';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interface to communicate to another Environment instance about important changes
|
|
29
|
+
*/
|
|
30
|
+
export interface CrossEnvironmentNotifier {
|
|
31
|
+
/**
|
|
32
|
+
* function call to unsubscribe from notifications
|
|
33
|
+
*/
|
|
34
|
+
unsubscribe(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* To notify other environment instances of important changes
|
|
37
|
+
* @param notification
|
|
38
|
+
*/
|
|
39
|
+
notifyCrossEnvironments(notification: EnvironmentChangeNotification): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export declare function isUpdateNotification<T>(notification: EnvironmentChangeNotification): notification is UpdateEnvironmentChangeNotification<T>;
|
|
42
|
+
export {};
|
package/dist/types/main.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { DurableTTLOverride, DefaultDurableTTLOverride } from './DurableTTLStore
|
|
|
3
3
|
export { makeDurable, DurableEnvironment } from './makeDurable';
|
|
4
4
|
export { publishDurableStoreEntries } from './makeDurable/revive';
|
|
5
5
|
export { isDurableEnvironmentEvent } from './events';
|
|
6
|
+
export { CrossEnvironmentNotifier, EnvironmentChangeNotification, UpdateEnvironmentChangeNotification, isUpdateNotification, } from './CrossEnvironmentNotifier';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InMemoryStore } from '@luvio/engine';
|
|
2
2
|
import type { DurableStore, DurableStoreOperation } from '../DurableStore';
|
|
3
3
|
import type { DurableStoreRejectionHandler } from './error';
|
|
4
|
-
|
|
4
|
+
import type { CrossEnvironmentNotifier } from '../CrossEnvironmentNotifier';
|
|
5
|
+
export declare function flushInMemoryStoreValuesToDurableStore(store: InMemoryStore, durableStore: DurableStore, crossEnvironmentNotifier: CrossEnvironmentNotifier | undefined, durableStoreErrorHandler: DurableStoreRejectionHandler, redirects: Map<string, string>, additionalDurableStoreOperations?: DurableStoreOperation<unknown>[], enableDurableMetadataRefresh?: boolean): Promise<void>;
|
|
@@ -2,6 +2,7 @@ import type { Environment, RecordSource, InMemoryStore } from '@luvio/engine';
|
|
|
2
2
|
import type { DurableStore, DurableStoreOperation } from './DurableStore';
|
|
3
3
|
import type { InstrumentationFunction } from './makeDurable/error';
|
|
4
4
|
import type { TTLOverridesMap } from './DurableTTLStore';
|
|
5
|
+
import type { CrossEnvironmentNotifier } from './CrossEnvironmentNotifier';
|
|
5
6
|
export interface DurableEnvironment extends Environment {
|
|
6
7
|
/**
|
|
7
8
|
* Disposes the environment and detaches the durable store listener
|
|
@@ -33,6 +34,15 @@ export interface DurableEnvironment extends Environment {
|
|
|
33
34
|
* otherwise returns `undefined`.
|
|
34
35
|
*/
|
|
35
36
|
getIngestStagingStore(): InMemoryStore['fallbackStringKeyInMemoryStore'] | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Set the environments cross notification.
|
|
39
|
+
* Must be set due to order of operations.
|
|
40
|
+
*/
|
|
41
|
+
setCrossEnvironmentNotifier(crossEnvironmentNotifier: CrossEnvironmentNotifier): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get the environments cross notification
|
|
44
|
+
*/
|
|
45
|
+
getCrossEnvironmentNotifier(): Promise<CrossEnvironmentNotifier | undefined>;
|
|
36
46
|
}
|
|
37
47
|
export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
|
|
38
48
|
export declare const ADAPTER_CONTEXT_ID_SUFFIX = "__NAMED_CONTEXT";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luvio/environments",
|
|
3
|
-
"version": "0.154.
|
|
3
|
+
"version": "0.154.9",
|
|
4
4
|
"description": "Luvio Environments",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"watch": "yarn build --watch"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@luvio/engine": "^0.154.
|
|
30
|
+
"@luvio/engine": "^0.154.9"
|
|
31
31
|
},
|
|
32
32
|
"volta": {
|
|
33
33
|
"extends": "../../../package.json"
|