@eliware/common 1.1.8 → 12.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 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
- # MIT License
1
+ MIT License
2
2
 
3
- Copyright (c) 2025 Eli Sterling, eliware.org
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,101 +1,91 @@
1
- # @eliware/common
1
+ # [![eliware.org](https://eliware.org/logos/brand.png)](https://discord.gg/M6aTR9eTwN)
2
2
 
3
- A small ESM convenience package that provides one stable import surface for Eliware's shared Node.js utilities.
3
+ ## @eliware/common [![npm](https://img.shields.io/npm/v/@eliware/common)](https://www.npmjs.com/package/@eliware/common) [![License](https://img.shields.io/github/license/eliware/common)](https://github.com/eliware/common/blob/main/LICENSE) [![CI](https://github.com/eliware/common/actions/workflows/ci.yaml/badge.svg)](https://github.com/eliware/common/actions/workflows/ci.yaml)
4
+
5
+ A shared ESM compatibility package for Eliware filesystem, path, logging, error, and signal APIs.
6
+
7
+ ## Table of Contents
8
+
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)
23
+
24
+ ## Features
25
+
26
+ Import shared Eliware APIs from `@eliware/common`.
4
27
 
5
28
  ## Requirements
6
29
 
7
- - Node.js 26 or newer
8
- - Published Eliware dependency packages matching the versions in `package.json`
30
+ Use Node.js 26 or later.
31
+
32
+ ## Setup
9
33
 
10
- ## Installation
34
+ Install the package.
11
35
 
12
- ```bash
36
+ ```text
13
37
  npm install @eliware/common
14
38
  ```
15
39
 
16
- ## Exports
17
-
18
- `@eliware/common` re-exports the current public APIs from:
40
+ ## Usage
19
41
 
20
- - `@eliware/log`: `log`, `createLogger`, `safeSerialize`
21
- - `@eliware/path`: `path`, `pathUrl`, `getCurrentDirname`, `getCurrentFilename`, `resolvePath`, `relativePath`, `fileUrlToPath`
22
- - `@eliware/errors`: `registerHandlers`
23
- - `@eliware/signals`: `registerSignals`
24
- - Node.js `fs`
42
+ Read the [user docs](docs/README.md) and [release notes](RELEASE_NOTES.md).
25
43
 
26
- The implementation is split into focused modules under [`src/`](src/) while the package root remains the public entry point.
44
+ ## Development
27
45
 
28
- ## Usage
46
+ Read the [examples index](examples/README.md) and [specifications index](specs/README.md).
29
47
 
30
- ```js
31
- import {
32
- fs,
33
- log,
34
- path,
35
- pathUrl,
36
- resolvePath,
37
- registerHandlers,
38
- registerSignals,
39
- } from '@eliware/common';
48
+ ## Testing
40
49
 
41
- const configPath = path(import.meta, '.env');
42
- const configUrl = pathUrl(import.meta, '.env');
43
- const absolutePath = resolvePath(import.meta, 'config');
50
+ Run `npm test` to check the repository.
44
51
 
45
- log.info('Application starting', { configPath, configUrl, absolutePath });
46
- log.info(`Files: ${fs.readdirSync(path(import.meta)).join(', ')}`);
52
+ ## Troubleshooting
47
53
 
48
- const errors = registerHandlers({ events: ['uncaughtException', 'unhandledRejection'] });
49
- const signals = registerSignals({ shutdownHook: async () => errors.removeHandlers() });
54
+ Read the [troubleshooting guide](docs/troubleshooting.md).
50
55
 
51
- process.once('SIGTERM', () => void signals.shutdown('SIGTERM'));
52
- ```
56
+ ## Security
53
57
 
54
- ## TypeScript
58
+ Keep secrets and credentials out of logs and examples.
55
59
 
56
- Type declarations are included and expose the dependency option and return types:
60
+ ## API
57
61
 
58
- ```ts
59
- import {
60
- createLogger,
61
- getCurrentDirname,
62
- registerSignals,
63
- type RegisterSignalsOptions,
64
- } from '@eliware/common';
62
+ Read the [API reference](docs/api.md) for exported values and types.
65
63
 
