@luvio/environments 0.154.10 → 0.154.12
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,
|
|
281
|
+
function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, redirects, additionalDurableStoreOperations = [], enableDurableMetadataRefresh = false) {
|
|
282
282
|
const durableRecords = create(null);
|
|
283
283
|
const refreshedDurableRecords = create(null);
|
|
284
284
|
const evictedRecords = create(null);
|
|
@@ -318,21 +318,14 @@ function flushInMemoryStoreValuesToDurableStore(store, durableStore, crossEnviro
|
|
|
318
318
|
segment: DefaultDurableSegment,
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
|
-
|
|
321
|
+
const refreshKeys = keys(refreshedDurableRecords);
|
|
322
|
+
if (refreshKeys.length > 0) {
|
|
322
323
|
// publishes with only metadata updates
|
|
323
324
|
durableStoreOperations.push({
|
|
324
325
|
type: 'setMetadata',
|
|
325
326
|
entries: refreshedDurableRecords,
|
|
326
327
|
segment: DefaultDurableSegment,
|
|
327
328
|
});
|
|
328
|
-
if (crossEnvironmentNotifier !== undefined) {
|
|
329
|
-
crossEnvironmentNotifier.notifyCrossEnvironments({
|
|
330
|
-
data: {
|
|
331
|
-
refreshedDurableRecords,
|
|
332
|
-
},
|
|
333
|
-
type: 'Update',
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
329
|
}
|
|
337
330
|
// redirects
|
|
338
331
|
redirects.forEach((value, key) => {
|
|
@@ -637,14 +630,17 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
|
|
|
637
630
|
}
|
|
638
631
|
// process metadata only refreshes
|
|
639
632
|
if (metadataRefreshSegmentKeys.length > 0) {
|
|
640
|
-
const
|
|
641
|
-
if (
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
633
|
+
const filteredKeys = metadataRefreshSegmentKeys.filter((s) => environment.storeKeyExists(s));
|
|
634
|
+
if (filteredKeys.length > 0) {
|
|
635
|
+
const entries = await durableStore.getMetadata(filteredKeys, DefaultDurableSegment);
|
|
636
|
+
if (entries !== undefined) {
|
|
637
|
+
const entryKeys = keys(entries);
|
|
638
|
+
for (let i = 0, len = entryKeys.length; i < len; i++) {
|
|
639
|
+
const entryKey = entryKeys[i];
|
|
640
|
+
const { metadata } = entries[entryKey];
|
|
641
|
+
if (metadata !== undefined) {
|
|
642
|
+
environment.putStoreMetadata(entryKey, metadata, false);
|
|
643
|
+
}
|
|
648
644
|
}
|
|
649
645
|
}
|
|
650
646
|
}
|
|
@@ -667,15 +663,6 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
|
|
|
667
663
|
}
|
|
668
664
|
}
|
|
669
665
|
});
|
|
670
|
-
let notifier;
|
|
671
|
-
const getCrossEnvironmentNotifier = function () {
|
|
672
|
-
validateNotDisposed();
|
|
673
|
-
return notifier;
|
|
674
|
-
};
|
|
675
|
-
const setCrossEnvironmentNotifier = function (crossEnvironmentNotifier) {
|
|
676
|
-
validateNotDisposed();
|
|
677
|
-
notifier = crossEnvironmentNotifier;
|
|
678
|
-
};
|
|
679
666
|
const dispose = function () {
|
|
680
667
|
validateNotDisposed();
|
|
681
668
|
disposed = true;
|
|
@@ -728,7 +715,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
|
|
|
728
715
|
if (stagingStore === null) {
|
|
729
716
|
return Promise.resolve();
|
|
730
717
|
}
|
|
731
|
-
const promise = flushInMemoryStoreValuesToDurableStore(stagingStore, durableStore,
|
|
718
|
+
const promise = flushInMemoryStoreValuesToDurableStore(stagingStore, durableStore, durableStoreErrorHandler, new Map(pendingStoreRedirects), additionalDurableStoreOperations, enableDurableMetadataRefresh);
|
|
732
719
|
pendingStoreRedirects.clear();
|
|
733
720
|
stagingStore = null;
|
|
734
721
|
return promise;
|
|
@@ -1098,13 +1085,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
|
|
|
1098
1085
|
handleErrorResponse: { value: handleErrorResponse },
|
|
1099
1086
|
getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
|
|
1100
1087
|
notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
|
|
1101
|
-
getCrossEnvironmentNotifier: { value: getCrossEnvironmentNotifier },
|
|
1102
|
-
setCrossEnvironmentNotifier: { value: setCrossEnvironmentNotifier },
|
|
1103
1088
|
});
|
|
1104
1089
|
}
|
|
1105
1090
|
|
|
1106
|
-
|
|
1107
|
-
return notification.type === 'Update';
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
export { DURABLE_METADATA_VERSION, DefaultDurableSegment, isDurableEnvironmentEvent, isUpdateNotification, makeDurable, publishDurableStoreEntries };
|
|
1091
|
+
export { DURABLE_METADATA_VERSION, DefaultDurableSegment, isDurableEnvironmentEvent, makeDurable, publishDurableStoreEntries };
|
package/dist/types/main.d.ts
CHANGED
|
@@ -3,4 +3,3 @@ 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,5 +1,4 @@
|
|
|
1
1
|
import type { InMemoryStore } from '@luvio/engine';
|
|
2
2
|
import type { DurableStore, DurableStoreOperation } from '../DurableStore';
|
|
3
3
|
import type { DurableStoreRejectionHandler } from './error';
|
|
4
|
-
|
|
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>;
|
|
4
|
+
export declare function flushInMemoryStoreValuesToDurableStore(store: InMemoryStore, durableStore: DurableStore, durableStoreErrorHandler: DurableStoreRejectionHandler, redirects: Map<string, string>, additionalDurableStoreOperations?: DurableStoreOperation<unknown>[], enableDurableMetadataRefresh?: boolean): Promise<void>;
|
|
@@ -2,7 +2,6 @@ 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';
|
|
6
5
|
export interface DurableEnvironment extends Environment {
|
|
7
6
|
/**
|
|
8
7
|
* Disposes the environment and detaches the durable store listener
|
|
@@ -34,15 +33,6 @@ export interface DurableEnvironment extends Environment {
|
|
|
34
33
|
* otherwise returns `undefined`.
|
|
35
34
|
*/
|
|
36
35
|
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>;
|
|
46
36
|
}
|
|
47
37
|
export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
|
|
48
38
|
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.12",
|
|
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.12"
|
|
31
31
|
},
|
|
32
32
|
"volta": {
|
|
33
33
|
"extends": "../../../package.json"
|
|
@@ -1,42 +0,0 @@
|
|
|
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 {};
|