HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
appliedblockchain
assert-combinators
TypeScript2020–2023
appliedblockchain / assert-combinators · Archived

assert-combinators

Functional assertion combinators.

2Distinct people
13Mentions
0Explicit recommenders
24GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Functional assertion combinators.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 12:54:37 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year13 dated mentions

Observed mentions: 2020-03-13 00:00:19 UTC to 2023-06-24 14:47:29 UTC.

02462020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 6 mentions; 0 submissions, 6 comments20212022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2023

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC202
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC606
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC303
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC202

What Hacker News says

13 sources
This can't be solved by static analysis - anything that crosses i/o boundary has to be asserted, refuted or predicated at runtime and you have libraries for it ie. [0] which doesn't throw (based on refutations which can be mapped to predicates without much cost and assertions) or [1] which throws (based on assertions). Predicates are the most performant but won't give you any indication on why it failed (ie. some nested field was null but was expected to be number etc). Refutations is great sweet spot as it's fast while giving information about error. Assertions are slow, but more often than not you don't care. You can map between any of them, but it doesn't make much sense for mapping ie. assertion to predicate as you'd be paying cost for nested try/catch while dropping error information. Refutation is great base for all 3. [0] https://g
Read the rest
In Why doesn't TypeScript properly type Object.keys?
We use in prod variant of no 1. [0]. Why? Because: * it's sql * it's extremely lightweight (built on pure, functional combinators) * it allows us to use more complex patterns ie. convention where every json field ends with Json which is automatically parsed; which, unlike datatype alone, allows us to create composable query to fetch arbitrarily nested graphs and promoting single [$] key ie. to return list of emails as `string[]` not `{ email: string }[]` with `select email as [$] from Users` etc. * has convenience combinators for things like constructing where clauses from monodb like queries * all usual queries like CRUD, exists etc. and some more complex sql-wise but simple function-api-wise ie. insertIgnore list of objects, merge1n, upsert etc all have convenient function apis and allow for composing whatever more is needed for the pro
Read the rest
ject We resort to runtime type assertions [1] which works well for this and all other i/o; runtime type assertions are necessary for cases when your running service is incorrectly attached to old or future remote schema/api (there are other protections against it but still happens). [0] https://github.com/appliedblockchain/tsql [1] https://github.com/appliedblockchain/assert-combinators
In Kysely: TypeScript SQL Query Builder
We use not so much frameworks but combination of lightweight libraries: - runtime assertions [0] - to map unknown values at i/o boundary into statically typed code (rpc input parameters, sql results etc) - template based sql combinators to sanitize sql/generate sql [1] - jsonrpc over websockets - for bidirectional comms between f/e and b/e It works very well for us for hundreds of rpcs - it's easy to manage things like permissioning/narrowing visibility and other aspects you need in business/enterprise-like setting ie. performance monitoring is very easy/straight forward. [0] https://github.com/appliedblockchain/assert-combinators [1] https://github.com/appliedblockchain/tsql
In GraphJin – GraphQL to SQL Compiler
In js/ts-land going from unknown type to known one normally means: 1. JSON.parse(...) string to json value 2. runtime assert it ie. with [0] which is a form of parsing but on json input as opposed to string parsing In other words, when dealing with jsons, it's better to work on combinators over json values than combinators over string – the code is much more terse, natural and performant. [0] https://github.com/appliedblockchain/assert-combinators
In Parsing Text with Nom
Types can be asserted at runtime (parsed) at IO boundaries (reading http request or response, websocket message, parsing json file etc). Once they enter statically type system they don't need to be asserted again. The difference it makes is illusion of type-safety vs type-safety this article touches on. It's basically mapping of an `unknown` type into known one, at runtime. You can try to bind service with client (types) somehow but in many cases this will fail in production as you can't guarantee paired versioning, due to normal situations by design of your architecture or temporary mid-deployment state or other team doing something they were not suppose to do (new client is deployed connecting to old service or vice versa) etc. It's hard to avoid runtime parsing/type assertion in general. Functional combinator approaches like [0] or fas
Read the rest
ter [1] with predicate/assert semantics work very well with typescript, which is very pleasant language to work with. [0] https://github.com/appliedblockchain/assert-combinators [1] https://github.com/preludejs/refute
In An Inconsistent Truth: Next.js and Typesafety
from a look at the readme, you combine those `$.TYPE` things to build a validation function that checks if its argument matches some pattern (and throws an exception if it doesn't). import * as $ from '@appliedblockchain/assert-combinators' const validateFooBar = ( $.object({ foo: $.string, bar: $.boolean }) ) // probably roughly equivalent to /* const validateFooBar = (x) => { console.assert( typeof x === 'object' && typeof x.foo === 'string' && typeof x.bar === 'boolean' ) return x } */ const test1 = { foo: "abc", bar: false } const test2 = { foo: 0, quux: true } const { foo, bar } = validateFooBar(test1) // ok const oops = validateFooBar(test2) // throws error the source is pretty readable too if you want to get an idea how it works. https://github.com/appli
Read the rest
In Parse, Don't Validate (2019)
Imagine you're writing typescript project. You type everything and have type safety. This type safety is an illusion on I/O boundaries – whenever ie. JSON.parse(...) from file/websocket/http happens. To preserve type safety, you want to use something like [0] to do runtime type assertions. Once i/o boundaries are parsing unknown types at runtime into what is defined as static types, your type safety is guaranteed. [0] https://github.com/appliedblockchain/assert-combinators
In Parsix: Parse Don't Validate
We do for for managing stuff with many $1... zeros for serious top fortune companies in business critical projects. Java/Go type systems are primitive compared to typescript. Shallow or no dependencies, functional, ocaml like modules, pervasive use of algebraic types provided by ts (previously flow), several years in production, nice codebase, several successful, non-trivial major releases, constant updates with codebase worked on every day by many people, several deployments per month. Problems I personally have with it: 1. no exact object types in ts as in flow - means they have to be emulated by destructing, sad, but you can live with it/you have to be careful 2. transpile times - but recent experiments with swc for tranpilation and deferring typecheck to run concurrently while tests are kicked off after swc finishes look promising 3.
Read the rest
type system could be a bit smarter in few places, but no blockers so far I'd recommend but with caution - spectrum of developer's competency is closer to php (almost anybody can do it) than the one of languages like ocaml/haskell/rust and others (where entry bar is higher). Vet your dependencies, hire competent developers and it can work very well. Some of libraries we're using: - https://github.com/appliedblockchain/assert-combinators - light, runtime type assertions ("parse, don't validate" style to avoid illusion of type safety at io boundaries) - https://github.com/appliedblockchain/tsql - functional, tagged template based combinators for sql generation
In Node.js 16 Available Now
It's true, I like the feel of Haskell type annotations as well, but I'm working with js/flow in day-to-day job; finding mysqlf moving towards those one-line-type-annoations to mimick Haskell, I'm surprised flow actually handles most of the code, even not so trivial ones; inference is good enough that those one liners are most of the time all that's needed, examples are here [1] [2] [3] if somebody wants to peek. [1] https://github.com/appliedblockchain/tsql/ [2] https://github.com/appliedblockchain/parser-combinators [3] https://github.com/appliedblockchain/assert-combinators
In Gleam: A statically typed language for the Erlang VM

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.