Skip to content

Commit

Permalink
fix: "_text" property is removed from json output (#13)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: accessing data via ._text property is no longer valid
  • Loading branch information
patrickmichalina authored Jan 31, 2019
1 parent 0ad85d5 commit f117e44
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
"dependencies": {
"js-sha1": "^0.6.0",
"node-fetch": "^2.3.0",
"rxjs": "^6.3.3",
"rxjs": "^6.4.0",
"typescript-monads": "^3.10.0",
"uuid": "^3.3.2",
"xml-js": "^1.6.9",
"xmldom": "^0.1.27"
},
"devDependencies": {
"@types/fs-extra": "^5.0.4",
"@types/node": "^10.12.19",
"@types/node-fetch": "^2.1.4",
"@types/node": "^10.12.20",
"@types/node-fetch": "^2.1.5",
"@types/uuid": "^3.4.4",
"@types/xml-js": "^1.0.0",
"@types/xmldom": "^0.1.29",
Expand Down
1 change: 1 addition & 0 deletions src/config/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface ITransportPayoad {
readonly statusMessage: string
readonly status: number
}

export type ITransport = (body: string) => (uri: string) => Observable<ITransportPayoad>

export type IEncodeBase64 = (str: string) => string
Expand Down
2 changes: 1 addition & 1 deletion src/config/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const FETCH_CONFIG = (body: string) => ({ method: 'POST', body, headers:
export const sharedFetchWrapper =
(fetchResponse: Promise<any>) =>
from(fetchResponse)
.pipe(flatMap<Response, ITransportPayoad>(a => a.text().then(body => {
.pipe(flatMap<Response, Promise<ITransportPayoad>>(a => a.text().then(body => {
return {
body,
status: a.status,
Expand Down
14 changes: 12 additions & 2 deletions src/soap/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const soapShell =
<${SOAP_NODE.Body}>${rawBody}</${SOAP_NODE.Body}>
</${SOAP_NODE.Envelope}>`

const stringIsBool = (str: string) => str.toLowerCase() === 'true' || str.toLowerCase() === 'false'
const stringToBool = (str: string) => str.toLowerCase() === 'true' ? true : false
const typeConversion = (str: string) => stringIsBool(str) ? stringToBool(str) : str

export const mapResponseXmlToJson =
<T>(node: string) =>
(source: Observable<IOnvifResult>) =>
Expand All @@ -82,8 +86,14 @@ export const mapResponseXmlToJson =
const parsed = JSON.parse(xml2json(b.xmlString, {
compact: true,
spaces: 2,
nativeType: true,
nativeTypeAttributes: true,
textFn: (value: any, parentElement: any) => {
try {
const keyNo = Object.keys(parentElement._parent).length
const keyName = Object.keys(parentElement._parent)[keyNo - 1]
// tslint:disable-next-line:no-object-mutation
parentElement._parent[keyName] = typeConversion(value)
} catch (e) { }
},
elementNameFn: (d: string) => maybe(d.split(':')[1]).valueOr(d)
} as any))

Expand Down

0 comments on commit f117e44

Please sign in to comment.