Skip to content

Commit

Permalink
Refactor and restructure repository
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Jul 12, 2023
1 parent 739b9a4 commit f178218
Show file tree
Hide file tree
Showing 346 changed files with 825 additions and 750 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PathItem } from '../types';
import type { PathItem } from '../../types';

/**
* Issue reason type.
Expand Down
1 change: 1 addition & 0 deletions library/src/error/ValiError/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ValiError';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest';
import { ValiError } from './ValiError';
import { ValiError } from '../ValiError';
import { flatten } from './flatten';

describe('flatten', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ValiError } from './ValiError';
import type { ValiError } from '../ValiError';

/**
* Flat errors type.
Expand Down
1 change: 1 addition & 0 deletions library/src/error/flatten/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './flatten';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest';
import { parse } from './parse';
import { date, number, string } from '../../schemas';
import { parse } from '../parse';
import { coerce } from './coerce';
import { date, number, string } from '../schemas';

describe('coerce', () => {
test('should coerce number to string', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseSchema, Input } from '../types';
import type { BaseSchema, Input } from '../../types';

/**
* Coerces the input of a scheme to match the required type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest';
import { parseAsync } from './parseAsync';
import { dateAsync, numberAsync, stringAsync } from '../../schemas';
import { parseAsync } from '../parse';
import { coerceAsync } from './coerceAsync';
import { dateAsync, numberAsync, stringAsync } from '../schemas';

describe('coerceAsync', () => {
test('should coerce number to string', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseSchemaAsync, Input } from '../types';
import type { BaseSchemaAsync, Input } from '../../types';

/**
* Coerces the input of a async scheme to match the required type.
Expand Down
2 changes: 2 additions & 0 deletions library/src/methods/coerce/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './coerce';
export * from './coerceAsync';
13 changes: 2 additions & 11 deletions library/src/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
export * from './coerce';
export * from './coerceAsync';
export * from './keyof';
export { merge } from './merge';
export * from './mergeAsync';
export { omit } from './omit';
export * from './omitAsync';
export * from './merge';
export * from './omit';
export * from './parse';
export * from './parseAsync';
export * from './partial';
export * from './partialAsync';
export * from './pick';
export * from './pickAsync';
export * from './required';
export * from './requiredAsync';
export * from './safeParse';
export * from './safeParseAsync';
export * from './transform';
export * from './transformAsync';
export * from './unwrap';
export * from './useDefault';
1 change: 1 addition & 0 deletions library/src/methods/keyof/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './keyof';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest';
import { enumType, number, object, string } from '../../schemas';
import { comparable } from '../../utils';
import { keyof } from './keyof';
import { enumType, number, object, string } from '../schemas';
import { comparable } from '../utils';

describe('keyof', () => {
test('should create enum schema', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
type EnumSchema,
type ObjectSchema,
type ObjectSchemaAsync,
} from '../schemas';
} from '../../schemas';

/**
* Converts union to intersection types.
Expand Down
2 changes: 2 additions & 0 deletions library/src/methods/merge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './merge';
export * from './mergeAsync';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import { number, object, string } from '../schemas';
import { comparable } from '../utils';
import { merge } from './merge';
import { parse } from './parse';
import { number, object, string } from '../../schemas';
import { comparable } from '../../utils';
import { merge } from '../merge';
import { parse } from '../parse';

describe('merge', () => {
test('should merge object schemas', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {
object,
type ObjectOutput,
type ObjectSchema,
type ObjectSchemaAsync,
} from '../schemas';
import type { Pipe } from '../types';
import { getErrorAndPipe } from '../utils';
import { object, type ObjectOutput, type ObjectSchema } from '../../schemas';
import type { Pipe } from '../../types';
import { getErrorAndPipe } from '../../utils';
import type { MergeSchemaObjects } from './types';

/**
* Object schemas type.
Expand All @@ -16,31 +12,6 @@ type ObjectSchemas = [
...ObjectSchema<any>[]
];

/**
* Merges schema objects types.
*/
export type MergeSchemaObjects<
TObjectSchemas extends (ObjectSchema<any> | ObjectSchemaAsync<any>)[]
> = TObjectSchemas extends [infer TFirstObjectSchema]
? TFirstObjectSchema extends ObjectSchema<any> | ObjectSchemaAsync<any>
? TFirstObjectSchema['object']
: never
: TObjectSchemas extends [
infer TFirstObjectSchema,
...infer TRestObjectSchemas
]
? TFirstObjectSchema extends ObjectSchema<any> | ObjectSchemaAsync<any>
? TRestObjectSchemas extends (ObjectSchema<any> | ObjectSchemaAsync<any>)[]
? {
[TKey in Exclude<
keyof TFirstObjectSchema['object'],
keyof MergeSchemaObjects<TRestObjectSchemas>
>]: TFirstObjectSchema['object'][TKey];
} & MergeSchemaObjects<TRestObjectSchemas>
: never
: never
: never;

