@luvio/environments 0.154.10 → 0.154.11

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.
@@ -278,7 +278,7 @@ class DurableTTLStore {
278
278
  }
279
279
  }
280
280
 
281
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, crossEnvironmentNotifier, durableStoreErrorHandler, redirects, additionalDurableStoreOperations = [], enableDurableMetadataRefresh = false) {
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);
@@ -306,7 +306,10 @@ function flushInMemoryStoreValuesToDurableStore(store, durableStore, crossEnviro
306
306
  const entries = wasVisited === true || enableDurableMetadataRefresh === false
307
307
  ? durableRecords
308
308
  : refreshedDurableRecords;
309
- setRecordTo(entries, key, record, metadata);
309
+ const isMetadataRefresh = entries === refreshedDurableRecords;
310
+ setRecordTo(entries, key,
311
+ // dont send record data with metadata refresh
312
+ isMetadataRefresh ? undefined : record, metadata);
310
313
  }
311
314
  const durableStoreOperations = additionalDurableStoreOperations;
312
315
  const recordKeys = keys(durableRecords);
@@ -318,21 +321,14 @@ function flushInMemoryStoreValuesToDurableStore(store, durableStore, crossEnviro
318
321
  segment: DefaultDurableSegment,
319
322
  });
320
323
  }
321
- if (keys(refreshedDurableRecords).length > 0) {
324
+ const refreshKeys = keys(refreshedDurableRecords);
325
+ if (refreshKeys.length > 0) {
322
326
  // publishes with only metadata updates
323
327
  durableStoreOperations.push({
324
328
  type: 'setMetadata',
325
329
  entries: refreshedDurableRecords,
326
330
  segment: DefaultDurableSegment,
327
331
  });
328
- if (crossEnvironmentNotifier !== undefined) {
329
- crossEnvironmentNotifier.notifyCrossEnvironments({
330
- data: {
331
- refreshedDurableRecords,
332
- },
333
- type: 'Update',
334
- });
335
- }
336
332
  }
337
333
  // redirects
338
334
  redirects.forEach((value, key) => {
@@ -637,14 +633,17 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
637
633
  }
638
634
  // process metadata only refreshes
639
635
  if (metadataRefreshSegmentKeys.length > 0) {
640
- const entries = await durableStore.getMetadata(metadataRefreshSegmentKeys, DefaultDurableSegment);
641
- if (entries !== undefined) {
642
- const entryKeys = keys(entries);
643
- for (let i = 0, len = entryKeys.length; i < len; i++) {
644
- const entryKey = entryKeys[i];
645
- const { metadata } = entries[entryKey];
646
- if (metadata !== undefined) {
647
- environment.putStoreMetadata(entryKey, metadata, false);
636
+ const filteredKeys = metadataRefreshSegmentKeys.filter((s) => environment.storeKeyExists(s));
637
+ if (filteredKeys.length > 0) {
638
+ const entries = await durableStore.getMetadata(filteredKeys, DefaultDurableSegment);
639
+ if (entries !== undefined) {
640
+ const entryKeys = keys(entries);
641
+ for (let i = 0, len = entryKeys.length; i < len; i++) {
642
+ const entryKey = entryKeys[i];
643
+ const { metadata } = entries[entryKey];
644
+ if (metadata !== undefined) {
645
+ environment.putStoreMetadata(entryKey, metadata, false);
646
+ }
648
647
  }
649
648
  }
650
649
  }
@@ -667,15 +666,6 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
667
666
  }
668
667
  }
669
668
  });
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
669
  const dispose = function () {
680
670
  validateNotDisposed();
681
671
  disposed = true;
@@ -728,7 +718,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
728
718
  if (stagingStore === null) {
729
719
  return Promise.resolve();
730
720
  }
731
- const promise = flushInMemoryStoreValuesToDurableStore(stagingStore, durableStore, getCrossEnvironmentNotifier(), durableStoreErrorHandler, new Map(pendingStoreRedirects), additionalDurableStoreOperations, enableDurableMetadataRefresh);
721
+ const promise = flushInMemoryStoreValuesToDurableStore(stagingStore, durableStore, durableStoreErrorHandler, new Map(pendingStoreRedirects), additionalDurableStoreOperations, enableDurableMetadataRefresh);
732
722
  pendingStoreRedirects.clear();
733
723
  stagingStore = null;
734
724
  return promise;
@@ -1098,13 +1088,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
1098
1088
  handleErrorResponse: { value: handleErrorResponse },
1099
1089
  getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
1100
1090
  notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
1101
- getCrossEnvironmentNotifier: { value: getCrossEnvironmentNotifier },
1102
- setCrossEnvironmentNotifier: { value: setCrossEnvironmentNotifier },
1103
1091
  });
1104
1092
  }
1105
1093
 
1106
- function isUpdateNotification(notification) {
1107
- return notification.type === 'Update';
1108
- }
1109
-
1110
- export { DURABLE_METADATA_VERSION, DefaultDurableSegment, isDurableEnvironmentEvent, isUpdateNotification, makeDurable, publishDurableStoreEntries };
1094
+ export { DURABLE_METADATA_VERSION, DefaultDurableSegment, isDurableEnvironmentEvent, makeDurable, publishDurableStoreEntries };
@@ -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
- 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>;
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.10",
3
+ "version": "0.154.11",
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.10"
30
+ "@luvio/engine": "^0.154.11"
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 {};