xml-toolkit 1.0.18 → 1.0.19

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/README.md CHANGED
@@ -99,7 +99,7 @@ const xml = xs.stringify (data)
99
99
  const http = require ('http')
100
100
  const {SOAP11} = require ('xml-toolkit')
101
101
 
102
- const soap = await SOAP11.fromFile ('their.wsdl')
102
+ const soap = new SOAP11 ('their.wsdl')
103
103
 
104
104
  const {method, headers, body} = soap.http ({RequestElementNameOfTheirs: {amount: '0.01'}})
105
105
 
package/lib/SOAP11.js CHANGED
@@ -7,9 +7,27 @@ const SOAPHTTP = require ('./SOAPHTTP.js')
7
7
 
8
8
  const SOAP11 = class {
9
9
 
10
+ constructor (fn) {
11
+
12
+ this.definitions = []
13
+
14
+ if (fn) {
15
+
16
+ this.xs = new XMLSchemata (fn)
17
+
18
+ for (const doc of this.xs.documents)
19
+
20
+ if (doc.localName === 'definitions' && doc.namespaceURI === 'http://schemas.xmlsoap.org/wsdl/')
21
+
22
+ this.definitions.push (doc)
23
+
24
+ }
25
+
26
+ }
27
+
10
28
  getMessageLocalNameByElementLocalName (elementLocalName) {
11
29
 
12
- for (const m of this.definitions.children) if (m.localName === 'message')
30
+ for (const d of this.definitions) for (const m of d.children) if (m.localName === 'message')
13
31
 
14
32
  for (const p of m.children) if (p.localName === 'part')
15
33
 
@@ -21,7 +39,7 @@ const SOAP11 = class {
21
39
 
22
40
  getOperationNameByMessageLocalName (messageLocalName) {
23
41
 
24
- for (const p of this.definitions.children) if (p.localName === 'portType')
42
+ for (const d of this.definitions) for (const p of d.children) if (p.localName === 'portType')
25
43
 
26
44
  for (const o of p.children) if (o.localName === 'operation')
27
45
 
@@ -36,7 +54,7 @@ const SOAP11 = class {
36
54
 
37
55
  getSoapActionByOperationName (operationName) {
38
56
 
39
- for (const b of this.definitions.children) if (b.localName === 'binding')
57
+ for (const d of this.definitions) for (const b of d.children) if (b.localName === 'binding')
40
58
 
41
59
  for (const o of b.children) if (o.localName === 'operation' && o.attributes.get ('name') === operationName)
42
60
 
@@ -97,11 +115,13 @@ SOAP11.fromFile = async function (fn, options = {}) {
97
115
 
98
116
  s.xs = await XMLSchemata.fromFile (fn)
99
117
 
100
- s.definitions = await new XMLReader ({
118
+ const nodes = new XMLReader ({
101
119
  filterElements: e =>
102
120
  e.namespaceURI === WSDL.namespaceURI &&
103
121
  e.localName === 'definitions'
104
- }).process (fs.createReadStream (fn)).findFirst ()
122
+ }).process (fs.createReadStream (fn))
123
+
124
+ for await (const node of nodes) s.definitions.push (node)
105
125
 
106
126
  return s
107
127
 
@@ -20,6 +20,8 @@ const XMLSchemata = class extends Map {
20
20
 
21
21
  this [IDX] = new Map ()
22
22
 
23
+ this.documents = []
24
+
23
25
  if (fn) {
24
26
  this.parser = new XMLParser ()
25
27
  this.addFileSync (fn)
@@ -166,10 +168,14 @@ const XMLSchemata = class extends Map {
166
168
  options.addLocation = function (schemaLocation, namespace) {
167
169
 
168
170
  that.addFileSync (path.join (dirname, schemaLocation), {targetNamespace: namespace})
169
-
171
+
170
172
  }
171
173
 
172
- this.addSchemaSync (this.parser.process (fs.readFileSync (fn, 'utf-8')), options)
174
+ const document = this.parser.process (fs.readFileSync (fn, 'utf-8'))
175
+
176
+ this.documents.push (document)
177
+
178
+ this.addSchemaSync (document, options)
173
179
 
174
180
  }
175
181
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-toolkit",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Collection of classes for dealing with XML",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/test.js CHANGED
@@ -335,10 +335,14 @@ async function test_006_schemata (fn) {
335
335
  async function test_007_wsdl (fn) {
336
336
 
337
337
  const soap = await SOAP11.fromFile ('test/20186.wsdl')
338
+ const soaps = new SOAP11 ('test/20186.wsdl')
339
+
340
+ const d = {GetForm9Sync: {address: {Region: {Code: 78}}}}
338
341
 
339
- console.log (soap.http ({GetForm9Sync: {address: {Region: {Code: 78}}}}))
342
+ console.log (soap.http (d))
343
+ console.log (soaps.http (d))
340
344
 
341
- console.log (soap)
345
+ // console.log (soap)
342
346
 
343
347
  }
344
348
 
@@ -453,10 +457,10 @@ async function main () {
453
457
  // await test_003_emitter_sync ('not-sa01.xml')
454
458
  // await test_003_emitter_sync ('ent.xml')
455
459
  // await test_003_emitter_sync ('soap.xml')
456
- await test_004_schemata ()
460
+ // await test_004_schemata ()
457
461
  // await test_005_schemata ()
458
462
  // await test_006_schemata ()
459
- // await test_007_wsdl ()
463
+ await test_007_wsdl ()
460
464
  // await test_008_schemata ()
461
465
 
462
466
  // test_010_node ()