fix(core): update

This commit is contained in:
Philipp Kunz 2024-06-19 15:07:49 +02:00
parent 6f19c3cc71
commit 937252f99e
5 changed files with 65 additions and 52 deletions

View File

@ -35,7 +35,7 @@
"@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.2" "@types/node": "^20.14.5"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

66
pnpm-lock.yaml generated
View File

@ -38,16 +38,16 @@ importers:
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.2) version: 1.2.46(@types/node@20.14.5)
'@git.zone/tstest': '@git.zone/tstest':
specifier: ^1.0.90 specifier: ^1.0.90
version: 1.0.90(@types/node@20.14.2) version: 1.0.90(@types/node@20.14.5)
'@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.2 specifier: ^20.14.5
version: 20.14.2 version: 20.14.5
packages: packages:
@ -766,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.2': '@types/node@20.14.5':
resolution: {integrity: sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==} resolution: {integrity: sha512-aoRR+fJkZT2l0aGOJhuA8frnCSoNX6W7U2mpNq63+BxBIj5BQFt8rHy627kijCmm63ijdSdwvGgpUsU6MBsZZA==}
'@types/parse5@6.0.3': '@types/parse5@6.0.3':
resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==} resolution: {integrity: sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==}
@ -3257,22 +3257,22 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
'@git.zone/tsrun@1.2.46(@types/node@20.14.2)': '@git.zone/tsrun@1.2.46(@types/node@20.14.5)':
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.2)(typescript@5.1.6) ts-node: 10.9.2(@types/node@20.14.5)(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.2)': '@git.zone/tstest@1.0.90(@types/node@20.14.5)':
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.2) '@git.zone/tsrun': 1.2.46(@types/node@20.14.5)
'@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
@ -4027,14 +4027,14 @@ snapshots:
'@types/accepts@1.3.7': '@types/accepts@1.3.7':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
'@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.2 '@types/node': 20.14.5
'@types/buffer-json@2.0.3': {} '@types/buffer-json@2.0.3': {}
@ -4046,17 +4046,17 @@ snapshots:
'@types/clean-css@4.2.11': '@types/clean-css@4.2.11':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
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.2 '@types/node': 20.14.5
'@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.2 '@types/node': 20.14.5
'@types/content-disposition@0.5.8': {} '@types/content-disposition@0.5.8': {}
@ -4069,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.2 '@types/node': 20.14.5
'@types/cors@2.8.17': '@types/cors@2.8.17':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
'@types/debounce@1.2.4': {} '@types/debounce@1.2.4': {}
@ -4085,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.2 '@types/node': 20.14.5
'@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
@ -4099,17 +4099,17 @@ snapshots:
'@types/from2@2.3.5': '@types/from2@2.3.5':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
'@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.2 '@types/node': 20.14.5
'@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.2 '@types/node': 20.14.5
'@types/hast@3.0.4': '@types/hast@3.0.4':
dependencies: dependencies:
@ -4143,7 +4143,7 @@ snapshots:
'@types/jsonfile@6.1.4': '@types/jsonfile@6.1.4':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
'@types/keygrip@1.0.6': {} '@types/keygrip@1.0.6': {}
@ -4160,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.2 '@types/node': 20.14.5
'@types/mdast@4.0.4': '@types/mdast@4.0.4':
dependencies: dependencies:
@ -4176,7 +4176,7 @@ snapshots:
'@types/ms@0.7.34': {} '@types/ms@0.7.34': {}
'@types/node@20.14.2': '@types/node@20.14.5':
dependencies: dependencies:
undici-types: 5.26.5 undici-types: 5.26.5
@ -4195,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.2 '@types/node': 20.14.5
'@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.2 '@types/node': 20.14.5
'@types/send': 0.17.4 '@types/send': 0.17.4
'@types/sinon-chai@3.2.12': '@types/sinon-chai@3.2.12':
@ -4218,7 +4218,7 @@ snapshots:
'@types/through2@2.0.41': '@types/through2@2.0.41':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
'@types/trusted-types@2.0.7': {} '@types/trusted-types@2.0.7': {}
@ -4238,15 +4238,15 @@ snapshots:
'@types/ws@7.4.7': '@types/ws@7.4.7':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
'@types/ws@8.5.10': '@types/ws@8.5.10':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
'@types/yauzl@2.10.3': '@types/yauzl@2.10.3':
dependencies: dependencies:
'@types/node': 20.14.2 '@types/node': 20.14.5
optional: true optional: true
'@ungap/structured-clone@1.2.0': {} '@ungap/structured-clone@1.2.0': {}
@ -4754,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.2 '@types/node': 20.14.5
accepts: 1.3.8 accepts: 1.3.8
base64id: 2.0.0 base64id: 2.0.0
cookie: 0.4.2 cookie: 0.4.2
@ -6520,14 +6520,14 @@ snapshots:
trough@2.2.0: {} trough@2.2.0: {}
ts-node@10.9.2(@types/node@20.14.2)(typescript@5.1.6): ts-node@10.9.2(@types/node@20.14.5)(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.2 '@types/node': 20.14.5
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

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/npmextra', name: '@push.rocks/npmextra',
version: '5.0.17', version: '5.0.18',
description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.' description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.'
} }

