Skip to content

Commit

Permalink
Typescript d.ts (v2) (#53)
Browse files Browse the repository at this point in the history
* all

* assemble

* Works but dangerous

* Working!

* Even better

* assembleP

* assocWith

* assocWithP

* backoff

* Batch

* combine

* combineAll

* combineAllP

* combineP

* combineWith

* Dep shuffle

* Comment

* combineWithP

* Better combined

* convergeP

* Move ZipArgs

* Better convergeP

* copyPath

* copyProp

* evolveP

* juxtP

* mapP

* move

* Oops

* normalizeBy

* onSuccess

* onSuccessP

* overP

* promisify

* reject

* rename

* renameAll

* renamePath

* renamePick

* resolve

* tapP

* unlessP

* useWithP

* validate

* validateWith

* whenP

* Wildcard export

* s/lib/src/

* LOUD exports

* Browser

* Wildcard again

* Fix commands

* Bump @types/ramda

* v2 changes

* Bump
  • Loading branch information
mgreystone authored Jan 18, 2024
1 parent 6f0147f commit c46cfae
Show file tree
Hide file tree
Showing 83 changed files with 2,573 additions and 16 deletions.
37 changes: 37 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export { default as all } from './types/all'
export { default as assemble } from './types/assemble'
export { default as assembleP } from './types/assembleP'
export { default as assocWith } from './types/assocWith'
export { default as assocWithP } from './types/assocWithP'
export { default as backoff } from './types/backoff'
export { default as batch } from './types/batch'
export { default as combine } from './types/combine'
export { default as combineAll } from './types/combineAll'
export { default as combineAllP } from './types/combineAllP'
export { default as combineP } from './types/combineP'
export { default as combineWith } from './types/combineWith'
export { default as combineWithP } from './types/combineWithP'
export { default as convergeP } from './types/convergeP'
export { default as copyPath } from './types/copyPath'
export { default as copyProp } from './types/copyProp'
export { default as evolveP } from './types/evolveP'
export { default as juxtP } from './types/juxtP'
export { default as mapP } from './types/mapP'
export { default as move } from './types/move'
export { default as normalizeBy } from './types/normalizeBy'
export { default as onSuccess } from './types/onSuccess'
export { default as onSuccessP } from './types/onSuccessP'
export { default as overP } from './types/overP'
export { default as promisify } from './types/promisify'
export { default as reject } from './types/reject'
export { default as rename } from './types/rename'
export { default as renameAll } from './types/renameAll'
export { default as renamePath } from './types/renamePath'
export { default as renamePick } from './types/renamePick'
export { default as resolve } from './types/resolve'
export { default as tapP } from './types/tapP'
export { default as unlessP } from './types/unlessP'
export { default as useWithP } from './types/useWithP'
export { default as validate } from './types/validate'
export { default as validateWith } from './types/validateWith'
export { default as whenP } from './types/whenP'
34 changes: 29 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
{
"name": "@articulate/funky",
"version": "2.0.3",
"version": "2.1.0",
"description": "Functional helper library",
"main": "index.js",
"types": "index.d.ts",
"exports": {
".": {
"require": "./index.js",
"browser": "./index.js",
"types": "./index.d.ts"
},
"./lib/*": {
"require": "./lib/*.js",
"browser": "./lib/*.js",
"types": "./types/*.d.ts"
}
},
"repository": {
"type": "git",
"url": "https://github.com/articulate/funky"
Expand All @@ -21,25 +34,36 @@
"clean": "rm -rf lib && mkdir -p lib",
"lint": "eslint src test",
"prebuild": "yarn run clean",
"pretest": "yarn run build",
"prepublish": "yarn run build",
"test": "mocha test --reporter=dot"
"pretest": "yarn run build",
"preversion": "git checkout master && yarn run build",
"test": "mocha test --reporter=dot && yarn run test:tsd",
"test:ci": "yarn run lint && yarn run test:coverage && yarn run coverage && yarn run test:tsd",
"test:coverage": "nyc yarn run test",
"test:tsd": "tsd"
},
"dependencies": {
"ramda": "0.27.2"
"ramda": "0.27.2",
"ts-toolbelt": "^9.6.0",
"type-fest": "^4.9.0"
},
"devDependencies": {
"@articulate/spy": "^0.0.1",
"@types/hapi__joi": "^17.1.14",
"@types/ramda": "~0.27.0",
"buble": "^0.15.2",
"chai": "^4.1.1",
"eslint": "^4.3.0",
"joi": "^10.0",
"mocha": "^3.5.0",
"nyc": "^11.1.0",
"prop-factory": "^1.0.0",
"proxyquire": "^2.0.1"
"proxyquire": "^2.0.1",
"ts-arithmetic": "^0.1.1",
"tsd": "^0.29.0"
},
"peerDependencies": {
"@types/hapi__joi": ">=10",
"joi": ">=10"
}
}
6 changes: 6 additions & 0 deletions test-d/all.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expectType } from 'tsd'
import { all } from '..'

