@jd-data-limited/easy-fm 3.2.7 → 4.0.0

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 (102) hide show
  1. package/README.md +36 -24
  2. package/package.json +15 -8
  3. package/src/FMError.d.ts +1 -1
  4. package/src/FMError.js +7 -2
  5. package/src/FMError.ts +3 -3
  6. package/src/connection/FMHost.d.ts +3 -2
  7. package/src/connection/FMHost.js +37 -47
  8. package/src/connection/FMHost.ts +6 -6
  9. package/src/connection/HostBase.d.ts +1 -1
  10. package/src/connection/HostBase.js +1 -1
  11. package/src/connection/HostBase.ts +2 -4
  12. package/src/connection/database.d.ts +12 -9
  13. package/src/connection/database.js +93 -116
  14. package/src/connection/database.ts +79 -90
  15. package/src/connection/databaseBase.d.ts +5 -2
  16. package/src/connection/databaseBase.js +1 -1
  17. package/src/connection/databaseBase.ts +5 -4
  18. package/src/databaseStructure.d.ts +6 -0
  19. package/src/databaseStructure.js +4 -0
  20. package/src/databaseStructure.ts +12 -0
  21. package/src/index.d.ts +3 -6
  22. package/src/index.js +3 -5
  23. package/src/index.ts +4 -9
  24. package/src/layouts/layout.d.ts +5 -19
  25. package/src/layouts/layout.js +27 -69
  26. package/src/layouts/layout.ts +26 -65
  27. package/src/layouts/layoutBase.d.ts +4 -4
  28. package/src/layouts/layoutBase.js +1 -1
  29. package/src/layouts/layoutBase.ts +5 -5
  30. package/src/layouts/layoutInterface.d.ts +1 -1
  31. package/src/layouts/layoutInterface.js +1 -1
  32. package/src/layouts/layoutInterface.ts +2 -2
  33. package/src/layouts/layoutRecordManager.d.ts +5 -6
  34. package/src/layouts/layoutRecordManager.js +20 -39
  35. package/src/layouts/layoutRecordManager.ts +20 -41
  36. package/src/layouts/recordFieldsMap.d.ts +2 -2
  37. package/src/layouts/recordFieldsMap.js +1 -1
  38. package/src/layouts/recordFieldsMap.ts +3 -3
  39. package/src/models/apiResults.d.ts +103 -0
  40. package/src/models/apiResults.js +28 -0
  41. package/src/models/apiResults.ts +112 -0
  42. package/src/records/field.d.ts +3 -22
  43. package/src/records/field.js +4 -177
  44. package/src/records/field.ts +4 -187
  45. package/src/records/fieldBase.d.ts +30 -0
  46. package/src/records/fieldBase.js +154 -0
  47. package/src/records/fieldBase.ts +174 -0
  48. package/src/records/getOperations/recordGetOperation.d.ts +47 -11
  49. package/src/records/getOperations/recordGetOperation.js +144 -30
  50. package/src/records/getOperations/recordGetOperation.ts +172 -30
  51. package/src/records/layoutRecord.d.ts +8 -7
  52. package/src/records/layoutRecord.js +107 -153
  53. package/src/records/layoutRecord.ts +117 -141
  54. package/src/records/portal.d.ts +6 -5
  55. package/src/records/portal.js +4 -1
  56. package/src/records/portal.ts +7 -7
  57. package/src/records/portalBase.d.ts +5 -4
  58. package/src/records/portalBase.js +1 -1
  59. package/src/records/portalBase.ts +6 -6
  60. package/src/records/portalRecord.d.ts +6 -6
  61. package/src/records/portalRecord.js +5 -3
  62. package/src/records/portalRecord.ts +5 -5
  63. package/src/records/recordBase.d.ts +7 -12
  64. package/src/records/recordBase.js +12 -11
  65. package/src/records/recordBase.ts +10 -15
  66. package/src/types.d.ts +18 -19
  67. package/src/types.js +7 -1
  68. package/src/types.ts +20 -21
  69. package/.expo/README.md +0 -15
  70. package/.expo/settings.json +0 -8
  71. package/.idea/compiler.xml +0 -7
  72. package/.idea/copyright/JD_Data.xml +0 -6
  73. package/.idea/copyright/profiles_settings.xml +0 -7
  74. package/.idea/discord.xml +0 -7
  75. package/.idea/easy-fm.iml +0 -8
  76. package/.idea/jsLibraryMappings.xml +0 -6
  77. package/.idea/modules.xml +0 -8
  78. package/.idea/php.xml +0 -18
  79. package/.idea/vcs.xml +0 -6
  80. package/decs.d.ts +0 -7
  81. package/dist/index.min.js +0 -2
  82. package/dist/index.min.js.LICENSE.txt +0 -3
  83. package/docs/classes/FileMakerConnection.md +0 -86
  84. package/docs/classes/layout.md +0 -0
  85. package/examples/test.js +0 -7
  86. package/fmErrors.json +0 -1010
  87. package/img.png +0 -0
  88. package/src/records/getOperations/find.d.ts +0 -15
  89. package/src/records/getOperations/find.js +0 -90
  90. package/src/records/getOperations/find.ts +0 -88
  91. package/src/records/getOperations/recordGetRange.d.ts +0 -13
  92. package/src/records/getOperations/recordGetRange.js +0 -95
  93. package/src/records/getOperations/recordGetRange.ts +0 -84
  94. package/src/records/portalRecordBase.d.ts +0 -4
  95. package/src/records/portalRecordBase.js +0 -6
  96. package/test.d.ts +0 -2
  97. package/test.js +0 -30
  98. package/test.ts +0 -33
  99. package/test2.d.ts +0 -1
  100. package/test2.js +0 -15
  101. package/tsconfig.json +0 -16
  102. package/webpack.config.cjs +0 -20
