Compare commits

..

No commits in common. "master" and "v5.0.15" have entirely different histories.

10 changed files with 143 additions and 294 deletions

View File

@ -1,57 +0,0 @@
# Changelog
## 2024-11-06 - 5.1.2 - fix(appdata)
Fix iteration over overwriteObject in AppData class
- Corrected the for loop from in to of inside the AppData class for iterating over overwriteObject keys.
## 2024-11-05 - 5.1.1 - fix(AppData)
Fix issue with overwrite object handling in AppData class
- Corrected logic to handle cases when overwriteObject is undefined.
## 2024-11-05 - 5.1.0 - feat(appdata)
Add support for overwriting keys using the overwriteObject option in AppData
- Introduced the overwriteObject option in IAppDataOptions to allow overwriting specific keys in the AppData class.
## 2024-06-19 - 5.0.17 - 5.0.23 - Core Updates
Routine maintenance and updates to the core components.
- Multiple core updates and fixes improving stability
## 2024-06-12 - 5.0.13 - 5.0.16 - Core Updates
Maintenance focus on core systems with enhancements and problem resolutions.
- Enhancements and updates in the core functionality
## 2024-05-29 - 5.0.13 - Documentation Update
Descriptive improvements aligned with current features.
- Updated core description for better clarity in documentation
## 2024-04-01 - 5.0.10 - Configuration Update
Improved configuration management for build processes.
- Updated `npmextra.json` to reflect changes in git repository management
## 2024-02-12 - 5.0.0 - 5.0.9 - Major Core Enhancements
A series of critical updates with resolved issues in the core components.
- Introduction of new core features
- Several core system updates
## 2024-02-12 - 4.0.16 - Major Version Transition
Migration to the new major version with impactful changes.
- BREAKING CHANGE: Significant updates requiring attention for smooth transition
## 2023-08-24 - 3.0.9 - 4.0.16 - Organization Updates
Formatted updates with attention to organizational standards and practice.
- SWITCH to a new organizational scheme
## 2023-07-11 - 3.0.9 - Organizational Enhancement
Shifts aligning with contemporary structuring and logistics.
- Strategic realignment with organizational principles

View File

@ -14,7 +14,7 @@
"githost": "code.foss.global", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "npmextra", "gitrepo": "npmextra",
"description": "A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.", "description": "Enhances npm with additional configuration and tool management capabilities, including a key-value store for project setups.",
"npmPackagename": "@push.rocks/npmextra", "npmPackagename": "@push.rocks/npmextra",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [
@ -26,13 +26,7 @@
"typescript", "typescript",
"environment setup", "environment setup",
"dependencies management", "dependencies management",
"npm package enhancement", "npm package enhancement"
"automation",
"async operations",
"app configuration",
"smart file handling",
"workflow improvement",
"persistent storage"
] ]
} }
}, },

View File

@ -1,8 +1,8 @@
{ {
"name": "@push.rocks/npmextra", "name": "@push.rocks/npmextra",
"version": "5.1.2", "version": "5.0.15",
"private": false, "private": false,
"description": "A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.", "description": "Enhances npm with additional configuration and tool management capabilities, including a key-value store for project setups.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
@ -28,15 +28,14 @@
"@push.rocks/smartpath": "^5.0.18", "@push.rocks/smartpath": "^5.0.18",
"@push.rocks/smartpromise": "^4.0.2", "@push.rocks/smartpromise": "^4.0.2",
"@push.rocks/smartrx": "^3.0.7", "@push.rocks/smartrx": "^3.0.7",
"@push.rocks/taskbuffer": "^3.1.7", "@push.rocks/taskbuffer": "^3.1.7"
"@tsclass/tsclass": "^4.0.59"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.80", "@git.zone/tsbuild": "^2.1.80",
"@git.zone/tsrun": "^1.2.44", "@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.90", "@git.zone/tstest": "^1.0.90",
"@push.rocks/tapbundle": "^5.0.23", "@push.rocks/tapbundle": "^5.0.23",
"@types/node": "^20.14.5" "@types/node": "^20.14.2"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@ -63,12 +62,6 @@
"typescript", "typescript",
"environment setup", "environment setup",
"dependencies management", "dependencies management",
"npm package enhancement", "npm package enhancement"
"automation",
"async operations",
"app configuration",
"smart file handling",
"workflow improvement",
"persistent storage"
] ]
} }

85
pnpm-lock.yaml generated
View File

