@push.rocks/smartconfig 6.0.1 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.smartconfig.json +13 -7
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.appdata.js +7 -6
- package/dist_ts/classes.keyvaluestore.d.ts +1 -1
- package/dist_ts/classes.keyvaluestore.js +18 -10
- package/dist_ts/classes.smartconfig.js +4 -3
- package/dist_ts/plugins.d.ts +4 -2
- package/dist_ts/plugins.js +5 -3
- package/license +21 -0
- package/package.json +19 -16
- package/readme.md +195 -390
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.appdata.ts +8 -7
- package/ts/classes.keyvaluestore.ts +17 -12
- package/ts/classes.smartconfig.ts +5 -7
- package/ts/plugins.ts +6 -2
package/ts/00_commitinfo_data.ts
CHANGED
package/ts/classes.appdata.ts
CHANGED
|
@@ -403,7 +403,7 @@ export class AppData<T = any> {
|
|
|
403
403
|
// instance
|
|
404
404
|
public readyDeferred = plugins.smartpromise.defer<void>();
|
|
405
405
|
public options: IAppDataOptions<T>;
|
|
406
|
-
private kvStore
|
|
406
|
+
private kvStore!: KeyValueStore<T>;
|
|
407
407
|
|
|
408
408
|
constructor(optionsArg: IAppDataOptions<T> = {}) {
|
|
409
409
|
this.options = optionsArg;
|
|
@@ -430,8 +430,8 @@ export class AppData<T = any> {
|
|
|
430
430
|
const appDataDir = '/app/data';
|
|
431
431
|
const dataDir = '/data';
|
|
432
432
|
const nogitAppData = '.nogit/appdata';
|
|
433
|
-
const appDataExists = plugins.
|
|
434
|
-
const dataExists = plugins.
|
|
433
|
+
const appDataExists = plugins.nodeFs.existsSync(appDataDir) && plugins.nodeFs.statSync(appDataDir).isDirectory();
|
|
434
|
+
const dataExists = plugins.nodeFs.existsSync(dataDir) && plugins.nodeFs.statSync(dataDir).isDirectory();
|
|
435
435
|
if (appDataExists) {
|
|
436
436
|
this.options.dirPath = appDataDir;
|
|
437
437
|
console.log(` 📁 Auto-selected container directory: ${appDataDir}`);
|
|
@@ -439,7 +439,7 @@ export class AppData<T = any> {
|
|
|
439
439
|
this.options.dirPath = dataDir;
|
|
440
440
|
console.log(` 📁 Auto-selected data directory: ${dataDir}`);
|
|
441
441
|
} else {
|
|
442
|
-
await plugins.
|
|
442
|
+
await plugins.smartFs.directory(nogitAppData).create();
|
|
443
443
|
this.options.dirPath = nogitAppData;
|
|
444
444
|
console.log(` 📁 Auto-selected local directory: ${nogitAppData}`);
|
|
445
445
|
}
|
|
@@ -494,17 +494,18 @@ export class AppData<T = any> {
|
|
|
494
494
|
|
|
495
495
|
// Apply overwrite object after env mapping
|
|
496
496
|
if (this.options.overwriteObject) {
|
|
497
|
-
const
|
|
497
|
+
const overwriteObject = this.options.overwriteObject as Record<string, unknown>;
|
|
498
|
+
const overwriteKeys = Object.keys(overwriteObject);
|
|
498
499
|
console.log(`🔄 Applying overwriteObject with ${overwriteKeys.length} key(s)...`);
|
|
499
500
|
|
|
500
501
|
for (const key of overwriteKeys) {
|
|
501
|
-
const value =
|
|
502
|
+
const value = overwriteObject[key];
|
|
502
503
|
const valueType = Array.isArray(value) ? 'array' : typeof value;
|
|
503
504
|
console.log(` 🔧 Overwriting key "${key}" with ${valueType} value`);
|
|
504
505
|
|
|
505
506
|
await this.kvStore.writeKey(
|
|
506
507
|
key as keyof T,
|
|
507
|
-
value,
|
|
508
|
+
value as T[keyof T],
|
|
508
509
|
);
|
|
509
510
|
}
|
|
510
511
|
|
|
@@ -26,21 +26,18 @@ export class KeyValueStore<T = any> {
|
|
|
26
26
|
name: 'syncTask',
|
|
27
27
|
buffered: true,
|
|
28
28
|
bufferMax: 1,
|
|
29
|
-
execDelay: 0,
|
|
30
29
|
taskFunction: async () => {
|
|
31
30
|
if (this.type !== 'ephemeral') {
|
|
31
|
+
const storedJson = await plugins.smartFs.file(this.filePath!).encoding('utf8').read() as string;
|
|
32
32
|
this.dataObject = {
|
|
33
|
-
...plugins.
|
|
33
|
+
...plugins.smartjson.parse(storedJson || '{}'),
|
|
34
34
|
...this.dataObject,
|
|
35
35
|
};
|
|
36
36
|
for (const key of Object.keys(this.deletedObject) as Array<keyof T>) {
|
|
37
37
|
delete this.dataObject[key];
|
|
38
38
|
}
|
|
39
39
|
this.deletedObject = {};
|
|
40
|
-
await plugins.
|
|
41
|
-
plugins.smartjson.stringifyPretty(this.dataObject),
|
|
42
|
-
this.filePath,
|
|
43
|
-
);
|
|
40
|
+
await plugins.smartFs.file(this.filePath!).encoding('utf8').write(plugins.smartjson.stringifyPretty(this.dataObject));
|
|
44
41
|
}
|
|
45
42
|
const newStateString = plugins.smartjson.stringify(this.dataObject);
|
|
46
43
|
|
|
@@ -67,13 +64,16 @@ export class KeyValueStore<T = any> {
|
|
|
67
64
|
paths.cwd,
|
|
68
65
|
);
|
|
69
66
|
this.filePath = absolutePath;
|
|
70
|
-
if (plugins.
|
|
67
|
+
if (plugins.nodeFs.existsSync(this.filePath) && plugins.nodeFs.statSync(this.filePath).isDirectory()) {
|
|
71
68
|
this.filePath = plugins.path.join(
|
|
72
69
|
this.filePath,
|
|
73
70
|
this.identity + '.json',
|
|
74
71
|
);
|
|
75
72
|
}
|
|
76
|
-
plugins.
|
|
73
|
+
plugins.nodeFs.mkdirSync(plugins.path.dirname(this.filePath), { recursive: true });
|
|
74
|
+
if (!plugins.nodeFs.existsSync(this.filePath)) {
|
|
75
|
+
plugins.nodeFs.writeFileSync(this.filePath, '{}');
|
|
76
|
+
}
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -84,8 +84,10 @@ export class KeyValueStore<T = any> {
|
|
|
84
84
|
throw new Error('kv type not supported');
|
|
85
85
|
}
|
|
86
86
|
this.filePath = plugins.path.join(baseDir, this.identity + '.json');
|
|
87
|
-
plugins.
|
|
88
|
-
plugins.
|
|
87
|
+
plugins.nodeFs.mkdirSync(baseDir, { recursive: true });
|
|
88
|
+
if (!plugins.nodeFs.existsSync(this.filePath)) {
|
|
89
|
+
plugins.nodeFs.writeFileSync(this.filePath, '{}');
|
|
90
|
+
}
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
// if no custom path is provided, try to store at home directory
|
|
@@ -162,8 +164,11 @@ export class KeyValueStore<T = any> {
|
|
|
162
164
|
*/
|
|
163
165
|
public async wipe(): Promise<void> {
|
|
164
166
|
this.dataObject = {};
|
|
165
|
-
if (this.type !== 'ephemeral') {
|
|
166
|
-
|
|
167
|
+
if (this.type !== 'ephemeral' && this.filePath) {
|
|
168
|
+
const file = plugins.smartFs.file(this.filePath);
|
|
169
|
+
if (await file.exists()) {
|
|
170
|
+
await file.delete();
|
|
171
|
+
}
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
|
|
@@ -6,8 +6,8 @@ import * as paths from './paths.js';
|
|
|
6
6
|
*/
|
|
7
7
|
export class Smartconfig {
|
|
8
8
|
cwd: string;
|
|
9
|
-
lookupPath
|
|
10
|
-
smartconfigJsonExists
|
|
9
|
+
lookupPath!: string;
|
|
10
|
+
smartconfigJsonExists = false;
|
|
11
11
|
smartconfigJsonData: any;
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -48,9 +48,7 @@ export class Smartconfig {
|
|
|
48
48
|
* checks if the JSON exists
|
|
49
49
|
*/
|
|
50
50
|
private checkSmartconfigJsonExists() {
|
|
51
|
-
this.smartconfigJsonExists = plugins.
|
|
52
|
-
this.lookupPath,
|
|
53
|
-
);
|
|
51
|
+
this.smartconfigJsonExists = plugins.nodeFs.existsSync(this.lookupPath);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
/**
|
|
@@ -69,8 +67,8 @@ export class Smartconfig {
|
|
|
69
67
|
*/
|
|
70
68
|
private checkSmartconfigJsonData() {
|
|
71
69
|
if (this.smartconfigJsonExists) {
|
|
72
|
-
this.smartconfigJsonData = plugins.
|
|
73
|
-
this.lookupPath,
|
|
70
|
+
this.smartconfigJsonData = plugins.smartjson.parse(
|
|
71
|
+
plugins.nodeFs.readFileSync(this.lookupPath, 'utf8'),
|
|
74
72
|
);
|
|
75
73
|
} else {
|
|
76
74
|
this.smartconfigJsonData = {};
|
package/ts/plugins.ts
CHANGED
|
@@ -4,19 +4,23 @@ export { tsclass };
|
|
|
4
4
|
|
|
5
5
|
import * as qenv from '@push.rocks/qenv';
|
|
6
6
|
import * as smartlog from '@push.rocks/smartlog';
|
|
7
|
+
import * as nodeFs from 'node:fs';
|
|
7
8
|
import * as path from 'path';
|
|
8
|
-
import * as
|
|
9
|
+
import * as smartfs from '@push.rocks/smartfs';
|
|
9
10
|
import * as smartjson from '@push.rocks/smartjson';
|
|
10
11
|
import * as smartpath from '@push.rocks/smartpath';
|
|
11
12
|
import * as smartpromise from '@push.rocks/smartpromise';
|
|
12
13
|
import * as smartrx from '@push.rocks/smartrx';
|
|
13
14
|
import * as taskbuffer from '@push.rocks/taskbuffer';
|
|
14
15
|
|
|
16
|
+
export const smartFs = new smartfs.SmartFs(new smartfs.SmartFsProviderNode());
|
|
17
|
+
|
|
15
18
|
export {
|
|
16
19
|
qenv,
|
|
17
20
|
smartlog,
|
|
21
|
+
nodeFs,
|
|
18
22
|
path,
|
|
19
|
-
|
|
23
|
+
smartfs,
|
|
20
24
|
smartjson,
|
|
21
25
|
smartpath,
|
|
22
26
|
smartpromise,
|