Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
chore: cleanup (#88)
Browse files Browse the repository at this point in the history
<!-- πŸ‘‹ Hi, thanks for sending a PR to tson! πŸ’–.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [ ] Addresses an existing open issue: fixes #000
- [ ] That issue was marked as [`status: accepting
prs`](https://github.com/trpc/tupleson/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [ ] Steps in
[CONTRIBUTING.md](https://github.com/trpc/tupleson/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

<!-- Description of what is changed and how the code change does that.
-->
  • Loading branch information
helmturner authored Nov 26, 2023
1 parent d7c8dbc commit 16944e9
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 164 deletions.
31 changes: 0 additions & 31 deletions src/async/asyncHelpers.ts

This file was deleted.

75 changes: 0 additions & 75 deletions src/async/iterableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,93 +156,18 @@ export interface AsyncIterableEsque<T = unknown> {
[Symbol.asyncIterator](): AsyncIterator<T>;
}

export function isAsyncIterableEsque(
maybeAsyncIterable: unknown,
): maybeAsyncIterable is AsyncIterableEsque {
return (
!!maybeAsyncIterable &&
(typeof maybeAsyncIterable === "object" ||
typeof maybeAsyncIterable === "function") &&
Symbol.asyncIterator in maybeAsyncIterable
);
}

export interface IterableEsque<T = unknown> {
[Symbol.iterator](): Iterator<T>;
}

export function isIterableEsque(
maybeIterable: unknown,
): maybeIterable is IterableEsque {
return (
!!maybeIterable &&
(typeof maybeIterable === "object" ||
typeof maybeIterable === "function") &&
Symbol.iterator in maybeIterable
);
}

type SyncOrAsyncGeneratorFnEsque = AsyncGeneratorFnEsque | GeneratorFnEsque;

export function isMaybeAsyncGeneratorFn(
maybeAsyncGeneratorFn: unknown,
): maybeAsyncGeneratorFn is SyncOrAsyncGeneratorFnEsque {
return (
typeof maybeAsyncGeneratorFn === "function" &&
["AsyncGeneratorFunction", "GeneratorFunction"].includes(
maybeAsyncGeneratorFn.constructor.name,
)
);
}

export type GeneratorFnEsque = () => Generator;

export function isGeneratorFnEsque(
maybeGeneratorFn: unknown,
): maybeGeneratorFn is GeneratorFnEsque {
return (
typeof maybeGeneratorFn === "function" &&
maybeGeneratorFn.constructor.name === "GeneratorFunction"
);
}

export type AsyncGeneratorFnEsque = () => AsyncGenerator;

export function isAsyncGeneratorFnEsque(
maybeAsyncGeneratorFn: unknown,
): maybeAsyncGeneratorFn is AsyncGeneratorFnEsque {
return (
typeof maybeAsyncGeneratorFn === "function" &&
maybeAsyncGeneratorFn.constructor.name === "AsyncGeneratorFunction"
);
}

export type PromiseEsque = PromiseLike<unknown>;

export function isPromiseEsque(
maybePromise: unknown,
): maybePromise is PromiseEsque {
return (
!!maybePromise &&
typeof maybePromise === "object" &&
"then" in maybePromise &&
typeof maybePromise.then === "function"
);
}

export type ThunkEsque = () => unknown;

export function isThunkEsque(maybeThunk: unknown): maybeThunk is ThunkEsque {
return (
!!maybeThunk && typeof maybeThunk === "function" && maybeThunk.length === 0
);
}

export type Thunkable =
| AsyncIterableEsque
| IterableEsque
| PromiseEsque
| SyncOrAsyncGeneratorFnEsque
| ThunkEsque;

export type MaybePromise<T> = Promise<T> | T;
15 changes: 0 additions & 15 deletions src/iterableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@

/* eslint-disable @typescript-eslint/no-empty-interface */

/**
* A stronger type for Iterator
*/
export interface Iterator<T = unknown, TReturn = unknown, TNextArg = unknown>
extends globalThis.Iterator<T, TReturn, TNextArg> {}

/**
* A stronger type for AsyncIterator
*/
export interface AsyncIterator<
T = unknown,
TReturn = unknown,
TNextArg = unknown,
> extends globalThis.AsyncIterator<T, TReturn, TNextArg> {}

/**
* A stronger type for Generator
*/
Expand Down
2 changes: 0 additions & 2 deletions src/sync/syncTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export interface TsonTypeTesterCustom {
test: (v: unknown) => boolean;
}

export type TsonTypeTester = TsonTypeTesterCustom | TsonTypeTesterPrimitive;

export type TsonType<
/**
* The type of the value
Expand Down
41 changes: 0 additions & 41 deletions src/tsonAssert.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
export const asserts = Symbol("asserted");
export type Not<T extends boolean> = T extends true ? false : true;

const secret = Symbol("secret");
type Secret = typeof secret;

export type IsNever<T> = [T] extends [never] ? true : false;
export type IsAny<T> = [T] extends [Secret] ? Not<IsNever<T>> : false;
export type IsUnknown<T> = [unknown] extends [T] ? Not<IsAny<T>> : false;
/**
* The more I think about these semantics, the less they make sense.
* What is this API, really? What is the goal?
* Is it to provide a way to assert that a value is of a certain type? I think
* this only makes sense in a few limited cases.
*
* At what point in the pipeline would this occur? Would this happen for all
* values? If so, well... you've asserted that your parser only handles
* the type you're asserting. I don't know why you'd want to predetermine
* that at the time of configuration. Alternatively, if this isn't called
* for each value, then one of the following must be true:
*
* - you have also specified, somehow, *when* to apply this assertion
* - it is part of an array of operations that are attempted in order,
* and the first one that succeeds is used
*
* The first point could easily be accomplished by a conditional inside the
* assertion function (e.g. for the number guard, If not of type 'number'
* then it's definitely not NaN)... so no need for anything special like an
* array of type handler keys associated with the assertion.
*
* The second point is an option, since that's how custom tson types work.
* But is there really any utility to that? We're not zod validating...
* we're marshalling. We assume the type layer is accurate, without
* enforcing it. If we want to integrate runtime type validation, that
* seems like a feature request, potentially warranting it's own API.
*
* Ultimately, I feel like this functionality is easily served by a simple
* assertion function that throws for invalid values. For most (all?) except
* for the unknown object guard they would come first in the array, while
* the unknown object guard would come last.
*/
interface TsonGuardBase {
key: string;
}
Expand Down

0 comments on commit 16944e9

Please sign in to comment.