mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-03 10:40:06 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bde28046be | ||
|
|
eab61a80bf | ||
|
|
9149f932c3 | ||
|
|
fb30ff8876 | ||
|
|
afff422333 | ||
|
|
b49010cfe5 | ||
|
|
fd6fad9b07 |
10
package-lock.json
generated
10
package-lock.json
generated
@@ -9,7 +9,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@sasjs/utils": "3.5.2",
|
||||
"axios": "1.8.2",
|
||||
"axios": "1.12.2",
|
||||
"axios-cookiejar-support": "5.0.5",
|
||||
"form-data": "4.0.4",
|
||||
"https": "1.0.0",
|
||||
@@ -3510,13 +3510,13 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.8.2.tgz",
|
||||
"integrity": "sha512-ls4GYBm5aig9vWx8AWDSGLpnpDQRtWAfrjU+EuytuODrFBkqesN2RkOQCBzrA1RQNHw1SmRMSDDDSwzNAYQ6Rg==",
|
||||
"version": "1.12.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.12.2.tgz",
|
||||
"integrity": "sha512-vMJzPewAlRyOgxV2dU0Cuz2O8zzzx9VYtbJOaBgXFeLc4IV/Eg50n4LowmehOOR61S8ZMpc2K5Sa7g6A4jfkUw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"form-data": "^4.0.4",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@sasjs/utils": "3.5.2",
|
||||
"axios": "1.8.2",
|
||||
"axios": "1.12.2",
|
||||
"axios-cookiejar-support": "5.0.5",
|
||||
"form-data": "4.0.4",
|
||||
"https": "1.0.0",
|
||||
|
||||
14
src/SASjs.ts
14
src/SASjs.ts
@@ -9,7 +9,8 @@ import {
|
||||
ErrorResponse,
|
||||
LoginOptions,
|
||||
LoginResult,
|
||||
ExecutionQuery
|
||||
ExecutionQuery,
|
||||
Tables
|
||||
} from './types'
|
||||
import { SASViyaApiClient } from './SASViyaApiClient'
|
||||
import { SAS9ApiClient } from './SAS9ApiClient'
|
||||
@@ -1240,4 +1241,15 @@ export default class SASjs {
|
||||
public setVerboseMode = (verboseMode: VerboseMode) => {
|
||||
this.requestClient?.setVerboseMode(verboseMode)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a tables class containing one or more tables to be sent to
|
||||
* SAS.
|
||||
* @param table - initial table data
|
||||
* @param macroName - macro name
|
||||
* @returns Tables class
|
||||
*/
|
||||
Tables(table: Record<string, any>, macroName: string) {
|
||||
return new Tables(table, macroName)
|
||||
}
|
||||
}
|
||||
|
||||
28
src/types/Tables.spec.ts
Normal file
28
src/types/Tables.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import SASjs from '../SASjs'
|
||||
|
||||
describe('Tables - basic coverage', () => {
|
||||
const adapter = new SASjs()
|
||||
|
||||
it('should throw an error if first argument is not an array', () => {
|
||||
expect(() => adapter.Tables({}, 'test')).toThrow('First argument')
|
||||
})
|
||||
|
||||
it('should throw an error if second argument is not a string', () => {
|
||||
// @ts-expect-error
|
||||
expect(() => adapter.Tables([], 1234)).toThrow('Second argument')
|
||||
})
|
||||
|
||||
it('should throw an error if macro name ends with a number', () => {
|
||||
expect(() => adapter.Tables([], 'test1')).toThrow('number at the end')
|
||||
})
|
||||
|
||||
it('should throw an error if no arguments are passed', () => {
|
||||
// @ts-expect-error
|
||||
expect(() => adapter.Tables()).toThrow('Missing arguments')
|
||||
})
|
||||
|
||||
it('should create Tables class successfully with _tables property', () => {
|
||||
const tables = adapter.Tables([], 'test')
|
||||
expect(tables).toHaveProperty('_tables')
|
||||
})
|
||||
})
|
||||
29
src/types/Tables.ts
Normal file
29
src/types/Tables.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ArgumentError } from './errors'
|
||||
|
||||
export class Tables {
|
||||
_tables: { [macroName: string]: Record<string, any> }
|
||||
|
||||
constructor(table: Record<string, any>, macroName: string) {
|
||||
this._tables = {}
|
||||
|
||||
this.add(table, macroName)
|
||||
}
|
||||
|
||||
add(table: Record<string, any> | null, macroName: string) {
|
||||
if (table && macroName) {
|
||||
if (!(table instanceof Array)) {
|
||||
throw new ArgumentError('First argument must be array')
|
||||
}
|
||||
if (typeof macroName !== 'string') {
|
||||
throw new ArgumentError('Second argument must be string')
|
||||
}
|
||||
if (!isNaN(Number(macroName[macroName.length - 1]))) {
|
||||
throw new ArgumentError('Macro name cannot have number at the end')
|
||||
}
|
||||
} else {
|
||||
throw new ArgumentError('Missing arguments')
|
||||
}
|
||||
|
||||
this._tables[macroName] = table
|
||||
}
|
||||
}
|
||||
7
src/types/errors/ArgumentError.ts
Normal file
7
src/types/errors/ArgumentError.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export class ArgumentError extends Error {
|
||||
constructor(public message: string) {
|
||||
super(message)
|
||||
this.name = 'ArgumentError'
|
||||
Object.setPrototypeOf(this, ArgumentError.prototype)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './ArgumentError'
|
||||
export * from './AuthorizeError'
|
||||
export * from './CertificateError'
|
||||
export * from './ComputeJobExecutionError'
|
||||
|
||||
@@ -15,3 +15,4 @@ export * from './PollOptions'
|
||||
export * from './WriteStream'
|
||||
export * from './ExecuteScript'
|
||||
export * from './errors'
|
||||
export * from './Tables'
|
||||
|
||||
Reference in New Issue
Block a user