@jd-data-limited/easy-fm 3.2.6 → 3.2.8
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/package.json +10 -6
- package/src/FMError.d.ts +1 -1
- package/src/FMError.js +5 -0
- package/src/FMError.ts +1 -1
- package/src/connection/FMHost.d.ts +1 -1
- package/src/connection/FMHost.js +36 -45
- package/src/connection/FMHost.ts +3 -3
- package/src/connection/database.d.ts +5 -3
- package/src/connection/database.js +90 -112
- package/src/connection/database.ts +70 -82
- package/src/connection/databaseBase.d.ts +4 -1
- package/src/connection/databaseBase.ts +4 -1
- package/src/layouts/layout.d.ts +3 -3
- package/src/layouts/layout.js +26 -50
- package/src/layouts/layout.ts +22 -39
- package/src/layouts/layoutBase.d.ts +2 -2
- package/src/layouts/layoutBase.ts +2 -1
- package/src/layouts/layoutRecordManager.d.ts +1 -1
- package/src/layouts/layoutRecordManager.js +16 -31
- package/src/layouts/layoutRecordManager.ts +14 -30
- package/src/models/apiResults.d.ts +103 -0
- package/src/models/apiResults.js +28 -0
- package/src/models/apiResults.ts +112 -0
- package/src/records/field.d.ts +3 -2
- package/src/records/field.js +44 -68
- package/src/records/field.ts +46 -64
- package/src/records/getOperations/find.js +18 -38
- package/src/records/getOperations/find.ts +17 -28
- package/src/records/getOperations/recordGetOperation.js +7 -4
- package/src/records/getOperations/recordGetOperation.ts +1 -1
- package/src/records/getOperations/recordGetRange.js +16 -34
- package/src/records/getOperations/recordGetRange.ts +17 -24
- package/src/records/layoutRecord.js +103 -151
- package/src/records/layoutRecord.ts +101 -133
- package/src/records/portal.js +3 -0
- package/src/records/portalRecord.js +2 -1
- package/src/records/recordBase.js +6 -1
- package/src/types.d.ts +0 -4
- package/src/types.ts +1 -7
- package/.expo/README.md +0 -15
- package/.expo/settings.json +0 -8
- package/.idea/compiler.xml +0 -7
- package/.idea/copyright/JD_Data.xml +0 -6
- package/.idea/copyright/profiles_settings.xml +0 -7
- package/.idea/discord.xml +0 -7
- package/.idea/easy-fm.iml +0 -8
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -18
- package/.idea/vcs.xml +0 -6
- package/decs.d.ts +0 -7
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.LICENSE.txt +0 -3
- package/docs/classes/FileMakerConnection.md +0 -86
- package/docs/classes/layout.md +0 -0
- package/examples/test.js +0 -7
- package/fmErrors.json +0 -1010
- package/img.png +0 -0
- package/test.d.ts +0 -2
- package/test.js +0 -30
- package/test.ts +0 -33
- package/test2.d.ts +0 -1
- package/test2.js +0 -15
- package/tsconfig.json +0 -16
- package/webpack.config.cjs +0 -20
|
@@ -7,6 +7,7 @@ import {LayoutRecord} from "../layoutRecord.js";
|
|
|
7
7
|
import {LayoutInterface} from "../../layouts/layoutInterface";
|
|
8
8
|
import {LayoutBase} from "../../layouts/layoutBase.js";
|
|
9
9
|
import {FMError} from "../../FMError.js";
|
|
10
|
+
import {ApiRecordResponseObj} from "../../models/apiResults";
|
|
10
11
|
|
|
11
12
|
export class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
12
13
|
protected queries: object[]
|
|
@@ -54,35 +55,23 @@ export class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
|
54
55
|
return this.fetch()
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
fetch(): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
|
|
58
|
+
async fetch(): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
|
|
58
59
|
let trace = new Error()
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
port: 443,
|
|
65
|
-
method: "POST",
|
|
66
|
-
body: JSON.stringify(this.toObject())
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
.then(async res => {
|
|
70
|
-
// // console.log(res)
|
|
71
|
-
if (res.messages[0].code === "0") {
|
|
72
|
-
// console.log("RESOLVING")
|
|
73
|
-
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
74
|
-
let data = res.response.data.map(item => {
|
|
75
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
76
|
-
})
|
|
77
|
-
resolve(data)
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace))
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
.catch(e => {
|
|
84
|
-
reject(e)
|
|
85
|
-
})
|
|
60
|
+
await this.layout.getLayoutMeta()
|
|
61
|
+
let res = await this.layout.database.apiRequest<ApiRecordResponseObj>(`${this.layout.endpoint}/_find`, {
|
|
62
|
+
port: 443,
|
|
63
|
+
method: "POST",
|
|
64
|
+
body: JSON.stringify(this.toObject())
|
|
86
65
|
})
|
|
66
|
+
if (res.messages[0].code === "0") {
|
|
67
|
+
// console.log("RESOLVING")
|
|
68
|
+
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
69
|
+
return res.response.data.map(item => {
|
|
70
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
|
|
75
|
+
}
|
|
87
76
|
}
|
|
88
77
|
}
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
export class RecordGetOperation {
|
|
5
|
+
layout;
|
|
6
|
+
limit = 100;
|
|
7
|
+
scripts;
|
|
8
|
+
sort;
|
|
9
|
+
limitPortals = [];
|
|
10
|
+
offset = 0;
|
|
5
11
|
constructor(layout) {
|
|
6
|
-
this.limit = 100;
|
|
7
|
-
this.limitPortals = [];
|
|
8
|
-
this.offset = 0;
|
|
9
12
|
this.layout = layout;
|
|
10
13
|
this.scripts = {
|
|
11
14
|
"script": null,
|
|
@@ -37,7 +40,7 @@ export class RecordGetOperation {
|
|
|
37
40
|
setOffset(offset) {
|
|
38
41
|
if (offset < 0)
|
|
39
42
|
throw "Record offset too low";
|
|
40
|
-
this.
|
|
43
|
+
this.offset = offset;
|
|
41
44
|
return this;
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
4
|
import { RecordGetOperation } from "./recordGetOperation.js";
|
|
14
5
|
import { LayoutRecord } from "../layoutRecord.js";
|
|
15
6
|
import { FMError } from "../../FMError.js";
|
|
@@ -63,33 +54,24 @@ export class RecordGetRange extends RecordGetOperation {
|
|
|
63
54
|
run(extraBody = {}) {
|
|
64
55
|
return this.fetch(extraBody);
|
|
65
56
|
}
|
|
66
|
-
fetch(extraBody = {}) {
|
|
57
|
+
async fetch(extraBody = {}) {
|
|
67
58
|
let trace = new Error();
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
72
|
-
method: "GET"
|
|
73
|
-
});
|
|
74
|
-
})
|
|
75
|
-
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
// // console.log(res)
|
|
77
|
-
if (res.messages[0].code === "0") {
|
|
78
|
-
// console.log("RESOLVING")
|
|
79
|
-
if (!this.layout.metadata)
|
|
80
|
-
yield this.layout.getLayoutMeta();
|
|
81
|
-
let data = res.response.data.map(item => {
|
|
82
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
83
|
-
});
|
|
84
|
-
resolve(data);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
88
|
-
}
|
|
89
|
-
}))
|
|
90
|
-
.catch(e => {
|
|
91
|
-
reject(e);
|
|
59
|
+
let res = await this.layout.getLayoutMeta().then(() => {
|
|
60
|
+
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
61
|
+
method: "GET"
|
|
92
62
|
});
|
|
93
63
|
});
|
|
64
|
+
if (res.messages[0].code === "0") {
|
|
65
|
+
// console.log("RESOLVING")
|
|
66
|
+
if (!this.layout.metadata)
|
|
67
|
+
await this.layout.getLayoutMeta();
|
|
68
|
+
let data = res.response.data.map(item => {
|
|
69
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
70
|
+
});
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
75
|
+
}
|
|
94
76
|
}
|
|
95
77
|
}
|
|
@@ -7,6 +7,7 @@ import {RecordGetOperation} from "./recordGetOperation.js";
|
|
|
7
7
|
import {LayoutRecord} from "../layoutRecord.js";
|
|
8
8
|
import {extraBodyOptions} from "../../types.js";
|
|
9
9
|
import {FMError} from "../../FMError.js";
|
|
10
|
+
import {ApiRecordResponseObj} from "../../models/apiResults";
|
|
10
11
|
|
|
11
12
|
export class RecordGetRange<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
12
13
|
constructor(layout, start = 0, limit = 100) {
|
|
@@ -53,32 +54,24 @@ export class RecordGetRange<T extends LayoutInterface> extends RecordGetOperatio
|
|
|
53
54
|
return this.fetch(extraBody)
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
fetch(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
|
|
57
|
+
async fetch(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
|
|
57
58
|
let trace = new Error()
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
62
|
-
method: "GET"
|
|
63
|
-
})
|
|
59
|
+
let res = await this.layout.getLayoutMeta().then(() => {
|
|
60
|
+
return this.layout.database.apiRequest<ApiRecordResponseObj>(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
61
|
+
method: "GET"
|
|
64
62
|
})
|
|
65
|
-
.then(async res => {
|
|
66
|
-
// // console.log(res)
|
|
67
|
-
if (res.messages[0].code === "0") {
|
|
68
|
-
// console.log("RESOLVING")
|
|
69
|
-
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
70
|
-
let data = res.response.data.map(item => {
|
|
71
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
72
|
-
})
|
|
73
|
-
resolve(data)
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace))
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
.catch(e => {
|
|
80
|
-
reject(e)
|
|
81
|
-
})
|
|
82
63
|
})
|
|
64
|
+
|
|
65
|
+
if (res.messages[0].code === "0") {
|
|
66
|
+
// console.log("RESOLVING")
|
|
67
|
+
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
68
|
+
let data = res.response.data.map(item => {
|
|
69
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
70
|
+
})
|
|
71
|
+
return data
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
|
|
75
|
+
}
|
|
83
76
|
}
|
|
84
77
|
}
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
4
|
import { RecordBase } from "./recordBase.js";
|
|
14
5
|
import { PortalRecord } from "./portalRecord.js";
|
|
15
6
|
import { Portal } from "./portal.js";
|
|
16
7
|
import { FMError } from "../FMError.js";
|
|
17
8
|
export class LayoutRecord extends RecordBase {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
portals = {};
|
|
18
11
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
19
12
|
super(layout, recordId, modId);
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
this.portals = {};
|
|
22
13
|
this.processFieldData(fieldData);
|
|
23
14
|
if (portalData) {
|
|
24
15
|
this.processPortalData(portalData);
|
|
@@ -27,76 +18,61 @@ export class LayoutRecord extends RecordBase {
|
|
|
27
18
|
get portalsArray() {
|
|
28
19
|
return Object.values(this.portals);
|
|
29
20
|
}
|
|
30
|
-
commit(extraBody = {}) {
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
if (this.recordId === -1) {
|
|
53
|
-
// This is a new LayoutRecord
|
|
54
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
55
|
-
port: 443,
|
|
56
|
-
method: "POST",
|
|
57
|
-
body: JSON.stringify(data)
|
|
58
|
-
})
|
|
59
|
-
.then(res => {
|
|
60
|
-
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
61
|
-
reject(new FMError(res.response.scriptError, res.status, res, trace));
|
|
62
|
-
}
|
|
63
|
-
else if (res.messages[0].code === "0") {
|
|
64
|
-
this.recordId = parseInt(res.response.recordId);
|
|
65
|
-
this.modId = parseInt(res.response.modId);
|
|
66
|
-
resolve(this);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
.catch(e => {
|
|
73
|
-
reject(e);
|
|
74
|
-
});
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// for (let item of Object.keys(data)) extraBody[item] = data[item]
|
|
78
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
21
|
+
async commit(extraBody = {}) {
|
|
22
|
+
let data = this.toObject();
|
|
23
|
+
delete data.recordId;
|
|
24
|
+
delete data.modId;
|
|
25
|
+
if (extraBody.scripts?.after) {
|
|
26
|
+
data["script"] = extraBody.scripts.after.name;
|
|
27
|
+
if (extraBody.scripts.after.parameter)
|
|
28
|
+
data["script.param"] = extraBody.scripts.after.parameter;
|
|
29
|
+
}
|
|
30
|
+
if (extraBody.scripts?.prerequest) {
|
|
31
|
+
data["script.prerequest"] = extraBody.scripts.after.name;
|
|
32
|
+
if (extraBody.scripts.prerequest.parameter)
|
|
33
|
+
data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter;
|
|
34
|
+
}
|
|
35
|
+
if (extraBody.scripts?.presort) {
|
|
36
|
+
data["script.presort"] = extraBody.scripts.presort.name;
|
|
37
|
+
if (extraBody.scripts.presort.parameter)
|
|
38
|
+
data["script.presort.param"] = extraBody.scripts.presort.parameter;
|
|
39
|
+
}
|
|
40
|
+
if (this.recordId === -1) {
|
|
41
|
+
// This is a new LayoutRecord
|
|
42
|
+
let res = await this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
79
43
|
port: 443,
|
|
80
|
-
method: "
|
|
44
|
+
method: "POST",
|
|
81
45
|
body: JSON.stringify(data)
|
|
82
|
-
})
|
|
83
|
-
.then(res => {
|
|
84
|
-
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
85
|
-
reject(new FMError(res.response.scriptError, res.status, res, trace));
|
|
86
|
-
}
|
|
87
|
-
else if (res.messages[0].code === "0") {
|
|
88
|
-
this.modId = res.response.modId;
|
|
89
|
-
this._onSave();
|
|
90
|
-
resolve(this);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
.catch(e => {
|
|
97
|
-
reject(e);
|
|
98
46
|
});
|
|
99
|
-
|
|
47
|
+
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
48
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res);
|
|
49
|
+
}
|
|
50
|
+
else if (res.messages[0].code === "0") {
|
|
51
|
+
this.recordId = parseInt(res.response.recordId);
|
|
52
|
+
this.modId = parseInt(res.response.modId);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// for (let item of Object.keys(data)) extraBody[item] = data[item]
|
|
60
|
+
let res = await this.layout.database.apiRequest(this.endpoint, {
|
|
61
|
+
port: 443,
|
|
62
|
+
method: "PATCH",
|
|
63
|
+
body: JSON.stringify(data)
|
|
64
|
+
});
|
|
65
|
+
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
66
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res);
|
|
67
|
+
}
|
|
68
|
+
else if (res.messages[0].code === "0") {
|
|
69
|
+
this.modId = +res.response.modId;
|
|
70
|
+
this._onSave();
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res);
|
|
75
|
+
}
|
|
100
76
|
}
|
|
101
77
|
processPortalData(portalData) {
|
|
102
78
|
for (let portalName of Object.keys(portalData)) {
|
|
@@ -111,89 +87,65 @@ export class LayoutRecord extends RecordBase {
|
|
|
111
87
|
this.portals[portalName] = _portal;
|
|
112
88
|
}
|
|
113
89
|
}
|
|
114
|
-
get() {
|
|
90
|
+
async get() {
|
|
115
91
|
let trace = new Error();
|
|
116
92
|
if (this.recordId === -1) {
|
|
117
93
|
throw "Cannot get this RecordBase until a commit() is done.";
|
|
118
94
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
resolve(this);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
.catch(e => {
|
|
141
|
-
reject(e);
|
|
142
|
-
});
|
|
143
|
-
}));
|
|
95
|
+
if (!this.layout.metadata)
|
|
96
|
+
await this.layout.getLayoutMeta();
|
|
97
|
+
let res = await this.layout.database.apiRequest(this.endpoint, {
|
|
98
|
+
port: 443,
|
|
99
|
+
method: "GET"
|
|
100
|
+
});
|
|
101
|
+
if (res.messages[0].code === "0") {
|
|
102
|
+
// console.log(res, res.response.data)
|
|
103
|
+
this.modId = +res.response.data[0].modId;
|
|
104
|
+
this.processFieldData(res.response.data[0].fieldData);
|
|
105
|
+
this.portalData = [];
|
|
106
|
+
if (res.response.data[0].portalData)
|
|
107
|
+
this.processPortalData(res.response.data[0].portalData);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
144
110
|
}
|
|
145
111
|
getPortal(portal) {
|
|
146
112
|
return this.portalsArray.find(p => p.name === portal);
|
|
147
113
|
}
|
|
148
|
-
duplicate() {
|
|
114
|
+
async duplicate() {
|
|
149
115
|
let trace = new Error();
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
.catch(e => {
|
|
170
|
-
reject(e);
|
|
171
|
-
});
|
|
172
|
-
}));
|
|
116
|
+
let res = await this.layout.database.apiRequest(this.endpoint, {
|
|
117
|
+
port: 443,
|
|
118
|
+
method: "POST"
|
|
119
|
+
});
|
|
120
|
+
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
121
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res, trace);
|
|
122
|
+
}
|
|
123
|
+
else if (res.messages[0].code === "0") {
|
|
124
|
+
let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false);
|
|
125
|
+
let _res = new LayoutRecord(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData);
|
|
126
|
+
this.emit("duplicated");
|
|
127
|
+
return _res;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
131
|
+
}
|
|
173
132
|
}
|
|
174
|
-
delete() {
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
.catch(e => {
|
|
194
|
-
reject(e);
|
|
195
|
-
});
|
|
196
|
-
}));
|
|
133
|
+
async delete() {
|
|
134
|
+
let res = await this.layout.database.apiRequest(this.endpoint, {
|
|
135
|
+
port: 443,
|
|
136
|
+
method: "DELETE"
|
|
137
|
+
});
|
|
138
|
+
console.log(res);
|
|
139
|
+
if (typeof res.response?.scriptError !== "undefined" && res.response?.scriptError !== '0') {
|
|
140
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res);
|
|
141
|
+
}
|
|
142
|
+
else if (res.messages[0].code === "0") {
|
|
143
|
+
this.emit("deleted");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res);
|
|
148
|
+
}
|
|
197
149
|
}
|
|
198
150
|
toObject(filter = (a) => a.edited, portalFilter = (a) => a.records.find(record => record.edited), portalRowFilter = (a) => a.edited, portalFieldFilter = (a) => a.edited) {
|
|
199
151
|
let obj = super.toObject(filter, portalFilter, portalRowFilter, portalFieldFilter);
|