/**
* Merges multiple object schemas into a single one. Subsequent object schemas
* overwrite the previous ones.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import { number, object, objectAsync, string } from '../schemas';
import { comparable } from '../utils';
import { number, object, objectAsync, string } from '../../schemas';
import { comparable } from '../../utils';
import { parseAsync } from '../parse';
import { mergeAsync } from './mergeAsync';
import { parseAsync } from './parseAsync';

describe('mergeAsync', () => {
test('should merge object schemas', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
type ObjectOutput,
type ObjectSchema,
type ObjectSchemaAsync,
} from '../schemas';
import type { PipeAsync } from '../types';
import { getErrorAndPipe } from '../utils';
import type { MergeSchemaObjects } from './merge';
} from '../../schemas';
import type { PipeAsync } from '../../types';
import { getErrorAndPipe } from '../../utils';
import type { MergeSchemaObjects } from './types';

/**
* Object schemas type.
Expand Down
26 changes: 26 additions & 0 deletions library/src/methods/merge/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ObjectSchema, ObjectSchemaAsync } from '../../schemas';

/**
* Merges schema objects types.
*/
export type MergeSchemaObjects<
TObjectSchemas extends (ObjectSchema<any> | ObjectSchemaAsync<any>)[]
> = TObjectSchemas extends [infer TFirstObjectSchema]
? TFirstObjectSchema extends ObjectSchema<any> | ObjectSchemaAsync<any>
? TFirstObjectSchema['object']
: never
: TObjectSchemas extends [
infer TFirstObjectSchema,
...infer TRestObjectSchemas
]
? TFirstObjectSchema extends ObjectSchema<any> | ObjectSchemaAsync<any>
? TRestObjectSchemas extends (ObjectSchema<any> | ObjectSchemaAsync<any>)[]
? {
[TKey in Exclude<
keyof TFirstObjectSchema['object'],
keyof MergeSchemaObjects<TRestObjectSchemas>
>]: TFirstObjectSchema['object'][TKey];
} & MergeSchemaObjects<TRestObjectSchemas>
: never
: never
: never;
2 changes: 2 additions & 0 deletions library/src/methods/omit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './omit';
export * from './omitAsync';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import { comparable } from '../utils';
import { object, string } from '../schemas';
import { omit } from './omit';
import { parse } from './parse';
import { comparable } from '../../utils';
import { object, string } from '../../schemas';
import { omit } from '../omit';
import { parse } from '../parse';

