@itrocks/core-transformers 0.1.4 → 0.2.0
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/collection-type.d.ts +6 -6
- package/cjs/collection-type.js +9 -9
- package/cjs/primitive.d.ts +4 -4
- package/cjs/primitive.js +3 -3
- package/cjs/store.d.ts +4 -4
- package/cjs/store.js +7 -6
- package/esm/collection-type.d.ts +6 -6
- package/esm/collection-type.js +7 -7
- package/esm/primitive.d.ts +4 -4
- package/esm/primitive.js +3 -3
- package/esm/store.d.ts +4 -4
- package/esm/store.js +7 -6
- package/package.json +1 -1
package/cjs/collection-type.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ObjectOrType } from '@itrocks/class-type';
|
|
2
|
+
import { Type } from '@itrocks/class-type';
|
|
3
3
|
export type Dependencies = {
|
|
4
|
-
displayOf: (object:
|
|
5
|
-
fieldNameOf: (property:
|
|
6
|
-
fieldIdOf: (property:
|
|
4
|
+
displayOf: <T extends object>(object: ObjectOrType<T>, property: keyof T) => string;
|
|
5
|
+
fieldNameOf: (property: keyof any) => string;
|
|
6
|
+
fieldIdOf: (property: keyof any) => string;
|
|
7
7
|
ignoreTransformedValue: any;
|
|
8
|
-
propertyOutput: <T extends object>(object: T, property:
|
|
8
|
+
propertyOutput: <T extends object>(object: T, property: keyof T) => Promise<string>;
|
|
9
9
|
representativeValueOf: (object: object) => Promise<string>;
|
|
10
10
|
routeOf: (type: Type) => string;
|
|
11
11
|
tr: (text: string) => string;
|
package/cjs/collection-type.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initCollectionHtmlTransformers = initCollectionHtmlTransformers;
|
|
4
4
|
exports.initCollectionTransformers = initCollectionTransformers;
|
|
5
5
|
const composition_1 = require("@itrocks/composition");
|
|
6
|
+
const composition_2 = require("@itrocks/composition");
|
|
6
7
|
const storage_1 = require("@itrocks/storage");
|
|
7
8
|
const class_type_1 = require("@itrocks/class-type");
|
|
8
9
|
const class_type_2 = require("@itrocks/class-type");
|
|
@@ -12,11 +13,10 @@ const reflect_1 = require("@itrocks/reflect");
|
|
|
12
13
|
const reflect_2 = require("@itrocks/reflect");
|
|
13
14
|
const transformer_1 = require("@itrocks/transformer");
|
|
14
15
|
const transformer_2 = require("@itrocks/transformer");
|
|
15
|
-
const transformer_3 = require("@itrocks/transformer");
|
|
16
16
|
const depends = {
|
|
17
|
-
displayOf: (_object, property) => property,
|
|
18
|
-
fieldNameOf: property => property,
|
|
19
|
-
fieldIdOf: property => property,
|
|
17
|
+
displayOf: (_object, property) => property.toString(),
|
|
18
|
+
fieldNameOf: property => property.toString(),
|
|
19
|
+
fieldIdOf: property => property.toString(),
|
|
20
20
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
21
21
|
propertyOutput: async (object, property) => '' + await object[property],
|
|
22
22
|
representativeValueOf: async (object) => (0, class_type_1.baseType)((0, class_type_2.typeOf)(object)).name,
|
|
@@ -55,7 +55,7 @@ function collectionInput(values, object, property, data) {
|
|
|
55
55
|
delete object[property];
|
|
56
56
|
const data_property_id = data[(0, rename_1.toField)(property) + '_id'];
|
|
57
57
|
Object.assign(object, {
|
|
58
|
-
[property + 'Ids']: Object.keys(values).map(key => +data_property_id[key]).filter(value => value)
|
|
58
|
+
[property.toString() + 'Ids']: Object.keys(values).map(key => +data_property_id[key]).filter(value => value)
|
|
59
59
|
});
|
|
60
60
|
return depends.ignoreTransformedValue;
|
|
61
61
|
}
|
|
@@ -67,7 +67,7 @@ async function collectionOutput(values, object, property, askFor) {
|
|
|
67
67
|
const propertyType = new reflect_2.ReflectProperty(object, property).collectionType;
|
|
68
68
|
const type = propertyType.elementType.type;
|
|
69
69
|
const propertyClass = new reflect_1.ReflectClass(type);
|
|
70
|
-
const properties = propertyClass.propertyNames.filter(property => !(0,
|
|
70
|
+
const properties = propertyClass.propertyNames.filter(property => !(0, composition_2.compositeOf)(type, property));
|
|
71
71
|
const html = [];
|
|
72
72
|
html.push('<table>');
|
|
73
73
|
html.push('<tr>'
|
|
@@ -95,9 +95,9 @@ async function collectionOutput(values, object, property, askFor) {
|
|
|
95
95
|
}
|
|
96
96
|
function initCollectionHtmlTransformers(dependencies = {}) {
|
|
97
97
|
Object.assign(depends, dependencies);
|
|
98
|
-
(0,
|
|
99
|
-
(0,
|
|
100
|
-
(0,
|
|
98
|
+
(0, transformer_2.setPropertyTypeTransformer)(property_type_1.CollectionType, transformer_1.HTML, transformer_1.EDIT, collectionEdit);
|
|
99
|
+
(0, transformer_2.setPropertyTypeTransformer)(property_type_1.CollectionType, transformer_1.HTML, transformer_1.INPUT, collectionInput);
|
|
100
|
+
(0, transformer_2.setPropertyTypeTransformer)(property_type_1.CollectionType, transformer_1.HTML, transformer_1.OUTPUT, collectionOutput);
|
|
101
101
|
}
|
|
102
102
|
function initCollectionTransformers(dependencies = {}) {
|
|
103
103
|
initCollectionHtmlTransformers(dependencies);
|
package/cjs/primitive.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectOrType } from '@itrocks/class-type';
|
|
2
2
|
export type CoreDependencies = {
|
|
3
|
-
displayOf: (object:
|
|
4
|
-
fieldIdOf: (property:
|
|
5
|
-
fieldNameOf: (property:
|
|
3
|
+
displayOf: <T extends object>(object: ObjectOrType<T>, property: keyof T) => string;
|
|
4
|
+
fieldIdOf: (property: keyof any) => string;
|
|
5
|
+
fieldNameOf: (property: keyof any) => string;
|
|
6
6
|
tr: (text: string) => string;
|
|
7
7
|
};
|
|
8
8
|
export type Dependencies = CoreDependencies & {
|
package/cjs/primitive.js
CHANGED
|
@@ -15,10 +15,10 @@ const transformer_2 = require("@itrocks/transformer");
|
|
|
15
15
|
const transformer_3 = require("@itrocks/transformer");
|
|
16
16
|
const lfTab = '\n\t\t\t\t';
|
|
17
17
|
const depends = {
|
|
18
|
-
displayOf: (_object, property) => property,
|
|
18
|
+
displayOf: (_object, property) => property.toString(),
|
|
19
19
|
formatDate: date => date.toString(),
|
|
20
|
-
fieldIdOf: property => property,
|
|
21
|
-
fieldNameOf: property => property,
|
|
20
|
+
fieldIdOf: property => property.toString(),
|
|
21
|
+
fieldNameOf: property => property.toString(),
|
|
22
22
|
parseDate: date => new Date(date),
|
|
23
23
|
tr: text => text
|
|
24
24
|
};
|
package/cjs/store.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectOrType } from '@itrocks/class-type';
|
|
2
2
|
import { Type } from '@itrocks/class-type';
|
|
3
3
|
export type SqlDependencies = {
|
|
4
4
|
ignoreTransformedValue: any;
|
|
5
5
|
};
|
|
6
6
|
export type Dependencies = SqlDependencies & {
|
|
7
|
-
displayOf: (object:
|
|
8
|
-
fieldIdOf: (property:
|
|
9
|
-
fieldNameOf: (property:
|
|
7
|
+
displayOf: <T extends object>(object: ObjectOrType<T>, property: keyof T) => string;
|
|
8
|
+
fieldIdOf: (property: keyof any) => string;
|
|
9
|
+
fieldNameOf: (property: keyof any) => string;
|
|
10
10
|
representativeValueOf: (object: object) => Promise<string>;
|
|
11
11
|
routeOf: (type: Type) => string;
|
|
12
12
|
tr: (text: string) => string;
|
package/cjs/store.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.initStoreSqlTransformers = initStoreSqlTransformers;
|
|
|
6
6
|
exports.initStoreTransformers = initStoreTransformers;
|
|
7
7
|
exports.setStoreDependencies = setStoreDependencies;
|
|
8
8
|
const class_type_1 = require("@itrocks/class-type");
|
|
9
|
+
const class_type_2 = require("@itrocks/class-type");
|
|
9
10
|
const reflect_1 = require("@itrocks/reflect");
|
|
10
11
|
const storage_1 = require("@itrocks/storage");
|
|
11
12
|
const transformer_1 = require("@itrocks/transformer");
|
|
@@ -13,11 +14,11 @@ const transformer_2 = require("@itrocks/transformer");
|
|
|
13
14
|
const transformer_3 = require("@itrocks/transformer");
|
|
14
15
|
const lfTab = '\n\t\t\t\t';
|
|
15
16
|
const depends = {
|
|
16
|
-
displayOf: (_object, property) => property,
|
|
17
|
-
fieldIdOf: property => property,
|
|
18
|
-
fieldNameOf: property => property,
|
|
17
|
+
displayOf: (_object, property) => property.toString(),
|
|
18
|
+
fieldIdOf: property => property.toString(),
|
|
19
|
+
fieldNameOf: property => property.toString(),
|
|
19
20
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
20
|
-
representativeValueOf: async (object) => (0, class_type_1.baseType)((0,
|
|
21
|
+
representativeValueOf: async (object) => (0, class_type_1.baseType)((0, class_type_2.typeOf)(object)).name,
|
|
21
22
|
routeOf: type => '/' + (0, class_type_1.baseType)(type).name,
|
|
22
23
|
tr: text => text
|
|
23
24
|
};
|
|
@@ -52,7 +53,7 @@ async function storeEdit(value, object, property) {
|
|
|
52
53
|
return label + lfTab + inputId + input;
|
|
53
54
|
}
|
|
54
55
|
function storeInput(value, object, property, data) {
|
|
55
|
-
const propertyId = property + 'Id';
|
|
56
|
+
const propertyId = (property.toString() + 'Id');
|
|
56
57
|
const fieldId = depends.fieldNameOf(propertyId);
|
|
57
58
|
const id = +data[fieldId];
|
|
58
59
|
if (id === ((propertyId in object) ? object[propertyId] : value?.id)) {
|
|
@@ -79,7 +80,7 @@ async function storeSave(value, _object, property, record) {
|
|
|
79
80
|
if (value && !dao.isObjectConnected(value)) {
|
|
80
81
|
await dao.save(value);
|
|
81
82
|
}
|
|
82
|
-
const columnId = property + '_id';
|
|
83
|
+
const columnId = property.toString() + '_id';
|
|
83
84
|
const id = (value && dao.isObjectConnected(value)) ? value.id : record[columnId];
|
|
84
85
|
record[columnId] = id ?? null;
|
|
85
86
|
return depends.ignoreTransformedValue;
|
package/esm/collection-type.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ObjectOrType } from '@itrocks/class-type';
|
|
2
|
+
import { Type } from '@itrocks/class-type';
|
|
3
3
|
export type Dependencies = {
|
|
4
|
-
displayOf: (object:
|
|
5
|
-
fieldNameOf: (property:
|
|
6
|
-
fieldIdOf: (property:
|
|
4
|
+
displayOf: <T extends object>(object: ObjectOrType<T>, property: keyof T) => string;
|
|
5
|
+
fieldNameOf: (property: keyof any) => string;
|
|
6
|
+
fieldIdOf: (property: keyof any) => string;
|
|
7
7
|
ignoreTransformedValue: any;
|
|
8
|
-
propertyOutput: <T extends object>(object: T, property:
|
|
8
|
+
propertyOutput: <T extends object>(object: T, property: keyof T) => Promise<string>;
|
|
9
9
|
representativeValueOf: (object: object) => Promise<string>;
|
|
10
10
|
routeOf: (type: Type) => string;
|
|
11
11
|
tr: (text: string) => string;
|
package/esm/collection-type.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { componentOf
|
|
1
|
+
import { componentOf } from '@itrocks/composition';
|
|
2
|
+
import { compositeOf } from '@itrocks/composition';
|
|
2
3
|
import { dataSource } from '@itrocks/storage';
|
|
3
4
|
import { baseType } from '@itrocks/class-type';
|
|
4
5
|
import { typeOf } from '@itrocks/class-type';
|
|
@@ -6,13 +7,12 @@ import { CollectionType } from '@itrocks/property-type';
|
|
|
6
7
|
import { toField } from '@itrocks/rename';
|
|
7
8
|
import { ReflectClass } from '@itrocks/reflect';
|
|
8
9
|
import { ReflectProperty } from '@itrocks/reflect';
|
|
9
|
-
import { EDIT, HTML } from '@itrocks/transformer';
|
|
10
|
-
import { INPUT, OUTPUT } from '@itrocks/transformer';
|
|
10
|
+
import { EDIT, HTML, INPUT, OUTPUT } from '@itrocks/transformer';
|
|
11
11
|
import { setPropertyTypeTransformer } from '@itrocks/transformer';
|
|
12
12
|
const depends = {
|
|
13
|
-
displayOf: (_object, property) => property,
|
|
14
|
-
fieldNameOf: property => property,
|
|
15
|
-
fieldIdOf: property => property,
|
|
13
|
+
displayOf: (_object, property) => property.toString(),
|
|
14
|
+
fieldNameOf: property => property.toString(),
|
|
15
|
+
fieldIdOf: property => property.toString(),
|
|
16
16
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
17
17
|
propertyOutput: async (object, property) => '' + await object[property],
|
|
18
18
|
representativeValueOf: async (object) => baseType(typeOf(object)).name,
|
|
@@ -51,7 +51,7 @@ function collectionInput(values, object, property, data) {
|
|
|
51
51
|
delete object[property];
|
|
52
52
|
const data_property_id = data[toField(property) + '_id'];
|
|
53
53
|
Object.assign(object, {
|
|
54
|
-
[property + 'Ids']: Object.keys(values).map(key => +data_property_id[key]).filter(value => value)
|
|
54
|
+
[property.toString() + 'Ids']: Object.keys(values).map(key => +data_property_id[key]).filter(value => value)
|
|
55
55
|
});
|
|
56
56
|
return depends.ignoreTransformedValue;
|
|
57
57
|
}
|
package/esm/primitive.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectOrType } from '@itrocks/class-type';
|
|
2
2
|
export type CoreDependencies = {
|
|
3
|
-
displayOf: (object:
|
|
4
|
-
fieldIdOf: (property:
|
|
5
|
-
fieldNameOf: (property:
|
|
3
|
+
displayOf: <T extends object>(object: ObjectOrType<T>, property: keyof T) => string;
|
|
4
|
+
fieldIdOf: (property: keyof any) => string;
|
|
5
|
+
fieldNameOf: (property: keyof any) => string;
|
|
6
6
|
tr: (text: string) => string;
|
|
7
7
|
};
|
|
8
8
|
export type Dependencies = CoreDependencies & {
|
package/esm/primitive.js
CHANGED
|
@@ -4,10 +4,10 @@ import { EDIT, HTML, INPUT, OUTPUT } from '@itrocks/transformer';
|
|
|
4
4
|
import { READ, SAVE, SQL } from '@itrocks/transformer';
|
|
5
5
|
const lfTab = '\n\t\t\t\t';
|
|
6
6
|
const depends = {
|
|
7
|
-
displayOf: (_object, property) => property,
|
|
7
|
+
displayOf: (_object, property) => property.toString(),
|
|
8
8
|
formatDate: date => date.toString(),
|
|
9
|
-
fieldIdOf: property => property,
|
|
10
|
-
fieldNameOf: property => property,
|
|
9
|
+
fieldIdOf: property => property.toString(),
|
|
10
|
+
fieldNameOf: property => property.toString(),
|
|
11
11
|
parseDate: date => new Date(date),
|
|
12
12
|
tr: text => text
|
|
13
13
|
};
|
package/esm/store.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectOrType } from '@itrocks/class-type';
|
|
2
2
|
import { Type } from '@itrocks/class-type';
|
|
3
3
|
export type SqlDependencies = {
|
|
4
4
|
ignoreTransformedValue: any;
|
|
5
5
|
};
|
|
6
6
|
export type Dependencies = SqlDependencies & {
|
|
7
|
-
displayOf: (object:
|
|
8
|
-
fieldIdOf: (property:
|
|
9
|
-
fieldNameOf: (property:
|
|
7
|
+
displayOf: <T extends object>(object: ObjectOrType<T>, property: keyof T) => string;
|
|
8
|
+
fieldIdOf: (property: keyof any) => string;
|
|
9
|
+
fieldNameOf: (property: keyof any) => string;
|
|
10
10
|
representativeValueOf: (object: object) => Promise<string>;
|
|
11
11
|
routeOf: (type: Type) => string;
|
|
12
12
|
tr: (text: string) => string;
|
package/esm/store.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { baseType
|
|
1
|
+
import { baseType } from '@itrocks/class-type';
|
|
2
|
+
import { typeOf } from '@itrocks/class-type';
|
|
2
3
|
import { ReflectProperty } from '@itrocks/reflect';
|
|
3
4
|
import { dataSource } from '@itrocks/storage';
|
|
4
5
|
import { setPropertyTypeTransformer } from '@itrocks/transformer';
|
|
@@ -6,9 +7,9 @@ import { EDIT, HTML } from '@itrocks/transformer';
|
|
|
6
7
|
import { INPUT, OUTPUT, SAVE, SQL } from '@itrocks/transformer';
|
|
7
8
|
const lfTab = '\n\t\t\t\t';
|
|
8
9
|
const depends = {
|
|
9
|
-
displayOf: (_object, property) => property,
|
|
10
|
-
fieldIdOf: property => property,
|
|
11
|
-
fieldNameOf: property => property,
|
|
10
|
+
displayOf: (_object, property) => property.toString(),
|
|
11
|
+
fieldIdOf: property => property.toString(),
|
|
12
|
+
fieldNameOf: property => property.toString(),
|
|
12
13
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
13
14
|
representativeValueOf: async (object) => baseType(typeOf(object)).name,
|
|
14
15
|
routeOf: type => '/' + baseType(type).name,
|
|
@@ -45,7 +46,7 @@ async function storeEdit(value, object, property) {
|
|
|
45
46
|
return label + lfTab + inputId + input;
|
|
46
47
|
}
|
|
47
48
|
function storeInput(value, object, property, data) {
|
|
48
|
-
const propertyId = property + 'Id';
|
|
49
|
+
const propertyId = (property.toString() + 'Id');
|
|
49
50
|
const fieldId = depends.fieldNameOf(propertyId);
|
|
50
51
|
const id = +data[fieldId];
|
|
51
52
|
if (id === ((propertyId in object) ? object[propertyId] : value?.id)) {
|
|
@@ -72,7 +73,7 @@ async function storeSave(value, _object, property, record) {
|
|
|
72
73
|
if (value && !dao.isObjectConnected(value)) {
|
|
73
74
|
await dao.save(value);
|
|
74
75
|
}
|
|
75
|
-
const columnId = property + '_id';
|
|
76
|
+
const columnId = property.toString() + '_id';
|
|
76
77
|
const id = (value && dao.isObjectConnected(value)) ? value.id : record[columnId];
|
|
77
78
|
record[columnId] = id ?? null;
|
|
78
79
|
return depends.ignoreTransformedValue;
|
package/package.json
CHANGED