66
- const logger = createLogger({ format: 'json' });
67
- const directory = getCurrentDirname(import.meta);
68
- const options: RegisterSignalsOptions = { exit: false };
69
- const registration = registerSignals(options);
70
- ```
64
+ ## Packaging
71
65
 
72
- ## Errors / Troubleshooting
66
+ Use native ESM. Read the [package guide](docs/package.md) for entry points and files.
73
67
 
74
- This package is a compatibility layer and delegates behavior to its underlying packages. For logging, path, error-handler, or signal-handler failures, consult the corresponding dependency documentation. Keep dependency versions synchronized with the public exports and declarations.
68
+ ## Examples
75
69
 
76
- ## Development
70
+ Run the [native ESM examples](examples/README.md) with Node.js 26 or later.
77
71
 
78
- ```bash
79
- npm install
80
- npm test
81
- npm run lint
82
- npm run test:gaps
83
- npm run typecheck
84
- npm run pack
85
- ```
72
+ ## Support
86
73
 
87
- This package is a re-export/compatibility layer. Its tests verify the public export contract and representative delegation to the underlying packages; implementation behavior is tested in those dependency packages.
74
+ For help, questions, or to chat with the author and community, visit:
88
75
 
89
- ## Security
76
+ [![Discord](https://eliware.org/logos/discord_96.png)](https://discord.gg/M6aTR9eTwN)[![eliware.org](https://eliware.org/logos/eliware_96.png)](https://discord.gg/M6aTR9eTwN)
90
77
 
91
- Do not log secrets or include credentials or machine-specific paths in examples. Review delegated package behavior and keep dependencies updated before publishing.
78
+ **[eliware.org on Discord](https://discord.gg/M6aTR9eTwN)**
92
79
 
93
80
  ## Links
94
81
 
95
- - [GitHub](https://github.com/eliware/common)
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)
96
86
  - [npm](https://www.npmjs.com/package/@eliware/common)
97
- - [eliware Discord](https://discord.gg/M6aTR9eTwN)
87
+ - [Discord](https://discord.gg/M6aTR9eTwN)
98
88
 
99
89
  ## License
100
90
 
101
- [MIT](LICENSE)
91
+ [MIT © Eliware](LICENSE)
@@ -0,0 +1,93 @@
1
+ # Release Notes
2
+
3
+ ## 12.0.0 — 2026-10-12
4
+
5
+ ### Added
6
+
7
+ - Added Snowflake ID exports, constants, and TypeScript types.
8
+ - Added user docs for APIs, package contents, setup, and troubleshooting.
9
+
10
+ ### Changed
11
+
12
+ - Updated the Eliware runtime dependencies to major version 12.
13
+ - Moved the public runtime and declaration entry points into `src/`.
14
+
15
+ ### Breaking changes
16
+
17
+ - Removed the root-level `index.mjs` and `index.d.ts` files. Import from `@eliware/common`.
18
+ - Require major version 12 of the Eliware runtime dependencies.
19
+
20
+ ## 2.0.0 — 2026-08-25
21
+
22
+ ### Changed
23
+
24
+ - Modernized the package for the shared Eliware conventions and Node.js `>=26`.
25
+ - Replaced direct Jest tooling with `@eliware/test`, including enforced 100×4 coverage and shared linting.
26
+ - Updated CI for Ubuntu and Windows validation on `main`, pull requests, and `v*` tags, with gated publishing.
27
+ - Updated package metadata, documentation, and dependency auditing.
28
+
29
+ ### Breaking changes
30
+
31
+ - Required Node.js `>=26`.
32
+ - Replaced direct Jest and Oxlint project tooling with the shared `@eliware/test` harness.
33
+
34
+ ## 1.1.8 — 2026-08-10
35
+
36
+ ### Changed
37
+
38
+ - Updated `@eliware/errors` to 1.1.9, `@eliware/log` to 1.1.12, and `@eliware/signals` to 1.1.7.
39
+ - Added the `safeSerialize` TypeScript declaration to match the runtime export.
40
+ - Updated signal handler contract coverage for the current upstream listener behavior.
41
+
42
+ ## 1.1.7 — 2026-08-07
43
+
44
+ ### Changed
45
+
46
+ - Standardized package layout, validation scripts, TypeScript checking, CI, and package contents.
47
+ - Updated internal dependencies to the latest released Eliware versions.
48
+ - Expanded troubleshooting, development, and security documentation.
49
+
50
+ ## 1.1.6 — 2026-08-07
51
+
52
+ ### Changed
53
+
54
+ - Updated `@eliware/errors`, `@eliware/log`, `@eliware/path`, and `@eliware/signals` to current releases.
55
+ - Standardized Jest coverage on the V8 provider for accurate ESM coverage reporting.
56
+
57
+ ## 1.1.5 — 2026-08-06
58
+
59
+ ### Changed
60
+
61
+ - Refactored the package into focused ESM modules under `src/`.
62
+ - Expanded the unified export surface to include the current public APIs from four shared packages.
63
+ - Added logger and path exports, including `safeSerialize`, `resolvePath`, `relativePath`, and `fileUrlToPath`.
64
+ - Updated TypeScript declarations for the expanded API and dependency option types.
65
+ - Replaced CommonJS entry points and tests with ESM-only files.
66
+ - Expanded contract tests for public exports, helper APIs, handlers, cleanup, and shutdown hooks.
67
+ - Updated the README, examples, dependencies, package files, and development guidance.
68
+ - Standardized linting, coverage scripts, CI, and repository artifact ignores.
69
+
70
+ ## 1.1.4 — 2026-07-01
71
+
72
+ ### Changed
73
+
74
+ - Updated package metadata and dependencies.
75
+ - Refreshed the lockfile and standardized repository tooling.
76
+
77
+ ## 1.1.3 — 2025-12-21
78
+
79
+ ### Changed
80
+
81
+ - Released maintenance updates.
82
+
83
+ ## 1.1.2 — 2025-12-21
84
+
85
+ ### Changed
86
+
87
+ - Released maintenance updates.
88
+
89
+ ## 1.1.1 — 2025-12-09
90
+
91
+ ### Added
92
+
93
+ - 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,117 @@
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
+ ## Error handlers
49
+
50
+ Call `registerHandlers(options?)` to register handlers for process events.
51
+ The default events are `uncaughtException`, `unhandledRejection`, and `warning`.
52
+
53
+ | Option | Default | Purpose |
54
+ | ------------ | -------------------------- | --------------------------------------------- |
55
+ | `processObj` | `process` | Set the process-like event source. |
56
+ | `log` | `@eliware/log` | Set the logger. |
57
+ | `events` | Three process error events | Set the events to handle. |
58
+ | `once` | `false` | Set one-time handler behavior. |
59
+ | `signal` | None | Remove handlers when an `AbortSignal` aborts. |
60
+
61
+ The result has a read-only `removed` value and a `removeHandlers()` method.
62
+ Set a custom logger with `error`, `warn`, and `debug` methods.
63
+ Pass a non-empty array of supported event names. The package rejects unsupported event names.
64
+ Read the [errors package docs](https://github.com/eliware/errors/tree/main/docs) for event behavior and errors.
65
+
66
+ ## Shutdown handlers
67
+
68
+ Call `registerSignals(options?)` to register process shutdown handlers.
69
+ The default signals are `SIGTERM`, `SIGINT`, and `SIGHUP`.
70
+
71
+ | Option | Default | Purpose |
72
+ | -------------- | ----------------------------- | ------------------------------------------------ |
73
+ | `processObj` | `process` | Set the process-like event source. |
74
+ | `log` | `@eliware/log` | Set the logger. |
75
+ | `signals` | `SIGTERM`, `SIGINT`, `SIGHUP` | Set the signals to handle. |
76
+ | `shutdownHook` | None | Set cleanup work. The hook can return a promise. |
77
+ | `exitCode` | `0` | Set the process exit code. |
78
+ | `exit` | `true` | Allow or prevent process exit. |
79
+ | `signal` | None | Remove handlers when an `AbortSignal` aborts. |
80
+
81
+ The result has `removed`, `shutdown(signal?)`, `getShuttingDown()`, and `removeHandlers()` members.
82
+ The default `exit` value is `true`. Set `exit: false` when your program controls process exit.
83
+ Each hook runs once. The package runs hooks in order and continues after a hook error.
84
+ Pass an empty `signals` array to disable signal events. A `beforeExit` handler still runs.
85
+ Read the [signals API docs](https://github.com/eliware/signals/blob/main/docs/api.md) for shutdown order and error behavior.
86
+
87
+ ## Snowflake IDs
88
+
89
+ Call `createSnowflakeGenerator(options?)` to make a generator. Each call returns a decimal string.
90
+
91
+ | Option | Type | Default | Purpose |
92
+ | ----------- | -------------------- | ------------------ | ------------------------------------------- |
93
+ | `epoch` | `number` or `bigint` | `365662380000n` | Set the epoch in Unix milliseconds. |
94
+ | `workerId` | `number` or `bigint` | `0` | Set a worker value from 0 through 31. |
95
+ | `processId` | `number` or `bigint` | `process.pid % 32` | Set a process value from 0 through 31. |
96
+ | `now` | function | `Date.now` | Set a clock that returns Unix milliseconds. |
97
+
98
+ Use one epoch for all generators in one application. Give each active generator a unique worker and process ID pair.
99
+ 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.
100
+ Each generator can create 4096 IDs per millisecond. It throws `RangeError` when time or sequence limits fail.
101
+ Pass a safe integer or `bigint` to `epoch`, `workerId`, and `processId`.
102
+ Pass a clock that returns Unix milliseconds as a safe integer or `bigint`.
103
+ The generator uses its last timestamp when the clock moves backward.
104
+ The exports `generate`, `snowflake`, and the default export from `@eliware/snowflake` use one shared generator.
105
+ The `constants` export provides `epoch`, `sequenceBits`, `processBits`, and `workerBits` values as `bigint`.
106
+ Read the [Snowflake usage guide](https://github.com/eliware/snowflake/blob/main/docs/usage.md) for timestamp bounds and clock behavior.
107
+
108
+ ## TypeScript types
109
+
110
+ The package exports these types:
111
+
112
+ - `Logger`
113
+ - `RegisterHandlersOptions` and `RegisteredHandlers`
114
+ - `RegisterSignalsOptions` and `SignalsRegistration`
115
+ - `SnowflakeGeneratorOptions` and `SnowflakeConstants`
116
+
117
+ Read the [declaration file](../src/index.d.ts) for the current type exports.
@@ -0,0 +1,44 @@
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/signals`
23
+ - `@eliware/snowflake`
24
+
25
+ Use the exports in this package. Use each dependency directly when you need its own package entry point.
26
+ Read the [API reference](api.md) for each exported value.
27
+
28
+ ## Published files
29
+
30
+ The npm package contains:
31
+
32
+ - `src/` for runtime modules and declarations.
33
+ - `docs/` for user docs.
34
+ - `examples/` for native ESM examples.
35
+ - `specs/` for repository specifications.
36
+ - `README.md`, `AGENTS.md`, `LICENSE`, and `RELEASE_NOTES.md`.
37
+
38
+ The package excludes tests, workflows, and lock files.
39
+
40
+ ## Version and release
41
+
42
+ Use the published npm version that matches your application requirements.
43
+ Read [release notes](../RELEASE_NOTES.md) for changes by package version.
44
+ 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,127 @@
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
+ ## Handle process errors and signals
90
+
91
+ Call `registerHandlers(options)` to add process error handlers. Call its `removeHandlers()` method when you no longer need them.
92
+ Call `registerSignals(options)` to add shutdown handlers. Pass `shutdownHook` to run cleanup work.
93
+ Read the [API reference](api.md) for defaults, options, return values, and dependency guides.
94
+
95
+ ## Create Snowflake IDs
96
+
97
+ Create one generator with a unique worker and process ID pair.
98
+
99
+ ```js
100
+ import { createSnowflakeGenerator } from "@eliware/common";
101
+
102
+ const createId = createSnowflakeGenerator({ workerId: 3, processId: 7 });
103
+ console.log(createId());
104
+ ```
105
+
106
+ Each call returns a decimal string. Keep the ID as a string in JavaScript and JSON.
107
+ Read the [Snowflake section in the API reference](api.md#snowflake-ids) for options and limits.
108
+
109
+ ## TypeScript
110
+
111
+ Import the types with a `type` modifier.
112
+
113
+ ```ts
114
+ import {
115
+ createSnowflakeGenerator,
116
+ registerSignals,
117
+ type RegisterSignalsOptions,
118
+ } from "@eliware/common";
119
+
120
+ const options: RegisterSignalsOptions = { exit: false };
121
+ const registration = registerSignals(options);
122
+ const createId = createSnowflakeGenerator();
123
+ console.log(createId());
124
+ registration.removeHandlers();
125
+ ```
126
+
127
+ 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.
@@ -6,13 +6,13 @@ import {
6
6
  resolvePath,
7
7
  registerHandlers,
8
8
  registerSignals,
9
- } from '@eliware/common';
9
+ } from "@eliware/common";
10
10
 
