@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.
Files changed (65) hide show
  1. package/package.json +10 -6
  2. package/src/FMError.d.ts +1 -1
  3. package/src/FMError.js +5 -0
  4. package/src/FMError.ts +1 -1
  5. package/src/connection/FMHost.d.ts +1 -1
  6. package/src/connection/FMHost.js +36 -45
  7. package/src/connection/FMHost.ts +3 -3
  8. package/src/connection/database.d.ts +5 -3
  9. package/src/connection/database.js +90 -112
  10. package/src/connection/database.ts +70 -82
  11. package/src/connection/databaseBase.d.ts +4 -1
  12. package/src/connection/databaseBase.ts +4 -1
  13. package/src/layouts/layout.d.ts +3 -3
  14. package/src/layouts/layout.js +26 -50
  15. package/src/layouts/layout.ts +22 -39
  16. package/src/layouts/layoutBase.d.ts +2 -2
  17. package/src/layouts/layoutBase.ts +2 -1
  18. package/src/layouts/layoutRecordManager.d.ts +1 -1
  19. package/src/layouts/layoutRecordManager.js +16 -31
  20. package/src/layouts/layoutRecordManager.ts +14 -30
  21. package/src/models/apiResults.d.ts +103 -0
  22. package/src/models/apiResults.js +28 -0
  23. package/src/models/apiResults.ts +112 -0
  24. package/src/records/field.d.ts +3 -2
  25. package/src/records/field.js +44 -68
  26. package/src/records/field.ts +46 -64
  27. package/src/records/getOperations/find.js +18 -38
  28. package/src/records/getOperations/find.ts +17 -28
  29. package/src/records/getOperations/recordGetOperation.js +7 -4
  30. package/src/records/getOperations/recordGetOperation.ts +1 -1
  31. package/src/records/getOperations/recordGetRange.js +16 -34
  32. package/src/records/getOperations/recordGetRange.ts +17 -24
  33. package/src/records/layoutRecord.js +103 -151
  34. package/src/records/layoutRecord.ts +101 -133
  35. package/src/records/portal.js +3 -0
  36. package/src/records/portalRecord.js +2 -1
  37. package/src/records/recordBase.js +6 -1
  38. package/src/types.d.ts +0 -4
  39. package/src/types.ts +1 -7
  40. package/.expo/README.md +0 -15
  41. package/.expo/settings.json +0 -8
  42. package/.idea/compiler.xml +0 -7
  43. package/.idea/copyright/JD_Data.xml +0 -6
  44. package/.idea/copyright/profiles_settings.xml +0 -7
  45. package/.idea/discord.xml +0 -7
  46. package/.idea/easy-fm.iml +0 -8
  47. package/.idea/jsLibraryMappings.xml +0 -6
  48. package/.idea/modules.xml +0 -8
  49. package/.idea/php.xml +0 -18
  50. package/.idea/vcs.xml +0 -6
  51. package/decs.d.ts +0 -7
  52. package/dist/index.min.js +0 -2
  53. package/dist/index.min.js.LICENSE.txt +0 -3
  54. package/docs/classes/FileMakerConnection.md +0 -86
  55. package/docs/classes/layout.md +0 -0
  56. package/examples/test.js +0 -7
  57. package/fmErrors.json +0 -1010
  58. package/img.png +0 -0
  59. package/test.d.ts +0 -2
  60. package/test.js +0 -30
  61. package/test.ts +0 -33
  62. package/test2.d.ts +0 -1
  63. package/test2.js +0 -15
  64. package/tsconfig.json +0 -16
  65. package/webpack.config.cjs +0 -20
@@ -10,6 +10,7 @@ import {PortalInterface} from "../layouts/layoutInterface.js";
10
10
  import {FMError} from "../FMError.js";
11
11
  import {RecordFieldsMap} from "../layouts/recordFieldsMap";
12
12
  import {LayoutRecordBase} from "./layoutRecordBase";
13
+ import {ApiRecordResponseObj, ApiResultSetObj} from "../models/apiResults";
13
14
 
