@jd-data-limited/easy-fm 3.2.7 → 3.2.9
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 +11 -7
- package/src/FMError.d.ts +1 -1
- package/src/FMError.ts +1 -1
- package/src/connection/FMHost.d.ts +1 -1
- package/src/connection/FMHost.ts +3 -3
- package/src/connection/database.d.ts +5 -3
- package/src/connection/database.js +42 -49
- 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 +15 -29
- 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 +24 -27
- 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 +28 -43
- package/src/records/field.ts +46 -64
- package/src/records/getOperations/find.js +18 -28
- package/src/records/getOperations/find.ts +17 -28
- package/src/records/getOperations/recordGetRange.js +15 -22
- package/src/records/getOperations/recordGetRange.ts +17 -24
- package/src/records/layoutRecord.js +73 -102
- package/src/records/layoutRecord.ts +101 -133
- package/src/types.d.ts +0 -4
- package/src/types.ts +0 -5
- 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
package/src/records/field.ts
CHANGED
|
@@ -7,6 +7,7 @@ import fetch, {File, FormData} from "node-fetch";
|
|
|
7
7
|
import * as http from "http";
|
|
8
8
|
import {ContainerBufferResult, DOWNLOAD_MODES, FieldMetaData} from "../types.js";
|
|
9
9
|
import {FMError} from "../FMError.js";
|
|
10
|
+
import {ApiFieldDisplayTypes, ApiFieldMetadata, ApiFieldResultTypes, ApiFieldTypes} from "../models/apiResults.js";
|
|
10
11
|
|
|
11
12
|
export type FieldValue = string | number | Date | Container
|
|
12
13
|
export type Container = null
|
|
@@ -41,14 +42,14 @@ export class Field<T extends FieldValue> {
|
|
|
41
42
|
this.edited = true
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
get metadata():
|
|
45
|
+
get metadata(): ApiFieldMetadata {
|
|
45
46
|
if (!this.record.layout.metadata) {
|
|
46
47
|
// Default to a regular text field
|
|
47
48
|
return {
|
|
48
49
|
name: this.id.toString(),
|
|
49
|
-
type:
|
|
50
|
-
displayType:
|
|
51
|
-
result:
|
|
50
|
+
type: ApiFieldTypes.NORMAL,
|
|
51
|
+
displayType: ApiFieldDisplayTypes.EDIT_TEXT,
|
|
52
|
+
result: ApiFieldResultTypes.TEXT,
|
|
52
53
|
global: false,
|
|
53
54
|
autoEnter: true,
|
|
54
55
|
fourDigitYear: false,
|
|
@@ -57,9 +58,9 @@ export class Field<T extends FieldValue> {
|
|
|
57
58
|
notEmpty: false,
|
|
58
59
|
numeric: false,
|
|
59
60
|
timeOfDay: false,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
61
|
+
repetitions: 1,
|
|
62
|
+
valueList: ""
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
65
|
if (this.record.type === RecordTypes.PORTAL) {
|
|
65
66
|
// @ts-ignore
|
|
@@ -81,11 +82,11 @@ export class Field<T extends FieldValue> {
|
|
|
81
82
|
} as FieldMetaData
|
|
82
83
|
}
|
|
83
84
|
else {
|
|
84
|
-
return this.record.layout.metadata.fieldMetaData.find(i => i.name === this.id)
|
|
85
|
+
return this.record.layout.metadata.fieldMetaData.find(i => i.name === this.id) || {
|
|
85
86
|
name: this.id.toString(),
|
|
86
|
-
type:
|
|
87
|
-
displayType:
|
|
88
|
-
result:
|
|
87
|
+
type: ApiFieldTypes.NORMAL,
|
|
88
|
+
displayType: ApiFieldDisplayTypes.EDIT_TEXT,
|
|
89
|
+
result: ApiFieldResultTypes.TEXT,
|
|
89
90
|
global: false,
|
|
90
91
|
autoEnter: true,
|
|
91
92
|
fourDigitYear: false,
|
|
@@ -94,9 +95,9 @@ export class Field<T extends FieldValue> {
|
|
|
94
95
|
notEmpty: false,
|
|
95
96
|
numeric: false,
|
|
96
97
|
timeOfDay: false,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
98
|
+
repetitions: 1,
|
|
99
|
+
valueList: ""
|
|
100
|
+
}
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
@@ -130,64 +131,45 @@ export class Field<T extends FieldValue> {
|
|
|
130
131
|
throw "Field value is not a number"
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
upload(buffer: Buffer, filename: string, mime: string): Promise<void> {
|
|
134
|
+
async upload(buffer: Buffer, filename: string, mime: string): Promise<void> {
|
|
134
135
|
let trace = new Error()
|
|
135
136
|
if (this.metadata.result !== "container") throw "Cannot upload a file to the field; " + this.id + " (not a container field)"
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
body: form
|
|
145
|
-
}).then(res => res.json())
|
|
146
|
-
.then(data => {
|
|
147
|
-
let _res = data as any
|
|
148
|
-
if (_res.messages[0].code === "0") {
|
|
149
|
-
resolve()
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
reject(new FMError(_res.messages[0].code, _res.status, data, trace))
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
.catch(e => {
|
|
156
|
-
reject(e)
|
|
157
|
-
})
|
|
137
|
+
let form = new FormData()
|
|
138
|
+
form.append("upload", new File([buffer], filename, {type: mime}))
|
|
139
|
+
|
|
140
|
+
await this.record.layout.database.apiRequest<null>(`${this.record.endpoint}/containers/${this.id}/1`, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
headers: {"Authorization": "Bearer " + this.record.layout.database.token, "Content-Type": "multipart/form-data"},
|
|
144
|
+
body: form
|
|
158
145
|
})
|
|
159
146
|
}
|
|
160
147
|
|
|
161
148
|
download(mode: DOWNLOAD_MODES.Stream): Promise<http.IncomingMessage>
|
|
162
149
|
download(mode: DOWNLOAD_MODES.Buffer): Promise<ContainerBufferResult>
|
|
163
|
-
download(mode: DOWNLOAD_MODES = DOWNLOAD_MODES.Stream): Promise<http.IncomingMessage | ContainerBufferResult> {
|
|
150
|
+
async download(mode: DOWNLOAD_MODES = DOWNLOAD_MODES.Stream): Promise<http.IncomingMessage | ContainerBufferResult> {
|
|
151
|
+
if (this.metadata.result !== ApiFieldResultTypes.CONTAINER) throw new Error("Cannot perform download() on a non-container field")
|
|
152
|
+
|
|
153
|
+
let stream = await this.record.layout.database.streamURL(this.string)
|
|
154
|
+
if (mode === DOWNLOAD_MODES.Stream) {
|
|
155
|
+
return stream
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let body = []
|
|
164
159
|
return new Promise((resolve, reject) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
stream.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
reject(e)
|
|
179
|
-
})
|
|
180
|
-
stream.on("end", () => {
|
|
181
|
-
resolve({
|
|
182
|
-
buffer: Buffer.concat(body),
|
|
183
|
-
mime: stream.headers["content-type"],
|
|
184
|
-
request: stream
|
|
185
|
-
} as ContainerBufferResult)
|
|
186
|
-
})
|
|
187
|
-
})
|
|
188
|
-
.catch(e => {
|
|
189
|
-
reject(e)
|
|
190
|
-
})
|
|
160
|
+
stream.on("data", chunk => {
|
|
161
|
+
body.push(chunk)
|
|
162
|
+
})
|
|
163
|
+
stream.on("error", (e) => {
|
|
164
|
+
reject(e)
|
|
165
|
+
})
|
|
166
|
+
stream.on("end", () => {
|
|
167
|
+
resolve({
|
|
168
|
+
buffer: Buffer.concat(body),
|
|
169
|
+
mime: stream.headers["content-type"],
|
|
170
|
+
request: stream
|
|
171
|
+
} as ContainerBufferResult)
|
|
172
|
+
})
|
|
191
173
|
})
|
|
192
174
|
}
|
|
193
175
|
}
|
|
@@ -56,35 +56,25 @@ export class Find extends RecordGetOperation {
|
|
|
56
56
|
return this.fetch();
|
|
57
57
|
}
|
|
58
58
|
fetch() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.layout.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
method: "POST",
|
|
67
|
-
body: JSON.stringify(this.toObject())
|
|
68
|
-
});
|
|
69
|
-
})
|
|
70
|
-
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
// // console.log(res)
|
|
72
|
-
if (res.messages[0].code === "0") {
|
|
73
|
-
// console.log("RESOLVING")
|
|
74
|
-
if (!this.layout.metadata)
|
|
75
|
-
yield this.layout.getLayoutMeta();
|
|
76
|
-
let data = res.response.data.map(item => {
|
|
77
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
78
|
-
});
|
|
79
|
-
resolve(data);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
83
|
-
}
|
|
84
|
-
}))
|
|
85
|
-
.catch(e => {
|
|
86
|
-
reject(e);
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
let trace = new Error();
|
|
61
|
+
yield this.layout.getLayoutMeta();
|
|
62
|
+
let res = yield this.layout.database.apiRequest(`${this.layout.endpoint}/_find`, {
|
|
63
|
+
port: 443,
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: JSON.stringify(this.toObject())
|
|
87
66
|
});
|
|
67
|
+
if (res.messages[0].code === "0") {
|
|
68
|
+
// console.log("RESOLVING")
|
|
69
|
+
if (!this.layout.metadata)
|
|
70
|
+
yield this.layout.getLayoutMeta();
|
|
71
|
+
return res.response.data.map(item => {
|
|
72
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
77
|
+
}
|
|
88
78
|
});
|
|
89
79
|
}
|
|
90
80
|
}
|
|
@@ -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
|
}
|
|
@@ -64,32 +64,25 @@ export class RecordGetRange extends RecordGetOperation {
|
|
|
64
64
|
return this.fetch(extraBody);
|
|
65
65
|
}
|
|
66
66
|
fetch(extraBody = {}) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.layout.getLayoutMeta().then(() => {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
let trace = new Error();
|
|
69
|
+
let res = yield this.layout.getLayoutMeta().then(() => {
|
|
71
70
|
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
72
71
|
method: "GET"
|
|
73
72
|
});
|
|
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);
|
|
92
73
|
});
|
|
74
|
+
if (res.messages[0].code === "0") {
|
|
75
|
+
// console.log("RESOLVING")
|
|
76
|
+
if (!this.layout.metadata)
|
|
77
|
+
yield this.layout.getLayoutMeta();
|
|
78
|
+
let data = res.response.data.map(item => {
|
|
79
|
+
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
80
|
+
});
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
85
|
+
}
|
|
93
86
|
});
|
|
94
87
|
}
|
|
95
88
|
}
|
|
@@ -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
|
}
|
|
@@ -28,9 +28,8 @@ export class LayoutRecord extends RecordBase {
|
|
|
28
28
|
return Object.values(this.portals);
|
|
29
29
|
}
|
|
30
30
|
commit(extraBody = {}) {
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
var _a, _b, _c;
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
33
|
let data = this.toObject();
|
|
35
34
|
delete data.recordId;
|
|
36
35
|
delete data.modId;
|
|
@@ -51,52 +50,41 @@ export class LayoutRecord extends RecordBase {
|
|
|
51
50
|
}
|
|
52
51
|
if (this.recordId === -1) {
|
|
53
52
|
// This is a new LayoutRecord
|
|
54
|
-
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
53
|
+
let res = yield this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
55
54
|
port: 443,
|
|
56
55
|
method: "POST",
|
|
57
56
|
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
57
|
});
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// for (let item of Object.keys(data)) extraBody[item] = data[item]
|
|
78
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
79
|
-
port: 443,
|
|
80
|
-
method: "PATCH",
|
|
81
|
-
body: JSON.stringify(data)
|
|
82
|
-
})
|
|
83
|
-
.then(res => {
|
|
84
58
|
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
85
|
-
|
|
59
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res);
|
|
86
60
|
}
|
|
87
61
|
else if (res.messages[0].code === "0") {
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
|
|
62
|
+
this.recordId = parseInt(res.response.recordId);
|
|
63
|
+
this.modId = parseInt(res.response.modId);
|
|
64
|
+
return this;
|
|
91
65
|
}
|
|
92
66
|
else {
|
|
93
|
-
|
|
67
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res);
|
|
94
68
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
}
|
|
70
|
+
// for (let item of Object.keys(data)) extraBody[item] = data[item]
|
|
71
|
+
let res = yield this.layout.database.apiRequest(this.endpoint, {
|
|
72
|
+
port: 443,
|
|
73
|
+
method: "PATCH",
|
|
74
|
+
body: JSON.stringify(data)
|
|
98
75
|
});
|
|
99
|
-
|
|
76
|
+
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
77
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res);
|
|
78
|
+
}
|
|
79
|
+
else if (res.messages[0].code === "0") {
|
|
80
|
+
this.modId = +res.response.modId;
|
|
81
|
+
this._onSave();
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
100
88
|
}
|
|
101
89
|
processPortalData(portalData) {
|
|
102
90
|
for (let portalName of Object.keys(portalData)) {
|
|
@@ -112,88 +100,71 @@ export class LayoutRecord extends RecordBase {
|
|
|
112
100
|
}
|
|
113
101
|
}
|
|
114
102
|
get() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
let trace = new Error();
|
|
105
|
+
if (this.recordId === -1) {
|
|
106
|
+
throw "Cannot get this RecordBase until a commit() is done.";
|
|
107
|
+
}
|
|
120
108
|
if (!this.layout.metadata)
|
|
121
109
|
yield this.layout.getLayoutMeta();
|
|
122
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
110
|
+
let res = yield this.layout.database.apiRequest(this.endpoint, {
|
|
123
111
|
port: 443,
|
|
124
112
|
method: "GET"
|
|
125
|
-
})
|
|
126
|
-
.then(res => {
|
|
127
|
-
if (res.messages[0].code === "0") {
|
|
128
|
-
// console.log(res, res.response.data)
|
|
129
|
-
this.modId = res.response.data[0].modId;
|
|
130
|
-
this.processFieldData(res.response.data[0].fieldData);
|
|
131
|
-
this.portalData = [];
|
|
132
|
-
if (res.response.data[0].portalData)
|
|
133
|
-
this.processPortalData(res.response.data[0].portalData);
|
|
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
113
|
});
|
|
143
|
-
|
|
114
|
+
if (res.messages[0].code === "0") {
|
|
115
|
+
// console.log(res, res.response.data)
|
|
116
|
+
this.modId = +res.response.data[0].modId;
|
|
117
|
+
this.processFieldData(res.response.data[0].fieldData);
|
|
118
|
+
this.portalData = [];
|
|
119
|
+
if (res.response.data[0].portalData)
|
|
120
|
+
this.processPortalData(res.response.data[0].portalData);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
144
124
|
}
|
|
145
125
|
getPortal(portal) {
|
|
146
126
|
return this.portalsArray.find(p => p.name === portal);
|
|
147
127
|
}
|
|
148
128
|
duplicate() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
let trace = new Error();
|
|
131
|
+
let res = yield this.layout.database.apiRequest(this.endpoint, {
|
|
152
132
|
port: 443,
|
|
153
133
|
method: "POST"
|
|
154
|
-
})
|
|
155
|
-
.then(res => {
|
|
156
|
-
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
157
|
-
reject(new FMError(res.response.scriptError, res.status, res, trace));
|
|
158
|
-
}
|
|
159
|
-
else if (res.messages[0].code === "0") {
|
|
160
|
-
let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false);
|
|
161
|
-
let _res = new LayoutRecord(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData);
|
|
162
|
-
this.emit("duplicated");
|
|
163
|
-
resolve(_res);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
.catch(e => {
|
|
170
|
-
reject(e);
|
|
171
134
|
});
|
|
172
|
-
|
|
135
|
+
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
136
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res, trace);
|
|
137
|
+
}
|
|
138
|
+
else if (res.messages[0].code === "0") {
|
|
139
|
+
let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false);
|
|
140
|
+
let _res = new LayoutRecord(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData);
|
|
141
|
+
this.emit("duplicated");
|
|
142
|
+
return _res;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
173
148
|
}
|
|
174
149
|
delete() {
|
|
175
|
-
|
|
176
|
-
return
|
|
177
|
-
this.layout.database.apiRequest(this.endpoint, {
|
|
150
|
+
var _a, _b;
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
let res = yield this.layout.database.apiRequest(this.endpoint, {
|
|
178
153
|
port: 443,
|
|
179
154
|
method: "DELETE"
|
|
180
|
-
})
|
|
181
|
-
.then(res => {
|
|
182
|
-
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
183
|
-
reject(new FMError(res.response.scriptError, res.status, res, trace));
|
|
184
|
-
}
|
|
185
|
-
else if (res.messages[0].code === "0") {
|
|
186
|
-
this.emit("deleted");
|
|
187
|
-
resolve();
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
.catch(e => {
|
|
194
|
-
reject(e);
|
|
195
155
|
});
|
|
196
|
-
|
|
156
|
+
console.log(res);
|
|
157
|
+
if (typeof ((_a = res.response) === null || _a === void 0 ? void 0 : _a.scriptError) !== "undefined" && ((_b = res.response) === null || _b === void 0 ? void 0 : _b.scriptError) !== '0') {
|
|
158
|
+
throw new FMError(res.response.scriptError, res.httpStatus, res);
|
|
159
|
+
}
|
|
160
|
+
else if (res.messages[0].code === "0") {
|
|
161
|
+
this.emit("deleted");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
197
168
|
}
|
|
198
169
|
toObject(filter = (a) => a.edited, portalFilter = (a) => a.records.find(record => record.edited), portalRowFilter = (a) => a.edited, portalFieldFilter = (a) => a.edited) {
|
|
199
170
|
let obj = super.toObject(filter, portalFilter, portalRowFilter, portalFieldFilter);
|