@azrico/webobject 1.5.58 → 1.5.61
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/README.md +9 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/src/WebObjects/ParentWebObject.d.ts +24 -0
- package/dist/src/WebObjects/ParentWebObject.js +77 -0
- package/dist/src/WebObjects/WebObject.d.ts +153 -0
- package/dist/src/WebObjects/WebObject.js +654 -0
- package/dist/src/WebObjects/WebObjectHelper.d.ts +9 -0
- package/dist/src/WebObjects/WebObjectHelper.js +18 -0
- package/dist/src/WebObjects/WebObjectHelper.test.d.ts +1 -0
- package/dist/src/WebObjects/WebObjectHelper.test.js +45 -0
- package/dist/src/WebObjects/WebObjectManager.d.ts +68 -0
- package/dist/src/WebObjects/WebObjectManager.js +290 -0
- package/dist/src/WebObjects/WebObjectPathHelper.d.ts +36 -0
- package/dist/src/WebObjects/WebObjectPathHelper.js +84 -0
- package/dist/src/WebObjects/WebObjectPathHelper.test.d.ts +1 -0
- package/dist/src/WebObjects/WebObjectPathHelper.test.js +31 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +10 -0
- package/dist/src/structs/DummyObject.d.ts +5 -0
- package/dist/src/structs/DummyObject.js +8 -0
- package/dist/src/structs/MapableObject.d.ts +43 -0
- package/dist/src/structs/MapableObject.js +77 -0
- package/dist/src/structs/MetaObject.d.ts +15 -0
- package/dist/src/structs/MetaObject.js +35 -0
- package/dist/src/structs/ObjectArray.d.ts +10 -0
- package/dist/src/structs/ObjectArray.js +43 -0
- package/dist/src/structs/ObjectManager.d.ts +136 -0
- package/dist/src/structs/ObjectManager.js +332 -0
- package/dist/src/structs/ObjectWithTemp.d.ts +16 -0
- package/dist/src/structs/ObjectWithTemp.js +35 -0
- package/dist/src/structs/SimpleObject.js +1138 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# deus-object
|
|
2
|
-
|
|
3
|
-
> Some useful object functions
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
yarn add @azrico/webobject
|
|
9
|
-
```
|
|
1
|
+
# deus-object
|
|
2
|
+
|
|
3
|
+
> Some useful object functions
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @azrico/webobject
|
|
9
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import WebObject from "./WebObject";
|
|
2
|
+
type mrow = {
|
|
3
|
+
__parent__table_id: any;
|
|
4
|
+
__table_id: any;
|
|
5
|
+
__children?: any[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* This web object contains some more webobjects
|
|
9
|
+
*/
|
|
10
|
+
export declare class ParentWebObject extends WebObject {
|
|
11
|
+
constructor(is_readonly?: boolean);
|
|
12
|
+
__children: WebObject[] | undefined;
|
|
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;
|
|
23
|
+
}
|
|
24
|
+
export default ParentWebObject;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import WebObject from "./WebObject";
|
|
2
|
+
/**
|
|
3
|
+
* This web object contains some more webobjects
|
|
4
|
+
*/
|
|
5
|
+
export class ParentWebObject extends WebObject {
|
|
6
|
+
constructor(is_readonly = false) {
|
|
7
|
+
super(is_readonly);
|
|
8
|
+
}
|
|
9
|
+
__children = undefined;
|
|
10
|
+
set_children(val) {
|
|
11
|
+
if (Array.isArray(val)) {
|
|
12
|
+
const selftableid = this.__table_id;
|
|
13
|
+
val.forEach((v) => {
|
|
14
|
+
v.__parent__table_id = selftableid;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else
|
|
18
|
+
val = [];
|
|
19
|
+
this.__children = val;
|
|
20
|
+
}
|
|
21
|
+
static getParentTableId(obj) {
|
|
22
|
+
return (obj.__parent__table_id ??
|
|
23
|
+
obj.parent_id ??
|
|
24
|
+
obj.parent ??
|
|
25
|
+
obj.parentid);
|
|
26
|
+
}
|
|
27
|
+
static getTableId(obj) {
|
|
28
|
+
return obj.__table_id ?? obj._id;
|
|
29
|
+
}
|
|
30
|
+
static fixChildParentRelations(rows) {
|
|
31
|
+
if (!Array.isArray(rows))
|
|
32
|
+
rows = [];
|
|
33
|
+
const anyparentid = rows.find((r) => this.getParentTableId(r));
|
|
34
|
+
const anyselfid = rows.find((r) => this.getTableId(r));
|
|
35
|
+
if (!anyparentid || !anyselfid)
|
|
36
|
+
return rows;
|
|
37
|
+
const converted_rows = rows
|
|
38
|
+
.filter((r) => r != null)
|
|
39
|
+
.map((r) => {
|
|
40
|
+
return {
|
|
41
|
+
parent: this.getParentTableId(r),
|
|
42
|
+
self: this.getTableId(r),
|
|
43
|
+
data: r,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const top_level_rows = converted_rows.filter((r) => !r.parent);
|
|
47
|
+
const any_child = converted_rows.find((r) => Boolean(r.parent));
|
|
48
|
+
if (any_child) {
|
|
49
|
+
//find children of top-level parents:
|
|
50
|
+
for (let index = 0; index < top_level_rows.length; index++) {
|
|
51
|
+
const mrow = top_level_rows[index];
|
|
52
|
+
this.assignChildren(mrow, converted_rows);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return top_level_rows.map((r) => r.data);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* assign children of row based on all_rows
|
|
59
|
+
* @param row
|
|
60
|
+
* @param all_rows
|
|
61
|
+
*/
|
|
62
|
+
static assignChildren(row, all_rows) {
|
|
63
|
+
const my_children = all_rows.filter((s) => row.self == s.parent);
|
|
64
|
+
if (my_children.length > 0) {
|
|
65
|
+
//find children of my children:
|
|
66
|
+
for (let index = 0; index < my_children.length; index++) {
|
|
67
|
+
const child = my_children[index];
|
|
68
|
+
this.assignChildren(child, all_rows);
|
|
69
|
+
}
|
|
70
|
+
row.data.__children = my_children.map((r) => r.data);
|
|
71
|
+
}
|
|
72
|
+
else if (!Array.isArray(row.data.__children) ||
|
|
73
|
+
row.data.__children.length == 0)
|
|
74
|
+
row.data.__children = undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export default ParentWebObject;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { SimpleObject, deltaParams, sendChangesType } from "../index";
|
|
2
|
+
import { WebObjectManager } from "../index";
|
|
3
|
+
export type ObjectWithUsers = Partial<{
|
|
4
|
+
_creator: string;
|
|
5
|
+
_users: string[];
|
|
6
|
+
attentions: string[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare class WebObject extends SimpleObject {
|
|
9
|
+
static readonly __web_path: string;
|
|
10
|
+
static readonly __protectedProperties: string[];
|
|
11
|
+
static readonly __requiredProperties: never[];
|
|
12
|
+
meta_data: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
_created_date?: string | Date;
|
|
16
|
+
_creator?: string;
|
|
17
|
+
_users?: string[];
|
|
18
|
+
constructor(is_readonly?: boolean);
|
|
19
|
+
/**
|
|
20
|
+
* get a list of all user ids that work on the given object
|
|
21
|
+
* _creator + _users + attentions(old)
|
|
22
|
+
* removes duplicates
|
|
23
|
+
* @returns array of ids
|
|
24
|
+
*/
|
|
25
|
+
getAllUsers(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* get a unique list of all user ids that work on the given object
|
|
28
|
+
* `_creator + _users + attentions`
|
|
29
|
+
* @returns array of ids
|
|
30
|
+
*/
|
|
31
|
+
static getAllUsers(obj: ObjectWithUsers): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Update meta value of this object , meta data is stored in meta_data variable
|
|
34
|
+
* @param key
|
|
35
|
+
* @param value
|
|
36
|
+
* @param sendChange
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
setMetaValue(key: string, value: any, sendChange?: sendChangesType): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Get meta value by key
|
|
42
|
+
* @param key
|
|
43
|
+
* @returns value or undefined
|
|
44
|
+
*/
|
|
45
|
+
getMetaValue(key: string): any;
|
|
46
|
+
/**
|
|
47
|
+
* Get meta value by key
|
|
48
|
+
* @param o
|
|
49
|
+
* @param key
|
|
50
|
+
* @returns value or undefined
|
|
51
|
+
*/
|
|
52
|
+
static getMetaValue(o: WebObject | null | undefined, key: string): any | undefined;
|
|
53
|
+
static zipSaveList(svlist: any): string;
|
|
54
|
+
static unzipSaveList(svlist: any): any[];
|
|
55
|
+
static saveList(itemList: WebObject[], extraOptions?: {
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}): Promise<boolean>;
|
|
58
|
+
Save(): Promise<any>;
|
|
59
|
+
Delete(): Promise<any>;
|
|
60
|
+
Lock(): Promise<any>;
|
|
61
|
+
UnLock(): Promise<any>;
|
|
62
|
+
Archive(): Promise<any>;
|
|
63
|
+
UnArchive(): Promise<any>;
|
|
64
|
+
canSave(deltaObj?: any): true | string;
|
|
65
|
+
canDelete(): boolean;
|
|
66
|
+
canArchive(): boolean;
|
|
67
|
+
deltaIsValid(d: any): true | string;
|
|
68
|
+
/**
|
|
69
|
+
* converts this object to an basic object
|
|
70
|
+
* that can be passed into client components from server components
|
|
71
|
+
*
|
|
72
|
+
* uses `get_fullDeltaObject`
|
|
73
|
+
* @param p
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
get_basicObject(): Promise<Partial<this>>;
|
|
77
|
+
/**
|
|
78
|
+
* calls the `get_deltaObject` with
|
|
79
|
+
* `allProperties` `extraProperties`
|
|
80
|
+
* set to true
|
|
81
|
+
*
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
get_fullDeltaObject(p?: deltaParams): Promise<any>;
|
|
85
|
+
/**
|
|
86
|
+
* calls the `get_deltaObject` with
|
|
87
|
+
* `allProperties` `extraProperties` `tempProperties`
|
|
88
|
+
* set to true
|
|
89
|
+
*
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
get_fullObject(p?: deltaParams): Promise<any>;
|
|
93
|
+
/**
|
|
94
|
+
* You will post this to the server for saving
|
|
95
|
+
* automatically removes unchangeable fields
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
get_deltaObject(p?: deltaParams): Promise<any>;
|
|
99
|
+
get manager(): WebObjectManager<any> | undefined;
|
|
100
|
+
get __web_path(): string;
|
|
101
|
+
get_webpath(): string;
|
|
102
|
+
static get_webpath(): string;
|
|
103
|
+
static get_dbname(): string;
|
|
104
|
+
onDelete(...p: any): Promise<any>;
|
|
105
|
+
onArchive(...p: any): Promise<any>;
|
|
106
|
+
onUnArchive(...p: any): Promise<any>;
|
|
107
|
+
onLock(...p: any): Promise<any>;
|
|
108
|
+
onUnLock(...p: any): Promise<any>;
|
|
109
|
+
onLoad(...p: any): Promise<any>;
|
|
110
|
+
onSave(...p: any): Promise<any>;
|
|
111
|
+
onAfterSave(...p: any): Promise<any>;
|
|
112
|
+
getSaveResult(original?: boolean): any;
|
|
113
|
+
onNew(...p: any): Promise<any>;
|
|
114
|
+
saveResultHasID(s: any): any;
|
|
115
|
+
static saveResultHasID(s: any): any;
|
|
116
|
+
/**
|
|
117
|
+
* Load Id and _index_value from the given save result into our object
|
|
118
|
+
* @param o
|
|
119
|
+
* @param srObject
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
static LoadIdsFromSaveResult(o: WebObject, srObject: any): void;
|
|
123
|
+
/**
|
|
124
|
+
* get a single web object
|
|
125
|
+
* default order of parameters : search,readonly,fetchID
|
|
126
|
+
*/
|
|
127
|
+
static get_single(...p: any[]): Promise<WebObject | any | undefined>;
|
|
128
|
+
/**
|
|
129
|
+
* Get a list of web objects
|
|
130
|
+
* default order of parameters : search,readonly,fetchID
|
|
131
|
+
*/
|
|
132
|
+
static get_list(...p: any[]): Promise<Array<WebObject | any>>;
|
|
133
|
+
/**
|
|
134
|
+
* uses `get_list` and then saves the result to `gcache`
|
|
135
|
+
* then uses the `equals` function to return matched results
|
|
136
|
+
* @param search
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
139
|
+
static get_list_cache(search?: any): Promise<Array<WebObject>>;
|
|
140
|
+
/**
|
|
141
|
+
* uses `get_list_cache` then the `equals` function to return matched result
|
|
142
|
+
* @param search
|
|
143
|
+
* @returns
|
|
144
|
+
*/
|
|
145
|
+
static get_single_cache(search: any): Promise<WebObject | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* Get a list of web objects and convert them to basic objects
|
|
148
|
+
* can be passed to client components
|
|
149
|
+
* default order of parameters : search,readonly,fetchID
|
|
150
|
+
*/
|
|
151
|
+
static get_basicList(...p: any[]): Promise<any[]>;
|
|
152
|
+
}
|
|
153
|
+
export default WebObject;
|