@@ -1,54 +1,196 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. See LICENSE file for more information
3
3
  */
4
4
 
5
5
  import {LayoutInterface} from "../../layouts/layoutInterface.js";
6
- import {Portal} from "../portal.js";
7
- import {limitPortalsInterface} from "../../types.js";
6
+ import {ScriptRequestData} from "../../types.js";
8
7
  import {LayoutBase} from "../../layouts/layoutBase.js"
8
+ import {LayoutRecord} from "../layoutRecord.js";
9
+ import {ApiRecordResponseObj} from "../../models/apiResults.js";
10
+ import {FMError} from "../../FMError.js";
9
11
 
10
- export class RecordGetOperation<T extends LayoutInterface> {
12
+ export type SortOrder = "ascend" | "descend"
13
+ export type FindRequest = {
14
+ [key: string]: string,
15
+ omit?: "true" | "false"
16
+ }
17
+ export type PortalRequest = {
18
+ name: string,
19
+ }
20
+
21
+ type PortalData<T extends LayoutInterface> = {
22
+ [key in keyof T["portals"]]: {
23
+ limit: number,
24
+ offset: number
25
+ }
26
+ }
27
+ export type GetOperationOptions<T extends LayoutInterface> = {
28
+ portals: Partial<PortalData<T>>,
29
+ limit?: number,
30
+ offset?: number
31
+ }
32
+
33
+ export class RecordGetOperation<T extends LayoutInterface, OPTIONS extends GetOperationOptions<T>> {
11
34
  protected layout: LayoutBase
12
35
  protected limit: number = 100
13
- protected scripts: object
14
- protected sort: object[]
15
- protected limitPortals: limitPortalsInterface[] = []
16
- protected offset: number = 0
36
+ protected scriptData: ScriptRequestData = {}
37
+ protected sortData: { fieldName: string, sortOrder: SortOrder }[] = []
38
+ protected portals: Partial<PortalData<T>>
39
+ protected offset: number = 1
40
+ protected queries: FindRequest[] = []
17
41
 
18
- constructor(layout: LayoutBase) {
42
+ constructor(layout: LayoutBase, options: OPTIONS) {
19
43
  this.layout = layout
20
- this.scripts = {
21
- "script": null, // Runs after everything
22
- "script.prerequeset": null, // Runs before the request
23
- "script.presort": null // Runs before the sort
44
+ this.sortData = []
45
+ this.portals = options.portals
46
+ this.offset = options.offset || 1 // Offset refers to the starting record. offset 1 is the same as no offset.
47
+ this.limit = options.limit || 100
48
+ }
49
+
50
+ get isFindRequest() {
51
+ return this.queries.length !== 0
52
+ }
53
+
54
+ protected generateParamsBody(offset: number, limit: number) {
55
+ const params: {[key: string]: any} = {
56
+ limit: limit.toString(),
57
+ offset: offset.toString(),
24
58
  }
25
- this.sort = []
59
+ if (this.sortData.length !== 0) params.sort = JSON.stringify(this.sortData)
60
+
61
+
62
+ if (this.scriptData.after) params["script"] = this.scriptData.after.name
63
+ if (this.scriptData.after?.parameter) params["script.param"] = this.scriptData.after.parameter
64
+
65
+ if (this.scriptData.presort) params["script.presort"] = this.scriptData.after.name
66
+ if (this.scriptData.presort?.parameter) params["script.presort.param"] = this.scriptData.after.parameter
67
+
68
+ if (this.scriptData.prerequest) params["script.prerequest"] = this.scriptData.after.name
69
+ if (this.scriptData.prerequest?.parameter) params["script.prerequest.param"] = this.scriptData.after.parameter
70
+
71
+ if (this.queries.length !== 0) params["query"] = this.queries
72
+
73
+ let portals = Object.keys(this.portals)
74
+ params["portal"] = portals
75
+ for (let portal of portals) {
76
+ params[`offset.${portal}`] = this.portals[portal].offset
77
+ params[`limit.${portal}`] = this.portals[portal].limit
78
+ }
79
+
80
+ return params
26
81
  }
82
+ protected generateParamsURL(offset: number, limit: number) {
83
+ const params = new URLSearchParams({
84
+ _limit: limit.toString(),
85
+ _offset: offset.toString(),
86
+ })
87
+ if (this.sortData.length !== 0) params.set("_sort", JSON.stringify(this.sortData))
27
88
 
28
- /*
29
- addToPortalLimit() will adjust the results of the get request so that if a layout has multiple portals in it,
30
- only data from the specified ones will be read. This may help reduce load on your FileMaker API
31
- */
32
- addToPortalLimit(portal: Portal<any>, offset = 0, limit = 100) {
33
- if (offset < 0) throw "Portal offset cannot be less than 0"
34
- this.limitPortals.push({portalName: portal.name, offset, limit})
35
- return this
89
+ if (this.scriptData.after) params.set("script", this.scriptData.after.name)
90
+ if (this.scriptData.after?.parameter) params.set("script.param", this.scriptData.after.parameter)
91
+
92
+ if (this.scriptData.presort) params.set("script.presort", this.scriptData.after.name)
93
+ if (this.scriptData.presort?.parameter) params.set("script.presort.param", this.scriptData.after.parameter)
94
+
95
+ if (this.scriptData.prerequest) params.set("script.prerequest", this.scriptData.after.name)
96
+ if (this.scriptData.prerequest?.parameter) params.set("script.prerequest.param", this.scriptData.after.parameter)
97
+
98
+ let portals = Object.keys(this.portals)
99
+ for (let portal of portals) {
100
+ params.set(`_offset.${portal}`, this.portals[portal].limit.toString())
101
+ params.set(`_offset.${portal}`, this.portals[portal].offset.toString())
102
+ }
103
+ params.set('portal', JSON.stringify(portals))
104
+
105
+ return params
36
106
  }
37
107
 
38
- setLimit(limit: number) {
39
- if (limit < 1) throw "Record limit too low"
40
- this.limit = limit
108
+ scripts(scripts: ScriptRequestData) {
109
+ this.scriptData = scripts;
41
110
  return this
42
111
  }
43
112
 
44
- addSort(fieldName, sortOrder) {
45
- this.sort.push({fieldName, sortOrder})
113
+ sort(fieldName: string, sortOrder: SortOrder) {
114
+ this.sortData.push({fieldName, sortOrder})
46
115
  return this
47
116
  }
48
117
 
49
- setOffset(offset: number) {
50
- if (offset < 0) throw "Record offset too low"
51
- this.offset = offset
118
+ addRequest(query: FindRequest) {
119
+ this.queries.push(query)
52
120
  return this
53
121
  }
122
+
123
+ fetch() {
124
+ return this.performFind(this.offset, this.limit)
125
+ }
126
+
127
+ private async performFind(offset: number, limit: number): Promise<LayoutRecord<T, keyof OPTIONS["portals"]>[]> {
128
+ let trace = new Error()
129
+ await this.layout.getLayoutMeta()
130
+
131
+ const is_find = this.isFindRequest
132
+ let endpoint = this.layout.endpoint + (is_find ? "/_find" : "/records")
133
+ if (!is_find) endpoint += "?" + new URLSearchParams(this.generateParamsURL(offset, limit)).toString()
134
+ const reqData = {
135
+ // port: 443,
136
+ method: is_find ? "POST" : "GET",
137
+ body: is_find ? JSON.stringify(this.generateParamsBody(offset, limit)) : undefined,
138
+ }
139
+
140
+ let res = await this.layout.database.apiRequest<ApiRecordResponseObj>(
141
+ endpoint,
142
+ reqData
143
+ )
144
+ if (res.messages[0].code === "0") {
145
+ // console.log("RESOLVING")
146
+ if (!this.layout.metadata) await this.layout.getLayoutMeta()
147
+ return res.response.data.map(item => {
148
+ return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
149
+ })
150
+ }
151
+ else if (res.messages[0].code == "401") {
152
+ // No records found, so return empty set
153
+ return []
154
+ }
155
+ else {
156
+ throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
157
+ }
158
+ }
159
+
160
+ [Symbol.asyncIterator]() {
161
+ let nextOffset = this.offset
162
+ let startOffset: number = JSON.parse(JSON.stringify(this.offset))
163
+ let limit = this.limit
164
+
165
+ let exit_after_last_record = false
166
+ let records: LayoutRecord<T, keyof OPTIONS["portals"]>[] = []
167
+
168
+ const fetch = async () => {
169
+ const theoretical_limit = (limit - nextOffset) + startOffset
170
+ if (theoretical_limit === 0) {
171
+ exit_after_last_record = true
172
+ records = []
173
+ return
174
+ }
175
+ records = await this.performFind(nextOffset, theoretical_limit < 100 ? theoretical_limit : 100);
176
+ nextOffset += 100;
177
+ if (records.length < 100) exit_after_last_record = true
178
+ }
179
+
180
+ return {
181
+ next: async () => {
182
+ if (records.length === 0 && !exit_after_last_record) {
183
+ await fetch();
184
+ }
185
+
186
+ if (records.length === 0 && exit_after_last_record) {
187
+ return {done: true, value: undefined};
188
+ }
189
+ else {
190
+ const record = records.shift()
191
+ return {done: false, value: record};
192
+ }
193
+ }
194
+ };
195
+ }
54
196
  }
@@ -1,18 +1,19 @@
1
1
  import { extraBodyOptions, recordObject } from "../types.js";
2
2
  import { RecordBase } from "./recordBase.js";
3
3
  import { Portal } from "./portal.js";
4
- import { PortalInterface } from "../layouts/layoutInterface.js";
5
- import { RecordFieldsMap } from "../layouts/recordFieldsMap";
6
- import { LayoutRecordBase } from "./layoutRecordBase";
7
- export declare class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> implements LayoutRecordBase {
8
- portals: P;
9
- constructor(layout: any, recordId: any, modId?: any, fieldData?: {}, portalData?: any);
4
+ import { LayoutInterface } from "../layouts/layoutInterface.js";
5
+ import { LayoutRecordBase } from "./layoutRecordBase.js";
6
+ import { LayoutBase } from "../layouts/layoutBase.js";
7
+ export declare class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = string> extends RecordBase<LAYOUT["fields"]> implements LayoutRecordBase {
8
+ portals: Pick<LAYOUT["portals"], PORTALS_TO_INCLUDE>;
9
+ private readonly portalsToInclude;
10
+ constructor(layout: LayoutBase, recordId: number | string, modId?: string | number, fieldData?: Record<string, string | number>, portalData?: any, portalsToInclude?: PORTALS_TO_INCLUDE[]);
10
11
  get portalsArray(): Portal<any>[];
11
12
  commit(extraBody?: extraBodyOptions): Promise<this>;
12
13
  protected processPortalData(portalData: any): void;
13
14
  get(): Promise<this>;
14
15
  getPortal(portal: any): Portal<any>;
15
- duplicate(): Promise<LayoutRecord<T, P>>;
16
+ duplicate(): Promise<LayoutRecord<LAYOUT>>;
16
17
  delete(): Promise<void>;
17
18
  toObject(filter?: (a: any) => any, portalFilter?: (a: any) => any, portalRowFilter?: (a: any) => any, portalFieldFilter?: (a: any) => any): recordObject;
18
19
  }
@@ -1,25 +1,18 @@
1
1
  /*
2
- * Copyright (c) 2023. See LICENSE file for more information
2
+ * Copyright (c) 2023-2024. 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 {
18
- constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
9
+ // @ts-ignore
10
+ portals = {};
11
+ portalsToInclude;
12
+ constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null, portalsToInclude = []) {
19
13
  super(layout, recordId, modId);
20
- // @ts-ignore
21
- this.portals = {};
22
14
  this.processFieldData(fieldData);
15
+ this.portalsToInclude = portalsToInclude;
23
16
  if (portalData) {
24
17
  this.processPortalData(portalData);
25
18
  }
@@ -27,76 +20,61 @@ export class LayoutRecord extends RecordBase {
27
20
  get portalsArray() {
28
21
  return Object.values(this.portals);
29
22
  }
30
- commit(extraBody = {}) {
31
- let trace = new Error();
32
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
33
- var _a, _b, _c;
34
- let data = this.toObject();
35
- delete data.recordId;
36
- delete data.modId;
37
- if ((_a = extraBody.scripts) === null || _a === void 0 ? void 0 : _a.after) {
38
- data["script"] = extraBody.scripts.after.name;
39
- if (extraBody.scripts.after.parameter)
40
- data["script.param"] = extraBody.scripts.after.parameter;
41
- }
42
- if ((_b = extraBody.scripts) === null || _b === void 0 ? void 0 : _b.prerequest) {
43
- data["script.prerequest"] = extraBody.scripts.after.name;
44
- if (extraBody.scripts.prerequest.parameter)
45
- data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter;
46
- }
47
- if ((_c = extraBody.scripts) === null || _c === void 0 ? void 0 : _c.presort) {
48
- data["script.presort"] = extraBody.scripts.presort.name;
49
- if (extraBody.scripts.presort.parameter)
50
- data["script.presort.param"] = extraBody.scripts.presort.parameter;
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, {
23
+ async commit(extraBody = {}) {
24
+ let data = this.toObject();
25
+ delete data.recordId;
26
+ delete data.modId;
27
+ if (extraBody.scripts?.after) {
28
+ data["script"] = extraBody.scripts.after.name;
29
+ if (extraBody.scripts.after.parameter)
30
+ data["script.param"] = extraBody.scripts.after.parameter;
31
+ }
32
+ if (extraBody.scripts?.prerequest) {
33
+ data["script.prerequest"] = extraBody.scripts.after.name;
34
+ if (extraBody.scripts.prerequest.parameter)
35
+ data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter;
36
+ }
37
+ if (extraBody.scripts?.presort) {
38
+ data["script.presort"] = extraBody.scripts.presort.name;
39
+ if (extraBody.scripts.presort.parameter)
40
+ data["script.presort.param"] = extraBody.scripts.presort.parameter;
41
+ }
42
+ if (this.recordId === -1) {
43
+ // This is a new LayoutRecord
44
+ let res = await this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
79
45
  port: 443,
80
- method: "PATCH",
46
+ method: "POST",
81
47
  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
48
  });
99
- }));
49
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
50
+ throw new FMError(res.response.scriptError, res.httpStatus, res);
51
+ }
52
+ else if (res.messages[0].code === "0") {
53
+ this.recordId = parseInt(res.response.recordId);
54
+ this.modId = parseInt(res.response.modId);
55
+ return this;
56
+ }
57
+ else {
58
+ throw new FMError(res.messages[0].code, res.httpStatus, res);
59
+ }
60
+ }
61
+ // for (let item of Object.keys(data)) extraBody[item] = data[item]
62
+ let res = await this.layout.database.apiRequest(this.endpoint, {
63
+ port: 443,
64
+ method: "PATCH",
65
+ body: JSON.stringify(data)
66
+ });
67
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
68
+ throw new FMError(res.response.scriptError, res.httpStatus, res);
69
+ }
70
+ else if (res.messages[0].code === "0") {
71
+ this.modId = +res.response.modId;
72
+ this._onSave();
73
+ return this;
74
+ }
75
+ else {
76
+ throw new FMError(res.messages[0].code, res.httpStatus, res);
77
+ }
100
78
  }
101
79
  processPortalData(portalData) {
102
80
  for (let portalName of Object.keys(portalData)) {
@@ -111,89 +89,65 @@ export class LayoutRecord extends RecordBase {
111
89
  this.portals[portalName] = _portal;
112
90
  }
113
91
  }
114
- get() {
92
+ async get() {
115
93
  let trace = new Error();
116
94
  if (this.recordId === -1) {
117
95
  throw "Cannot get this RecordBase until a commit() is done.";
118
96
  }
119
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
120
- if (!this.layout.metadata)
121
- yield this.layout.getLayoutMeta();
122
- this.layout.database.apiRequest(this.endpoint, {
123
- port: 443,
124
- 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
- });
143
- }));
97
+ if (!this.layout.metadata)
98
+ await this.layout.getLayoutMeta();
99
+ let res = await this.layout.database.apiRequest(this.endpoint, {
100
+ port: 443,
101
+ method: "GET"
102
+ });
103
+ if (res.messages[0].code === "0") {
104
+ // console.log(res, res.response.data)
105
+ this.modId = +res.response.data[0].modId;
106
+ this.processFieldData(res.response.data[0].fieldData);
107
+ this.portalData = [];
108
+ if (res.response.data[0].portalData)
109
+ this.processPortalData(res.response.data[0].portalData);
110
+ return this;
111
+ }
144
112
  }
145
113
  getPortal(portal) {
146
114
  return this.portalsArray.find(p => p.name === portal);
147
115
  }
148
- duplicate() {
116
+ async duplicate() {
149
117
  let trace = new Error();
150
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
151
- this.layout.database.apiRequest(this.endpoint, {
152
- port: 443,
153
- 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
- });
172
- }));
118
+ let res = await this.layout.database.apiRequest(this.endpoint, {
119
+ port: 443,
120
+ method: "POST"
121
+ });
122
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
123
+ throw new FMError(res.response.scriptError, res.httpStatus, res, trace);
124
+ }
125
+ else if (res.messages[0].code === "0") {
126
+ let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false);
127
+ let _res = new LayoutRecord(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData);
128
+ this.emit("duplicated");
129
+ return _res;
130
+ }
131
+ else {
132
+ throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
133
+ }
173
134
  }
174
- delete() {
175
- let trace = new Error();
176
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
177
- this.layout.database.apiRequest(this.endpoint, {
178
- port: 443,
179
- 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
- });
196
- }));
135
+ async delete() {
136
+ let res = await this.layout.database.apiRequest(this.endpoint, {
137
+ port: 443,
138
+ method: "DELETE"
139
+ });
140
+ console.log(res);
141
+ if (typeof res.response?.scriptError !== "undefined" && res.response?.scriptError !== '0') {
142
+ throw new FMError(res.response.scriptError, res.httpStatus, res);
143
+ }
144
+ else if (res.messages[0].code === "0") {
145
+ this.emit("deleted");
146
+ return;
147
+ }
148
+ else {
149
+ throw new FMError(res.messages[0].code, res.httpStatus, res);
150
+ }
197
151
  }
198
152
  toObject(filter = (a) => a.edited, portalFilter = (a) => a.records.find(record => record.edited), portalRowFilter = (a) => a.edited, portalFieldFilter = (a) => a.edited) {
199
153
  let obj = super.toObject(filter, portalFilter, portalRowFilter, portalFieldFilter);