Skip to content

Commit

Permalink
feat: move init from extended class to template
Browse files Browse the repository at this point in the history
  • Loading branch information
damcou committed Nov 15, 2021
1 parent ec4bf6f commit 3808198
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 46 deletions.
2 changes: 2 additions & 0 deletions algolia-typescript-template/api-all.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ export class HttpError extends Error {

export { RequestFile } from '../model/models';

export class searchClient extends SearchApi{}

export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
{{/apiInfo}}
29 changes: 8 additions & 21 deletions algolia-typescript-template/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,14 @@ export class {{classname}} {

protected interceptors: Interceptor[] = [];

constructor(basePath?: string);
{{#authMethods}}
{{#isBasicBasic}}
constructor(username: string, password: string, basePath?: string);
{{/isBasicBasic}}
{{/authMethods}}
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) {
{{#authMethods}}
{{#isBasicBasic}}
this.username = basePathOrUsername;
this.password = password
{{/isBasicBasic}}
{{/authMethods}}
if (basePath) {
this.basePath = basePath;
}
} else {
if (basePathOrUsername) {
this.basePath = basePathOrUsername
}
constructor(appId: string, apiKey: string, basePath?: string) {
this.setApiKey(SearchApiApiKeys.appId, appId);
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
this.basePath = 'https://' + appId + '-1.algolianet.com';
if (basePath) {
this.basePath = basePath;
}
}

Expand Down
2 changes: 1 addition & 1 deletion app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { searchClient } from './searchClient';
import { searchClient } from 'algoliasearch-client-javascript';

const appId = process.env.ALGOLIA_APPLICATION_ID_1 || '**** APP_ID *****';
const apiKey = process.env.ALGOLIA_ADMIN_KEY_1 || '**** API_KEY *****';
Expand Down
2 changes: 2 additions & 0 deletions output/client-search/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export class HttpError extends Error {

export { RequestFile } from '../model/models';

export class searchClient extends SearchApi {}

export const APIS = [SearchApi];
17 changes: 7 additions & 10 deletions output/client-search/searchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ export class SearchApi {

protected interceptors: Interceptor[] = [];

constructor(basePath?: string);
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) {
if (basePath) {
this.basePath = basePath;
}
} else {
if (basePathOrUsername) {
this.basePath = basePathOrUsername;
}
constructor(appId: string, apiKey: string, basePath?: string) {
this.setApiKey(SearchApiApiKeys.appId, appId);
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
this.basePath = 'https://' + appId + '-1.algolianet.com';

if (basePath) {
this.basePath = basePath;
}
}

Expand Down
11 changes: 0 additions & 11 deletions searchClient.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"outDir": "dist",
"typeRoots": ["node_modules/@types"]
},
"include": ["searchClient.ts", "app.ts"]
"include": ["app.ts"]
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ __metadata:

"algoliasearch-client-javascript@file:output/::locator=%40algolia%2Fautomation-javascript-client%40workspace%3A.":
version: 5.0.0
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=d8075e&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=342434&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
dependencies:
"@types/request": ^2.48.7
request: ^2.81.0
checksum: e5b977ffab9bcff3a3d3ef9754c43424b825a47865cff391483674c4d837f579687d4ff5c8243acf3ca7a0d7d8f042dec1a1ed4659f7898ac6cc3851dfb02b40
checksum: 79ae2881a4d93698d4600f7710ea07512df105e9faf61982acc2cc8327d1666fe39f7e83c4a4d471b1876c321b932850a49923a49d22d474bacdf16dfaa81e71
languageName: node
linkType: hard

Expand Down

0 comments on commit 3808198

Please sign in to comment.