@eliware/common 12.0.1 → 14.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/AGENTS.md +16 -23
- package/README.md +7 -6
- package/RELEASE_NOTES.md +22 -63
- package/docs/api.md +60 -29
- package/docs/package.md +2 -2
- package/docs/troubleshooting.md +5 -5
- package/docs/usage.md +59 -11
- package/package.json +8 -8
- package/specs/directives.yaml +4 -4
- package/src/errors.d.mts +37 -0
- package/src/errors.mjs +2 -2
- package/src/index.d.ts +18 -12
- package/src/index.mjs +2 -1
- package/src/log.d.mts +29 -0
- package/src/path.d.mts +47 -0
- package/src/path.mjs +2 -0
- package/src/snowflake.d.mts +22 -0
package/AGENTS.md
CHANGED
|
@@ -2,54 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
## Project
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
Use Node.js 26 or later.
|
|
5
|
+
See `README.md` for the repository purpose, owner, scope, and boundaries.
|
|
7
6
|
|
|
8
7
|
## Scope and boundaries
|
|
9
8
|
|
|
10
|
-
Keep
|
|
11
|
-
Get Eliware Operations approval before publication.
|
|
9
|
+
Keep repository requirements in `specs/directives.yaml`.
|
|
12
10
|
|
|
13
11
|
## Layout
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
Put one matching test in `tests/` for each runtime module.
|
|
17
|
-
Put user docs in `docs/`, examples in `examples/`, and specs in `specs/`.
|
|
13
|
+
Use `README.md` and `specs/README.md` to find maintained files.
|
|
18
14
|
|
|
19
15
|
## Development
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
Keep `src/index.mjs` as the public export barrel.
|
|
23
|
-
Keep docs, declarations, package data, and tests in sync.
|
|
17
|
+
Give each source and test module one cohesive purpose.
|
|
24
18
|
|
|
25
19
|
## Validation
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
Use Node.js 26 or later and native ESM for maintained JavaScript modules.
|
|
22
|
+
Run `npm test` for aggregate validation.
|
|
28
23
|
Run `npm run lint` for lint checks.
|
|
29
24
|
Run `npm run audit` for dependency checks.
|
|
30
25
|
Run `npm run format` to format files.
|
|
31
|
-
Run `npm run format:check` to check
|
|
32
|
-
Run `npm run typecheck` to check declarations.
|
|
33
|
-
Run `npm run pack` to check package contents.
|
|
26
|
+
Run `npm run format:check` to check formatting.
|
|
34
27
|
|
|
35
28
|
## Security
|
|
36
29
|
|
|
37
|
-
Keep
|
|
38
|
-
Review dependency behavior and update dependencies before publication.
|
|
30
|
+
Keep credentials, secret values, private data, and runtime state out of Git.
|
|
39
31
|
|
|
40
32
|
## Changes
|
|
41
33
|
|
|
42
|
-
Describe user-visible
|
|
34
|
+
Describe each user-visible change in `RELEASE_NOTES.md`.
|
|
43
35
|
Keep release notes accurate.
|
|
44
36
|
|
|
45
37
|
## Library
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
Run focused tests first during development.
|
|
40
|
+
Run one test file with `npm test -- tests/path/to/example.test.mjs`.
|
|
41
|
+
Run multiple test files with `npm test -- tests/path/to/first.test.mjs tests/path/to/second.test.mjs`.
|
|
42
|
+
Prevent repeated full-suite runs during development.
|
|
43
|
+
Run the full `npm test` suite for final validation before a commit, milestone, or release.
|
|
50
44
|
|
|
51
45
|
## npm publication
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Passing checks does not approve publication.
|
|
47
|
+
Run `npm run pack` to check package contents.
|
|
48
|
+
Publish only after approved release steps.
|
package/README.md
CHANGED
|
@@ -23,7 +23,8 @@ A shared ESM compatibility package for Eliware filesystem, path, logging, error,
|
|
|
23
23
|
|
|
24
24
|
## Features
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Eliware maintains this shared package for common Node.js APIs.
|
|
27
|
+
It re-exports filesystem, path, logger, error, signal, redaction, and Snowflake APIs.
|
|
27
28
|
|
|
28
29
|
## Requirements
|
|
29
30
|
|
|
@@ -43,7 +44,7 @@ Read the [user docs](docs/README.md) and [release notes](RELEASE_NOTES.md).
|
|
|
43
44
|
|
|
44
45
|
## Development
|
|
45
46
|
|
|
46
|
-
Read the [
|
|
47
|
+
Read the [specifications index](specs/README.md) before you change files.
|
|
47
48
|
|
|
48
49
|
## Testing
|
|
49
50
|
|
|
@@ -55,19 +56,19 @@ Read the [troubleshooting guide](docs/troubleshooting.md).
|
|
|
55
56
|
|
|
56
57
|
## Security
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
Read the [redaction API guide](docs/api.md#redaction-apis) before you use sensitive data.
|
|
59
60
|
|
|
60
61
|
## API
|
|
61
62
|
|
|
62
|
-
Read the [API reference](docs/api.md)
|
|
63
|
+
Read the [API reference](docs/api.md).
|
|
63
64
|
|
|
64
65
|
## Packaging
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
Read the [package guide](docs/package.md).
|
|
67
68
|
|
|
68
69
|
## Examples
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
Read the [examples index](examples/README.md).
|
|
71
72
|
|
|
72
73
|
## Support
|
|
73
74
|
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## 14.0.0 — 2026-10-21
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Re-exported the complete runtime APIs and public types from the Eliware errors, log, path, redact, signals, and snowflake packages.
|
|
8
|
+
- Added `createPathHelpers` with structured operation records and added type parity checks for dependency APIs.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Upgraded the package and its Eliware runtime and test dependencies to major version 14.
|
|
13
|
+
- Aligned package metadata, specifications, CI, npm publication, and Knit workflows with convention version 14.
|
|
14
|
+
- Expanded and corrected the API, setup, usage, package, and troubleshooting guides.
|
|
15
|
+
- Simplified `README.md` and `AGENTS.md` while keeping the content required by repository conventions.
|
|
16
|
+
- Removed invalid Log type aliases from Common and kept Common's valid public types available.
|
|
17
|
+
- Added a strict packed-consumer check for Common's retained public types.
|
|
18
|
+
|
|
19
|
+
### Breaking changes
|
|
20
|
+
|
|
21
|
+
- Require major version 14 of the Eliware runtime dependencies.
|
|
22
|
+
|
|
3
23
|
## 12.0.1 — 2026-10-12
|
|
4
24
|
|
|
5
25
|
### Added
|
|
@@ -28,72 +48,11 @@
|
|
|
28
48
|
### Changed
|
|
29
49
|
|
|
30
50
|
- Modernized the package for the shared Eliware conventions and Node.js `>=26`.
|
|
31
|
-
- Replaced direct Jest tooling with `@eliware/test`,
|
|
51
|
+
- Replaced direct Jest tooling with `@eliware/test`, with enforced 100×4 coverage and shared linting.
|
|
32
52
|
- Updated CI for Ubuntu and Windows validation on `main`, pull requests, and `v*` tags, with gated publishing.
|
|
33
|
-
- Updated package metadata, documentation, and dependency
|
|
53
|
+
- Updated package metadata, documentation, and dependency checks.
|
|
34
54
|
|
|
35
55
|
### Breaking changes
|
|
36
56
|
|
|
37
57
|
- Required Node.js `>=26`.
|
|
38
58
|
- Replaced direct Jest and Oxlint project tooling with the shared `@eliware/test` harness.
|
|
39
|
-
|
|
40
|
-
## 1.1.8 — 2026-08-10
|
|
41
|
-
|
|
42
|
-
### Changed
|
|
43
|
-
|
|
44
|
-
- Updated `@eliware/errors` to 1.1.9, `@eliware/log` to 1.1.12, and `@eliware/signals` to 1.1.7.
|
|
45
|
-
- Added the `safeSerialize` TypeScript declaration to match the runtime export.
|
|
46
|
-
- Updated signal handler contract coverage for the current upstream listener behavior.
|
|
47
|
-
|
|
48
|
-
## 1.1.7 — 2026-08-07
|
|
49
|
-
|
|
50
|
-
### Changed
|
|
51
|
-
|
|
52
|
-
- Standardized package layout, validation scripts, TypeScript checking, CI, and package contents.
|
|
53
|
-
- Updated internal dependencies to the latest released Eliware versions.
|
|
54
|
-
- Expanded troubleshooting, development, and security documentation.
|
|
55
|
-
|
|
56
|
-
## 1.1.6 — 2026-08-07
|
|
57
|
-
|
|
58
|
-
### Changed
|
|
59
|
-
|
|
60
|
-
- Updated `@eliware/errors`, `@eliware/log`, `@eliware/path`, and `@eliware/signals` to current releases.
|
|
61
|
-
- Standardized Jest coverage on the V8 provider for accurate ESM coverage reporting.
|
|
62
|
-
|
|
63
|
-
## 1.1.5 — 2026-08-06
|
|
64
|
-
|
|
65
|
-
### Changed
|
|
66
|
-
|
|
67
|
-
- Refactored the package into focused ESM modules under `src/`.
|
|
68
|
-
- Expanded the unified export surface to include the current public APIs from four shared packages.
|
|
69
|
-
- Added logger and path exports, including `safeSerialize`, `resolvePath`, `relativePath`, and `fileUrlToPath`.
|
|
70
|
-
- Updated TypeScript declarations for the expanded API and dependency option types.
|
|
71
|
-
- Replaced CommonJS entry points and tests with ESM-only files.
|
|
72
|
-
- Expanded contract tests for public exports, helper APIs, handlers, cleanup, and shutdown hooks.
|
|
73
|
-
- Updated the README, examples, dependencies, package files, and development guidance.
|
|
74
|
-
- Standardized linting, coverage scripts, CI, and repository artifact ignores.
|
|
75
|
-
|
|
76
|
-
## 1.1.4 — 2026-07-01
|
|
77
|
-
|
|
78
|
-
### Changed
|
|
79
|
-
|
|
80
|
-
- Updated package metadata and dependencies.
|
|
81
|
-
- Refreshed the lockfile and standardized repository tooling.
|
|
82
|
-
|
|
83
|
-
## 1.1.3 — 2025-12-21
|
|
84
|
-
|
|
85
|
-
### Changed
|
|
86
|
-
|
|
87
|
-
- Released maintenance updates.
|
|
88
|
-
|
|
89
|
-
## 1.1.2 — 2025-12-21
|
|
90
|
-
|
|
91
|
-
### Changed
|
|
92
|
-
|
|
93
|
-
- Released maintenance updates.
|
|
94
|
-
|
|
95
|
-
## 1.1.1 — 2025-12-09
|
|
96
|
-
|
|
97
|
-
### Added
|
|
98
|
-
|
|
99
|
-
- Released the first tagged version of the common ESM utility package.
|
package/docs/api.md
CHANGED
|
@@ -17,7 +17,8 @@ Read the [Node.js file system API](https://nodejs.org/api/fs.html) for functions
|
|
|
17
17
|
|
|
18
18
|
| Export | Call | Result |
|
|
19
19
|
| -------------------- | ------------------------------------------ | -------------------------------------------------- |
|
|
20
|
-
| `path` | `path(metaOrDir, ...segments)` |
|
|
20
|
+
| `path` | `path(metaOrDir, ...segments)` | Add segments to a module directory. |
|
|
21
|
+
| `createPathHelpers` | `createPathHelpers(options?)` | Create path helpers that log each operation. |
|
|
21
22
|
| `pathUrl` | `pathUrl(metaOrDir, ...segments)` | Return a file URL string. |
|
|
22
23
|
| `getCurrentDirname` | `getCurrentDirname(metaOrDir, dirnameFn?)` | Return the module directory. |
|
|
23
24
|
| `getCurrentFilename` | `getCurrentFilename(metaOrDir)` | Return the module filename or input string. |
|
|
@@ -26,10 +27,15 @@ Read the [Node.js file system API](https://nodejs.org/api/fs.html) for functions
|
|
|
26
27
|
| `fileUrlToPath` | `fileUrlToPath(fileUrl)` | Convert a file URL string or `URL` to a file path. |
|
|
27
28
|
|
|
28
29
|
Pass `import.meta` or a directory string as `metaOrDir`. Pass `dirnameFn` only with `import.meta`.
|
|
30
|
+
|
|
31
|
+
Call `createPathHelpers()` to use the default logger. Pass `options.logger` to set the logger.
|
|
32
|
+
The helpers write debug records after operations. They write error records before they throw an error.
|
|
33
|
+
The default logger uses the `info` level, so it filters debug records. Set its level to `debug` to receive operation records.
|
|
34
|
+
|
|
29
35
|
The default export from `@eliware/path` is named `path` here.
|
|
30
36
|
Read the [path package docs](https://github.com/eliware/path/tree/main/docs) for details.
|
|
31
37
|
|
|
32
|
-
##
|
|
38
|
+
## Logger APIs
|
|
33
39
|
|
|
34
40
|
| Export | Call | Result |
|
|
35
41
|
| --------------- | ----------------------------------------------- | ------------------------------------------------ |
|
|
@@ -40,10 +46,11 @@ Read the [path package docs](https://github.com/eliware/path/tree/main/docs) for
|
|
|
40
46
|
`createLogger` accepts `level`, `transports`, `format`, `timestamp`, and `keys` options.
|
|
41
47
|
Use `format: "text"` or `format: "json"`. The default level is `info`.
|
|
42
48
|
The other defaults are a console transport, text format, no timestamp, and no custom redaction keys.
|
|
49
|
+
|
|
43
50
|
`safeSerialize` accepts `keys`, `redactKeys`, `marker`, `circularMarker`, `maxDepth`, `maxKeys`, `maxArray`, and `maxString` options.
|
|
44
51
|
It does not call `toJSON`. It uses default secret keys and limits when you omit options.
|
|
45
52
|
It returns JSON-safe values. It converts BigInt values to text and marks circular or truncated values.
|
|
46
|
-
Read the [
|
|
53
|
+
Read the [logger package docs](https://github.com/eliware/log/tree/main/docs) for defaults and details.
|
|
47
54
|
|
|
48
55
|
## Redaction APIs
|
|
49
56
|
|
|
@@ -51,29 +58,34 @@ Read the [log package docs](https://github.com/eliware/log/tree/main/docs) for d
|
|
|
51
58
|
Call `createPolicy(options?)` to make a frozen policy with custom key names or markers.
|
|
52
59
|
Call `redactValue(value, options?)` to return a redacted copy of an object or array.
|
|
53
60
|
Call `redactHeaders(headers, options?)` to redact header values in an object, pair array, or entries object.
|
|
54
|
-
Call `redactText(value, options?)` to redact
|
|
61
|
+
Call `redactText(value, options?)` to redact standard credential patterns, custom key values, and literal secrets.
|
|
55
62
|
Call `replaceLiteralSecret(value, secret, marker?)` to replace one exact secret in text.
|
|
56
63
|
|
|
57
64
|
Policy options include `keys`, `redactKeys`, `marker`, and `circularMarker`.
|
|
58
65
|
Structured values also support `maxDepth`, `maxKeys`, and `maxArray` limits.
|
|
59
66
|
Text also supports `secrets` and the `maxOutputLength` limit.
|
|
67
|
+
|
|
60
68
|
The default marker is `[REDACTED]`. The default text limit is 10,000 characters.
|
|
61
69
|
`redactText` detects authorization values, secret assignments, provider tokens, JWT-like strings, and key blocks.
|
|
70
|
+
|
|
62
71
|
`redactValue` returns a copy and does not change its input.
|
|
63
72
|
`redactHeaders` keeps the input shape for objects and pair arrays. It returns a lowercase object for entries objects.
|
|
64
|
-
|
|
73
|
+
|
|
74
|
+
The `safeSerialize` export in Logger APIs matches the `safeSerialize` export from `@eliware/redact`.
|
|
75
|
+
|
|
65
76
|
Read the [Redact API guide](https://github.com/eliware/redact/blob/main/docs/api.md) for full rules and limits.
|
|
66
77
|
|
|
67
78
|
## Error handlers
|
|
68
79
|
|
|
69
|
-
Call `registerHandlers(options?)` to
|
|
80
|
+
Call `registerHandlers(options?)` to add handlers for process events.
|
|
70
81
|
The default events are `uncaughtException`, `unhandledRejection`, and `warning`.
|
|
82
|
+
The `defaultEvents` export contains the default event names.
|
|
71
83
|
|
|
72
84
|
| Option | Default | Purpose |
|
|
73
85
|
| ------------ | -------------------------- | --------------------------------------------- |
|
|
74
86
|
| `processObj` | `process` | Set the process-like event source. |
|
|
75
87
|
| `log` | `@eliware/log` | Set the logger. |
|
|
76
|
-
| `events` | Three process error events | Set the events
|
|
88
|
+
| `events` | Three process error events | Set the events for this function. |
|
|
77
89
|
| `once` | `false` | Set one-time handler behavior. |
|
|
78
90
|
| `signal` | None | Remove handlers when an `AbortSignal` aborts. |
|
|
79
91
|
|
|
@@ -84,51 +96,70 @@ Read the [errors package docs](https://github.com/eliware/errors/tree/main/docs)
|
|
|
84
96
|
|
|
85
97
|
## Shutdown handlers
|
|
86
98
|
|
|
87
|
-
Call `registerSignals(options?)` to
|
|
99
|
+
Call `registerSignals(options?)` to add process shutdown handlers.
|
|
88
100
|
The default signals are `SIGTERM`, `SIGINT`, and `SIGHUP`.
|
|
89
101
|
|
|
90
|
-
| Option | Default | Purpose
|
|
91
|
-
| -------------- | ----------------------------- |
|
|
92
|
-
| `processObj` | `process` | Set the process-like event source.
|
|
93
|
-
| `log` | `@eliware/log` | Set the logger.
|
|
94
|
-
| `signals` | `SIGTERM`, `SIGINT`, `SIGHUP` | Set the signals
|
|
95
|
-
| `shutdownHook` | None | Set cleanup work.
|
|
96
|
-
| `exitCode` | `0` | Set the process exit code.
|
|
97
|
-
| `exit` | `true` | Allow or prevent process exit.
|
|
98
|
-
| `signal` | None | Remove handlers when an `AbortSignal` aborts.
|
|
102
|
+
| Option | Default | Purpose |
|
|
103
|
+
| -------------- | ----------------------------- | ----------------------------------------------------- |
|
|
104
|
+
| `processObj` | `process` | Set the process-like event source. |
|
|
105
|
+
| `log` | `@eliware/log` | Set the logger. |
|
|
106
|
+
| `signals` | `SIGTERM`, `SIGINT`, `SIGHUP` | Set the signals for this function. |
|
|
107
|
+
| `shutdownHook` | None | Set cleanup work. This function can return a promise. |
|
|
108
|
+
| `exitCode` | `0` | Set the process exit code. |
|
|
109
|
+
| `exit` | `true` | Allow or prevent process exit. |
|
|
110
|
+
| `signal` | None | Remove handlers when an `AbortSignal` aborts. |
|
|
99
111
|
|
|
100
112
|
The result has `removed`, `shutdown(signal?)`, `getShuttingDown()`, and `removeHandlers()` members.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
113
|
+
|
|
114
|
+
The default `exit` value is `true`. Set `exit: false` when your app controls process exit.
|
|
115
|
+
|
|
116
|
+
Each callback runs once. The package calls callbacks in order and continues after an error.
|
|
117
|
+
|
|
118
|
+
Pass an empty `signals` array to disable signal events. A `beforeExit` handler also runs.
|
|
104
119
|
Read the [signals API docs](https://github.com/eliware/signals/blob/main/docs/api.md) for shutdown order and error behavior.
|
|
105
120
|
|
|
106
121
|
## Snowflake IDs
|
|
107
122
|
|
|
108
123
|
Call `createSnowflakeGenerator(options?)` to make a generator. Each call returns a decimal string.
|
|
109
124
|
|
|
110
|
-
| Option | Type | Default | Purpose
|
|
111
|
-
| ----------- | -------------------- | ------------------ |
|
|
112
|
-
| `epoch` | `number` or `bigint` | `365662380000n` | Set the epoch in Unix milliseconds.
|
|
113
|
-
| `workerId` | `number` or `bigint` | `0` | Set a worker value from 0 through 31.
|
|
114
|
-
| `processId` | `number` or `bigint` | `process.pid % 32` | Set a process value from 0 through 31.
|
|
115
|
-
| `now` | function | `Date.now` | Set a clock that returns Unix milliseconds.
|
|
125
|
+
| Option | Type | Default | Purpose |
|
|
126
|
+
| ----------- | -------------------- | ------------------ | ------------------------------------------------- |
|
|
127
|
+
| `epoch` | `number` or `bigint` | `365662380000n` | Set the epoch in Unix milliseconds. |
|
|
128
|
+
| `workerId` | `number` or `bigint` | `0` | Set a worker value from 0 through 31. |
|
|
129
|
+
| `processId` | `number` or `bigint` | `process.pid % 32` | Set a process value from 0 through 31. |
|
|
130
|
+
| `now` | function | `Date.now` | Set a clock that returns Unix milliseconds. |
|
|
131
|
+
| `logger` | Winston `Logger` | None | Record generator events with a structured logger. |
|
|
116
132
|
|
|
117
133
|
Use one epoch for all generators in one application. Give each active generator a unique worker and process ID pair.
|
|
118
134
|
Keep each ID as a string. An ID uses a 42-bit timestamp, 5-bit worker value, 5-bit process value, and 12-bit sequence.
|
|
119
|
-
|
|
135
|
+
|
|
136
|
+
Each generator can create 4096 IDs for each millisecond. It throws `RangeError` when time or sequence limits fail.
|
|
137
|
+
|
|
120
138
|
Pass a safe integer or `bigint` to `epoch`, `workerId`, and `processId`.
|
|
139
|
+
Set `epoch` from zero through `(1n << 42n) - 1n`. Set `workerId` and `processId` from 0 through 31.
|
|
140
|
+
|
|
121
141
|
Pass a clock that returns Unix milliseconds as a safe integer or `bigint`.
|
|
122
|
-
|
|
142
|
+
Set the first clock value at or after the epoch.
|
|
143
|
+
After the first ID, the generator uses its last timestamp when the clock moves to an earlier time.
|
|
144
|
+
|
|
145
|
+
The generator increments its sequence during a clock rollback. It throws `RangeError` when one generator creates more than 4096 IDs in one millisecond.
|
|
146
|
+
|
|
147
|
+
Pass a logger with `error`, `warn`, `info`, and `debug` methods to record generator events. The generator writes no records when you omit the logger.
|
|
148
|
+
The records do not include generated IDs, credentials, tokens, or error messages.
|
|
149
|
+
|
|
123
150
|
The exports `generate`, `snowflake`, and the default export from `@eliware/snowflake` use one shared generator.
|
|
124
151
|
The `constants` export provides `epoch`, `sequenceBits`, `processBits`, and `workerBits` values as `bigint`.
|
|
125
|
-
|
|
152
|
+
|
|
153
|
+
Read the [Snowflake usage guide](https://github.com/eliware/snowflake/blob/main/docs/usage.md) for timestamp limits and clock behavior.
|
|
126
154
|
|
|
127
155
|
## TypeScript types
|
|
128
156
|
|
|
129
157
|
The package exports these types:
|
|
130
158
|
|
|
131
159
|
- `Logger`
|
|
160
|
+
- `PathLogger`, `PathHelpersOptions`, and `PathHelpers`
|
|
161
|
+
- `NodeSignal`, `SignalsLogger`, and `SignalsProcessLike`
|
|
162
|
+
- `ProcessEvent`, `ProcessListener`, and `ProcessLike`
|
|
132
163
|
- `RegisterHandlersOptions` and `RegisteredHandlers`
|
|
133
164
|
- `RegisterSignalsOptions` and `SignalsRegistration`
|
|
134
165
|
- `RedactionPolicy`, `SerializationOptions`, `StructuredRedactionOptions`, and `TextRedactionOptions`
|
package/docs/package.md
CHANGED
|
@@ -14,7 +14,7 @@ The package does not provide a CommonJS entry point.
|
|
|
14
14
|
|
|
15
15
|
## Runtime dependencies
|
|
16
16
|
|
|
17
|
-
The package uses major version
|
|
17
|
+
The package uses major version 14 of these Eliware packages:
|
|
18
18
|
|
|
19
19
|
- `@eliware/errors`
|
|
20
20
|
- `@eliware/log`
|
|
@@ -23,7 +23,7 @@ The package uses major version 12 of these Eliware packages:
|
|
|
23
23
|
- `@eliware/signals`
|
|
24
24
|
- `@eliware/snowflake`
|
|
25
25
|
|
|
26
|
-
Use the exports in this package. Use
|
|
26
|
+
Use the exports in this package. Use a dependency directly when your app requires its own entry point.
|
|
27
27
|
Read the [API reference](api.md) for each exported value.
|
|
28
28
|
|
|
29
29
|
## Published files
|
package/docs/troubleshooting.md
CHANGED
|
@@ -19,15 +19,15 @@ Pass `import.meta` or a directory string to a path helper.
|
|
|
19
19
|
Pass a file URL to `fileUrlToPath`.
|
|
20
20
|
Read the [path API section](api.md#path-helpers) for each helper's result.
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Logger errors
|
|
23
23
|
|
|
24
24
|
Check the `level`, `transports`, and `format` options passed to `createLogger`.
|
|
25
25
|
Pass a logger with `debug`, `info`, `warn`, and `error` methods where required.
|
|
26
|
-
Remove secret values before you write metadata to
|
|
26
|
+
Remove secret values before you write metadata to logger output.
|
|
27
27
|
|
|
28
28
|
## Process handler errors
|
|
29
29
|
|
|
30
|
-
Keep each handler registration while
|
|
30
|
+
Keep each handler registration while it is required.
|
|
31
31
|
Call `removeHandlers()` to remove error or signal handlers.
|
|
32
32
|
Pass a valid process-like object and event names.
|
|
33
33
|
Read the [API reference](api.md#error-handlers) and [shutdown handler guide](api.md#shutdown-handlers).
|
|
@@ -36,7 +36,7 @@ Read the [API reference](api.md#error-handlers) and [shutdown handler guide](api
|
|
|
36
36
|
|
|
37
37
|
Give each active generator a unique worker and process ID pair.
|
|
38
38
|
Keep generated IDs as decimal strings. Do not convert them to `number`.
|
|
39
|
-
Wait
|
|
39
|
+
Wait until the clock value changes after a sequence limit error.
|
|
40
40
|
Check the epoch and clock when the generator reports a timestamp error.
|
|
41
41
|
Read [Snowflake IDs](api.md#snowflake-ids) for limits and clock behavior.
|
|
42
42
|
|
|
@@ -44,4 +44,4 @@ Read [Snowflake IDs](api.md#snowflake-ids) for limits and clock behavior.
|
|
|
44
44
|
|
|
45
45
|
Run `npm ci` to install locked dependencies.
|
|
46
46
|
Run `npm test` to check the repository.
|
|
47
|
-
|
|
47
|
+
Repair the first reported error, then run `npm test` again.
|
package/docs/usage.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Requirements
|
|
4
4
|
|
|
5
|
-
Use Node.js 26 or later. Use a project
|
|
5
|
+
Use Node.js 26 or later. Use a project that supports native ESM.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -14,9 +14,22 @@ npm install @eliware/common
|
|
|
14
14
|
|
|
15
15
|
The package installs its Eliware runtime dependencies.
|
|
16
16
|
|
|
17
|
+
## Read a file
|
|
18
|
+
|
|
19
|
+
Use the Node.js `fs` namespace for file operations. This example reads a file as UTF-8 text.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { fs } from "@eliware/common";
|
|
23
|
+
|
|
24
|
+
const text = await fs.promises.readFile("./config.json", "utf8");
|
|
25
|
+
const config = JSON.parse(text);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use Node.js `fs` documentation for available methods, options, and errors.
|
|
29
|
+
|
|
17
30
|
## Import public APIs
|
|
18
31
|
|
|
19
|
-
Import the APIs that your
|
|
32
|
+
Import the APIs that your app requires.
|
|
20
33
|
|
|
21
34
|
```js
|
|
22
35
|
import {
|
|
@@ -45,8 +58,8 @@ registerSignals({
|
|
|
45
58
|
console.log(fs.existsSync(configFile));
|
|
46
59
|
```
|
|
47
60
|
|
|
48
|
-
This code
|
|
49
|
-
The shutdown
|
|
61
|
+
This code writes one Snowflake ID and checks one file. It stays active until a signal starts shutdown.
|
|
62
|
+
The shutdown callback stops the timer and removes the error handlers.
|
|
50
63
|
|
|
51
64
|
## Use path helpers
|
|
52
65
|
|
|
@@ -73,7 +86,19 @@ const localFile = fileUrlToPath(url);
|
|
|
73
86
|
Pass a directory string when code does not have `import.meta`.
|
|
74
87
|
Read the [API reference](api.md) for each path helper.
|
|
75
88
|
|
|
76
|
-
|
|
89
|
+
Use `createPathHelpers` when your app must record path operations with a custom logger.
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
import { createPathHelpers } from "@eliware/common";
|
|
93
|
+
|
|
94
|
+
const records = [];
|
|
95
|
+
const helpers = createPathHelpers({ logger: { log: (record) => records.push(record) } });
|
|
96
|
+
const file = helpers.path(import.meta, "data", "input.json");
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The helper writes a debug record after it completes a path operation.
|
|
100
|
+
|
|
101
|
+
## Use logger APIs
|
|
77
102
|
|
|
78
103
|
Use the default `log` object or create a logger with `createLogger(options)`.
|
|
79
104
|
|
|
@@ -84,11 +109,20 @@ const logger = createLogger({ format: "json", timestamp: true });
|
|
|
84
109
|
logger.info("Request complete", safeSerialize({ requestId: "example" }));
|
|
85
110
|
```
|
|
86
111
|
|
|
87
|
-
Pass metadata as the second logger argument. Use `safeSerialize` to remove secret fields before you
|
|
112
|
+
Pass metadata as the second logger argument. Use `safeSerialize` to remove secret fields and limit nested values before you write records.
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import { createLogger, safeSerialize } from "@eliware/common";
|
|
116
|
+
|
|
117
|
+
const logger = createLogger({ format: "json" });
|
|
118
|
+
logger.info("Request complete", safeSerialize({ token: "example", status: 200 }));
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The serializer returns a bounded representation. It does not guarantee that all sensitive data has been removed.
|
|
88
122
|
|
|
89
123
|
## Redact sensitive values
|
|
90
124
|
|
|
91
|
-
Use `redactText` to remove credentials from text before you
|
|
125
|
+
Use `redactText` to remove credentials from text before you write or store it.
|
|
92
126
|
|
|
93
127
|
```js
|
|
94
128
|
import { redactText, redactValue } from "@eliware/common";
|
|
@@ -98,14 +132,28 @@ const record = redactValue({ user: "alex", token: "example-token" });
|
|
|
98
132
|
console.log(message, record);
|
|
99
133
|
```
|
|
100
134
|
|
|
101
|
-
`redactText` applies
|
|
135
|
+
`redactText` applies standard credential rules. Pass `secrets` to replace known literal values.
|
|
102
136
|
`redactValue` returns a copy with sensitive property values replaced.
|
|
103
137
|
Read the [Redaction APIs](api.md#redaction-apis) for policies, options, limits, and header handling.
|
|
104
138
|
|
|
105
|
-
|
|
139
|
+
Use `redactHeaders` for HTTP header data. Use `createPolicy` to add a sensitive property name.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
import { createPolicy, redactHeaders, redactValue } from "@eliware/common";
|
|
143
|
+
|
|
144
|
+
const policy = createPolicy({ keys: ["token", "sessionId"] });
|
|
145
|
+
const record = redactValue({ sessionId: "example", status: 200 }, policy);
|
|
146
|
+
const headers = redactHeaders({ Authorization: "Bearer example", Accept: "application/json" });
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The policy replaces the default sensitive names with the names that you provide. Include the default names when you want to keep them.
|
|
150
|
+
|
|
151
|
+
## Process errors and signals
|
|
106
152
|
|
|
107
|
-
Call `registerHandlers(options)` to add process error handlers.
|
|
108
|
-
Call `
|
|
153
|
+
Call `registerHandlers(options)` to add process error handlers.
|
|
154
|
+
Call its `removeHandlers()` method when the handlers are no longer required.
|
|
155
|
+
Call `registerSignals(options)` to add shutdown handlers.
|
|
156
|
+
Pass `shutdownHook` to run cleanup.
|
|
109
157
|
Read the [API reference](api.md) for defaults, options, return values, and dependency guides.
|
|
110
158
|
|
|
111
159
|
## Create Snowflake IDs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eliware/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A shared ESM compatibility package for Eliware filesystem, path, logging, error, and signal APIs.",
|
|
6
6
|
"keywords": [
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"node": ">=26"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@eliware/errors": "^
|
|
48
|
-
"@eliware/log": "^
|
|
49
|
-
"@eliware/path": "^
|
|
50
|
-
"@eliware/redact": "^
|
|
51
|
-
"@eliware/signals": "^
|
|
52
|
-
"@eliware/snowflake": "^
|
|
47
|
+
"@eliware/errors": "^14.0.0",
|
|
48
|
+
"@eliware/log": "^14.0.0",
|
|
49
|
+
"@eliware/path": "^14.0.0",
|
|
50
|
+
"@eliware/redact": "^14.0.0",
|
|
51
|
+
"@eliware/signals": "^14.0.0",
|
|
52
|
+
"@eliware/snowflake": "^14.0.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@eliware/test": "^
|
|
55
|
+
"@eliware/test": "^14.0.0",
|
|
56
56
|
"typescript": "^7.0.2"
|
|
57
57
|
},
|
|
58
58
|
"jest": {
|
package/specs/directives.yaml
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
version: "
|
|
2
|
-
description: Defines requirements for the Eliware
|
|
1
|
+
version: "14.0"
|
|
2
|
+
description: Defines requirements for the Eliware shared package.
|
|
3
3
|
directives:
|
|
4
4
|
- id: E-199.0
|
|
5
5
|
dos:
|
|
6
|
-
- Export
|
|
6
|
+
- Export shared file system, path, logger, error, signal, Redact, and Snowflake APIs.
|
|
7
7
|
- Keep the package entry point and declaration file under src/.
|
|
8
8
|
- Mirror every source module with one test module under tests/.
|
|
9
9
|
- Use the shared Eliware packages for delegated runtime behavior.
|
|
10
10
|
- Run repository validation through eliware-test.
|
|
11
|
-
-
|
|
11
|
+
- Limit published files to package code and user docs.
|
|
12
12
|
donts:
|
|
13
13
|
- Do not add global configuration or import-time work.
|
|
14
14
|
- Do not duplicate behavior owned by shared Eliware packages.
|
package/src/errors.d.mts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type ProcessEvent = "uncaughtException" | "unhandledRejection" | "warning";
|
|
2
|
+
|
|
3
|
+
export declare const defaultEvents: readonly ProcessEvent[];
|
|
4
|
+
|
|
5
|
+
export type ProcessListener = (...args: unknown[]) => void;
|
|
6
|
+
|
|
7
|
+
export interface Logger {
|
|
8
|
+
error(message: string, metadata: unknown): unknown;
|
|
9
|
+
warn(message: string, metadata: unknown): unknown;
|
|
10
|
+
debug(message: string): unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ProcessLike = {
|
|
14
|
+
on(event: ProcessEvent, listener: ProcessListener): unknown;
|
|
15
|
+
once?(event: ProcessEvent, listener: ProcessListener): unknown;
|
|
16
|
+
listeners?(event: ProcessEvent): ProcessListener[];
|
|
17
|
+
} & (
|
|
18
|
+
| { off(event: ProcessEvent, listener: ProcessListener): unknown }
|
|
19
|
+
| { removeListener(event: ProcessEvent, listener: ProcessListener): unknown }
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export interface RegisterHandlersOptions {
|
|
23
|
+
processObj?: ProcessLike;
|
|
24
|
+
log?: Logger;
|
|
25
|
+
events?: ProcessEvent[];
|
|
26
|
+
once?: boolean;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RegisteredHandlers {
|
|
31
|
+
readonly removed: boolean;
|
|
32
|
+
removeHandlers(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare function registerHandlers(options?: RegisterHandlersOptions): RegisteredHandlers;
|
|
36
|
+
|
|
37
|
+
export default registerHandlers;
|
package/src/errors.mjs
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
|
-
import type logger from "@eliware/log";
|
|
3
|
-
import type { RegisterHandlersOptions, RegisteredHandlers } from "@eliware/errors";
|
|
4
|
-
import type { RegisterSignalsOptions, SignalsRegistration } from "@eliware/signals";
|
|
5
|
-
|
|
6
2
|
export { fs };
|
|
7
|
-
export { createLogger, default as log, safeSerialize } from "
|
|
3
|
+
export { createLogger, default as log, safeSerialize } from "./log.mjs";
|
|
8
4
|
export {
|
|
9
5
|
path,
|
|
6
|
+
createPathHelpers,
|
|
10
7
|
pathUrl,
|
|
11
8
|
getCurrentDirname,
|
|
12
9
|
getCurrentFilename,
|
|
13
10
|
resolvePath,
|
|
14
11
|
relativePath,
|
|
15
12
|
fileUrlToPath,
|
|
16
|
-
} from "
|
|
13
|
+
} from "./path.mjs";
|
|
14
|
+
export type { PathLogger, PathHelpersOptions, PathHelpers } from "./path.mjs";
|
|
17
15
|
export {
|
|
18
16
|
createSnowflakeGenerator,
|
|
19
17
|
generate,
|
|
20
18
|
default as snowflake,
|
|
21
19
|
constants,
|
|
22
|
-
} from "
|
|
23
|
-
export type { SnowflakeGeneratorOptions, SnowflakeConstants } from "
|
|
20
|
+
} from "./snowflake.mjs";
|
|
21
|
+
export type { SnowflakeGeneratorOptions, SnowflakeConstants } from "./snowflake.mjs";
|
|
24
22
|
export {
|
|
25
23
|
createPolicy,
|
|
26
24
|
defaultPolicy,
|
|
@@ -35,13 +33,21 @@ export type {
|
|
|
35
33
|
StructuredRedactionOptions,
|
|
36
34
|
TextRedactionOptions,
|
|
37
35
|
} from "@eliware/redact";
|
|
38
|
-
export { default as registerHandlers } from "
|
|
36
|
+
export { default as registerHandlers } from "./errors.mjs";
|
|
37
|
+
export { defaultEvents } from "./errors.mjs";
|
|
39
38
|
export { default as registerSignals } from "@eliware/signals";
|
|
40
39
|
export type {
|
|
40
|
+
Logger,
|
|
41
|
+
ProcessEvent,
|
|
42
|
+
ProcessListener,
|
|
43
|
+
ProcessLike,
|
|
41
44
|
RegisterHandlersOptions,
|
|
42
45
|
RegisteredHandlers,
|
|
46
|
+
} from "./errors.mjs";
|
|
47
|
+
export type {
|
|
48
|
+
NodeSignal,
|
|
49
|
+
ProcessLike as SignalsProcessLike,
|
|
50
|
+
SignalsLogger,
|
|
43
51
|
RegisterSignalsOptions,
|
|
44
52
|
SignalsRegistration,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type Logger = typeof logger;
|
|
53
|
+
} from "@eliware/signals";
|
package/src/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ export { default as fs } from "./fs.mjs";
|
|
|
2
2
|
export { default as log, createLogger, safeSerialize } from "./log.mjs";
|
|
3
3
|
export {
|
|
4
4
|
default as path,
|
|
5
|
+
createPathHelpers,
|
|
5
6
|
pathUrl,
|
|
6
7
|
getCurrentDirname,
|
|
7
8
|
getCurrentFilename,
|
|
@@ -23,5 +24,5 @@ export {
|
|
|
23
24
|
redactText,
|
|
24
25
|
replaceLiteralSecret,
|
|
25
26
|
} from "@eliware/redact";
|
|
26
|
-
export { default as registerHandlers } from "./errors.mjs";
|
|
27
|
+
export { defaultEvents, default as registerHandlers } from "./errors.mjs";
|
|
27
28
|
export { default as registerSignals } from "./signals.mjs";
|
package/src/log.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type SafeSerializedValue =
|
|
2
|
+
null | boolean | number | string | SafeSerializedValue[] | { [key: string]: SafeSerializedValue };
|
|
3
|
+
|
|
4
|
+
export declare function createLogger(options?: {
|
|
5
|
+
level?: string;
|
|
6
|
+
transports?: import("winston-transport")[];
|
|
7
|
+
format?: "text" | "json";
|
|
8
|
+
timestamp?: boolean;
|
|
9
|
+
keys?: string[];
|
|
10
|
+
}): import("winston").Logger & {
|
|
11
|
+
debug(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
12
|
+
info(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
13
|
+
warn(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
14
|
+
error(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export declare function safeSerialize(
|
|
18
|
+
value: unknown,
|
|
19
|
+
options?: import("@eliware/redact").SerializationOptions,
|
|
20
|
+
): SafeSerializedValue;
|
|
21
|
+
|
|
22
|
+
export declare const log: import("winston").Logger & {
|
|
23
|
+
debug(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
24
|
+
info(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
25
|
+
warn(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
26
|
+
error(message: unknown, meta?: unknown, ...args: unknown[]): import("winston").Logger;
|
|
27
|
+
} & { [level: string]: unknown };
|
|
28
|
+
|
|
29
|
+
export default log;
|
package/src/path.d.mts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Returns the current filename from import.meta or the supplied directory string. */
|
|
2
|
+
export declare function getCurrentFilename(metaOrDir: ImportMeta | string): string;
|
|
3
|
+
|
|
4
|
+
/** Returns the current directory from import.meta or the supplied directory string. */
|
|
5
|
+
export declare function getCurrentDirname(
|
|
6
|
+
metaOrDir: ImportMeta | string,
|
|
7
|
+
dirnameFn?: (path: string) => string,
|
|
8
|
+
): string;
|
|
9
|
+
|
|
10
|
+
/** Joins the current directory with path segments. */
|
|
11
|
+
export declare const path: (metaOrDir: ImportMeta | string, ...segments: string[]) => string;
|
|
12
|
+
|
|
13
|
+
/** Converts a resolved path to a file URL string. */
|
|
14
|
+
export declare function pathUrl(metaOrDir: ImportMeta | string, ...segments: string[]): string;
|
|
15
|
+
|
|
16
|
+
/** Resolves path segments from the module directory. */
|
|
17
|
+
export declare function resolvePath(metaOrDir: ImportMeta | string, ...segments: string[]): string;
|
|
18
|
+
|
|
19
|
+
/** Returns a path relative to the module directory. */
|
|
20
|
+
export declare function relativePath(metaOrDir: ImportMeta | string, ...segments: string[]): string;
|
|
21
|
+
|
|
22
|
+
/** Converts a file URL string or URL object to a file path. */
|
|
23
|
+
export declare function fileUrlToPath(fileUrl: string | URL): string;
|
|
24
|
+
|
|
25
|
+
/** A logger that accepts structured Winston-style records. */
|
|
26
|
+
export type PathLogger = Pick<import("winston").Logger, "log">;
|
|
27
|
+
|
|
28
|
+
/** Options for path helpers with an injected logger. */
|
|
29
|
+
export interface PathHelpersOptions {
|
|
30
|
+
logger?: PathLogger;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Path helper functions that write structured records to the supplied logger. */
|
|
34
|
+
export interface PathHelpers {
|
|
35
|
+
getCurrentFilename(metaOrDir: ImportMeta | string): string;
|
|
36
|
+
getCurrentDirname(metaOrDir: ImportMeta | string, dirnameFn?: (path: string) => string): string;
|
|
37
|
+
path(metaOrDir: ImportMeta | string, ...segments: string[]): string;
|
|
38
|
+
pathUrl(metaOrDir: ImportMeta | string, ...segments: string[]): string;
|
|
39
|
+
resolvePath(metaOrDir: ImportMeta | string, ...segments: string[]): string;
|
|
40
|
+
relativePath(metaOrDir: ImportMeta | string, ...segments: string[]): string;
|
|
41
|
+
fileUrlToPath(fileUrl: string | URL): string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Creates path helpers that write safe operation records. */
|
|
45
|
+
export declare function createPathHelpers(options?: PathHelpersOptions): PathHelpers;
|
|
46
|
+
|
|
47
|
+
export default path;
|
package/src/path.mjs
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface SnowflakeGeneratorOptions {
|
|
2
|
+
epoch?: number | bigint;
|
|
3
|
+
workerId?: number | bigint;
|
|
4
|
+
processId?: number | bigint;
|
|
5
|
+
now?: () => number | bigint;
|
|
6
|
+
logger?: import("winston").Logger;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SnowflakeConstants {
|
|
10
|
+
readonly epoch: bigint;
|
|
11
|
+
readonly sequenceBits: bigint;
|
|
12
|
+
readonly processBits: bigint;
|
|
13
|
+
readonly workerBits: bigint;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare function createSnowflakeGenerator(options?: SnowflakeGeneratorOptions): () => string;
|
|
17
|
+
|
|
18
|
+
export declare const generate: () => string;
|
|
19
|
+
export declare const snowflake: typeof generate;
|
|
20
|
+
export declare const constants: SnowflakeConstants;
|
|
21
|
+
|
|
22
|
+
export default generate;
|