@sasjs/adapter 3.10.4 → 3.10.7
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 +14 -6
- package/index.js +2 -2
- package/node/index.js +2 -2
- package/node/utils/convertToCsv.d.ts +5 -0
- package/package.json +2 -2
- package/src/file/generateTableUploadForm.ts +3 -2
- package/src/request/RequestClient.ts +7 -0
- package/src/utils/convertToCsv.ts +14 -2
- package/src/utils/formatDataForRequest.ts +4 -3
- package/utils/convertToCsv.d.ts +5 -0
|
@@ -5,3 +5,8 @@
|
|
|
5
5
|
export declare const convertToCSV: (data: {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}, tableName: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if table is table of formats (table name should start from '$' character).
|
|
10
|
+
* @param tableName - table name.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isFormatsTable: (tableName: string) => boolean;
|
package/package.json
CHANGED
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"prettier": "2.7.1",
|
|
65
65
|
"process": "0.11.10",
|
|
66
66
|
"rimraf": "3.0.2",
|
|
67
|
-
"semantic-release": "
|
|
67
|
+
"semantic-release": "19.0.3",
|
|
68
68
|
"terser-webpack-plugin": "5.3.1",
|
|
69
69
|
"ts-jest": "27.1.3",
|
|
70
70
|
"ts-loader": "9.2.6",
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"https": "1.0.0",
|
|
88
88
|
"tough-cookie": "4.0.0"
|
|
89
89
|
},
|
|
90
|
-
"version": "3.10.
|
|
90
|
+
"version": "3.10.7"
|
|
91
91
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as NodeFormData from 'form-data'
|
|
2
|
-
import { convertToCSV } from '../utils/convertToCsv'
|
|
2
|
+
import { convertToCSV, isFormatsTable } from '../utils/convertToCsv'
|
|
3
3
|
import { splitChunks } from '../utils/splitChunks'
|
|
4
4
|
|
|
5
5
|
export const generateTableUploadForm = (
|
|
@@ -13,7 +13,8 @@ export const generateTableUploadForm = (
|
|
|
13
13
|
for (const tableName in data) {
|
|
14
14
|
tableCounter++
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// Formats table should not be sent as part of 'sasjs_tables'
|
|
17
|
+
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
|
17
18
|
|
|
18
19
|
const csv = convertToCSV(data, tableName)
|
|
19
20
|
|
|
@@ -703,7 +703,14 @@ const parseError = (data: string) => {
|
|
|
703
703
|
} catch (_) {}
|
|
704
704
|
|
|
705
705
|
try {
|
|
706
|
+
// There are some edge cases in which the SAS mp_abort macro
|
|
707
|
+
// (https://core.sasjs.io/mp__abort_8sas.html) is unable to
|
|
708
|
+
// provide a clean exit. In this case the JSON response will
|
|
709
|
+
// be wrapped in >>weboutBEGIN<< and >>weboutEND<< strings.
|
|
710
|
+
// Therefore, if the first string exists, we won't throw an
|
|
711
|
+
// error just yet (the parser may yet throw one instead)
|
|
706
712
|
const hasError =
|
|
713
|
+
!data?.match(/>>weboutBEGIN<</) &&
|
|
707
714
|
!!data?.match(/Stored Process Error/i) &&
|
|
708
715
|
!!data?.match(/This request completed with errors./i)
|
|
709
716
|
if (hasError) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isSpecialMissing } from '@sasjs/utils/input/validators'
|
|
2
|
+
import { prefixMessage } from '@sasjs/utils/error'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Converts the given JSON object array to a CSV string.
|
|
@@ -9,7 +10,10 @@ export const convertToCSV = (
|
|
|
9
10
|
tableName: string
|
|
10
11
|
) => {
|
|
11
12
|
if (!data[tableName]) {
|
|
12
|
-
throw
|
|
13
|
+
throw prefixMessage(
|
|
14
|
+
'No table provided to be converted to CSV.',
|
|
15
|
+
'Error while converting to CSV. '
|
|
16
|
+
)
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
const table = data[tableName]
|
|
@@ -137,7 +141,9 @@ export const convertToCSV = (
|
|
|
137
141
|
)
|
|
138
142
|
}
|
|
139
143
|
|
|
140
|
-
|
|
144
|
+
const dot = value.includes('.') ? '' : '.'
|
|
145
|
+
|
|
146
|
+
return `${dot}${value.toLowerCase()}`
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
// if there any present, it should have preceding (") for escaping
|
|
@@ -170,6 +176,12 @@ export const convertToCSV = (
|
|
|
170
176
|
return finalCSV
|
|
171
177
|
}
|
|
172
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Checks if table is table of formats (table name should start from '$' character).
|
|
181
|
+
* @param tableName - table name.
|
|
182
|
+
*/
|
|
183
|
+
export const isFormatsTable = (tableName: string) => /^\$.*/.test(tableName)
|
|
184
|
+
|
|
173
185
|
const getByteSize = (str: string) => {
|
|
174
186
|
let byteSize = str.length
|
|
175
187
|
for (let i = str.length - 1; i >= 0; i--) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertToCSV } from './convertToCsv'
|
|
1
|
+
import { convertToCSV, isFormatsTable } from './convertToCsv'
|
|
2
2
|
import { splitChunks } from './splitChunks'
|
|
3
3
|
|
|
4
4
|
export const formatDataForRequest = (data: any) => {
|
|
@@ -8,7 +8,7 @@ export const formatDataForRequest = (data: any) => {
|
|
|
8
8
|
|
|
9
9
|
for (const tableName in data) {
|
|
10
10
|
if (
|
|
11
|
-
tableName
|
|
11
|
+
isFormatsTable(tableName) &&
|
|
12
12
|
Object.keys(data).includes(tableName.replace(/^\$/, ''))
|
|
13
13
|
) {
|
|
14
14
|
continue
|
|
@@ -16,7 +16,8 @@ export const formatDataForRequest = (data: any) => {
|
|
|
16
16
|
|
|
17
17
|
tableCounter++
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// Formats table should not be sent as part of 'sasjs_tables'
|
|
20
|
+
if (!isFormatsTable(tableName)) sasjsTables.push(tableName)
|
|
20
21
|
|
|
21
22
|
const csv = convertToCSV(data, tableName)
|
|
22
23
|
|
package/utils/convertToCsv.d.ts
CHANGED
|
@@ -5,3 +5,8 @@
|
|
|
5
5
|
export declare const convertToCSV: (data: {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}, tableName: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if table is table of formats (table name should start from '$' character).
|
|
10
|
+
* @param tableName - table name.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isFormatsTable: (tableName: string) => boolean;
|