Skip to content

Commit 6a27b5f

Browse files
committed
chore: 2024 unfinished
1 parent be0e375 commit 6a27b5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3056
-12622
lines changed

.eslintrc.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/semantic.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
dist
1+
dist/*
2+
!dist/.gitkeep
23
node_modules
34
tsconfig.tsbuildinfo
45
.env
6+
.DS_Store

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 20.12.1

CONTRIBUTING.md

Lines changed: 0 additions & 68 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Tim Kinnane
3+
Copyright (c) 2024 Tim Kinnane
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ A small but powerful functional programming utility for type-safe pipe-like oper
1212
---
1313

1414
Assemble composes arrays of functions that pick from and assign to a given type (assembling it).
15+
1516
The composed "assembly" is like a pipe that steps through each function, merging input with any
16-
returned props and passing it to the next, returning the assembled result. Common use cases would be
17-
applying a sequence of functions to app state, DB or API results.
17+
returned props and passing it to the next, returning the assembled result.
18+
19+
Common use cases would be applying a sequence of functions to app state, DB or API results.
1820

1921
The focus of Assemble is to encourage an approach to function composition that is versatile yet
2022
simple to reason about and is type-safe with minimal definition overhead.
@@ -27,9 +29,9 @@ This sample shows two "assemblers" operating on a props type. These functions be
2729
hinting for the props they can access and if defined, the props they need to return.
2830

2931
```ts
30-
import { assemble, Assembler, VoidAssembler } from '@os-gurus/assemble'
32+
import { assemble, Assembler, NonAssembler } from '@os-gurus/assemble'
3133

32-
interface Props {
34+
type Props = {
3335
name: string
3436
message?: string
3537
}
@@ -39,7 +41,7 @@ const prepareMessage: Assembler<Props, 'message'> = ({ name }) => {
3941
}
4042
// ☝️ Must return { message }
4143

42-
const logMessage: VoidAssembler<Props> = ({ message }) => {
44+
const logMessage: NonAssembler<Props> = ({ message }) => {
4345
console.log(message)
4446
}
4547
// ☝️ Must return void
@@ -54,11 +56,11 @@ sayHello({ name: 'World' })
5456

5557
### Assembler Functions
5658

57-
The `Assembler`, `PartialAssembler` and `VoidAssembler` type utilities define functions that can
59+
The `Assembler`, `PartialAssembler` and `NonAssembler` type utilities define functions that can
5860
be given to `assemble` and declare the props type they will operate on.
5961
- `Assembler` functions return a subset of props, as defined by keys given to the utility.
6062
- `PartialAssembler` functions optionally return a subset of props as defined.
61-
- `VoidAssembler` functions return void, but can use the props, e.g. for logging or sending.
63+
- `NonAssembler` functions return undefined but can use the props, e.g. for logging or sending.
6264

6365
Note, you don't have to use these utilities. Any function signature can be given to `assemble` as
6466
long as it accepts a single props object argument and returns either a subset of props or nothing.
@@ -77,7 +79,7 @@ Assembler<Props, 'name' | 'message'>
7779
PartialAssembler<Props, 'message'>
7880
// ➥ (props: Props) => { message?: string } | undefined
7981

80-
VoidAssembler<Props>
82+
NonAssembler<Props>
8183
// ➥ (props: Props) => void
8284
```
8385

@@ -86,15 +88,15 @@ VoidAssembler<Props>
8688
### Async Assemblers
8789

8890
`AsyncAssembler` works exactly as `Assembler` for asynchronous functions and `assemble` can compose
89-
a mixture of async and sync assemblers. As do `AsyncPartialAssembler` and `AsyncVoidAssembler`.
91+
a mixture of async and sync assemblers. As do `AsyncPartialAssembler` and `AsyncNonAssembler`.
9092

9193
`assembleSync` can be used to enforce synchronous functions and a non-promise return.
9294

9395
```ts
9496
import fetch from 'node-fetch'
95-
import { assemble, Assembler, AsyncAssembler, VoidAssembler } from '@os-gurus/assemble'
97+
import { assemble, Assembler, AsyncAssembler, NonAssembler } from '@os-gurus/assemble'
9698

97-
interface Props {
99+
type Props = {
98100
name?: string
99101
message?: string
100102
}
@@ -109,8 +111,9 @@ const prepareMessage: Assembler<Props, 'message'> = ({ name }) => {
109111
return { message: `Hello ${name}` }
110112
}
111113

112-
const logMessage: VoidAssembler<Props> = ({ message }) => {
114+
const logMessage: NonAssembler<Props> = ({ message }) => {
113115
console.log(message)
116+
return undefined // see known issues below
114117
}
115118

116119
const sayHello = assemble(fetchName, prepareMessage, logMessage)
@@ -158,6 +161,16 @@ mixedAssembly({ b: true })
158161

159162
### Known Issues
160163

164+
**Partial Assembler has to return undefined**
165+
166+
I tried to make void and partial assemblers that didn't need to return explicit undefined. This
167+
might have been nicer to use, but for now if they don't return a prop they must `return undefined`
168+
(or `{}` for partial assemblers only).
169+
170+
Unfortunately any async function type will not raise a type error when applied to a `() => void`
171+
type restriction. This meant by including void returning assemblers the `SyncAssemblers` type would
172+
allow async assemblers.
173+
161174
**Merged type constraints override**
162175

163176
Using `MergeUnion` on function's input and prop types to cast the return type of `assemble` creates

biome.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
3+
"files": {
4+
"ignore": [
5+
"node_modules",
6+
"dist"
7+
]
8+
},
9+
"organizeImports": {
10+
"enabled": true
11+
},
12+
"formatter": {
13+
"enabled": true,
14+
"indentStyle": "tab"
15+
},
16+
"linter": {
17+
"enabled": true,
18+
"rules": {
19+
"recommended": true
20+
}
21+
},
22+
"javascript": {
23+
"formatter": {
24+
"quoteStyle": "single",
25+
"semicolons": "asNeeded"
26+
}
27+
}
28+
}

dist/.gitkeep

Whitespace-only changes.

examples/TODO.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Make examples for docs
2+
- [ ] Screen cap type hinting and errors to show inferred type safety
3+
- [ ] assemble type error when function added with required props that weren't required prior

0 commit comments

Comments
 (0)