@sasjs/adapter 3.7.8 → 3.7.9

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.
@@ -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: any[], sasFormats?: {
6
- formats: {
7
- [key: string]: string;
8
- };
9
- } | undefined) => string;
5
+ export declare const convertToCSV: (data: {
6
+ [key: string]: any;
7
+ }, tableName: string) => string;
package/package.json CHANGED
@@ -43,23 +43,23 @@
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.2",
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": "10.0.0",
53
- "express": "4.17.1",
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.4",
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.0",
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",
@@ -67,18 +67,18 @@
67
67
  "typedoc": "0.22.11",
68
68
  "typedoc-neo-theme": "1.1.1",
69
69
  "typedoc-plugin-external-module-name": "4.0.6",
70
- "typescript": "4.5.4",
71
- "webpack": "5.66.0",
72
- "webpack-cli": "4.7.2"
70
+ "typescript": "4.5.5",
71
+ "webpack": "5.69.0",
72
+ "webpack-cli": "4.9.2"
73
73
  },
74
74
  "main": "index.js",
75
75
  "dependencies": {
76
- "@sasjs/utils": "2.35.0",
76
+ "@sasjs/utils": "2.36.1",
77
77
  "axios": "0.26.0",
78
78
  "axios-cookiejar-support": "1.0.1",
79
79
  "form-data": "4.0.0",
80
80
  "https": "1.0.0",
81
81
  "tough-cookie": "4.0.0"
82
82
  },
83
- "version": "3.7.8"
83
+ "version": "3.7.9"
84
84
  }
@@ -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[tableName])
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[tableName])
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
- const csv = convertToCSV(data[tableName])
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[tableName])
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: any[],
7
- sasFormats?: { formats: { [key: string]: string } }
6
+ data: { [key: string]: any },
7
+ tableName: string
8
8
  ) => {
9
- let formats = sasFormats?.formats
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(data[0])
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
- data.forEach((row: { [key: string]: any }) => {
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 = data
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 (sasFormats) {
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 = data.map((row: any) => {
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
- const csv = convertToCSV(data[tableName], data[`$${tableName}`])
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
  })
@@ -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: any[], sasFormats?: {
6
- formats: {
7
- [key: string]: string;
8
- };
9
- } | undefined) => string;
5
+ export declare const convertToCSV: (data: {
6
+ [key: string]: any;
7
+ }, tableName: string) => string;