@nesgarbo/node-jt400 5.4.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.
- package/LICENSE +20 -0
- package/README.md +511 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/integration-test/call-rpg-spec.d.ts +1 -0
- package/dist/integration-test/call-rpg-spec.js +88 -0
- package/dist/integration-test/call-rpg-spec.js.map +1 -0
- package/dist/integration-test/dataq-spec.d.ts +1 -0
- package/dist/integration-test/dataq-spec.js +42 -0
- package/dist/integration-test/dataq-spec.js.map +1 -0
- package/dist/integration-test/db.d.ts +2 -0
- package/dist/integration-test/db.js +8 -0
- package/dist/integration-test/db.js.map +1 -0
- package/dist/integration-test/db2-connect-spec.d.ts +1 -0
- package/dist/integration-test/db2-connect-spec.js +34 -0
- package/dist/integration-test/db2-connect-spec.js.map +1 -0
- package/dist/integration-test/db2-pool-spec.d.ts +1 -0
- package/dist/integration-test/db2-pool-spec.js +191 -0
- package/dist/integration-test/db2-pool-spec.js.map +1 -0
- package/dist/integration-test/ifs-spec.d.ts +1 -0
- package/dist/integration-test/ifs-spec.js +118 -0
- package/dist/integration-test/ifs-spec.js.map +1 -0
- package/dist/integration-test/msgf-spec.d.ts +1 -0
- package/dist/integration-test/msgf-spec.js +25 -0
- package/dist/integration-test/msgf-spec.js.map +1 -0
- package/dist/integration-test/msgq-spec.d.ts +1 -0
- package/dist/integration-test/msgq-spec.js +34 -0
- package/dist/integration-test/msgq-spec.js.map +1 -0
- package/dist/java/JT400.d.ts +77 -0
- package/dist/java/JT400.js +3 -0
- package/dist/java/JT400.js.map +1 -0
- package/dist/java/index.d.ts +11 -0
- package/dist/java/index.js +45 -0
- package/dist/java/index.js.map +1 -0
- package/dist/lib/baseConnection.d.ts +5 -0
- package/dist/lib/baseConnection.js +264 -0
- package/dist/lib/baseConnection.js.map +1 -0
- package/dist/lib/baseConnection.types.d.ts +53 -0
- package/dist/lib/baseConnection.types.js +7 -0
- package/dist/lib/baseConnection.types.js.map +1 -0
- package/dist/lib/connection.d.ts +13 -0
- package/dist/lib/connection.js +143 -0
- package/dist/lib/connection.js.map +1 -0
- package/dist/lib/connection.types.d.ts +77 -0
- package/dist/lib/connection.types.js +3 -0
- package/dist/lib/connection.types.js.map +1 -0
- package/dist/lib/handleError.d.ts +3 -0
- package/dist/lib/handleError.js +25 -0
- package/dist/lib/handleError.js.map +1 -0
- package/dist/lib/ifs/index.d.ts +4 -0
- package/dist/lib/ifs/index.js +47 -0
- package/dist/lib/ifs/index.js.map +1 -0
- package/dist/lib/ifs/read_stream.d.ts +6 -0
- package/dist/lib/ifs/read_stream.js +33 -0
- package/dist/lib/ifs/read_stream.js.map +1 -0
- package/dist/lib/ifs/types.d.ts +16 -0
- package/dist/lib/ifs/types.js +3 -0
- package/dist/lib/ifs/types.js.map +1 -0
- package/dist/lib/ifs/write_stream.d.ts +6 -0
- package/dist/lib/ifs/write_stream.js +39 -0
- package/dist/lib/ifs/write_stream.js.map +1 -0
- package/dist/lib/inMemoryConnection.d.ts +7 -0
- package/dist/lib/inMemoryConnection.js +35 -0
- package/dist/lib/inMemoryConnection.js.map +1 -0
- package/dist/lib/insertList.d.ts +4 -0
- package/dist/lib/insertList.js +44 -0
- package/dist/lib/insertList.js.map +1 -0
- package/dist/lib/jdbcstream.d.ts +1 -0
- package/dist/lib/jdbcstream.js +50 -0
- package/dist/lib/jdbcstream.js.map +1 -0
- package/dist/lib/jdbcwritestream.d.ts +1 -0
- package/dist/lib/jdbcwritestream.js +37 -0
- package/dist/lib/jdbcwritestream.js.map +1 -0
- package/dist/lib/logger.d.ts +7 -0
- package/dist/lib/logger.js +13 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/sqlutil.d.ts +1 -0
- package/dist/lib/sqlutil.js +18 -0
- package/dist/lib/sqlutil.js.map +1 -0
- package/dist/lib/streamTransformers.d.ts +2 -0
- package/dist/lib/streamTransformers.js +30 -0
- package/dist/lib/streamTransformers.js.map +1 -0
- package/dist/unit-test/hsql-spec.d.ts +1 -0
- package/dist/unit-test/hsql-spec.js +495 -0
- package/dist/unit-test/hsql-spec.js.map +1 -0
- package/dist/unit-test/sqlutil-spec.d.ts +1 -0
- package/dist/unit-test/sqlutil-spec.js +20 -0
- package/dist/unit-test/sqlutil-spec.js.map +1 -0
- package/dist/unit-test/streamTransformers-spec.d.ts +1 -0
- package/dist/unit-test/streamTransformers-spec.js +98 -0
- package/dist/unit-test/streamTransformers-spec.js.map +1 -0
- package/java/lib/hsqldb.jar +0 -0
- package/java/lib/json-simple-1.1.1.jar +0 -0
- package/java/lib/jt400.jar +0 -0
- package/java/lib/jt400wrap.jar +0 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 jakobrun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
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, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
# node-jt400
|
|
2
|
+
|
|
3
|
+
NodeJS JT400 wrapper to connect to IBM iSeries and AS/400 systems (OS400 operating system, database like DB2, programs and filesystem).
|
|
4
|
+
|
|
5
|
+
[](https://npmjs.org/package/node-jt400)
|
|
6
|
+
|
|
7
|
+
## About
|
|
8
|
+
|
|
9
|
+
This package is built on the IBM Toolbox for Java (http://jt400.sourceforge.net/). It maps the java functions to node using node-java. Not all of the Java code has been mapped over to node. The reason is that this module was originally written for internal use-only for Tryggingadmidstodin. Therefore we only implemented what Tryggingamidstodin needed, for example program calls, but not stored procedures.
|
|
10
|
+
|
|
11
|
+
Tryggingamidstodin is an Icelandic insurance company dealing with legacy systems in AS400. We figured other people or companies might be dealing with the similar problems so this module was made open source. Most of the coding and documentation reflects this, although we are always trying to improve that. For example the library for programs was orignally not configurable, but is now.
|
|
12
|
+
|
|
13
|
+
We are always open to suggestions on how to improve and welcome most pull-requests.
|
|
14
|
+
|
|
15
|
+
## Changes
|
|
16
|
+
|
|
17
|
+
Check out our [changelog.md](https://github.com/tryggingamidstodin/node-jt400/blob/master/CHANGELOG.md) to see changes to this project. Please note that this changelog was added in version 4.0 so documentation on versions prior to that are incomplete. Feel free to add to this changelog and report an issue if you're having troubles with updating this package.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install node-jt400 --save
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
#### Windows
|
|
26
|
+
|
|
27
|
+
Windows installations can be tricky because of node-java dependency. Make sure that that module works first. You can [check out the node-java documentation for windows installation](https://github.com/joeferner/node-java#installation-windows)
|
|
28
|
+
|
|
29
|
+
We also have some solved issues you can take a look at like [#13](https://github.com/tryggingamidstodin/node-jt400/issues/13) and [#26](https://github.com/tryggingamidstodin/node-jt400/issues/26)
|
|
30
|
+
|
|
31
|
+
Other issues might be related to node-gyp, python and MS build tools or VS IDE.
|
|
32
|
+
|
|
33
|
+
## Configure
|
|
34
|
+
|
|
35
|
+
Most basic configuration would be:
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
const config = {
|
|
39
|
+
host: 'myhost',
|
|
40
|
+
user: 'myuser',
|
|
41
|
+
password: 'xxx',
|
|
42
|
+
}
|
|
43
|
+
const pool = require('node-jt400').pool(config)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
But the config accepts all [JT400 JDBC Properties](https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzahh/javadoc/com/ibm/as400/access/doc-files/JDBCProperties.html) so you can add other options like `translate binary`
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
const config = {
|
|
50
|
+
host: 'myhost',
|
|
51
|
+
user: 'myuser',
|
|
52
|
+
password: 'xxx',
|
|
53
|
+
'translate binary': 'true',
|
|
54
|
+
trace: 'true',
|
|
55
|
+
}
|
|
56
|
+
const pool = require('node-jt400').pool(config)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
To close the connection pool you can call `pool.close()`
|
|
60
|
+
|
|
61
|
+
### Logging
|
|
62
|
+
|
|
63
|
+
You can also pass in you preferred logger. E.g. pino:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import createLogger from 'pino'
|
|
67
|
+
import { pool } from 'node-jt400'
|
|
68
|
+
|
|
69
|
+
const config = {}
|
|
70
|
+
const options = {
|
|
71
|
+
logger: createLogger()
|
|
72
|
+
}
|
|
73
|
+
const connection = pool(config, options)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
# SQL / Database
|
|
77
|
+
|
|
78
|
+
## Query
|
|
79
|
+
|
|
80
|
+
###### Promises
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
pool
|
|
84
|
+
.query('SELECT field1, field2 FROM foo WHERE bar=? AND baz=?', [1, 'a'])
|
|
85
|
+
.then((result) => {
|
|
86
|
+
console.log('result')
|
|
87
|
+
const field1 = result[0].FIELD1
|
|
88
|
+
console.log(field1)
|
|
89
|
+
})
|
|
90
|
+
.catch((error) => {
|
|
91
|
+
console.log('error')
|
|
92
|
+
console.log(error)
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
###### Async/await
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
try {
|
|
100
|
+
const results = await pool.query(
|
|
101
|
+
'SELECT field1, field2 FROM foo WHERE bar=? AND baz=?',
|
|
102
|
+
[1, 'a']
|
|
103
|
+
)
|
|
104
|
+
console.log('result')
|
|
105
|
+
const field1 = result[0].FIELD1
|
|
106
|
+
console.log(field1)
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log('error')
|
|
109
|
+
console.log(error)
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Please note that values from the database are automatically trimmed so 'abc ' will be returned as 'abc'.
|
|
114
|
+
[Issue #27](https://github.com/tryggingamidstodin/node-jt400/issues/22)
|
|
115
|
+
To override this use the optional QueryOptions parameter to set trim to false.
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
pool.query('SELECT field1, field2 FROM foo WHERE bar=? AND baz=?', [1, 'a'], {
|
|
119
|
+
trim: false,
|
|
120
|
+
})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Update
|
|
124
|
+
|
|
125
|
+
###### Promises
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
pool.update('UPDATE foo SET bar=? WHERE baz=?', [1, 'a']).then((nUpdated) => {
|
|
129
|
+
console.log('Updated ' + nUpdated + ' rows')
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
###### Async/await
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
try {
|
|
137
|
+
const rowsUpdated = await pool.update('UPDATE foo SET bar=? WHERE baz=?', [
|
|
138
|
+
1,
|
|
139
|
+
'a',
|
|
140
|
+
])
|
|
141
|
+
console.log('rows updated')
|
|
142
|
+
console.log(rowsUpdated)
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.log('error')
|
|
145
|
+
console.log(error)
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Delete
|
|
150
|
+
|
|
151
|
+
###### Promises
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
pool
|
|
155
|
+
.update('DELETE FROM foo WHERE bar=?', [1])
|
|
156
|
+
.then(nUpdated => {
|
|
157
|
+
console.log('Deleted + ' nUpdated + ' rows');
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
###### Async/await
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
try {
|
|
165
|
+
const rowsDeleted = await pool.update('DELETE FROM foo WHERE bar=?', [1]);
|
|
166
|
+
console.log('Deleted + ' rowsDeleted + ' rows');
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
console.log('error');
|
|
170
|
+
console.log(error);
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Insert
|
|
175
|
+
|
|
176
|
+
###### Promises
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
pool
|
|
180
|
+
.insertAndGetId('INSERT INTO foo (bar, baz) VALUES(?,?)', [2, 'b'])
|
|
181
|
+
.then((id) => {
|
|
182
|
+
console.log('Inserted new row with id ' + id)
|
|
183
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
###### Async/await
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
try {
|
|
190
|
+
const id = await pool.insertAndGetId(
|
|
191
|
+
'INSERT INTO foo (bar, baz) VALUES(?,?)',
|
|
192
|
+
[2, 'b']
|
|
193
|
+
)
|
|
194
|
+
console.log('Inserted new row with id ' + id)
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.log('error')
|
|
197
|
+
console.log(error)
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Insert list
|
|
202
|
+
|
|
203
|
+
###### Promises
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
const tableName = 'foo'
|
|
207
|
+
const idColumn = 'fooid'
|
|
208
|
+
const rows = [
|
|
209
|
+
{ FIELD1: 1, FIELD2: 'a' },
|
|
210
|
+
{ FIELD1: 2, FIELD2: 'b' },
|
|
211
|
+
]
|
|
212
|
+
|
|
213
|
+
pool.insertList(tableName, idColumn, rows).then((listOfGeneratedIds) => {
|
|
214
|
+
console.log(listOfGeneratedIds)
|
|
215
|
+
})
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
###### Async/await
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
try {
|
|
222
|
+
const idList = await pool.insertList(tableName, idColumn, rows)
|
|
223
|
+
console.log(idList)
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.log('error')
|
|
226
|
+
console.log(error)
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Batch update
|
|
231
|
+
|
|
232
|
+
###### Promises
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
//insert list in one statement
|
|
236
|
+
const data = [
|
|
237
|
+
[1, 'a'],
|
|
238
|
+
[2, 'b'],
|
|
239
|
+
]
|
|
240
|
+
|
|
241
|
+
pool
|
|
242
|
+
.batchUpdate('INSERT INTO FOO (FIELD1, FIELD2) VALUES(?,?)', data)
|
|
243
|
+
.then((result) => {
|
|
244
|
+
console.log(result)
|
|
245
|
+
//result is number of updated rows for each row. [1, 1] in this case.
|
|
246
|
+
})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
###### Async/await
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
try {
|
|
253
|
+
const result = await pool.batchUpdate(
|
|
254
|
+
'INSERT INTO FOO (FIELD1, FIELD2) VALUES(?,?)',
|
|
255
|
+
data
|
|
256
|
+
)
|
|
257
|
+
console.log(result)
|
|
258
|
+
// result is the number of updated rows for each row. [1, 1] in this case.
|
|
259
|
+
} catch (error) {
|
|
260
|
+
console.log('error')
|
|
261
|
+
console.log(error)
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### SQL stream
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
pool
|
|
269
|
+
.createReadStream('SELECT FIELD1, FIELD2 FROM FOO WHERE BAR=? AND BAZ=?', [
|
|
270
|
+
1,
|
|
271
|
+
'a',
|
|
272
|
+
])
|
|
273
|
+
.pipe(JSONStream.parse([true]))
|
|
274
|
+
.pipe(pool.createWriteStream('INSERT INTO FOO2 (F1, F2) VALUES(?, ?)'))
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### asObjectStream
|
|
278
|
+
|
|
279
|
+
```javascript
|
|
280
|
+
const streamOfObjects = await pool.execute('SELECT field1, field2 FROM foo', []).then(statement => statement.asObjectStream())
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### iterable
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
const statement = await pool.execute(
|
|
287
|
+
'SELECT FIELD1, FIELD2 FROM FOO WHERE BAR=? AND BAZ=?',
|
|
288
|
+
[1, 'a']
|
|
289
|
+
)
|
|
290
|
+
const rows = statement.asIterable()
|
|
291
|
+
for await (const [field1, field2] of rows) {
|
|
292
|
+
console.log(field1, field2)
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Transactions
|
|
297
|
+
|
|
298
|
+
Transaction is commited on success and rolled back on failure.
|
|
299
|
+
The transaction object has the same api as the pool object.
|
|
300
|
+
|
|
301
|
+
```javascript
|
|
302
|
+
pool.transaction((transaction) => {
|
|
303
|
+
const fooId = 1
|
|
304
|
+
|
|
305
|
+
return transaction
|
|
306
|
+
.update('INSERT INTO FOO (FOOID, FIELD2) VALUES(?,?)', [fooId, 'a'])
|
|
307
|
+
.then(function () {
|
|
308
|
+
return transaction.update('update BAR set FOOID=? where BARID=?', [
|
|
309
|
+
fooId,
|
|
310
|
+
2,
|
|
311
|
+
])
|
|
312
|
+
})
|
|
313
|
+
})
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Complex types
|
|
317
|
+
|
|
318
|
+
The node-jt400 module handles strings, longs, doubles and nulls automatically as types. When using other types like CLOB or BLOB you need to specify the type specifically.
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
pool
|
|
322
|
+
.update('INSERT INTO foo (fooid, textfield, clobfield) VALUES(?, ?)', [
|
|
323
|
+
1,
|
|
324
|
+
'text',
|
|
325
|
+
{ type: 'CLOB', value: 'A really long string' },
|
|
326
|
+
])
|
|
327
|
+
.then(() => {
|
|
328
|
+
console.log('updated')
|
|
329
|
+
})
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
For BLOB pass the base64 string representation of a file. The module will convert it to a blob for the AS400 database.
|
|
333
|
+
|
|
334
|
+
```javascript
|
|
335
|
+
const fs = require('fs').promises
|
|
336
|
+
const base64String = await fs.readFile('/path/to/file.jpg', {
|
|
337
|
+
encoding: 'base64',
|
|
338
|
+
})
|
|
339
|
+
pool
|
|
340
|
+
.update('INSERT INTO foo (fooid, textfield, blobfield) VALUES(?, ?)', [
|
|
341
|
+
1,
|
|
342
|
+
'text',
|
|
343
|
+
{ type: 'BLOB', value: base64String },
|
|
344
|
+
])
|
|
345
|
+
.then(() => {
|
|
346
|
+
console.log('updated')
|
|
347
|
+
})
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
When querying a blob field you will recieve a string.
|
|
351
|
+
|
|
352
|
+
## Filesystem
|
|
353
|
+
|
|
354
|
+
### IFS read
|
|
355
|
+
|
|
356
|
+
```javascript
|
|
357
|
+
const ifs = pool.ifs()
|
|
358
|
+
const readStream = ifs.createReadStream('/foo/bar.txt') // readStream from IFS
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
As with any readable stream you can pipe it wherever you want. For example into the node filesystem.
|
|
362
|
+
|
|
363
|
+
```javascript
|
|
364
|
+
const createWriteStream = require('fs').createWriteStream
|
|
365
|
+
const join = require('path').join
|
|
366
|
+
const filename = join(__dirname, 'old.txt')
|
|
367
|
+
const writeStream = createWriteStream(filename) // writeStream to nodeJS filesystem.
|
|
368
|
+
|
|
369
|
+
const ifs = pool.ifs()
|
|
370
|
+
const readStream = ifs.createReadStream('/new.txt') // Reading bar.txt from IFS
|
|
371
|
+
|
|
372
|
+
readStream.pipe(writeStream) // Piping from IFS to nodeJS
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### IFS write
|
|
376
|
+
|
|
377
|
+
```javascript
|
|
378
|
+
const ifs = pool.ifs();
|
|
379
|
+
const writeStream = ifs.createWriteStream(('/foo/bar.txt')
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
As with any other writable streams you can pipe a readable stream into it.
|
|
383
|
+
|
|
384
|
+
```javascript
|
|
385
|
+
const fs = require('fs').createReadStream
|
|
386
|
+
const join = require('path').join
|
|
387
|
+
const filename = join(__dirname, 'old.txt')
|
|
388
|
+
const readStream = createReadStream(filename) // readStream from nodeJS filesystem
|
|
389
|
+
|
|
390
|
+
const ifs = pool.ifs()
|
|
391
|
+
const writeStream = ifs.createWriteStream('/new.txt')
|
|
392
|
+
|
|
393
|
+
readStream.pipe(writeStream) // Piping from nodeJS to IFS
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
You can see more examples in [issue #27](https://github.com/tryggingamidstodin/node-jt400/issues/27)
|
|
397
|
+
|
|
398
|
+
### IFS delete
|
|
399
|
+
|
|
400
|
+
```javascript
|
|
401
|
+
const ifs = pool.ifs()
|
|
402
|
+
ifs.deleteFile('/foo/bar.txt.old').then(console.log) // true or false
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## Programs
|
|
406
|
+
|
|
407
|
+
With programs it is necessary to define your input parameters first. These must match your program defination in AS.
|
|
408
|
+
|
|
409
|
+
```javascript
|
|
410
|
+
const myProgram = pool.defineProgram({
|
|
411
|
+
programName: 'MYPGM',
|
|
412
|
+
paramsSchema: [
|
|
413
|
+
{ type: 'DECIMAL', precision: 10, scale: 0, name: 'myId'},
|
|
414
|
+
{ type: 'NUMERIC', precision: 8, scale: 0, name: 'myDate'},
|
|
415
|
+
{ type: 'NUMERIC', precision: 12, scale: 2, name: 'myTotalValue' },
|
|
416
|
+
{ type: 'CHAR', precision: 32, scale: 0, name: 'myString'}
|
|
417
|
+
],
|
|
418
|
+
libraryName: 'WTMEXC' // Optional. Defaults to *LIBL
|
|
419
|
+
);
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
The Decimal type maps to com.ibm.as400.access.AS400PackedDecimal
|
|
423
|
+
The Numeric type maps to com.ibm.as400.access.AS400ZonedDecimal
|
|
424
|
+
Everything else (char) maps to com.ibm.as400.access.AS400Text
|
|
425
|
+
Precision is the size and scale is the decimals.
|
|
426
|
+
|
|
427
|
+
> ATTENTION: To make the API clearer we renamed .pgm to .defineProgram. The pgm function is deprecated in v3.0
|
|
428
|
+
|
|
429
|
+
When you have defined your program, you can call/invoke it with the parameters you defined.
|
|
430
|
+
|
|
431
|
+
```javascript
|
|
432
|
+
myProgram(
|
|
433
|
+
{
|
|
434
|
+
myId: 123
|
|
435
|
+
myDate: '20170608',
|
|
436
|
+
myTotalValue: 88450.57,
|
|
437
|
+
myString: 'This is a test'
|
|
438
|
+
},
|
|
439
|
+
10 // Optional timeout in sec
|
|
440
|
+
)
|
|
441
|
+
.then(result => {
|
|
442
|
+
console.log(result)
|
|
443
|
+
});
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
> ATTENTION: In version 3.0 we added a optional timeout parameter for program calls. This defaults to 3 sec. This is a breaking change since your programs will no longer halt or hang for extended period and therefore never give a response. If you have complicated programs that run for longer than 3 sec then you need to adjust the timeout parameter for those specific calls. Setting it to 0 will ignore the timeout limit.
|
|
447
|
+
|
|
448
|
+
## Keyed Data Queues
|
|
449
|
+
|
|
450
|
+
[IBM KeyedDataQueue Reference](https://javadoc.midrange.com/jtopen/index.html?com/ibm/as400/access/KeyedDataQueue.html)
|
|
451
|
+
|
|
452
|
+
```javascript
|
|
453
|
+
const jt400 = pool(jt400config)
|
|
454
|
+
// Open a keyed data queue for reading
|
|
455
|
+
let queue = jt400.createKeyedDataQ({ name })
|
|
456
|
+
// -1 waits until a message exists. (MSGW)
|
|
457
|
+
let m = await queue.read({ key: inboxKey, wait: 2 })
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
## Message Queues
|
|
461
|
+
|
|
462
|
+
[IBM MessageQueue Reference](https://javadoc.midrange.com/jtopen/index.html?com/ibm/as400/access/MessageQueue.html)
|
|
463
|
+
|
|
464
|
+
```javascript
|
|
465
|
+
const path = '/QSYS.LIB/' + process.env.AS400_USERNAME + '.MSGQ'
|
|
466
|
+
const msgq = await jt400.openMessageQ({ path: path })
|
|
467
|
+
const testMessage = 'Test Message'
|
|
468
|
+
await msgq.sendInformational(testMessage) // Writes a basic message
|
|
469
|
+
await msgq.read()
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
## Message Files
|
|
473
|
+
|
|
474
|
+
[IBM AS400Message Reference](https://javadoc.midrange.com/jtopen/index.html?com/ibm/as400/access/MessageFile.html)
|
|
475
|
+
|
|
476
|
+
```javascript
|
|
477
|
+
const file = await pool.openMessageFile({
|
|
478
|
+
path: '/QSYS.LIB/YOURLIB.LIB/YOURMSGF.MSGF',
|
|
479
|
+
})
|
|
480
|
+
let msg = await file.read({ messageId: 'AMX0051' })
|
|
481
|
+
console.log('msg', await msg.getText())
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
# Error handling
|
|
485
|
+
|
|
486
|
+
This module uses [oops-error](https://github.com/tryggingamidstodin/oops-error) to categorize errors into operational errors and programmer errors. We reccomend you take a look at the [readme](https://github.com/tryggingamidstodin/oops-error/blob/master/README.md) for further information about these categories.
|
|
487
|
+
|
|
488
|
+
The oops-error has few properties:
|
|
489
|
+
|
|
490
|
+
- category: Tells you the error is programmer or operational.
|
|
491
|
+
- message: The basic error message.
|
|
492
|
+
- cause: the original error.
|
|
493
|
+
- fullstack: function that returns the fullstack of causes.
|
|
494
|
+
|
|
495
|
+
## Examples
|
|
496
|
+
|
|
497
|
+
Lets define too many paramters for our query.
|
|
498
|
+
|
|
499
|
+
```javascript
|
|
500
|
+
pool
|
|
501
|
+
.query('SELECT field1, field2 FROM foo WHERE bar=? AND baz=?', [1, 'a', 'b])
|
|
502
|
+
.then(result => {
|
|
503
|
+
console.log('we will not go here')
|
|
504
|
+
})
|
|
505
|
+
.catch(error => {
|
|
506
|
+
console.log('we got programmer error');
|
|
507
|
+
console.log('category': errror.category) // ProgrammerError
|
|
508
|
+
console.log('message': errror.message) // Descriptor index not valid.
|
|
509
|
+
console.log('original error', error.cause)
|
|
510
|
+
});
|
|
511
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Connection } from './lib/connection.types';
|
|
2
|
+
import { InMemoryConnection } from './lib/inMemoryConnection';
|
|
3
|
+
import { Logger } from './lib/logger';
|
|
4
|
+
export * from './lib/baseConnection.types';
|
|
5
|
+
export * from './lib/connection.types';
|
|
6
|
+
export * from './lib/ifs/types';
|
|
7
|
+
export { InMemoryConnection, Logger };
|
|
8
|
+
export type JT400Options = {
|
|
9
|
+
logger?: Logger;
|
|
10
|
+
};
|
|
11
|
+
export declare function pool(config?: {}, options?: JT400Options): Connection;
|
|
12
|
+
export declare function connect(config?: {}, options?: JT400Options): Promise<Connection>;
|
|
13
|
+
export declare function useInMemoryDb(options?: JT400Options): InMemoryConnection;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.pool = pool;
|
|
27
|
+
exports.connect = connect;
|
|
28
|
+
exports.useInMemoryDb = useInMemoryDb;
|
|
29
|
+
const java_1 = require("./java");
|
|
30
|
+
const connection_1 = require("./lib/connection");
|
|
31
|
+
const inMemoryConnection_1 = require("./lib/inMemoryConnection");
|
|
32
|
+
const insertList_1 = require("./lib/insertList");
|
|
33
|
+
const logger_1 = require("./lib/logger");
|
|
34
|
+
__exportStar(require("./lib/baseConnection.types"), exports);
|
|
35
|
+
__exportStar(require("./lib/connection.types"), exports);
|
|
36
|
+
__exportStar(require("./lib/ifs/types"), exports);
|
|
37
|
+
const defaultConfig = {
|
|
38
|
+
host: process.env.AS400_HOST,
|
|
39
|
+
user: process.env.AS400_USERNAME,
|
|
40
|
+
password: process.env.AS400_PASSWORD,
|
|
41
|
+
naming: 'system',
|
|
42
|
+
};
|
|
43
|
+
const javaBridge = (0, java_1.initJavaBridge)();
|
|
44
|
+
function pool(config = {}, options = {}) {
|
|
45
|
+
const javaCon = javaBridge.createPool(JSON.stringify(Object.assign(Object.assign({}, defaultConfig), config)));
|
|
46
|
+
return (0, connection_1.createConnection)({
|
|
47
|
+
connection: javaCon,
|
|
48
|
+
insertListFun: insertList_1.createInsertListInOneStatment,
|
|
49
|
+
bufferToJavaType: javaBridge.bufferToJavaType,
|
|
50
|
+
javaTypeToBuffer: javaBridge.javaTypeToBuffer,
|
|
51
|
+
logger: options.logger || (0, logger_1.createDefaultLogger)(),
|
|
52
|
+
inMemory: false,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function connect() {
|
|
56
|
+
return __awaiter(this, arguments, void 0, function* (config = {}, options = {}) {
|
|
57
|
+
const javaCon = yield javaBridge.createConnection(JSON.stringify(Object.assign(Object.assign({}, defaultConfig), config)));
|
|
58
|
+
return (0, connection_1.createConnection)({
|
|
59
|
+
connection: javaCon,
|
|
60
|
+
insertListFun: insertList_1.createInsertListInOneStatment,
|
|
61
|
+
bufferToJavaType: javaBridge.bufferToJavaType,
|
|
62
|
+
javaTypeToBuffer: javaBridge.javaTypeToBuffer,
|
|
63
|
+
logger: options.logger || (0, logger_1.createDefaultLogger)(),
|
|
64
|
+
inMemory: false,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function useInMemoryDb(options = {}) {
|
|
69
|
+
return (0, inMemoryConnection_1.createInMemoryConnection)(javaBridge, options.logger || (0, logger_1.createDefaultLogger)());
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./ts-src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,oBAYC;AACD,0BAeC;AAED,sCAKC;AA/DD,iCAAuC;AACvC,iDAAmD;AAEnD,iEAGiC;AACjC,iDAAgE;AAChE,yCAA0D;AAE1D,6DAA0C;AAC1C,yDAAsC;AACtC,kDAA+B;AAG/B,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;IAC5B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;IAChC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;IACpC,MAAM,EAAE,QAAQ;CACjB,CAAA;AAED,MAAM,UAAU,GAAG,IAAA,qBAAc,GAAE,CAAA;AAMnC,SAAgB,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE,UAAwB,EAAE;IAC1D,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CACnC,IAAI,CAAC,SAAS,iCAAM,aAAa,GAAK,MAAM,EAAG,CAChD,CAAA;IACD,OAAO,IAAA,6BAAgB,EAAC;QACtB,UAAU,EAAE,OAAO;QACnB,aAAa,EAAE,0CAA6B;QAC5C,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAA,4BAAmB,GAAE;QAC/C,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAA;AACJ,CAAC;AACD,SAAsB,OAAO;yDAC3B,MAAM,GAAG,EAAE,EACX,UAAwB,EAAE;QAE1B,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,gBAAgB,CAC/C,IAAI,CAAC,SAAS,iCAAM,aAAa,GAAK,MAAM,EAAG,CAChD,CAAA;QACD,OAAO,IAAA,6BAAgB,EAAC;YACtB,UAAU,EAAE,OAAO;YACnB,aAAa,EAAE,0CAA6B;YAC5C,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;YAC7C,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;YAC7C,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAA,4BAAmB,GAAE;YAC/C,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAA;IACJ,CAAC;CAAA;AAED,SAAgB,aAAa,CAAC,UAAwB,EAAE;IACtD,OAAO,IAAA,6CAAwB,EAC7B,UAAU,EACV,OAAO,CAAC,MAAM,IAAI,IAAA,4BAAmB,GAAE,CACxC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|