11
- const configPath = path(import.meta, '.env');
12
- const configUrl = pathUrl(import.meta, '.env');
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('Common package example', {
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: ['uncaughtException', 'unhandledRejection'],
23
+ events: ["uncaughtException", "unhandledRejection"],
24
24
  });
25
25
 
26
- const signals = registerSignals({
27
- shutdownHook: async signal => {
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('Handlers registered. Send SIGTERM or SIGINT to shut down gracefully.');
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.");
@@ -0,0 +1,4 @@
1
+ import { createSnowflakeGenerator } from "@eliware/common";
2
+
3
+ const createId = createSnowflakeGenerator({ workerId: 1, processId: 1 });
4
+ console.log(createId());
package/package.json CHANGED
@@ -1,65 +1,118 @@
1
1
  {
2
- "name": "@eliware/common",
3
- "type": "module",
4
- "version": "1.1.8",
5
- "description": "An ESM/Jest/Node-friendly utility for resolving file and directory paths, logging, error handling, and signal handling in both ESM environments.",
6
- "types": "index.d.ts",
7
- "files": [
8
- "index.mjs",
9
- "src",
10
- "index.d.ts",
11
- "README.md",
12
- "LICENSE",
13
- "examples"
2
+ "name": "@eliware/common",
3
+ "version": "12.0.0",
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/signals": "^12.0.0",
51
+ "@eliware/snowflake": "^12.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@eliware/test": "^12.0.0",
55
+ "typescript": "^7.0.2"
56
+ },
57
+ "jest": {
58
+ "testEnvironment": "node",
59
+ "testMatch": [
60
+ "**/tests/**/*.test.mjs"
14
61
  ],
15
- "exports": {
16
- ".": {
17
- "import": "./index.mjs",
18
- "types": "./index.d.ts"
19
- }
20
- },
21
- "scripts": {
22
- "test": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --detectOpenHandles --silent --coverage --coverageProvider=v8",
23
- "test:gaps": "npm test 2>&1 | grep '|' | grep -vF '| 100 | 100 | 100 | 100 |'",
24
- "lint": "npx oxlint .",
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"
62
+ "collectCoverageFrom": [
63
+ "src/**/*.mjs"
41
64
  ],
42
- "author": "Eli Sterling, eliware.org <eli@eliware.org>",
43
- "license": "MIT",
44
- "bugs": {
45
- "url": "https://github.com/eliware/common/issues"
46
- },
47
- "homepage": "https://github.com/eliware/common#readme",
48
- "devDependencies": {
49
- "jest": "^30.4.2",
50
- "typescript": "^7.0.2"
51
- },
52
- "jest": {
53
- "testEnvironment": "node",
54
- "testMatch": [
55
- "**/?(*.)+(spec|test).[jt]s?(x)",
56
- "**/?(*.)+(spec|test).mjs"
57
- ]
58
- },
59
- "dependencies": {
60
- "@eliware/errors": "^1.1.9",
61
- "@eliware/log": "^1.1.12",
62
- "@eliware/path": "^1.1.8",
63
- "@eliware/signals": "^1.1.7"
65
+ "coverageReporters": [
66
+ "text",
67
+ "json-summary"
68
+ ],
69
+ "coverageThreshold": {
70
+ "global": {
71
+ "branches": 100,
72
+ "functions": 100,
73
+ "lines": 100,
74
+ "statements": 100
75
+ }
76
+ }
77
+ },
78
+ "prettier": {
79
+ "printWidth": 100,
80
+ "tabWidth": 2,
81
+ "useTabs": false,
82
+ "semi": true,
83
+ "singleQuote": false,
84
+ "quoteProps": "as-needed",
85
+ "jsxSingleQuote": false,
86
+ "trailingComma": "all",
87
+ "bracketSpacing": true,
88
+ "bracketSameLine": false,
89
+ "arrowParens": "always",
90
+ "proseWrap": "preserve",
91
+ "endOfLine": "lf"
92
+ },
93
+ "author": "Eliware <eliware@eliware.org>",
94
+ "license": "MIT",
95
+ "repository": {
96
+ "type": "git",
97
+ "url": "git+https://github.com/eliware/common.git"
98
+ },
99
+ "homepage": "https://github.com/eliware/common#readme",
100
+ "bugs": {
101
+ "url": "https://github.com/eliware/common/issues"
102
+ },
103
+ "eliware": {
104
+ "id": "E-199",
105
+ "apply": [
106
+ "general",
107
+ "library",
108
+ "npm-published"
109
+ ]
110
+ },
111
+ "types": "./src/index.d.ts",
112
+ "exports": {
113
+ ".": {
114
+ "types": "./src/index.d.ts",
115
+ "import": "./src/index.mjs"
64
116
  }
65
- }
117
+ }
118
+ }
@@ -0,0 +1,3 @@
1
+ # Specifications
2
+
3
+ - [Repository requirements](directives.yaml)
@@ -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
@@ -1,4 +1,4 @@
1
- import registerHandlers from '@eliware/errors';
1
+ import registerHandlers from "@eliware/errors";
2
2
 
3
3
  export { registerHandlers };
4
4
  export default registerHandlers;
package/src/fs.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import fs from 'fs';
1
+ import fs from "fs";
2
2
 
3
3
  export default fs;
4
4
  export { fs };
package/src/index.d.ts ADDED
@@ -0,0 +1,33 @@
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 { 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/src/index.mjs ADDED
@@ -0,0 +1,19 @@
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 { default as registerHandlers } from "./errors.mjs";
19
+ export { default as registerSignals } from "./signals.mjs";
package/src/log.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createLogger, log, safeSerialize } from '@eliware/log';
1
+ import { createLogger, log, safeSerialize } from "@eliware/log";
2
2
 
3
3
  export default log;
4
4
  export { createLogger, log, safeSerialize };
package/src/path.mjs CHANGED
@@ -6,7 +6,15 @@ import {
6
6
  resolvePath,
7
7
  relativePath,
8
8
  fileUrlToPath,
9
- } from '@eliware/path';
9
+ } from "@eliware/path";
10
10
 
11
- export { path, pathUrl, getCurrentDirname, getCurrentFilename, resolvePath, relativePath, fileUrlToPath };
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
@@ -1,4 +1,4 @@
1
- import registerSignals from '@eliware/signals';
1
+ import registerSignals from "@eliware/signals";
2
2
 
3
3
  export { registerSignals };
4
4
  export default registerSignals;
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';