-
Notifications
You must be signed in to change notification settings - Fork 21
chore(repository): improve repository structure and naming #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
646d7de
chore(repository): improve repository structure and naming
shortcuts 0fc7f37
fix: pin typescript version
shortcuts ad3f6c9
add playground folder, rename template
shortcuts ebce6f7
remove old search spec, fix typo in contribution guide
shortcuts bc4e6fb
remove `package` field from workspace
shortcuts 56e9bd5
add `playground:js` workspace command
shortcuts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Clients | ||
|
||
This folder hosts the generated clients and their utils. | ||
|
||
## Generated clients | ||
|
||
- [algoliasearch-client-javascript](./algoliasearch-client-javascript/): The Algolia JavaScript client. | ||
shortcuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Utils | ||
|
||
- [JavaScript](./utils/javascript/): The Algolia JavaScript utils. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
output/client-search/searchApi.ts → ...ent-javascript/client-search/searchApi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
output/model/models.ts → ...asearch-client-javascript/model/models.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface Cache { | ||
/** | ||
* Gets the value of the given `key`. | ||
*/ | ||
get: <TValue>(key: object | string, defaultValue: () => Promise<TValue>) => Promise<TValue>; | ||
|
||
/** | ||
* Sets the given value with the given `key`. | ||
*/ | ||
set: <TValue>(key: object | string, value: TValue) => Promise<TValue>; | ||
|
||
/** | ||
* Deletes the given `key`. | ||
*/ | ||
delete: (key: object | string) => Promise<void>; | ||
|
||
/** | ||
* Clears the cache. | ||
*/ | ||
clear: () => Promise<void>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Cache } from './Cache'; | ||
|
||
export class MemoryCache implements Cache { | ||
private cache: Record<string, any> = {}; | ||
|
||
async get<TValue>(key: object | string, defaultValue: () => Promise<TValue>): Promise<TValue> { | ||
const keyAsString = JSON.stringify(key); | ||
|
||
if (keyAsString in this.cache) { | ||
return Promise.resolve(this.cache[keyAsString]); | ||
} | ||
return await defaultValue(); | ||
} | ||
|
||
async set<TValue>(key: object | string, value: TValue): Promise<TValue> { | ||
this.cache[JSON.stringify(key)] = value; | ||
return value; | ||
} | ||
|
||
async delete(key: object | string): Promise<void> { | ||
delete this.cache[JSON.stringify(key)]; | ||
} | ||
|
||
async clear(): Promise<void> { | ||
this.cache = {}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { EndRequest, Response } from './types'; | ||
import * as http from 'http'; | ||
import * as https from 'https'; | ||
|
||
export class Requester { | ||
private httpAgent: http.Agent; | ||
private httpsAgent: https.Agent; | ||
|
||
constructor() { | ||
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); | ||
|
||
const path = url.search === null ? url.pathname : `${url.pathname}?${url.search}`; | ||
|
||
const options: https.RequestOptions = { | ||
agent: url.protocol === 'https:' ? this.httpsAgent : this.httpAgent, | ||
hostname: url.hostname, | ||
path, | ||
method: request.method, | ||
headers: request.headers, | ||
...(url.port !== undefined ? { port: url.port || '' } : {}), | ||
}; | ||
|
||
const req = (url.protocol === 'https:' ? https : http).request(options, (response) => { | ||
let contentBuffers: Buffer[] = []; | ||
|
||
response.on('data', (chunk) => { | ||
contentBuffers = contentBuffers.concat(chunk); | ||
}); | ||
|
||
response.on('end', () => { | ||
clearTimeout(connectTimeout); | ||
clearTimeout(responseTimeout as NodeJS.Timeout); | ||
|
||
resolve({ | ||
status: response.statusCode || 0, | ||
content: Buffer.concat(contentBuffers).toString(), | ||
isTimedOut: false, | ||
}); | ||
}); | ||
}); | ||
|
||
const createTimeout = (timeout: number, content: string): NodeJS.Timeout => { | ||
return setTimeout(() => { | ||
req.destroy(); | ||
|
||
resolve({ | ||
status: 0, | ||
content, | ||
isTimedOut: true, | ||
}); | ||
}, timeout * 1000); | ||
}; | ||
|
||
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout'); | ||
|
||
let responseTimeout: NodeJS.Timeout | undefined; | ||
|
||
req.on('error', (error) => { | ||
clearTimeout(connectTimeout); | ||
clearTimeout(responseTimeout as NodeJS.Timeout); | ||
resolve({ status: 0, content: error.message, isTimedOut: false }); | ||
}); | ||
|
||
req.once('response', () => { | ||
clearTimeout(connectTimeout); | ||
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout'); | ||
}); | ||
|
||
if (request.data !== undefined) { | ||
req.write(request.data); | ||
} | ||
|
||
req.end(); | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Host } from './types'; | ||
|
||
const EXPIRATION_DELAY = 2 * 60 * 1000; | ||
|
||
export class StatefulHost implements Host { | ||
url: string; | ||
accept: 'read' | 'write' | 'readWrite'; | ||
protocol: 'http' | 'https'; | ||
|
||
private lastUpdate: number; | ||
private status: 'up' | 'down' | 'timedout'; | ||
|
||
constructor(host: Host, status: StatefulHost['status'] = 'up') { | ||
this.url = host.url; | ||
this.accept = host.accept; | ||
this.protocol = host.protocol; | ||
|
||
this.status = status; | ||
this.lastUpdate = Date.now(); | ||
} | ||
|
||
isUp(): boolean { | ||
return this.status === 'up' || Date.now() - this.lastUpdate > EXPIRATION_DELAY; | ||
} | ||
|
||
isTimedout(): boolean { | ||
return this.status === 'timedout' && Date.now() - this.lastUpdate <= EXPIRATION_DELAY; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.