Type-safe dependency injection.
Function-style:
const Foo = Context.Service<{
readonly bar: Effect.Effect<number>| try { | |
| const doc = await s3.getObject(); | |
| } catch (err) { | |
| // error is any or unknown | |
| if (err instanceof ObjectNotFoundError) { | |
| // TODO: handle error | |
| } | |
| } |
| import { reduceMap } from './reduce-map'; | |
| describe('reduceMap', () => { | |
| const sumValueAndSubtractKey = (result: number, value: number, key: number) => result + value - key; | |
| it('should return initial value for empty map', () => { | |
| expect( | |
| reduceMap( | |
| new Map(), | |
| sumValueAndSubtractKey, |
| import { Controller, ControllerOptions } from '@nestjs/common'; | |
| import { join } from 'path'; | |
| import { AuthenticationGuard, AccessControlGuard } from 'app/guards'; | |
| expose function AdminController(options: ControllerOptions) { | |
| return function (target: Function) { | |
| Controller(join('/admin', options.path))(target); | |
| AuthenticationGuard()(target); | |
| AccessControlGuard({ role: 'admin' })(target); | |
| }; |
| @AdminController(options) { | |
| @Controller({ path: '/admin' + options.path }) | |
| @AuthenticationGuard() | |
| @AccessControlGuard({ role: 'admin' }) | |
| } |
| import { Controller, Get } from '@nestjs/common'; | |
| import { AdminController, AccessControlGuard } from 'app/decorators'; | |
| @AdminController({ path: '/dashboard' }) | |
| export class AdminDashboardController { | |
| @Get() | |
| index(): string { | |
| return 'dashboard data for admin'; | |
| } | |
| } |
| import { Controller, Get } from '@nestjs/common'; | |
| import { AuthenticationGuard, AccessControlGuard } from 'app/decorators'; | |
| @Controller({ path: '/admin/dashboard' }) | |
| @AuthenticationGuard() | |
| @AccessControlGuard({ role: 'admin' }) | |
| export class AdminDashboardController { | |
| @Get() | |
| index(): string { | |
| return 'dashboard data for admin'; |
| import { Controller, Get } from '@nestjs/common'; | |
| @Controller('/cats') | |
| export class CatsController { | |
| @Get() | |
| findAll(): string { | |
| return 'This action returns all cats'; | |
| } | |
| } |
| resource "google_cloud_run_service_iam_binding" "binding" { | |
| location = google_cloud_run_service.nodejs_app.location | |
| service = google_cloud_run_service.nodejs_app.name | |
| role = "roles/run.invoker" | |
| members = [ | |
| "allUsers", | |
| ] | |
| } |
| variable "app_name" { | |
| type=string | |
| } | |
| variable "image_tag" { type=string } | |
| resource "google_cloud_run_service" "nodejs_app" { | |
| name = var.app_name | |
| location = "us-central1" | |