@sasjs/adapter 3.7.8 → 3.7.11
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/createTSDocs.js +35 -0
- package/index.js +2 -2
- package/node/index.js +2 -2
- package/node/utils/convertToCsv.d.ts +3 -5
- package/package.json +12 -13
- package/src/SASViyaApiClient.ts +3 -1
- package/src/SASjs.ts +3 -0
- package/src/api/viya/uploadTables.ts +1 -1
- package/src/file/generateFileUploadForm.ts +1 -1
- package/src/file/generateTableUploadForm.ts +8 -1
- package/src/job-execution/Sas9JobExecutor.ts +2 -1
- package/src/utils/convertToCsv.ts +16 -8
- package/src/utils/formatDataForRequest.ts +6 -1
- package/typedoc.json +7 -39
- package/utils/convertToCsv.d.ts +3 -5
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Converts the given JSON object array to a CSV string.
|
|
3
3
|
* @param data - the array of JSON objects to convert.
|
|
4
4
|
*/
|
|
5
|
-
export declare const convertToCSV: (data:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
} | undefined) => string;
|
|
5
|
+
export declare const convertToCSV: (data: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}, tableName: string) => string;
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"prepublishOnly": "cp -r ./build/* . && rm -rf ./build",
|
|
15
15
|
"postpublish": "git clean -fd",
|
|
16
16
|
"semantic-release": "semantic-release",
|
|
17
|
-
"typedoc": "
|
|
17
|
+
"typedoc": "node createTSDocs",
|
|
18
18
|
"prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks && git config core.autocrlf false || true"
|
|
19
19
|
},
|
|
20
20
|
"publishConfig": {
|
|
@@ -43,42 +43,41 @@
|
|
|
43
43
|
"@types/axios": "0.14.0",
|
|
44
44
|
"@types/express": "4.17.13",
|
|
45
45
|
"@types/form-data": "2.5.0",
|
|
46
|
-
"@types/jest": "27.0
|
|
46
|
+
"@types/jest": "27.4.0",
|
|
47
47
|
"@types/mime": "2.0.3",
|
|
48
48
|
"@types/pem": "1.9.6",
|
|
49
49
|
"@types/tough-cookie": "4.0.1",
|
|
50
50
|
"copyfiles": "2.4.1",
|
|
51
51
|
"cp": "0.2.0",
|
|
52
|
-
"dotenv": "
|
|
53
|
-
"express": "4.17.
|
|
52
|
+
"dotenv": "16.0.0",
|
|
53
|
+
"express": "4.17.3",
|
|
54
54
|
"jest": "27.4.7",
|
|
55
55
|
"jest-extended": "2.0.0",
|
|
56
56
|
"node-polyfill-webpack-plugin": "1.1.4",
|
|
57
57
|
"path": "0.12.7",
|
|
58
|
-
"pem": "1.14.
|
|
58
|
+
"pem": "1.14.6",
|
|
59
59
|
"process": "0.11.10",
|
|
60
60
|
"rimraf": "3.0.2",
|
|
61
61
|
"semantic-release": "18.0.0",
|
|
62
|
-
"terser-webpack-plugin": "5.3.
|
|
62
|
+
"terser-webpack-plugin": "5.3.1",
|
|
63
63
|
"ts-jest": "27.1.3",
|
|
64
64
|
"ts-loader": "9.2.6",
|
|
65
65
|
"tslint": "6.1.3",
|
|
66
66
|
"tslint-config-prettier": "1.18.0",
|
|
67
67
|
"typedoc": "0.22.11",
|
|
68
|
-
"typedoc-
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"webpack": "
|
|
72
|
-
"webpack-cli": "4.7.2"
|
|
68
|
+
"typedoc-plugin-rename-defaults": "0.4.0",
|
|
69
|
+
"typescript": "4.5.5",
|
|
70
|
+
"webpack": "5.69.0",
|
|
71
|
+
"webpack-cli": "4.9.2"
|
|
73
72
|
},
|
|
74
73
|
"main": "index.js",
|
|
75
74
|
"dependencies": {
|
|
76
|
-
"@sasjs/utils": "2.
|
|
75
|
+
"@sasjs/utils": "2.36.1",
|
|
77
76
|
"axios": "0.26.0",
|
|
78
77
|
"axios-cookiejar-support": "1.0.1",
|
|
79
78
|
"form-data": "4.0.0",
|
|
80
79
|
"https": "1.0.0",
|
|
81
80
|
"tough-cookie": "4.0.0"
|
|
82
81
|
},
|
|
83
|
-
"version": "3.7.
|
|
82
|
+
"version": "3.7.11"
|
|
84
83
|
}
|
package/src/SASViyaApiClient.ts
CHANGED
|
@@ -836,7 +836,9 @@ export class SASViyaApiClient {
|
|
|
836
836
|
|
|
837
837
|
const { result: members } = await this.requestClient
|
|
838
838
|
.get<{ items: any[] }>(
|
|
839
|
-
`/folders/folders/${folder.id}/members?limit=${
|
|
839
|
+
`/folders/folders/${folder.id}/members?limit=${
|
|
840
|
+
folder.memberCount < 500 ? 500 : folder.memberCount
|
|
841
|
+
}`, // this is a fix for https://github.com/sasjs/adapter/issues/669
|
|
840
842
|
accessToken
|
|
841
843
|
)
|
|
842
844
|
.catch((err) => {
|
package/src/SASjs.ts
CHANGED
|
@@ -113,6 +113,9 @@ export default class SASjs {
|
|
|
113
113
|
debug?: boolean
|
|
114
114
|
) {
|
|
115
115
|
this.isMethodSupported('executeScriptSASViya', [ServerType.SasViya])
|
|
116
|
+
|
|
117
|
+
contextName = contextName || this.sasjsConfig.contextName
|
|
118
|
+
|
|
116
119
|
if (!contextName) {
|
|
117
120
|
throw new Error(
|
|
118
121
|
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
|
|
@@ -18,7 +18,7 @@ export async function uploadTables(
|
|
|
18
18
|
const uploadedFiles = []
|
|
19
19
|
|
|
20
20
|
for (const tableName in data) {
|
|
21
|
-
const csv = convertToCSV(data
|
|
21
|
+
const csv = convertToCSV(data, tableName)
|
|
22
22
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
23
23
|
throw new Error(
|
|
24
24
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
@@ -18,7 +18,7 @@ export const generateFileUploadForm = (
|
|
|
18
18
|
if (!Array.isArray(data[tableName])) continue
|
|
19
19
|
|
|
20
20
|
const name = tableName
|
|
21
|
-
const csv = convertToCSV(data
|
|
21
|
+
const csv = convertToCSV(data, tableName)
|
|
22
22
|
|
|
23
23
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
24
24
|
throw new Error(
|
|
@@ -9,18 +9,24 @@ export const generateTableUploadForm = (
|
|
|
9
9
|
const sasjsTables = []
|
|
10
10
|
const requestParams: any = {}
|
|
11
11
|
let tableCounter = 0
|
|
12
|
+
|
|
12
13
|
for (const tableName in data) {
|
|
13
14
|
tableCounter++
|
|
15
|
+
|
|
14
16
|
sasjsTables.push(tableName)
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
const csv = convertToCSV(data, tableName)
|
|
19
|
+
|
|
16
20
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
17
21
|
throw new Error(
|
|
18
22
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
19
23
|
)
|
|
20
24
|
}
|
|
25
|
+
|
|
21
26
|
// if csv has length more then 16k, send in chunks
|
|
22
27
|
if (csv.length > 16000) {
|
|
23
28
|
const csvChunks = splitChunks(csv)
|
|
29
|
+
|
|
24
30
|
// append chunks to form data with same key
|
|
25
31
|
csvChunks.map((chunk) => {
|
|
26
32
|
formData.append(`sasjs${tableCounter}data`, chunk)
|
|
@@ -29,6 +35,7 @@ export const generateTableUploadForm = (
|
|
|
29
35
|
requestParams[`sasjs${tableCounter}data`] = csv
|
|
30
36
|
}
|
|
31
37
|
}
|
|
38
|
+
|
|
32
39
|
requestParams['sasjs_tables'] = sasjsTables.join(' ')
|
|
33
40
|
|
|
34
41
|
return { formData, requestParams }
|
|
@@ -125,7 +125,8 @@ const generateFileUploadForm = (
|
|
|
125
125
|
): NodeFormData => {
|
|
126
126
|
for (const tableName in data) {
|
|
127
127
|
const name = tableName
|
|
128
|
-
const csv = convertToCSV(data
|
|
128
|
+
const csv = convertToCSV(data, tableName)
|
|
129
|
+
|
|
129
130
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
130
131
|
throw new Error(
|
|
131
132
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
* @param data - the array of JSON objects to convert.
|
|
4
4
|
*/
|
|
5
5
|
export const convertToCSV = (
|
|
6
|
-
data:
|
|
7
|
-
|
|
6
|
+
data: { [key: string]: any },
|
|
7
|
+
tableName: string
|
|
8
8
|
) => {
|
|
9
|
-
|
|
9
|
+
if (!data[tableName]) {
|
|
10
|
+
throw new Error('No table provided to be converted to CSV')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const table = data[tableName]
|
|
14
|
+
|
|
15
|
+
if (!Array.isArray(table)) return ''
|
|
16
|
+
|
|
17
|
+
let formats = data[`$${tableName}`]?.formats
|
|
10
18
|
let headers: string[] = []
|
|
11
19
|
let csvTest
|
|
12
20
|
let invalidString = false
|
|
@@ -16,14 +24,14 @@ export const convertToCSV = (
|
|
|
16
24
|
headers = Object.keys(formats).map((key) => `${key}:${formats![key]}`)
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
const headerFields = Object.keys(
|
|
27
|
+
const headerFields = Object.keys(table[0])
|
|
20
28
|
|
|
21
29
|
headerFields.forEach((field) => {
|
|
22
30
|
if (!formats || !Object.keys(formats).includes(field)) {
|
|
23
31
|
let hasNullOrNumber = false
|
|
24
32
|
let hasSpecialMissingString = false
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
table.forEach((row: { [key: string]: any }) => {
|
|
27
35
|
if (row[field] === null || typeof row[field] === 'number') {
|
|
28
36
|
hasNullOrNumber = true
|
|
29
37
|
} else if (
|
|
@@ -45,7 +53,7 @@ export const convertToCSV = (
|
|
|
45
53
|
let hasMixedTypes: boolean = false
|
|
46
54
|
let rowNumError: number = -1
|
|
47
55
|
|
|
48
|
-
const longestValueForField =
|
|
56
|
+
const longestValueForField = table
|
|
49
57
|
.map((row: any, index: number) => {
|
|
50
58
|
if (row[field] || row[field] === '') {
|
|
51
59
|
if (firstFoundType) {
|
|
@@ -101,7 +109,7 @@ export const convertToCSV = (
|
|
|
101
109
|
}
|
|
102
110
|
})
|
|
103
111
|
|
|
104
|
-
if (
|
|
112
|
+
if (formats) {
|
|
105
113
|
headers = headers.sort(
|
|
106
114
|
(a, b) =>
|
|
107
115
|
headerFields.indexOf(a.replace(/:.*/, '')) -
|
|
@@ -111,7 +119,7 @@ export const convertToCSV = (
|
|
|
111
119
|
|
|
112
120
|
if (invalidString) return 'ERROR: LARGE STRING LENGTH'
|
|
113
121
|
|
|
114
|
-
csvTest =
|
|
122
|
+
csvTest = table.map((row: any) => {
|
|
115
123
|
const fields = Object.keys(row).map((fieldName, index) => {
|
|
116
124
|
let value
|
|
117
125
|
const currentCell = row[fieldName]
|
|
@@ -15,19 +15,24 @@ export const formatDataForRequest = (data: any) => {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
tableCounter++
|
|
18
|
+
|
|
18
19
|
sasjsTables.push(tableName)
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
const csv = convertToCSV(data, tableName)
|
|
20
22
|
|
|
21
23
|
if (csv === 'ERROR: LARGE STRING LENGTH') {
|
|
22
24
|
throw new Error(
|
|
23
25
|
'The max length of a string value in SASjs is 32765 characters.'
|
|
24
26
|
)
|
|
25
27
|
}
|
|
28
|
+
|
|
26
29
|
// if csv has length more then 16k, send in chunks
|
|
27
30
|
if (csv.length > 16000) {
|
|
28
31
|
const csvChunks = splitChunks(csv)
|
|
32
|
+
|
|
29
33
|
// append chunks to form data with same key
|
|
30
34
|
result[`sasjs${tableCounter}data0`] = csvChunks.length
|
|
35
|
+
|
|
31
36
|
csvChunks.forEach((chunk, index) => {
|
|
32
37
|
result[`sasjs${tableCounter}data${index + 1}`] = chunk
|
|
33
38
|
})
|
package/typedoc.json
CHANGED
|
@@ -1,45 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"out": "docs",
|
|
3
|
-
"
|
|
4
|
-
"exclude": "**/*+(index|.spec|.e2e).ts",
|
|
5
|
-
"ignoreCompilerErrors": true,
|
|
6
|
-
"disableOutputCheck": true,
|
|
3
|
+
"exclude": ["**/*+(index|.spec|.e2e).ts"],
|
|
7
4
|
"excludeExternals": true,
|
|
8
5
|
"excludePrivate": true,
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"Types": "modules/types"
|
|
16
|
-
},
|
|
17
|
-
"SAS Viya API Client": "classes/reflection-717.reflection-180.sasviyaapiclient",
|
|
18
|
-
"SAS 9 API Client": "classes/reflection-717.reflection-180.sas9apiclient"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"links": [
|
|
22
|
-
{
|
|
23
|
-
"label": "SASjs on Github",
|
|
24
|
-
"url": "https://github.com/sasjs/adapter"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"label": "SASjs.io",
|
|
28
|
-
"url": "https://sasjs.io"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"label": "SASjs CLI",
|
|
32
|
-
"url": "https://github.com/sasjs/cli"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"label": "React Seed App",
|
|
36
|
-
"url": "https://github.com/sasjs/react-seed-app"
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
"source": [
|
|
40
|
-
{
|
|
41
|
-
"path": "https://github.com/sasjs/adapter/blob/master/src/",
|
|
42
|
-
"line": "L"
|
|
43
|
-
}
|
|
6
|
+
"entryPoints": [
|
|
7
|
+
"src/SASjs.ts",
|
|
8
|
+
"src/SAS9ApiClient.ts",
|
|
9
|
+
"src/SASjsApiClient.ts",
|
|
10
|
+
"src/SASViyaApiClient.ts",
|
|
11
|
+
"src/types"
|
|
44
12
|
]
|
|
45
13
|
}
|
package/utils/convertToCsv.d.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Converts the given JSON object array to a CSV string.
|
|
3
3
|
* @param data - the array of JSON objects to convert.
|
|
4
4
|
*/
|
|
5
|
-
export declare const convertToCSV: (data:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
} | undefined) => string;
|
|
5
|
+
export declare const convertToCSV: (data: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}, tableName: string) => string;
|