@webtypen/webframez-core 0.2.29 → 0.2.30
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.
|
@@ -13,6 +13,7 @@ export type DataBuilderSchema = {
|
|
|
13
13
|
fields: {
|
|
14
14
|
[key: string]: any;
|
|
15
15
|
};
|
|
16
|
+
newDataHandler?: Function;
|
|
16
17
|
};
|
|
17
18
|
export type DataBuilderType = {
|
|
18
19
|
key: string;
|
|
@@ -37,7 +38,6 @@ export type DataBuilderFieldType = {
|
|
|
37
38
|
export declare class DataBuilder {
|
|
38
39
|
private types;
|
|
39
40
|
private fieldTypes;
|
|
40
|
-
newDataHandler: null | ((req: Request) => Promise<any>);
|
|
41
41
|
getType(key: string): DataBuilderType | null;
|
|
42
42
|
registerType(typeObj: DataBuilderType): this;
|
|
43
43
|
registerFieldType(key: string, options?: any): this;
|
|
@@ -84,7 +84,7 @@ export declare class DataBuilder {
|
|
|
84
84
|
status: string;
|
|
85
85
|
data: any;
|
|
86
86
|
message?: undefined;
|
|
87
|
-
}
|
|
87
|
+
}>;
|
|
88
88
|
apiAutoComplete(req: any): Promise<{
|
|
89
89
|
status: string;
|
|
90
90
|
data: void;
|
|
@@ -19,7 +19,6 @@ class DataBuilder {
|
|
|
19
19
|
constructor() {
|
|
20
20
|
this.types = {};
|
|
21
21
|
this.fieldTypes = {};
|
|
22
|
-
this.newDataHandler = null;
|
|
23
22
|
}
|
|
24
23
|
getType(key) {
|
|
25
24
|
return this.types[key] && this.types[key].key ? this.types[key] : null;
|
|
@@ -178,7 +177,7 @@ class DataBuilder {
|
|
|
178
177
|
loadType(req) {
|
|
179
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
179
|
const type = this.getTypeFromRequest(req);
|
|
181
|
-
const data = Object.assign(Object.assign({}, (yield this.typeForFrontend(type, req))), { fieldtypes: this.getFieldTypesFrontend(), new_data_handler:
|
|
180
|
+
const data = Object.assign(Object.assign({}, (yield this.typeForFrontend(type, req))), { fieldtypes: this.getFieldTypesFrontend(), new_data_handler: type.schema && type.schema.newDataHandler && typeof type.schema.newDataHandler === "function" ? true : false });
|
|
182
181
|
return {
|
|
183
182
|
status: "success",
|
|
184
183
|
data: Object.assign(Object.assign({}, data), { schema: Object.assign(Object.assign({}, (data.schema ? data.schema : {})), { fields: yield this.getFieldsFrontend(type.schema
|
|
@@ -428,16 +427,16 @@ class DataBuilder {
|
|
|
428
427
|
}
|
|
429
428
|
detailsNewData(db, req) {
|
|
430
429
|
return __awaiter(this, void 0, void 0, function* () {
|
|
431
|
-
if (!this.newDataHandler) {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
430
|
const type = this.getTypeFromRequest(req);
|
|
435
431
|
if (!type || !type.schema || !type.schema.fields) {
|
|
436
432
|
throw new Error("Missing schema fields ...");
|
|
437
433
|
}
|
|
434
|
+
if (!type.schema || !type.schema.newDataHandler || typeof type.schema.newDataHandler !== "function") {
|
|
435
|
+
throw new Error("Missing newDataHandler-Function ...");
|
|
436
|
+
}
|
|
438
437
|
let data = null;
|
|
439
438
|
try {
|
|
440
|
-
data = yield
|
|
439
|
+
data = yield type.schema.newDataHandler(req);
|
|
441
440
|
}
|
|
442
441
|
catch (e) {
|
|
443
442
|
console.error(e);
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ export type DataBuilderSchema = {
|
|
|
12
12
|
getAggregation?: any;
|
|
13
13
|
events?: { [key: string]: any };
|
|
14
14
|
fields: { [key: string]: any };
|
|
15
|
+
newDataHandler?: Function;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export type DataBuilderType = {
|
|
@@ -40,8 +41,6 @@ export class DataBuilder {
|
|
|
40
41
|
private types: { [key: string]: DataBuilderType } = {};
|
|
41
42
|
private fieldTypes: { [key: string]: DataBuilderFieldType } = {};
|
|
42
43
|
|
|
43
|
-
newDataHandler: null | ((req: Request) => Promise<any>) = null;
|
|
44
|
-
|
|
45
44
|
getType(key: string) {
|
|
46
45
|
return this.types[key] && this.types[key].key ? this.types[key] : null;
|
|
47
46
|
}
|
|
@@ -225,7 +224,7 @@ export class DataBuilder {
|
|
|
225
224
|
const data = {
|
|
226
225
|
...(await this.typeForFrontend(type, req)),
|
|
227
226
|
fieldtypes: this.getFieldTypesFrontend(),
|
|
228
|
-
new_data_handler:
|
|
227
|
+
new_data_handler: type.schema && type.schema.newDataHandler && typeof type.schema.newDataHandler === "function" ? true : false,
|
|
229
228
|
};
|
|
230
229
|
return {
|
|
231
230
|
status: "success",
|
|
@@ -517,18 +516,18 @@ export class DataBuilder {
|
|
|
517
516
|
}
|
|
518
517
|
|
|
519
518
|
async detailsNewData(db: any, req: any) {
|
|
520
|
-
if (!this.newDataHandler) {
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
519
|
const type = this.getTypeFromRequest(req);
|
|
525
520
|
if (!type || !type.schema || !type.schema.fields) {
|
|
526
521
|
throw new Error("Missing schema fields ...");
|
|
527
522
|
}
|
|
528
523
|
|
|
524
|
+
if (!type.schema || !type.schema.newDataHandler || typeof type.schema.newDataHandler !== "function") {
|
|
525
|
+
throw new Error("Missing newDataHandler-Function ...");
|
|
526
|
+
}
|
|
527
|
+
|
|
529
528
|
let data: any = null;
|
|
530
529
|
try {
|
|
531
|
-
data = await
|
|
530
|
+
data = await type.schema.newDataHandler(req);
|
|
532
531
|
} catch (e: any) {
|
|
533
532
|
console.error(e);
|
|
534
533
|
}
|