Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pavadeli committed Oct 23, 2024
1 parent eede34b commit b39ed0f
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 128 deletions.
154 changes: 77 additions & 77 deletions README.md

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions etc/types.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export interface ArrayTypeConfig extends LengthChecksConfig {
// @public
export type ArrayViolation = LengthViolation;

// @public
export function autoCast<T extends BaseTypeImpl<unknown>>(type: T): T;

// @public
export function autoCastAll<T extends BaseTypeImpl<unknown>>(type: T): T;

// @public
export const autoCastFailure: unique symbol;

Expand All @@ -56,15 +62,13 @@ export abstract class BaseTypeImpl<ResultType, TypeConfig = unknown> implements
abstract accept<R>(visitor: Visitor<R>): R;
andThen<Return, RestArgs extends unknown[]>(fn: (value: ResultType, ...restArgs: RestArgs) => Return): (input: unknown, ...restArgs: RestArgs) => Return;
assert(input: unknown): asserts input is ResultType;
get autoCast(): this;
get autoCastAll(): this;
protected autoCaster?(this: BaseTypeImpl<ResultType, TypeConfig>, value: unknown): unknown;
abstract readonly basicType: BasicType | 'mixed';
get check(): (this: void, input: unknown) => ResultType;
protected combineConfig(oldConfig: TypeConfig, newConfig: TypeConfig): TypeConfig;
construct(input: unknown): ResultType;
// (undocumented)
protected createAutoCastAllType(): this;
protected createAutoCastAllType(): Type<ResultType>;
protected createResult(input: unknown, result: unknown, validatorResult: ValidationResult): Result<ResultType>;
protected readonly customValidators: ReadonlyArray<Validator<unknown>>;
readonly enumerableLiteralDomain?: Iterable<LiteralValue>;
Expand Down Expand Up @@ -617,17 +621,17 @@ export type ValidationDetails = {
// @public
export class ValidationError extends Error implements Failure {
// (undocumented)
details: OneOrMore<FailureDetails>;
readonly details: OneOrMore<FailureDetails>;
static fromFailure(failure: Failure): ValidationError;
// (undocumented)
input: unknown;
readonly input: unknown;
// (undocumented)
readonly name = "ValidationError";
// (undocumented)
readonly ok = false;
static try<Return>({ type, input }: Pick<Failure, 'type' | 'input'>, fn: () => Return): Result<Return>;
// (undocumented)
type: BaseTypeImpl<unknown>;
readonly type: BaseTypeImpl<unknown>;
}

// @public
Expand Down
27 changes: 27 additions & 0 deletions markdown/types.autocast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@skunkteam/types](./types.md) &gt; [autoCast](./types.autocast.md)

## autoCast() function

Returns the same type, but with an auto-casting default parser installed.

**Signature:**

```typescript
declare function autoCast<T extends BaseTypeImpl<unknown>>(type: T): T;
```

## Parameters

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| type | T | |

**Returns:**

T

## Remarks

Each type implementation provides its own auto-cast rules. See builtin types for examples of auto-cast rules.
27 changes: 27 additions & 0 deletions markdown/types.autocastall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@skunkteam/types](./types.md) &gt; [autoCastAll](./types.autocastall.md)

## autoCastAll() function

Create a recursive autocasting version of the given type.

**Signature:**

```typescript
declare function autoCastAll<T extends BaseTypeImpl<unknown>>(type: T): T;
```

## Parameters

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| type | T | |

**Returns:**

T

## Remarks

This will replace any parser in the nested structure with the appropriate autocaster when applicable.
17 changes: 0 additions & 17 deletions markdown/types.basetypeimpl.autocast.md

This file was deleted.

17 changes: 0 additions & 17 deletions markdown/types.basetypeimpl.autocastall.md

This file was deleted.

4 changes: 2 additions & 2 deletions markdown/types.basetypeimpl.createautocastalltype.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
**Signature:**

```typescript
protected createAutoCastAllType(): this;
protected createAutoCastAllType(): Type<ResultType>;
```

**Returns:**

