@azrico/webobject 1.4.156 → 1.4.158
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/dist/src/WebObjects/ParentWebObject.d.ts +14 -0
- package/dist/src/WebObjects/ParentWebObject.js +72 -0
- package/dist/src/WebObjects/WebObject.d.ts +0 -1
- package/dist/src/WebObjects/WebObject.js +1 -1
- package/dist/src/structs/MapableObject.d.ts +0 -1
- package/dist/src/structs/MapableObject.js +0 -1
- package/dist/src/structs/ObjectWithTemp.d.ts +1 -1
- package/dist/src/structs/ObjectWithTemp.js +1 -1
- package/dist/src/structs/SimpleObject.d.ts +1 -0
- package/dist/src/structs/SimpleObject.js +2 -0
- package/package.json +1 -1
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import WebObject from "./WebObject";
|
|
2
|
+
type mrow = {
|
|
3
|
+
__parent__table_id: any;
|
|
4
|
+
__table_id: any;
|
|
5
|
+
__children?: any[];
|
|
6
|
+
};
|
|
2
7
|
/**
|
|
3
8
|
* This web object contains some more webobjects
|
|
4
9
|
*/
|
|
@@ -6,5 +11,14 @@ export declare class ParentWebObject extends WebObject {
|
|
|
6
11
|
constructor(is_readonly?: boolean);
|
|
7
12
|
__children: WebObject[] | undefined;
|
|
8
13
|
set_children(val: WebObject[] | undefined): void;
|
|
14
|
+
private static getParentTableId;
|
|
15
|
+
private static getTableId;
|
|
16
|
+
static fixChildParentRelations<T extends mrow>(rows: T[]): T[];
|
|
17
|
+
/**
|
|
18
|
+
* assign children of row based on all_rows
|
|
19
|
+
* @param row
|
|
20
|
+
* @param all_rows
|
|
21
|
+
*/
|
|
22
|
+
private static assignChildren;
|
|
9
23
|
}
|
|
10
24
|
export default ParentWebObject;
|
|
@@ -44,6 +44,78 @@ var ParentWebObject = exports.ParentWebObject = /*#__PURE__*/function (_WebObjec
|
|
|
44
44
|
} else val = [];
|
|
45
45
|
this.__children = val;
|
|
46
46
|
}
|
|
47
|
+
}], [{
|
|
48
|
+
key: "getParentTableId",
|
|
49
|
+
value: function getParentTableId(obj) {
|
|
50
|
+
var _ref, _obj$__parent__table_;
|
|
51
|
+
return (_ref = (_obj$__parent__table_ = obj.__parent__table_id) !== null && _obj$__parent__table_ !== void 0 ? _obj$__parent__table_ : obj.parentid) !== null && _ref !== void 0 ? _ref : obj.parent;
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "getTableId",
|
|
55
|
+
value: function getTableId(obj) {
|
|
56
|
+
var _obj$__table_id;
|
|
57
|
+
return (_obj$__table_id = obj.__table_id) !== null && _obj$__table_id !== void 0 ? _obj$__table_id : obj._id;
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
60
|
+
key: "fixChildParentRelations",
|
|
61
|
+
value: function fixChildParentRelations(rows) {
|
|
62
|
+
var _this2 = this;
|
|
63
|
+
if (!Array.isArray(rows)) rows = [];
|
|
64
|
+
var anyparentid = rows.find(function (r) {
|
|
65
|
+
return _this2.getParentTableId(r);
|
|
66
|
+
});
|
|
67
|
+
var anyselfid = rows.find(function (r) {
|
|
68
|
+
return _this2.getTableId(r);
|
|
69
|
+
});
|
|
70
|
+
if (!anyparentid || !anyselfid) return rows;
|
|
71
|
+
var converted_rows = rows.filter(function (r) {
|
|
72
|
+
return r != null;
|
|
73
|
+
}).map(function (r) {
|
|
74
|
+
return {
|
|
75
|
+
parent: _this2.getParentTableId(r),
|
|
76
|
+
self: _this2.getTableId(r),
|
|
77
|
+
data: r
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
var top_level_rows = converted_rows.filter(function (r) {
|
|
81
|
+
return !r.parent;
|
|
82
|
+
});
|
|
83
|
+
var any_child = converted_rows.find(function (r) {
|
|
84
|
+
return Boolean(r.parent);
|
|
85
|
+
});
|
|
86
|
+
if (any_child) {
|
|
87
|
+
//find children of top-level parents:
|
|
88
|
+
for (var index = 0; index < top_level_rows.length; index++) {
|
|
89
|
+
var mrow = top_level_rows[index];
|
|
90
|
+
this.assignChildren(mrow, converted_rows);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return top_level_rows.map(function (r) {
|
|
94
|
+
return r.data;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* assign children of row based on all_rows
|
|
99
|
+
* @param row
|
|
100
|
+
* @param all_rows
|
|
101
|
+
*/
|
|
102
|
+
}, {
|
|
103
|
+
key: "assignChildren",
|
|
104
|
+
value: function assignChildren(row, all_rows) {
|
|
105
|
+
var my_children = all_rows.filter(function (s) {
|
|
106
|
+
return row.self == s.parent;
|
|
107
|
+
});
|
|
108
|
+
if (my_children.length > 0) {
|
|
109
|
+
//find children of my children:
|
|
110
|
+
for (var index = 0; index < my_children.length; index++) {
|
|
111
|
+
var child = my_children[index];
|
|
112
|
+
this.assignChildren(child, all_rows);
|
|
113
|
+
}
|
|
114
|
+
row.data.__children = my_children.map(function (r) {
|
|
115
|
+
return r.data;
|
|
116
|
+
});
|
|
117
|
+
} else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
|
|
118
|
+
}
|
|
47
119
|
}]);
|
|
48
120
|
return ParentWebObject;
|
|
49
121
|
}(_WebObject2["default"]);
|
|
@@ -43,7 +43,7 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
|
|
|
43
43
|
_classCallCheck(this, WebObject);
|
|
44
44
|
_this = _callSuper(this, WebObject, [is_readonly]);
|
|
45
45
|
_defineProperty(_assertThisInitialized(_this), "meta_data", void 0);
|
|
46
|
-
|
|
46
|
+
//created date
|
|
47
47
|
_defineProperty(_assertThisInitialized(_this), "_created_date", void 0);
|
|
48
48
|
//the owner of the object
|
|
49
49
|
_defineProperty(_assertThisInitialized(_this), "_creator", void 0);
|
|
@@ -5,7 +5,6 @@ declare type FirstInTuple<T extends any[]> = ((...args: T) => any) extends (arg:
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class MapableObject extends ObjectWithTemp {
|
|
7
7
|
readonly __uid: string;
|
|
8
|
-
__data_id?: string;
|
|
9
8
|
__table_id?: string;
|
|
10
9
|
__parent__table_id?: string;
|
|
11
10
|
__row_number?: number;
|
|
@@ -34,7 +34,6 @@ var MapableObject = exports.MapableObject = /*#__PURE__*/function (_ObjectWithTe
|
|
|
34
34
|
_classCallCheck(this, MapableObject);
|
|
35
35
|
_this = _callSuper(this, MapableObject);
|
|
36
36
|
_defineProperty(_assertThisInitialized(_this), "__uid", void 0);
|
|
37
|
-
_defineProperty(_assertThisInitialized(_this), "__data_id", void 0);
|
|
38
37
|
_defineProperty(_assertThisInitialized(_this), "__table_id", void 0);
|
|
39
38
|
_defineProperty(_assertThisInitialized(_this), "__parent__table_id", void 0);
|
|
40
39
|
_defineProperty(_assertThisInitialized(_this), "__row_number", void 0);
|
|
@@ -19,7 +19,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
19
19
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
20
|
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
21
21
|
/**
|
|
22
|
-
* This object
|
|
22
|
+
* This object supports temp values
|
|
23
23
|
*/
|
|
24
24
|
var _getTempProperty = /*#__PURE__*/new WeakSet();
|
|
25
25
|
var _setTempProperty = /*#__PURE__*/new WeakSet();
|
|
@@ -39,6 +39,7 @@ export declare class SimpleObject extends MapableObject {
|
|
|
39
39
|
protected __saveResultObject?: any;
|
|
40
40
|
protected __saveResultIsSuccess: boolean;
|
|
41
41
|
protected __saveResultType?: saveResultType;
|
|
42
|
+
_id: string;
|
|
42
43
|
_index_key: string;
|
|
43
44
|
_index_value: number;
|
|
44
45
|
constructor(is_readonly?: boolean);
|
|
@@ -86,6 +86,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
|
|
|
86
86
|
_defineProperty(_assertThisInitialized(_this), "__saveResultObject", void 0);
|
|
87
87
|
_defineProperty(_assertThisInitialized(_this), "__saveResultIsSuccess", true);
|
|
88
88
|
_defineProperty(_assertThisInitialized(_this), "__saveResultType", void 0);
|
|
89
|
+
_defineProperty(_assertThisInitialized(_this), "_id", "");
|
|
89
90
|
//sequence key (usually managed by the database)
|
|
90
91
|
_defineProperty(_assertThisInitialized(_this), "_index_key", "");
|
|
91
92
|
//sequence value , used to index the object with increasing numbers
|
|
@@ -118,6 +119,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
|
|
|
118
119
|
return undefined;
|
|
119
120
|
});
|
|
120
121
|
_this.__is_readonly = is_readonly;
|
|
122
|
+
if (_this._id) _this.__table_id = _this._id;
|
|
121
123
|
_this.clear_changes();
|
|
122
124
|
return _this;
|
|
123
125
|
}
|