@eliware/common 2.0.0 → 12.0.1
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 +55 -0
- package/LICENSE +2 -2
- package/README.md +55 -70
- package/RELEASE_NOTES.md +58 -23
- package/docs/README.md +12 -0
- package/docs/api.md +137 -0
- package/docs/package.md +45 -0
- package/docs/troubleshooting.md +47 -0
- package/docs/usage.md +143 -0
- package/examples/README.md +21 -0
- package/examples/example.mjs +11 -12
- package/examples/snowflake.mjs +4 -0
- package/package.json +115 -60
- package/specs/README.md +3 -0
- package/specs/directives.yaml +15 -0
- package/src/errors.mjs +1 -1
- package/src/fs.mjs +1 -1
- package/src/index.d.ts +47 -0
- package/src/index.mjs +27 -0
- package/src/log.mjs +1 -1
- package/src/path.mjs +10 -2
- package/src/signals.mjs +1 -1
- package/index.d.ts +0 -33
- package/index.mjs +0 -13
package/AGENTS.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Project
|
|
4
|
+
|
|
5
|
+
Maintain `@eliware/common`, a native ESM library for shared Eliware APIs.
|
|
6
|
+
Use Node.js 26 or later.
|
|
7
|
+
|
|
8
|
+
## Scope and boundaries
|
|
9
|
+
|
|
10
|
+
Keep this repository to the package, its user docs, examples, tests, and specs.
|
|
11
|
+
Get Eliware Operations approval before publication.
|
|
12
|
+
|
|
13
|
+
## Layout
|
|
14
|
+
|
|
15
|
+
Put runtime modules and declarations in `src/`.
|
|
16
|
+
Put one matching test in `tests/` for each runtime module.
|
|
17
|
+
Put user docs in `docs/`, examples in `examples/`, and specs in `specs/`.
|
|
18
|
+
|
|
19
|
+
## Development
|
|
20
|
+
|
|
21
|
+
Use native ESM.
|
|
22
|
+
Keep `src/index.mjs` as the public export barrel.
|
|
23
|
+
Keep docs, declarations, package data, and tests in sync.
|
|
24
|
+
|
|
25
|
+
## Validation
|
|
26
|
+
|
|
27
|
+
Run `npm test` for all checks.
|
|
28
|
+
Run `npm run lint` for lint checks.
|
|
29
|
+
Run `npm run audit` for dependency checks.
|
|
30
|
+
Run `npm run format` to format files.
|
|
31
|
+
Run `npm run format:check` to check file format.
|
|
32
|
+
Run `npm run typecheck` to check declarations.
|
|
33
|
+
Run `npm run pack` to check package contents.
|
|
34
|
+
|
|
35
|
+
## Security
|
|
36
|
+
|
|
37
|
+
Keep secrets, credentials, private data, and machine paths out of tracked files.
|
|
38
|
+
Review dependency behavior and update dependencies before publication.
|
|
39
|
+
|
|
40
|
+
## Changes
|
|
41
|
+
|
|
42
|
+
Describe user-visible changes in `RELEASE_NOTES.md`.
|
|
43
|
+
Keep release notes accurate.
|
|
44
|
+
|
|
45
|
+
## Library
|
|
46
|
+
|
|
47
|
+
Export runtime APIs from `src/index.mjs` and types from `src/index.d.ts`.
|
|
48
|
+
Mirror each runtime module with one test.
|
|
49
|
+
Keep native ESM examples in `examples/`.
|
|
50
|
+
|
|
51
|
+
## npm publication
|
|
52
|
+
|
|
53
|
+
Set the package version in `package.json`.
|
|
54
|
+
Use the Eliware Operations publication checklist.
|
|
55
|
+
Passing checks does not approve publication.
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 Eliware
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,106 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# [](https://discord.gg/M6aTR9eTwN)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## @eliware/common [](https://www.npmjs.com/package/@eliware/common) [](https://github.com/eliware/common/blob/main/LICENSE) [](https://github.com/eliware/common/actions/workflows/ci.yaml)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A shared ESM compatibility package for Eliware filesystem, path, logging, error, and signal APIs.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- Node.js `>=26`
|
|
9
|
-
- Published Eliware dependency packages matching the versions in `package.json`
|
|
7
|
+
## Table of Contents
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
- [Features](#features)
|
|
10
|
+
- [Requirements](#requirements)
|
|
11
|
+
- [Setup](#setup)
|
|
12
|
+
- [Usage](#usage)
|
|
13
|
+
- [Development](#development)
|
|
14
|
+
- [Testing](#testing)
|
|
15
|
+
- [Troubleshooting](#troubleshooting)
|
|
16
|
+
- [Security](#security)
|
|
17
|
+
- [API](#api)
|
|
18
|
+
- [Packaging](#packaging)
|
|
19
|
+
- [Examples](#examples)
|
|
20
|
+
- [Support](#support)
|
|
21
|
+
- [Links](#links)
|
|
22
|
+
- [License](#license)
|
|
12
23
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
Import shared Eliware APIs, including secret-redaction tools, from `@eliware/common`.
|
|
16
27
|
|
|
17
|
-
##
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
Use Node.js 26 or later.
|
|
18
31
|
|
|
19
|
-
|
|
32
|
+
## Setup
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
- `@eliware/path`: `path`, `pathUrl`, `getCurrentDirname`, `getCurrentFilename`, `resolvePath`, `relativePath`, `fileUrlToPath`
|
|
23
|
-
- `@eliware/errors`: `registerHandlers`
|
|
24
|
-
- `@eliware/signals`: `registerSignals`
|
|
25
|
-
- Node.js `fs`
|
|
34
|
+
Install the package.
|
|
26
35
|
|
|
27
|
-
|
|
36
|
+
```text
|
|
37
|
+
npm install @eliware/common
|
|
38
|
+
```
|
|
28
39
|
|
|
29
40
|
## Usage
|
|
30
41
|
|
|
31
|
-
|
|
32
|
-
import {
|
|
33
|
-
fs,
|
|
34
|
-
log,
|
|
35
|
-
path,
|
|
36
|
-
pathUrl,
|
|
37
|
-
resolvePath,
|
|
38
|
-
registerHandlers,
|
|
39
|
-
registerSignals,
|
|
40
|
-
} from '@eliware/common';
|
|
42
|
+
Read the [user docs](docs/README.md) and [release notes](RELEASE_NOTES.md).
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
const configUrl = pathUrl(import.meta, '.env');
|
|
44
|
-
const absolutePath = resolvePath(import.meta, 'config');
|
|
44
|
+
## Development
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
log.info(`Files: ${fs.readdirSync(path(import.meta)).join(', ')}`);
|
|
46
|
+
Read the [examples index](examples/README.md) and [specifications index](specs/README.md).
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
const signals = registerSignals({ shutdownHook: async () => errors.removeHandlers() });
|
|
48
|
+
## Testing
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
```
|
|
50
|
+
Run `npm test` to check the repository.
|
|
54
51
|
|
|
55
|
-
##
|
|
52
|
+
## Troubleshooting
|
|
56
53
|
|
|
57
|
-
|
|
54
|
+
Read the [troubleshooting guide](docs/troubleshooting.md).
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
import {
|
|
61
|
-
createLogger,
|
|
62
|
-
getCurrentDirname,
|
|
63
|
-
registerSignals,
|
|
64
|
-
type RegisterSignalsOptions,
|
|
65
|
-
} from '@eliware/common';
|
|
56
|
+
## Security
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
const directory = getCurrentDirname(import.meta);
|
|
69
|
-
const options: RegisterSignalsOptions = { exit: false };
|
|
70
|
-
const registration = registerSignals(options);
|
|
71
|
-
```
|
|
58
|
+
Keep secrets and credentials out of logs and examples. Use redaction tools as an extra safeguard.
|
|
72
59
|
|
|
73
|
-
##
|
|
60
|
+
## API
|
|
74
61
|
|
|
75
|
-
|
|
62
|
+
Read the [API reference](docs/api.md) for exported values and types.
|
|
76
63
|
|
|
77
|
-
##
|
|
64
|
+
## Packaging
|
|
78
65
|
|
|
79
|
-
|
|
66
|
+
Use native ESM. Read the [package guide](docs/package.md) for entry points and files.
|
|
80
67
|
|
|
81
|
-
##
|
|
68
|
+
## Examples
|
|
82
69
|
|
|
83
|
-
|
|
84
|
-
npm install
|
|
85
|
-
npm test
|
|
86
|
-
npm run lint
|
|
87
|
-
npm run typecheck
|
|
88
|
-
npm run pack
|
|
89
|
-
npm audit --omit=dev --audit-level=moderate
|
|
90
|
-
```
|
|
70
|
+
Run the [native ESM examples](examples/README.md) with Node.js 26 or later.
|
|
91
71
|
|
|
92
|
-
|
|
72
|
+
## Support
|
|
93
73
|
|
|
94
|
-
|
|
74
|
+
For help, questions, or to chat with the author and community, visit:
|
|
75
|
+
|
|
76
|
+
[](https://discord.gg/M6aTR9eTwN)[](https://discord.gg/M6aTR9eTwN)
|
|
95
77
|
|
|
96
|
-
|
|
78
|
+
**[eliware.org on Discord](https://discord.gg/M6aTR9eTwN)**
|
|
97
79
|
|
|
98
80
|
## Links
|
|
99
81
|
|
|
100
|
-
- [
|
|
82
|
+
- [Home Page](https://eliware.org)
|
|
83
|
+
- [GitHub Org](https://github.com/eliware)
|
|
84
|
+
- [GitHub Repo](https://github.com/eliware/common)
|
|
85
|
+
- [Bug Reports](https://github.com/eliware/common/issues)
|
|
101
86
|
- [npm](https://www.npmjs.com/package/@eliware/common)
|
|
102
|
-
- [
|
|
87
|
+
- [Discord](https://discord.gg/M6aTR9eTwN)
|
|
103
88
|
|
|
104
89
|
## License
|
|
105
90
|
|
|
106
|
-
[MIT](LICENSE)
|
|
91
|
+
[MIT © Eliware](LICENSE)
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -1,64 +1,99 @@
|
|
|
1
|
-
# Release
|
|
1
|
+
# Release Notes
|
|
2
|
+
|
|
3
|
+
## 12.0.1 — 2026-10-12
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added `@eliware/redact` APIs and TypeScript option types.
|
|
8
|
+
|
|
9
|
+
## 12.0.0 — 2026-10-12
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Added Snowflake ID exports, constants, and TypeScript types.
|
|
14
|
+
- Added user docs for APIs, package contents, setup, and troubleshooting.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Updated the Eliware runtime dependencies to major version 12.
|
|
19
|
+
- Moved the public runtime and declaration entry points into `src/`.
|
|
20
|
+
|
|
21
|
+
### Breaking changes
|
|
22
|
+
|
|
23
|
+
- Removed the root-level `index.mjs` and `index.d.ts` files. Import from `@eliware/common`.
|
|
24
|
+
- Require major version 12 of the Eliware runtime dependencies.
|
|
2
25
|
|
|
3
26
|
## 2.0.0 — 2026-08-25
|
|
4
27
|
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
5
30
|
- Modernized the package for the shared Eliware conventions and Node.js `>=26`.
|
|
6
31
|
- Replaced direct Jest tooling with `@eliware/test`, including enforced 100×4 coverage and shared linting.
|
|
7
32
|
- Updated CI for Ubuntu and Windows validation on `main`, pull requests, and `v*` tags, with gated publishing.
|
|
8
33
|
- Updated package metadata, documentation, and dependency auditing.
|
|
9
|
-
|
|
10
|
-
|
|
34
|
+
|
|
35
|
+
### Breaking changes
|
|
36
|
+
|
|
37
|
+
- Required Node.js `>=26`.
|
|
38
|
+
- Replaced direct Jest and Oxlint project tooling with the shared `@eliware/test` harness.
|
|
11
39
|
|
|
12
40
|
## 1.1.8 — 2026-08-10
|
|
13
41
|
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
14
44
|
- Updated `@eliware/errors` to 1.1.9, `@eliware/log` to 1.1.12, and `@eliware/signals` to 1.1.7.
|
|
15
45
|
- Added the `safeSerialize` TypeScript declaration to match the runtime export.
|
|
16
46
|
- Updated signal handler contract coverage for the current upstream listener behavior.
|
|
17
47
|
|
|
18
|
-
|
|
19
48
|
## 1.1.7 — 2026-08-07
|
|
20
49
|
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
21
52
|
- Standardized package layout, validation scripts, TypeScript checking, CI, and package contents.
|
|
22
53
|
- Updated internal dependencies to the latest released Eliware versions.
|
|
23
54
|
- Expanded troubleshooting, development, and security documentation.
|
|
24
55
|
|
|
25
|
-
## 1.1.6 —
|
|
56
|
+
## 1.1.6 — 2026-08-07
|
|
57
|
+
|
|
58
|
+
### Changed
|
|
26
59
|
|
|
27
60
|
- Updated `@eliware/errors`, `@eliware/log`, `@eliware/path`, and `@eliware/signals` to current releases.
|
|
28
61
|
- Standardized Jest coverage on the V8 provider for accurate ESM coverage reporting.
|
|
29
62
|
|
|
30
|
-
## 1.1.5 —
|
|
63
|
+
## 1.1.5 — 2026-08-06
|
|
31
64
|
|
|
32
65
|
### Changed
|
|
33
66
|
|
|
34
67
|
- Refactored the package into focused ESM modules under `src/`.
|
|
35
|
-
- Expanded the unified export surface to include the current public APIs from
|
|
36
|
-
- Added logger exports
|
|
37
|
-
- Added path exports: `resolvePath`, `relativePath`, and `fileUrlToPath`.
|
|
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`.
|
|
38
70
|
- Updated TypeScript declarations for the expanded API and dependency option types.
|
|
39
71
|
- Replaced CommonJS entry points and tests with ESM-only files.
|
|
40
|
-
- Expanded contract tests for
|
|
41
|
-
- Updated README,
|
|
42
|
-
- Standardized linting, coverage scripts, CI
|
|
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.
|
|
43
75
|
|
|
44
|
-
|
|
76
|
+
## 1.1.4 — 2026-07-01
|
|
45
77
|
|
|
46
|
-
|
|
47
|
-
- Lint passes with zero warnings and errors.
|
|
48
|
-
|
|
49
|
-
## 1.1.4 — July 1, 2026
|
|
78
|
+
### Changed
|
|
50
79
|
|
|
51
80
|
- Updated package metadata and dependencies.
|
|
52
81
|
- Refreshed the lockfile and standardized repository tooling.
|
|
53
82
|
|
|
54
|
-
## 1.1.3 —
|
|
83
|
+
## 1.1.3 — 2025-12-21
|
|
84
|
+
|
|
85
|
+
### Changed
|
|
55
86
|
|
|
56
|
-
-
|
|
87
|
+
- Released maintenance updates.
|
|
88
|
+
|
|
89
|
+
## 1.1.2 — 2025-12-21
|
|
90
|
+
|
|
91
|
+
### Changed
|
|
57
92
|
|
|
58
|
-
|
|
93
|
+
- Released maintenance updates.
|
|
59
94
|
|
|
60
|
-
|
|
95
|
+
## 1.1.1 — 2025-12-09
|
|
61
96
|
|
|
62
|
-
|
|
97
|
+
### Added
|
|
63
98
|
|
|
64
|
-
-
|
|
99
|
+
- Released the first tagged version of the common ESM utility package.
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# User docs
|
|
2
|
+
|
|
3
|
+
Use these guides to install and use `@eliware/common`.
|
|
4
|
+
|
|
5
|
+
## Guides
|
|
6
|
+
|
|
7
|
+
- [Setup and usage](usage.md)
|
|
8
|
+
- [API reference](api.md)
|
|
9
|
+
- [Package contents and compatibility](package.md)
|
|
10
|
+
- [Troubleshooting](troubleshooting.md)
|
|
11
|
+
|
|
12
|
+
Use Node.js 26 or later. Use an ESM project.
|
package/docs/api.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
Import public values from `@eliware/common`.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { fs, log, path, createSnowflakeGenerator } from "@eliware/common";
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The package re-exports APIs from Node.js and the Eliware packages listed in [package contents](package.md).
|
|
10
|
+
|
|
11
|
+
## File system
|
|
12
|
+
|
|
13
|
+
`fs` is the Node.js `fs` module namespace. Use its standard functions, such as `readFile`, `readdir`, and `stat`.
|
|
14
|
+
Read the [Node.js file system API](https://nodejs.org/api/fs.html) for functions, options, and errors.
|
|
15
|
+
|
|
16
|
+
## Path helpers
|
|
17
|
+
|
|
18
|
+
| Export | Call | Result |
|
|
19
|
+
| -------------------- | ------------------------------------------ | -------------------------------------------------- |
|
|
20
|
+
| `path` | `path(metaOrDir, ...segments)` | Join segments to a module directory. |
|
|
21
|
+
| `pathUrl` | `pathUrl(metaOrDir, ...segments)` | Return a file URL string. |
|
|
22
|
+
| `getCurrentDirname` | `getCurrentDirname(metaOrDir, dirnameFn?)` | Return the module directory. |
|
|
23
|
+
| `getCurrentFilename` | `getCurrentFilename(metaOrDir)` | Return the module filename or input string. |
|
|
24
|
+
| `resolvePath` | `resolvePath(metaOrDir, ...segments)` | Return an absolute path. |
|
|
25
|
+
| `relativePath` | `relativePath(metaOrDir, ...segments)` | Return a path from the module directory. |
|
|
26
|
+
| `fileUrlToPath` | `fileUrlToPath(fileUrl)` | Convert a file URL string or `URL` to a file path. |
|
|
27
|
+
|
|
28
|
+
Pass `import.meta` or a directory string as `metaOrDir`. Pass `dirnameFn` only with `import.meta`.
|
|
29
|
+
The default export from `@eliware/path` is named `path` here.
|
|
30
|
+
Read the [path package docs](https://github.com/eliware/path/tree/main/docs) for details.
|
|
31
|
+
|
|
32
|
+
## Log APIs
|
|
33
|
+
|
|
34
|
+
| Export | Call | Result |
|
|
35
|
+
| --------------- | ----------------------------------------------- | ------------------------------------------------ |
|
|
36
|
+
| `log` | `log.debug/info/warn/error(message, metadata?)` | Use the shared default logger. |
|
|
37
|
+
| `createLogger` | `createLogger(options?)` | Create a logger instance. |
|
|
38
|
+
| `safeSerialize` | `safeSerialize(value, options?)` | Return JSON-safe data with redaction and limits. |
|
|
39
|
+
|
|
40
|
+
`createLogger` accepts `level`, `transports`, `format`, `timestamp`, and `keys` options.
|
|
41
|
+
Use `format: "text"` or `format: "json"`. The default level is `info`.
|
|
42
|
+
The other defaults are a console transport, text format, no timestamp, and no custom redaction keys.
|
|
43
|
+
`safeSerialize` accepts `keys`, `redactKeys`, `marker`, `circularMarker`, `maxDepth`, `maxKeys`, `maxArray`, and `maxString` options.
|
|
44
|
+
It does not call `toJSON`. It uses default secret keys and limits when you omit options.
|
|
45
|
+
It returns JSON-safe values. It converts BigInt values to text and marks circular or truncated values.
|
|
46
|
+
Read the [log package docs](https://github.com/eliware/log/tree/main/docs) for defaults and details.
|
|
47
|
+
|
|
48
|
+
## Redaction APIs
|
|
49
|
+
|
|
50
|
+
`defaultPolicy` provides the default sensitive key names and marker.
|
|
51
|
+
Call `createPolicy(options?)` to make a frozen policy with custom key names or markers.
|
|
52
|
+
Call `redactValue(value, options?)` to return a redacted copy of an object or array.
|
|
53
|
+
Call `redactHeaders(headers, options?)` to redact header values in an object, pair array, or entries object.
|
|
54
|
+
Call `redactText(value, options?)` to redact common credential patterns, custom key values, and literal secrets.
|
|
55
|
+
Call `replaceLiteralSecret(value, secret, marker?)` to replace one exact secret in text.
|
|
56
|
+
|
|
57
|
+
Policy options include `keys`, `redactKeys`, `marker`, and `circularMarker`.
|
|
58
|
+
Structured values also support `maxDepth`, `maxKeys`, and `maxArray` limits.
|
|
59
|
+
Text also supports `secrets` and the `maxOutputLength` limit.
|
|
60
|
+
The default marker is `[REDACTED]`. The default text limit is 10,000 characters.
|
|
61
|
+
`redactText` detects authorization values, secret assignments, provider tokens, JWT-like strings, and key blocks.
|
|
62
|
+
`redactValue` returns a copy and does not change its input.
|
|
63
|
+
`redactHeaders` keeps the input shape for objects and pair arrays. It returns a lowercase object for entries objects.
|
|
64
|
+
The `safeSerialize` export in Log APIs is the same function as `@eliware/redact` exports.
|
|
65
|
+
Read the [Redact API guide](https://github.com/eliware/redact/blob/main/docs/api.md) for full rules and limits.
|
|
66
|
+
|
|
67
|
+
## Error handlers
|
|
68
|
+
|
|
69
|
+
Call `registerHandlers(options?)` to register handlers for process events.
|
|
70
|
+
The default events are `uncaughtException`, `unhandledRejection`, and `warning`.
|
|
71
|
+
|
|
72
|
+
| Option | Default | Purpose |
|
|
73
|
+
| ------------ | -------------------------- | --------------------------------------------- |
|
|
74
|
+
| `processObj` | `process` | Set the process-like event source. |
|
|
75
|
+
| `log` | `@eliware/log` | Set the logger. |
|
|
76
|
+
| `events` | Three process error events | Set the events to handle. |
|
|
77
|
+
| `once` | `false` | Set one-time handler behavior. |
|
|
78
|
+
| `signal` | None | Remove handlers when an `AbortSignal` aborts. |
|
|
79
|
+
|
|
80
|
+
The result has a read-only `removed` value and a `removeHandlers()` method.
|
|
81
|
+
Set a custom logger with `error`, `warn`, and `debug` methods.
|
|
82
|
+
Pass a non-empty array of supported event names. The package rejects unsupported event names.
|
|
83
|
+
Read the [errors package docs](https://github.com/eliware/errors/tree/main/docs) for event behavior and errors.
|
|
84
|
+
|
|
85
|
+
## Shutdown handlers
|
|
86
|
+
|
|
87
|
+
Call `registerSignals(options?)` to register process shutdown handlers.
|
|
88
|
+
The default signals are `SIGTERM`, `SIGINT`, and `SIGHUP`.
|
|
89
|
+
|
|
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 to handle. |
|
|
95
|
+
| `shutdownHook` | None | Set cleanup work. The hook can return a promise. |
|
|
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. |
|
|
99
|
+
|
|
100
|
+
The result has `removed`, `shutdown(signal?)`, `getShuttingDown()`, and `removeHandlers()` members.
|
|
101
|
+
The default `exit` value is `true`. Set `exit: false` when your program controls process exit.
|
|
102
|
+
Each hook runs once. The package runs hooks in order and continues after a hook error.
|
|
103
|
+
Pass an empty `signals` array to disable signal events. A `beforeExit` handler still runs.
|
|
104
|
+
Read the [signals API docs](https://github.com/eliware/signals/blob/main/docs/api.md) for shutdown order and error behavior.
|
|
105
|
+
|
|
106
|
+
## Snowflake IDs
|
|
107
|
+
|
|
108
|
+
Call `createSnowflakeGenerator(options?)` to make a generator. Each call returns a decimal string.
|
|
109
|
+
|
|
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. |
|
|
116
|
+
|
|
117
|
+
Use one epoch for all generators in one application. Give each active generator a unique worker and process ID pair.
|
|
118
|
+
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
|
+
Each generator can create 4096 IDs per millisecond. It throws `RangeError` when time or sequence limits fail.
|
|
120
|
+
Pass a safe integer or `bigint` to `epoch`, `workerId`, and `processId`.
|
|
121
|
+
Pass a clock that returns Unix milliseconds as a safe integer or `bigint`.
|
|
122
|
+
The generator uses its last timestamp when the clock moves backward.
|
|
123
|
+
The exports `generate`, `snowflake`, and the default export from `@eliware/snowflake` use one shared generator.
|
|
124
|
+
The `constants` export provides `epoch`, `sequenceBits`, `processBits`, and `workerBits` values as `bigint`.
|
|
125
|
+
Read the [Snowflake usage guide](https://github.com/eliware/snowflake/blob/main/docs/usage.md) for timestamp bounds and clock behavior.
|
|
126
|
+
|
|
127
|
+
## TypeScript types
|
|
128
|
+
|
|
129
|
+
The package exports these types:
|
|
130
|
+
|
|
131
|
+
- `Logger`
|
|
132
|
+
- `RegisterHandlersOptions` and `RegisteredHandlers`
|
|
133
|
+
- `RegisterSignalsOptions` and `SignalsRegistration`
|
|
134
|
+
- `RedactionPolicy`, `SerializationOptions`, `StructuredRedactionOptions`, and `TextRedactionOptions`
|
|
135
|
+
- `SnowflakeGeneratorOptions` and `SnowflakeConstants`
|
|
136
|
+
|
|
137
|
+
Read the [declaration file](../src/index.d.ts) for the current type exports.
|
package/docs/package.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Package contents and compatibility
|
|
2
|
+
|
|
3
|
+
## Runtime
|
|
4
|
+
|
|
5
|
+
Use Node.js 26 or later. Use the package from a native ESM module.
|
|
6
|
+
Install `@eliware/common` from [npm](https://www.npmjs.com/package/@eliware/common).
|
|
7
|
+
|
|
8
|
+
## Entry points
|
|
9
|
+
|
|
10
|
+
Import `@eliware/common` for the public runtime APIs.
|
|
11
|
+
The runtime entry point is `src/index.mjs`.
|
|
12
|
+
The TypeScript declaration entry point is `src/index.d.ts`.
|
|
13
|
+
The package does not provide a CommonJS entry point.
|
|
14
|
+
|
|
15
|
+
## Runtime dependencies
|
|
16
|
+
|
|
17
|
+
The package uses major version 12 of these Eliware packages:
|
|
18
|
+
|
|
19
|
+
- `@eliware/errors`
|
|
20
|
+
- `@eliware/log`
|
|
21
|
+
- `@eliware/path`
|
|
22
|
+
- `@eliware/redact`
|
|
23
|
+
- `@eliware/signals`
|
|
24
|
+
- `@eliware/snowflake`
|
|
25
|
+
|
|
26
|
+
Use the exports in this package. Use each dependency directly when you need its own package entry point.
|
|
27
|
+
Read the [API reference](api.md) for each exported value.
|
|
28
|
+
|
|
29
|
+
## Published files
|
|
30
|
+
|
|
31
|
+
The npm package contains:
|
|
32
|
+
|
|
33
|
+
- `src/` for runtime modules and declarations.
|
|
34
|
+
- `docs/` for user docs.
|
|
35
|
+
- `examples/` for native ESM examples.
|
|
36
|
+
- `specs/` for repository specifications.
|
|
37
|
+
- `README.md`, `AGENTS.md`, `LICENSE`, and `RELEASE_NOTES.md`.
|
|
38
|
+
|
|
39
|
+
The package excludes tests, workflows, and lock files.
|
|
40
|
+
|
|
41
|
+
## Version and release
|
|
42
|
+
|
|
43
|
+
Use the published npm version that matches your application requirements.
|
|
44
|
+
Read [release notes](../RELEASE_NOTES.md) for changes by package version.
|
|
45
|
+
Repository validation does not publish this package. Follow the Eliware Operations release process before publication.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
## Import errors
|
|
4
|
+
|
|
5
|
+
Use Node.js 26 or later.
|
|
6
|
+
Set the project to native ESM.
|
|
7
|
+
Run `npm install @eliware/common` to install the package and its dependencies.
|
|
8
|
+
Import from `@eliware/common`. Do not import private files under `src/`.
|
|
9
|
+
|
|
10
|
+
## Type errors
|
|
11
|
+
|
|
12
|
+
Use the package types that match the installed package version.
|
|
13
|
+
Run `npm install` to update the lock file after a version change.
|
|
14
|
+
Read the [API reference](api.md) and [declaration file](../src/index.d.ts).
|
|
15
|
+
|
|
16
|
+
## Path errors
|
|
17
|
+
|
|
18
|
+
Pass `import.meta` or a directory string to a path helper.
|
|
19
|
+
Pass a file URL to `fileUrlToPath`.
|
|
20
|
+
Read the [path API section](api.md#path-helpers) for each helper's result.
|
|
21
|
+
|
|
22
|
+
## Log errors
|
|
23
|
+
|
|
24
|
+
Check the `level`, `transports`, and `format` options passed to `createLogger`.
|
|
25
|
+
Pass a logger with `debug`, `info`, `warn`, and `error` methods where required.
|
|
26
|
+
Remove secret values before you write metadata to logs.
|
|
27
|
+
|
|
28
|
+
## Process handler errors
|
|
29
|
+
|
|
30
|
+
Keep each handler registration while you need it.
|
|
31
|
+
Call `removeHandlers()` to remove error or signal handlers.
|
|
32
|
+
Pass a valid process-like object and event names.
|
|
33
|
+
Read the [API reference](api.md#error-handlers) and [shutdown handler guide](api.md#shutdown-handlers).
|
|
34
|
+
|
|
35
|
+
## Snowflake errors
|
|
36
|
+
|
|
37
|
+
Give each active generator a unique worker and process ID pair.
|
|
38
|
+
Keep generated IDs as decimal strings. Do not convert them to `number`.
|
|
39
|
+
Wait for the clock to advance after a sequence limit error.
|
|
40
|
+
Check the epoch and clock when the generator reports a timestamp error.
|
|
41
|
+
Read [Snowflake IDs](api.md#snowflake-ids) for limits and clock behavior.
|
|
42
|
+
|
|
43
|
+
## Repository checks
|
|
44
|
+
|
|
45
|
+
Run `npm ci` to install locked dependencies.
|
|
46
|
+
Run `npm test` to check the repository.
|
|
47
|
+
Fix the first reported error, then run `npm test` again.
|
package/docs/usage.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Setup and usage
|
|
2
|
+
|
|
3
|
+
## Requirements
|
|
4
|
+
|
|
5
|
+
Use Node.js 26 or later. Use a project with native ESM.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Install `@eliware/common` from npm.
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
npm install @eliware/common
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The package installs its Eliware runtime dependencies.
|
|
16
|
+
|
|
17
|
+
## Import public APIs
|
|
18
|
+
|
|
19
|
+
Import the APIs that your program needs.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import {
|
|
23
|
+
createSnowflakeGenerator,
|
|
24
|
+
fs,
|
|
25
|
+
log,
|
|
26
|
+
path,
|
|
27
|
+
registerHandlers,
|
|
28
|
+
registerSignals,
|
|
29
|
+
} from "@eliware/common";
|
|
30
|
+
|
|
31
|
+
const configFile = path(import.meta, "config.json");
|
|
32
|
+
const createId = createSnowflakeGenerator({ workerId: 1, processId: 1 });
|
|
33
|
+
|
|
34
|
+
log.info("Read configuration", { configFile, id: createId() });
|
|
35
|
+
const handlers = registerHandlers();
|
|
36
|
+
const keepAlive = setInterval(() => log.info("Waiting for SIGTERM or SIGINT."), 60_000);
|
|
37
|
+
|
|
38
|
+
registerSignals({
|
|
39
|
+
shutdownHook: () => {
|
|
40
|
+
clearInterval(keepAlive);
|
|
41
|
+
handlers.removeHandlers();
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log(fs.existsSync(configFile));
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This code logs one Snowflake ID and checks one file. It stays active until a signal starts shutdown.
|
|
49
|
+
The shutdown hook stops the timer and removes the error handlers.
|
|
50
|
+
|
|
51
|
+
## Use path helpers
|
|
52
|
+
|
|
53
|
+
Pass `import.meta` to find paths from the current module.
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import {
|
|
57
|
+
fileUrlToPath,
|
|
58
|
+
getCurrentDirname,
|
|
59
|
+
path,
|
|
60
|
+
pathUrl,
|
|
61
|
+
relativePath,
|
|
62
|
+
resolvePath,
|
|
63
|
+
} from "@eliware/common";
|
|
64
|
+
|
|
65
|
+
const directory = getCurrentDirname(import.meta);
|
|
66
|
+
const file = path(import.meta, "data", "input.json");
|
|
67
|
+
const url = pathUrl(import.meta, "data", "input.json");
|
|
68
|
+
const absolute = resolvePath(import.meta, "data", "input.json");
|
|
69
|
+
const relative = relativePath(import.meta, "data", "input.json");
|
|
70
|
+
const localFile = fileUrlToPath(url);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Pass a directory string when code does not have `import.meta`.
|
|
74
|
+
Read the [API reference](api.md) for each path helper.
|
|
75
|
+
|
|
76
|
+
## Use log APIs
|
|
77
|
+
|
|
78
|
+
Use the default `log` object or create a logger with `createLogger(options)`.
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
import { createLogger, safeSerialize } from "@eliware/common";
|
|
82
|
+
|
|
83
|
+
const logger = createLogger({ format: "json", timestamp: true });
|
|
84
|
+
logger.info("Request complete", safeSerialize({ requestId: "example" }));
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Pass metadata as the second logger argument. Use `safeSerialize` to remove secret fields before you log data.
|
|
88
|
+
|
|
89
|
+
## Redact sensitive values
|
|
90
|
+
|
|
91
|
+
Use `redactText` to remove credentials from text before you log or store it.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { redactText, redactValue } from "@eliware/common";
|
|
95
|
+
|
|
96
|
+
const message = redactText("Authorization: Bearer example-token");
|
|
97
|
+
const record = redactValue({ user: "alex", token: "example-token" });
|
|
98
|
+
console.log(message, record);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`redactText` applies common credential rules. Pass `secrets` to replace known literal values.
|
|
102
|
+
`redactValue` returns a copy with sensitive property values replaced.
|
|
103
|
+
Read the [Redaction APIs](api.md#redaction-apis) for policies, options, limits, and header handling.
|
|
104
|
+
|
|
105
|
+
## Handle process errors and signals
|
|
106
|
+
|
|
107
|
+
Call `registerHandlers(options)` to add process error handlers. Call its `removeHandlers()` method when you no longer need them.
|
|
108
|
+
Call `registerSignals(options)` to add shutdown handlers. Pass `shutdownHook` to run cleanup work.
|
|
109
|
+
Read the [API reference](api.md) for defaults, options, return values, and dependency guides.
|
|
110
|
+
|
|
111
|
+
## Create Snowflake IDs
|
|
112
|
+
|
|
113
|
+
Create one generator with a unique worker and process ID pair.
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { createSnowflakeGenerator } from "@eliware/common";
|
|
117
|
+
|
|
118
|
+
const createId = createSnowflakeGenerator({ workerId: 3, processId: 7 });
|
|
119
|
+
console.log(createId());
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Each call returns a decimal string. Keep the ID as a string in JavaScript and JSON.
|
|
123
|
+
Read the [Snowflake section in the API reference](api.md#snowflake-ids) for options and limits.
|
|
124
|
+
|
|
125
|
+
## TypeScript
|
|
126
|
+
|
|
127
|
+
Import the types with a `type` modifier.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import {
|
|
131
|
+
createSnowflakeGenerator,
|
|
132
|
+
registerSignals,
|
|
133
|
+
type RegisterSignalsOptions,
|
|
134
|
+
} from "@eliware/common";
|
|
135
|
+
|
|
136
|
+
const options: RegisterSignalsOptions = { exit: false };
|
|
137
|
+
const registration = registerSignals(options);
|
|
138
|
+
const createId = createSnowflakeGenerator();
|
|
139
|
+
console.log(createId());
|
|
140
|
+
registration.removeHandlers();
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The package includes TypeScript declarations. Read [API types](api.md#typescript-types) for the exported type names.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Use Node.js 26 or later. Install `@eliware/common` in the example project.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
- [Shared APIs](example.mjs)
|
|
8
|
+
- [Snowflake IDs](snowflake.mjs)
|
|
9
|
+
|
|
10
|
+
## Shared APIs
|
|
11
|
+
|
|
12
|
+
Run `node examples/example.mjs` from the project root.
|
|
13
|
+
The example logs paths and registers error and shutdown handlers.
|
|
14
|
+
It stays active and logs a wait message each minute.
|
|
15
|
+
Send `SIGTERM` or `SIGINT` to start shutdown.
|
|
16
|
+
The shutdown hook stops the timer and removes the error handlers.
|
|
17
|
+
|
|
18
|
+
## Snowflake IDs
|
|
19
|
+
|
|
20
|
+
Run `node examples/snowflake.mjs` from the project root.
|
|
21
|
+
The example writes one decimal ID string.
|
package/examples/example.mjs
CHANGED
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
resolvePath,
|
|
7
7
|
registerHandlers,
|
|
8
8
|
registerSignals,
|
|
9
|
-
} from
|
|
9
|
+
} from "@eliware/common";
|
|
10
10
|
|
|
11
|
-
const configPath = path(import.meta,
|
|
12
|
-
const configUrl = pathUrl(import.meta,
|
|
11
|
+
const configPath = path(import.meta, ".env");
|
|
12
|
+
const configUrl = pathUrl(import.meta, ".env");
|
|
13
13
|
const configDirectory = resolvePath(import.meta);
|
|
14
14
|
|
|
15
|
-
log.info(
|
|
15
|
+
log.info("Common package example", {
|
|
16
16
|
configPath,
|
|
17
17
|
configUrl,
|
|
18
18
|
configDirectory,
|
|
@@ -20,18 +20,17 @@ log.info('Common package example', {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
const errorHandlers = registerHandlers({
|
|
23
|
-
events: [
|
|
23
|
+
events: ["uncaughtException", "unhandledRejection"],
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const keepAlive = setInterval(() => log.info("Waiting for SIGTERM or SIGINT."), 60_000);
|
|
27
|
+
|
|
28
|
+
registerSignals({
|
|
29
|
+
shutdownHook: async (signal) => {
|
|
28
30
|
log.info(`Cleaning up after ${signal}`);
|
|
29
31
|
errorHandlers.removeHandlers();
|
|
32
|
+
clearInterval(keepAlive);
|
|
30
33
|
},
|
|
31
34
|
});
|
|
32
35
|
|
|
33
|
-
log.info(
|
|
34
|
-
|
|
35
|
-
// Keep the process alive for this demonstration; real applications usually
|
|
36
|
-
// stay alive because they have a server, worker, or other active resource.
|
|
37
|
-
void signals;
|
|
36
|
+
log.info("Handlers registered. Send SIGTERM or SIGINT to shut down gracefully.");
|
package/package.json
CHANGED
|
@@ -1,64 +1,119 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
"name": "@eliware/common",
|
|
3
|
+
"version": "12.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A shared ESM compatibility package for Eliware filesystem, path, logging, error, and signal APIs.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"nodejs",
|
|
8
|
+
"common utilities",
|
|
9
|
+
"compatibility",
|
|
10
|
+
"filesystem",
|
|
11
|
+
"logging",
|
|
12
|
+
"path utilities",
|
|
13
|
+
"error handling",
|
|
14
|
+
"signal handling",
|
|
15
|
+
"esm",
|
|
16
|
+
"typescript"
|
|
17
|
+
],
|
|
18
|
+
"private": false,
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"provenance": true
|
|
22
|
+
},
|
|
23
|
+
"main": "./src/index.mjs",
|
|
24
|
+
"files": [
|
|
25
|
+
"src/",
|
|
26
|
+
"docs/",
|
|
27
|
+
"README.md",
|
|
28
|
+
"AGENTS.md",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"RELEASE_NOTES.md",
|
|
31
|
+
"examples/",
|
|
32
|
+
"specs/"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "eliware-test",
|
|
36
|
+
"lint": "eliware-test --lint",
|
|
37
|
+
"audit": "eliware-test --audit",
|
|
38
|
+
"format": "eliware-test --format",
|
|
39
|
+
"format:check": "eliware-test --format-check",
|
|
40
|
+
"typecheck": "tsc --project tsconfig.json",
|
|
41
|
+
"pack": "eliware-test --pack"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=26"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@eliware/errors": "^12.0.0",
|
|
48
|
+
"@eliware/log": "^12.0.0",
|
|
49
|
+
"@eliware/path": "^12.0.0",
|
|
50
|
+
"@eliware/redact": "^12.0.0",
|
|
51
|
+
"@eliware/signals": "^12.0.0",
|
|
52
|
+
"@eliware/snowflake": "^12.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@eliware/test": "^12.0.0",
|
|
56
|
+
"typescript": "^7.0.2"
|
|
57
|
+
},
|
|
58
|
+
"jest": {
|
|
59
|
+
"testEnvironment": "node",
|
|
60
|
+
"testMatch": [
|
|
61
|
+
"**/tests/**/*.test.mjs"
|
|
15
62
|
],
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"import": "./index.mjs",
|
|
19
|
-
"types": "./index.d.ts"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "eliware-test",
|
|
24
|
-
"lint": "eliware-test --lint",
|
|
25
|
-
"typecheck": "tsc --project tsconfig.json",
|
|
26
|
-
"pack": "npm pack --dry-run"
|
|
27
|
-
},
|
|
28
|
-
"repository": {
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/eliware/common.git"
|
|
31
|
-
},
|
|
32
|
-
"keywords": [
|
|
33
|
-
"nodejs",
|
|
34
|
-
"common utilities",
|
|
35
|
-
"logging",
|
|
36
|
-
"path utilities",
|
|
37
|
-
"error handling",
|
|
38
|
-
"signal handling",
|
|
39
|
-
"esm",
|
|
40
|
-
"typescript"
|
|
63
|
+
"collectCoverageFrom": [
|
|
64
|
+
"src/**/*.mjs"
|
|
41
65
|
],
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
|
|
66
|
+
"coverageReporters": [
|
|
67
|
+
"text",
|
|
68
|
+
"json-summary"
|
|
69
|
+
],
|
|
70
|
+
"coverageThreshold": {
|
|
71
|
+
"global": {
|
|
72
|
+
"branches": 100,
|
|
73
|
+
"functions": 100,
|
|
74
|
+
"lines": 100,
|
|
75
|
+
"statements": 100
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"prettier": {
|
|
80
|
+
"printWidth": 100,
|
|
81
|
+
"tabWidth": 2,
|
|
82
|
+
"useTabs": false,
|
|
83
|
+
"semi": true,
|
|
84
|
+
"singleQuote": false,
|
|
85
|
+
"quoteProps": "as-needed",
|
|
86
|
+
"jsxSingleQuote": false,
|
|
87
|
+
"trailingComma": "all",
|
|
88
|
+
"bracketSpacing": true,
|
|
89
|
+
"bracketSameLine": false,
|
|
90
|
+
"arrowParens": "always",
|
|
91
|
+
"proseWrap": "preserve",
|
|
92
|
+
"endOfLine": "lf"
|
|
93
|
+
},
|
|
94
|
+
"author": "Eliware <eliware@eliware.org>",
|
|
95
|
+
"license": "MIT",
|
|
96
|
+
"repository": {
|
|
97
|
+
"type": "git",
|
|
98
|
+
"url": "git+https://github.com/eliware/common.git"
|
|
99
|
+
},
|
|
100
|
+
"homepage": "https://github.com/eliware/common#readme",
|
|
101
|
+
"bugs": {
|
|
102
|
+
"url": "https://github.com/eliware/common/issues"
|
|
103
|
+
},
|
|
104
|
+
"eliware": {
|
|
105
|
+
"id": "E-199",
|
|
106
|
+
"apply": [
|
|
107
|
+
"general",
|
|
108
|
+
"library",
|
|
109
|
+
"npm-published"
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
"types": "./src/index.d.ts",
|
|
113
|
+
"exports": {
|
|
114
|
+
".": {
|
|
115
|
+
"types": "./src/index.d.ts",
|
|
116
|
+
"import": "./src/index.mjs"
|
|
63
117
|
}
|
|
64
|
-
}
|
|
118
|
+
}
|
|
119
|
+
}
|
package/specs/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
version: "12.0"
|
|
2
|
+
description: Defines requirements for the Eliware common package.
|
|
3
|
+
directives:
|
|
4
|
+
- id: E-199.0
|
|
5
|
+
dos:
|
|
6
|
+
- Export the shared file system, path, logging, error, signal, and Snowflake APIs from the package entry point.
|
|
7
|
+
- Keep the package entry point and declaration file under src/.
|
|
8
|
+
- Mirror every source module with one test module under tests/.
|
|
9
|
+
- Use the shared Eliware packages for delegated runtime behavior.
|
|
10
|
+
- Run repository validation through eliware-test.
|
|
11
|
+
- Keep published files limited to package content and user documentation.
|
|
12
|
+
donts:
|
|
13
|
+
- Do not add global configuration or import-time work.
|
|
14
|
+
- Do not duplicate behavior owned by shared Eliware packages.
|
|
15
|
+
- Do not publish or deploy without the required approval.
|
package/src/errors.mjs
CHANGED
package/src/fs.mjs
CHANGED
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
export { fs };
|
|
7
|
+
export { createLogger, default as log, safeSerialize } from "@eliware/log";
|
|
8
|
+
export {
|
|
9
|
+
path,
|
|
10
|
+
pathUrl,
|
|
11
|
+
getCurrentDirname,
|
|
12
|
+
getCurrentFilename,
|
|
13
|
+
resolvePath,
|
|
14
|
+
relativePath,
|
|
15
|
+
fileUrlToPath,
|
|
16
|
+
} from "@eliware/path";
|
|
17
|
+
export {
|
|
18
|
+
createSnowflakeGenerator,
|
|
19
|
+
generate,
|
|
20
|
+
default as snowflake,
|
|
21
|
+
constants,
|
|
22
|
+
} from "@eliware/snowflake";
|
|
23
|
+
export type { SnowflakeGeneratorOptions, SnowflakeConstants } from "@eliware/snowflake";
|
|
24
|
+
export {
|
|
25
|
+
createPolicy,
|
|
26
|
+
defaultPolicy,
|
|
27
|
+
redactValue,
|
|
28
|
+
redactHeaders,
|
|
29
|
+
redactText,
|
|
30
|
+
replaceLiteralSecret,
|
|
31
|
+
} from "@eliware/redact";
|
|
32
|
+
export type {
|
|
33
|
+
RedactionPolicy,
|
|
34
|
+
SerializationOptions,
|
|
35
|
+
StructuredRedactionOptions,
|
|
36
|
+
TextRedactionOptions,
|
|
37
|
+
} from "@eliware/redact";
|
|
38
|
+
export { default as registerHandlers } from "@eliware/errors";
|
|
39
|
+
export { default as registerSignals } from "@eliware/signals";
|
|
40
|
+
export type {
|
|
41
|
+
RegisterHandlersOptions,
|
|
42
|
+
RegisteredHandlers,
|
|
43
|
+
RegisterSignalsOptions,
|
|
44
|
+
SignalsRegistration,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type Logger = typeof logger;
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { default as fs } from "./fs.mjs";
|
|
2
|
+
export { default as log, createLogger, safeSerialize } from "./log.mjs";
|
|
3
|
+
export {
|
|
4
|
+
default as path,
|
|
5
|
+
pathUrl,
|
|
6
|
+
getCurrentDirname,
|
|
7
|
+
getCurrentFilename,
|
|
8
|
+
resolvePath,
|
|
9
|
+
relativePath,
|
|
10
|
+
fileUrlToPath,
|
|
11
|
+
} from "./path.mjs";
|
|
12
|
+
export {
|
|
13
|
+
default as snowflake,
|
|
14
|
+
createSnowflakeGenerator,
|
|
15
|
+
generate,
|
|
16
|
+
constants,
|
|
17
|
+
} from "@eliware/snowflake";
|
|
18
|
+
export {
|
|
19
|
+
createPolicy,
|
|
20
|
+
defaultPolicy,
|
|
21
|
+
redactValue,
|
|
22
|
+
redactHeaders,
|
|
23
|
+
redactText,
|
|
24
|
+
replaceLiteralSecret,
|
|
25
|
+
} from "@eliware/redact";
|
|
26
|
+
export { default as registerHandlers } from "./errors.mjs";
|
|
27
|
+
export { default as registerSignals } from "./signals.mjs";
|
package/src/log.mjs
CHANGED
package/src/path.mjs
CHANGED
|
@@ -6,7 +6,15 @@ import {
|
|
|
6
6
|
resolvePath,
|
|
7
7
|
relativePath,
|
|
8
8
|
fileUrlToPath,
|
|
9
|
-
} from
|
|
9
|
+
} from "@eliware/path";
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
path,
|
|
13
|
+
pathUrl,
|
|
14
|
+
getCurrentDirname,
|
|
15
|
+
getCurrentFilename,
|
|
16
|
+
resolvePath,
|
|
17
|
+
relativePath,
|
|
18
|
+
fileUrlToPath,
|
|
19
|
+
};
|
|
12
20
|
export default path;
|
package/src/signals.mjs
CHANGED
package/index.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import type logger from '@eliware/log';
|
|
3
|
-
import type {
|
|
4
|
-
RegisterHandlersOptions,
|
|
5
|
-
RegisteredHandlers,
|
|
6
|
-
} from '@eliware/errors';
|
|
7
|
-
import type {
|
|
8
|
-
RegisterSignalsOptions,
|
|
9
|
-
SignalsRegistration,
|
|
10
|
-
} from '@eliware/signals';
|
|
11
|
-
|
|
12
|
-
export { fs };
|
|
13
|
-
export { createLogger, default as log } from '@eliware/log';
|
|
14
|
-
export declare function safeSerialize(obj: unknown, redact?: ReadonlySet<string>): unknown;
|
|
15
|
-
export {
|
|
16
|
-
path,
|
|
17
|
-
pathUrl,
|
|
18
|
-
getCurrentDirname,
|
|
19
|
-
getCurrentFilename,
|
|
20
|
-
resolvePath,
|
|
21
|
-
relativePath,
|
|
22
|
-
fileUrlToPath,
|
|
23
|
-
} from '@eliware/path';
|
|
24
|
-
export { default as registerHandlers } from '@eliware/errors';
|
|
25
|
-
export { default as registerSignals } from '@eliware/signals';
|
|
26
|
-
export type {
|
|
27
|
-
RegisterHandlersOptions,
|
|
28
|
-
RegisteredHandlers,
|
|
29
|
-
RegisterSignalsOptions,
|
|
30
|
-
SignalsRegistration,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type Logger = typeof logger;
|
package/index.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { default as fs } from './src/fs.mjs';
|
|
2
|
-
export { default as log, createLogger, safeSerialize } from './src/log.mjs';
|
|
3
|
-
export {
|
|
4
|
-
default as path,
|
|
5
|
-
pathUrl,
|
|
6
|
-
getCurrentDirname,
|
|
7
|
-
getCurrentFilename,
|
|
8
|
-
resolvePath,
|
|
9
|
-
relativePath,
|
|
10
|
-
fileUrlToPath,
|
|
11
|
-
} from './src/path.mjs';
|
|
12
|
-
export { default as registerHandlers } from './src/errors.mjs';
|
|
13
|
-
export { default as registerSignals } from './src/signals.mjs';
|