With the following generic trigger function:
CREATE OR REPLACE FUNCTION allow_updating_only()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
DECLARE
whitelist TEXT[] := TG_ARGV::TEXT[];
schema_table TEXT;
With the following generic trigger function:
CREATE OR REPLACE FUNCTION allow_updating_only()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
DECLARE
whitelist TEXT[] := TG_ARGV::TEXT[];
schema_table TEXT;
Use Caddy (brew install caddy
) to run localhost sites with custom addresses and https certificates.
caddy reverse-proxy --from site.localhost --to localhost:3000
https://site.localhost/
For a more stable config, create a Caddyfile
site.localhost {
reverse_proxy localhost:3000
export type SingletonAsyncFn<Args extends any[], Result> = { | |
getCurrent(): Promise<Result> | null | |
} & ((...args: Args) => Promise<Result>) | |
/** Wrap an async function so only one instance runs at the time | |
* and concurrent calls await the running instance | |
* | |
* @example | |
* const getRand = makeSingletonAsyncFn(() => new Promise<number>(resolve => setTimeout(() => resolve(Math.random()), 1000))) | |
* console.log(await Promise.all([getRand(), getRand()])) // e.g. [0.6214563565449123, 0.6214563565449123] after 1sec |
import * as z from 'zod' | |
function zJson <T extends z.ZodTypeAny> (schema: T) { | |
return z.string().transform((val, ctx) => { | |
try { | |
return JSON.parse(val) | |
} catch (err) { | |
ctx.addIssue({ | |
code: z.ZodIssueCode.custom, | |
message: 'Invalid JSON', |
Updated Jan 2024. For looking up trending newer alternatives, use npmtrends. For Nodejs, nodejstoolbox a precompiled list of trends by category.
Standard libs extend the runtime with convenience helpers, structures and patterns.
type User = { | |
name: string | |
age: number | |
} | |
const users: User[] = [ | |
{ name: 'Adibou', age: 30 }, | |
{ name: 'Bounda', age: 69 }, | |
{ name: 'Adibou', age: 18 }, | |
] |
export function createStructuredError< | |
ErrorCodes extends Record<any, (data: any) => string> | |
>(name: string, codes: ErrorCodes) { | |
return class StructuredError< | |
ErrorCode extends keyof ErrorCodes, | |
ErrorData extends Parameters<ErrorCodes[ErrorCode]>[0] | |
> extends Error { | |
constructor( | |
public readonly code: ErrorCode, | |
public readonly data: ErrorData |
class Emitter<Events extends Record<any, (val: any) => any>> { | |
private observers: Map<keyof Events, Set<(val: any) => any>> = new Map() | |
on<Name extends keyof Events, Fn extends Events[Name]>(name: Name, fn: Fn) { | |
if (!this.observers.has(name)) { | |
this.observers.set(name, new Set()) | |
} | |
this.observers.get(name)!.add(fn) |