@ -32,25 +32,22 @@ importers:
'@push.rocks/taskbuffer': '@push.rocks/taskbuffer':
specifier: ^3.1.7 specifier: ^3.1.7
version: 3.1.7 version: 3.1.7
'@tsclass/tsclass':
specifier: ^4.0.59
version: 4.0.59
devDependencies: devDependencies:
'@git.zone/tsbuild': '@git.zone/tsbuild':
specifier: ^2.1.80 specifier: ^2.1.80
version: 2.1.80 version: 2.1.80
'@git.zone/tsrun': '@git.zone/tsrun':
specifier: ^1.2.44 specifier: ^1.2.44
version: 1.2.46(@types/node@20.14.5) version: 1.2.46(@types/node@20.14.2)
'@git.zone/tstest': '@git.zone/tstest':
specifier: ^1.0.90 specifier: ^1.0.90
version: 1.0.90(@types/node@20.14.5) version: 1.0.90(@types/node@20.14.2)
'@push.rocks/tapbundle': '@push.rocks/tapbundle':
specifier: ^5.0.23 specifier: ^5.0.23
version: 5.0.23 version: 5.0.23
'@types/node': '@types/node':
specifier: ^20.14.5 specifier: ^20.14.2
version: 20.14.5 version: 20.14.2
packages: packages:
@ -628,8 +625,8 @@ packages:
'@tsclass/tsclass@3.0.48': '@tsclass/tsclass@3.0.48':
resolution: {integrity: sha512-hC65UvDlp9qvsl6OcIZXz0JNiWZ0gyzsTzbXpg215sGxopgbkOLCr6E0s4qCTnweYm95gt2AdY95uP7M7kExaQ==} resolution: {integrity: sha512-hC65UvDlp9qvsl6OcIZXz0JNiWZ0gyzsTzbXpg215sGxopgbkOLCr6E0s4qCTnweYm95gt2AdY95uP7M7kExaQ==}
'@tsclass/tsclass@4.0.59': '@tsclass/tsclass@4.0.55':
resolution: {integrity: sha512-zSdNX/qzuekfCFG81k4e1X2tj1S+rbs2tM4CFAzT+aLiu2/AqdS1iPYwH/sYpY8vm+vBfllks9rlsuRSA2xTeg==} resolution: {integrity: sha512-zg774JF90/3/rJ7xk4LyGgxcUzxdKIQcwtBVxez4LhvegESxvHiFmX42WL105iBpE53ISJ8sctLWlwG1JQZdlA==}
'@tsconfig/node10@1.0.11': '@tsconfig/node10@1.0.11':
resolution: {integrity: sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==} resolution: {integrity: sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==}
@ -769,8 +766,8 @@ packages:
'@types/ms@0.7.34': '@types/ms@0.7.34':
resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==} resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==}
'@types/node@20.14.5': '@types/node@20.14.2':
resolution: {integrity: sha512-aoRR+fJkZT2l0aGOJhuA8frnCSoNX6W7U2mpNq63+BxBIj5BQFt8rHy627kijCmm63ijdSdwvGgpUsU6MBsZZA==} resolution: {integrity: sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==}
'@types/parse5@6.0.3': '@types/parse5@6.0.3':
resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==} resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==}
@ -3063,7 +3060,7 @@ snapshots:
'@push.rocks/taskbuffer': 3.1.7 '@push.rocks/taskbuffer': 3.1.7
'@push.rocks/webrequest': 3.0.37 '@push.rocks/webrequest': 3.0.37
'@push.rocks/webstore': 2.0.20 '@push.rocks/webstore': 2.0.20
'@tsclass/tsclass': 4.0.59 '@tsclass/tsclass': 4.0.55
'@types/express': 4.17.21 '@types/express': 4.17.21
body-parser: 1.20.2 body-parser: 1.20.2
cors: 2.8.5 cors: 2.8.5
@ -3260,22 +3257,22 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
'@git.zone/tsrun@1.2.46(@types/node@20.14.5)': '@git.zone/tsrun@1.2.46(@types/node@20.14.2)':
dependencies: dependencies:
'@push.rocks/smartfile': 10.0.41 '@push.rocks/smartfile': 10.0.41
'@push.rocks/smartshell': 3.0.5 '@push.rocks/smartshell': 3.0.5
ts-node: 10.9.2(@types/node@20.14.5)(typescript@5.1.6) ts-node: 10.9.2(@types/node@20.14.2)(typescript@5.1.6)
typescript: 5.1.6 typescript: 5.1.6
transitivePeerDependencies: transitivePeerDependencies:
- '@swc/core' - '@swc/core'
- '@swc/wasm' - '@swc/wasm'
- '@types/node' - '@types/node'
'@git.zone/tstest@1.0.90(@types/node@20.14.5)': '@git.zone/tstest@1.0.90(@types/node@20.14.2)':
dependencies: dependencies:
'@api.global/typedserver': 3.0.50 '@api.global/typedserver': 3.0.50
'@git.zone/tsbundle': 2.0.15 '@git.zone/tsbundle': 2.0.15
'@git.zone/tsrun': 1.2.46(@types/node@20.14.5) '@git.zone/tsrun': 1.2.46(@types/node@20.14.2)
'@push.rocks/consolecolor': 2.0.2 '@push.rocks/consolecolor': 2.0.2
'@push.rocks/smartbrowser': 2.0.6 '@push.rocks/smartbrowser': 2.0.6
'@push.rocks/smartdelay': 3.0.5 '@push.rocks/smartdelay': 3.0.5
@ -3568,7 +3565,7 @@ snapshots:
'@push.rocks/smartlog-interfaces@3.0.2': '@push.rocks/smartlog-interfaces@3.0.2':
dependencies: dependencies:
'@api.global/typedrequest-interfaces': 2.0.2 '@api.global/typedrequest-interfaces': 2.0.2
'@tsclass/tsclass': 4.0.59 '@tsclass/tsclass': 4.0.55
'@push.rocks/smartlog@3.0.7': '@push.rocks/smartlog@3.0.7':
dependencies: dependencies:
@ -3648,7 +3645,7 @@ snapshots:
'@push.rocks/smartpromise': 4.0.3 '@push.rocks/smartpromise': 4.0.3
'@push.rocks/smartpuppeteer': 2.0.2 '@push.rocks/smartpuppeteer': 2.0.2
'@push.rocks/smartunique': 3.0.9 '@push.rocks/smartunique': 3.0.9
'@tsclass/tsclass': 4.0.59 '@tsclass/tsclass': 4.0.55
'@types/express': 4.17.21 '@types/express': 4.17.21
express: 4.19.2 express: 4.19.2
pdf-lib: 1.17.1 pdf-lib: 1.17.1
@ -3706,7 +3703,7 @@ snapshots:
'@push.rocks/smartxml': 1.0.8 '@push.rocks/smartxml': 1.0.8
'@push.rocks/smartyaml': 2.0.5 '@push.rocks/smartyaml': 2.0.5
'@push.rocks/webrequest': 3.0.37 '@push.rocks/webrequest': 3.0.37
'@tsclass/tsclass': 4.0.59 '@tsclass/tsclass': 4.0.55
'@push.rocks/smartsocket@2.0.27': '@push.rocks/smartsocket@2.0.27':
dependencies: dependencies:
@ -3840,7 +3837,7 @@ snapshots:
dependencies: dependencies:
'@pushrocks/smartdelay': 3.0.1 '@pushrocks/smartdelay': 3.0.1
'@pushrocks/smartpromise': 4.0.2 '@pushrocks/smartpromise': 4.0.2
'@tsclass/tsclass': 4.0.59 '@tsclass/tsclass': 4.0.55
'@push.rocks/webstore@2.0.20': '@push.rocks/webstore@2.0.20':
dependencies: dependencies:
@ -4016,7 +4013,7 @@ snapshots:
dependencies: dependencies:
type-fest: 2.19.0 type-fest: 2.19.0
'@tsclass/tsclass@4.0.59': '@tsclass/tsclass@4.0.55':
dependencies: dependencies:
type-fest: 4.20.0 type-fest: 4.20.0
@ -4030,14 +4027,14 @@ snapshots:
'@types/accepts@1.3.7': '@types/accepts@1.3.7':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/babel__code-frame@7.0.6': {} '@types/babel__code-frame@7.0.6': {}
'@types/body-parser@1.19.5': '@types/body-parser@1.19.5':
dependencies: dependencies:
'@types/connect': 3.4.38 '@types/connect': 3.4.38
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/buffer-json@2.0.3': {} '@types/buffer-json@2.0.3': {}
@ -4049,17 +4046,17 @@ snapshots:
'@types/clean-css@4.2.11': '@types/clean-css@4.2.11':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
source-map: 0.6.1 source-map: 0.6.1
'@types/co-body@6.1.3': '@types/co-body@6.1.3':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/qs': 6.9.15 '@types/qs': 6.9.15
'@types/connect@3.4.38': '@types/connect@3.4.38':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/content-disposition@0.5.8': {} '@types/content-disposition@0.5.8': {}
@ -4072,11 +4069,11 @@ snapshots:
'@types/connect': 3.4.38 '@types/connect': 3.4.38
'@types/express': 4.17.21 '@types/express': 4.17.21
'@types/keygrip': 1.0.6 '@types/keygrip': 1.0.6
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/cors@2.8.17': '@types/cors@2.8.17':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/debounce@1.2.4': {} '@types/debounce@1.2.4': {}
@ -4088,7 +4085,7 @@ snapshots:
'@types/express-serve-static-core@4.19.3': '@types/express-serve-static-core@4.19.3':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/qs': 6.9.15 '@types/qs': 6.9.15
'@types/range-parser': 1.2.7 '@types/range-parser': 1.2.7
'@types/send': 0.17.4 '@types/send': 0.17.4
@ -4102,17 +4099,17 @@ snapshots:
'@types/from2@2.3.5': '@types/from2@2.3.5':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/fs-extra@11.0.4': '@types/fs-extra@11.0.4':
dependencies: dependencies:
'@types/jsonfile': 6.1.4 '@types/jsonfile': 6.1.4
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/glob@8.1.0': '@types/glob@8.1.0':
dependencies: dependencies:
'@types/minimatch': 5.1.2 '@types/minimatch': 5.1.2
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/hast@3.0.4': '@types/hast@3.0.4':
dependencies: dependencies:
@ -4146,7 +4143,7 @@ snapshots:
'@types/jsonfile@6.1.4': '@types/jsonfile@6.1.4':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/keygrip@1.0.6': {} '@types/keygrip@1.0.6': {}
@ -4163,7 +4160,7 @@ snapshots:
'@types/http-errors': 2.0.4 '@types/http-errors': 2.0.4
'@types/keygrip': 1.0.6 '@types/keygrip': 1.0.6
'@types/koa-compose': 3.2.8 '@types/koa-compose': 3.2.8
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/mdast@4.0.4': '@types/mdast@4.0.4':
dependencies: dependencies:
@ -4179,7 +4176,7 @@ snapshots:
'@types/ms@0.7.34': {} '@types/ms@0.7.34': {}
'@types/node@20.14.5': '@types/node@20.14.2':
dependencies: dependencies:
undici-types: 5.26.5 undici-types: 5.26.5
@ -4198,12 +4195,12 @@ snapshots:
'@types/send@0.17.4': '@types/send@0.17.4':
dependencies: dependencies:
'@types/mime': 1.3.5 '@types/mime': 1.3.5
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/serve-static@1.15.7': '@types/serve-static@1.15.7':
dependencies: dependencies:
'@types/http-errors': 2.0.4 '@types/http-errors': 2.0.4
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/send': 0.17.4 '@types/send': 0.17.4
'@types/sinon-chai@3.2.12': '@types/sinon-chai@3.2.12':
@ -4221,7 +4218,7 @@ snapshots:
'@types/through2@2.0.41': '@types/through2@2.0.41':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/trusted-types@2.0.7': {} '@types/trusted-types@2.0.7': {}
@ -4241,15 +4238,15 @@ snapshots:
'@types/ws@7.4.7': '@types/ws@7.4.7':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/ws@8.5.10': '@types/ws@8.5.10':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
'@types/yauzl@2.10.3': '@types/yauzl@2.10.3':
dependencies: dependencies:
'@types/node': 20.14.5 '@types/node': 20.14.2
optional: true optional: true
'@ungap/structured-clone@1.2.0': {} '@ungap/structured-clone@1.2.0': {}
@ -4757,7 +4754,7 @@ snapshots:
dependencies: dependencies:
'@types/cookie': 0.4.1 '@types/cookie': 0.4.1
'@types/cors': 2.8.17 '@types/cors': 2.8.17
'@types/node': 20.14.5 '@types/node': 20.14.2
accepts: 1.3.8 accepts: 1.3.8
base64id: 2.0.0 base64id: 2.0.0
cookie: 0.4.2 cookie: 0.4.2
@ -6523,14 +6520,14 @@ snapshots:
trough@2.2.0: {} trough@2.2.0: {}
ts-node@10.9.2(@types/node@20.14.5)(typescript@5.1.6): ts-node@10.9.2(@types/node@20.14.2)(typescript@5.1.6):
dependencies: dependencies:
'@cspotcode/source-map-support': 0.8.1 '@cspotcode/source-map-support': 0.8.1
'@tsconfig/node10': 1.0.11 '@tsconfig/node10': 1.0.11
'@tsconfig/node12': 1.0.11 '@tsconfig/node12': 1.0.11
'@tsconfig/node14': 1.0.3 '@tsconfig/node14': 1.0.3
'@tsconfig/node16': 1.0.4 '@tsconfig/node16': 1.0.4
'@types/node': 20.14.5 '@types/node': 20.14.2
acorn: 8.11.3 acorn: 8.11.3
acorn-walk: 8.3.2 acorn-walk: 8.3.2
arg: 4.1.3 arg: 4.1.3