expectType<Promise<[ number, number ]>>(
all([ Promise.resolve(1), Promise.resolve(2) ])
)
56 changes: 56 additions & 0 deletions test-d/assemble.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { add } from 'ramda'
import { expectAssignable } from 'tsd'
import { assemble } from '..'

const xfrmsUnary = {
foo: [[ add(1) ]] as [[ (x: number) => number ]],
bar: [{ baz: add(2) }] as [{ baz: (x: number) => number }],
bat: 1
} as const

type ExpectationUnary = {
foo: [[ number ]],
bar: [{ baz: number }],
bat: number
}

expectAssignable<ExpectationUnary>(assemble(xfrmsUnary, 1))
expectAssignable<ExpectationUnary>(assemble(xfrmsUnary)(1))

const xfrmsNary = {
foo: (one: string, two: string) => [ one, two ].join(','),
bar: {
baz: (one: string, two: string, three: string) => [ one, two, three ].join('|'),
},
bat: 1
}

type ExpectationNary = {
foo: string,
bar: { baz: string },
bat: number
}

expectAssignable<ExpectationNary>(assemble(xfrmsNary, 'one', 'two', 'three'))
expectAssignable<ExpectationNary>(assemble(xfrmsNary)('one', 'two', 'three'))
expectAssignable<ExpectationNary>(assemble(xfrmsNary)('one')('two', 'three'))
expectAssignable<ExpectationNary>(assemble(xfrmsNary)('one')('two')('three'))

const xfrms0ary = {
foo: (...params: string[]) => params.join(','),
bar: {
baz: (...params: string[]) => params.join('|'),
},
bat: 1
}

type Expectation0ary = {
foo: string,
bar: {
baz: string,
},
bat: number
}

expectAssignable<Expectation0ary>(assemble(xfrms0ary, 'one', 'two', 'three'))
expectAssignable<Expectation0ary>(assemble(xfrms0ary)('one', 'two', 'three'))
59 changes: 59 additions & 0 deletions test-d/assembleP.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { curry } from 'ramda'
import { expectAssignable } from 'tsd'
import { assembleP } from '..'

const add = curry((a: number, b: number) => Promise.resolve(a + b))
const mult = curry((a: number, b: number) => Promise.resolve(a * b))

const xfrmsUnary = {
foo: [[ add(1) ]] as [[ (x: number) => Promise<number> ]],
bar: [{ baz: mult(2) }] as [{ baz: (x: number) => Promise<number> }],
bat: 1
} as const

type ExpectationUnary = Promise<{
foo: [[ number ]],
bar: [{ baz: number }],
bat: number
}>

expectAssignable<ExpectationUnary>(assembleP(xfrmsUnary, 1))
expectAssignable<ExpectationUnary>(assembleP(xfrmsUnary)(1))

const xfrmsNary = {
foo: (one: string, two: string) => Promise.resolve([ one, two ].join(',')),
bar: {
baz: (one: string, two: string, three: string) => Promise.resolve([ one, two, three ].join('|')),
},
bat: 1
}

type ExpectationNary = Promise<{
foo: string,
bar: { baz: string },
bat: number
}>

expectAssignable<ExpectationNary>(assembleP(xfrmsNary, 'one', 'two', 'three'))
expectAssignable<ExpectationNary>(assembleP(xfrmsNary)('one', 'two', 'three'))
expectAssignable<ExpectationNary>(assembleP(xfrmsNary)('one')('two', 'three'))
expectAssignable<ExpectationNary>(assembleP(xfrmsNary)('one')('two')('three'))

const xfrms0ary = {
foo: (...params: string[]) => Promise.resolve(params.join(',')),
bar: {
baz: (...params: string[]) => Promise.resolve(params.join('|')),
},
bat: 1
}

type Expectation0ary = Promise<{
foo: string,
bar: {
baz: string,
},
bat: number
}>

expectAssignable<Expectation0ary>(assembleP(xfrms0ary, 'one', 'two', 'three'))
expectAssignable<Expectation0ary>(assembleP(xfrms0ary)('one', 'two', 'three'))
14 changes: 14 additions & 0 deletions test-d/assocWith.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expectAssignable } from 'tsd'

import { assocWith } from '..'

function concatBarToFoo(obj: { foo: 'foo' }): 'foobar' {
return obj.foo + 'bar' as 'foobar'
}

type Result = { foo: 'foo', baz: 'foobar' }

expectAssignable<Result>(assocWith('baz', concatBarToFoo, { foo: 'foo' }))
expectAssignable<Result>(assocWith('baz')(concatBarToFoo)({ foo: 'foo' }))
expectAssignable<Result>(assocWith('baz', concatBarToFoo)({ foo: 'foo' }))
expectAssignable<Result>(assocWith('baz')(concatBarToFoo, { foo: 'foo' }))
14 changes: 14 additions & 0 deletions test-d/assocWithP.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expectAssignable } from 'tsd'

