@quatrain/core 1.1.18 → 1.1.21
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/lib/Core.d.ts +18 -8
- package/lib/Core.js +39 -0
- package/lib/components/DataObject.js +1 -2
- package/lib/components/User.js +1 -2
- package/lib/properties/BaseProperty.js +3 -2
- package/lib/properties/HashProperty.d.ts +1 -1
- package/lib/properties/HashProperty.js +1 -1
- package/lib/properties/ObjectProperty.js +49 -44
- package/package.json +8 -8
package/lib/Core.d.ts
CHANGED
|
@@ -2,18 +2,18 @@ import { User } from './components/User';
|
|
|
2
2
|
import { DataObjectClass } from './components/types/DataObjectClass';
|
|
3
3
|
import { AbstractLoggerAdapter, LogLevel } from '@quatrain/log';
|
|
4
4
|
export declare class Core {
|
|
5
|
-
static me: string;
|
|
6
|
-
static storage: any;
|
|
7
|
-
static storagePrefix
|
|
8
|
-
static userClass: typeof User;
|
|
9
|
-
static classRegistry: {
|
|
5
|
+
static readonly me: string;
|
|
6
|
+
static readonly storage: any;
|
|
7
|
+
static readonly storagePrefix = "core";
|
|
8
|
+
static readonly userClass: typeof User;
|
|
9
|
+
static readonly classRegistry: {
|
|
10
10
|
[key: string]: any;
|
|
11
11
|
};
|
|
12
|
-
static logLevel
|
|
13
|
-
static logger: AbstractLoggerAdapter;
|
|
12
|
+
static readonly logLevel = LogLevel.DEBUG;
|
|
13
|
+
static readonly logger: AbstractLoggerAdapter;
|
|
14
14
|
static addLogger(alias?: string): any;
|
|
15
15
|
static setLogLevel(level: LogLevel): void;
|
|
16
|
-
static timestamp: () => string;
|
|
16
|
+
static readonly timestamp: () => string;
|
|
17
17
|
static definition(key: string): {
|
|
18
18
|
manifest: {
|
|
19
19
|
type: StringConstructor;
|
|
@@ -24,6 +24,16 @@ export declare class Core {
|
|
|
24
24
|
static getConfig(key: string): Promise<any>;
|
|
25
25
|
static addClass(name: string, obj: any): void;
|
|
26
26
|
static getClass(name: string): any;
|
|
27
|
+
/**
|
|
28
|
+
* Execute an external command in a promise
|
|
29
|
+
* @see https://stackoverflow.com/questions/46289682/how-to-wait-for-child-process-spawn-execution-with-async-await
|
|
30
|
+
* @see https://dzone.com/articles/understanding-execfile-spawn-exec-and-fork-in-node
|
|
31
|
+
* @param string command
|
|
32
|
+
* @param array args
|
|
33
|
+
* @return Promise
|
|
34
|
+
*/
|
|
35
|
+
static readonly execPromise: (command: string, args?: any[], cwd?: string) => Promise<any>;
|
|
36
|
+
static readonly getSystemCommandPath: (command: string) => Promise<string>;
|
|
27
37
|
/**
|
|
28
38
|
* Returns the class to use for a data object
|
|
29
39
|
* This is currently just a stub that will be implemented from config in the future
|
package/lib/Core.js
CHANGED
|
@@ -8,12 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
var _a;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.Core = void 0;
|
|
14
17
|
const DataObject_1 = require("./components/DataObject");
|
|
15
18
|
const User_1 = require("./components/User");
|
|
16
19
|
const log_1 = require("@quatrain/log");
|
|
20
|
+
const child_process_1 = require("child_process");
|
|
21
|
+
const which_1 = __importDefault(require("which"));
|
|
17
22
|
class Core {
|
|
18
23
|
static addLogger(alias = this.name) {
|
|
19
24
|
return log_1.Log.addLogger('@' + alias, new log_1.DefaultLoggerAdapter(alias, this.logLevel), true);
|
|
@@ -89,3 +94,37 @@ Core.logLevel = log_1.LogLevel.DEBUG;
|
|
|
89
94
|
Core.logger = _a.addLogger();
|
|
90
95
|
// How timestamp are formatted
|
|
91
96
|
Core.timestamp = () => new Date().toISOString();
|
|
97
|
+
/**
|
|
98
|
+
* Execute an external command in a promise
|
|
99
|
+
* @see https://stackoverflow.com/questions/46289682/how-to-wait-for-child-process-spawn-execution-with-async-await
|
|
100
|
+
* @see https://dzone.com/articles/understanding-execfile-spawn-exec-and-fork-in-node
|
|
101
|
+
* @param string command
|
|
102
|
+
* @param array args
|
|
103
|
+
* @return Promise
|
|
104
|
+
*/
|
|
105
|
+
Core.execPromise = (command, args = [], cwd = process.cwd()) => {
|
|
106
|
+
try {
|
|
107
|
+
_a.info(`Executing command ${command} in ${cwd} with arguments:`);
|
|
108
|
+
args.forEach((arg) => console.log(`\t${arg}`));
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const child = (0, child_process_1.spawn)(command, args, { cwd });
|
|
111
|
+
child.stdout.on('data', (data) => _a.debug(data.toString()));
|
|
112
|
+
child.stderr.on('data', (data) => _a.debug(data.toString()));
|
|
113
|
+
child.on('close', (code) => {
|
|
114
|
+
if (code !== 0) {
|
|
115
|
+
_a.error(`Command execution failed with code: ${code}`);
|
|
116
|
+
reject(new Error(`Process failed and returned code: ${code}`));
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
_a.info(`Command execution completed with code: ${code}`);
|
|
120
|
+
resolve(undefined);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
_a.error(err.message);
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
Core.getSystemCommandPath = (command) => (0, which_1.default)(command);
|
|
@@ -247,11 +247,10 @@ class DataObject {
|
|
|
247
247
|
const data = {};
|
|
248
248
|
Object.keys(this._properties).forEach((key) => {
|
|
249
249
|
const prop = Reflect.get(this._properties, key);
|
|
250
|
-
if (ignoreNulls &&
|
|
250
|
+
if (ignoreNulls && (prop.val() === null || prop.val() === undefined))
|
|
251
251
|
return;
|
|
252
252
|
if (ignoreUnchanged && prop.hasChanged === false)
|
|
253
253
|
return;
|
|
254
|
-
// console.log(prop.constructor.name);
|
|
255
254
|
switch (prop.constructor.name) {
|
|
256
255
|
case 'CollectionProperty':
|
|
257
256
|
// ignore
|
package/lib/components/User.js
CHANGED
|
@@ -39,7 +39,6 @@ const HashProperty_1 = require("../properties/HashProperty");
|
|
|
39
39
|
const StringProperty_1 = require("../properties/StringProperty");
|
|
40
40
|
const htmlType = __importStar(require("../properties/types/PropertyHTMLType"));
|
|
41
41
|
const BaseObjectProperties_1 = require("./BaseObjectProperties");
|
|
42
|
-
const Entity_1 = require("./Entity");
|
|
43
42
|
/**
|
|
44
43
|
* Callback function to populate the 'name' property
|
|
45
44
|
* @param dao DataObject
|
|
@@ -118,7 +117,7 @@ exports.UserProperties = [
|
|
|
118
117
|
name: 'entity',
|
|
119
118
|
mandatory: false,
|
|
120
119
|
type: properties_1.ObjectProperty.TYPE,
|
|
121
|
-
instanceOf:
|
|
120
|
+
instanceOf: 'Entity',
|
|
122
121
|
},
|
|
123
122
|
];
|
|
124
123
|
class User extends BaseObject_1.BaseObject {
|
|
@@ -18,7 +18,7 @@ class BaseProperty {
|
|
|
18
18
|
typeof config.defaultValue === 'function'
|
|
19
19
|
? config.defaultValue()
|
|
20
20
|
: config.defaultValue;
|
|
21
|
-
this._value =
|
|
21
|
+
this._value = this._defaultValue;
|
|
22
22
|
this._hasChanged = false;
|
|
23
23
|
this._htmlType = config.htmlType || 'off';
|
|
24
24
|
if (typeof config.onChange === 'function') {
|
|
@@ -56,7 +56,8 @@ class BaseProperty {
|
|
|
56
56
|
this._protected === true) {
|
|
57
57
|
throw new Error(`Value '${this._name}' already defined as '${this._value}' and protected from change`);
|
|
58
58
|
}
|
|
59
|
-
if (value
|
|
59
|
+
if (JSON.stringify({ value: value }) !==
|
|
60
|
+
JSON.stringify({ value: this._value })) {
|
|
60
61
|
this._value = value;
|
|
61
62
|
this._hasChanged = setChanged;
|
|
62
63
|
}
|
|
@@ -17,7 +17,7 @@ export declare class HashProperty extends StringProperty {
|
|
|
17
17
|
constructor(config: HashPropertyType);
|
|
18
18
|
_hash(value: string): string;
|
|
19
19
|
/**
|
|
20
|
-
* Never return the
|
|
20
|
+
* Never return the value which is hashed anyway
|
|
21
21
|
* @param transform
|
|
22
22
|
* @returns
|
|
23
23
|
*/
|
|
@@ -23,51 +23,56 @@ class ObjectProperty extends BaseProperty_1.BaseProperty {
|
|
|
23
23
|
return this._instanceOf;
|
|
24
24
|
}
|
|
25
25
|
val(transform = undefined) {
|
|
26
|
-
|
|
27
|
-
this._instanceOf
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
try {
|
|
27
|
+
if (typeof this._instanceOf === 'string') {
|
|
28
|
+
this._instanceOf = Core_1.Core.getClass(this._instanceOf);
|
|
29
|
+
}
|
|
30
|
+
if (!this._value) {
|
|
31
|
+
return this._defaultValue;
|
|
32
|
+
}
|
|
33
|
+
switch (transform) {
|
|
34
|
+
case returnAs.AS_DATAOBJECTS:
|
|
35
|
+
if (this._value instanceof DataObject_1.DataObject) {
|
|
36
|
+
Core_1.Core.debug(`Returning already existing dataObject`);
|
|
37
|
+
return this._value;
|
|
38
|
+
}
|
|
39
|
+
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
40
|
+
Core_1.Core.debug(`Converting objectUri -> dataObject`);
|
|
41
|
+
return DataObject_1.DataObject.factory({
|
|
42
|
+
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
43
|
+
uri: this._value,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
Core_1.Core.debug(`Converting instance -> dataObject`);
|
|
48
|
+
return this._value.dataObject;
|
|
49
|
+
}
|
|
50
|
+
case returnAs.AS_INSTANCES:
|
|
51
|
+
if (this._value instanceof DataObject_1.DataObject) {
|
|
52
|
+
Core_1.Core.debug(`Converting dataObject -> instance`);
|
|
53
|
+
return Reflect.construct(this._instanceOf, [this._value]);
|
|
54
|
+
}
|
|
55
|
+
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
56
|
+
Core_1.Core.debug(`Converting objectUri -> dataObject -> instance`);
|
|
57
|
+
const dao = DataObject_1.DataObject.factory({
|
|
58
|
+
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
59
|
+
uri: this._value,
|
|
60
|
+
});
|
|
61
|
+
return Reflect.construct(this._instanceOf, [dao]);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
Core_1.Core.log(`Returning already existing instance`);
|
|
65
|
+
return this._value;
|
|
66
|
+
}
|
|
67
|
+
case returnAs.AS_OBJECTURIS:
|
|
68
|
+
default:
|
|
36
69
|
return this._value;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
Core_1.Core.log(`Converting instance -> dataObject`);
|
|
47
|
-
return this._value.dataObject;
|
|
48
|
-
}
|
|
49
|
-
case returnAs.AS_INSTANCES:
|
|
50
|
-
if (this._value instanceof DataObject_1.DataObject) {
|
|
51
|
-
Core_1.Core.log(`Converting dataObject -> instance`);
|
|
52
|
-
return Reflect.construct(this._instanceOf, [this._value]);
|
|
53
|
-
}
|
|
54
|
-
else if (this._value instanceof ObjectUri_1.ObjectUri) {
|
|
55
|
-
// console.log('ObjectProperty', this)
|
|
56
|
-
Core_1.Core.log(`Converting objectUri -> dataObject -> instance`);
|
|
57
|
-
// console.log(this._instanceOf)
|
|
58
|
-
const dao = DataObject_1.DataObject.factory({
|
|
59
|
-
properties: Reflect.get(this._instanceOf, 'PROPS_DEFINITION'),
|
|
60
|
-
uri: this._value,
|
|
61
|
-
});
|
|
62
|
-
return Reflect.construct(this._instanceOf, [dao]);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
Core_1.Core.log(`Returning already existing instance`);
|
|
66
|
-
return this._value;
|
|
67
|
-
}
|
|
68
|
-
case returnAs.AS_OBJECTURIS:
|
|
69
|
-
default:
|
|
70
|
-
return this._value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
Core_1.Core.error(`Error in ObjectProperty.val() for property ${this._name}: ${err}`);
|
|
74
|
+
console.log(err);
|
|
75
|
+
return undefined;
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
set(value, setChanged = true) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.21",
|
|
4
4
|
"description": "Core objects for business apps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -12,21 +12,21 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@tsconfig/recommended": "^1.0.1",
|
|
15
|
-
"@types/jest": "^
|
|
15
|
+
"@types/jest": "^30.0.0",
|
|
16
16
|
"@types/node": "^22.10.1",
|
|
17
17
|
"@types/node-persist": "^3.1.8",
|
|
18
|
-
"
|
|
19
|
-
"jest
|
|
18
|
+
"@types/which": "^3.0.4",
|
|
19
|
+
"jest": "^30.1.1",
|
|
20
20
|
"trace-unhandled": "^2.0.1",
|
|
21
|
-
"ts-jest": "^
|
|
21
|
+
"ts-jest": "^29.4.1",
|
|
22
22
|
"ts-node": "^10.4.0",
|
|
23
23
|
"typescript": "^5.1.5"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@faker-js/faker": "^7.6.0",
|
|
27
|
-
"@quatrain/log": "^0.
|
|
28
|
-
"
|
|
29
|
-
"
|
|
27
|
+
"@quatrain/log": "^1.0.2",
|
|
28
|
+
"node-persist": "^4.0.4",
|
|
29
|
+
"which": "^5.0.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"test-ci": "jest --runInBand",
|