describe('omit', () => {
test('should omit two object keys', () => {
Expand Down
19 changes: 4 additions & 15 deletions library/src/methods/omit.ts → library/src/methods/omit/omit.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import {
object,
type ObjectOutput,
type ObjectSchema,
type ObjectSchemaAsync,
} from '../schemas';
import type { Pipe } from '../types';
import { getErrorAndPipe } from '../utils';

/**
* Object keys type.
*/
export type ObjectKeys<
TObjectSchema extends ObjectSchema<any> | ObjectSchemaAsync<any>
> = [keyof TObjectSchema['object'], ...(keyof TObjectSchema['object'])[]];
import { object, type ObjectOutput, type ObjectSchema } from '../../schemas';
import type { Pipe } from '../../types';
import { getErrorAndPipe } from '../../utils';
import type { ObjectKeys } from './types';

/**
* Creates an object schema that contains not the selected keys of an existing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import { comparable } from '../utils';
import { object, objectAsync, string } from '../schemas';
import { comparable } from '../../utils';
import { object, objectAsync, string } from '../../schemas';
import { parseAsync } from '../parse';
import { omitAsync } from './omitAsync';
import { parseAsync } from './parseAsync';

describe('omitAsync', () => {
test('should omit two object keys', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
type ObjectOutput,
type ObjectSchema,
type ObjectSchemaAsync,
} from '../schemas';
import type { PipeAsync } from '../types';
import { getErrorAndPipe } from '../utils';
import type { ObjectKeys } from './omit';
} from '../../schemas';
import type { PipeAsync } from '../../types';
import { getErrorAndPipe } from '../../utils';
import type { ObjectKeys } from './types';

/**
* Creates an async object schema that contains only the selected keys of an
Expand Down
8 changes: 8 additions & 0 deletions library/src/methods/omit/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ObjectSchema, ObjectSchemaAsync } from '../../schemas';

/**
* Object keys type.
*/
export type ObjectKeys<
TObjectSchema extends ObjectSchema<any> | ObjectSchemaAsync<any>
> = [keyof TObjectSchema['object'], ...(keyof TObjectSchema['object'])[]];
2 changes: 2 additions & 0 deletions library/src/methods/parse/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './parse';
export * from './parseAsync';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest';
import { number, object, string } from '../../schemas';
import { parse } from './parse';
import { number, object, string } from '../schemas';

describe('parse', () => {
test('should parse schema', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseSchema, Output } from '../types';
import type { BaseSchema, Output } from '../../types';

/**
* Parses unknown input based on a schema.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'vitest';
import { numberAsync, object, string } from '../../schemas';
import { parseAsync } from './parseAsync';
import { numberAsync, object, string } from '../schemas';

describe('parseAsync', () => {
test('should parse schema', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseSchema, BaseSchemaAsync, Output } from '../types';
import type { BaseSchema, BaseSchemaAsync, Output } from '../../types';

/**
* Parses unknown input based on a schema.
Expand Down
2 changes: 2 additions & 0 deletions library/src/methods/partial/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './partial';
export * from './partialAsync';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import { comparable } from '../utils';
import { object, optional, string } from '../schemas';
import { comparable } from '../../utils';
import { object, optional, string } from '../../schemas';
import { parse } from '../parse';
import { partial } from './partial';
import { parse } from './parse';

describe('partial', () => {
test('should have optional keys', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
type ObjectShape,
optional,
type OptionalSchema,
} from '../schemas';
import type { BaseSchema, Pipe } from '../types';
import { getErrorAndPipe } from '../utils';
} from '../../schemas';
import type { BaseSchema, Pipe } from '../../types';
import { getErrorAndPipe } from '../../utils';

/**
* Partial object schema type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import { comparable } from '../utils';
import { object, objectAsync, optionalAsync, string } from '../schemas';
import { comparable } from '../../utils';
import { object, objectAsync, optionalAsync, string } from '../../schemas';
import { parseAsync } from '../parse';
import { partialAsync } from './partialAsync';
import { parseAsync } from './parseAsync';

describe('partialAsync', () => {
test('should have optional keys', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
type ObjectShapesAsync,
optionalAsync,
type OptionalSchemaAsync,
} from '../schemas';
import type { BaseSchema, Pipe } from '../types';
import { getErrorAndPipe } from '../utils';
} from '../../schemas';
import type { BaseSchema, Pipe } from '../../types';
import { getErrorAndPipe } from '../../utils';

/**
* Partial object schema type.
Expand Down
2 changes: 2 additions & 0 deletions library/src/methods/pick/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './pick';
export * from './pickAsync';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import { comparable } from '../utils';
import { object, string } from '../schemas';
import { comparable } from '../../utils';
import { object, string } from '../../schemas';
import { parse } from '../parse';
import { pick } from './pick';
import { parse } from './parse';

describe('pick', () => {
test('should pick two object keys', () => {
Expand Down
Loading

0 comments on commit f178218

Please sign in to comment.