@luvio/environments 0.142.2 → 0.142.3

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.
Files changed (40) hide show
  1. package/dist/{es/es2018/environments.js → environments.js} +7 -5
  2. package/dist/{es/es2018/types → types}/makeDurable.d.ts +2 -1
  3. package/package.json +9 -5
  4. package/dist/umd/es2018/environments.js +0 -864
  5. package/dist/umd/es2018/types/DurableStore.d.ts +0 -134
  6. package/dist/umd/es2018/types/DurableTTLStore.d.ts +0 -25
  7. package/dist/umd/es2018/types/events.d.ts +0 -18
  8. package/dist/umd/es2018/types/main.d.ts +0 -5
  9. package/dist/umd/es2018/types/makeDurable/error.d.ts +0 -11
  10. package/dist/umd/es2018/types/makeDurable/flush.d.ts +0 -4
  11. package/dist/umd/es2018/types/makeDurable/revive.d.ts +0 -38
  12. package/dist/umd/es2018/types/makeDurable/stagingStore.d.ts +0 -6
  13. package/dist/umd/es2018/types/makeDurable/ttl.d.ts +0 -3
  14. package/dist/umd/es2018/types/makeDurable/utils.d.ts +0 -2
  15. package/dist/umd/es2018/types/makeDurable.d.ts +0 -47
  16. package/dist/umd/es2018/types/utils/language.d.ts +0 -21
  17. package/dist/umd/es5/environments.js +0 -1013
  18. package/dist/umd/es5/types/DurableStore.d.ts +0 -134
  19. package/dist/umd/es5/types/DurableTTLStore.d.ts +0 -25
  20. package/dist/umd/es5/types/events.d.ts +0 -18
  21. package/dist/umd/es5/types/main.d.ts +0 -5
  22. package/dist/umd/es5/types/makeDurable/error.d.ts +0 -11
  23. package/dist/umd/es5/types/makeDurable/flush.d.ts +0 -4
  24. package/dist/umd/es5/types/makeDurable/revive.d.ts +0 -38
  25. package/dist/umd/es5/types/makeDurable/stagingStore.d.ts +0 -6
  26. package/dist/umd/es5/types/makeDurable/ttl.d.ts +0 -3
  27. package/dist/umd/es5/types/makeDurable/utils.d.ts +0 -2
  28. package/dist/umd/es5/types/makeDurable.d.ts +0 -47
  29. package/dist/umd/es5/types/utils/language.d.ts +0 -21
  30. /package/dist/{es/es2018/types → types}/DurableStore.d.ts +0 -0
  31. /package/dist/{es/es2018/types → types}/DurableTTLStore.d.ts +0 -0
  32. /package/dist/{es/es2018/types → types}/events.d.ts +0 -0
  33. /package/dist/{es/es2018/types → types}/main.d.ts +0 -0
  34. /package/dist/{es/es2018/types → types}/makeDurable/error.d.ts +0 -0
  35. /package/dist/{es/es2018/types → types}/makeDurable/flush.d.ts +0 -0
  36. /package/dist/{es/es2018/types → types}/makeDurable/revive.d.ts +0 -0
  37. /package/dist/{es/es2018/types → types}/makeDurable/stagingStore.d.ts +0 -0
  38. /package/dist/{es/es2018/types → types}/makeDurable/ttl.d.ts +0 -0
  39. /package/dist/{es/es2018/types → types}/makeDurable/utils.d.ts +0 -0
  40. /package/dist/{es/es2018/types → types}/utils/language.d.ts +0 -0
