common.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* tslint:disable */
  2. /* eslint-disable */
  3. /**
  4. * Storage node API
  5. * Storage node API
  6. *
  7. * The version of the OpenAPI document: 0.1.0
  8. * Contact: info@joystream.org
  9. *
  10. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  11. * https://openapi-generator.tech
  12. * Do not edit the class manually.
  13. */
  14. import { Configuration } from './configuration'
  15. import { RequiredError, RequestArgs } from './base'
  16. import { AxiosInstance } from 'axios'
  17. /**
  18. *
  19. * @export
  20. */
  21. export const DUMMY_BASE_URL = 'https://example.com'
  22. /**
  23. *
  24. * @throws {RequiredError}
  25. * @export
  26. */
  27. export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
  28. if (paramValue === null || paramValue === undefined) {
  29. throw new RequiredError(
  30. paramName,
  31. `Required parameter ${paramName} was null or undefined when calling ${functionName}.`
  32. )
  33. }
  34. }
  35. /**
  36. *
  37. * @export
  38. */
  39. export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
  40. if (configuration && configuration.apiKey) {
  41. const localVarApiKeyValue =
  42. typeof configuration.apiKey === 'function' ? await configuration.apiKey(keyParamName) : await configuration.apiKey
  43. object[keyParamName] = localVarApiKeyValue
  44. }
  45. }
  46. /**
  47. *
  48. * @export
  49. */
  50. export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
  51. if (configuration && (configuration.username || configuration.password)) {
  52. object['auth'] = { username: configuration.username, password: configuration.password }
  53. }
  54. }
  55. /**
  56. *
  57. * @export
  58. */
  59. export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
  60. if (configuration && configuration.accessToken) {
  61. const accessToken =
  62. typeof configuration.accessToken === 'function'
  63. ? await configuration.accessToken()
  64. : await configuration.accessToken
  65. object['Authorization'] = 'Bearer ' + accessToken
  66. }
  67. }
  68. /**
  69. *
  70. * @export
  71. */
  72. export const setOAuthToObject = async function (
  73. object: any,
  74. name: string,
  75. scopes: string[],
  76. configuration?: Configuration
  77. ) {
  78. if (configuration && configuration.accessToken) {
  79. const localVarAccessTokenValue =
  80. typeof configuration.accessToken === 'function'
  81. ? await configuration.accessToken(name, scopes)
  82. : await configuration.accessToken
  83. object['Authorization'] = 'Bearer ' + localVarAccessTokenValue
  84. }
  85. }
  86. /**
  87. *
  88. * @export
  89. */
  90. export const setSearchParams = function (url: URL, ...objects: any[]) {
  91. const searchParams = new URLSearchParams(url.search)
  92. for (const object of objects) {
  93. for (const key in object) {
  94. if (Array.isArray(object[key])) {
  95. searchParams.delete(key)
  96. for (const item of object[key]) {
  97. searchParams.append(key, item)
  98. }
  99. } else {
  100. searchParams.set(key, object[key])
  101. }
  102. }
  103. }
  104. url.search = searchParams.toString()
  105. }
  106. /**
  107. *
  108. * @export
  109. */
  110. export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
  111. const nonString = typeof value !== 'string'
  112. const needsSerialization =
  113. nonString && configuration && configuration.isJsonMime
  114. ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
  115. : nonString
  116. return needsSerialization ? JSON.stringify(value !== undefined ? value : {}) : value || ''
  117. }
  118. /**
  119. *
  120. * @export
  121. */
  122. export const toPathString = function (url: URL) {
  123. return url.pathname + url.search + url.hash
  124. }
  125. /**
  126. *
  127. * @export
  128. */
  129. export const createRequestFunction = function (
  130. axiosArgs: RequestArgs,
  131. globalAxios: AxiosInstance,
  132. BASE_PATH: string,
  133. configuration?: Configuration
  134. ) {
  135. return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
  136. const axiosRequestArgs = { ...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url }
  137. return axios.request(axiosRequestArgs)
  138. }
  139. }