@eliware/common 2.0.0 → 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,106 +1,91 @@
1
- # @eliware/common
1
+ # [![eliware.org](https://eliware.org/logos/brand.png)](https://discord.gg/M6aTR9eTwN)
2
2
 
3
- A small native ESM compatibility 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
4
 
5
- ## Requirements
5
+ A shared ESM compatibility package for Eliware filesystem, path, logging, error, and signal APIs.
6
6
 
7
- - Node.js 26 or newer
8
- - Node.js `>=26`
9
- - Published Eliware dependency packages matching the versions in `package.json`
7
+ ## Table of Contents
10
8
 
11
- ## Installation
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
- ```bash
14
- npm install @eliware/common
15
- ```
24
+ ## Features
25
+
26
+ Import shared Eliware APIs from `@eliware/common`.
16
27
 
17
- ## Exports
28
+ ## Requirements
29
+
30
+ Use Node.js 26 or later.
18
31
 
19
- `@eliware/common` re-exports the current public APIs from:
32
+ ## Setup
20
33
 
21
- - `@eliware/log`: `log`, `createLogger`, `safeSerialize`
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
- The implementation is split into focused modules under [`src/`](src/) while the package root remains the public entry point.
36
+ ```text
37
+ npm install @eliware/common
38
+ ```
28
39
 
29
40
  ## Usage
30
41
 
31
- ```js
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
- const configPath = path(import.meta, '.env');
43
- const configUrl = pathUrl(import.meta, '.env');
44
- const absolutePath = resolvePath(import.meta, 'config');
44
+ ## Development
45
45
 
46
- log.info('Application starting', { configPath, configUrl, absolutePath });
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
- const errors = registerHandlers({ events: ['uncaughtException', 'unhandledRejection'] });
50
- const signals = registerSignals({ shutdownHook: async () => errors.removeHandlers() });
48
+ ## Testing
51
49
 
52
- process.once('SIGTERM', () => void signals.shutdown('SIGTERM'));
53
- ```
50
+ Run `npm test` to check the repository.
54
51
 
55
- ## TypeScript
52
+ ## Troubleshooting
56
53
 
57
- Type declarations are included and expose the dependency option and return types:
54
+ Read the [troubleshooting guide](docs/troubleshooting.md).
58
55
 
59
- ```ts
60
- import {
61
- createLogger,
62
- getCurrentDirname,
63
- registerSignals,
64
- type RegisterSignalsOptions,
65
- } from '@eliware/common';
56
+ ## Security
66
57
 
67
- const logger = createLogger({ format: 'json' });
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.
72
59
 
73
- ## Configuration and operations
60
+ ## API
74
61
 
75
- The package has no global configuration and performs no work at import time. Configure the delegated logger, error handlers, and signal handlers through their options. Applications should validate their own configuration before opening files or external connections and should make shutdown cleanup idempotent.
62
+ Read the [API reference](docs/api.md) for exported values and types.
76
63
 
77
- ## Errors / Troubleshooting
64
+ ## Packaging
78
65
 
79
- 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.
66
+ Use native ESM. Read the [package guide](docs/package.md) for entry points and files.
80
67
 
81
- ## Development
68
+ ## Examples
82
69
 
83
- ```bash
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
- 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.
72
+ ## Support
93
73
 
94
- ## Security
74
+ For help, questions, or to chat with the author and community, visit:
75
+
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)
95
77
 
96
- 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)**
97
79
 
98
80
  ## Links
99
81
 
