@adviser/cement 0.3.16 → 0.3.18

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 (62) hide show
  1. package/cf/index.cjs +102 -4
  2. package/cf/index.cjs.map +1 -1
  3. package/cf/index.js +2 -2
  4. package/{chunk-Z3IR6QEZ.js → chunk-ERFPFVXB.js} +2 -2
  5. package/{chunk-H3CAVBMO.js → chunk-NYHENJUJ.js} +136 -7
  6. package/chunk-NYHENJUJ.js.map +1 -0
  7. package/{chunk-WGRZHIFK.js → chunk-RQKI6UPM.js} +3 -3
  8. package/deno/index.cjs +102 -4
  9. package/deno/index.cjs.map +1 -1
  10. package/deno/index.js +1 -1
  11. package/index.cjs +137 -59
  12. package/index.cjs.map +1 -1
  13. package/index.d.cts +41 -20
  14. package/index.d.ts +41 -20
  15. package/index.js +7 -55
  16. package/index.js.map +1 -1
  17. package/metafile-cjs.json +1 -1
  18. package/metafile-esm.json +1 -1
  19. package/node/index.cjs +102 -4
  20. package/node/index.cjs.map +1 -1
  21. package/node/index.js +1 -1
  22. package/package.json +1 -1
  23. package/src/index.ts +1 -1
  24. package/src/jsr.json +1 -1
  25. package/src/lru-map-set.ts +153 -0
  26. package/src/resolve-once.ts +16 -6
  27. package/test/index.cjs +102 -4
  28. package/test/index.cjs.map +1 -1
  29. package/test/index.js +3 -3
  30. package/ts/src/index.d.ts +1 -1
  31. package/ts/src/index.d.ts.map +1 -1
  32. package/ts/src/index.js +1 -1
  33. package/ts/src/index.js.map +1 -1
  34. package/ts/src/lru-map-set.d.ts +32 -0
  35. package/ts/src/lru-map-set.d.ts.map +1 -0
  36. package/ts/src/lru-map-set.js +114 -0
  37. package/ts/src/lru-map-set.js.map +1 -0
  38. package/ts/src/lru-map-set.test.d.ts +2 -0
  39. package/ts/src/lru-map-set.test.d.ts.map +1 -0
  40. package/ts/src/lru-map-set.test.js +81 -0
  41. package/ts/src/lru-map-set.test.js.map +1 -0
  42. package/ts/src/resolve-once.d.ts +9 -4
  43. package/ts/src/resolve-once.d.ts.map +1 -1
  44. package/ts/src/resolve-once.js +11 -6
  45. package/ts/src/resolve-once.js.map +1 -1
  46. package/ts/src/resolve-once.test.js +10 -0
  47. package/ts/src/resolve-once.test.js.map +1 -1
  48. package/web/index.cjs +102 -4
  49. package/web/index.cjs.map +1 -1
  50. package/web/index.js +2 -2
  51. package/chunk-H3CAVBMO.js.map +0 -1
  52. package/src/lru-cache.ts +0 -68
  53. package/ts/src/lru-cache.d.ts +0 -15
  54. package/ts/src/lru-cache.d.ts.map +0 -1
  55. package/ts/src/lru-cache.js +0 -46
  56. package/ts/src/lru-cache.js.map +0 -1
  57. package/ts/src/lru-cache.test.d.ts +0 -2
  58. package/ts/src/lru-cache.test.d.ts.map +0 -1
  59. package/ts/src/lru-cache.test.js +0 -54
  60. package/ts/src/lru-cache.test.js.map +0 -1
  61. /package/{chunk-Z3IR6QEZ.js.map → chunk-ERFPFVXB.js.map} +0 -0
  62. /package/{chunk-WGRZHIFK.js.map → chunk-RQKI6UPM.js.map} +0 -0
package/test/index.cjs CHANGED
@@ -865,6 +865,100 @@ var WrapperSysAbstraction = class {
865
865
  }
866
866
  };
867
867
 
