@jd-data-limited/easy-fm 1.0.0-alpha1 → 1.0.1-alpha1

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.
@@ -0,0 +1,6 @@
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>
@@ -0,0 +1,7 @@
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/easy-fm.iml CHANGED
@@ -1,8 +1,8 @@
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>
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
8
  </module>
@@ -0,0 +1,6 @@
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 CHANGED
@@ -1,8 +1,8 @@
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>
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
8
  </project>
package/.idea/vcs.xml CHANGED
@@ -1,6 +1,6 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
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
6
  </project>
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 JD-Data-Limited
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 JD-Data-Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,212 +1,212 @@
1
- # easy-fm
2
-
3
- easy-fm is a Node.js module that allows you to interact with
4
- a [FileMaker database](https://www.claris.com/filemaker/) stored on
5
- a [FileMaker server](https://www.claris.com/filemaker/server/). This module interacts with your server using the
6
- [FileMaker Data API](https://help.claris.com/en/data-api-guide/content/index.html).
7
-
8
- ## FileMaker setup instructions
9
-
10
- 1. Enable the FileMaker Data API from the server's admin console. This setting is located
11
- in `Connectors > FileMaker Data API`.
12
- 2. Create a FileMaker database account for easy-fm to use. This account must have the 'Access via FileMaker Data API (
13
- fmrest)' extended privilege
14
-
15
- ---
16
-
17
- ## Table of contents
18
-
19
- 1. [Connecting to a database](#connecting-to-a-database)
20
- 2. [Working with records](#working-with-records)
21
- 3. [Performing find requests](#perform-find-requests)
22
- 4. [Scripts](#scripts)
23
- 5. [Index](#index)
24
-
25
- ---
26
-
27
- ## Connecting to a database
28
-
29
- easy-fm currently does not support connecting to external data sources, or authenticating by any method other than plain
30
- FileMaker authentication.
31
-
32
- ```javascript
33
- import fm, {FMError} from "easy-fm"; // Import the module
34
- const connection = new fm(); // This variable will be used for interacting with the server
35
-
36
- connection.login(hostname, database, username, password).then(async token => { // Login
37
-
38
- })
39
- ```
40
-
41
- ---
42
-
43
- ## Working with records
44
-
45
- When running scripts or interacting with records, the first step that you need to do is get the layout that you want to
46
- use
47
-
48
- ```javascript
49
- let layout = connection.getLayout("layout1") // Get the layout known as 'layout1'
50
- ```
51
-
52
- Once you have the layout, you can perform a multitude of tasks
53
-
54
- ### Get a single record using its RecordID
55
-
56
- [What's a RecordID?](#recordid)
57
-
58
- ```javascript
59
- let record_id = 1
60
- let record = layout.getRecord(record_id)
61
-
62
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
63
-
64
- let field = record.getField("field1")
65
- console.log(field.value) // Get the value of 'field1'
66
- ```
67
-
68
- ### Modify a record
69
-
70
- WARNING: The commit step is mandatory. Otherwise the changes will never be uploaded
71
-
72
- ```javascript
73
- let record_id = 1
74
- let record = layout.getRecord(record_id)
75
-
76
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
77
- record.getField("field1").set("This is a value")
78
- record.getField("field2").set("This is also a value")
79
- await record.commit()
80
- ```
81
-
82
- ### Create a new record
83
-
84
- WARNING: The record is not created on the database until a commit is done
85
-
86
- ```javascript
87
- let record = await layout.createRecord()
88
- record.getField("field1").set("ABC")
89
- record.getField("field2").set("DEF")
90
- await record.commit()
91
- ```
92
-
93
- ### Downloading container field files
94
-
95
- ```javascript
96
- let record_id = 1
97
- let record = layout.getRecord(record_id)
98
-
99
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
100
-
101
- let container = record.getField("container")
102
- container.download().then(stream => {
103
- // Returns an IncomingMessage, which is an extension of ReadableStream
104
- })
105
- ```
106
-
107
- [IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
108
- , [ReadableStream](https://nodejs.org/api/stream.html#class-streamreadable)
109
-
110
- ### Uploading container files
111
-
112
- When uploading files, they should be uploaded as a [Buffer](https://nodejs.org/api/buffer.html) object, along with a
113
- filename (string) and MIME (also string)
114
-
115
- MIME types are not currently automatically detected
116
-
117
- ```javascript
118
- const fs = require("fs")
119
- let filename = "image.jpg"
120
- let buffer = fs.readdirSync("./" + filename)
121
- let mime = "image/jpeg"
122
-
123
- let record_id = 1
124
- let record = layout.getRecord(record_id)
125
- await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
126
-
127
- let container = record.getField("container")
128
- container.upload(buffer, filename, mime).then(() => {
129
- console.log("UPLOAD SUCCESSFUL!")
130
- })
131
- ```
132
- [(Mozilla) Common MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
133
-
134
- ### Read and modify portal information
135
-
136
- To be able to read portal information for a record, you'll need to put a portal on the layout you are using. Make sure
137
- you also:
138
-
139
- - Give the portal object a name
140
- - Include the exact fields you need in the portal. Any fields you leave out will not be accessible by node.js, and
141
- putting extra fields in is not a good idea.
142
-
143
- ```javascript
144
- let record = layout.getRecord(1)
145
-
146
- // Portal data is downloaded when the record is fetched
147
- await record.get()
148
- let portal = record.getPortal("Portal1")
149
-
150
- for (let _record of portal.records) {
151
- // Runs for all records in the portal
152
- let field = _record.getField("field2")
153
- console.log(field.value)
154
- field.set("GHI")
155
- }
156
- ```
157
-
158
- **WARNING**: Commiting a related portal record will also commit any changes to the parent record as well as any other
159
- portal records.
160
-
161
- ---
162
-
163
- ## Perform find requests
164
-
165
- Performing find requests is one of the most common database operations
166
-
167
- ![img.png](img.png)
168
-
169
- The image above is how the find request would look when doing it in a FileMaker script. This should hopefully help you
170
- understand how the find request process works.
171
-
172
- ```javascript
173
- let find = layout.newFind() // Create a new find operation
174
-
175
- find.addRequests( // Specify the find criteria
176
- {"PrimaryKey": "AAAAA", "ModifiedBy": "BBBB"},
177
- {"CreatedBy": "BBBB"}
178
- )
179
-
180
- find.addSort("CreatedBy", "ascend") // Sort the results in ascending order
181
- let records = await find.find() // Perform the find
182
- console.log(records)
183
- ```
184
-
185
- ---
186
-
187
- ### Scripts
188
-
189
- Running scripts is another operation you may need to do regularly. This one is fairly straight-forward in how it works
190
-
191
- ```javascript
192
- let layout = connection.getLayout("layout1")
193
- let script = connection.script("MyFileMakerScript", "This is a parameter")
194
- let result = await layout.runScript(script)
195
- console.log(result)
196
- ```
197
-
198
- ---
199
-
200
- ## Classes and methods
201
-
202
-
203
-
204
-
205
- ---
206
-
207
- ## Index
208
-
209
- ### RecordID
210
-
211
- This is not a custom field that can be set and/or changed. You can get a record's ID from within FileMaker by
1
+ # easy-fm
2
+
3
+ easy-fm is a Node.js module that allows you to interact with
4
+ a [FileMaker database](https://www.claris.com/filemaker/) stored on
5
+ a [FileMaker server](https://www.claris.com/filemaker/server/). This module interacts with your server using the
6
+ [FileMaker Data API](https://help.claris.com/en/data-api-guide/content/index.html).
7
+
8
+ ## FileMaker setup instructions
9
+
10
+ 1. Enable the FileMaker Data API from the server's admin console. This setting is located
11
+ in `Connectors > FileMaker Data API`.
12
+ 2. Create a FileMaker database account for easy-fm to use. This account must have the 'Access via FileMaker Data API (
13
+ fmrest)' extended privilege
14
+
15
+ ---
16
+
17
+ ## Table of contents
18
+
19
+ 1. [Connecting to a database](#connecting-to-a-database)
20
+ 2. [Working with records](#working-with-records)
21
+ 3. [Performing find requests](#perform-find-requests)
22
+ 4. [Scripts](#scripts)
23
+ 5. [Index](#index)
24
+
25
+ ---
26
+
27
+ ## Connecting to a database
28
+
29
+ easy-fm currently does not support connecting to external data sources, or authenticating by any method other than plain
30
+ FileMaker authentication.
31
+
32
+ ```javascript
33
+ import fm, {FMError} from "easy-fm"; // Import the module
34
+ const connection = new fm(); // This variable will be used for interacting with the server
35
+
36
+ connection.login(hostname, database, username, password).then(async token => { // Login
37
+
38
+ })
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Working with records
44
+
45
+ When running scripts or interacting with records, the first step that you need to do is get the layout that you want to
46
+ use
47
+
48
+ ```javascript
49
+ let layout = connection.getLayout("layout1") // Get the layout known as 'layout1'
50
+ ```
51
+
52
+ Once you have the layout, you can perform a multitude of tasks
53
+
54
+ ### Get a single record using its RecordID
55
+
56
+ [What's a RecordID?](#recordid)
57
+
58
+ ```javascript
59
+ let record_id = 1
60
+ let record = layout.getRecord(record_id)
61
+
62
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
63
+
64
+ let field = record.getField("field1")
65
+ console.log(field.value) // Get the value of 'field1'
66
+ ```
67
+
68
+ ### Modify a record
69
+
70
+ WARNING: The commit step is mandatory. Otherwise the changes will never be uploaded
71
+
72
+ ```javascript
73
+ let record_id = 1
74
+ let record = layout.getRecord(record_id)
75
+
76
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
77
+ record.getField("field1").set("This is a value")
78
+ record.getField("field2").set("This is also a value")
79
+ await record.commit()
80
+ ```
81
+
82
+ ### Create a new record
83
+
84
+ WARNING: The record is not created on the database until a commit is done
85
+
86
+ ```javascript
87
+ let record = await layout.createRecord()
88
+ record.getField("field1").set("ABC")
89
+ record.getField("field2").set("DEF")
90
+ await record.commit()
91
+ ```
92
+
93
+ ### Downloading container field files
94
+
95
+ ```javascript
96
+ let record_id = 1
97
+ let record = layout.getRecord(record_id)
98
+
99
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
100
+
101
+ let container = record.getField("container")
102
+ container.download().then(stream => {
103
+ // Returns an IncomingMessage, which is an extension of ReadableStream
104
+ })
105
+ ```
106
+
107
+ [IncomingMessage](https://nodejs.org/api/http.html#class-httpincomingmessage)
108
+ , [ReadableStream](https://nodejs.org/api/stream.html#class-streamreadable)
109
+
110
+ ### Uploading container files
111
+
112
+ When uploading files, they should be uploaded as a [Buffer](https://nodejs.org/api/buffer.html) object, along with a
113
+ filename (string) and MIME (also string)
114
+
115
+ MIME types are not currently automatically detected
116
+
117
+ ```javascript
118
+ const fs = require("fs")
119
+ let filename = "image.jpg"
120
+ let buffer = fs.readdirSync("./" + filename)
121
+ let mime = "image/jpeg"
122
+
123
+ let record_id = 1
124
+ let record = layout.getRecord(record_id)
125
+ await record.get() // The 'getRecord' method does not automatically get that record's values, so this step does that instead
126
+
127
+ let container = record.getField("container")
128
+ container.upload(buffer, filename, mime).then(() => {
129
+ console.log("UPLOAD SUCCESSFUL!")
130
+ })
131
+ ```
132
+ [(Mozilla) Common MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
133
+
134
+ ### Read and modify portal information
135
+
136
+ To be able to read portal information for a record, you'll need to put a portal on the layout you are using. Make sure
137
+ you also:
138
+
139
+ - Give the portal object a name
140
+ - Include the exact fields you need in the portal. Any fields you leave out will not be accessible by node.js, and
141
+ putting extra fields in is not a good idea.
142
+
143
+ ```javascript
144
+ let record = layout.getRecord(1)
145
+
146
+ // Portal data is downloaded when the record is fetched
147
+ await record.get()
148
+ let portal = record.getPortal("Portal1")
149
+
150
+ for (let _record of portal.records) {
151
+ // Runs for all records in the portal
152
+ let field = _record.getField("field2")
153
+ console.log(field.value)
154
+ field.set("GHI")
155
+ }
156
+ ```
157
+
158
+ **WARNING**: Commiting a related portal record will also commit any changes to the parent record as well as any other
159
+ portal records.
160
+
161
+ ---
162
+
163
+ ## Perform find requests
164
+
165
+ Performing find requests is one of the most common database operations
166
+
167
+ ![img.png](img.png)
168
+
169
+ The image above is how the find request would look when doing it in a FileMaker script. This should hopefully help you
170
+ understand how the find request process works.
171
+
172
+ ```javascript
173
+ let find = layout.newFind() // Create a new find operation
174
+
175
+ find.addRequests( // Specify the find criteria
176
+ {"PrimaryKey": "AAAAA", "ModifiedBy": "BBBB"},
177
+ {"CreatedBy": "BBBB"}
178
+ )
179
+
180
+ find.addSort("CreatedBy", "ascend") // Sort the results in ascending order
181
+ let records = await find.find() // Perform the find
182
+ console.log(records)
183
+ ```
184
+
185
+ ---
186
+
187
+ ### Scripts
188
+
189
+ Running scripts is another operation you may need to do regularly. This one is fairly straight-forward in how it works
190
+
191
+ ```javascript
192
+ let layout = connection.getLayout("layout1")
193
+ let script = connection.script("MyFileMakerScript", "This is a parameter")
194
+ let result = await layout.runScript(script)
195
+ console.log(result)
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Classes and methods
201
+
202
+
203
+
204
+
205
+ ---
206
+
207
+ ## Index
208
+
209
+ ### RecordID
210
+
211
+ This is not a custom field that can be set and/or changed. You can get a record's ID from within FileMaker by
212
212
  using `Get(RecordID)`
package/decs.d.ts CHANGED
@@ -1,7 +1,7 @@
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"
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
7
  declare module "buffer"