View File

@ -1,5 +1,5 @@
# @push.rocks/npmextra # @push.rocks/npmextra
A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups. Enhances npm with additional configuration and tool management capabilities, including a key-value store for project setups.
## Install ## Install
To install `@push.rocks/npmextra`, use the following npm command: To install `@push.rocks/npmextra`, use the following npm command:
@ -14,7 +14,7 @@ This package is available on [npm](https://www.npmjs.com/package/@push.rocks/npm
`@push.rocks/npmextra` is designed to supplement npm functionalities with enhanced configuration and tool management. It facilitates the management of project configurations and tool setups in a consolidated manner, enabling a smoother workflow and maintenance process. Below are detailed use cases and examples implemented with ESM syntax and TypeScript. `@push.rocks/npmextra` is designed to supplement npm functionalities with enhanced configuration and tool management. It facilitates the management of project configurations and tool setups in a consolidated manner, enabling a smoother workflow and maintenance process. Below are detailed use cases and examples implemented with ESM syntax and TypeScript.
### Initial Setup and Configuration ### Initial Setup and Configuration
To start using `npmextra` in your project, first include it with an import statement: To start using npmextra in your project, first include it in your project with an import statement:
```typescript ```typescript
import { Npmextra } from '@push.rocks/npmextra'; import { Npmextra } from '@push.rocks/npmextra';
@ -27,7 +27,7 @@ const npmExtraInstance = new Npmextra('/path/to/your/project');
``` ```
### Managing Tool Configurations with `npmextra.json` ### Managing Tool Configurations with `npmextra.json`
`@push.rocks/npmextra` excels in unifying tool configurations through a single `npmextra.json` file. Instead of scattering configurations across multiple files, `npmextra` enables you to define tool-specific settings within this centralized configuration file, which can then be accessed programmatically. `@push.rocks/npmextra` excels in unifying tool configurations through a single `npmextra.json` file. Instead of scattering configurations across multiple files, `@push.rocks/npmextra` enables you to define tool-specific settings within this centralized configuration file, which can then be accessed programmatically.
#### Creating and Utilizing `npmextra.json` #### Creating and Utilizing `npmextra.json`
@ -56,9 +56,9 @@ import { Npmextra } from '@push.rocks/npmextra';
const npmExtraInstance = new Npmextra(); const npmExtraInstance = new Npmextra();
// Retrieve the configuration for 'toolname', merging defaults with any found in npmextra.json // Retrieve the configuration for 'toolname', merging defaults with any found in npmextra.json
const toolConfig = npmExtraInstance.dataFor<{ setting1: string, setting2: string }>('toolname', { const toolConfig = npmExtraInstance.dataFor('toolname', {
setting1: 'defaultValue1', defaultKey1: 'defaultValue1',
setting2: 'defaultValue2' defaultKey2: 'defaultValue2'
}); });
// toolConfig now contains the merged settings from npmextra.json and provided defaults // toolConfig now contains the merged settings from npmextra.json and provided defaults
@ -75,10 +75,7 @@ To utilize the KeyValueStore, create an instance specifying its scope (e.g., 'us
```typescript ```typescript
import { KeyValueStore } from '@push.rocks/npmextra'; import { KeyValueStore } from '@push.rocks/npmextra';
const kvStore = new KeyValueStore<'userHomeDir'>({ const kvStore = new KeyValueStore<'userHomeDir'>('userHomeDir', 'myUniqueAppName');
typeArg: 'userHomeDir',
identityArg: 'myUniqueAppName'
});
``` ```
You can then use the `writeKey`, `readKey`, `writeAll`, and `readAll` methods to manage your store respectively. You can then use the `writeKey`, `readKey`, `writeAll`, and `readAll` methods to manage your store respectively.
@ -104,14 +101,57 @@ const allData = await kvStore.readAll();
console.log(allData); // Outputs the entire store's contents console.log(allData); // Outputs the entire store's contents
``` ```
### Advanced Key-Value Store Management ### Integrating with Tools
`@push.rocks/npmextra` seamlessly integrates with numerous tools, enabling them to leverage `npmextra.json` for configuration purposes. Tools such as `npmts`, `npmci`, and `npmdocker` are already utilizing this feature for enhanced configuration management. Below is an example of integrating a fictional tool named `toolname` with `npmextra`.
In addition to basic read/write operations, `npmextra`s `KeyValueStore` supports advanced scenarios like mandatory keys and custom file paths. #### Example: Tool Integration
Imagine you have a custom tool called `toolname` that requires specific configurations. Here's how you might configure and use it with `npmextra`:
1. Define the configuration in `npmextra.json`:
```json
{
"toolname": {
"configKey1": "configValue1",
"configKey2": "configValue2",
}
}
```
2. Access the configuration within your tool:
```typescript
// Import npmextra
import { Npmextra } from '@push.rocks/npmextra';
class ToolName {
config: any;
constructor() {
const npmExtraInstance = new Npmextra();
this.config = npmExtraInstance.dataFor('toolname', {
configKey1: 'defaultValue1',
configKey2: 'defaultValue2'
});
}
run() {
// Utilize the configuration
console.log(this.config.configKey1); // Outputs: configValue1
console.log(this.config.configKey2); // Outputs: configValue2
}
}
const toolInstance = new ToolName();
toolInstance.run();
```
### Advanced Key-Value Store Usage
In addition to basic read/write operations, `@push.rocks/npmextra`s `KeyValueStore` supports advanced usage scenarios, such as mandatory keys and custom file paths.
#### Example: Mandatory Keys and Custom Paths #### Example: Mandatory Keys and Custom Paths
Consider a scenario where your application requires specific keys to be present in the KeyValueStore. You can define mandatory keys and use a custom path for your store like this:
```typescript ```typescript
import { KeyValueStore } from '@push.rocks/npmextra'; import { KeyValueStore } from '@push.rocks/npmextra';
@ -146,8 +186,7 @@ console.log(allData); // Outputs: { key1: 'value1', key2: 123 }
``` ```
### Combining AppData and KeyValueStore ### Combining AppData and KeyValueStore
The `AppData` class extends the functionality of `KeyValueStore` by integrating environmental variables and specifying additional configurations.
The `AppData` class extends the functionality of `KeyValueStore` by integrating environmental variables, specifying additional configurations, and providing a more structured approach to data management.
#### Example: AppData Usage #### Example: AppData Usage
@ -190,8 +229,7 @@ console.log(allSettings); // Outputs: { settingA: 'exampleValue', settingB: 100,
``` ```
### Error Handling and Debugging ### Error Handling and Debugging
Proper error handling ensures that your integrations with `npmextra` are robust and stable. Below are some strategies for error handling and debugging potential issues.
Proper error handling ensures your integrations with `npmextra` are robust and stable. Below are some strategies for error handling and debugging potential issues.
#### Example: Error Handling in KeyValueStore #### Example: Error Handling in KeyValueStore
@ -230,7 +268,6 @@ console.log(toolConfig);
``` ```
### Integration Tests ### Integration Tests
Writing tests ensures that your integration with `npmextra` works as expected. Below are examples of integration tests for both `Npmextra` and `KeyValueStore`. Writing tests ensures that your integration with `npmextra` works as expected. Below are examples of integration tests for both `Npmextra` and `KeyValueStore`.
#### Example: Testing `Npmextra` Class #### Example: Testing `Npmextra` Class
@ -265,10 +302,7 @@ import { KeyValueStore } from '@push.rocks/npmextra';
let kvStore: KeyValueStore<{ key1: string, key2: number }>; let kvStore: KeyValueStore<{ key1: string, key2: number }>;
tap.test('should create a KeyValueStore instance', async () => { tap.test('should create a KeyValueStore instance', async () => {
kvStore = new KeyValueStore({ kvStore = new KeyValueStore('userHomeDir', 'testApp');
typeArg: 'userHomeDir',
identityArg: 'testApp'
});
expect(kvStore).toBeInstanceOf(KeyValueStore); expect(kvStore).toBeInstanceOf(KeyValueStore);
}); });
@ -288,8 +322,7 @@ tap.start();
``` ```
### Summary ### Summary
By centralizing configuration management and offering a versatile key-value store, `@push.rocks/npmextra` significantly simplifies the setup and management of tools and settings in modern JavaScript and TypeScript projects. Whether you're managing project-wide configurations or need persistent storage for key-value pairs, `@push.rocks/npmextra` provides an efficient and streamlined solution. Leveraging these robust features will ensure your project is well-configured and maintainable.
By centralizing configuration management and offering a versatile key-value store, `@push.rocks/npmextra` significantly simplifies the setup and management of tools and settings in modern JavaScript and TypeScript projects. Whether you're managing project-wide configurations or need persistent storage for key-value pairs, `npmextra` provides an efficient and streamlined solution. Leveraging these robust features will ensure your project is well-configured and maintainable.
## License and Legal Information ## License and Legal Information

View File

@ -1,27 +0,0 @@
import { expect, tap } from '@push.rocks/tapbundle';
import path = require('path');
// module to test
import * as npmextra from '../ts/index.js';
interface ITestOptions {
hi: string;
deep: {
deep1: string;
deep2: string;
};
}
let testAppdata: npmextra.AppData<ITestOptions>;
tap.test('should create a valid AppData', async () => {
testAppdata = new npmextra.AppData<ITestOptions>({
envMapping: {
deep: {
deep1: '',
},
},
});
});
export default tap.start();

View File

@ -1,8 +1,8 @@
/** /**
* autocreated commitinfo by @push.rocks/commitinfo * autocreated commitinfo by @pushrocks/commitinfo
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/npmextra', name: '@push.rocks/npmextra',
version: '5.1.2', version: '5.0.15',
description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.' description: 'Enhances npm with additional configuration and tool management capabilities, including a key-value store for project setups.'
} }

View File

@ -1,21 +1,18 @@
import * as plugins from './npmextra.plugins.js'; import * as plugins from './npmextra.plugins.js';
import * as paths from './npmextra.paths.js'; import * as paths from './npmextra.paths.js';
import { KeyValueStore } from './npmextra.classes.keyvaluestore.js'; import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
import { env } from 'process';
export interface IAppDataOptions<T = any> { export interface IAppDataOptions<T = any> {
dirPath?: string; dirPath?: string;
requiredKeys?: Array<keyof T>; requiredKeys?: Array<keyof T>;
/**
* wether keys should be persisted on disk or not
*/
ephermal?: boolean;
/** /**
* kvStoreKey: 'MY_ENV_VAR' * kvStoreKey: 'MY_ENV_VAR'
*/ */
envMapping?: plugins.tsclass.typeFest.PartialDeep<T>; envMapping?: {
overwriteObject?: plugins.tsclass.typeFest.PartialDeep<T>; [key in keyof T]?: string | object;
};
} }
export class AppData<T = any> { export class AppData<T = any> {
@ -25,9 +22,7 @@ export class AppData<T = any> {
* @param pathArg * @param pathArg
* @returns * @returns
*/ */
public static async createAndInit<T = any>( public static async createAndInit<T = any>(optionsArg: IAppDataOptions<T> = {}): Promise<AppData<T>> {
optionsArg: IAppDataOptions<T> = {}
): Promise<AppData<T>> {
const appData = new AppData<T>(optionsArg); const appData = new AppData<T>(optionsArg);
await appData.readyDeferred.promise; await appData.readyDeferred.promise;
return appData; return appData;
@ -48,7 +43,7 @@ export class AppData<T = any> {
* @param pathArg * @param pathArg
*/ */
private async init(pathArg?: string) { private async init(pathArg?: string) {
if (this.options.dirPath || this.options.ephermal) { if (this.options.dirPath) {
// ok, nothing to do here; // ok, nothing to do here;
} else { } else {
const appDataDir = '/app/data'; const appDataDir = '/app/data';
@ -67,88 +62,30 @@ export class AppData<T = any> {
} }
this.kvStore = new KeyValueStore<T>({ this.kvStore = new KeyValueStore<T>({
typeArg: this.options.ephermal ? 'ephemeral' : 'custom', typeArg: 'custom',
identityArg: 'appkv', identityArg: 'appkv',
customPath: this.options.dirPath, customPath: this.options.dirPath,
mandatoryKeys: this.options.requiredKeys as Array<keyof T>, mandatoryKeys: this.options.requiredKeys as Array<keyof T>
}); });
if (this.options.envMapping) { if (this.options.envMapping) {
const qenvInstance = new plugins.qenv.Qenv( const qenvInstance = new plugins.qenv.Qenv(process.cwd(), plugins.path.join(process.cwd(), '.nogit'));
process.cwd(),
plugins.path.join(process.cwd(), '.nogit')
);
// Recursive function to handle nested objects, now includes key parameter // Recursive function to handle nested objects, now includes key parameter
const processEnvMapping = async ( const processEnvMapping = async (key: keyof T, mappingValue: any, parentKey: keyof T | '' = ''): Promise<any> => {
key: keyof T,
mappingValue: any,
parentKey: keyof T | '' = ''
): Promise<any> => {
if (typeof mappingValue === 'string') { if (typeof mappingValue === 'string') {
let envValue: string | boolean | T[keyof T]; let envValue: string | T[keyof T];
let convert: 'none' | 'json' | 'base64' | 'boolean' = 'none'; if (mappingValue.startsWith('hard:')) {
switch (true) { envValue = mappingValue.replace('hard:', '') as T[keyof T];
case mappingValue.startsWith('hard:'): } else {
envValue = mappingValue.replace('hard:', '') as T[keyof T]; envValue = await qenvInstance.getEnvVarOnDemand(mappingValue) as T[keyof T];
break;
case mappingValue.startsWith('hard_boolean:'):
envValue = mappingValue.replace('hard_boolean:', '') === 'true';
convert = 'boolean';
break;
case mappingValue.startsWith('hard_json:'):
envValue = JSON.parse(mappingValue.replace('hard_json:', '')) as T[keyof T];
convert = 'json';
break;
case mappingValue.startsWith('hard_base64:'):
envValue = Buffer.from(
mappingValue.replace('hard_base64:', ''),
'base64'
).toString() as T[keyof T];
convert = 'base64';
break;
case mappingValue.startsWith('boolean:'):
envValue = (await qenvInstance.getEnvVarOnDemand(
mappingValue.replace('boolean:', '')
)) as T[keyof T];
convert = 'boolean';
break;
case mappingValue.startsWith('json:'):
envValue = (await qenvInstance.getEnvVarOnDemand(
mappingValue.replace('json:', '')
)) as T[keyof T];
convert = 'json';
break;
case mappingValue.startsWith('base64:'):
envValue = (await qenvInstance.getEnvVarOnDemand(
mappingValue.replace('base64:', '')
)) as T[keyof T];
convert = 'base64';
break;
default:
envValue = (await qenvInstance.getEnvVarOnDemand(mappingValue)) as T[keyof T];
break;
} }
// lets format the env value
if (envValue) { if (envValue) {
if (typeof envValue === 'string' && convert === 'boolean') { if (typeof envValue === 'string' && mappingValue.endsWith('_JSON')) {
envValue = envValue === 'true'; envValue = JSON.parse(envValue) as T[keyof T];
}
if (
typeof envValue === 'string' &&
(mappingValue.endsWith('_JSON') || convert === 'json')
) {
envValue = JSON.parse(envValue as string) as T[keyof T];
}
if (
typeof envValue === 'string' &&
(mappingValue.endsWith('_BASE64') || convert === 'base64')
) {
envValue = Buffer.from(envValue as string, 'base64').toString();
} }
if (!parentKey) { if (!parentKey) {
await this.kvStore.writeKey(key, envValue as any); await this.kvStore.writeKey(key, envValue);
} else { } else {
return envValue; return envValue;
} }
@ -176,13 +113,6 @@ export class AppData<T = any> {
for (const key in this.options.envMapping) { for (const key in this.options.envMapping) {
await processEnvMapping(key as keyof T, this.options.envMapping[key]); await processEnvMapping(key as keyof T, this.options.envMapping[key]);
} }
if (this.options.overwriteObject) {
for (const key of Object.keys(this.options.overwriteObject)) {
console.log(`-> heads up: overwriting key ${key} from options.overwriteObject`);
await this.kvStore.writeKey(key as keyof T, this.options.overwriteObject[key]);
}
}
} }
this.readyDeferred.resolve(); this.readyDeferred.resolve();

View File

@ -3,7 +3,7 @@ import * as paths from './npmextra.paths.js';
import { Task } from '@push.rocks/taskbuffer'; import { Task } from '@push.rocks/taskbuffer';
export type TKeyValueStore = 'custom' | 'userHomeDir' | 'ephemeral'; export type TKeyValueStore = 'custom' | 'userHomeDir';
export interface IKvStoreConstructorOptions<T> { export interface IKvStoreConstructorOptions<T> {
typeArg: TKeyValueStore; typeArg: TKeyValueStore;
@ -28,20 +28,18 @@ export class KeyValueStore<T = any> {
bufferMax: 1, bufferMax: 1,
execDelay: 0, execDelay: 0,
taskFunction: async () => { taskFunction: async () => {
if (this.type !== 'ephemeral') { this.dataObject = {
this.dataObject = { ...plugins.smartfile.fs.toObjectSync(this.filePath),
...plugins.smartfile.fs.toObjectSync(this.filePath), ...this.dataObject,
...this.dataObject, };
}; for (const key of Object.keys(this.deletedObject) as Array<keyof T>) {
for (const key of Object.keys(this.deletedObject) as Array<keyof T>) { delete this.dataObject[key];
delete this.dataObject[key];
}
this.deletedObject = {};
await plugins.smartfile.memory.toFs(
plugins.smartjson.stringifyPretty(this.dataObject),
this.filePath
);
} }
this.deletedObject = {};
await plugins.smartfile.memory.toFs(
plugins.smartjson.stringifyPretty(this.dataObject),
this.filePath
);
const newStateString = plugins.smartjson.stringify(this.dataObject); const newStateString = plugins.smartjson.stringify(this.dataObject);
// change detection // change detection
@ -56,10 +54,6 @@ export class KeyValueStore<T = any> {
* computes the identity and filePath * computes the identity and filePath
*/ */
private initFilePath = () => { private initFilePath = () => {
if (this.type === 'ephemeral') {
// No file path is needed for ephemeral type
return;
}
if (this.customPath) { if (this.customPath) {
// Use custom path if provided // Use custom path if provided
const absolutePath = plugins.smartpath.transform.makeAbsolute(this.customPath, paths.cwd); const absolutePath = plugins.smartpath.transform.makeAbsolute(this.customPath, paths.cwd);
@ -85,7 +79,7 @@ export class KeyValueStore<T = any> {
// if no custom path is provided, try to store at home directory // if no custom path is provided, try to store at home directory
public type: TKeyValueStore; public type: TKeyValueStore;
public identity: string; public identity: string;
public filePath?: string; public filePath: string;
private customPath?: string; // Optionally allow custom path private customPath?: string; // Optionally allow custom path
/** /**
@ -153,9 +147,7 @@ export class KeyValueStore<T = any> {
*/ */
public async wipe(): Promise<void> { public async wipe(): Promise<void> {
this.dataObject = {}; this.dataObject = {};
if (this.type !== 'ephemeral') { await plugins.smartfile.fs.remove(this.filePath);
await plugins.smartfile.fs.remove(this.filePath);
}
} }
/** /**

View File

@ -1,9 +1,3 @@
import * as tsclass from '@tsclass/tsclass';
export {
tsclass
}
import * as qenv from '@push.rocks/qenv'; import * as qenv from '@push.rocks/qenv';
import * as smartlog from '@push.rocks/smartlog'; import * as smartlog from '@push.rocks/smartlog';
import * as path from 'path'; import * as path from 'path';