this
[Type](./types.type.md)<!-- -->&lt;ResultType&gt;
2 changes: 0 additions & 2 deletions markdown/types.basetypeimpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ All type-implementations must extend this base class. Use [createType()](./types
| Property | Modifiers | Type | Description |
| --------------------------------------------------------------------------- | --------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [autoCast](./types.basetypeimpl.autocast.md) | <code>readonly</code> | this | The same type, but with an auto-casting default parser installed. |
| [autoCastAll](./types.basetypeimpl.autocastall.md) | <code>readonly</code> | this | Create a recursive autocasting version of the current type. |
| [basicType](./types.basetypeimpl.basictype.md) | <p><code>abstract</code></p><p><code>readonly</code></p> | [BasicType](./types.basictype.md) \| 'mixed' | The kind of values this type validates. |
| [check](./types.basetypeimpl.check.md) | <code>readonly</code> | (this: void, input: unknown) =&gt; ResultType | Asserts that a value conforms to this Type and returns the input as is, if it does. |
| [customValidators](./types.basetypeimpl.customvalidators.md) | <p><code>protected</code></p><p><code>readonly</code></p> | ReadonlyArray&lt;[Validator](./types.validator.md)<!-- -->&lt;unknown&gt;&gt; | Additional custom validation added using [withValidation](./types.basetypeimpl.withvalidation.md) or [withConstraint](./types.basetypeimpl.withconstraint.md)<!-- -->. |
Expand Down
2 changes: 1 addition & 1 deletion markdown/types.interfacepickoptions.applyparser.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ applyParser?: boolean;

## Remarks

By default, custom parsers (i.e. parsers that are added to a type using [BaseTypeImpl.withParser()](./types.basetypeimpl.withparser.md) or [BaseTypeImpl.autoCast](./types.basetypeimpl.autocast.md)<!-- -->) are not reused when a new type is created using [InterfaceType.pick()](./types.interfacetype.pick.md) and [InterfaceType.omit()](./types.interfacetype.omit.md)<!-- -->.
By default, custom parsers (i.e. parsers that are added to a type using [BaseTypeImpl.withParser()](./types.basetypeimpl.withparser.md) or [autoCast()](./types.autocast.md)<!-- -->) are not reused when a new type is created using [InterfaceType.pick()](./types.interfacetype.pick.md) and [InterfaceType.omit()](./types.interfacetype.omit.md)<!-- -->.

However, it is possible to reuse a parser that is set on the base type. Parsers have a single input of type `unknown` and may produce anything (also with type `unknown`<!-- -->). The result of a parser will always be validated afterwards by the type it is applied to. Technically, any parser is applicable to any type, but it might not make sense to do so. Therefore, you can choose to apply it or not with this option.

Expand Down
2 changes: 2 additions & 0 deletions markdown/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Runtime type-validation with derived TypeScript types.
| Function | Description |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| [array(args)](./types.array.md) | Create a type that checks whether the input is an array and all elements conform to the given <code>elementType</code>. |
| [autoCast(type)](./types.autocast.md) | Returns the same type, but with an auto-casting default parser installed. |
| [autoCastAll(type)](./types.autocastall.md) | Create a recursive autocasting version of the given type. |
| [booleanAutoCaster(input)](./types.booleanautocaster.md) | |
| [createType(impl, override)](./types.createtype.md) | Create a Type from the given type-implementation. |
| [intersection(args)](./types.intersection.md) | Intersect the given types. |
Expand Down
2 changes: 1 addition & 1 deletion markdown/types.validationerror.details.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
**Signature:**

```typescript
details: OneOrMore<FailureDetails>;
readonly details: OneOrMore<FailureDetails>;
```
2 changes: 1 addition & 1 deletion markdown/types.validationerror.input.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
**Signature:**

```typescript
input: unknown;
readonly input: unknown;
```
6 changes: 3 additions & 3 deletions markdown/types.validationerror.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Is itself also a [Failure](./types.failure.md) and can be used as such in APIs.
| Property | Modifiers | Type | Description |
| --------------------------------------------- | --------------------- | ---------------------------------------------------------------------------------------------------- | ----------- |
| [details](./types.validationerror.details.md) | | [OneOrMore](./types.oneormore.md)<!-- -->&lt;[FailureDetails](./types.failuredetails.md)<!-- -->&gt; | |
| [input](./types.validationerror.input.md) | | unknown | |
| [details](./types.validationerror.details.md) | <code>readonly</code> | [OneOrMore](./types.oneormore.md)<!-- -->&lt;[FailureDetails](./types.failuredetails.md)<!-- -->&gt; | |
| [input](./types.validationerror.input.md) | <code>readonly</code> | unknown | |
| [name](./types.validationerror.name.md) | <code>readonly</code> | (not declared) | |
| [ok](./types.validationerror.ok.md) | <code>readonly</code> | (not declared) | |
| [type](./types.validationerror.type.md) | | [BaseTypeImpl](./types.basetypeimpl.md)<!-- -->&lt;unknown&gt; | |
| [type](./types.validationerror.type.md) | <code>readonly</code> | [BaseTypeImpl](./types.basetypeimpl.md)<!-- -->&lt;unknown&gt; | |
## Methods
Expand Down
2 changes: 1 addition & 1 deletion markdown/types.validationerror.type.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
**Signature:**

```typescript
type: BaseTypeImpl<unknown>;
readonly type: BaseTypeImpl<unknown>;
```

0 comments on commit b39ed0f

Please sign in to comment.