Skip to content

Commit

Permalink
building
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp committed Nov 17, 2021
1 parent 94a9c50 commit 78ead4f
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 1,127 deletions.
16 changes: 9 additions & 7 deletions algolia-typescript-template/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { {{classname}} } from '{{filename}}';

import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models';
{{#hasAuthMethods}}
import { HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models';
import { HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models';
{{/hasAuthMethods}}

import { HttpError, RequestFile } from './apis';
Expand Down Expand Up @@ -131,7 +131,7 @@ export class {{classname}} {
const path = '{{{path}}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};
let headers: Headers = {};
let queryParams: Record<string, string> = {};
let queryParameters: Record<string, string> = {};
{{#hasProduces}}
const produces = [{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}];
// give precedence to 'application/json'
Expand All @@ -154,7 +154,7 @@ export class {{classname}} {
{{/allParams}}
{{#queryParams}}
if ({{paramName}} !== undefined) {
queryParams['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
queryParameters['{{baseName}}'] = ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}");
}

{{/queryParams}}
Expand All @@ -165,14 +165,16 @@ export class {{classname}} {

const request: Request = {
method: '{{httpMethod}}',
url: path,
headers,
path,
{{#bodyParam}}
data: ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}")
{{/bodyParam}}
};

const requestOptions: RequestOptions = {};
const requestOptions: RequestOptions = {
headers,
queryParameters
};

let authenticationPromise = Promise.resolve();
{{#authMethods}}
Expand Down Expand Up @@ -206,7 +208,7 @@ export class {{classname}} {

await interceptorPromise;

return transporter.retryableRequest(request, requestOptions);
return this.transporter.retryableRequest(request, requestOptions);
}
{{/operation}}
}
Expand Down
5 changes: 3 additions & 2 deletions algolia-typescript-template/models.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export interface Authentication {
applyToRequest(requestOptions: RequestOptions): Promise<void> | void;
}
/*
export class HttpBasicAuth implements Authentication {
public username: string = '';
public password: string = '';
Expand All @@ -194,7 +195,7 @@ export class HttpBasicAuth implements Authentication {
username: this.username, password: this.password
}
}
}
}*/
export class HttpBearerAuth implements Authentication {
public accessToken: string | (() => string) = '';
Expand All @@ -217,7 +218,7 @@ export class ApiKeyAuth implements Authentication {
applyToRequest(requestOptions: RequestOptions): void {
if (this.location == "query") {
(<any>requestOptions.qs)[this.paramName] = this.apiKey;
requestOptions.queryParameters[this.paramName] = this.apiKey;
} else if (this.location == "header" && requestOptions && requestOptions.headers) {
requestOptions.headers[this.paramName] = this.apiKey;
} else if (this.location == 'cookie' && requestOptions && requestOptions.headers) {
Expand Down
10 changes: 3 additions & 7 deletions algolia-typescript-template/package.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
"test": "yarn build && node dist/client.js"
},
"engines": {
"node": ">= 12.0.0",
"yarn": ">= 2.0.0"
},
"dependencies": {
"@types/request": "^2.48.7",
"request": "^2.81.0"
"node": ">= 16.0.0",
"yarn": ">= 3.0.0"
},
"devDependencies": {
"@types/node": "^16.11.6",
Expand All @@ -29,4 +25,4 @@
"publishConfig": {
"registry": "{{npmRepository}}"
}{{/npmRepository}}
}
}
3 changes: 2 additions & 1 deletion algolia-typescript-template/tsconfig.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"declaration": true,
"lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"],
"outDir": "dist",
"typeRoots": ["node_modules/@types"]
"typeRoots": ["node_modules/@types"],
"types": ["node"]
},
"include": ["client-search", "model", "api.ts"],
"exclude": ["dist", "node_modules"]
Expand Down
1 change: 1 addition & 0 deletions complement/Requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class Requester {
this.httpAgent = new http.Agent({ keepAlive: true });
this.httpsAgent = new https.Agent({ keepAlive: true });
}

async send(request: EndRequest): Promise<Response> {
return new Promise((resolve) => {
const url = new URL(request.url);
Expand Down
3 changes: 2 additions & 1 deletion complement/Transporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Timeouts,
Response,
Outcomes,
EndRequest,
} from './types';
import { MemoryCache } from './MemoryCache';
import type { Cache } from './Cache';
Expand Down Expand Up @@ -137,7 +138,7 @@ export class Transporter {
throw new RetryError(stackTrace);
}

const payload = {
const payload: EndRequest = {
data,
headers,
method,
Expand Down
4 changes: 1 addition & 3 deletions complement/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export function deserializeSuccess<TObject>(response: Response): TObject {
try {
return JSON.parse(response.content);
} catch (e) {
if (e instanceof Error) {
throw new DeserializationError(e.message, response);
}
throw new DeserializationError((e as Error).message, response);
}
}

Expand Down
4 changes: 2 additions & 2 deletions complement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type RequestOptions = {
* Custom query parameters for the request. This query parameters are
* going to be merged the transporter query parameters.
*/
queryParameters?: Record<string, any>;
queryParameters: Record<string, any>;
data?: Record<string, any>;
};

Expand All @@ -34,7 +34,7 @@ export type EndRequest = {
connectTimeout: number;
responseTimeout: number;
headers: Headers;
data: string;
data?: string;
};

export type Response = {
Expand Down
38 changes: 22 additions & 16 deletions output/client-search/searchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MultipleQueriesResponse } from '../model/multipleQueriesResponse';
import { SaveObjectResponse } from '../model/saveObjectResponse';

import { ObjectSerializer, Authentication, VoidAuth, Interceptor } from '../model/models';
import { HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models';
import { HttpBearerAuth, ApiKeyAuth, OAuth } from '../model/models';

import { HttpError, RequestFile } from './apis';

Expand Down Expand Up @@ -86,7 +86,7 @@ export class SearchApi {
encodeURIComponent(String(indexName))
);
let headers: Headers = {};
let queryParams: Record<string, string> = {};
let queryParameters: Record<string, string> = {};
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand All @@ -110,12 +110,14 @@ export class SearchApi {

const request: Request = {
method: 'POST',
url: path,
headers,
path,
data: ObjectSerializer.serialize(batchObject, 'BatchObject'),
};

const requestOptions: RequestOptions = {};
const requestOptions: RequestOptions = {
headers,
queryParameters,
};

let authenticationPromise = Promise.resolve();
if (this.authentications.apiKey.apiKey) {
Expand All @@ -139,7 +141,7 @@ export class SearchApi {

await interceptorPromise;

return transporter.retryableRequest(request, requestOptions);
return this.transporter.retryableRequest(request, requestOptions);
}
/**
*
Expand All @@ -152,7 +154,7 @@ export class SearchApi {
): Promise<{ response: http.IncomingMessage; body: MultipleQueriesResponse }> {
const path = '/1/indexes/*/queries';
let headers: Headers = {};
let queryParams: Record<string, string> = {};
let queryParameters: Record<string, string> = {};
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand All @@ -173,12 +175,14 @@ export class SearchApi {

const request: Request = {
method: 'POST',
url: path,
headers,
path,
data: ObjectSerializer.serialize(multipleQueriesObject, 'MultipleQueriesObject'),
};

const requestOptions: RequestOptions = {};
const requestOptions: RequestOptions = {
headers,
queryParameters,
};

let authenticationPromise = Promise.resolve();
if (this.authentications.apiKey.apiKey) {
Expand All @@ -202,7 +206,7 @@ export class SearchApi {

await interceptorPromise;

return transporter.retryableRequest(request, requestOptions);
return this.transporter.retryableRequest(request, requestOptions);
}
/**
* Add an object to the index, automatically assigning it an object ID
Expand All @@ -220,7 +224,7 @@ export class SearchApi {
encodeURIComponent(String(indexName))
);
let headers: Headers = {};
let queryParams: Record<string, string> = {};
let queryParameters: Record<string, string> = {};
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
Expand Down Expand Up @@ -248,12 +252,14 @@ export class SearchApi {

const request: Request = {
method: 'POST',
url: path,
headers,
path,
data: ObjectSerializer.serialize(requestBody, '{ [key: string]: object; }'),
};

const requestOptions: RequestOptions = {};
const requestOptions: RequestOptions = {
headers,
queryParameters,
};

let authenticationPromise = Promise.resolve();
if (this.authentications.apiKey.apiKey) {
Expand All @@ -277,6 +283,6 @@ export class SearchApi {

await interceptorPromise;

return transporter.retryableRequest(request, requestOptions);
return this.transporter.retryableRequest(request, requestOptions);
}
}
1 change: 1 addition & 0 deletions output/complement
21 changes: 0 additions & 21 deletions output/complement/Cache.ts

This file was deleted.

27 changes: 0 additions & 27 deletions output/complement/MemoryCache.ts

This file was deleted.

Loading

0 comments on commit 78ead4f

Please sign in to comment.