14
15
  export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface> extends RecordBase<T> implements LayoutRecordBase {
15
16
  // @ts-ignore
@@ -27,77 +28,68 @@ export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface>
27
28
  return Object.values(this.portals)
28
29
  }
29
30
 
30
- commit(extraBody: extraBodyOptions = {}): Promise<this> {
31
- let trace = new Error()
32
- return new Promise(async (resolve, reject) => {
33
- let data = this.toObject()
34
- delete data.recordId
35
- delete data.modId
36
-
37
- if (extraBody.scripts?.after) {
38
- data["script"] = extraBody.scripts.after.name
39
- if (extraBody.scripts.after.parameter) data["script.param"] = extraBody.scripts.after.parameter
40
- }
41
- if (extraBody.scripts?.prerequest) {
42
- data["script.prerequest"] = extraBody.scripts.after.name
43
- if (extraBody.scripts.prerequest.parameter) data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter
44
- }
45
- if (extraBody.scripts?.presort) {
46
- data["script.presort"] = extraBody.scripts.presort.name
47
- if (extraBody.scripts.presort.parameter) data["script.presort.param"] = extraBody.scripts.presort.parameter
48
- }
31
+ async commit(extraBody: extraBodyOptions = {}): Promise<this> {
32
+ let data = this.toObject()
33
+ delete data.recordId
34
+ delete data.modId
49
35
 
50
- if (this.recordId === -1) {
51
- // This is a new LayoutRecord
36
+ if (extraBody.scripts?.after) {
37
+ data["script"] = extraBody.scripts.after.name
38
+ if (extraBody.scripts.after.parameter) data["script.param"] = extraBody.scripts.after.parameter
39
+ }
40
+ if (extraBody.scripts?.prerequest) {
41
+ data["script.prerequest"] = extraBody.scripts.after.name
42
+ if (extraBody.scripts.prerequest.parameter) data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter
43
+ }
44
+ if (extraBody.scripts?.presort) {
45
+ data["script.presort"] = extraBody.scripts.presort.name
46
+ if (extraBody.scripts.presort.parameter) data["script.presort.param"] = extraBody.scripts.presort.parameter
47
+ }
52
48
 
53
- this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
49
+ if (this.recordId === -1) {
50
+ // This is a new LayoutRecord
51
+ let res = await this.layout.database.apiRequest<{ recordId: string, modId: string }>(`${this.layout.endpoint}/records`, {
54
52
  port: 443,
55
53
  method: "POST",
56
54
  body: JSON.stringify(data)
57
55
  })
58
- .then(res => {
59
- if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
60
- reject(new FMError(res.response.scriptError, res.status, res, trace))
61
- }
62
- else if (res.messages[0].code === "0") {
63
- this.recordId = parseInt(res.response.recordId)
64
- this.modId = parseInt(res.response.modId)
65
- resolve(this)
66
- }
67
- else {
68
- reject(new FMError(res.messages[0].code, res.status, res, trace))
69
- }
70
- })
71
- .catch(e => {
72
- reject(e)
73
- })
74
-
75
- return
76
- }
77
56
 
78
- // for (let item of Object.keys(data)) extraBody[item] = data[item]
79
- this.layout.database.apiRequest(this.endpoint, {
80
- port: 443,
81
- method: "PATCH",
82
- body: JSON.stringify(data)
83
- })
84
- .then(res => {
85
- if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
86
- reject(new FMError(res.response.scriptError, res.status, res, trace))
87
- }
88
- else if (res.messages[0].code === "0") {
89
- this.modId = res.response.modId
90
- this._onSave()
91
- resolve(this)
92
- }
93
- else {
94
- reject(new FMError(res.messages[0].code, res.status, res, trace))
95
- }
96
- })
97
- .catch(e => {
98
- reject(e)
99
- })
57
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
58
+ throw new FMError(res.response.scriptError, res.httpStatus, res)
59
+ }
60
+ else if (res.messages[0].code === "0") {
61
+ this.recordId = parseInt(res.response.recordId)
62
+ this.modId = parseInt(res.response.modId)
63
+ return this
64
+ }
65
+ else {
66
+ throw new FMError(res.messages[0].code, res.httpStatus, res)
67
+ }
68
+ }
69
+
70
+ // for (let item of Object.keys(data)) extraBody[item] = data[item]
71
+ let res = await this.layout.database.apiRequest<{
72
+ modId: string, newPortalRecordInfo: {
73
+ tableName: string,
74
+ recordId: string,
75
+ modId: string
76
+ }[]
77
+ }>(this.endpoint, {
78
+ port: 443,
79
+ method: "PATCH",
80
+ body: JSON.stringify(data)
100
81
  })
82
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
83
+ throw new FMError(res.response.scriptError, res.httpStatus, res)
84
+ }
85
+ else if (res.messages[0].code === "0") {
86
+ this.modId = +res.response.modId
87
+ this._onSave()
88
+ return this
89
+ }
90
+ else {
91
+ throw new FMError(res.messages[0].code, res.httpStatus, res)
92
+ }
101
93
  }
