@itrocks/core-transformers 0.0.4 → 0.0.6
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/cjs/store.d.ts +2 -2
- package/cjs/store.js +16 -6
- package/esm/store.d.ts +2 -2
- package/esm/store.js +16 -6
- package/package.json +2 -2
package/cjs/store.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export type SqlDependencies = {
|
|
|
5
5
|
};
|
|
6
6
|
export type Dependencies = SqlDependencies & {
|
|
7
7
|
displayOf: (object: AnyObject, property: string) => string;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
fieldIdOf: (property: string) => string;
|
|
9
|
+
fieldNameOf: (property: string) => string;
|
|
10
10
|
representativeValueOf: (object: object) => string;
|
|
11
11
|
routeOf: (type: Type) => string;
|
|
12
12
|
tr: (text: string) => string;
|
package/cjs/store.js
CHANGED
|
@@ -14,8 +14,8 @@ const transformer_3 = require("@itrocks/transformer");
|
|
|
14
14
|
const lfTab = '\n\t\t\t\t';
|
|
15
15
|
const depends = {
|
|
16
16
|
displayOf: (_object, property) => property,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
fieldIdOf: property => property,
|
|
18
|
+
fieldNameOf: property => property,
|
|
19
19
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
20
20
|
representativeValueOf: object => (0, class_type_1.baseType)((0, class_type_1.typeOf)(object)).name,
|
|
21
21
|
routeOf: type => '/' + (0, class_type_1.baseType)(type).name,
|
|
@@ -39,8 +39,8 @@ function setStoreDependencies(dependencies) {
|
|
|
39
39
|
exports.setStoreHtmlDependencies = setStoreDependencies;
|
|
40
40
|
exports.setStoreSqlDependencies = setStoreDependencies;
|
|
41
41
|
function storeEdit(value, object, property) {
|
|
42
|
-
const fieldName = depends.
|
|
43
|
-
const fieldId = depends.
|
|
42
|
+
const fieldName = depends.fieldNameOf(property);
|
|
43
|
+
const fieldId = depends.fieldIdOf(property);
|
|
44
44
|
const propertyType = new reflect_1.ReflectProperty(object, property).type;
|
|
45
45
|
const textValue = value ? depends.representativeValueOf(value) : '';
|
|
46
46
|
const fetch = depends.routeOf(propertyType) + '/summary';
|
|
@@ -53,13 +53,23 @@ function storeEdit(value, object, property) {
|
|
|
53
53
|
}
|
|
54
54
|
function storeInput(value, object, property, data) {
|
|
55
55
|
const propertyId = property + 'Id';
|
|
56
|
-
const fieldId = depends.
|
|
56
|
+
const fieldId = depends.fieldNameOf(propertyId);
|
|
57
57
|
if ((fieldId in data)
|
|
58
58
|
&& ((propertyId in object)
|
|
59
59
|
? (data[fieldId] !== object[propertyId] + '')
|
|
60
60
|
: (data[fieldId] !== value?.id + ''))) {
|
|
61
61
|
delete object[property];
|
|
62
|
-
|
|
62
|
+
const id = +data[fieldId];
|
|
63
|
+
if (id) {
|
|
64
|
+
Object.assign(object, { [propertyId]: id });
|
|
65
|
+
}
|
|
66
|
+
else if ((typeof value === 'object')) {
|
|
67
|
+
Object.assign(object, { [property]: value });
|
|
68
|
+
}
|
|
69
|
+
else if ((typeof value === 'string') && (value !== '')) {
|
|
70
|
+
const reflectProperty = new reflect_1.ReflectProperty(object, property);
|
|
71
|
+
Object.assign(object, { [property]: new reflectProperty.type(value) });
|
|
72
|
+
}
|
|
63
73
|
}
|
|
64
74
|
return depends.ignoreTransformedValue;
|
|
65
75
|
}
|
package/esm/store.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export type SqlDependencies = {
|
|
|
5
5
|
};
|
|
6
6
|
export type Dependencies = SqlDependencies & {
|
|
7
7
|
displayOf: (object: AnyObject, property: string) => string;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
fieldIdOf: (property: string) => string;
|
|
9
|
+
fieldNameOf: (property: string) => string;
|
|
10
10
|
representativeValueOf: (object: object) => string;
|
|
11
11
|
routeOf: (type: Type) => string;
|
|
12
12
|
tr: (text: string) => string;
|
package/esm/store.js
CHANGED
|
@@ -7,8 +7,8 @@ import { INPUT, OUTPUT, SAVE, SQL } from '@itrocks/transformer';
|
|
|
7
7
|
const lfTab = '\n\t\t\t\t';
|
|
8
8
|
const depends = {
|
|
9
9
|
displayOf: (_object, property) => property,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
fieldIdOf: property => property,
|
|
11
|
+
fieldNameOf: property => property,
|
|
12
12
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
13
13
|
representativeValueOf: object => baseType(typeOf(object)).name,
|
|
14
14
|
routeOf: type => '/' + baseType(type).name,
|
|
@@ -32,8 +32,8 @@ export function setStoreDependencies(dependencies) {
|
|
|
32
32
|
export const setStoreHtmlDependencies = setStoreDependencies;
|
|
33
33
|
export const setStoreSqlDependencies = setStoreDependencies;
|
|
34
34
|
function storeEdit(value, object, property) {
|
|
35
|
-
const fieldName = depends.
|
|
36
|
-
const fieldId = depends.
|
|
35
|
+
const fieldName = depends.fieldNameOf(property);
|
|
36
|
+
const fieldId = depends.fieldIdOf(property);
|
|
37
37
|
const propertyType = new ReflectProperty(object, property).type;
|
|
38
38
|
const textValue = value ? depends.representativeValueOf(value) : '';
|
|
39
39
|
const fetch = depends.routeOf(propertyType) + '/summary';
|
|
@@ -46,13 +46,23 @@ function storeEdit(value, object, property) {
|
|
|
46
46
|
}
|
|
47
47
|
function storeInput(value, object, property, data) {
|
|
48
48
|
const propertyId = property + 'Id';
|
|
49
|
-
const fieldId = depends.
|
|
49
|
+
const fieldId = depends.fieldNameOf(propertyId);
|
|
50
50
|
if ((fieldId in data)
|
|
51
51
|
&& ((propertyId in object)
|
|
52
52
|
? (data[fieldId] !== object[propertyId] + '')
|
|
53
53
|
: (data[fieldId] !== value?.id + ''))) {
|
|
54
54
|
delete object[property];
|
|
55
|
-
|
|
55
|
+
const id = +data[fieldId];
|
|
56
|
+
if (id) {
|
|
57
|
+
Object.assign(object, { [propertyId]: id });
|
|
58
|
+
}
|
|
59
|
+
else if ((typeof value === 'object')) {
|
|
60
|
+
Object.assign(object, { [property]: value });
|
|
61
|
+
}
|
|
62
|
+
else if ((typeof value === 'string') && (value !== '')) {
|
|
63
|
+
const reflectProperty = new ReflectProperty(object, property);
|
|
64
|
+
Object.assign(object, { [property]: new reflectProperty.type(value) });
|
|
65
|
+
}
|
|
56
66
|
}
|
|
57
67
|
return depends.ignoreTransformedValue;
|
|
58
68
|
}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"description": "Prefabricated HTML and SQL data transformers for it.rocks primitives and basic types",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/node": "^22.10",
|
|
17
|
-
"typescript": "
|
|
17
|
+
"typescript": "~5.8"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=18"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"build:esm": "tsc -p tsconfig.esm.json && node esm/esm"
|
|
48
48
|
},
|
|
49
49
|
"types": "./esm/core-transformers.d.ts",
|
|
50
|
-
"version": "0.0.
|
|
50
|
+
"version": "0.0.6"
|
|
51
51
|
}
|