@contello/store 3.0.1 → 4.0.0

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/index.cjs CHANGED
@@ -1,84 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
- value: mod,
21
- enumerable: true
22
- }) : target, mod));
23
- //#endregion
24
2
  let _contello_client = require("@contello/client");
25
- let projected = require("projected");
26
- let node_diagnostics_channel = require("node:diagnostics_channel");
27
- node_diagnostics_channel = __toESM(node_diagnostics_channel, 1);
3
+ let _entwico_dash_async = require("@entwico/dash/async");
4
+ let _entwico_projected = require("@entwico/projected");
5
+ let _contello_opentelemetry = require("@contello/opentelemetry");
6
+ let _entwico_dash = require("@entwico/dash");
28
7
  let lru_cache = require("lru-cache");
29
- //#region src/diagnostics.ts
30
- const channels = {
31
- start: "@contello/store:start",
32
- end: "@contello/store:end",
33
- error: "@contello/store:error"
34
- };
35
- const onStart = node_diagnostics_channel.default.channel(channels.start);
36
- const onEnd = node_diagnostics_channel.default.channel(channels.end);
37
- const onError = node_diagnostics_channel.default.channel(channels.error);
38
- function hasSubscribers() {
39
- return onStart.hasSubscribers || onEnd.hasSubscribers || onError.hasSubscribers;
40
- }
41
- function wrap(name, fn) {
42
- if (!hasSubscribers()) return fn();
43
- const start = performance.now();
44
- onStart.publish({ name });
45
- let result;
46
- try {
47
- result = fn();
48
- } catch (error) {
49
- onError.publish({
50
- name,
51
- error,
52
- durationMs: performance.now() - start
53
- });
54
- throw error;
55
- }
56
- if (result instanceof Promise) return (async () => {
57
- try {
58
- const r = await result;
59
- onEnd.publish({
60
- name,
61
- cached: false,
62
- durationMs: performance.now() - start
63
- });
64
- return r;
65
- } catch (error) {
66
- onError.publish({
67
- name,
68
- error,
69
- durationMs: performance.now() - start
70
- });
71
- throw error;
72
- }
73
- })();
74
- onEnd.publish({
75
- name,
76
- cached: true,
77
- durationMs: performance.now() - start
78
- });
79
- return result;
80
- }
81
- //#endregion
82
8
  //#region src/generated/graphql.ts
83
9
  const MediaAssetFragmentSchema = `fragment MediaAsset on ContelloAsset {
84
10
  id
@@ -243,6 +169,9 @@ ${StoreAssetFragmentSchema}`,
243
169
  models: { dummy: "DummyEntity" }
244
170
  };
245
171
  //#endregion
172
+ //#region src/telemetry.ts
173
+ const { wrap } = (0, _contello_opentelemetry.createOperationTelemetry)("@contello/store");
174
+ //#endregion
246
175
  //#region src/utils.ts