102
94
 
103
95
  protected processPortalData(portalData): void {
@@ -115,92 +107,68 @@ export class LayoutRecord<T extends RecordFieldsMap, P extends PortalInterface>
115
107
  }
116
108
  }
117
109
 
118
- get(): Promise<this> {
110
+ async get(): Promise<this> {
119
111
  let trace = new Error()
120
112
  if (this.recordId === -1) {
121
113
  throw "Cannot get this RecordBase until a commit() is done."
122
114
  }
123
- return new Promise(async (resolve, reject) => {
124
- if (!this.layout.metadata) await this.layout.getLayoutMeta()
125
-
126
- this.layout.database.apiRequest(this.endpoint, {
127
- port: 443,
128
- method: "GET"
129
- })
130
- .then(res => {
131
- if (res.messages[0].code === "0") {
132
- // console.log(res, res.response.data)
133
- this.modId = res.response.data[0].modId
134
- this.processFieldData(res.response.data[0].fieldData)
135
- this.portalData = []
136
- if (res.response.data[0].portalData) this.processPortalData(res.response.data[0].portalData)
137
- resolve(this)
138
- }
139
- else {
140
- reject(new FMError(res.messages[0].code, res.status, res, trace))
141
- }
142
- })
143
- .catch(e => {
144
- reject(e)
145
- })
115
+ if (!this.layout.metadata) await this.layout.getLayoutMeta()
116
+ let res = await this.layout.database.apiRequest<ApiRecordResponseObj>(this.endpoint, {
117
+ port: 443,
118
+ method: "GET"
146
119
  })
120
+
121
+ if (res.messages[0].code === "0") {
122
+ // console.log(res, res.response.data)
123
+ this.modId = +res.response.data[0].modId
124
+ this.processFieldData(res.response.data[0].fieldData)
125
+ this.portalData = []
126
+ if (res.response.data[0].portalData) this.processPortalData(res.response.data[0].portalData)
127
+ return this
128
+ }
147
129
  }
148
130
 
149
131
  getPortal(portal) {
150
132
  return this.portalsArray.find(p => p.name === portal)
151
133
  }
152
134
 
153
- duplicate(): Promise<LayoutRecord<T,P>> {
135
+ async duplicate(): Promise<LayoutRecord<T, P>> {
154
136
  let trace = new Error()
155
- return new Promise(async (resolve, reject) => {
156
- this.layout.database.apiRequest(this.endpoint, {
157
- port: 443,
158
- method: "POST"
159
- })
160
- .then(res => {
161
- if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
162
- reject(new FMError(res.response.scriptError, res.status, res, trace))
163
- }
164
- else if (res.messages[0].code === "0") {
165
- let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false)
166
- let _res = new LayoutRecord<T,P>(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData)
167
-
168
- this.emit("duplicated")
169
- resolve(_res)
170
- }
171
- else {
172
- reject(new FMError(res.messages[0].code, res.status, res, trace))
173
- }
174
- })
175
- .catch(e => {
176
- reject(e)
177
- })
137
+ let res = await this.layout.database.apiRequest<{recordId: string, modId: string}>(this.endpoint, {
138
+ port: 443,
139
+ method: "POST"
178
140
  })
141
+ if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
142
+ throw new FMError(res.response.scriptError, res.httpStatus, res, trace)
143
+ }
144
+ else if (res.messages[0].code === "0") {
145
+ let data = this.toObject((a) => true, (a) => true, (a) => false, (a) => false)
146
+ let _res = new LayoutRecord<T, P>(this.layout, res.response.recordId, res.response.modId, data.fieldData, data.portalData)
147
+
148
+ this.emit("duplicated")
149
+ return _res
150
+ }
151
+ else {
152
+ throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
153
+ }
179
154
  }
180
155
 
181
- delete(): Promise<void> {
182
- let trace = new Error()
183
- return new Promise(async (resolve, reject) => {
184
- this.layout.database.apiRequest(this.endpoint, {
185
- port: 443,
186
- method: "DELETE"
187
- })
188
- .then(res => {
189
- if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
190
- reject(new FMError(res.response.scriptError, res.status, res, trace))
191
- }
192
- else if (res.messages[0].code === "0") {
193
- this.emit("deleted")
194
- resolve()
195
- }
196
- else {
197
- reject(new FMError(res.messages[0].code, res.status, res, trace))
198
- }
199
- })
200
- .catch(e => {
201
- reject(e)
202
- })
156
+ async delete(): Promise<void> {
157
+ let res = await this.layout.database.apiRequest(this.endpoint, {
158
+ port: 443,
159
+ method: "DELETE"
203
160
  })
161
+ console.log(res)
162
+ if (typeof res.response?.scriptError !== "undefined" && res.response?.scriptError !== '0') {
163
+ throw new FMError(res.response.scriptError, res.httpStatus, res)
164
+ }
165
+ else if (res.messages[0].code === "0") {
166
+ this.emit("deleted")
167
+ return
168
+ }
169
+ else {
170
+ throw new FMError(res.messages[0].code, res.httpStatus, res)
171
+ }
204
172
  }
205
173
 
206
174
  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 {
@@ -3,6 +3,9 @@
3
3
  */
4
4
  import { PortalRecord } from "./portalRecord.js";
5
5
  export class Portal {
6
+ record;
7
+ name;
8
+ records;
6
9
  constructor(record, name) {
7
10
  this.record = record;
8
11
  this.name = name;
@@ -3,9 +3,10 @@
3
3
  */
4
4
  import { RecordBase, RecordTypes } from "./recordBase.js";
5
5
  export class PortalRecord extends RecordBase {
6
+ portal;
7
+ type = RecordTypes.PORTAL;
6
8
  constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
7
9
  super(record.layout, recordId, modId);
8
- this.type = RecordTypes.PORTAL;
9
10
  this.portal = portal;
10
11
  this.processFieldData(fieldData);
11
12
  }
@@ -11,9 +11,14 @@ export var RecordTypes;
11
11
  RecordTypes[RecordTypes["PORTAL"] = 2] = "PORTAL";
12
12
  })(RecordTypes || (RecordTypes = {}));
13
13
  export class RecordBase extends EventEmitter {
14
+ layout;
15
+ type = RecordTypes.UNKNOWN;
16
+ recordId;
17
+ modId;
18
+ fields;
19
+ portalData;
14
20
  constructor(layout, recordId, modId = recordId) {
15
21
  super();
16
- this.type = RecordTypes.UNKNOWN;
17
22
  this.layout = layout;
18
23
  this.recordId = recordId;
19
24
  this.modId = modId;
package/src/types.d.ts CHANGED
@@ -65,10 +65,6 @@ export interface recordObject {
65
65
  fieldData: any;
66
66
  portalData?: portalDataObject;
67
67
  }
68
- export interface fileMakerResponse {
69
- response: any;
70
- messages: any[];
71
- }
72
68
  export interface portalDataObject {
73
69
  [key: string]: recordObject;
74
70
  }
package/src/types.ts CHANGED
@@ -83,11 +83,6 @@ export interface recordObject {
83
83
  portalData?: portalDataObject
84
84
  }
85
85
 
86
- export interface fileMakerResponse {
87
- response: any,
88
- messages: any[]
89
- }
90
-
91
86
  export interface portalDataObject {
92
87
  [key: string]: recordObject
93
88
  }
@@ -152,5 +147,4 @@ export interface AuthorizationHeadersOAuth {
152
147
  "Content-Type": "application/json"
153
148
  "X-FM-Data-OAuth-RequestId": string,
154
149
  "X-FM-Data-OAuth-Identifier": string
155
- }
156
-
150
+ }
package/.expo/README.md DELETED
@@ -1,15 +0,0 @@
1
- > Why do I have a folder named ".expo" in my project?
2
-
3
- The ".expo" folder is created when an Expo project is started using "expo start" command.
4
-
5
- > What do the files contain?
6
-
7
- - "devices.json": contains information about devices that have recently opened this project. This is used to populate the "Development sessions" list in your development builds.
8
- - "packager-info.json": contains port numbers and process PIDs that are used to serve the application to the mobile device/simulator.
9
- - "settings.json": contains the server configuration that is used to serve the application manifest.
10
-
11
- > Should I commit the ".expo" folder?
12
-
13
- No, you should not share the ".expo" folder. It does not contain any information that is relevant for other developers working on the project, it is specific to your machine.
14
-
15
- Upon project creation, the ".expo" folder is already added to your ".gitignore" file.
@@ -1,8 +0,0 @@
1
- {
2
- "hostType": "lan",
3
- "lanType": "ip",
4
- "dev": true,
5
- "minify": false,
6
- "urlRandomness": null,
7
- "https": false
8
- }
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="TypeScriptCompiler">
4
- <option name="recompileOnChanges" value="true" />
5
- <option name="versionType" value="EMBEDDED" />
6
- </component>
7
- </project>
@@ -1,6 +0,0 @@
1
- <component name="CopyrightManager">
2
- <copyright>
3
- <option name="notice" value="Copyright (c) &amp;#36;originalComment.match(&quot;Copyright \(c\) (\d+)&quot;, 1, &quot;-&quot;, &quot;&amp;#36;today.year&quot;)&amp;#36;today.year. See LICENSE file for more information" />
4
- <option name="myName" value="JD-Data" />
5
- </copyright>
6
- </component>
@@ -1,7 +0,0 @@
1
- <component name="CopyrightManager">
2
- <settings default="JD-Data">
3
- <module2copyright>
4
- <element module="Project Files" copyright="JD-Data" />
5
- </module2copyright>
6
- </settings>
7
- </component>
package/.idea/discord.xml DELETED
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="DiscordProjectSettings">
4
- <option name="show" value="ASK" />
5
- <option name="description" value="" />
6
- </component>
7
- </project>
package/.idea/easy-fm.iml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$" />
5
- <orderEntry type="inheritedJdk" />
6
- <orderEntry type="sourceFolder" forTests="false" />
7
- </component>
8
- </module>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptLibraryMappings">
4
- <includedPredefinedLibrary name="Node.js Core" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/easy-fm.iml" filepath="$PROJECT_DIR$/.idea/easy-fm.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/php.xml DELETED
@@ -1,18 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="MessDetectorOptionsConfiguration">
4
- <option name="transferred" value="true" />
5
- </component>
6
- <component name="PHPCSFixerOptionsConfiguration">
7
- <option name="transferred" value="true" />
8
- </component>
9
- <component name="PHPCodeSnifferOptionsConfiguration">
10
- <option name="transferred" value="true" />
11
- </component>
12
- <component name="PhpStanOptionsConfiguration">
13
- <option name="transferred" value="true" />
14
- </component>
15
- <component name="PsalmOptionsConfiguration">
16
- <option name="transferred" value="true" />
17
- </component>
18
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>
package/decs.d.ts DELETED
@@ -1,7 +0,0 @@
1
- declare module "fs"
2
- declare module "events"
3
- declare module "path"
4
- declare module "url"
5
- declare module "node-fetch"
6
- declare module "btoa"
7
- declare module "buffer"