This file contains 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
#!/bin/bash | |
blueutil -p 0 | |
sleep 1 | |
blueutil -p 1 |
This file contains 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
public interface IUserRepoSearchActor : IActor | |
{ | |
Task<Result<SearchOutput>> SearchAsync(SearchInput input); | |
Task SetUserInfoAsync(UserInfo userInfo); | |
Task SetRepositoryAsync(Repository repository); | |
Task<AutoCompleteOutput> AutoCompleteAsync(SearchInput input); | |
Task<SearchOutput> GetSuggestionsAsync(SearchInput input); | |
} |
This file contains 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
function sendRequest<TInput, TOutput>( | |
endpoint: ApiEndpoint<TInput, TOutput>, | |
data?: TInput) { | |
return request<TOutput>({ | |
url: endpoint.pathStr(), | |
data: data, | |
method: 'POST' | |
}); | |
} |
This file contains 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
// Initialize the express server | |
const server = express(); | |
server.use(bodyParser.json()); | |
// Mount the recipes API handlers | |
const mounter = new ExpressApiMounter(server); | |
mounter.mountHandler(api.recipe.create, create); | |
mounter.mountHandler(api.recipe.read, read); | |
mounter.mountHandler(api.recipe.update, update); | |
mounter.mountHandler(api.recipe.destroy, destroy); |
This file contains 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
export function setPaths<T>( | |
space: T, path: string[] = [], | |
clone: boolean = true) { | |
if (!space) return space; | |
let result = clone ? cloneDeep(space) : space; | |
for (const key in result) { | |
if (result.hasOwnProperty(key)) { |
This file contains 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
export default class ExpressApiMounter implements ApiMounter { | |
constructor(public readonly router: Router) { } | |
mountHandler<TInput, TOutput>( | |
endpoint: ApiEndpoint<TInput, TOutput>, | |
handler: ApiHandler<TInput, TOutput>): void { | |
this.router.post(endpoint.pathStr(), async (req, res) => { | |
const output = await handler(req.body as TInput); | |
res.json(output); |
This file contains 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
export interface ApiMounter { | |
mountHandler<TInput, TOutput>( | |
endpoint: ApiEndpoint<TInput, TOutput>, | |
handler: ApiHandler<TInput, TOutput>): void | |
} |
This file contains 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
export interface RequestHandler { | |
(req: Request, res: Response, next: NextFunction): any; | |
} |
This file contains 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
export type ApiHandler<TInput, TOutput> = | |
(data: TInput) => Promise<TOutput> |
This file contains 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
const api = { | |
create: new ApiEndpoint<Recipe, Recipe>(), | |
read: new ApiEndpoint<FindParams, Recipe>(), | |
update: new ApiEndpoint<Recipe, Recipe>(), | |
destroy: new ApiEndpoint<FindParams, undefined>(), | |
list: new ApiEndpoint<undefined, Recipe[]>() | |
}; |
NewerOlder