Skip to content

Commit

Permalink
feat: drop support for Node 10
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Jun 1, 2021
1 parent 8f4f2b1 commit b34257e
Show file tree
Hide file tree
Showing 9 changed files with 857 additions and 1,251 deletions.
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package-lock.json
yarn.lock
build
pkg
coverage
5 changes: 2 additions & 3 deletions docs/task-instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ Expand the error types of a task. Purely a TypeScript type system modification.
{% tab title="Usage" %}
```typescript
const task: Task<number | AnotherErrorPossibility, number> = Task.fail(
5,
).errorUnion<AnotherErrorPossibility>()
const task: Task<number | AnotherErrorPossibility, number> =
Task.fail(5).errorUnion<AnotherErrorPossibility>()
```

{% endtab %}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@
"eslint-plugin-prettier": "^3.4.0",
"gzip-size-cli": "^5.0.0",
"husky": "^6.0.0",
"jest": "^26.6.3",
"jest": "^27.0.0",
"lint-staged": "^11.0.0",
"prettier": "^2.3.0",
"semantic-release": "^17.4.3",
"terser": "^5.7.0",
"ts-jest": "^26.5.5",
"ts-jest": "^27.0.0",
"ts-toolbelt": "^9.6.0",
"typescript": "^4.3.2"
},
Expand Down
3 changes: 2 additions & 1 deletion src/Subscription/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class Subscription<T> {
EventSubscriber<T>
>()
private status_: Status = "inactive"
private statusSubscribers_: Set<StatusSubscriber> = new Set<StatusSubscriber>()
private statusSubscribers_: Set<StatusSubscriber> =
new Set<StatusSubscriber>()

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public emit(value: T): Task<any, any[]> {
Expand Down
11 changes: 6 additions & 5 deletions src/Task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ export const fromLazyPromise = <S>(
* lazily returns a Task instead.
* @param fn A function which returns a promise
*/
export const wrapPromiseCreator = <S, Args extends unknown[]>(
fn: (...args: Args) => Promise<S>,
) => (...args: Args): Task<unknown, S> => fromLazyPromise(() => fn(...args))
export const wrapPromiseCreator =
<S, Args extends unknown[]>(fn: (...args: Args) => Promise<S>) =>
(...args: Args): Task<unknown, S> =>
fromLazyPromise(() => fn(...args))

/**
* Given a task, create a Promise which resolves when the task does.
Expand Down Expand Up @@ -955,9 +956,9 @@ export class Task<E, S> implements PromiseLike<S> {
public ap<
E2,
S2,
S3 = S extends (arg: S2) => unknown ? ReturnType<S> : never
S3 = S extends (arg: S2) => unknown ? ReturnType<S> : never,
>(task: Task<E | E2, S2>): Task<E | E2, S3> {
return ap((this as unknown) as Task<E, (result: S2) => S3>, task)
return ap(this as unknown as Task<E, (result: S2) => S3>, task)
}

public wait(ms: number): Task<E, S> {
Expand Down
17 changes: 8 additions & 9 deletions src/__tests__/piuggi2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ const contentToQuery: ContentTypes[] = [
const unpublishAndDelete = (entry: typeof ENTRY) =>
entry.isPublished() ? entry.unpublish() : entry.delete()

const queryContentType = (environment: typeof ENV) => (
contentType: ContentTypes,
) =>
environment[contentType]({
order: "sys.createdAt",
limit: 1000,
})
.map(response => response.items.map(unpublishAndDelete))
.chain(Task.sequence)
const queryContentType =
(environment: typeof ENV) => (contentType: ContentTypes) =>
environment[contentType]({
order: "sys.createdAt",
limit: 1000,
})
.map(response => response.items.map(unpublishAndDelete))
.chain(Task.sequence)

describe("piugi script 2", () => {
test("the test", () =>
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { RemoteData, Task, ExternalTask, LoopContinue, LoopBreak, Subscription }
* returns a promise instead.
* @param fn A function which returns a promise
*/
export const wrapTaskCreator = <S, Args extends unknown[]>(
fn: (...args: Args) => Task<unknown, S>,
) => (...args: Args): Promise<S> => fn(...args).toPromise()
export const wrapTaskCreator =
<S, Args extends unknown[]>(fn: (...args: Args) => Task<unknown, S>) =>
(...args: Args): Promise<S> =>
fn(...args).toPromise()
22 changes: 14 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export const range = (end: number, start = 0): number[] =>
.fill(undefined)
.map((_, i) => start + i)

export const to = <A, T>(fn: (items: A[]) => T) =>
export const to =
<A, T>(fn: (items: A[]) => T) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
(sum: any, _item: A, index: number, all: A[]): T => {
const isLast = index === all.length - 1
Expand All @@ -15,16 +16,21 @@ export const to = <A, T>(fn: (items: A[]) => T) =>
return fn(all)
}

export const constant = <T>(value: T): (() => T) => () => value
export const constant =
<T>(value: T): (() => T) =>
() =>
value

export const identity = <T>(x: T): T => x

export const toIndexedObject = <T, V, R extends { [key: string]: V }>(
fn: (item: T, index: number) => [string, V],
) => (sum: R, item: T, index: number): R => {
const [key, value] = fn(item, index)
return ((sum as { [key: string]: V })[key] = value), sum
}
export const toIndexedObject =
<T, V, R extends { [key: string]: V }>(
fn: (item: T, index: number) => [string, V],
) =>
(sum: R, item: T, index: number): R => {
const [key, value] = fn(item, index)
return ((sum as { [key: string]: V })[key] = value), sum
}

export const mapToIndexedObject = <T, V, R extends { [key: string]: V }>(
fn: (item: T, index: number) => [string, V],
Expand Down

0 comments on commit b34257e

Please sign in to comment.