868
+ // src/lru-map-set.ts
869
+ var LRUMap = class {
870
+ constructor(c = {}) {
871
+ this._map = /* @__PURE__ */ new Map();
872
+ this.param = {
873
+ maxEntries: c.maxEntries || 100,
874
+ maxAge: c.maxAge || 0
875
+ };
876
+ }
877
+ touch(key) {
878
+ if (!this._map.has(key)) {
879
+ throw new Error(`key not found in cache: ${key}`);
880
+ }
881
+ const value = this._map.get(key);
882
+ this._map.delete(key);
883
+ this._map.set(key, value);
884
+ return value;
885
+ }
886
+ setParam(param2 = {}) {
887
+ if (typeof param2.maxEntries === "number") {
888
+ this.param.maxEntries = param2.maxEntries;
889
+ if (param2.maxEntries > 0 && this._map.size > param2.maxEntries) {
890
+ const toDelete = [];
891
+ let cacheSize = this._map.size;
892
+ for (const key of this._map.keys()) {
893
+ if (cacheSize > param2.maxEntries) {
894
+ toDelete.push(key);
895
+ cacheSize--;
896
+ } else {
897
+ break;
898
+ }
899
+ }
900
+ for (const key of toDelete) {
901
+ this._map.delete(key);
902
+ }
903
+ }
904
+ }
905
+ }
906
+ has(key) {
907
+ return this._map.has(key);
908
+ }
909
+ get size() {
910
+ return this._map.size;
911
+ }
912
+ async getSet(key, createFN) {
913
+ const val = this.get(key);
914
+ if (val) {
915
+ return val;
916
+ } else {
917
+ const val2 = await createFN(key);
918
+ this.set(key, val2);
919
+ return val2;
920
+ }
921
+ }
922
+ get(key) {
923
+ if (this._map.has(key)) {
924
+ return this.touch(key);
925
+ }
926
+ return this._map.get(key);
927
+ }
928
+ set(key, value) {
929
+ this._map.delete(key);
930
+ if (this.param.maxEntries > 0 && this._map.size >= this.param.maxEntries) {
931
+ this._map.delete(this._map.keys().next().value);
932
+ this._map.set(key, value);
933
+ } else {
934
+ this._map.set(key, value);
935
+ }
936
+ }
937
+ delete(key) {
938
+ this._map.delete(key);
939
+ }
940
+ clear() {
941
+ this._map.clear();
942
+ }
943
+ forEach(callbackfn) {
944
+ this._map.forEach(callbackfn);
945
+ }
946
+ entries() {
947
+ return this._map.entries();
948
+ }
949
+ // *entries(): IterableIterator<[T, K]> {
950
+ // for (const x of this._cache.entries()) {
951
+ // yield x;
952
+ // }
953
+ // }
954
+ // getLeastRecent(): K {
955
+ // return Array.from(this.cache)[0];
956
+ // }
957
+ // getMostRecent(): K {
958
+ // return Array.from(this.cache)[this.cache.size - 1];
959
+ // }
960
+ };
961
+
868
962
  // src/resolve-once.ts
869
963
  var ResolveOnce = class {
870
964
  constructor(ctx) {
@@ -958,9 +1052,13 @@ var ResolveOnce = class {
958
1052
  }
959
1053
  };
960
1054
  var Keyed = class {
961
- constructor(factory) {
962
- this._map = /* @__PURE__ */ new Map();
1055
+ constructor(factory, params) {
1056
+ var _a;
963
1057
  this.factory = factory;
1058
+ this._map = new LRUMap((_a = params == null ? void 0 : params.lru) != null ? _a : { maxEntries: -1 });
1059
+ }
1060
+ setParam(params) {
1061
+ this._map.setParam(params.lru);
964
1062
  }
965
1063
  async asyncGet(key) {
966
1064
  return this.get(await key());
@@ -987,8 +1085,8 @@ var Keyed = class {
987
1085
  }
988
1086
  };
989
1087
  var KeyedResolvOnce = class extends Keyed {
990
- constructor() {
991
- super((key) => new ResolveOnce(key));
1088
+ constructor(kp = {}) {
1089
+ super((key) => new ResolveOnce(key), kp);
992
1090
  }
993
1091
  /**
994
1092
  *