import { sortBy, pick } from 'lodash'; | |
/** | |
* NOT A REAL IMPLEMENTATION!! This is just a high level example of how | |
* dynamo stores data. | |
*/ | |
type Row = { | |
hashKey: string; | |
rangeKey: string; | |
[k: string]: any; |
#!/usr/bin/env node | |
const { exec } = require('child_process'); | |
const { resolve } = require('path'); | |
const cwd = process.argv[2] ? resolve(process.argv[2]) : process.cwd(); | |
const maxBuffer = 10 * 1024 * 1024; | |
const execShell = (command) => { | |
return new Promise((resolve) => { | |
exec(command, { cwd, maxBuffer }, (error, stdout, stderr) => { |
type Semaphore = { | |
acquire: () => Promise<void>; | |
release: () => void; | |
}; | |
export const simpleSemaphore = (size: number): Semaphore => { | |
const waiting: (() => void)[] = []; | |
let available = size; | |
const acquire = async (): Promise<void> => { |
Originally introduced by yarn
, starting with version 7 npm
also provides support for this.
Workspaces are first-class support in the package manager for monorepo structures in npm packages. A monorepo is simply a collection of related packages, and having them share a single git repo can help eliminate a lot of redundancy in the project setup, as well as make it easier to work with interdependencies during development.
They're relatively simple. They consist of:
- a parent directory whose
package.json
contains a list (or wildcard pattern) defining subprojects
Here, I am going to examine NestJS -- primarily focusing on its dependency injection --
Nest's DI system is based on a custom-defined module system. For every service defined in the application, there is a module file that "owns" that service. I use the term "service" loosely here to simply mean "anything we want to be part of the DI system". For example:
@Injectable()
These launch configs will allow you to debug typescript files directly from VSCode. It will honor the tsconfig
and resolve node modules properly. You do not need to install ts-node
or nodemon
, as everything is run using npx
. The first
{
"configurations": [
{
"type": "node",
"request": "launch",
/* eslint-disable @typescript-eslint/no-misused-promises */ | |
import { Readable, Transform, Writable } from 'node:stream' | |
import { pipeline } from 'node:stream/promises' | |
export const asyncHandler = (handle: (value: any) => Promise<void>) => { | |
return new Writable({ | |
objectMode: true, | |
write: async (value, _, next) => { | |
try { | |
await handle(value) |