247
176
  /**
248
177
  * default `cache.ttl` applied across all store kinds. eager stores (collections, singletons)
@@ -283,7 +212,7 @@ function createRefresher(fn, onRefreshed, onStart) {
283
212
  refreshing = true;
284
213
  inFlightKind = kind;
285
214
  onStart?.();
286
- (0, _contello_client.runWithBackoff)(fn).then(() => {
215
+ (0, _entwico_dash_async.retryWithBackoff)(fn).then(() => {
287
216
  const finished = inFlightKind;
288
217
  refreshing = false;
289
218
  inFlightKind = void 0;
@@ -298,7 +227,7 @@ function createRefresher(fn, onRefreshed, onStart) {
298
227
  return scheduleRefresh;
299
228
  }
300
229
  function createRefreshChannel(onRefresh) {
301
- const stream$ = (0, _contello_client.createAsyncIterableSubject)();
230
+ const stream$ = (0, _entwico_dash_async.createAsyncIterableSubject)();
302
231
  return {
303
232
  stream$,
304
233
  emit(event) {
@@ -383,10 +312,10 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
383
312
  });
384
313
  let loaded = false;
385
314
  const assetsSourceDoc = (0, _contello_client.createSourceSubscription)(schema.sources.storeAsset);
386
- const projected$8 = new projected.ProjectedMap({
315
+ const projected = new _entwico_projected.ProjectedMap({
387
316
  key: (asset) => asset.id,
388
317
  values: (ids) => wrap("assets", async () => {
389
- const items = (await (0, _contello_client.collectAsync)((0, _contello_client.mapAsync)(client.subscribe(assetsSourceDoc, { ids }), (data) => data.source))).map((item) => mapAsset$1(item));
318
+ const items = (await (0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe(assetsSourceDoc, { ids }), (data) => data.source))).map((item) => mapAsset$1(item));
390
319
  if (ids === void 0 && !loaded) {
391
320
  loaded = true;
392
321
  ttl.mark();
@@ -402,8 +331,8 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
402
331
  });
403
332
  }
404
333
  function runFullRefresh(kind) {
405
- refreshByTtl.enqueue(() => (0, _contello_client.runWithBackoff)(async () => {
406
- emit((await projected$8.refresh()).keys().toArray(), kind);
334
+ refreshByTtl.enqueue(() => (0, _entwico_dash_async.retryWithBackoff)(async () => {
335
+ emit((await projected.refresh()).keys().toArray(), kind);
407
336
  ttl.mark();
408
337
  }));
409
338
  }
@@ -413,8 +342,8 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
413
342
  emit(changedIds, "upstream-update");
414
343
  return;
415
344
  }
416
- (0, _contello_client.runWithBackoff)(async () => {
417
- await projected$8.refresh(refreshIds);
345
+ (0, _entwico_dash_async.retryWithBackoff)(async () => {
346
+ await projected.refresh(refreshIds);
418
347
  emit(changedIds, "upstream-update");
419
348
  });
420
349
  }
@@ -425,20 +354,20 @@ function createAssetsCollection(options, client, updates$, refreshByTtl) {
425
354
  for (const event of batch.asset) if (event.mutation === "delete") deleted.push(event.id);
426
355
  else upserted.add(event.id);
427
356
  if (cache.eviction === "clear") {
428
- projected$8.clear();
357
+ projected.clear();
429
358
  return;
430
359
  }
431
- if (deleted.length > 0) projected$8.delete(deleted);
360
+ if (deleted.length > 0) projected.delete(deleted);
432
361
  runPartialRefresh([...upserted], deleted);
433
362
  });
434
363
  return {
435
364
  instance: {
436
365
  refresh$: channel.stream$,
437
366
  async load() {
438
- if (!loaded) await projected$8.getAllAsMap();
367
+ if (!loaded) await projected.getAllAsMap();
439
368
  },
440
369
  get(idOrIds) {
441
- return projected$8.get(idOrIds);
370
+ return projected.get(idOrIds);
442
371
  },
443
372
  upload(data, meta, options) {
444
373
  return client.upload(data, meta, options);
@@ -628,7 +557,7 @@ var DependencyCollector = class {
628
557
  //#endregion
629
558
  //#region src/collection.ts
630
559
  function fetchCollection(source, client, ids) {
631
- return (0, _contello_client.collectAsync)((0, _contello_client.mapAsync)(client.subscribe((0, _contello_client.createSourceSubscription)(source), { ids }), (r) => r.source));
560
+ return (0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe((0, _contello_client.createSourceSubscription)(source), { ids }), (r) => r.source));
632
561
  }
633
562
  function createCollection(source, options, client, updates$, resolver, refreshByTtl) {
634
563
  const opts = options ?? {};
@@ -648,10 +577,10 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
648
577
  run: () => runFullRefresh("ttl")
649
578
  });
650
579
  let loaded = false;
651
- const projected$7 = new projected.ProjectedMap({
580
+ const projected = new _entwico_projected.ProjectedMap({
652
581
  key: (item) => item.id,
653
- values: (ids) => wrap(`collection:${_def.name}`, () => (0, projected.maybeThen)(fetchCollection(source, client, ids), async (rawItems) => {
654
- const items = await Promise.all(rawItems.map((item) => Promise.resolve(dependencyCollector.createContext((ref, register) => (0, projected.maybeThen)(mapFn(item, ref), (mapped) => {
582
+ values: (ids) => wrap(`collection:${_def.name}`, () => (0, _entwico_dash.maybeThen)(fetchCollection(source, client, ids), async (rawItems) => {
583
+ const items = await Promise.all(rawItems.map((item) => Promise.resolve(dependencyCollector.createContext((ref, register) => (0, _entwico_dash.maybeThen)(mapFn(item, ref), (mapped) => {
655
584
  register(mapped.id);
656
585
  return mapped;
657
586
  })))));
@@ -677,8 +606,8 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
677
606
  });
678
607
  }
679
608
  function runFullRefresh(kind) {
680
- refreshByTtl.enqueue(() => (0, _contello_client.runWithBackoff)(async () => {
681
- emit((await projected$7.refresh()).keys().toArray(), kind);
609
+ refreshByTtl.enqueue(() => (0, _entwico_dash_async.retryWithBackoff)(async () => {
610
+ emit((await projected.refresh()).keys().toArray(), kind);
682
611
  ttl.mark();
683
612
  }));
684
613
  }
@@ -688,8 +617,8 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
688
617
  emit(changedIds, "upstream-update");
689
618
  return;
690
619
  }
691
- (0, _contello_client.runWithBackoff)(async () => {
692
- await projected$7.refresh(refreshIds);
620
+ (0, _entwico_dash_async.retryWithBackoff)(async () => {
621
+ await projected.refresh(refreshIds);
693
622
  emit(changedIds, "upstream-update");
694
623
  });
695
624
  }
@@ -705,11 +634,11 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
705
634
  if (deleted.length === 0 && upserted.size === 0 && depAffected.size === 0) return;
706
635
  if (_def.cache.eviction === "clear") {
707
636
  dependencyCollector.clear();
708
- projected$7.clear();
637
+ projected.clear();
709
638
  return;
710
639
  }
711
640
  for (const id of deleted) dependencyCollector.removeItem(id);
712
- if (deleted.length > 0) projected$7.delete(deleted);
641
+ if (deleted.length > 0) projected.delete(deleted);
713
642
  const refreshIds = upserted.union(depAffected);
714
643
  for (const id of deleted) refreshIds.delete(id);
715
644
  runPartialRefresh([...refreshIds], deleted);
@@ -719,16 +648,16 @@ function createCollection(source, options, client, updates$, resolver, refreshBy
719
648
  name: _def.name,
720
649
  refresh$: channel.stream$,
721
650
  get(idOrIds) {
722
- return projected$7.get(idOrIds);
651
+ return projected.get(idOrIds);
723
652
  },
724
653
  getAll() {
725
- return projected$7.getAll();
654
+ return projected.getAll();
726
655
  },
727
656
  refresh() {
728
657
  runFullRefresh("on-demand");
729
658
  },
730
659
  async load() {
731
- if (!loaded) await projected$7.getAllAsMap();
660
+ if (!loaded) await projected.getAllAsMap();
732
661
  }
733
662
  },
734
663
  destroy() {
@@ -787,10 +716,10 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
787
716
  });
788
717
  let loaded = false;
789
718
  const i18nSourceDoc = (0, _contello_client.createSourceSubscription)(schema.sources.storeI18nMessage);
790
- const projected$6 = new projected.ProjectedMap({
719
+ const projected = new _entwico_projected.ProjectedMap({
791
720
  key: (msg) => msg.id,
792
721
  values: (ids) => wrap(`i18n:${def.collection}`, async () => {
793
- const items = (await (0, _contello_client.collectAsync)((0, _contello_client.mapAsync)(client.subscribe(i18nSourceDoc, {
722
+ const items = (await (0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe(i18nSourceDoc, {
794
723
  collection: def.collection,
795
724
  ids
796
725
  }), (data) => data.source))).map((msg) => ({
@@ -812,18 +741,18 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
812
741
  });
813
742
  }
814
743
  function emitWithCurrentIds(kind) {
815
- (0, projected.maybeThen)(projected$6.getAll(), (msgs) => {
744
+ (0, _entwico_dash.maybeThen)(projected.getAll(), (msgs) => {
816
745
  emit(msgs.map((m) => m.id), kind);
817
746
  });
818
747
  }
819
748
  function runTtlRefresh() {
820
749
  refreshByTtl.enqueue(async () => {
821
- await (0, _contello_client.runWithBackoff)(() => projected$6.refresh());
750
+ await (0, _entwico_dash_async.retryWithBackoff)(() => projected.refresh());
822
751
  emitWithCurrentIds("ttl");
823
752
  ttl.mark();
824
753
  });
825
754
  }
826
- const scheduleRefresh = createRefresher(() => projected$6.refresh(), (kind) => {
755
+ const scheduleRefresh = createRefresher(() => projected.refresh(), (kind) => {
827
756
  emitWithCurrentIds(kind);
828
757
  ttl.mark();
829
758
  }, () => {});
@@ -834,8 +763,8 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
834
763
  emit(changedIds, "upstream-update");
835
764
  return;
836
765
  }
837
- (0, _contello_client.runWithBackoff)(async () => {
838
- await projected$6.refresh(upsertedIds);
766
+ (0, _entwico_dash_async.retryWithBackoff)(async () => {
767
+ await projected.refresh(upsertedIds);
839
768
  emit(changedIds, "upstream-update");
840
769
  });
841
770
  }
@@ -846,16 +775,16 @@ function createI18nMessagesCollection(def, client, updates$, refreshByTtl) {
846
775
  const upserted = /* @__PURE__ */ new Set();
