@jd-data-limited/easy-fm 3.0.10 → 3.1.1

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.
Files changed (67) hide show
  1. package/.idea/compiler.xml +7 -0
  2. package/.idea/discord.xml +7 -0
  3. package/dist/index.min.js +2 -0
  4. package/dist/index.min.js.LICENSE.txt +3 -0
  5. package/examples/test.js +7 -0
  6. package/img.png +0 -0
  7. package/package.json +2 -2
  8. package/src/FMError.d.ts +12 -0
  9. package/src/FMError.js +1028 -0
  10. package/src/FMError.ts +1035 -0
  11. package/src/connection/FMHost.d.ts +12 -0
  12. package/src/connection/FMHost.js +68 -0
  13. package/src/connection/FMHost.ts +75 -0
  14. package/src/connection/database.d.ts +28 -0
  15. package/src/connection/database.js +195 -0
  16. package/src/connection/database.ts +216 -0
  17. package/src/connection/generateAuthorizationHeaders.d.ts +2 -0
  18. package/src/connection/generateAuthorizationHeaders.js +23 -0
  19. package/src/connection/generateAuthorizationHeaders.ts +32 -0
  20. package/src/index.d.ts +19 -0
  21. package/src/index.js +19 -2076
  22. package/src/index.ts +38 -2325
  23. package/src/layouts/layout.d.ts +29 -0
  24. package/src/layouts/layout.js +84 -0
  25. package/src/layouts/layout.ts +92 -0
  26. package/src/layouts/layoutInterface.d.ts +13 -0
  27. package/src/layouts/layoutInterface.js +4 -0
  28. package/src/layouts/layoutInterface.ts +21 -0
  29. package/src/layouts/layoutRecordManager.d.ts +13 -0
  30. package/src/layouts/layoutRecordManager.js +50 -0
  31. package/src/layouts/layoutRecordManager.ts +59 -0
  32. package/src/records/field.d.ts +23 -0
  33. package/src/records/field.js +177 -0
  34. package/src/records/field.ts +189 -0
  35. package/src/records/getOperations/find.d.ts +15 -0
  36. package/src/records/getOperations/find.js +90 -0
  37. package/src/records/getOperations/find.ts +88 -0
  38. package/src/records/getOperations/recordGetOperation.d.ts +17 -0
  39. package/src/records/getOperations/recordGetOperation.js +43 -0
  40. package/src/records/getOperations/recordGetOperation.ts +54 -0
  41. package/src/records/getOperations/recordGetRange.d.ts +13 -0
  42. package/src/records/getOperations/recordGetRange.js +95 -0
  43. package/src/records/getOperations/recordGetRange.ts +84 -0
  44. package/src/records/layoutRecord.d.ts +16 -0
  45. package/src/records/layoutRecord.js +211 -0
  46. package/src/records/layoutRecord.ts +220 -0
  47. package/src/records/portal.d.ts +10 -0
  48. package/src/records/portal.js +19 -0
  49. package/src/records/portal.ts +28 -0
  50. package/src/records/portalRecord.d.ts +12 -0
  51. package/src/records/portalRecord.js +32 -0
  52. package/src/records/portalRecord.ts +43 -0
  53. package/src/records/recordBase.d.ts +21 -0
  54. package/src/records/recordBase.js +95 -0
  55. package/src/records/recordBase.ts +121 -0
  56. package/src/types.d.ts +119 -0
  57. package/src/types.js +8 -0
  58. package/src/types.ts +151 -0
  59. package/test.d.ts +1 -0
  60. package/test.js +4 -0
  61. package/tsconfig.json +4 -0
  62. package/TEMP/FILEMAKER.txt +0 -218
  63. package/TEMP/WEBAPP.txt +0 -92
  64. package/TEMP/config.yaml +0 -40
  65. package/TEMP/data.json +0 -19837
  66. package/temp2/1.19.2-forge-43.2.8.json +0 -347
  67. package/temp2/Quinn-1.19.2-forge-43.2.8.json +0 -347
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright (c) 2023. See LICENSE file for more information
3
+ */
4
+
5
+ import {LayoutInterface} from "../../layouts/layoutInterface";
6
+ import {RecordGetOperation} from "./recordGetOperation";
7
+ import {LayoutRecord} from "../layoutRecord";
8
+ import {extraBodyOptions} from "../../types.js";
9
+ import {FMError} from "../../FMError";
10
+
11
+ export class RecordGetRange<T extends LayoutInterface> extends RecordGetOperation<T> {
12
+ constructor(layout, start = 0, limit = 100) {
13
+ super(layout)
14
+ this.setOffset(start)
15
+ this.setLimit(limit)
16
+ }
17
+
18
+ private generateQueryParams(extraBody: extraBodyOptions = {}) {
19
+ let params = []
20
+ if (this.limit !== 100) params.push("_limit=" + this.limit)
21
+ if (this.offset !== 0) params.push("_offset=" + this.offset)
22
+ if (this.sort.length > 0) params.push("_sort=" + encodeURI(JSON.stringify(this.sort)))
23
+ if (this.limitPortals.length > 0) {
24
+ params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portal.name))))
25
+ for (let item of this.limitPortals) {
26
+ if (item.offset !== 0) params.push("_offset." + item.portal.name.replace(/[^0-9A-z]/g, "") + "=" + item.offset)
27
+ if (item.limit !== 100) params.push("_limit." + item.portal.name.replace(/[^0-9A-z]/g, "") + "=" + item.limit)
28
+ }
29
+ }
30
+ if (extraBody.scripts) {
31
+ if (extraBody.scripts.prerequest) {
32
+ params.push("script.prerequest=" + extraBody.scripts.prerequest.name)
33
+ if (extraBody.scripts.prerequest.parameter) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter)
34
+ }
35
+ if (extraBody.scripts.presort) {
36
+ params.push("script.presort=" + extraBody.scripts.presort.name)
37
+ if (extraBody.scripts.presort.parameter) params.push("script.presort.param=" + extraBody.scripts.presort.parameter)
38
+ }
39
+ if (extraBody.scripts.after) {
40
+ params.push("script=" + extraBody.scripts.after.name)
41
+ if (extraBody.scripts.after.parameter) params.push("script.param=" + extraBody.scripts.after.parameter)
42
+ }
43
+ }
44
+
45
+ if (params.length === 0) return ""
46
+ return "?" + params.join("&")
47
+ }
48
+
49
+ /**
50
+ * @deprecated in favour of .fetch()
51
+ */
52
+ run(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
53
+ return this.fetch(extraBody)
54
+ }
55
+
56
+ fetch(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
57
+ let trace = new Error()
58
+ return new Promise((resolve, reject) => {
59
+ // console.log(this.#toObject())
60
+ this.layout.getLayoutMeta().then(() => {
61
+ return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
62
+ method: "GET"
63
+ })
64
+ })
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
+ })
83
+ }
84
+ }
@@ -0,0 +1,16 @@
1
+ import { extraBodyOptions, recordObject } from "../types.js";
2
+ import { RecordBase } from "./recordBase";
3
+ import { Portal } from "./portal";
4
+ import { PortalInterface, RecordFieldsMap } from "../layouts/layoutInterface";
5
+ export declare class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> {
6
+ portals: P;
7
+ constructor(layout: any, recordId: any, modId?: any, fieldData?: {}, portalData?: any);
8
+ get portalsArray(): Portal<any>[];
9
+ commit(extraBody?: extraBodyOptions): Promise<this>;
10
+ protected processPortalData(portalData: any): void;
11
+ get(): Promise<this>;
12
+ getPortal(portal: any): Portal<any>;
13
+ duplicate(): Promise<LayoutRecord<T, P>>;
14
+ delete(): Promise<void>;
15
+ toObject(filter?: (a: any) => any, portalFilter?: (a: any) => any, portalRowFilter?: (a: any) => any, portalFieldFilter?: (a: any) => any): recordObject;
16
+ }
@@ -0,0 +1,211 @@
1
+ /*
2
+ * Copyright (c) 2023. See LICENSE file for more information
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
+ import { RecordBase } from "./recordBase";
14
+ import { PortalRecord } from "./portalRecord";
15
+ import { Portal } from "./portal";
16
+ import { FMError } from "../FMError";
17
+ export class LayoutRecord extends RecordBase {
18
+ constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
19
+ super(layout, recordId, modId);
20
+ this.processFieldData(fieldData);
21
+ if (portalData) {
22
+ this.processPortalData(portalData);
23
+ }
24
+ }
25
+ get portalsArray() {
26
+ return Object.values(this.portals);
27
+ }
28
+ commit(extraBody = {}) {
29
+ let trace = new Error();
30
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
31
+ var _a, _b, _c;
32
+ let data = this.toObject();
33
+ delete data.recordId;
34
+ delete data.modId;
35
+ if ((_a = extraBody.scripts) === null || _a === void 0 ? void 0 : _a.after) {
36
+ data["script"] = extraBody.scripts.after.name;
37
+ if (extraBody.scripts.after.parameter)
38
+ data["script.param"] = extraBody.scripts.after.parameter;
39
+ }
40
+ if ((_b = extraBody.scripts) === null || _b === void 0 ? void 0 : _b.prerequest) {
41
+ data["script.prerequest"] = extraBody.scripts.after.name;
42
+ if (extraBody.scripts.prerequest.parameter)
43
+ data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter;
44
+ }
45
+ if ((_c = extraBody.scripts) === null || _c === void 0 ? void 0 : _c.presort) {
46
+ data["script.presort"] = extraBody.scripts.presort.name;
47
+ if (extraBody.scripts.presort.parameter)
48
+ data["script.presort.param"] = extraBody.scripts.presort.parameter;
49
+ }
50
+ if (this.recordId === -1) {
51
+ // This is a new LayoutRecord
52
+ this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
53
+ port: 443,
54
+ method: "POST",
55
+ body: JSON.stringify(data)
56
+ })
57
+ .then(res => {
58
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
59
+ reject(new FMError(res.response.scriptError, res.status, res, trace));
60
+ }
61
+ else if (res.messages[0].code === "0") {
62
+ this.recordId = parseInt(res.response.recordId);
63
+ this.modId = parseInt(res.response.modId);
64
+ resolve(this);
65
+ }
66
+ else {
67
+ reject(new FMError(res.messages[0].code, res.status, res, trace));
68
+ }
69
+ })
70
+ .catch(e => {
71
+ reject(e);
72
+ });
73
+ return;
74
+ }
75
+ // for (let item of Object.keys(data)) extraBody[item] = data[item]
76
+ this.layout.database.apiRequest(this.endpoint, {
77
+ port: 443,
78
+ method: "PATCH",
79
+ body: JSON.stringify(data)
80
+ })
81
+ .then(res => {
82
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
83
+ reject(new FMError(res.response.scriptError, res.status, res, trace));
84
+ }
85
+ else if (res.messages[0].code === "0") {
86
+ this.modId = res.response.modId;
87
+ this._onSave();
88
+ resolve(this);
89
+ }
90
+ else {
91
+ reject(new FMError(res.messages[0].code, res.status, res, trace));
92
+ }
93
+ })
94
+ .catch(e => {
95
+ reject(e);
96
+ });
97
+ }));
98
+ }
99
+ processPortalData(portalData) {
100
+ for (let portalName of Object.keys(portalData)) {
101
+ let _portal = new Portal(this, portalName);
102
+ _portal.records = portalData[portalName].map(item => {
103
+ let fieldData = item;
104
+ delete fieldData.recordId;
105
+ delete fieldData.modId;
106
+ return new PortalRecord(this, _portal, item.recordId, item.modId, fieldData);
107
+ });
108
+ // @ts-ignore
109
+ this.portals[portalName] = _portal;
110
+ }
111
+ }
112
+ get() {
113
+ let trace = new Error();
114
+ if (this.recordId === -1) {
115
+ throw "Cannot get this RecordBase until a commit() is done.";
116
+ }
117
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
118
+ if (!this.layout.metadata)
119
+ yield this.layout.getLayoutMeta();
120
+ this.layout.database.apiRequest(this.endpoint, {
121
+ port: 443,
122
+ method: "GET"
123
+ })
124
+ .then(res => {
125
+ if (res.messages[0].code === "0") {
126
+ // console.log(res, res.response.data)
127
+ this.modId = res.response.data[0].modId;
128
+ this.processFieldData(res.response.data[0].fieldData);
129
+ this.portalData = [];
130
+ if (res.response.data[0].portalData)
131
+ this.processPortalData(res.response.data[0].portalData);
132
+ resolve(this);
133
+ }
134
+ else {
135
+ reject(new FMError(res.messages[0].code, res.status, res, trace));
136
+ }
137
+ })
138
+ .catch(e => {
139
+ reject(e);
140
+ });
141
+ }));
142
+ }
143
+ getPortal(portal) {
144
+ return this.portalsArray.find(p => p.name === portal);
145
+ }
146
+ duplicate() {
147
+ let trace = new Error();
148
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
149
+ this.layout.database.apiRequest(this.endpoint, {
150
+ port: 443,
151
+ method: "POST"
152
+ })
153
+ .then(res => {
154
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
155
+ reject(new FMError(res.response.scriptError, res.status, res, trace));
156
+ }
157
+ else if (res.messages[0].code === "0") {
158
+ let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false);
159
+ let _res = new LayoutRecord(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData);
160
+ this.emit("duplicated");
161
+ resolve(_res);
162
+ }
163
+ else {
164
+ reject(new FMError(res.messages[0].code, res.status, res, trace));
165
+ }
166
+ })
167
+ .catch(e => {
168
+ reject(e);
169
+ });
170
+ }));
171
+ }
172
+ delete() {
173
+ let trace = new Error();
174
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
175
+ this.layout.database.apiRequest(this.endpoint, {
176
+ port: 443,
177
+ method: "DELETE"
178
+ })
179
+ .then(res => {
180
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
181
+ reject(new FMError(res.response.scriptError, res.status, res, trace));
182
+ }
183
+ else if (res.messages[0].code === "0") {
184
+ this.emit("deleted");
185
+ resolve();
186
+ }
187
+ else {
188
+ reject(new FMError(res.messages[0].code, res.status, res, trace));
189
+ }
190
+ })
191
+ .catch(e => {
192
+ reject(e);
193
+ });
194
+ }));
195
+ }
196
+ toObject(filter = (a) => a.edited, portalFilter = (a) => a.records.find(record => record.edited), portalRowFilter = (a) => a.edited, portalFieldFilter = (a) => a.edited) {
197
+ let obj = super.toObject(filter, portalFilter, portalRowFilter, portalFieldFilter);
198
+ // Check if there's been any edited portal information
199
+ let portals = this.portalsArray.filter(a => portalFilter(a));
200
+ if (portals) {
201
+ obj["portalData"] = {};
202
+ for (let portal of portals) {
203
+ // @ts-ignore
204
+ obj["portalData"][portal.name] = portal.records.filter(a => portalRowFilter(a)).map(record => {
205
+ return record.toObject(portalFieldFilter);
206
+ });
207
+ }
208
+ }
209
+ return obj;
210
+ }
211
+ }
@@ -0,0 +1,220 @@
1
+ /*
2
+ * Copyright (c) 2023. See LICENSE file for more information
3
+ */
4
+
5
+ import {extraBodyOptions, recordObject} from "../types.js";
6
+ import {RecordBase} from "./recordBase";
7
+ import {PortalRecord} from "./portalRecord";
8
+ import {Portal} from "./portal";
9
+ import {PortalInterface, RecordFieldsMap} from "../layouts/layoutInterface";
10
+ import {FMError} from "../FMError";
11
+
12
+ export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> {
13
+ portals: P
14
+
15
+ constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
16
+ super(layout, recordId, modId);
17
+ this.processFieldData(fieldData)
18
+ if (portalData) {
19
+ this.processPortalData(portalData)
20
+ }
21
+ }
22
+
23
+ get portalsArray(): Portal<any>[] {
24
+ return Object.values(this.portals)
25
+ }
26
+
27
+ commit(extraBody: extraBodyOptions = {}): Promise<this> {
28
+ let trace = new Error()
29
+ return new Promise(async (resolve, reject) => {
30
+ let data = this.toObject()
31
+ delete data.recordId
32
+ delete data.modId
33
+
34
+ if (extraBody.scripts?.after) {
35
+ data["script"] = extraBody.scripts.after.name
36
+ if (extraBody.scripts.after.parameter) data["script.param"] = extraBody.scripts.after.parameter
37
+ }
38
+ if (extraBody.scripts?.prerequest) {
39
+ data["script.prerequest"] = extraBody.scripts.after.name
40
+ if (extraBody.scripts.prerequest.parameter) data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter
41
+ }
42
+ if (extraBody.scripts?.presort) {
43
+ data["script.presort"] = extraBody.scripts.presort.name
44
+ if (extraBody.scripts.presort.parameter) data["script.presort.param"] = extraBody.scripts.presort.parameter
45
+ }
46
+
47
+ if (this.recordId === -1) {
48
+ // This is a new LayoutRecord
49
+
50
+ this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
51
+ port: 443,
52
+ method: "POST",
53
+ body: JSON.stringify(data)
54
+ })
55
+ .then(res => {
56
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
57
+ reject(new FMError(res.response.scriptError, res.status, res, trace))
58
+ }
59
+ else if (res.messages[0].code === "0") {
60
+ this.recordId = parseInt(res.response.recordId)
61
+ this.modId = parseInt(res.response.modId)
62
+ resolve(this)
63
+ }
64
+ else {
65
+ reject(new FMError(res.messages[0].code, res.status, res, trace))
66
+ }
67
+ })
68
+ .catch(e => {
69
+ reject(e)
70
+ })
71
+
72
+ return
73
+ }
74
+
75
+ // for (let item of Object.keys(data)) extraBody[item] = data[item]
76
+ this.layout.database.apiRequest(this.endpoint, {
77
+ port: 443,
78
+ method: "PATCH",
79
+ body: JSON.stringify(data)
80
+ })
81
+ .then(res => {
82
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
83
+ reject(new FMError(res.response.scriptError, res.status, res, trace))
84
+ }
85
+ else if (res.messages[0].code === "0") {
86
+ this.modId = res.response.modId
87
+ this._onSave()
88
+ resolve(this)
89
+ }
90
+ else {
91
+ reject(new FMError(res.messages[0].code, res.status, res, trace))
92
+ }
93
+ })
94
+ .catch(e => {
95
+ reject(e)
96
+ })
97
+ })
98
+ }
99
+
100
+ protected processPortalData(portalData): void {
101
+ for (let portalName of Object.keys(portalData)) {
102
+ let _portal = new Portal(this, portalName)
103
+ _portal.records = portalData[portalName].map(item => {
104
+ let fieldData = item;
105
+ delete fieldData.recordId;
106
+ delete fieldData.modId;
107
+ return new PortalRecord(this, _portal, item.recordId, item.modId, fieldData);
108
+ })
109
+
110
+ // @ts-ignore
111
+ this.portals[portalName] = _portal;
112
+ }
113
+ }
114
+
115
+ get(): Promise<this> {
116
+ let trace = new Error()
117
+ if (this.recordId === -1) {
118
+ throw "Cannot get this RecordBase until a commit() is done."
119
+ }
120
+ return new Promise(async (resolve, reject) => {
121
+ if (!this.layout.metadata) await this.layout.getLayoutMeta()
122
+
123
+ this.layout.database.apiRequest(this.endpoint, {
124
+ port: 443,
125
+ method: "GET"
126
+ })
127
+ .then(res => {
128
+ if (res.messages[0].code === "0") {
129
+ // console.log(res, res.response.data)
130
+ this.modId = res.response.data[0].modId
131
+ this.processFieldData(res.response.data[0].fieldData)
132
+ this.portalData = []
133
+ if (res.response.data[0].portalData) 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
+ })
143
+ })
144
+ }
145
+
146
+ getPortal(portal) {
147
+ return this.portalsArray.find(p => p.name === portal)
148
+ }
149
+
150
+ duplicate(): Promise<LayoutRecord<T,P>> {
151
+ let trace = new Error()
152
+ return new Promise(async (resolve, reject) => {
153
+ this.layout.database.apiRequest(this.endpoint, {
154
+ port: 443,
155
+ method: "POST"
156
+ })
157
+ .then(res => {
158
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
159
+ reject(new FMError(res.response.scriptError, res.status, res, trace))
160
+ }
161
+ else if (res.messages[0].code === "0") {
162
+ let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false)
163
+ let _res = new LayoutRecord<T,P>(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData)
164
+
165
+ this.emit("duplicated")
166
+ resolve(_res)
167
+ }
168
+ else {
169
+ reject(new FMError(res.messages[0].code, res.status, res, trace))
170
+ }
171
+ })
172
+ .catch(e => {
173
+ reject(e)
174
+ })
175
+ })
176
+ }
177
+
178
+ delete(): Promise<void> {
179
+ let trace = new Error()
180
+ return new Promise(async (resolve, reject) => {
181
+ this.layout.database.apiRequest(this.endpoint, {
182
+ port: 443,
183
+ method: "DELETE"
184
+ })
185
+ .then(res => {
186
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
187
+ reject(new FMError(res.response.scriptError, res.status, res, trace))
188
+ }
189
+ else if (res.messages[0].code === "0") {
190
+ this.emit("deleted")
191
+ resolve()
192
+ }
193
+ else {
194
+ reject(new FMError(res.messages[0].code, res.status, res, trace))
195
+ }
196
+ })
197
+ .catch(e => {
198
+ reject(e)
199
+ })
200
+ })
201
+ }
202
+
203
+ toObject(filter: (a) => any = (a) => a.edited, portalFilter: (a) => any = (a) => a.records.find(record => record.edited), portalRowFilter: (a) => any = (a) => a.edited, portalFieldFilter: (a) => any = (a) => a.edited): recordObject {
204
+ let obj = super.toObject(filter, portalFilter, portalRowFilter, portalFieldFilter);
205
+
206
+ // Check if there's been any edited portal information
207
+ let portals = this.portalsArray.filter(a => portalFilter(a))
208
+ if (portals) {
209
+ obj["portalData"] = {}
210
+ for (let portal of portals) {
211
+ // @ts-ignore
212
+ obj["portalData"][portal.name] = portal.records.filter(a => portalRowFilter(a)).map(record => {
213
+ return record.toObject(portalFieldFilter)
214
+ })
215
+ }
216
+ }
217
+
218
+ return obj
219
+ }
220
+ }
@@ -0,0 +1,10 @@
1
+ import { LayoutRecord } from "./layoutRecord";
2
+ import { PortalRecord } from "./portalRecord";
3
+ import { RecordFieldsMap } from "../layouts/layoutInterface";
4
+ export declare class Portal<T extends RecordFieldsMap> {
5
+ readonly record: LayoutRecord<any, any>;
6
+ readonly name: string;
7
+ records: PortalRecord<T>[];
8
+ constructor(record: LayoutRecord<any, any>, name: string);
9
+ create(): PortalRecord<T>;
10
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2023. See LICENSE file for more information
3
+ */
4
+ import { PortalRecord } from "./portalRecord";
5
+ export class Portal {
6
+ constructor(record, name) {
7
+ this.record = record;
8
+ this.name = name;
9
+ }
10
+ create() {
11
+ let fields = {};
12
+ for (let _field of this.record.layout.metadata.portalMetaData[this.name]) {
13
+ fields[_field.name] = "";
14
+ }
15
+ let record = new PortalRecord(this.record, this, -1, -1, fields);
16
+ this.records.push(record);
17
+ return record;
18
+ }
19
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright (c) 2023. See LICENSE file for more information
3
+ */
4
+
5
+ import {LayoutRecord} from "./layoutRecord";
6
+ import {PortalRecord} from "./portalRecord";
7
+ import {LayoutInterface, PortalInterface, RecordFieldsMap} from "../layouts/layoutInterface";
8
+
9
+ export class Portal<T extends RecordFieldsMap> {
10
+ readonly record: LayoutRecord<any, any>;
11
+ readonly name: string;
12
+ public records: PortalRecord<T>[];
13
+
14
+ constructor(record: LayoutRecord<any, any>, name: string) {
15
+ this.record = record
16
+ this.name = name
17
+ }
18
+
19
+ create() {
20
+ let fields = {}
21
+ for (let _field of this.record.layout.metadata.portalMetaData[this.name]) {
22
+ fields[_field.name] = ""
23
+ }
24
+ let record = new PortalRecord<T>(this.record, this, -1, -1, fields)
25
+ this.records.push(record)
26
+ return record
27
+ }
28
+ }
@@ -0,0 +1,12 @@
1
+ import { RecordBase } from "./recordBase";
2
+ import { extraBodyOptions } from "../types.js";
3
+ import { Portal } from "./portal";
4
+ import { RecordFieldsMap } from "../layouts/layoutInterface";
5
+ export declare class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
6
+ readonly portal: Portal<any>;
7
+ constructor(record: any, portal: any, recordId: any, modId?: any, fieldData?: {});
8
+ _onSave(): void;
9
+ commit(extraBody?: extraBodyOptions): Promise<import("./layoutRecord").LayoutRecord<any, any>>;
10
+ toObject(fieldFilter: any): any;
11
+ getField(field: any): import("./field").Field<import("../layouts/layoutInterface").FieldValue>;
12
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) 2023. See LICENSE file for more information
3
+ */
4
+ import { RecordBase } from "./recordBase";
5
+ export class PortalRecord extends RecordBase {
6
+ constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
7
+ super(record.layout, recordId, modId);
8
+ this.portal = portal;
9
+ this.processFieldData(fieldData);
10
+ }
11
+ _onSave() {
12
+ super._onSave();
13
+ this.portal.record._onSave();
14
+ }
15
+ commit(extraBody = {}) {
16
+ return this.portal.record.commit(extraBody);
17
+ }
18
+ toObject(fieldFilter) {
19
+ super.toObject();
20
+ let res = {
21
+ recordId: this.recordId === -1 ? undefined : this.recordId,
22
+ modId: this.modId === -1 ? undefined : this.modId
23
+ };
24
+ for (let field of this.fieldsArray.filter(a => fieldFilter(a)))
25
+ res[field.id] = field.value;
26
+ // console.log(res)
27
+ return res;
28
+ }
29
+ getField(field) {
30
+ return this.fieldsArray.find(_field => _field.id === field) || this.fieldsArray.find(_field => _field.id === this.portal.name + "::" + field);
31
+ }
32
+ }
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Copyright (c) 2023. See LICENSE file for more information
3
+ */
4
+
5
+ import {RecordBase} from "./recordBase";
6
+ import {extraBodyOptions, recordObject} from "../types.js";
7
+ import {Portal} from "./portal";
8
+ import {RecordFieldsMap} from "../layouts/layoutInterface";
9
+
10
+ export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
11
+ readonly portal: Portal<any>;
12
+
13
+ constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
14
+ super(record.layout, recordId, modId);
15
+
16
+ this.portal = portal
17
+ this.processFieldData(fieldData)
18
+ }
19
+
20
+ _onSave() {
21
+ super._onSave();
22
+ this.portal.record._onSave()
23
+ }
24
+
25
+ commit(extraBody: extraBodyOptions = {}) {
26
+ return this.portal.record.commit(extraBody)
27
+ }
28
+
29
+ toObject(fieldFilter): any {
30
+ super.toObject()
31
+ let res = {
32
+ recordId: this.recordId === -1 ? undefined : this.recordId,
33
+ modId: this.modId === -1 ? undefined : this.modId
34
+ } as recordObject
35
+ for (let field of this.fieldsArray.filter(a => fieldFilter(a))) res[field.id] = field.value
36
+ // console.log(res)
37
+ return res
38
+ }
39
+
40
+ getField(field) {
41
+ return this.fieldsArray.find(_field => _field.id === field) || this.fieldsArray.find(_field => _field.id === this.portal.name + "::" + field)
42
+ }
43
+ }