Skip to content

Commit 3808198

Browse files
committed
feat: move init from extended class to template
1 parent ec4bf6f commit 3808198

File tree

8 files changed

+23
-46
lines changed

8 files changed

+23
-46
lines changed

algolia-typescript-template/api-all.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ export class HttpError extends Error {
1919

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

22+
export class searchClient extends SearchApi{}
23+
2224
export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
2325
{{/apiInfo}}

algolia-typescript-template/api-single.mustache

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,14 @@ export class {{classname}} {
5959

6060
protected interceptors: Interceptor[] = [];
6161

62-
constructor(basePath?: string);
63-
{{#authMethods}}
64-
{{#isBasicBasic}}
65-
constructor(username: string, password: string, basePath?: string);
66-
{{/isBasicBasic}}
67-
{{/authMethods}}
68-
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
69-
if (password) {
70-
{{#authMethods}}
71-
{{#isBasicBasic}}
72-
this.username = basePathOrUsername;
73-
this.password = password
74-
{{/isBasicBasic}}
75-
{{/authMethods}}
76-
if (basePath) {
77-
this.basePath = basePath;
78-
}
79-
} else {
80-
if (basePathOrUsername) {
81-
this.basePath = basePathOrUsername
82-
}
62+
constructor(appId: string, apiKey: string, basePath?: string) {
63+
64+
this.setApiKey(SearchApiApiKeys.appId, appId);
65+
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
66+
this.basePath = 'https://' + appId + '-1.algolianet.com';
67+
68+
if (basePath) {
69+
this.basePath = basePath;
8370
}
8471
}
8572

app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { searchClient } from './searchClient';
1+
import { searchClient } from 'algoliasearch-client-javascript';
22

33
const appId = process.env.ALGOLIA_APPLICATION_ID_1 || '**** APP_ID *****';
44
const apiKey = process.env.ALGOLIA_ADMIN_KEY_1 || '**** API_KEY *****';

output/client-search/apis.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ export class HttpError extends Error {
1111

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

14+
export class searchClient extends SearchApi {}
15+
1416
export const APIS = [SearchApi];

output/client-search/searchApi.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,13 @@ export class SearchApi {
3636

3737
protected interceptors: Interceptor[] = [];
3838

39-
constructor(basePath?: string);
40-
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
41-
if (password) {
42-
if (basePath) {
43-
this.basePath = basePath;
44-
}
45-
} else {
46-
if (basePathOrUsername) {
47-
this.basePath = basePathOrUsername;
48-
}
39+
constructor(appId: string, apiKey: string, basePath?: string) {
40+
this.setApiKey(SearchApiApiKeys.appId, appId);
41+
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
42+
this.basePath = 'https://' + appId + '-1.algolianet.com';
43+
44+
if (basePath) {
45+
this.basePath = basePath;
4946
}
5047
}
5148

searchClient.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"outDir": "dist",
1717
"typeRoots": ["node_modules/@types"]
1818
},
19-
"include": ["searchClient.ts", "app.ts"]
19+
"include": ["app.ts"]
2020
}

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ __metadata:
226226

227227
"algoliasearch-client-javascript@file:output/::locator=%40algolia%2Fautomation-javascript-client%40workspace%3A.":
228228
version: 5.0.0
229-
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=d8075e&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
229+
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=342434&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
230230
dependencies:
231231
"@types/request": ^2.48.7
232232
request: ^2.81.0
233-
checksum: e5b977ffab9bcff3a3d3ef9754c43424b825a47865cff391483674c4d837f579687d4ff5c8243acf3ca7a0d7d8f042dec1a1ed4659f7898ac6cc3851dfb02b40
233+
checksum: 79ae2881a4d93698d4600f7710ea07512df105e9faf61982acc2cc8327d1666fe39f7e83c4a4d471b1876c321b932850a49923a49d22d474bacdf16dfaa81e71
234234
languageName: node
235235
linkType: hard
236236

0 commit comments

Comments
 (0)