View File

@ -7,6 +7,11 @@ 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'
*/ */
@ -43,7 +48,7 @@ export class AppData<T = any> {
* @param pathArg * @param pathArg
*/ */
private async init(pathArg?: string) { private async init(pathArg?: string) {
if (this.options.dirPath) { if (this.options.dirPath || this.options.ephermal) {
// ok, nothing to do here; // ok, nothing to do here;
} else { } else {
const appDataDir = '/app/data'; const appDataDir = '/app/data';
@ -62,7 +67,7 @@ export class AppData<T = any> {
} }
this.kvStore = new KeyValueStore<T>({ this.kvStore = new KeyValueStore<T>({
typeArg: 'custom', typeArg: this.options.ephermal ? 'ephemeral' : '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>

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'; export type TKeyValueStore = 'custom' | 'userHomeDir' | 'ephemeral';
export interface IKvStoreConstructorOptions<T> { export interface IKvStoreConstructorOptions<T> {
typeArg: TKeyValueStore; typeArg: TKeyValueStore;
@ -20,7 +20,7 @@ export class KeyValueStore<T = any> {
private deletedObject: Partial<T> = {}; private deletedObject: Partial<T> = {};
private mandatoryKeys: Set<keyof T> = new Set(); private mandatoryKeys: Set<keyof T> = new Set();
public changeSubject = new plugins.smartrx.rxjs.Subject<Partial<T>>(); public changeSubject = new plugins.smartrx.rxjs.Subject<Partial<T>>();
private storedStateString: string = ''; private storedStateString: string = '';
public syncTask = new Task({ public syncTask = new Task({
name: 'syncTask', name: 'syncTask',
@ -28,18 +28,20 @@ export class KeyValueStore<T = any> {
bufferMax: 1, bufferMax: 1,
execDelay: 0, execDelay: 0,
taskFunction: async () => { taskFunction: async () => {
this.dataObject = { if (this.type !== 'ephemeral') {
...plugins.smartfile.fs.toObjectSync(this.filePath), this.dataObject = {
...this.dataObject, ...plugins.smartfile.fs.toObjectSync(this.filePath),
}; ...this.dataObject,
for (const key of Object.keys(this.deletedObject) as Array<keyof T>) { };
delete this.dataObject[key]; for (const key of Object.keys(this.deletedObject) as Array<keyof T>) {
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
@ -54,6 +56,10 @@ 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);
@ -79,7 +85,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
/** /**
@ -147,7 +153,9 @@ export class KeyValueStore<T = any> {
*/ */
public async wipe(): Promise<void> { public async wipe(): Promise<void> {
this.dataObject = {}; this.dataObject = {};
await plugins.smartfile.fs.remove(this.filePath); if (this.type !== 'ephemeral') {
await plugins.smartfile.fs.remove(this.filePath);
}
} }
/** /**