@eliware/snowflake 1.1.4 → 2.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/README.md CHANGED
@@ -9,11 +9,16 @@ A production-ready, BigInt-safe Snowflake ID generator for Node.js. IDs are retu
9
9
  - Custom epoch; the default is `365662380000n` (`1981-08-03T04:53:00Z`).
10
10
  - 42-bit millisecond timestamp, 5-bit worker ID, 5-bit process ID, and 12-bit sequence.
11
11
  - Clock rollback protection and sequence overflow handling.
12
+ - Sequence overflow fails fast; callers can retry after the clock advances.
12
13
  - Configurable worker/process identity for distributed deployments.
13
14
  - Injectable clock for deterministic tests.
14
15
  - Range validation and timestamp-capacity checks.
15
16
  - Native ESM, TypeScript declarations, and no runtime dependencies.
16
17
 
18
+ ## Requirements
19
+
20
+ - Node.js 26 or newer
21
+
17
22
  ## Installation
18
23
 
19
24
  ```bash
@@ -35,7 +40,11 @@ const replicaGenerator = createSnowflakeGenerator({
35
40
  console.log(replicaGenerator());
36
41
  ```
37
42
 
38
- For Kubernetes, assign each replica a stable `workerId` from configuration. `processId` defaults to `process.pid % 32`, but should be explicitly configured when process identity must be coordinated across hosts.
43
+ For Kubernetes or other distributed deployments, assign each replica a stable
44
+ `workerId` and coordinate `processId` values so that no two active generators
45
+ share the same worker/process pair. `processId` defaults to `process.pid % 32`,
46
+ but should be explicitly configured when process identity must be coordinated
47
+ across hosts.
39
48
 
40
49
  ## API
41
50
 
@@ -48,16 +57,45 @@ For Kubernetes, assign each replica a stable `workerId` from configuration. `pro
48
57
  | `processId` | `process.pid % 32` | Process ID, from `0` to `31`. |
49
58
  | `now` | `Date.now` | Injectable millisecond clock. |
50
59
 
51
- The exports `generate` and `snowflake` are ready-to-use default generators. `constants` exposes the bit layout and default epoch.
60
+ The exports `generate` and `snowflake` are ready-to-use default generators;
61
+ both refer to the same generator. `constants` exposes the bit layout and
62
+ default epoch. IDs are unique only when the configured worker/process identity
63
+ is unique and the system clock is not permanently stalled.
64
+
65
+ ## TypeScript
66
+
67
+ TypeScript declarations are included for all public exports and options.
68
+
69
+ ## Errors / Troubleshooting
70
+
71
+ Configuration values outside the supported ranges throw `RangeError`; a
72
+ non-function clock throws `TypeError`; timestamps before the epoch or beyond
73
+ Snowflake capacity throw `RangeError`. If more than 4096 IDs are requested in
74
+ one millisecond, generation throws a `RangeError`; retry after the clock has
75
+ advanced. Configure unique `workerId` and `processId` values across distributed
76
+ generators.
52
77
 
53
78
  ## Testing and linting
54
79
 
55
80
  ```bash
56
81
  npm test
57
- npm run test:gaps
58
82
  npm run lint
