@contello/store 4.4.1 → 4.5.1
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/fragments.d.ts +0 -2
- package/dist/fragments.d.ts.map +1 -1
- package/dist/fragments.js +1 -2
- package/dist/index.cjs +114 -71
- package/dist/index.d.cts +7 -20
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +7 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +114 -72
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/fragments.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/fragments.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* resolved absolute paths to the `.gql` fragment files that store-backed
|
|
4
3
|
* codegen should include. combines media's primitives with store's own
|
|
@@ -6,5 +5,4 @@
|
|
|
6
5
|
* codegen `documents` config.
|
|
7
6
|
*/
|
|
8
7
|
export declare const fragments: string[];
|
|
9
|
-
//#endregion
|
|
10
8
|
//# sourceMappingURL=fragments.d.ts.map
|
package/dist/fragments.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragments.d.ts","names":[],"sources":["../src/fragments.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fragments.d.ts","names":[],"sources":["../src/fragments.ts"],"mappings":";;;;;;qBAYa"}
|
package/dist/fragments.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import { fragments as fragments$1 } from "@contello/media/fragments";
|
|
3
|
-
|
|
3
|
+
// src/fragments.ts
|
|
4
4
|
const packageRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
5
5
|
/**
|
|
6
6
|
* resolved absolute paths to the `.gql` fragment files that store-backed
|
|
@@ -13,7 +13,6 @@ const fragments = [
|
|
|
13
13
|
`${packageRoot}fragments/asset.gql`,
|
|
14
14
|
`${packageRoot}fragments/route.gql`
|
|
15
15
|
];
|
|
16
|
-
//#endregion
|
|
17
16
|
export { fragments };
|
|
18
17
|
|
|
19
18
|
//# sourceMappingURL=fragments.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -3,9 +3,10 @@ let _contello_client = require("@contello/client");
|
|
|
3
3
|
let _entwico_dash_async = require("@entwico/dash/async");
|
|
4
4
|
let _entwico_projected = require("@entwico/projected");
|
|
5
5
|
let _contello_opentelemetry = require("@contello/opentelemetry");
|
|
6
|
+
let node_async_hooks = require("node:async_hooks");
|
|
6
7
|
let _entwico_dash = require("@entwico/dash");
|
|
7
8
|
let lru_cache = require("lru-cache");
|
|
8
|
-
|
|
9
|
+
// src/generated/graphql.ts
|
|
9
10
|
const MediaAssetFragmentSchema = `fragment MediaAsset on ContelloAsset {
|
|
10
11
|
id
|
|
11
12
|
original {
|
|
@@ -218,11 +219,9 @@ const schema = {
|
|
|
218
219
|
},
|
|
219
220
|
models: { dummy: "DummyEntity" }
|
|
220
221
|
};
|
|
221
|
-
|
|
222
|
-
//#region src/telemetry.ts
|
|
222
|
+
// src/telemetry.ts
|
|
223
223
|
const { wrap } = (0, _contello_opentelemetry.createOperationTelemetry)("@contello/store");
|
|
224
|
-
|
|
225
|
-
//#region src/utils.ts
|
|
224
|
+
// src/utils.ts
|
|
226
225
|
/**
|
|
227
226
|
* default `cache.ttl` applied across all store kinds. eager stores (collections, singletons)
|
|
228
227
|
* use it as the interval for a periodic full refresh; lazy stores use it as the per-item
|
|
@@ -238,6 +237,22 @@ function resolveTtl(ttl) {
|
|
|
238
237
|
if (ttl === false || ttl <= 0) return void 0;
|
|
239
238
|
return ttl;
|
|
240
239
|
}
|
|
240
|
+
function createRefreshRetry() {
|
|
241
|
+
const controller = new AbortController();
|
|
242
|
+
return {
|
|
243
|
+
async run(fn) {
|
|
244
|
+
try {
|
|
245
|
+
await (0, _entwico_dash_async.retryWithBackoff)(fn, { signal: controller.signal });
|
|
246
|
+
return true;
|
|
247
|
+
} catch {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
stop() {
|
|
252
|
+
controller.abort();
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
241
256
|
/**
|
|
242
257
|
* creates a coalescing refresh scheduler with exponential-backoff retry on failure.
|
|
243
258
|
*
|
|
@@ -246,11 +261,11 @@ function resolveTtl(ttl) {
|
|
|
246
261
|
* scheduleRefresh. once the in-flight refresh completes, at most one queued refresh
|
|
247
262
|
* starts, with that latest kind — collapsing any number of intermediate requests into one.
|
|
248
263
|
*
|
|
249
|
-
* on error, retries
|
|
264
|
+
* on error, retries with exponential backoff until `retry` is stopped. the projected value keeps serving
|
|
250
265
|
* the stale cached value throughout (SWR). the `onRefreshed` callback receives the kind that
|
|
251
266
|
* triggered the just-completed refresh.
|
|
252
267
|
*/
|
|
253
|
-
function createRefresher(fn, onRefreshed,
|
|
268
|
+
function createRefresher(fn, onRefreshed, retry) {
|
|
254
269
|
let refreshing = false;
|
|
255
270
|
let inFlightKind;
|
|
256
271
|
let pendingKind;
|
|
@@ -261,8 +276,8 @@ function createRefresher(fn, onRefreshed, onStart) {
|
|
|
261
276
|
}
|
|
262
277
|
refreshing = true;
|
|
263
278
|
inFlightKind = kind;
|
|
264
|
-
|
|
265
|
-
|
|
279
|
+
retry.run(fn).then((refreshed) => {
|
|
280
|
+
if (!refreshed) return;
|
|
266
281
|
const finished = inFlightKind;
|
|
267
282
|
refreshing = false;
|
|
268
283
|
inFlightKind = void 0;
|
|
@@ -289,17 +304,21 @@ function createRefreshChannel(onRefresh) {
|
|
|
289
304
|
};
|
|
290
305
|
}
|
|
291
306
|
function createTtlOrchestrator(options) {
|
|
307
|
+
const runInOwnContext = node_async_hooks.AsyncLocalStorage.snapshot();
|
|
292
308
|
let timer;
|
|
309
|
+
let cleared = false;
|
|
293
310
|
return {
|
|
294
311
|
mark() {
|
|
312
|
+
if (cleared) return;
|
|
295
313
|
if (timer !== void 0) {
|
|
296
314
|
clearTimeout(timer);
|
|
297
315
|
timer = void 0;
|
|
298
316
|
}
|
|
299
317
|
if (options.ttl === void 0) return;
|
|
300
|
-
timer = setTimeout(options.run, options.ttl);
|
|
318
|
+
timer = runInOwnContext(() => setTimeout(options.run, options.ttl));
|
|
301
319
|
},
|
|
302
320
|
clear() {
|
|
321
|
+
cleared = true;
|
|
303
322
|
if (timer === void 0) return;
|
|
304
323
|
clearTimeout(timer);
|
|
305
324
|
timer = void 0;
|
|
@@ -328,8 +347,7 @@ function createRefreshByTtlQueue() {
|
|
|
328
347
|
next();
|
|
329
348
|
} };
|
|
330
349
|
}
|
|
331
|
-
|
|
332
|
-
//#region src/write-buffer.ts
|
|
350
|
+
// src/write-buffer.ts
|
|
333
351
|
function createWriteBuffer() {
|
|
334
352
|
const parked = /* @__PURE__ */ new Map();
|
|
335
353
|
const awaited = /* @__PURE__ */ new Map();
|
|
@@ -374,8 +392,7 @@ function createWriteBuffer() {
|
|
|
374
392
|
}
|
|
375
393
|
};
|
|
376
394
|
}
|
|
377
|
-
|
|
378
|
-
//#region src/assets.ts
|
|
395
|
+
// src/assets.ts
|
|
379
396
|
function mapFile$1(raw) {
|
|
380
397
|
return {
|
|
381
398
|
uid: raw.uid,
|
|
@@ -401,6 +418,7 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
|
|
|
401
418
|
eviction: opts.cache?.eviction ?? "refresh"
|
|
402
419
|
};
|
|
403
420
|
const channel = createRefreshChannel(opts.onRefresh);
|
|
421
|
+
const retry = createRefreshRetry();
|
|
404
422
|
const ttl = createTtlOrchestrator({
|
|
405
423
|
ttl: cache.ttl,
|
|
406
424
|
run: () => runFullRefresh("ttl")
|
|
@@ -444,7 +462,7 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
|
|
|
444
462
|
});
|
|
445
463
|
}
|
|
446
464
|
function runFullRefresh(kind) {
|
|
447
|
-
refreshByTtl.enqueue(() =>
|
|
465
|
+
refreshByTtl.enqueue(() => retry.run(async () => {
|
|
448
466
|
emit((await projected.refresh()).keys().toArray(), kind);
|
|
449
467
|
ttl.mark();
|
|
450
468
|
}));
|
|
@@ -456,7 +474,7 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
|
|
|
456
474
|
return;
|
|
457
475
|
}
|
|
458
476
|
const settled = writeBuffer.awaitingUpstream(refreshIds);
|
|
459
|
-
|
|
477
|
+
retry.run(async () => {
|
|
460
478
|
await projected.refresh(refreshIds);
|
|
461
479
|
emit(changedIds, "upstream-update");
|
|
462
480
|
}).finally(settled);
|
|
@@ -530,6 +548,7 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
|
|
|
530
548
|
},
|
|
531
549
|
destroy() {
|
|
532
550
|
unsubUpdates();
|
|
551
|
+
retry.stop();
|
|
533
552
|
ttl.clear();
|
|
534
553
|
channel.complete();
|
|
535
554
|
}
|
|
@@ -551,8 +570,7 @@ function createAssetsSyncCollection(options, client, updates$, refreshByTtl) {
|
|
|
551
570
|
destroy
|
|
552
571
|
};
|
|
553
572
|
}
|
|
554
|
-
|
|
555
|
-
//#region src/dependency-collector.ts
|
|
573
|
+
// src/dependency-collector.ts
|
|
556
574
|
const EMPTY_KEYS = /* @__PURE__ */ new Set();
|
|
557
575
|
function createDependencyKey(target, id) {
|
|
558
576
|
return `${target}\0${id}`;
|
|
@@ -699,8 +717,7 @@ var DependencyCollector = class {
|
|
|
699
717
|
for (const key of this.forwardIndex.keys()) if (!keys.has(key)) this.clearItem(key);
|
|
700
718
|
}
|
|
701
719
|
};
|
|
702
|
-
|
|
703
|
-
//#region src/collection.ts
|
|
720
|
+
// src/collection.ts
|
|
704
721
|
function fetchCollection(source, client, ids) {
|
|
705
722
|
return (0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe((0, _contello_client.createSourceSubscription)(source), { ids }), (r) => r.source));
|
|
706
723
|
}
|
|
@@ -730,6 +747,7 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
|
|
|
730
747
|
};
|
|
731
748
|
const dependencyCollector = new DependencyCollector(_def.model, resolver);
|
|
732
749
|
const channel = createRefreshChannel(opts.onRefresh);
|
|
750
|
+
const retry = createRefreshRetry();
|
|
733
751
|
const ttl = createTtlOrchestrator({
|
|
734
752
|
ttl: _def.cache.ttl,
|
|
735
753
|
run: () => runFullRefresh("ttl")
|
|
@@ -775,7 +793,7 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
|
|
|
775
793
|
});
|
|
776
794
|
}
|
|
777
795
|
function runFullRefresh(kind) {
|
|
778
|
-
refreshByTtl.enqueue(() =>
|
|
796
|
+
refreshByTtl.enqueue(() => retry.run(async () => {
|
|
779
797
|
emit((await projected.refresh()).keys().toArray(), kind);
|
|
780
798
|
ttl.mark();
|
|
781
799
|
}));
|
|
@@ -787,7 +805,7 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
|
|
|
787
805
|
return;
|
|
788
806
|
}
|
|
789
807
|
const settled = writeBuffer.awaitingUpstream(refreshIds);
|
|
790
|
-
|
|
808
|
+
retry.run(async () => {
|
|
791
809
|
await projected.refresh(refreshIds);
|
|
792
810
|
emit(changedIds, "upstream-update");
|
|
793
811
|
}).finally(settled);
|
|
@@ -873,6 +891,7 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
|
|
|
873
891
|
},
|
|
874
892
|
destroy() {
|
|
875
893
|
unsubUpdates();
|
|
894
|
+
retry.stop();
|
|
876
895
|
ttl.clear();
|
|
877
896
|
channel.complete();
|
|
878
897
|
}
|
|
@@ -897,8 +916,7 @@ function createCollectionSync(source, options, client, updates$, resolver, refre
|
|
|
897
916
|
destroy
|
|
898
917
|
};
|
|
899
918
|
}
|
|
900
|
-
|
|
901
|
-
//#region src/i18n.ts
|
|
919
|
+
// src/i18n.ts
|
|
902
920
|
function toGqlMessageInput(msg) {
|
|
903
921
|
return {
|
|
904
922
|
token: msg.token,
|
|
@@ -921,6 +939,7 @@ function toGqlMessageInput(msg) {
|
|
|
921
939
|
}
|
|
922
940
|
function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
|
|
923
941
|
const channel = createRefreshChannel(def.onRefresh);
|
|
942
|
+
const retry = createRefreshRetry();
|
|
924
943
|
const ttl = createTtlOrchestrator({
|
|
925
944
|
ttl: resolveTtl(def.cache?.ttl),
|
|
926
945
|
run: () => runTtlRefresh()
|
|
@@ -958,7 +977,7 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
|
|
|
958
977
|
}
|
|
959
978
|
function runTtlRefresh() {
|
|
960
979
|
refreshByTtl.enqueue(async () => {
|
|
961
|
-
|
|
980
|
+
if (!await retry.run(() => projected.refresh())) return;
|
|
962
981
|
emitWithCurrentIds("ttl");
|
|
963
982
|
ttl.mark();
|
|
964
983
|
});
|
|
@@ -966,7 +985,7 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
|
|
|
966
985
|
const scheduleRefresh = createRefresher(() => projected.refresh(), (kind) => {
|
|
967
986
|
emitWithCurrentIds(kind);
|
|
968
987
|
ttl.mark();
|
|
969
|
-
},
|
|
988
|
+
}, retry);
|
|
970
989
|
function runPartialRefresh(upsertedIds, deletedIds) {
|
|
971
990
|
const changedIds = [.../* @__PURE__ */ new Set([...upsertedIds, ...deletedIds])];
|
|
972
991
|
if (changedIds.length === 0) return;
|
|
@@ -974,7 +993,7 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
|
|
|
974
993
|
emit(changedIds, "upstream-update");
|
|
975
994
|
return;
|
|
976
995
|
}
|
|
977
|
-
|
|
996
|
+
retry.run(async () => {
|
|
978
997
|
await projected.refresh(upsertedIds);
|
|
979
998
|
emit(changedIds, "upstream-update");
|
|
980
999
|
});
|
|
@@ -1010,13 +1029,13 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
|
|
|
1010
1029
|
},
|
|
1011
1030
|
destroy() {
|
|
1012
1031
|
unsubUpdates();
|
|
1032
|
+
retry.stop();
|
|
1013
1033
|
ttl.clear();
|
|
1014
1034
|
channel.complete();
|
|
1015
1035
|
}
|
|
1016
1036
|
};
|
|
1017
1037
|
}
|
|
1018
|
-
|
|
1019
|
-
//#region src/lru.ts
|
|
1038
|
+
// src/lru.ts
|
|
1020
1039
|
function createLruCache(options) {
|
|
1021
1040
|
const { max, ttl, onEvict: dispose } = options;
|
|
1022
1041
|
const lru = new lru_cache.LRUCache({
|
|
@@ -1042,8 +1061,7 @@ function createLruCache(options) {
|
|
|
1042
1061
|
keys: () => lru.keys().toArray()
|
|
1043
1062
|
};
|
|
1044
1063
|
}
|
|
1045
|
-
|
|
1046
|
-
//#region src/lazy-assets.ts
|
|
1064
|
+
// src/lazy-assets.ts
|
|
1047
1065
|
function mapFile(raw) {
|
|
1048
1066
|
return {
|
|
1049
1067
|
uid: raw.uid,
|
|
@@ -1088,13 +1106,14 @@ function createLazyAssetsCollection(def, client, updates$) {
|
|
|
1088
1106
|
});
|
|
1089
1107
|
}
|
|
1090
1108
|
let lastRefreshKeys = [];
|
|
1109
|
+
const retry = createRefreshRetry();
|
|
1091
1110
|
const scheduleRefresh = createRefresher(async () => {
|
|
1092
1111
|
lastRefreshKeys = cache.keys();
|
|
1093
1112
|
if (lastRefreshKeys.length === 0) return;
|
|
1094
1113
|
await projected.refresh(lastRefreshKeys);
|
|
1095
1114
|
}, (kind) => {
|
|
1096
1115
|
if (lastRefreshKeys.length > 0) emit(lastRefreshKeys, kind);
|
|
1097
|
-
},
|
|
1116
|
+
}, retry);
|
|
1098
1117
|
const unsubUpdates = updates$.subscribe((batch) => {
|
|
1099
1118
|
if (batch.asset.length === 0) return;
|
|
1100
1119
|
for (const event of batch.asset) projected.delete(event.id);
|
|
@@ -1124,12 +1143,12 @@ function createLazyAssetsCollection(def, client, updates$) {
|
|
|
1124
1143
|
},
|
|
1125
1144
|
destroy() {
|
|
1126
1145
|
unsubUpdates();
|
|
1146
|
+
retry.stop();
|
|
1127
1147
|
channel.complete();
|
|
1128
1148
|
}
|
|
1129
1149
|
};
|
|
1130
1150
|
}
|
|
1131
|
-
|
|
1132
|
-
//#region src/lazy-collection.ts
|
|
1151
|
+
// src/lazy-collection.ts
|
|
1133
1152
|
function createLazyCollection(source, options, client, updates$, resolver) {
|
|
1134
1153
|
const opts = options ?? {};
|
|
1135
1154
|
const mapFn = opts.map ?? ((item) => item);
|
|
@@ -1164,6 +1183,7 @@ function createLazyCollection(source, options, client, updates$, resolver) {
|
|
|
1164
1183
|
refresh$.next(event);
|
|
1165
1184
|
opts.onRefresh?.(event);
|
|
1166
1185
|
}
|
|
1186
|
+
const retry = createRefreshRetry();
|
|
1167
1187
|
let lastRefreshKeys = [];
|
|
1168
1188
|
const scheduleRefresh = createRefresher(async () => {
|
|
1169
1189
|
lastRefreshKeys = cache.keys();
|
|
@@ -1171,7 +1191,7 @@ function createLazyCollection(source, options, client, updates$, resolver) {
|
|
|
1171
1191
|
await projected.refresh(lastRefreshKeys);
|
|
1172
1192
|
}, (kind) => {
|
|
1173
1193
|
if (lastRefreshKeys.length > 0) emit(lastRefreshKeys, kind);
|
|
1174
|
-
},
|
|
1194
|
+
}, retry);
|
|
1175
1195
|
const unsubUpdates = updates$.subscribe((batch) => {
|
|
1176
1196
|
const evicted = /* @__PURE__ */ new Set();
|
|
1177
1197
|
const ownModelEvents = batch.entity.get(_def.model);
|
|
@@ -1201,12 +1221,35 @@ function createLazyCollection(source, options, client, updates$, resolver) {
|
|
|
1201
1221
|
},
|
|
1202
1222
|
destroy() {
|
|
1203
1223
|
unsubUpdates();
|
|
1224
|
+
retry.stop();
|
|
1204
1225
|
refresh$.complete();
|
|
1205
1226
|
}
|
|
1206
1227
|
};
|
|
1207
1228
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1229
|
+
// src/route-path.ts
|
|
1230
|
+
const ESCAPES = /(?:%[\dA-Fa-f]{2})+/g;
|
|
1231
|
+
const STAYS_ENCODED = /[/%?#\s\p{Cc}]/u;
|
|
1232
|
+
function decodeRun(run) {
|
|
1233
|
+
let decoded;
|
|
1234
|
+
try {
|
|
1235
|
+
decoded = decodeURIComponent(run);
|
|
1236
|
+
} catch {
|
|
1237
|
+
return run.toUpperCase();
|
|
1238
|
+
}
|
|
1239
|
+
let result = "";
|
|
1240
|
+
for (const char of decoded) result += STAYS_ENCODED.test(char) ? encodeURIComponent(char) : char;
|
|
1241
|
+
return result;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* The one form a route path is stored and looked up in: percent escapes decoded and unicode
|
|
1245
|
+
* composed (NFC), as core normalizes it. A request arrives percent-encoded (`/%C3%BCber-uns`),
|
|
1246
|
+
* the stored path is decoded (`/über-uns`); both spellings must hit the same cache entry. An
|
|
1247
|
+
* escape of a character a path cannot hold decoded stays encoded, with uppercase hex.
|
|
1248
|
+
*/
|
|
1249
|
+
function normalizeRoutePath(path) {
|
|
1250
|
+
return path.replaceAll(ESCAPES, decodeRun).normalize("NFC");
|
|
1251
|
+
}
|
|
1252
|
+
// src/routes-mapping.ts
|
|
1210
1253
|
function mapRoute(raw, resolver) {
|
|
1211
1254
|
const base = {
|
|
1212
1255
|
id: raw.id,
|
|
@@ -1256,8 +1299,7 @@ function mapRoute(raw, resolver) {
|
|
|
1256
1299
|
default: return;
|
|
1257
1300
|
}
|
|
1258
1301
|
}
|
|
1259
|
-
|
|
1260
|
-
//#region src/lazy-routes.ts
|
|
1302
|
+
// src/lazy-routes.ts
|
|
1261
1303
|
const ID_PREFIX = "1\0";
|
|
1262
1304
|
const PATH_PREFIX = "2\0";
|
|
1263
1305
|
const CACHE_KEY = Symbol("cacheKey");
|
|
@@ -1285,7 +1327,7 @@ function createRoutesCache(max, ttl) {
|
|
|
1285
1327
|
max,
|
|
1286
1328
|
ttl,
|
|
1287
1329
|
onEvict: (route) => {
|
|
1288
|
-
pathToId.delete(route.path);
|
|
1330
|
+
pathToId.delete(normalizeRoutePath(route.path));
|
|
1289
1331
|
idToPath.delete(route.id);
|
|
1290
1332
|
}
|
|
1291
1333
|
});
|
|
@@ -1302,8 +1344,8 @@ function createRoutesCache(max, ttl) {
|
|
|
1302
1344
|
get: (key) => lru.get(resolveKey(key)),
|
|
1303
1345
|
set: (_key, value) => {
|
|
1304
1346
|
const previousPath = idToPath.get(value.id);
|
|
1305
|
-
if (previousPath !== void 0 && previousPath !== value.path) pathToId.delete(previousPath);
|
|
1306
|
-
pathToId.set(value.path, value.id);
|
|
1347
|
+
if (previousPath !== void 0 && previousPath !== value.path) pathToId.delete(normalizeRoutePath(previousPath));
|
|
1348
|
+
pathToId.set(normalizeRoutePath(value.path), value.id);
|
|
1307
1349
|
idToPath.set(value.id, value.path);
|
|
1308
1350
|
lru.set(ID_PREFIX + value.id, value);
|
|
1309
1351
|
},
|
|
@@ -1311,7 +1353,7 @@ function createRoutesCache(max, ttl) {
|
|
|
1311
1353
|
const resolved = resolveKey(key);
|
|
1312
1354
|
const value = lru.get(resolved);
|
|
1313
1355
|
if (value) {
|
|
1314
|
-
pathToId.delete(value.path);
|
|
1356
|
+
pathToId.delete(normalizeRoutePath(value.path));
|
|
1315
1357
|
idToPath.delete(value.id);
|
|
1316
1358
|
}
|
|
1317
1359
|
lru.delete(resolved);
|
|
@@ -1351,7 +1393,7 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
|
|
|
1351
1393
|
}
|
|
1352
1394
|
const [rawByIds, rawByPaths] = await Promise.all([ids.length > 0 ? fetchRoutes({ ids }) : Promise.resolve([]), paths.length > 0 ? fetchRoutes({ paths }) : Promise.resolve([])]);
|
|
1353
1395
|
const byIds = collectRoutes(rawByIds, (r) => ID_PREFIX + r.id, resolver);
|
|
1354
|
-
const byPaths = collectRoutes(rawByPaths, (r) => PATH_PREFIX + r.path, resolver);
|
|
1396
|
+
const byPaths = collectRoutes(rawByPaths, (r) => PATH_PREFIX + normalizeRoutePath(r.path), resolver);
|
|
1355
1397
|
const found = [...byIds, ...byPaths];
|
|
1356
1398
|
const foundKeys = new Set(found.map((route) => route[CACHE_KEY]));
|
|
1357
1399
|
for (const key of prefixedKeys) if (!foundKeys.has(key)) negatives.set(key, true);
|
|
@@ -1367,13 +1409,14 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
|
|
|
1367
1409
|
});
|
|
1368
1410
|
}
|
|
1369
1411
|
let lastRefreshKeys = [];
|
|
1412
|
+
const retry = createRefreshRetry();
|
|
1370
1413
|
const scheduleRefresh = createRefresher(async () => {
|
|
1371
1414
|
lastRefreshKeys = cache.keys();
|
|
1372
1415
|
if (lastRefreshKeys.length === 0) return;
|
|
1373
1416
|
await projected.refresh(lastRefreshKeys);
|
|
1374
1417
|
}, (kind) => {
|
|
1375
1418
|
if (lastRefreshKeys.length > 0) emit(lastRefreshKeys.map((key) => key.slice(2)), kind);
|
|
1376
|
-
},
|
|
1419
|
+
}, retry);
|
|
1377
1420
|
const unsubUpdates = updates$.subscribe((batch) => {
|
|
1378
1421
|
const evicted = [];
|
|
1379
1422
|
for (const event of batch.route) {
|
|
@@ -1383,7 +1426,7 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
|
|
|
1383
1426
|
evicted.push(event.id);
|
|
1384
1427
|
} else {
|
|
1385
1428
|
negatives.delete(idKey);
|
|
1386
|
-
negatives.delete(PATH_PREFIX + event.after.path);
|
|
1429
|
+
negatives.delete(PATH_PREFIX + normalizeRoutePath(event.after.path));
|
|
1387
1430
|
if (cache.has(idKey)) cache.set(idKey, event.after);
|
|
1388
1431
|
evicted.push(event.after.path);
|
|
1389
1432
|
}
|
|
@@ -1407,8 +1450,8 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
|
|
|
1407
1450
|
return lookupOne(ID_PREFIX + idOrIds);
|
|
1408
1451
|
},
|
|
1409
1452
|
getByPath(pathOrPaths) {
|
|
1410
|
-
if (Array.isArray(pathOrPaths)) return lookupMany(pathOrPaths.map((p) => PATH_PREFIX + p));
|
|
1411
|
-
return lookupOne(PATH_PREFIX + pathOrPaths);
|
|
1453
|
+
if (Array.isArray(pathOrPaths)) return lookupMany(pathOrPaths.map((p) => PATH_PREFIX + normalizeRoutePath(p)));
|
|
1454
|
+
return lookupOne(PATH_PREFIX + normalizeRoutePath(pathOrPaths));
|
|
1412
1455
|
},
|
|
1413
1456
|
refresh() {
|
|
1414
1457
|
negatives.clear();
|
|
@@ -1421,12 +1464,12 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
|
|
|
1421
1464
|
},
|
|
1422
1465
|
destroy() {
|
|
1423
1466
|
unsubUpdates();
|
|
1467
|
+
retry.stop();
|
|
1424
1468
|
channel.complete();
|
|
1425
1469
|
}
|
|
1426
1470
|
};
|
|
1427
1471
|
}
|
|
1428
|
-
|
|
1429
|
-
//#region src/model-resolver.ts
|
|
1472
|
+
// src/model-resolver.ts
|
|
1430
1473
|
var ModelResolver = class {
|
|
1431
1474
|
_typeNames;
|
|
1432
1475
|
_toModel;
|
|
@@ -1463,8 +1506,7 @@ var ModelResolver = class {
|
|
|
1463
1506
|
return this._toModel.get(typeName) ?? typeName;
|
|
1464
1507
|
}
|
|
1465
1508
|
};
|
|
1466
|
-
|
|
1467
|
-
//#region src/routes.ts
|
|
1509
|
+
// src/routes.ts
|
|
1468
1510
|
function createRoutesCollection(options, client, updates$, resolver, refreshByTtl) {
|
|
1469
1511
|
const opts = options ?? {};
|
|
1470
1512
|
const cache = {
|
|
@@ -1472,6 +1514,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1472
1514
|
eviction: opts.cache?.eviction ?? "refresh"
|
|
1473
1515
|
};
|
|
1474
1516
|
const channel = createRefreshChannel(opts.onRefresh);
|
|
1517
|
+
const retry = createRefreshRetry();
|
|
1475
1518
|
const ttl = createTtlOrchestrator({
|
|
1476
1519
|
ttl: cache.ttl,
|
|
1477
1520
|
run: () => runFullRefresh("ttl")
|
|
@@ -1511,7 +1554,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1511
1554
|
idByPath.clear();
|
|
1512
1555
|
for (const r of items) {
|
|
1513
1556
|
pathById.set(r.id, r.path);
|
|
1514
|
-
idByPath.set(r.path, r.id);
|
|
1557
|
+
idByPath.set(normalizeRoutePath(r.path), r.id);
|
|
1515
1558
|
}
|
|
1516
1559
|
if (!loaded) {
|
|
1517
1560
|
loaded = true;
|
|
@@ -1524,14 +1567,14 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1524
1567
|
if (returnedIds.has(id)) continue;
|
|
1525
1568
|
const oldPath = pathById.get(id);
|
|
1526
1569
|
if (oldPath === void 0) continue;
|
|
1527
|
-
idByPath.delete(oldPath);
|
|
1570
|
+
idByPath.delete(normalizeRoutePath(oldPath));
|
|
1528
1571
|
pathById.delete(id);
|
|
1529
1572
|
}
|
|
1530
1573
|
for (const r of items) {
|
|
1531
1574
|
const oldPath = pathById.get(r.id);
|
|
1532
|
-
if (oldPath !== void 0 && oldPath !== r.path) idByPath.delete(oldPath);
|
|
1575
|
+
if (oldPath !== void 0 && oldPath !== r.path) idByPath.delete(normalizeRoutePath(oldPath));
|
|
1533
1576
|
pathById.set(r.id, r.path);
|
|
1534
|
-
idByPath.set(r.path, r.id);
|
|
1577
|
+
idByPath.set(normalizeRoutePath(r.path), r.id);
|
|
1535
1578
|
}
|
|
1536
1579
|
}
|
|
1537
1580
|
return items;
|
|
@@ -1544,7 +1587,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1544
1587
|
});
|
|
1545
1588
|
}
|
|
1546
1589
|
function runFullRefresh(kind) {
|
|
1547
|
-
refreshByTtl.enqueue(() =>
|
|
1590
|
+
refreshByTtl.enqueue(() => retry.run(async () => {
|
|
1548
1591
|
emit((await projected.refresh()).keys().toArray(), kind);
|
|
1549
1592
|
ttl.mark();
|
|
1550
1593
|
}));
|
|
@@ -1556,7 +1599,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1556
1599
|
return;
|
|
1557
1600
|
}
|
|
1558
1601
|
const settled = writeBuffer.awaitingUpstream(refreshIds);
|
|
1559
|
-
|
|
1602
|
+
retry.run(async () => {
|
|
1560
1603
|
await projected.refresh(refreshIds);
|
|
1561
1604
|
emit(changedIds, "upstream-update");
|
|
1562
1605
|
}).finally(settled);
|
|
@@ -1578,7 +1621,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1578
1621
|
for (const id of deleted) {
|
|
1579
1622
|
const oldPath = pathById.get(id);
|
|
1580
1623
|
if (oldPath === void 0) continue;
|
|
1581
|
-
idByPath.delete(oldPath);
|
|
1624
|
+
idByPath.delete(normalizeRoutePath(oldPath));
|
|
1582
1625
|
pathById.delete(id);
|
|
1583
1626
|
}
|
|
1584
1627
|
if (deleted.length > 0) projected.delete(deleted);
|
|
@@ -1592,7 +1635,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1592
1635
|
}
|
|
1593
1636
|
function lookupByPathSingle(path) {
|
|
1594
1637
|
return (0, _entwico_dash.maybeThen)(ensureLoaded(), () => {
|
|
1595
|
-
const id = idByPath.get(path);
|
|
1638
|
+
const id = idByPath.get(normalizeRoutePath(path));
|
|
1596
1639
|
return id === void 0 ? void 0 : projected.get(id);
|
|
1597
1640
|
});
|
|
1598
1641
|
}
|
|
@@ -1600,7 +1643,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1600
1643
|
return (0, _entwico_dash.maybeThen)(ensureLoaded(), () => {
|
|
1601
1644
|
const ids = [];
|
|
1602
1645
|
for (const p of paths) {
|
|
1603
|
-
const id = idByPath.get(p);
|
|
1646
|
+
const id = idByPath.get(normalizeRoutePath(p));
|
|
1604
1647
|
if (id !== void 0) ids.push(id);
|
|
1605
1648
|
}
|
|
1606
1649
|
return projected.get(ids);
|
|
@@ -1647,7 +1690,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1647
1690
|
writeBuffer.release([id]);
|
|
1648
1691
|
const oldPath = pathById.get(id);
|
|
1649
1692
|
if (oldPath !== void 0) {
|
|
1650
|
-
idByPath.delete(oldPath);
|
|
1693
|
+
idByPath.delete(normalizeRoutePath(oldPath));
|
|
1651
1694
|
pathById.delete(id);
|
|
1652
1695
|
}
|
|
1653
1696
|
projected.delete([id]);
|
|
@@ -1669,6 +1712,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
|
|
|
1669
1712
|
},
|
|
1670
1713
|
destroy() {
|
|
1671
1714
|
unsubUpdates();
|
|
1715
|
+
retry.stop();
|
|
1672
1716
|
ttl.clear();
|
|
1673
1717
|
channel.complete();
|
|
1674
1718
|
}
|
|
@@ -1693,8 +1737,7 @@ function createRoutesSyncCollection(options, client, updates$, resolver, refresh
|
|
|
1693
1737
|
destroy
|
|
1694
1738
|
};
|
|
1695
1739
|
}
|
|
1696
|
-
|
|
1697
|
-
//#region src/singleton.ts
|
|
1740
|
+
// src/singleton.ts
|
|
1698
1741
|
function createSingleton(source, options, client, updates$, resolver, refreshByTtl) {
|
|
1699
1742
|
const opts = options ?? {};
|
|
1700
1743
|
const mapFn = opts.map ?? ((item) => item);
|
|
@@ -1709,6 +1752,7 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
|
|
|
1709
1752
|
const dependencyCollector = new DependencyCollector(_def.model, resolver);
|
|
1710
1753
|
const itemKey = `singleton:${_def.name}`;
|
|
1711
1754
|
const channel = createRefreshChannel(opts.onRefresh);
|
|
1755
|
+
const retry = createRefreshRetry();
|
|
1712
1756
|
const ttl = createTtlOrchestrator({
|
|
1713
1757
|
ttl: _def.cache.ttl,
|
|
1714
1758
|
run: () => runTtlRefresh()
|
|
@@ -1728,7 +1772,7 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
|
|
|
1728
1772
|
}
|
|
1729
1773
|
function runTtlRefresh() {
|
|
1730
1774
|
refreshByTtl.enqueue(async () => {
|
|
1731
|
-
|
|
1775
|
+
if (!await retry.run(() => projected.refresh())) return;
|
|
1732
1776
|
emit("ttl");
|
|
1733
1777
|
ttl.mark();
|
|
1734
1778
|
});
|
|
@@ -1736,7 +1780,7 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
|
|
|
1736
1780
|
const scheduleRefresh = createRefresher(() => projected.refresh(), (kind) => {
|
|
1737
1781
|
emit(kind);
|
|
1738
1782
|
ttl.mark();
|
|
1739
|
-
},
|
|
1783
|
+
}, retry);
|
|
1740
1784
|
const unsubUpdates = updates$.subscribe((batch) => {
|
|
1741
1785
|
if (!loaded) return;
|
|
1742
1786
|
const hasOwnModel = batch.entity.has(_def.model);
|
|
@@ -1765,6 +1809,7 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
|
|
|
1765
1809
|
},
|
|
1766
1810
|
destroy() {
|
|
1767
1811
|
unsubUpdates();
|
|
1812
|
+
retry.stop();
|
|
1768
1813
|
ttl.clear();
|
|
1769
1814
|
channel.complete();
|
|
1770
1815
|
}
|
|
@@ -1784,8 +1829,7 @@ function createSingletonSync(source, options, client, updates$, resolver, refres
|
|
|
1784
1829
|
destroy
|
|
1785
1830
|
};
|
|
1786
1831
|
}
|
|
1787
|
-
|
|
1788
|
-
//#region src/watcher.ts
|
|
1832
|
+
// src/watcher.ts
|
|
1789
1833
|
function addRouteByModel(map, entityType, event) {
|
|
1790
1834
|
let list = map.get(entityType);
|
|
1791
1835
|
if (!list) {
|
|
@@ -1930,8 +1974,7 @@ function createInternalWatcher(client, resolver) {
|
|
|
1930
1974
|
}
|
|
1931
1975
|
};
|
|
1932
1976
|
}
|
|
1933
|
-
|
|
1934
|
-
//#region src/store.ts
|
|
1977
|
+
// src/store.ts
|
|
1935
1978
|
var Store = class {
|
|
1936
1979
|
_client;
|
|
1937
1980
|
_resolver;
|
|
@@ -2049,6 +2092,6 @@ var Store = class {
|
|
|
2049
2092
|
function createStore(options) {
|
|
2050
2093
|
return new Store(options);
|
|
2051
2094
|
}
|
|
2052
|
-
//#endregion
|
|
2053
2095
|
exports.Store = Store;
|
|
2054
2096
|
exports.createStore = createStore;
|
|
2097
|
+
exports.normalizeRoutePath = normalizeRoutePath;
|