@@ -1,1013 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
- })(this, (function (exports, engine) { 'use strict';
6
-
7
- // the last version the metadata shape was altered
8
- var DURABLE_METADATA_VERSION = '0.111.0';
9
- function isDeprecatedDurableStoreEntry(durableRecord) {
10
- if (durableRecord.expiration !== undefined) {
11
- return true;
12
- }
13
- var metadata = durableRecord.metadata;
14
- if (metadata !== undefined) {
15
- var metadataVersion = metadata.metadataVersion;
16
- // eventually we will want to assert that metadataVersion is defined
17
- if (metadataVersion !== undefined && metadataVersion !== DURABLE_METADATA_VERSION) {
18
- return true;
19
- }
20
- }
21
- // Add more deprecated shape checks here
22
- return false;
23
- }
24
- var DefaultDurableSegment = 'DEFAULT';
25
-
26
- /******************************************************************************
27
- Copyright (c) Microsoft Corporation.
28
-
29
- Permission to use, copy, modify, and/or distribute this software for any
30
- purpose with or without fee is hereby granted.
31
-
32
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
33
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
34
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
35
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
36
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38
- PERFORMANCE OF THIS SOFTWARE.
39
- ***************************************************************************** */
40
-
41
- var __assign = function() {
42
- __assign = Object.assign || function __assign(t) {
43
- for (var s, i = 1, n = arguments.length; i < n; i++) {
44
- s = arguments[i];
45
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
46
- }
47
- return t;
48
- };
49
- return __assign.apply(this, arguments);
50
- };
51
-
52
- function __awaiter(thisArg, _arguments, P, generator) {
53
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
54
- return new (P || (P = Promise))(function (resolve, reject) {
55
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
56
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
57
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
58
- step((generator = generator.apply(thisArg, _arguments || [])).next());
59
- });
60
- }
61
-
62
- function __generator(thisArg, body) {
63
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
64
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
65
- function verb(n) { return function (v) { return step([n, v]); }; }
66
- function step(op) {
67
- if (f) throw new TypeError("Generator is already executing.");
68
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
69
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
70
- if (y = 0, t) op = [op[0] & 2, t.value];
71
- switch (op[0]) {
72
- case 0: case 1: t = op; break;
73
- case 4: _.label++; return { value: op[1], done: false };
74
- case 5: _.label++; y = op[1]; op = [0]; continue;
75
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
76
- default:
77
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
78
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
79
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
80
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
81
- if (t[2]) _.ops.pop();
82
- _.trys.pop(); continue;
83
- }
84
- op = body.call(thisArg, _);
85
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
86
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
87
- }
88
- }
89
-
90
- var keys = Object.keys, create = Object.create;
91
-
92
- //Durable store error instrumentation key
93
- var DURABLE_STORE_ERROR = 'durable-store-error';
94
- /**
95
- * Returns a function that processes errors from durable store promise rejections.
96
- * If running in a non-production environment, the error is rethrown.
97
- * When running in production the error is sent to instrumentation.
98
- * @param instrument Instrumentation function implementation
99
- */
100
- function handleDurableStoreRejection(instrument) {
101
- return function (error) {
102
- if (process.env.NODE_ENV !== 'production') {
103
- throw error;
104
- }
105
- if (instrument !== undefined) {
106
- instrument(function () {
107
- var _a;
108
- return _a = {},
109
- _a[DURABLE_STORE_ERROR] = true,
110
- _a.error = error,
111
- _a;
112
- });
113
- }
114
- };
115
- }
116
-
117
- function isStoreEntryError(storeRecord) {
118
- return storeRecord.__type === 'error';
119
- }
120
-
121
- /**
122
- * Takes a set of entries from DurableStore and publishes them via the passed in funcs.
123
- * This respects expiration and checks for valid DurableStore data shapes. This should
124
- * be used over manually parsing DurableStoreEntries
125
- *
126
- * @param durableRecords The DurableStoreEntries to parse
127
- * @param publish A function to call with the data of each DurableStoreEntry
128
- * @param publishMetadata A function to call with the metadata of each DurableStoreEntry
129
- * @param pendingWriter the PendingWriter (this is going away soon)
130
- * @returns
131
- */
132
- function publishDurableStoreEntries(durableRecords, put, publishMetadata) {
133
- var revivedKeys = new engine.StoreKeySet();
134
- var hadUnexpectedShape = false;
135
- if (durableRecords === undefined) {
136
- return { revivedKeys: revivedKeys, hadUnexpectedShape: hadUnexpectedShape };
137
- }
138
- var durableKeys = keys(durableRecords);
139
- if (durableKeys.length === 0) {
140
- // no records to revive
141
- return { revivedKeys: revivedKeys, hadUnexpectedShape: hadUnexpectedShape };
142
- }
143
- for (var i = 0, len = durableKeys.length; i < len; i += 1) {
144
- var key = durableKeys[i];
145
- var durableRecord = durableRecords[key];
146
- if (isDeprecatedDurableStoreEntry(durableRecord)) {
147
- // had the old shape, skip reviving this entry.
148
- hadUnexpectedShape = true;
149
- continue;
150
- }
151
- var metadata = durableRecord.metadata, data = durableRecord.data;
152
- if (data === undefined) {
153
- // if unexpected data skip reviving
154
- hadUnexpectedShape = true;
155
- continue;
156
- }
157
- if (metadata !== undefined) {
158
- var expirationTimestamp = metadata.expirationTimestamp;
159
- if (expirationTimestamp === undefined) {
160
- // if unexpected expiration data skip reviving
161
- hadUnexpectedShape = true;
162
- continue;
163
- }
164
- publishMetadata(key, metadata);
165
- }
166
- if (isStoreEntryError(data)) {
167
- // freeze errors on way into L1
168
- engine.deepFreeze(data.error);
169
- }
170
- put(key, data);
171
- revivedKeys.add(key);
172
- }
173
- return { revivedKeys: revivedKeys, hadUnexpectedShape: hadUnexpectedShape };
174
- }
175
- /**
176
- * This method returns a Promise to a snapshot that is revived from L2 cache. If
177
- * L2 does not have the entries necessary to fulfill the snapshot then this method
178
- * will refresh the snapshot from network, and then run the results from network
179
- * through L2 ingestion, returning the subsequent revived snapshot.
180
- */
181
- function reviveSnapshot(baseEnvironment, durableStore, unavailableSnapshot, durableStoreErrorHandler, buildL1Snapshot, reviveMetrics) {
182
- if (reviveMetrics === void 0) { reviveMetrics = { l2Trips: [] }; }
183
- var recordId = unavailableSnapshot.recordId, select = unavailableSnapshot.select, missingLinks = unavailableSnapshot.missingLinks, seenRecords = unavailableSnapshot.seenRecords, state = unavailableSnapshot.state;
184
- // L2 can only revive Unfulfilled snapshots that have a selector since they have the
185
- // info needed to revive (like missingLinks) and rebuild. Otherwise return L1 snapshot.
186
- if (state !== 'Unfulfilled' || select === undefined) {
187
- return Promise.resolve({
188
- snapshot: unavailableSnapshot,
189
- metrics: reviveMetrics,
190
- });
191
- }
192
- // in case L1 store changes/deallocs a record while we are doing the async read
193
- // we attempt to read all keys from L2 - so combine recordId with any seenRecords
194
- var keysToReviveSet = new engine.StoreKeySet().add(recordId);
195
- keysToReviveSet.merge(seenRecords);
196
- keysToReviveSet.merge(missingLinks);
197
- var keysToRevive = keysToReviveSet.keysAsArray();
198
- var canonicalKeys = keysToRevive.map(function (x) {
199
- return engine.serializeStructuredKey(baseEnvironment.storeGetCanonicalKey(x));
200
- });
201
- var start = Date.now();
202
- var l2Trips = reviveMetrics.l2Trips;
203
- return durableStore.getEntries(canonicalKeys, DefaultDurableSegment).then(function (durableRecords) {
204
- l2Trips.push({
205
- duration: Date.now() - start,
206
- keysRequestedCount: canonicalKeys.length,
207
- });
208
- var _a = publishDurableStoreEntries(durableRecords,
209
- // TODO [W-10072584]: instead of implicitly using L1 we should take in
210
- // publish and publishMetadata funcs, so callers can decide where to
211
- // revive to (like they pass in how to do the buildL1Snapshot)
212
- baseEnvironment.storePut.bind(baseEnvironment), baseEnvironment.publishStoreMetadata.bind(baseEnvironment)), revivedKeys = _a.revivedKeys, hadUnexpectedShape = _a.hadUnexpectedShape;
213
- // if the data coming back from DS had an unexpected shape then just
214
- // return the L1 snapshot
215
- if (hadUnexpectedShape === true) {
216
- return { snapshot: unavailableSnapshot, metrics: reviveMetrics };
217
- }
218
- if (revivedKeys.size() === 0) {
219
- // durable store doesn't have what we asked for so return L1 snapshot
220
- return { snapshot: unavailableSnapshot, metrics: reviveMetrics };
221
- }
222
- // try building the snapshot from L1 now that we have revived the missingLinks
223
- var snapshot = buildL1Snapshot();
224
- // if snapshot is pending then some other in-flight refresh will broadcast
225
- // later
226
- if (snapshot.state === 'Pending') {
227
- return { snapshot: snapshot, metrics: reviveMetrics };
228
- }
229
- if (snapshot.state === 'Unfulfilled') {
230
- // have to check if the new snapshot has any additional seenRecords
231
- // and revive again if so
232
- var newSnapshotSeenRecords = snapshot.seenRecords, newSnapshotMissingLinks = snapshot.missingLinks, newSnapshotRecordId = snapshot.recordId;
233
- var newKeysToReviveSet = new engine.StoreKeySet();
234
- newKeysToReviveSet.add(newSnapshotRecordId);
235
- newKeysToReviveSet.merge(newSnapshotSeenRecords);
236
- newKeysToReviveSet.merge(newSnapshotMissingLinks);
237
- var newKeys = newKeysToReviveSet.keysAsArray();
238
- // in case DS returned additional entries we combine the requested
239
- // and returned keys
240
- var alreadyRequestedOrRevivedSet = keysToReviveSet;
241
- alreadyRequestedOrRevivedSet.merge(revivedKeys);
242
- // if there's any seen keys in the newly rebuilt snapshot that
243
- // haven't already been requested or returned then revive again
244
- for (var i = 0, len = newKeys.length; i < len; i++) {
245
- var newSnapshotSeenKey = newKeys[i];
246
- if (!alreadyRequestedOrRevivedSet.has(newSnapshotSeenKey)) {
247
- return reviveSnapshot(baseEnvironment, durableStore, snapshot, durableStoreErrorHandler, buildL1Snapshot, reviveMetrics);
248
- }
249
- }
250
- }
251
- return { snapshot: snapshot, metrics: reviveMetrics };
252
- }, function (error) {
253
- durableStoreErrorHandler(error);
254
- // getEntries failed, return the L1 snapshot
255
- return { snapshot: unavailableSnapshot, metrics: reviveMetrics };
256
- });
257
- }
258
-
259
- var TTL_DURABLE_SEGMENT = 'TTL_DURABLE_SEGMENT';
260
- var TTL_DEFAULT_KEY = 'TTL_DEFAULT_KEY';
261
- function buildDurableTTLOverrideStoreKey(namespace, representationName) {
262
- return "".concat(namespace, "::").concat(representationName);
263
- }
264
- function isEntryDurableTTLOverride(entry) {
265
- if (typeof entry === 'object' && entry !== undefined && entry !== null) {
266
- var data = entry.data;
267
- if (data !== undefined) {
268
- return (data.namespace !== undefined &&
269
- data.representationName !== undefined &&
270
- data.ttl !== undefined);
271
- }
272
- }
273
- return false;
274
- }
275
- function isDefaultDurableTTLOverride(override) {
276
- return (override.namespace === TTL_DEFAULT_KEY && override.representationName === TTL_DEFAULT_KEY);
277
- }
278
- /**
279
- * Class to set and get the TTL override values in the Durable Store
280
- */
281
- var DurableTTLStore = /** @class */ (function () {
282
- function DurableTTLStore(durableStore) {
283
- this.durableStore = durableStore;
284
- }
285
- DurableTTLStore.prototype.setDefaultDurableTTLOverrides = function (ttl) {
286
- var _a;
287
- return this.durableStore.setEntries((_a = {},
288
- _a[buildDurableTTLOverrideStoreKey(TTL_DEFAULT_KEY, TTL_DEFAULT_KEY)] = {
289
- data: {
290
- namespace: TTL_DEFAULT_KEY,
291
- representationName: TTL_DEFAULT_KEY,
292
- ttl: ttl,
293
- },
294
- },
295
- _a), TTL_DURABLE_SEGMENT);
296
- };
297
- DurableTTLStore.prototype.setDurableTTLOverride = function (namespace, representationName, ttl) {
298
- var _a;
299
- return this.durableStore.setEntries((_a = {},
300
- _a[buildDurableTTLOverrideStoreKey(namespace, representationName)] = {
301
- data: { namespace: namespace, representationName: representationName, ttl: ttl },
302
- },
303
- _a), TTL_DURABLE_SEGMENT);
304
- };
305
- DurableTTLStore.prototype.getDurableTTLOverrides = function () {
306
- return this.durableStore
307
- .getAllEntries(TTL_DURABLE_SEGMENT)
308
- .then(function (entries) {
309
- var overrides = [];
310
- var defaultTTL = undefined;
311
- if (entries === undefined) {
312
- return {
313
- defaultTTL: defaultTTL,
314
- overrides: overrides,
315
- };
316
- }
317
- var keys$1 = keys(entries);
318
- for (var i = 0, len = keys$1.length; i < len; i++) {
319
- var key = keys$1[i];
320
- var entry = entries[key];
321
- if (entry !== undefined && isEntryDurableTTLOverride(entry)) {
322
- if (isDefaultDurableTTLOverride(entry.data)) {
323
- defaultTTL = entry.data;
324
- }
325
- else {
326
- overrides.push(entry.data);
327
- }
328
- }
329
- }
330
- return {
331
- defaultTTL: defaultTTL,
332
- overrides: overrides,
333
- };
334
- });
335
- };
336
- return DurableTTLStore;
337
- }());
338
-
339
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations) {
340
- if (additionalDurableStoreOperations === void 0) { additionalDurableStoreOperations = []; }
341
- var durableRecords = create(null);
342
- var evictedRecords = create(null);
343
- var _a = store.fallbackStringKeyInMemoryStore, records = _a.records, storeMetadata = _a.metadata, visitedIds = _a.visitedIds, refreshedIds = _a.refreshedIds;
344
- // TODO: W-8909393 Once metadata is stored in its own segment we need to
345
- // call setEntries for the visitedIds on default segment and call setEntries
346
- // on the metadata segment for the refreshedIds
347
- var keys$1 = keys(__assign(__assign({}, visitedIds), refreshedIds));
348
- for (var i = 0, len = keys$1.length; i < len; i += 1) {
349
- var key = keys$1[i];
350
- var record = records[key];
351
- // this record has been evicted, evict from DS
352
- if (record === undefined) {
353
- evictedRecords[key] = true;
354
- continue;
355
- }
356
- var metadata = storeMetadata[key];
357
- durableRecords[key] = {
358
- data: record,
359
- };
360
- if (metadata !== undefined) {
361
- durableRecords[key].metadata = __assign(__assign({}, metadata), { metadataVersion: DURABLE_METADATA_VERSION });
362
- }
363
- }
364
- var durableStoreOperations = additionalDurableStoreOperations;
365
- // publishes
366
- var recordKeys = keys(durableRecords);
367
- if (recordKeys.length > 0) {
368
- durableStoreOperations.push({
369
- type: 'setEntries',
370
- entries: durableRecords,
371
- segment: DefaultDurableSegment,
372
- });
373
- }
374
- // evicts
375
- var evictedKeys = keys(evictedRecords);
376
- if (evictedKeys.length > 0) {
377
- durableStoreOperations.push({
378
- type: 'evictEntries',
379
- ids: evictedKeys,
380
- segment: DefaultDurableSegment,
381
- });
382
- }
383
- if (durableStoreOperations.length > 0) {
384
- return durableStore.batchOperations(durableStoreOperations).catch(durableStoreErrorHandler);
385
- }
386
- return Promise.resolve();
387
- }
388
-
389
- var DurableEnvironmentEventDiscriminator = 'durable';
390
- function isDurableEnvironmentEvent(event) {
391
- return (event.type === 'environment' && event.environment === DurableEnvironmentEventDiscriminator);
392
- }
393
- function emitDurableEnvironmentAdapterEvent(eventData, observers) {
394
- engine.emitAdapterEvent({
395
- type: 'environment',
396
- timestamp: Date.now(),
397
- environment: DurableEnvironmentEventDiscriminator,
398
- data: eventData,
399
- }, observers);
400
- }
401
-
402
- function reviveTTLOverrides(ttlStore, environment) {
403
- return __awaiter(this, void 0, void 0, function () {
404
- var map, defaultTTL, overrides, i, len, _a, namespace, representationName, ttl;
405
- return __generator(this, function (_b) {
406
- switch (_b.label) {
407
- case 0: return [4 /*yield*/, ttlStore.getDurableTTLOverrides()];
408
- case 1:
409
- map = _b.sent();
410
- defaultTTL = map.defaultTTL, overrides = map.overrides;
411
- if (defaultTTL !== undefined) {
412
- environment.storeSetDefaultTTLOverride(defaultTTL.ttl);
413
- }
414
- for (i = 0, len = overrides.length; i < len; i++) {
415
- _a = overrides[i], namespace = _a.namespace, representationName = _a.representationName, ttl = _a.ttl;
416
- environment.storeSetTTLOverride(namespace, representationName, ttl);
417
- }
418
- return [2 /*return*/];
419
- }
420
- });
421
- });
422
- }
423
-
424
- /**
425
- * Returns an empty InMemoryStore that can be used for ingestion. Copies over
426
- * the TTLOverrides from the given Environment's Store.
427
- */
428
- function buildIngestStagingStore(environment) {
429
- return environment.storeBuildIngestionStagingStore();
430
- }
431
-
432
- var AdapterContextSegment = 'ADAPTER-CONTEXT';
433
- var ADAPTER_CONTEXT_ID_SUFFIX = '__NAMED_CONTEXT';
434
- function reviveOrCreateContext(adapterId, durableStore, durableStoreErrorHandler, contextStores, pendingContextStoreKeys, onContextLoaded) {
435
- return __awaiter(this, void 0, void 0, function () {
436
- var context, contextReturn, entries, error_1;
437
- return __generator(this, function (_a) {
438
- switch (_a.label) {
439
- case 0:
440
- // initialize empty context store
441
- contextStores[adapterId] = create(null);
442
- context = {
443
- set: function (key, value) {
444
- var _a;
445
- contextStores[adapterId][key] = value;
446
- durableStore.setEntries((_a = {},
447
- _a[adapterId] = { data: contextStores[adapterId] },
448
- _a), AdapterContextSegment);
449
- pendingContextStoreKeys.add(adapterId);
450
- },
451
- get: function (key) {
452
- return contextStores[adapterId][key];
453
- },
454
- };
455
- contextReturn = function () {
456
- if (onContextLoaded !== undefined) {
457
- return onContextLoaded(context).then(function () {
458
- return context;
459
- });
460
- }
461
- return context;
462
- };
463
- _a.label = 1;
464
- case 1:
465
- _a.trys.push([1, 3, , 4]);
466
- return [4 /*yield*/, durableStore.getEntries([adapterId], AdapterContextSegment)];
467
- case 2:
468
- entries = _a.sent();
469
- if (entries !== undefined && entries[adapterId] !== undefined) {
470
- // if durable store has a saved context then load it in the store
471
- contextStores[adapterId] = entries[adapterId].data;
472
- }
473
- return [3 /*break*/, 4];
474
- case 3:
475
- error_1 = _a.sent();
476
- durableStoreErrorHandler(error_1);
477
- return [3 /*break*/, 4];
478
- case 4: return [2 /*return*/, contextReturn()];
479
- }
480
- });
481
- });
482
- }
483
- function isUnfulfilledSnapshot(cachedSnapshotResult) {
484
- if (cachedSnapshotResult === undefined) {
485
- return false;
486
- }
487
- if ('then' in cachedSnapshotResult) {
488
- return false;
489
- }
490
- return cachedSnapshotResult.state === 'Unfulfilled';
491
- }
492
- /**
493
- * Configures the environment to persist data into a durable store and attempt to resolve
494
- * data from the persistent store before hitting the network.
495
- *
496
- * @param environment The base environment
497
- * @param durableStore A DurableStore implementation
498
- * @param instrumentation An instrumentation function implementation
499
- */
500
- function makeDurable(environment, _a) {
501
- var _this = this;
502
- var durableStore = _a.durableStore, instrumentation = _a.instrumentation;
503
- var ingestStagingStore = null;
504
- var durableTTLStore = new DurableTTLStore(durableStore);
505
- var mergeKeysPromiseMap = new Map();
506
- // When a context store is mutated we write it to L2, which causes DS on change
507
- // event. If this instance of makeDurable caused that L2 write we can ignore that
508
- // on change event. This Set helps us do that.
509
- var pendingContextStoreKeys = new Set();
510
- var contextStores = create(null);
511
- var initializationPromise = new Promise(function (resolve) {
512
- var finish = function () {
513
- resolve();
514
- initializationPromise = undefined;
515
- };
516
- reviveTTLOverrides(durableTTLStore, environment).then(finish);
517
- });
518
- //instrumentation for durable store errors
519
- var durableStoreErrorHandler = handleDurableStoreRejection(instrumentation);
520
- var disposed = false;
521
- var validateNotDisposed = function () {
522
- if (disposed === true) {
523
- throw new Error('This makeDurable instance has been disposed');
524
- }
525
- };
526
- var unsubscribe = durableStore.registerOnChangedListener(function (changes) { return __awaiter(_this, void 0, void 0, function () {
527
- var defaultSegmentKeys, adapterContextSegmentKeys, i, len, change, adapterContextKeysFromDifferentInstance, _i, adapterContextSegmentKeys_1, key, entries, entryKeys, i, len, entryKey, entry, error_2, defaultSegmentKeysLength, i, key, canonical;
528
- return __generator(this, function (_a) {
529
- switch (_a.label) {
530
- case 0:
531
- defaultSegmentKeys = [];
532
- adapterContextSegmentKeys = [];
533
- for (i = 0, len = changes.length; i < len; i++) {
534
- change = changes[i];
535
- // we only care about changes to the data which is stored in the default
536
- // segment or the adapter context
537
- if (change.segment === DefaultDurableSegment) {
538
- defaultSegmentKeys.push.apply(defaultSegmentKeys, change.ids);
539
- }
540
- else if (change.segment === AdapterContextSegment) {
541
- adapterContextSegmentKeys.push.apply(adapterContextSegmentKeys, change.ids);
542
- }
543
- }
544
- adapterContextKeysFromDifferentInstance = [];
545
- for (_i = 0, adapterContextSegmentKeys_1 = adapterContextSegmentKeys; _i < adapterContextSegmentKeys_1.length; _i++) {
546
- key = adapterContextSegmentKeys_1[_i];
547
- if (pendingContextStoreKeys.has(key)) {
548
- // if this instance caused the L2 write then remove from the
549
- // "pending" Set and move on
550
- pendingContextStoreKeys.delete(key);
551
- }
552
- else {
553
- // else it came from another luvio instance and we need to
554
- // read from L2
555
- adapterContextKeysFromDifferentInstance.push(key);
556
- }
557
- }
558
- if (!(adapterContextKeysFromDifferentInstance.length > 0)) return [3 /*break*/, 4];
559
- _a.label = 1;
560
- case 1:
561
- _a.trys.push([1, 3, , 4]);
562
- return [4 /*yield*/, durableStore.getEntries(adapterContextKeysFromDifferentInstance, AdapterContextSegment)];
563
- case 2:
564
- entries = _a.sent();
565
- if (entries !== undefined) {
566
- entryKeys = keys(entries);
567
- for (i = 0, len = entryKeys.length; i < len; i++) {
568
- entryKey = entryKeys[i];
569
- entry = entries[entryKey];
570
- contextStores[entryKey] = entry.data;
571
- }
572
- }
573
- return [3 /*break*/, 4];
574
- case 3:
575
- error_2 = _a.sent();
576
- durableStoreErrorHandler(error_2);
577
- return [3 /*break*/, 4];
578
- case 4:
579
- defaultSegmentKeysLength = defaultSegmentKeys.length;
580
- if (!(defaultSegmentKeysLength > 0)) return [3 /*break*/, 6];
581
- for (i = 0; i < defaultSegmentKeysLength; i++) {
582
- key = defaultSegmentKeys[i];
583
- canonical = environment.storeGetCanonicalKey(key);
584
- if (canonical !== key) {
585
- continue;
586
- }
587
- // TODO: W-8909393 If expiration is the only thing that changed we should not evict the data... so
588
- // if we stored expiration and data at different keys (or same keys in different segments)
589
- // then we could know if only the expiration has changed and we wouldn't need to evict
590
- // and go through an entire broadcast/revive cycle for unchanged data
591
- // call base environment storeEvict so this evict is not tracked for durable deletion
592
- environment.storeEvict(key);
593
- }
594
- return [4 /*yield*/, environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable)];
595
- case 5:
596
- _a.sent();
597
- _a.label = 6;
598
- case 6: return [2 /*return*/];
599
- }
600
- });
601
- }); });
602
- var dispose = function () {
603
- validateNotDisposed();
604
- disposed = true;
605
- return unsubscribe();
606
- };
607
- var storePublish = function (key, data) {
608
- validateNotDisposed();
609
- if (ingestStagingStore === null) {
610
- ingestStagingStore = buildIngestStagingStore(environment);
611
- }
612
- ingestStagingStore.publish(key, data);
613
- // remove record from main luvio L1 cache while we are on the synchronous path
614
- // because we do not want some other code attempting to use the
615
- // in-memory values before the durable store onChanged handler
616
- // calls back and revives the values to in-memory
617
- environment.storeEvict(key);
618
- };
619
- var publishStoreMetadata = function (recordId, storeMetadata) {
620
- validateNotDisposed();
621
- if (ingestStagingStore === null) {
622
- ingestStagingStore = buildIngestStagingStore(environment);
623
- }
624
- ingestStagingStore.publishMetadata(recordId, storeMetadata);
625
- };
626
- var storeIngest = function (key, ingest, response, luvio) {
627
- validateNotDisposed();
628
- // we don't ingest to the luvio L1 store from network directly, we ingest to
629
- // L2 and let DurableStore on change event revive keys into luvio L1 store
630
- if (ingestStagingStore === null) {
631
- ingestStagingStore = buildIngestStagingStore(environment);
632
- }
633
- environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
634
- };
635
- var storeIngestError = function (key, errorSnapshot, storeMetadataParams, _storeOverride) {
636
- validateNotDisposed();
637
- if (ingestStagingStore === null) {
638
- ingestStagingStore = buildIngestStagingStore(environment);
639
- }
640
- environment.storeIngestError(key, errorSnapshot, storeMetadataParams, ingestStagingStore);
641
- };
642
- var storeBroadcast = function (_rebuildSnapshot, _snapshotDataAvailable) {
643
- validateNotDisposed();
644
- // publishing to L2 is essentially "broadcasting" because the onChanged
645
- // handler will fire which will revive records to the main L1 store and
646
- // call the base storeBroadcast
647
- return publishChangesToDurableStore();
648
- };
649
- var publishChangesToDurableStore = function (additionalDurableStoreOperations) {
650
- validateNotDisposed();
651
- if (ingestStagingStore === null) {
652
- return Promise.resolve();
653
- }
654
- var promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations);
655
- ingestStagingStore = null;
656
- return promise;
657
- };
658
- var storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
659
- validateNotDisposed();
660
- // if this lookup is right after an ingest there will be a staging store
661
- if (ingestStagingStore !== null) {
662
- var reader = new engine.Reader(ingestStagingStore, sel.variables, refresh, undefined, ttlStrategy);
663
- return reader.read(sel);
664
- }
665
- // otherwise this is from buildCachedSnapshot and we should use the luvio
666
- // L1 store
667
- return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
668
- };
669
- var storeEvict = function (key) {
670
- validateNotDisposed();
671
- if (ingestStagingStore === null) {
672
- ingestStagingStore = buildIngestStagingStore(environment);
673
- }
674
- ingestStagingStore.evict(key);
675
- };
676
- var getNode = function (key) {
677
- validateNotDisposed();
678
- if (ingestStagingStore === null) {
679
- ingestStagingStore = buildIngestStagingStore(environment);
680
- }
681
- return environment.getNode(key, ingestStagingStore);
682
- };
683
- var wrapNormalizedGraphNode = function (normalized) {
684
- validateNotDisposed();
685
- if (ingestStagingStore === null) {
686
- ingestStagingStore = buildIngestStagingStore(environment);
687
- }
688
- return environment.wrapNormalizedGraphNode(normalized, ingestStagingStore);
689
- };
690
- var rebuildSnapshot = function (snapshot, onRebuild) {
691
- validateNotDisposed();
692
- // try rebuilding from memory
693
- environment.rebuildSnapshot(snapshot, function (rebuilt) {
694
- // only try reviving from durable store if snapshot is unfulfilled
695
- if (rebuilt.state !== 'Unfulfilled') {
696
- onRebuild(rebuilt);
697
- return;
698
- }
699
- // Do an L2 revive and emit to subscriber using the callback.
700
- reviveSnapshot(environment, durableStore, rebuilt, durableStoreErrorHandler, function () {
701
- // reviveSnapshot will revive into L1, and since "records" is a reference
702
- // (and not a copy) to the L1 records we can use it for rebuild
703
- var rebuiltSnap;
704
- environment.rebuildSnapshot(snapshot, function (rebuilt) {
705
- rebuiltSnap = rebuilt;
706
- });
707
- return rebuiltSnap;
708
- }).then(function (result) {
709
- onRebuild(result.snapshot);
710
- });
711
- });
712
- };
713
- var withContext = function (adapter, options) {
714
- validateNotDisposed();
715
- var contextId = options.contextId, contextVersion = options.contextVersion, onContextLoaded = options.onContextLoaded;
716
- var context = undefined;
717
- var contextKey = "".concat(contextId);
718
- // if a context version is supplied, key with the version encoded
719
- if (contextVersion !== undefined) {
720
- contextKey += "::".concat(contextVersion);
721
- }
722
- contextKey += ADAPTER_CONTEXT_ID_SUFFIX;
723
- var contextAsPromise = reviveOrCreateContext(contextKey, durableStore, durableStoreErrorHandler, contextStores, pendingContextStoreKeys, onContextLoaded);
724
- return function (config, requestContext) {
725
- if (context === undefined) {
726
- return contextAsPromise.then(function (revivedContext) {
727
- context = revivedContext;
728
- return adapter(config, context, requestContext); // TODO - remove as any cast after https://github.com/salesforce-experience-platform-emu/luvio/pull/230
729
- });
730
- }
731
- return adapter(config, context, requestContext);
732
- };
733
- };
734
- var storeRedirect = function (existingKey, canonicalKey) {
735
- validateNotDisposed();
736
- // call redirect on staging store so "old" keys are removed from L2 on
737
- // the next publishChangesToDurableStore. NOTE: we don't need to call
738
- // redirect on the base environment store because staging store and base
739
- // L1 store share the same redirect and reverseRedirectKeys
740
- if (ingestStagingStore === null) {
741
- ingestStagingStore = buildIngestStagingStore(environment);
742
- }
743
- ingestStagingStore.redirect(existingKey, canonicalKey);
744
- };
745
- var storeSetTTLOverride = function (namespace, representationName, ttl) {
746
- validateNotDisposed();
747
- return Promise.all([
748
- environment.storeSetTTLOverride(namespace, representationName, ttl),
749
- durableTTLStore.setDurableTTLOverride(namespace, representationName, ttl),
750
- ]).then();
751
- };
752
- var storeSetDefaultTTLOverride = function (ttl) {
753
- validateNotDisposed();
754
- return Promise.all([
755
- environment.storeSetDefaultTTLOverride(ttl),
756
- durableTTLStore.setDefaultDurableTTLOverrides(ttl),
757
- ]).then();
758
- };
759
- var getDurableTTLOverrides = function () {
760
- validateNotDisposed();
761
- return durableTTLStore.getDurableTTLOverrides();
762
- };
763
- var dispatchResourceRequest = function (request, context, eventObservers) {
764
- return __awaiter(this, void 0, void 0, function () {
765
- return __generator(this, function (_a) {
766
- switch (_a.label) {
767
- case 0:
768
- validateNotDisposed();
769
- if (!(initializationPromise !== undefined)) return [3 /*break*/, 2];
770
- return [4 /*yield*/, initializationPromise];
771
- case 1:
772
- _a.sent();
773
- _a.label = 2;
774
- case 2: return [2 /*return*/, environment.dispatchResourceRequest(request, context, eventObservers)];
775
- }
776
- });
777
- });
778
- };
779
- // NOTE: we can't use "async" keyword on this function because that would
780
- // force it to always be an async response. The signature is a union
781
- // of sync/async so no "awaiting" in this function, just promise-chaining
782
- var applyCachePolicy = function (luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
783
- validateNotDisposed();
784
- var wrappedCacheLookup = function (injectedBuildSnapshotContext, injectedStoreLookup) {
785
- var snapshot = buildCachedSnapshot(injectedBuildSnapshotContext, injectedStoreLookup, luvio);
786
- // if the adapter attempted to do an L1 lookup and it was unfulfilled
787
- // then we can attempt an L2 lookup
788
- if (isUnfulfilledSnapshot(snapshot)) {
789
- var start_1 = Date.now();
790
- emitDurableEnvironmentAdapterEvent({ type: 'l2-revive-start' }, adapterRequestContext.eventObservers);
791
- var revivedSnapshot = reviveSnapshot(environment, durableStore, snapshot, durableStoreErrorHandler, function () { return injectedStoreLookup(snapshot.select, snapshot.refresh); }).then(function (result) {
792
- emitDurableEnvironmentAdapterEvent({
793
- type: 'l2-revive-end',
794
- snapshot: result.snapshot,
795
- duration: Date.now() - start_1,
796
- l2Trips: result.metrics.l2Trips,
797
- }, adapterRequestContext.eventObservers);
798
- return result.snapshot;
799
- });
800
- return revivedSnapshot;
801
- }
802
- // otherwise just return what buildCachedSnapshot gave us
803
- return snapshot;
804
- };
805
- var wrappedApplyCachePolicy = function () {
806
- return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, wrappedCacheLookup, buildNetworkSnapshot);
807
- };
808
- // GET adapters call applyCachePolicy before any other luvio
809
- // function so this is our chance to ensure we're initialized
810
- return initializationPromise !== undefined
811
- ? initializationPromise.then(wrappedApplyCachePolicy)
812
- : wrappedApplyCachePolicy();
813
- };
814
- var getIngestStagingStoreRecords = function () {
815
- validateNotDisposed();
816
- if (ingestStagingStore !== null) {
817
- return ingestStagingStore.fallbackStringKeyInMemoryStore.records;
818
- }
819
- return {};
820
- };
821
- var getIngestStagingStoreMetadata = function () {
822
- validateNotDisposed();
823
- if (ingestStagingStore !== null) {
824
- return ingestStagingStore.fallbackStringKeyInMemoryStore.metadata;
825
- }
826
- return {};
827
- };
828
- var handleSuccessResponse = function (ingestAndBroadcastFunc, getResponseCacheKeysFunc) {
829
- return __awaiter(this, void 0, void 0, function () {
830
- var cacheKeyMap, cacheKeyMapKeys, keysToRevive, _i, cacheKeyMapKeys_1, cacheKeyMapKey, cacheKey, canonical, snapshotFromMemoryIngest, keysToReviveAsArray, readWritePromise, _a, keysToReviveAsArray_1, key, _b, keysToReviveAsArray_2, key, pendingPromise, _c, select, refresh, result;
831
- var _this = this;
832
- return __generator(this, function (_d) {
833
- switch (_d.label) {
834
- case 0:
835
- validateNotDisposed();
836
- cacheKeyMap = getResponseCacheKeysFunc();
837
- cacheKeyMapKeys = cacheKeyMap.keysAsArray();
838
- keysToRevive = new engine.StoreKeySet();
839
- for (_i = 0, cacheKeyMapKeys_1 = cacheKeyMapKeys; _i < cacheKeyMapKeys_1.length; _i++) {
840
- cacheKeyMapKey = cacheKeyMapKeys_1[_i];
841
- cacheKey = cacheKeyMap.get(cacheKeyMapKey);
842
- if (cacheKey.mergeable === true) {
843
- canonical = environment.storeGetCanonicalKey(cacheKeyMapKey);
844
- keysToRevive.add(canonical);
845
- }
846
- }
847
- snapshotFromMemoryIngest = undefined;
848
- keysToReviveAsArray = Array.from(keysToRevive.keysAsStrings());
849
- if (!(keysToReviveAsArray.length > 0)) return [3 /*break*/, 5];
850
- readWritePromise = (function () { return __awaiter(_this, void 0, void 0, function () {
851
- var pendingPromises, _i, keysToReviveAsArray_3, key, pendingPromise, entries;
852
- return __generator(this, function (_a) {
853
- switch (_a.label) {
854
- case 0:
855
- pendingPromises = [];
856
- for (_i = 0, keysToReviveAsArray_3 = keysToReviveAsArray; _i < keysToReviveAsArray_3.length; _i++) {
857
- key = keysToReviveAsArray_3[_i];
858
- pendingPromise = mergeKeysPromiseMap.get(key);
859
- if (pendingPromise !== undefined) {
860
- // IMPORTANT: while on the synchronous code path we get a
861
- // handle to pendingPromise and push it onto the array.
862
- // This is important because later in this synchronous code
863
- // path we will upsert readWritePromise into the
864
- // mergeKeysPromiseMap (essentially overwriting pendingPromise
865
- // in the map).
866
- pendingPromises.push(pendingPromise);
867
- }
868
- }
869
- return [4 /*yield*/, Promise.all(pendingPromises)];
870
- case 1:
871
- _a.sent();
872
- return [4 /*yield*/, durableStore.getEntries(keysToReviveAsArray, DefaultDurableSegment)];
873
- case 2:
874
- entries = _a.sent();
875
- ingestStagingStore = buildIngestStagingStore(environment);
876
- publishDurableStoreEntries(entries, function (key, record) {
877
- if (typeof key === 'string') {
878
- ingestStagingStore.fallbackStringKeyInMemoryStore.records[key] =
879
- record;
880
- }
881
- else {
882
- ingestStagingStore.recordsMap.set(key, record);
883
- }
884
- }, function (key, metadata) {
885
- if (typeof key === 'string') {
886
- ingestStagingStore.fallbackStringKeyInMemoryStore.metadata[key] =
887
- metadata;
888
- }
889
- else {
890
- ingestStagingStore.metadataMap.set(key, metadata);
891
- }
892
- });
893
- return [4 /*yield*/, ingestAndBroadcastFunc()];
894
- case 3:
895
- snapshotFromMemoryIngest = _a.sent();
896
- return [2 /*return*/];
897
- }
898
- });
899
- }); })();
900
- for (_a = 0, keysToReviveAsArray_1 = keysToReviveAsArray; _a < keysToReviveAsArray_1.length; _a++) {
901
- key = keysToReviveAsArray_1[_a];
902
- // we are overwriting the previous promise at this key, but that
903
- // is ok because we got a handle to it earlier (see the IMPORTANT
904
- // comment about 35 lines up)
905
- mergeKeysPromiseMap.set(key, readWritePromise);
906
- }
907
- _d.label = 1;
908
- case 1:
909
- _d.trys.push([1, , 3, 4]);
910
- return [4 /*yield*/, readWritePromise];
911
- case 2:
912
- _d.sent();
913
- return [3 /*break*/, 4];
914
- case 3:
915
- for (_b = 0, keysToReviveAsArray_2 = keysToReviveAsArray; _b < keysToReviveAsArray_2.length; _b++) {
916
- key = keysToReviveAsArray_2[_b];
917
- pendingPromise = mergeKeysPromiseMap.get(key);
918
- // cleanup the entry from the map if this is the last promise
919
- // for that key
920
- if (pendingPromise === readWritePromise) {
921
- mergeKeysPromiseMap.delete(key);
922
- }
923
- }
924
- return [7 /*endfinally*/];
925
- case 4: return [3 /*break*/, 7];
926
- case 5:
927
- // we aren't doing any merging so we don't have to synchronize, the
928
- // underlying DurableStore implementation takes care of R/W sync
929
- // so all we have to do is ingest then write to L2
930
- ingestStagingStore = buildIngestStagingStore(environment);
931
- return [4 /*yield*/, ingestAndBroadcastFunc()];
932
- case 6:
933
- snapshotFromMemoryIngest = _d.sent();
934
- _d.label = 7;
935
- case 7:
936
- if (snapshotFromMemoryIngest === undefined) {
937
- return [2 /*return*/, undefined];
938
- }
939
- if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
940
- return [2 /*return*/, snapshotFromMemoryIngest];
941
- }
942
- _c = snapshotFromMemoryIngest, select = _c.select, refresh = _c.refresh;
943
- return [4 /*yield*/, reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, function () { return environment.storeLookup(select, environment.createSnapshot, refresh); })];
944
- case 8:
945
- result = _d.sent();
946
- return [2 /*return*/, result.snapshot];
947
- }
948
- });
949
- });
950
- };
951
- var handleErrorResponse = function (ingestAndBroadcastFunc) {
952
- return __awaiter(this, void 0, void 0, function () {
953
- return __generator(this, function (_a) {
954
- validateNotDisposed();
955
- ingestStagingStore = buildIngestStagingStore(environment);
956
- return [2 /*return*/, ingestAndBroadcastFunc()];
957
- });
958
- });
959
- };
960
- var getNotifyChangeStoreEntries = function (keys) {
961
- validateNotDisposed();
962
- return durableStore
963
- .getEntries(keys.map(engine.serializeStructuredKey), DefaultDurableSegment)
964
- .then(function (durableRecords) {
965
- var entries = [];
966
- publishDurableStoreEntries(durableRecords, function (key, record) {
967
- entries.push({
968
- key: key,
969
- record: record,
970
- });
971
- }, function () { });
972
- return entries;
973
- });
974
- };
975
- environment.defaultCachePolicy = {
976
- type: 'stale-while-revalidate',
977
- implementation: engine.buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
978
- };
979
- return create(environment, {
980
- publishStoreMetadata: { value: publishStoreMetadata },
981
- storeIngest: { value: storeIngest },
982
- storeIngestError: { value: storeIngestError },
983
- storeBroadcast: { value: storeBroadcast },
984
- storeLookup: { value: storeLookup },
985
- storeEvict: { value: storeEvict },
986
- wrapNormalizedGraphNode: { value: wrapNormalizedGraphNode },
987
- getNode: { value: getNode },
988
- rebuildSnapshot: { value: rebuildSnapshot },
989
- withContext: { value: withContext },
990
- storeSetTTLOverride: { value: storeSetTTLOverride },
991
- storeSetDefaultTTLOverride: { value: storeSetDefaultTTLOverride },
992
- storePublish: { value: storePublish },
993
- storeRedirect: { value: storeRedirect },
994
- dispose: { value: dispose },
995
- publishChangesToDurableStore: { value: publishChangesToDurableStore },
996
- getDurableTTLOverrides: { value: getDurableTTLOverrides },
997
- dispatchResourceRequest: { value: dispatchResourceRequest },
998
- applyCachePolicy: { value: applyCachePolicy },
999
- getIngestStagingStoreRecords: { value: getIngestStagingStoreRecords },
1000
- getIngestStagingStoreMetadata: { value: getIngestStagingStoreMetadata },
1001
- handleSuccessResponse: { value: handleSuccessResponse },
1002
- handleErrorResponse: { value: handleErrorResponse },
1003
- getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
1004
- });
1005
- }
1006
-
1007
- exports.DURABLE_METADATA_VERSION = DURABLE_METADATA_VERSION;
1008
- exports.DefaultDurableSegment = DefaultDurableSegment;
1009
- exports.isDurableEnvironmentEvent = isDurableEnvironmentEvent;
1010
- exports.makeDurable = makeDurable;
1011
- exports.publishDurableStoreEntries = publishDurableStoreEntries;
1012
-
1013
- }));