847
776
  for (const event of batch.i18nMessage) if (event.mutation === "delete") deleted.push(event.id);
848
777
  else upserted.add(event.id);
849
- if (deleted.length > 0) projected$6.delete(deleted);
778
+ if (deleted.length > 0) projected.delete(deleted);
850
779
  runPartialRefresh([...upserted], deleted);
851
780
  });
852
781
  return {
853
782
  refresh$: channel.stream$,
854
783
  get(idOrIds) {
855
- return projected$6.get(idOrIds);
784
+ return projected.get(idOrIds);
856
785
  },
857
786
  getAll() {
858
- return projected$6.getAll();
787
+ return projected.getAll();
859
788
  },
860
789
  register(messages) {
861
790
  return wrap(`i18n-register:${def.collection}`, async () => {
@@ -933,10 +862,10 @@ function createLazyAssetsCollection(def, client, updates$) {
933
862
  onEvict: void 0
934
863
  });
935
864
  const assetsSourceDoc = (0, _contello_client.createSourceSubscription)(schema.sources.storeAsset);
936
- const projected$5 = new projected.ProjectedLazyMap({
865
+ const projected = new _entwico_projected.ProjectedLazyMap({
937
866
  key: (asset) => asset.id,
938
867
  values: (ids) => wrap("assets", async () => {
939
- return (await (0, _contello_client.collectAsync)((0, _contello_client.mapAsync)(client.subscribe(assetsSourceDoc, { ids }), (data) => data.source))).map((item) => mapAsset(item));
868
+ return (await (0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe(assetsSourceDoc, { ids }), (data) => data.source))).map((item) => mapAsset(item));
940
869
  }),
941
870
  cache
942
871
  });
@@ -951,20 +880,20 @@ function createLazyAssetsCollection(def, client, updates$) {
951
880
  const scheduleRefresh = createRefresher(async () => {
952
881
  lastRefreshKeys = cache.keys();
953
882
  if (lastRefreshKeys.length === 0) return;
954
- await projected$5.refresh(lastRefreshKeys);
883
+ await projected.refresh(lastRefreshKeys);
955
884
  }, (kind) => {
956
885
  if (lastRefreshKeys.length > 0) emit(lastRefreshKeys, kind);
957
886
  }, () => {});
958
887
  const unsubUpdates = updates$.subscribe((batch) => {
959
888
  if (batch.asset.length === 0) return;
960
- for (const event of batch.asset) projected$5.delete(event.id);
889
+ for (const event of batch.asset) projected.delete(event.id);
961
890
  emit(batch.asset.map((e) => e.id), "upstream-update");
962
891
  });
963
892
  return {
964
893
  instance: {
965
894
  refresh$: channel.stream$,
966
895
  get(idOrIds) {
967
- return projected$5.get(idOrIds);
896
+ return projected.get(idOrIds);
968
897
  },
969
898
  upload(data, meta, options) {
970
899
  return client.upload(data, meta, options);
@@ -979,7 +908,7 @@ function createLazyAssetsCollection(def, client, updates$) {
979
908
  scheduleRefresh("on-demand");
980
909
  },
981
910
  clear() {
982
- projected$5.clear();
911
+ projected.clear();
983
912
  }
984
913
  },
985
914
  destroy() {
@@ -1007,15 +936,15 @@ function createLazyCollection(source, options, client, updates$, resolver) {
1007
936
  ttl: _def.cache.ttl,
1008
937
  onEvict: (_value, key) => dependencyCollector.removeItem(key)
1009
938
  });
1010
- const projected$4 = new projected.ProjectedLazyMap({
939
+ const projected = new _entwico_projected.ProjectedLazyMap({
1011
940
  key: (item) => item.id,
1012
- values: (keys) => wrap(`lazy-collection:${_def.name}`, () => (0, projected.maybeThen)((0, _contello_client.collectAsync)((0, _contello_client.mapAsync)(client.subscribe((0, _contello_client.createSourceSubscription)(source), { ids: keys }), (r) => r.source)), (rawItems) => Promise.all(rawItems.map((item) => Promise.resolve(dependencyCollector.createContext((ref, register) => (0, projected.maybeThen)(mapFn(item, ref), (mapped) => {
941
+ values: (keys) => wrap(`lazy-collection:${_def.name}`, () => (0, _entwico_dash.maybeThen)((0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe((0, _contello_client.createSourceSubscription)(source), { ids: keys }), (r) => r.source)), (rawItems) => Promise.all(rawItems.map((item) => Promise.resolve(dependencyCollector.createContext((ref, register) => (0, _entwico_dash.maybeThen)(mapFn(item, ref), (mapped) => {
1013
942
  register(mapped.id);
1014
943
  return mapped;
1015
944
  }))))))),
1016
945
  cache
1017
946
  });
1018
- const refresh$ = (0, _contello_client.createAsyncIterableSubject)();
947
+ const refresh$ = (0, _entwico_dash_async.createAsyncIterableSubject)();
1019
948
  function emit(ids, kind) {
1020
949
  const event = {
1021
950
  ids,
@@ -1028,7 +957,7 @@ function createLazyCollection(source, options, client, updates$, resolver) {
1028
957
  const scheduleRefresh = createRefresher(async () => {
1029
958
  lastRefreshKeys = cache.keys();
1030
959
  if (lastRefreshKeys.length === 0) return;
1031
- await projected$4.refresh(lastRefreshKeys);
960
+ await projected.refresh(lastRefreshKeys);
1032
961
  }, (kind) => {
1033
962
  if (lastRefreshKeys.length > 0) emit(lastRefreshKeys, kind);
1034
963
  }, () => {});
@@ -1040,7 +969,7 @@ function createLazyCollection(source, options, client, updates$, resolver) {
1040
969
  if (evicted.size > 0) {
1041
970
  for (const key of evicted) {
1042
971
  dependencyCollector.removeItem(key);
1043
- projected$4.delete(key);
972
+ projected.delete(key);
1044
973
  }
1045
974
  emit([...evicted], "upstream-update");
1046
975
  }
@@ -1050,14 +979,14 @@ function createLazyCollection(source, options, client, updates$, resolver) {
1050
979
  name: _def.name,
1051
980
  refresh$,
1052
981
  get(idOrIds) {
1053
- return projected$4.get(idOrIds);
982
+ return projected.get(idOrIds);
1054
983
  },
1055
984
  refresh() {
1056
985
  scheduleRefresh("on-demand");
1057
986
  },
1058
987
  clear() {
1059
988
  dependencyCollector.clear();
1060
- projected$4.clear();
989
+ projected.clear();
1061
990
  }
1062
991
  },
1063
992
  destroy() {
@@ -1188,9 +1117,9 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
1188
1117
  const cache = createRoutesCache(_def.cache.max, _def.cache.ttl);
1189
1118
  const routesSourceDoc = (0, _contello_client.createSourceSubscription)(schema.sources.storeRoute);
1190
1119
  function fetchRoutes(vars) {
1191
- return (0, _contello_client.collectAsync)((0, _contello_client.mapAsync)(client.subscribe(routesSourceDoc, vars), (data) => data.source));
1120
+ return (0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe(routesSourceDoc, vars), (data) => data.source));
1192
1121
  }
1193
- const projected$3 = new projected.ProjectedLazyMap({
1122
+ const projected = new _entwico_projected.ProjectedLazyMap({
1194
1123
  key: (route) => route[CACHE_KEY] ?? ID_PREFIX + route.id,
1195
1124
  values: (prefixedKeys) => wrap("routes", async () => {
1196
1125
  const ids = [];
@@ -1218,7 +1147,7 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
1218
1147
  const scheduleRefresh = createRefresher(async () => {
1219
1148
  lastRefreshKeys = cache.keys();
1220
1149
  if (lastRefreshKeys.length === 0) return;
1221
- await projected$3.refresh(lastRefreshKeys);
1150
+ await projected.refresh(lastRefreshKeys);
1222
1151
  }, (kind) => {
1223
1152
  if (lastRefreshKeys.length > 0) emit(lastRefreshKeys.map((key) => key.slice(2)), kind);
1224
1153
  }, () => {});
@@ -1240,18 +1169,18 @@ function createLazyRoutesCollection(def, client, updates$, resolver) {
1240
1169
  instance: {
1241
1170
  refresh$: channel.stream$,
1242
1171
  get(idOrIds) {
1243
- if (Array.isArray(idOrIds)) return projected$3.get(idOrIds.map((id) => ID_PREFIX + id));
1244
- return projected$3.get(ID_PREFIX + idOrIds);
1172
+ if (Array.isArray(idOrIds)) return projected.get(idOrIds.map((id) => ID_PREFIX + id));
1173
+ return projected.get(ID_PREFIX + idOrIds);
1245
1174
  },
1246
1175
  getByPath(pathOrPaths) {
1247
- if (Array.isArray(pathOrPaths)) return projected$3.get(pathOrPaths.map((p) => PATH_PREFIX + p));
1248
- return projected$3.get(PATH_PREFIX + pathOrPaths);
1176
+ if (Array.isArray(pathOrPaths)) return projected.get(pathOrPaths.map((p) => PATH_PREFIX + p));
1177
+ return projected.get(PATH_PREFIX + pathOrPaths);
1249
1178
  },
1250
1179
  refresh() {
1251
1180
  scheduleRefresh("on-demand");
1252
1181
  },
1253
1182
  clear() {
1254
- projected$3.clear();
1183
+ projected.clear();
1255
1184
  }
1256
1185
  },
1257
1186
  destroy() {
@@ -1315,10 +1244,10 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
1315
1244
  const idByPath = /* @__PURE__ */ new Map();
1316
1245
  let loaded = false;
1317
1246
  const routesSourceDoc = (0, _contello_client.createSourceSubscription)(schema.sources.storeRoute);
1318
- const projected$2 = new projected.ProjectedMap({
1247
+ const projected = new _entwico_projected.ProjectedMap({
1319
1248
  key: (route) => route.id,
1320
1249
  values: (ids) => wrap("routes", async () => {
1321
- const items = (await (0, _contello_client.collectAsync)((0, _contello_client.mapAsync)(client.subscribe(routesSourceDoc, { ids }), (data) => data.source))).reduce((acc, raw) => {
1250
+ const items = (await (0, _entwico_dash_async.concatAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe(routesSourceDoc, { ids }), (data) => data.source))).reduce((acc, raw) => {
1322
1251
  const mapped = mapRoute(raw, resolver);
1323
1252
  if (mapped) acc.push(mapped);
1324
1253
  return acc;
@@ -1362,8 +1291,8 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
1362
1291
  });
1363
1292
  }
1364
1293
  function runFullRefresh(kind) {
1365
- refreshByTtl.enqueue(() => (0, _contello_client.runWithBackoff)(async () => {
1366
- emit((await projected$2.refresh()).keys().toArray(), kind);
1294
+ refreshByTtl.enqueue(() => (0, _entwico_dash_async.retryWithBackoff)(async () => {
1295
+ emit((await projected.refresh()).keys().toArray(), kind);
1367
1296
  ttl.mark();
1368
1297
  }));
1369
1298
  }
@@ -1373,8 +1302,8 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
1373
1302
  emit(changedIds, "upstream-update");
1374
1303
  return;
1375
1304
  }
1376
- (0, _contello_client.runWithBackoff)(async () => {
1377
- await projected$2.refresh(refreshIds);
1305
+ (0, _entwico_dash_async.retryWithBackoff)(async () => {
1306
+ await projected.refresh(refreshIds);
1378
1307
  emit(changedIds, "upstream-update");
1379
1308
  });
1380
1309
  }
@@ -1387,7 +1316,7 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
1387
1316
  if (cache.eviction === "clear") {
1388
1317
  pathById.clear();
1389
1318
  idByPath.clear();
1390
- projected$2.clear();
1319
+ projected.clear();
1391
1320
  return;
1392
1321
  }
1393
1322
  for (const id of deleted) {
@@ -1397,40 +1326,40 @@ function createRoutesCollection(options, client, updates$, resolver, refreshByTt
1397
1326
  pathById.delete(id);
1398
1327
  }
1399
1328
  }
1400
- if (deleted.length > 0) projected$2.delete(deleted);
1329
+ if (deleted.length > 0) projected.delete(deleted);
1401
1330
  runPartialRefresh([...upserted], deleted);
1402
1331
  });
1403
1332
  function getByIdSingle(id) {
1404
- return projected$2.get(id);
1333
+ return projected.get(id);
1405
1334
  }
1406
1335
  function getByIds(ids) {
1407
- return projected$2.get(ids);
1336
+ return projected.get(ids);
1408
1337
  }
1409
1338
  function lookupByPathSingle(path) {
1410
- return (0, projected.maybeThen)(ensureLoaded(), () => {
1339
+ return (0, _entwico_dash.maybeThen)(ensureLoaded(), () => {
1411
1340
  const id = idByPath.get(path);
1412
- return id === void 0 ? void 0 : projected$2.get(id);
1341
+ return id === void 0 ? void 0 : projected.get(id);
1413
1342
  });
1414
1343
  }
1415
1344
  function lookupByPaths(paths) {
1416
- return (0, projected.maybeThen)(ensureLoaded(), () => {
1345
+ return (0, _entwico_dash.maybeThen)(ensureLoaded(), () => {
1417
1346
  const ids = [];
1418
1347
  for (const p of paths) {
1419
1348
  const id = idByPath.get(p);
1420
1349
  if (id !== void 0) ids.push(id);
1421
1350
  }
1422
- return projected$2.get(ids);
1351
+ return projected.get(ids);
1423
1352
  });
1424
1353
  }
1425
1354
  function ensureLoaded() {
1426
1355
  if (loaded) return;
1427
- return (0, projected.maybeThen)(projected$2.getAllAsMap(), () => {});
1356
+ return (0, _entwico_dash.maybeThen)(projected.getAllAsMap(), () => {});
1428
1357
  }
1429
1358
  return {
1430
1359
  instance: {
1431
1360
  refresh$: channel.stream$,
1432
1361
  async load() {
1433
- if (!loaded) await projected$2.getAllAsMap();
1362
+ if (!loaded) await projected.getAllAsMap();
1434
1363
  },
1435
1364
  get(idOrIds) {
1436
1365
  return typeof idOrIds === "string" ? getByIdSingle(idOrIds) : getByIds(idOrIds);
@@ -1489,7 +1418,7 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
1489
1418
  run: () => runTtlRefresh()
1490
1419
  });
1491
1420
  let loaded = false;
1492
- const projected$1 = new projected.ProjectedValue({ value: () => wrap(`singleton:${_def.name}`, () => (0, projected.maybeThen)((0, _contello_client.firstAsync)((0, _contello_client.mapAsync)(client.subscribe((0, _contello_client.createSourceSubscription)(source)), (r) => r.source)), (raw) => dependencyCollector.createContext((ref, register) => (0, projected.maybeThen)(mapFn(raw, ref), (mapped) => {
1421
+ const projected = new _entwico_projected.ProjectedValue({ value: () => wrap(`singleton:${_def.name}`, () => (0, _entwico_dash.maybeThen)((0, _entwico_dash_async.firstAsync)((0, _entwico_dash_async.mapAsync)(client.subscribe((0, _contello_client.createSourceSubscription)(source)), (r) => r.source)), (raw) => dependencyCollector.createContext((ref, register) => (0, _entwico_dash.maybeThen)(mapFn(raw, ref), (mapped) => {
1493
1422
  register(itemKey);
1494
1423
  if (!loaded) {
1495
1424
  loaded = true;
@@ -1503,12 +1432,12 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
1503
1432
  }
1504
1433
  function runTtlRefresh() {
1505
1434
  refreshByTtl.enqueue(async () => {
1506
- await (0, _contello_client.runWithBackoff)(() => projected$1.refresh());
1435
+ await (0, _entwico_dash_async.retryWithBackoff)(() => projected.refresh());
1507
1436
  emit("ttl");
1508
1437
  ttl.mark();
1509
1438
  });
1510
1439
  }
1511
- const scheduleRefresh = createRefresher(() => projected$1.refresh(), (kind) => {
1440
+ const scheduleRefresh = createRefresher(() => projected.refresh(), (kind) => {
1512
1441
  emit(kind);
1513
1442
  ttl.mark();
1514
1443
  }, () => {});
@@ -1519,7 +1448,7 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
1519
1448
  if (!hasOwnModel && !hasAffectedRefs) return;
1520
1449
  if (_def.cache.eviction === "clear") {
1521
1450
  dependencyCollector.clear();
1522
- projected$1.clear();
1451
+ projected.clear();
1523
1452
  return;
1524
1453
  }
1525
1454
  scheduleRefresh("upstream-update");
@@ -1529,13 +1458,13 @@ function createSingleton(source, options, client, updates$, resolver, refreshByT
1529
1458
  name: _def.name,
1530
1459
  refresh$: channel.stream$,
1531
1460
  get() {
1532
- return projected$1.get();
1461
+ return projected.get();
1533
1462
  },
1534
1463
  refresh() {
1535
1464
  scheduleRefresh("on-demand");
1536
1465
  },
1537
1466
  async load() {
1538
- if (!loaded) await projected$1.get();
1467
+ if (!loaded) await projected.get();
1539
1468
  }
1540
1469
  },
1541
1470
  destroy() {
@@ -1676,7 +1605,7 @@ function safeMapEvent(raw, resolver) {
1676
1605
  }
1677
1606
  }
1678
1607
  function createInternalWatcher(client, resolver) {
1679
- const updates$ = (0, _contello_client.createAsyncIterableSubject)();
1608
+ const updates$ = (0, _entwico_dash_async.createAsyncIterableSubject)();
1680
1609
  let controller;
1681
1610
  return {
1682
1611
  updates$,
@@ -1686,7 +1615,7 @@ function createInternalWatcher(client, resolver) {
1686
1615
  const signal = controller.signal;
1687
1616
  wrap("watcher:start", () => {
1688
1617
  (async () => {
1689
- const events = (0, _contello_client.mapAsync)((0, _contello_client.asyncKeepalive)(() => client.subscribe(storeWatchUpdatesDocument), signal), (data) => (data.contelloUpdatesBatch?.events ?? []).map((e) => safeMapEvent(e, resolver)).filter((e) => e !== void 0));
1618
+ const events = (0, _entwico_dash_async.mapAsync)((0, _entwico_dash_async.keepalive)(() => client.subscribe(storeWatchUpdatesDocument), { signal }), (data) => (data.contelloUpdatesBatch?.events ?? []).map((e) => safeMapEvent(e, resolver)).filter((e) => e !== void 0));
1690
1619
  for await (const list of events) {
1691
1620
  if (signal.aborted) return;
1692
1621
  if (list.length === 0) continue;
@@ -1829,12 +1758,12 @@ exports.createStore = createStore;
1829
1758
  Object.defineProperty(exports, "maybeCatch", {
1830
1759
  enumerable: true,
1831
1760
  get: function() {
1832
- return projected.maybeCatch;
1761
+ return _entwico_dash.maybeCatch;
1833
1762
  }
1834
1763
  });
1835
1764
  Object.defineProperty(exports, "maybeThen", {
1836
1765
  enumerable: true,
1837
1766
  get: function() {
1838
- return projected.maybeThen;
1767
+ return _entwico_dash.maybeThen;
1839
1768
  }
1840
1769
  });
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ConnectionEvents, ContelloClient, DownloadResult, ProxyResult, Schema, SourceCardinality, SourceDef, UploadData, UploadMetadata, UploadOptions } from "@contello/client";
2
- import { MaybePromise, MaybePromise as MaybePromise$1, ReadonlyDeep, ReadonlyDeep as ReadonlyDeep$1, maybeCatch, maybeThen } from "projected";
3
-
2
+ import { MaybePromise, MaybePromise as MaybePromise$1, ReadonlyDeep, ReadonlyDeep as ReadonlyDeep$1, maybeCatch, maybeThen } from "@entwico/dash";
4
3
  //#region src/routes-mapping.d.ts
5
4
  type StoreRouteCustomHeader = {
6
5
  name: string;