diff --git a/packages/sdk/scripts/config.json b/packages/sdk/scripts/config.json new file mode 100644 index 0000000000..a6a3e1acb8 --- /dev/null +++ b/packages/sdk/scripts/config.json @@ -0,0 +1,3 @@ +{ + "usePromises": true +} \ No newline at end of file diff --git a/packages/sdk/scripts/generate-sdk.sh b/packages/sdk/scripts/generate-sdk.sh index 88fbde906a..82cb3f1d36 100755 --- a/packages/sdk/scripts/generate-sdk.sh +++ b/packages/sdk/scripts/generate-sdk.sh @@ -17,12 +17,13 @@ cp ../../server/specs/openapi.yaml ./ docker run --rm \ -v ${PWD}/openapi.yaml:/openapi.yml \ -v ${PWD}/generated:/generated \ + -v ${PWD}/config.json:/config.json \ -u $(id -u):$(id -g) \ swaggerapi/swagger-codegen-cli-v3 generate \ -i /openapi.yml \ -l javascript \ - -o /generated - --additional-properties useES6=false + -o /generated \ + -c /config.json # Use a subset of the generated files mv generated/src ../sdk diff --git a/packages/sdk/src/index.js b/packages/sdk/src/index.js index e56ef051f7..23b3f9507e 100644 --- a/packages/sdk/src/index.js +++ b/packages/sdk/src/index.js @@ -15,37 +15,8 @@ export const configure = ({ apiKey, host }) => { ApiClient.basePath = `${host || ""}/api/public/v1` } -/** - * Promisifies a generated API SDK and turns it into a more traditional async - * function. - * @param apiName the name of the generated API SDK to promisify - */ -const promisify = apiName => { - // Construct an instance of the generated API - let api = new BudibaseApi[apiName](ApiClient) - - // Patch each API endpoint and promisify it - let fns = Object.getOwnPropertyNames(Object.getPrototypeOf(api)) - fns = fns.filter(x => x !== "constructor") - fns.forEach(fn => { - const generated = api[fn].bind(api) - api[fn] = async (...params) => { - return new Promise((resolve, reject) => { - generated(...params, (error, data) => { - if (error) { - reject(error) - } else { - resolve(data) - } - }) - }) - } - }) - return api -} - -export const ApplicationsApi = promisify("ApplicationsApi") -export const QueriesApi = promisify("QueriesApi") -export const RowsApi = promisify("RowsApi") -export const TablesApi = promisify("TablesApi") -export const UsersApi = promisify("UsersApi") +export const ApplicationsApi = new BudibaseApi.ApplicationsApi(ApiClient) +export const QueriesApi = new BudibaseApi.QueriesApi(ApiClient) +export const RowsApi = new BudibaseApi.RowsApi(ApiClient) +export const TablesApi = new BudibaseApi.TablesApi(ApiClient) +export const UsersApi = new BudibaseApi.UsersApi(ApiClient)