@plyaz/core 1.0.4 → 1.1.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { CACHE_MAX_SIZE_DEFAULT, CACHE_CLEANUP_INTERVAL_DEFAULT, TIME_CONSTANTS, FORMAT_CONSTANTS, FILE_CHECK_INTERVAL_DEFAULT, FEATURE_FLAG_FILE_PATHS, FEATURE_FLAG_CACHE_TTL_DEFAULT, MATH_CONSTANTS, ISO_STANDARDS, FEATURES } from '@plyaz/config';
1
+ import { CACHE_MAX_SIZE_DEFAULT, CACHE_CLEANUP_INTERVAL_DEFAULT, TIME_CONSTANTS, FORMAT_CONSTANTS, FILE_CHECK_INTERVAL_DEFAULT, FEATURE_FLAG_FILE_PATHS, FEATURE_FLAG_CACHE_TTL_DEFAULT, MATH_CONSTANTS, ISO_STANDARDS, FEATURES, FNV_CONSTANTS, HASH_SEED_CONSTANTS } from '@plyaz/config';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
  import { promisify } from 'util';
@@ -24,14 +24,13 @@ var __decorateClass = (decorators, target, key, kind) => {
24
24
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
25
25
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
26
26
  function hashString(str) {
27
- const HASH_SHIFT = 5;
28
- let hash = 0;
27
+ if (str.length === 0) return 0;
28
+ let hash = FNV_CONSTANTS.FNV_32_OFFSET;
29
29
  for (let i = 0; i < str.length; i++) {
30
- const char = str.charCodeAt(i);
31
- hash = (hash << HASH_SHIFT) - hash + char;
32
- hash = hash & hash;
30
+ hash ^= str.charCodeAt(i);
31
+ hash = Math.imul(hash, FNV_CONSTANTS.FNV_32_PRIME) >>> 0;
33
32
  }
34
- return Math.abs(hash);
33
+ return hash >>> 0;
35
34
  }
36
35
  __name(hashString, "hashString");
37
36
  function isInRollout(identifier, percentage) {
@@ -73,13 +72,14 @@ var HashUtils = {
73
72
  }, "isInBucketRange"),
74
73
  /**
75
74
  * Creates a deterministic random seed from a string.
75
+ * Uses the improved hash function and ensures the seed is within
76
+ * the safe range for JavaScript's Math.random seeding.
76
77
  *
77
78
  * @param str - String to convert to seed
78
- * @returns Deterministic seed value
79
+ * @returns Deterministic seed value (0 to 2^31-1)
79
80
  */
80
81
  createSeed: /* @__PURE__ */ __name((str) => {
81
- const SAFE_INT = 2147483647;
82
- return hashString(str) % SAFE_INT;
82
+ return hashString(str) % HASH_SEED_CONSTANTS.MAX_SAFE_SEED;
83
83
  }, "createSeed")
84
84
  };
85
85
  function isStringFalsy(value) {
@@ -1107,6 +1107,9 @@ var MemoryCacheStrategy = class {
1107
1107
  this.cleanupTimer = setInterval(() => {
1108
1108
  this.cleanupExpiredEntries();
1109
1109
  }, this.cleanupInterval);
1110
+ if (this.cleanupTimer && typeof this.cleanupTimer.unref === "function") {
1111
+ this.cleanupTimer.unref();
1112
+ }
1110
1113
  }
1111
1114
  /**
1112
1115
  * Removes expired entries from the cache.
@@ -3980,7 +3983,7 @@ function useFeatureFlagProviderStatus() {
3980
3983
  isInitialized: context.isInitialized,
3981
3984
  isLoading: context.isLoading,
3982
3985
  error: context.error,
3983
- lastUpdated: context.lastUpdated
3986
+ lastUpdated: context.lastUpdated ? new Date(context.lastUpdated) : void 0
3984
3987
  };
3985
3988
  }
3986
3989
  __name(useFeatureFlagProviderStatus, "useFeatureFlagProviderStatus");