Skip to content

Commit

Permalink
Merge branch 'main' into feat-nanoid-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller authored Aug 27, 2024
2 parents 9f25d78 + 6f470fd commit 0a2cd85
Show file tree
Hide file tree
Showing 137 changed files with 2,165 additions and 82 deletions.
1 change: 1 addition & 0 deletions library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the library will be documented in this file.
## vX.X.X (Month DD, YYYY)

- Add `nanoid` action to validate Nano IDs (pull request #789)
- Add `undefinedable` and `undefinedableAsync` schema (issue #385)

## v0.39.0 (August 24, 2024)

Expand Down
20 changes: 20 additions & 0 deletions library/src/methods/getDefault/getDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type {
NullishSchemaAsync,
OptionalSchema,
OptionalSchemaAsync,
UndefinedableSchema,
UndefinedableSchemaAsync,
} from '../../schemas/index.ts';
import type {
BaseIssue,
Expand Down Expand Up @@ -41,6 +43,15 @@ export type InferDefault<
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
unknown
>
| UndefinedableSchema<
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
unknown
>
| UndefinedableSchemaAsync<
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
unknown
>,
> = TSchema extends
| NullableSchema<
Expand Down Expand Up @@ -70,6 +81,15 @@ export type InferDefault<
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
infer TDefault
>
| UndefinedableSchema<
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
infer TDefault
>
| UndefinedableSchemaAsync<
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
infer TDefault
>
? [TDefault] extends [never]
? undefined
: TDefault extends () => MaybePromise<InferInput<TSchema>>
Expand Down
11 changes: 11 additions & 0 deletions library/src/methods/unwrap/unwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type {
NullishSchemaAsync,
OptionalSchema,
OptionalSchemaAsync,
UndefinedableSchema,
UndefinedableSchemaAsync,
} from '../../schemas/index.ts';
import type {
BaseIssue,
Expand Down Expand Up @@ -75,6 +77,15 @@ export function unwrap<
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
unknown
>
| UndefinedableSchema<
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
unknown
>
| UndefinedableSchemaAsync<
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
unknown
>,
>(schema: TSchema): TSchema['wrapped'] {
return schema.wrapped;
Expand Down
1 change: 1 addition & 0 deletions library/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export * from './symbol/index.ts';
export * from './tuple/index.ts';
export * from './tupleWithRest/index.ts';
export * from './undefined/index.ts';
export * from './undefinedable/index.ts';
export * from './union/index.ts';
export * from './unknown/index.ts';
export * from './variant/index.ts';
Expand Down
8 changes: 6 additions & 2 deletions library/src/schemas/looseObject/looseObject.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type StringIssue,
type StringSchema,
} from '../string/index.ts';
import type { UndefinedableSchema } from '../undefinedable/index.ts';
import { looseObject, type LooseObjectSchema } from './looseObject.ts';
import type { LooseObjectIssue } from './types.ts';

Expand Down Expand Up @@ -46,6 +47,7 @@ describe('looseObject', () => {
key3: NullishSchema<StringSchema<undefined>, never>;
key4: ObjectSchema<{ key: NumberSchema<undefined> }, never>;
key5: SchemaWithPipe<[StringSchema<undefined>, ReadonlyAction<string>]>;
key6: UndefinedableSchema<StringSchema<undefined>, 'bar'>;
},
undefined
>;
Expand All @@ -55,9 +57,10 @@ describe('looseObject', () => {
{
key1: string;
key2?: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
key5: string;
key6: string | undefined;
} & { [key: string]: unknown }
>();
});
Expand All @@ -67,9 +70,10 @@ describe('looseObject', () => {
{
key1: string;
key2: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
readonly key5: string;
key6: string;
} & { [key: string]: unknown }
>();
});
Expand Down
1 change: 0 additions & 1 deletion library/src/schemas/looseObject/looseObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ describe('looseObject', () => {
test('for nullish entry', () => {
expectNoSchemaIssue(looseObject({ key: nullish(number()) }), [
{},
// @ts-expect-error
{ key: undefined },
{ key: null },
{ key: 123 },
Expand Down
8 changes: 6 additions & 2 deletions library/src/schemas/looseObject/looseObjectAsync.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type StringIssue,
type StringSchema,
} from '../string/index.ts';
import type { UndefinedableSchema } from '../undefinedable/index.ts';
import {
looseObjectAsync,
type LooseObjectSchemaAsync,
Expand Down Expand Up @@ -51,6 +52,7 @@ describe('looseObjectAsync', () => {
key3: NullishSchema<StringSchema<undefined>, never>;
key4: ObjectSchema<{ key: NumberSchema<undefined> }, never>;
key5: SchemaWithPipe<[StringSchema<undefined>, ReadonlyAction<string>]>;
key6: UndefinedableSchema<StringSchema<undefined>, 'bar'>;
},
undefined
>;
Expand All @@ -60,9 +62,10 @@ describe('looseObjectAsync', () => {
{
key1: string;
key2?: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
key5: string;
key6: string | undefined;
} & { [key: string]: unknown }
>();
});
Expand All @@ -72,9 +75,10 @@ describe('looseObjectAsync', () => {
{
key1: string;
key2: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
readonly key5: string;
key6: string;
} & { [key: string]: unknown }
>();
});
Expand Down
8 changes: 1 addition & 7 deletions library/src/schemas/looseObject/looseObjectAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,7 @@ describe('looseObjectAsync', () => {
test('for nullish entry', async () => {
await expectNoSchemaIssueAsync(
looseObjectAsync({ key: nullish(number()) }),
[
{},
// @ts-expect-error
{ key: undefined },
{ key: null },
{ key: 123 },
]
[{}, { key: undefined }, { key: null }, { key: 123 }]
);
});

Expand Down
8 changes: 6 additions & 2 deletions library/src/schemas/object/object.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type StringIssue,
type StringSchema,
} from '../string/index.ts';
import type { UndefinedableSchema } from '../undefinedable/index.ts';
import { object, type ObjectSchema } from './object.ts';
import type { ObjectIssue } from './types.ts';

Expand Down Expand Up @@ -45,6 +46,7 @@ describe('object', () => {
key3: NullishSchema<StringSchema<undefined>, never>;
key4: ObjectSchema<{ key: NumberSchema<undefined> }, never>;
key5: SchemaWithPipe<[StringSchema<undefined>, ReadonlyAction<string>]>;
key6: UndefinedableSchema<StringSchema<undefined>, 'bar'>;
},
undefined
>;
Expand All @@ -53,19 +55,21 @@ describe('object', () => {
expectTypeOf<InferInput<Schema>>().toEqualTypeOf<{
key1: string;
key2?: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
key5: string;
key6: string | undefined;
}>();
});

test('of output', () => {
expectTypeOf<InferOutput<Schema>>().toEqualTypeOf<{
key1: string;
key2: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
readonly key5: string;
key6: string;
}>();
});

Expand Down
1 change: 0 additions & 1 deletion library/src/schemas/object/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ describe('object', () => {
test('for nullish entry', () => {
expectNoSchemaIssue(object({ key: nullish(number()) }), [
{},
// @ts-expect-error
{ key: undefined },
{ key: null },
{ key: 123 },
Expand Down
8 changes: 6 additions & 2 deletions library/src/schemas/object/objectAsync.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type StringIssue,
type StringSchema,
} from '../string/index.ts';
import type { UndefinedableSchema } from '../undefinedable/index.ts';
import { objectAsync, type ObjectSchemaAsync } from './objectAsync.ts';
import type { ObjectIssue } from './types.ts';

Expand Down Expand Up @@ -45,6 +46,7 @@ describe('objectAsync', () => {
key3: NullishSchema<StringSchema<undefined>, never>;
key4: ObjectSchemaAsync<{ key: NumberSchema<undefined> }, never>;
key5: SchemaWithPipe<[StringSchema<undefined>, ReadonlyAction<string>]>;
key6: UndefinedableSchema<StringSchema<undefined>, 'bar'>;
},
undefined
>;
Expand All @@ -53,19 +55,21 @@ describe('objectAsync', () => {
expectTypeOf<InferInput<Schema>>().toEqualTypeOf<{
key1: string;
key2?: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
key5: string;
key6: string | undefined;
}>();
});

test('of output', () => {
expectTypeOf<InferOutput<Schema>>().toEqualTypeOf<{
key1: string;
key2: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
readonly key5: string;
key6: string;
}>();
});

Expand Down
1 change: 0 additions & 1 deletion library/src/schemas/object/objectAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ describe('objectAsync', () => {
test('for nullish entry', async () => {
await expectNoSchemaIssueAsync(objectAsync({ key: nullish(number()) }), [
{},
// @ts-expect-error
{ key: undefined },
{ key: null },
{ key: 123 },
Expand Down
8 changes: 6 additions & 2 deletions library/src/schemas/objectWithRest/objectWithRest.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type StringIssue,
type StringSchema,
} from '../string/index.ts';
import type { UndefinedableSchema } from '../undefinedable/index.ts';
import { objectWithRest, type ObjectWithRestSchema } from './objectWithRest.ts';
import type { ObjectWithRestIssue } from './types.ts';

Expand Down Expand Up @@ -55,6 +56,7 @@ describe('objectWithRest', () => {
key3: NullishSchema<StringSchema<undefined>, never>;
key4: ObjectSchema<{ key: NumberSchema<undefined> }, never>;
key5: SchemaWithPipe<[StringSchema<undefined>, ReadonlyAction<string>]>;
key6: UndefinedableSchema<StringSchema<undefined>, 'bar'>;
},
BooleanSchema<undefined>,
undefined
Expand All @@ -65,9 +67,10 @@ describe('objectWithRest', () => {
{
key1: string;
key2?: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
key5: string;
key6: string | undefined;
} & { [key: string]: boolean }
>();
});
Expand All @@ -77,9 +80,10 @@ describe('objectWithRest', () => {
{
key1: string;
key2: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
readonly key5: string;
key6: string;
} & { [key: string]: boolean }
>();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type StringIssue,
type StringSchema,
} from '../string/index.ts';
import type { UndefinedableSchema } from '../undefinedable/index.ts';
import {
objectWithRestAsync,
type ObjectWithRestSchemaAsync,
Expand Down Expand Up @@ -58,6 +59,7 @@ describe('objectWithRestAsync', () => {
key3: NullishSchema<StringSchema<undefined>, never>;
key4: ObjectSchema<{ key: NumberSchema<undefined> }, never>;
key5: SchemaWithPipe<[StringSchema<undefined>, ReadonlyAction<string>]>;
key6: UndefinedableSchema<StringSchema<undefined>, 'bar'>;
},
BooleanSchema<undefined>,
undefined
Expand All @@ -68,9 +70,10 @@ describe('objectWithRestAsync', () => {
{
key1: string;
key2?: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
key5: string;
key6: string | undefined;
} & { [key: string]: boolean }
>();
});
Expand All @@ -80,9 +83,10 @@ describe('objectWithRestAsync', () => {
{
key1: string;
key2: string;
key3?: string | null;
key3?: string | null | undefined;
key4: { key: number };
readonly key5: string;
key6: string;
} & { [key: string]: boolean }
>();
});
Expand Down
Loading

0 comments on commit 0a2cd85

Please sign in to comment.