import { assocWithP } from '..'

async function concatBarToFoo(obj: { foo: 'foo' }): Promise<'foobar'> {
return obj.foo + 'bar' as 'foobar'
}

type Result = Promise<{ foo: 'foo', baz: 'foobar' }>

expectAssignable<Result>(assocWithP('baz', concatBarToFoo, { foo: 'foo' }))
expectAssignable<Result>(assocWithP('baz')(concatBarToFoo)({ foo: 'foo' }))
expectAssignable<Result>(assocWithP('baz', concatBarToFoo)({ foo: 'foo' }))
expectAssignable<Result>(assocWithP('baz')(concatBarToFoo, { foo: 'foo' }))
12 changes: 12 additions & 0 deletions test-d/backoff.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expectType } from 'tsd'

import { backoff } from '..'

async function f(a: 'foo', b: 'bar'): Promise<'baz'> {
return 'baz'
}

expectType<typeof f>(backoff(undefined, f))
expectType<typeof f>(backoff()(f))
expectType<typeof f>(backoff({ base: 16, tries: 5 }, f))
expectType<typeof f>(backoff({ base: 16, tries: 5 })(f))
23 changes: 23 additions & 0 deletions test-d/batch.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expectAssignable } from 'tsd'

import { batch } from '..'

interface In { inputId: string }
interface Out { outputId: string }

async function asyncListFn(args: In[]): Promise<Out[]> {
return [{ outputId: 'bar' }]
}

const batchedWoOptions = batch(undefined, asyncListFn)
expectAssignable<Promise<Out>>(batchedWoOptions({ inputId: 'foo' }))

const batchedWOptions = batch({ limit: 2, wait: 16 }, asyncListFn)
expectAssignable<Promise<Out>>(batchedWOptions({ inputId: 'bar' }))

const batchedWithMatching = batch({
inputKey: (x: { inputId: string }) => x.inputId,
outputKey: (x: { outputId: string }) => x.outputId,
}, asyncListFn)

expectAssignable<Promise<Out>>(batchedWithMatching({ inputId: 'bar' }))
14 changes: 14 additions & 0 deletions test-d/combine.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expectAssignable } from 'tsd'

import { combine } from '..'

const mixin = { foo: 'bar' as const }
const input = { baz: 'bip' as const }

function K(x: typeof mixin) {
return (y: typeof input) => x
}

type Expectation = { foo: 'bar', baz: 'bip' }

expectAssignable<Expectation>(combine(K(mixin))(input))
22 changes: 22 additions & 0 deletions test-d/combineAll.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expectAssignable } from 'tsd'

import { combineAll } from '..'

const input = { baz: 3 as const }

const actions = [
K({ foo: 1 as const }),
K({ bar: 2 as const }),
] as const

function K<T>(x: T) {
return (y: typeof input) => x
}

type Expectation = {
foo: 1,
bar: 2,
baz: 3,
}

expectAssignable<Expectation>(combineAll(actions)(input))
22 changes: 22 additions & 0 deletions test-d/combineAllP.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expectAssignable } from 'tsd'

import { combineAllP } from '..'

const input = { baz: 3 as const }

const actions = [
K(Promise.resolve({ foo: 1 as const })),
K(Promise.resolve({ bar: 2 as const })),
] as const

function K<T>(x: T) {
return (y: typeof input) => x
}

type Expectation = Promise<{
foo: 1,
bar: 2,
baz: 3,
}>

expectAssignable<Expectation>(combineAllP(actions)(input))
14 changes: 14 additions & 0 deletions test-d/combineP.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expectAssignable } from 'tsd'

import { combineP } from '..'

const mixin = { foo: 'bar' as const }
const input = { baz: 'bip' as const }

function K(x: typeof mixin) {
return async (y: typeof input) => x
}

type Expectation = Promise<{ foo: 'bar', baz: 'bip' }>

expectAssignable<Expectation>(combineP(K(mixin))(input))
13 changes: 13 additions & 0 deletions test-d/combineWith.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Add, Multiply } from 'ts-arithmetic'
import { expectType } from 'tsd'

import { combineWith } from '..'

declare function add(a: 2): {
(b: 3): Add<2, 3>
}

declare function multiply(a: 3, b: 5): Multiply<3, 5>

expectType<15>(combineWith(multiply)(add(2))(3))
expectType<15>(combineWith(multiply, add(2))(3))
13 changes: 13 additions & 0 deletions test-d/combineWithP.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Add, Multiply } from 'ts-arithmetic'
import { expectType } from 'tsd'

import { combineWithP } from '..'

declare function add(a: 2): {
(b: 3): Promise<Add<2, 3>>
}

declare function multiply(a: 3, b: 5): Promise<Multiply<3, 5>>

expectType<Promise<15>>(combineWithP(multiply)(add(2))(3))
expectType<Promise<15>>(combineWithP(multiply, add(2))(3))
Loading

0 comments on commit c46cfae

Please sign in to comment.