@adviser/cement 0.3.16 → 0.3.17

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 (46) hide show
  1. package/cf/index.cjs +99 -4
  2. package/cf/index.cjs.map +1 -1
  3. package/cf/index.js +2 -2
  4. package/{chunk-Z3IR6QEZ.js → chunk-JELISEAH.js} +2 -2
  5. package/{chunk-H3CAVBMO.js → chunk-ZWI2F6RL.js} +103 -7
  6. package/chunk-ZWI2F6RL.js.map +1 -0
  7. package/{chunk-WGRZHIFK.js → chunk-ZYKVQZJH.js} +3 -3
  8. package/deno/index.cjs +99 -4
  9. package/deno/index.cjs.map +1 -1
  10. package/deno/index.js +1 -1
  11. package/index.cjs +101 -57
  12. package/index.cjs.map +1 -1
  13. package/index.d.cts +29 -20
  14. package/index.d.ts +29 -20
  15. package/index.js +4 -54
  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 +99 -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/jsr.json +1 -1
  24. package/src/lru-cache.ts +59 -15
  25. package/src/resolve-once.ts +16 -6
  26. package/test/index.cjs +99 -4
  27. package/test/index.cjs.map +1 -1
  28. package/test/index.js +3 -3
  29. package/ts/src/lru-cache.d.ts +7 -2
  30. package/ts/src/lru-cache.d.ts.map +1 -1
  31. package/ts/src/lru-cache.js +50 -14
  32. package/ts/src/lru-cache.js.map +1 -1
  33. package/ts/src/lru-cache.test.js +35 -8
  34. package/ts/src/lru-cache.test.js.map +1 -1
  35. package/ts/src/resolve-once.d.ts +9 -4
  36. package/ts/src/resolve-once.d.ts.map +1 -1
  37. package/ts/src/resolve-once.js +11 -6
  38. package/ts/src/resolve-once.js.map +1 -1
  39. package/ts/src/resolve-once.test.js +10 -0
  40. package/ts/src/resolve-once.test.js.map +1 -1
  41. package/web/index.cjs +99 -4
  42. package/web/index.cjs.map +1 -1
  43. package/web/index.js +2 -2
  44. package/chunk-H3CAVBMO.js.map +0 -1
  45. /package/{chunk-Z3IR6QEZ.js.map → chunk-JELISEAH.js.map} +0 -0
  46. /package/{chunk-WGRZHIFK.js.map → chunk-ZYKVQZJH.js.map} +0 -0
package/test/index.cjs CHANGED
@@ -865,6 +865,97 @@ var WrapperSysAbstraction = class {
865
865
  }
866
866
  };
867
867
 
868
+ // src/lru-cache.ts
869
+ var LRUCache = class {
870
+ constructor(c = {}) {
871
+ this._cache = /* @__PURE__ */ new Map();
872
+ this.param = {
873
+ maxEntries: c.maxEntries || 100,
874
+ maxAge: c.maxAge || 0
875
+ };
876
+ }
877
+ touch(key) {
878
+ if (!this._cache.has(key)) {
879
+ throw new Error(`key not found in cache: ${key}`);
880
+ }
881
+ const value = this._cache.get(key);
882
+ this._cache.delete(key);
883
+ this._cache.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._cache.size > param2.maxEntries) {
890
+ const toDelete = [];
891
+ let cacheSize = this._cache.size;
892
+ for (const key of this._cache.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._cache.delete(key);
902
+ }
903
+ }
904
+ }
905
+ }
906
+ get size() {
907
+ return this._cache.size;
908
+ }
909
+ async getPut(key, createFN) {
910
+ const val = this.get(key);
911
+ if (val) {
912
+ return val;
913
+ } else {
914
+ const val2 = await createFN(key);
915
+ this.set(key, val2);
916
+ return val2;
917
+ }
918
+ }
919
+ get(key) {
920
+ if (this._cache.has(key)) {
921
+ return this.touch(key);
922
+ }
923
+ return this._cache.get(key);
924
+ }
925
+ set(key, value) {
926
+ this._cache.delete(key);
927
+ if (this.param.maxEntries > 0 && this._cache.size >= this.param.maxEntries) {
928
+ this._cache.delete(this._cache.keys().next().value);
929
+ this._cache.set(key, value);
930
+ } else {
931
+ this._cache.set(key, value);
932
+ }
933
+ }
934
+ delete(key) {
935
+ this._cache.delete(key);
936
+ }
937
+ clear() {
938
+ this._cache.clear();
939
+ }
940
+ forEach(callbackfn) {
941
+ this._cache.forEach(callbackfn);
942
+ }
943
+ entries() {
944
+ return this._cache.entries();
945
+ }
946
+ // *entries(): IterableIterator<[T, K]> {
947
+ // for (const x of this._cache.entries()) {
948
+ // yield x;
949
+ // }
950
+ // }
951
+ // getLeastRecent(): K {
952
+ // return Array.from(this.cache)[0];
953
+ // }
954
+ // getMostRecent(): K {
955
+ // return Array.from(this.cache)[this.cache.size - 1];
956
+ // }
957
+ };
958
+
868
959
  // src/resolve-once.ts
869
960
  var ResolveOnce = class {
870
961
  constructor(ctx) {
@@ -958,9 +1049,13 @@ var ResolveOnce = class {
958
1049
  }
959
1050
  };
960
1051
  var Keyed = class {
961
- constructor(factory) {
962
- this._map = /* @__PURE__ */ new Map();
1052
+ constructor(factory, params) {
1053
+ var _a;
963
1054
  this.factory = factory;
1055
+ this._map = new LRUCache((_a = params == null ? void 0 : params.lru) != null ? _a : { maxEntries: -1 });
1056
+ }
1057
+ setParam(params) {
1058
+ this._map.setParam(params.lru);
964
1059
  }
965
1060
  async asyncGet(key) {
966
1061
  return this.get(await key());
@@ -987,8 +1082,8 @@ var Keyed = class {
987
1082
  }
988
1083
  };
989
1084
  var KeyedResolvOnce = class extends Keyed {
990
- constructor() {
991
- super((key) => new ResolveOnce(key));
1085
+ constructor(kp = {}) {
1086
+ super((key) => new ResolveOnce(key), kp);
992
1087
  }
993
1088
  /**
994
1089
  *