@cdlab996/genid 1.0.0 → 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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @cdlab996/genid
2
2
 
3
- 一个基于 Snowflake 算法的高性能分布式唯一 ID 生成器。
3
+ 基于 Snowflake 算法的高性能分布式唯一 ID 生成器,支持漂移算法和时钟回拨处理,适用于分布式系统中的唯一标识生成需求。
4
4
 
5
5
  ## 特性
6
6
 
@@ -47,12 +47,6 @@ graph TB
47
47
 
48
48
  Q --> R[更新统计]
49
49
  R --> S[返回 ID]
50
-
51
- style B fill:#fff4e6
52
- style E fill:#e8f5e9
53
- style K fill:#fce4ec
54
- style Q fill:#f3e5f5
55
- style S fill:#c8e6c9
56
50
  ```
57
51
 
58
52
  ### ID 结构(64-bit)
package/dist/index.cjs CHANGED
@@ -183,7 +183,7 @@ var GenidOptimized = class {
183
183
  */
184
184
  _calcTurnBackId(useTimeTick) {
185
185
  const result = (BigInt(useTimeTick) << this._timestampShift) + (this.workerId << this.seqBitLength) + BigInt(this._turnBackIndex);
186
- this._turnBackTimeTick--;
186
+ this._turnBackTimeTick++;
187
187
  this._stats.totalGenerated++;
188
188
  return result;
189
189
  }
package/dist/index.js CHANGED
@@ -182,7 +182,7 @@ var GenidOptimized = class {
182
182
  */
183
183
  _calcTurnBackId(useTimeTick) {
184
184
  const result = (BigInt(useTimeTick) << this._timestampShift) + (this.workerId << this.seqBitLength) + BigInt(this._turnBackIndex);
185
- this._turnBackTimeTick--;
185
+ this._turnBackTimeTick++;
186
186
  this._stats.totalGenerated++;
187
187
  return result;
188
188
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cdlab996/genid",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "description": "基于 Snowflake 算法的高性能分布式唯一 ID 生成器",
6
6
  "author": "wudi <wuchendi96@gmail.com>",
7
7
  "license": "MIT",
@@ -46,21 +46,23 @@
46
46
  "engines": {
47
47
  "node": ">=20"
48
48
  },
49
- "scripts": {
50
- "build": "tsdown",
51
- "dev": "tsdown --watch",
52
- "test": "vitest --run",
53
- "test:watch": "vitest",
54
- "typecheck": "tsc --project tsconfig.json"
55
- },
56
49
  "devDependencies": {
57
- "@types/node": "^22",
58
- "tsdown": "^0.15.7",
50
+ "@types/node": "^24",
51
+ "tsdown": "^0.15.9",
59
52
  "typescript": "^5.9.3",
60
- "vitest": "^3.2.4"
53
+ "vitest": "^4.0.2"
61
54
  },
62
55
  "publishConfig": {
63
56
  "access": "public",
64
57
  "registry": "https://registry.npmjs.org/"
58
+ },
59
+ "scripts": {
60
+ "build": "tsdown",
61
+ "dev": "tsdown --watch",
62
+ "test": "vitest --run",
63
+ "test:index": "vitest --run tests/index.test.ts",
64
+ "test:performance": "vitest --run tests/performance.test.ts",
65
+ "test:stress": "vitest --run tests/stress.test.ts",
66
+ "typecheck": "tsc --project tsconfig.json"
65
67
  }
66
- }
68
+ }