83
+ npm run typecheck
84
+ npm run audit
85
+ npm run pack
59
86
  ```
60
87
 
88
+ ## Operations
89
+
90
+ Use the same `epoch`, `workerId`, and `processId` configuration consistently
91
+ for each generator instance. Persist IDs as decimal strings because Snowflake
92
+ values can exceed JavaScript's safe integer range. The generator performs no
93
+ filesystem or network I/O and does not require shutdown handling.
94
+
95
+ ## Security
96
+
97
+ Snowflake IDs are unique identifiers, not secrets. Do not use them as authentication tokens or assume they conceal timestamp and deployment information.
98
+
61
99
  ## License
62
100
 
63
101
  MIT © Eli Sterling, eliware.org
@@ -0,0 +1,57 @@
1
+ # Release Notes
2
+
3
+ ## 2.0.0 — August 28, 2026
4
+
5
+ - Adopted the shared `@eliware/test` harness for testing and linting with
6
+ strict 100×4 coverage enforcement.
7
+ - Modernized package metadata, documentation, package contents, and CI for
8
+ Node.js `>=26`, including cross-platform validation and tag-only publishing.
9
+ - Added production dependency auditing and repository-owned Knit validation.
10
+ - Added fail-fast sequence-overflow handling and expanded BigInt, boundary, and
11
+ rollback coverage.
12
+ - Removed obsolete Jest-result ignore configuration and added shared project
13
+ working rules.
14
+ - Breaking: the standard `test` and `lint` scripts now delegate to
15
+ `@eliware/test`.
16
+
17
+ ## 1.1.5 — August 7, 2026
18
+
19
+ - Aligned repository layout, scripts, CI, documentation, and package contents with Eliware library conventions.
20
+ - Added TypeScript declaration checking and standardized package validation.
21
+ - Moved tests under `tests/` and included a runnable `examples/` file in the package.
22
+ - Removed the legacy `main` metadata from this ESM-only package.
23
+ - Verification: tests, coverage, gap checks, lint, typecheck, smoke test, and package dry-run pass.
24
+
25
+ ## 1.1.4 — August 7, 2026
26
+
27
+ ### Changed
28
+
29
+ - Removed the unused `@eliware/common` runtime dependency.
30
+ - Reduced the installed dependency tree and regenerated the npm lockfile.
31
+ - Added manual GitHub Actions workflow dispatch support.
32
+
33
+ ### Verification
34
+
35
+ - npm audit: 0 vulnerabilities.
36
+
37
+ ## 1.1.2
38
+
39
+ ### Added
40
+
41
+ - Rebuilt the generator around a configurable, BigInt-safe Snowflake implementation.
42
+ - Added the custom Eliware epoch: `365662380000n` (`1981-08-03T04:53:00Z`).
43
+ - Added worker ID and process ID fields for distributed deployments.
44
+ - Added clock rollback protection and sequence overflow handling.
45
+ - Added injectable clocks, range validation, and timestamp-capacity validation.
46
+ - Added TypeScript declarations for all public options and exports.
47
+
48
+ ### Changed
49
+
50
+ - Removed CommonJS entrypoints and tests; the package is ESM-only.
51
+ - Expanded documentation with deployment and bit-layout guidance.
52
+ - Added complete generator behavior tests.
53
+
54
+ ### Verification
55
+
56
+ - Jest coverage: 100% statements, branches, functions, and lines.
57
+ - Oxlint: 0 warnings and errors.
@@ -0,0 +1,10 @@
1
+ // ESM example: example.mjs
2
+ import generate, { createSnowflakeGenerator } from './index.mjs';
3
+
4
+ console.log('Default generate():', generate());
5
+
6
+ const genWorker1 = createSnowflakeGenerator({ workerId: 1 });
7
+ console.log('Worker 1 generate():', genWorker1());
8
+
9
+ // Exported generator can be used anywhere in your app to create unique IDs
10
+ export default generate;
package/index.mjs CHANGED
@@ -57,7 +57,7 @@ export function createSnowflakeGenerator({
57
57
  if (timestamp === lastTimestamp) {
58
58
  sequence = (sequence + 1n) & SEQUENCE_MASK;
59
59
  if (sequence === 0n) {
60
- do timestamp = readTime(); while (timestamp <= lastTimestamp);
60
+ throw new RangeError('sequence overflow; clock must advance before retrying');
61
61
  }
62
62
  } else {
63
63
  sequence = 0n;
package/package.json CHANGED
@@ -1,16 +1,23 @@
1
1
  {
2
2
  "name": "@eliware/snowflake",
3
3
  "type": "module",
4
- "version": "1.1.4",
4
+ "version": "2.0.0",
5
5
  "description": "A minimal Node.js Snowflake ID generator (Discord-compatible). Provides BigInt-safe generators with configurable epoch and worker ID.",
6
- "main": "index.mjs",
6
+ "engines": {
7
+ "node": ">=26"
8
+ },
7
9
  "types": "index.d.ts",
8
10
  "files": [
9
11
  "index.mjs",
10
12
  "index.d.ts",
11
13
  "README.md",
12
- "LICENSE"
14
+ "LICENSE",
15
+ "RELEASE_NOTES.md",
16
+ "examples"
13
17
  ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
14
21
  "exports": {
15
22
  ".": {
16
23
  "types": "./index.d.ts",
@@ -18,9 +25,11 @@
18
25
  }
19
26
  },
20
27
  "scripts": {
21
- "test": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --detectOpenHandles --silent --coverage",
22
- "test:gaps": "npm test -- --coverageReporters=text 2>&1 | awk '!/100%/'",
23
- "lint": "npx oxlint ."
28
+ "test": "eliware-test",
29
+ "lint": "eliware-test --lint",
30
+ "audit": "npm audit --omit=dev --audit-level=moderate",
31
+ "typecheck": "tsc --project tsconfig.json",
32
+ "pack": "npm pack --dry-run"
24
33
  },
25
34
  "repository": {
26
35
  "type": "git",
@@ -43,13 +52,7 @@
43
52
  },
44
53
  "homepage": "https://github.com/eliware/snowflake#readme",
45
54
  "devDependencies": {
46
- "jest": "^30.4.2"
47
- },
48
- "jest": {
49
- "testEnvironment": "node",
50
- "testMatch": [
51
- "**/?(*.)+(spec|test).[jt]s?(x)",
52
- "**/?(*.)+(spec|test).mjs"
53
- ]
55
+ "@eliware/test": "^2.0.0",
56
+ "typescript": "^7.0.2"
54
57
  }
55
58
  }