100
- - [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)
101
86
  - [npm](https://www.npmjs.com/package/@eliware/common)
102
- - [eliware Discord](https://discord.gg/M6aTR9eTwN)
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,93 @@
1
- # Release notes
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.
2
19
 
3
20
  ## 2.0.0 — 2026-08-25
4
21
 
22
+ ### Changed
23
+
5
24
  - Modernized the package for the shared Eliware conventions and Node.js `>=26`.
6
25
  - Replaced direct Jest tooling with `@eliware/test`, including enforced 100×4 coverage and shared linting.
7
26
  - Updated CI for Ubuntu and Windows validation on `main`, pull requests, and `v*` tags, with gated publishing.
8
27
  - Updated package metadata, documentation, and dependency auditing.
9
- - Breaking: Node.js `>=26` is now required.
10
- - Breaking: direct Jest and Oxlint project tooling was replaced by the shared `@eliware/test` harness.
28
+
29
+ ### Breaking changes
30
+
31
+ - Required Node.js `>=26`.
32
+ - Replaced direct Jest and Oxlint project tooling with the shared `@eliware/test` harness.
11
33
 
12
34
  ## 1.1.8 — 2026-08-10
13
35
 
36
+ ### Changed
37
+
14
38
  - Updated `@eliware/errors` to 1.1.9, `@eliware/log` to 1.1.12, and `@eliware/signals` to 1.1.7.
15
39
  - Added the `safeSerialize` TypeScript declaration to match the runtime export.
16
40
  - Updated signal handler contract coverage for the current upstream listener behavior.
17
41
 
18
-
19
42
  ## 1.1.7 — 2026-08-07
20
43
 
44
+ ### Changed
45
+
21
46
  - Standardized package layout, validation scripts, TypeScript checking, CI, and package contents.
22
47
  - Updated internal dependencies to the latest released Eliware versions.
23
48
  - Expanded troubleshooting, development, and security documentation.
24
49
 
25
- ## 1.1.6 — August 7, 2026
50
+ ## 1.1.6 — 2026-08-07
51
+
52
+ ### Changed
26
53
 
27
54
  - Updated `@eliware/errors`, `@eliware/log`, `@eliware/path`, and `@eliware/signals` to current releases.
28
55
  - Standardized Jest coverage on the V8 provider for accurate ESM coverage reporting.
29
56
 
30
- ## 1.1.5 — August 6, 2026
57
+ ## 1.1.5 — 2026-08-06
31
58
 
32
59
  ### Changed
33
60
 
34
61
  - Refactored the package into focused ESM modules under `src/`.
35
- - Expanded the unified export surface to include the current public APIs from `@eliware/log`, `@eliware/path`, `@eliware/errors`, and `@eliware/signals`.
36
- - Added logger exports: `createLogger`, `log`, and `safeSerialize`.
37
- - Added path exports: `resolvePath`, `relativePath`, and `fileUrlToPath`.
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`.
38
64
  - Updated TypeScript declarations for the expanded API and dependency option types.
39
65
  - Replaced CommonJS entry points and tests with ESM-only files.
40
- - Expanded contract tests for all public exports, path helpers, logger helpers, error handlers, signal handlers, abort cleanup, and shutdown hooks.
41
- - Updated README, example usage, package files, dependencies, and development guidance in `AGENTS.md`.
42
- - Standardized linting, coverage scripts, CI configuration, and repository artifact ignores.
43
-
44
- ### Verification
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.
45
69
 
46
- - 6 tests passing.
47
- - Lint passes with zero warnings and errors.
70
+ ## 1.1.4 — 2026-07-01
48
71
 
49
- ## 1.1.4 — July 1, 2026
72
+ ### Changed
50
73
 
51
74
  - Updated package metadata and dependencies.
52
75
  - Refreshed the lockfile and standardized repository tooling.
53
76
 
54
- ## 1.1.3 — December 21, 2025
77
+ ## 1.1.3 — 2025-12-21
78
+
79
+ ### Changed
80
+
81
+ - Released maintenance updates.
82
+
83
+ ## 1.1.2 — 2025-12-21
55
84
 
56
- - Maintenance release with package and dependency metadata updates.
85
+ ### Changed
57
86
 
58
- ## 1.1.2 — December 21, 2025
87
+ - Released maintenance updates.
59
88
 
60
- - Maintenance release with package and dependency metadata updates.
89
+ ## 1.1.1 — 2025-12-09
61
90
 
62
- ## 1.1.1 — December 9, 2025
91
+ ### Added
63
92
 
64
- - Initial tagged release of the common ESM utility package.
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,64 +1,118 @@
1
1
  {
2
- "name": "@eliware/common",
3
- "type": "module",
4
- "version": "2.0.0",
5
- "description": "An ESM and Node.js compatibility layer for shared Eliware filesystem, path, logging, error, and signal APIs.",
6
- "types": "index.d.ts",
7
- "files": [
8
- "index.mjs",
9
- "src",
10
- "index.d.ts",
11
- "README.md",
12
- "LICENSE",
13
- "RELEASE_NOTES.md",
14
- "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"
15
61
  ],
16
- "exports": {
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"
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
- "@eliware/test": "^2.0.0",
50
- "typescript": "^7.0.2"
51
- },
52
- "dependencies": {
53
- "@eliware/errors": "^2.0.0",
54
- "@eliware/log": "^2.0.0",
55
- "@eliware/path": "^2.0.0",
56
- "@eliware/signals": "^2.0.0"
57
- },
58
- "engines": {
59
- "node": ">=26"
60
- },
61
- "publishConfig": {
62
- "access": "public"
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"
63
116
  }
64
- }
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';