Skip to content

Commit

Permalink
Merge branch 'main' into eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller authored Oct 20, 2023
2 parents 31ac6d3 + 1f213ec commit e1969e3
Show file tree
Hide file tree
Showing 92 changed files with 2,407 additions and 722 deletions.
34 changes: 34 additions & 0 deletions .github/actions/pnpm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Setup pnpm with cache

runs:
using: 'composite'
steps:
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install pnpm
uses: pnpm/action-setup@v2
id: pnpm-install
with:
version: 8
run_install: false

- name: Get store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install packages
shell: bash
run: pnpm install
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches: main
pull_request:

jobs:
install:
name: Install packages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: ./.github/actions/pnpm

library_prettier:
name: Run Prettier in library
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Prettier check
run: pnpm format.check
working-directory: library

library_eslint:
name: Run ESLint in library
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: ESLint check
run: pnpm lint
working-directory: library

library_vitest:
name: Run Vitest in library
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Vitest tests
run: pnpm test
working-directory: library

website_prettier:
name: Run Prettier in website
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Prettier check
run: pnpm format.check
working-directory: website

website_eslint:
name: Run ESLint in website
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: ESLint check
run: pnpm lint
working-directory: website
46 changes: 0 additions & 46 deletions .github/workflows/node.yml

This file was deleted.

20 changes: 18 additions & 2 deletions library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@ All notable changes to the library will be documented in this file.

## vX.X.X (Month DD, YYYY)

- Change regex of `email` validation (pull request #180)
- Fix types at `brand`, `transform` and `unwrap` method (issue #195)
- Add `getRestAndDefaultArgs` utility function
- Add new `rest` argument to `object` and `objectAsync` schema
- Fix type check in `date` and `dateAsync` for invalid dates (pull request #214)
- Improve security of regular expressions (pull request #202)
- Change `ObjectSchema` and `ObjectSchemaAsync` type
- Change type check in `tuple` and `tupleAsync` to be less strict
- Rename `ObjectShape` and `ObjectShapeAsync` types to `ObjectEntries` and `ObjectEntriesAsync`
- Rename `TupleShape` and `TupleShapeAsync` types to `TupleItems` and `TupleItemsAsync`
- Deprecate `passthrough`, `strict` and `strip` method in favor of `object` schema with `rest` argument

## v0.19.0 (October 08, 2023)

- Add `notBytes`, `notLength`, `notSize` and `notValue` validation function (pull request #194)
- Add support for unions as key of `record` and `recordAsync` schema (issue #201)
- Add support for pipeline validation to `transform` and `transformAsync` (issue #197)
- Change regex of `email` validation to improve performance and security (pull request #180)
- Change `object` and `objectAsync` schema to exclude non-existing keys (issue #199)
- Fix types at `brand`, `transform` and `unwrap` method (issue #195)
- Deprecate `equal` validation function in favor of `value` (issue #192)

## v0.18.0 (September 30, 2023)

Expand Down
2 changes: 1 addition & 1 deletion library/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "valibot",
"description": "The modular and TypeScript-first schema library",
"version": "0.18.0",
"version": "0.19.0",
"license": "MIT",
"author": "Fabian Hiller",
"homepage": "https://valibot.dev",
Expand Down
42 changes: 21 additions & 21 deletions library/src/error/flatten/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import type {
ArraySchemaAsync,
MapSchema,
MapSchemaAsync,
ObjectEntries,
ObjectEntriesAsync,
ObjectSchema,
ObjectSchemaAsync,
ObjectShape,
ObjectShapeAsync,
RecordSchema,
RecordSchemaAsync,
RecursiveSchema,
RecursiveSchemaAsync,
SetSchema,
SetSchemaAsync,
TupleItems,
TupleItemsAsync,
TupleSchema,
TupleSchemaAsync,
TupleShape,
TupleShapeAsync,
UnionOptions,
UnionOptionsAsync,
UnionSchema,
Expand All @@ -42,9 +42,9 @@ type DotPath<TKey, TSchema extends BaseSchema | BaseSchemaAsync> = TKey extends
/**
* Object path type.
*/
type ObjectPath<TObjectShape extends ObjectShape | ObjectShapeAsync> = {
[TKey in keyof TObjectShape]: DotPath<TKey, TObjectShape[TKey]>;
}[keyof TObjectShape];
type ObjectPath<TObjectEntries extends ObjectEntries | ObjectEntriesAsync> = {
[TKey in keyof TObjectEntries]: DotPath<TKey, TObjectEntries[TKey]>;
}[keyof TObjectEntries];

/**
* Tuple key type.
Expand All @@ -54,9 +54,9 @@ type TupleKey<T extends any[]> = Exclude<keyof T, keyof any[]>;
/**
* Tuple path type.
*/
type TuplePath<TTupleShape extends TupleShape | TupleShapeAsync> = {
[TKey in TupleKey<TTupleShape>]: DotPath<TKey, TTupleShape[TKey & number]>;
}[TupleKey<TTupleShape>];
type TuplePath<TTupleItems extends TupleItems | TupleItemsAsync> = {
[TKey in TupleKey<TTupleItems>]: DotPath<TKey, TTupleItems[TKey & number]>;
}[TupleKey<TTupleItems>];

/**
* Nested path type.
Expand All @@ -75,12 +75,12 @@ type NestedPath<TSchema extends BaseSchema | BaseSchemaAsync> =
| MapSchemaAsync<infer TMapKey, infer TMapValue>
? DotPath<Input<TMapKey>, TMapValue>
: // Object
TSchema extends ObjectSchema<infer TObjectShape extends ObjectShape>
? ObjectPath<TObjectShape>
: TSchema extends ObjectSchemaAsync<
infer TObjectShape extends ObjectShapeAsync
>
? ObjectPath<TObjectShape>
TSchema extends
| ObjectSchema<infer TObjectEntries, infer TObjectRest>
| ObjectSchemaAsync<infer TObjectEntries, infer TObjectRest>
? TObjectRest extends BaseSchema | BaseSchemaAsync
? ObjectPath<TObjectEntries> | DotPath<string, TObjectRest>
: ObjectPath<TObjectEntries>
: // Record
TSchema extends
| RecordSchema<infer TRecordKey, infer TRecordValue>
Expand All @@ -100,11 +100,11 @@ type NestedPath<TSchema extends BaseSchema | BaseSchemaAsync> =
? DotPath<number, TSetValue>
: // Tuple
TSchema extends
| TupleSchema<infer TTupleShape, infer TTupleRest>
| TupleSchemaAsync<infer TTupleShape, infer TTupleRest>
? TTupleRest extends BaseSchema
? TuplePath<TTupleShape> | DotPath<number, TTupleRest>
: TuplePath<TTupleShape>
| TupleSchema<infer TTupleItems, infer TTupleRest>
| TupleSchemaAsync<infer TTupleItems, infer TTupleRest>
? TTupleRest extends BaseSchema | BaseSchemaAsync
? TuplePath<TTupleItems> | DotPath<number, TTupleRest>
: TuplePath<TTupleItems>
: // Union
TSchema extends UnionSchema<infer TUnionOptions extends UnionOptions>
? NestedPath<TUnionOptions[number]>
Expand Down
32 changes: 20 additions & 12 deletions library/src/methods/brand/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@ export function brand<
Output<TSchema> & Brand<TBrandName>
>;

export function brand<TSchema extends NeverSchema>(
schema: TSchema,
action: (value: Output<TSchema>) => never
): NeverSchema;
export function brand<
TSchema extends NeverSchema,
TBrandName extends BrandName
>(schema: TSchema, name: TBrandName): NeverSchema;

export function brand<TSchema extends NeverSchemaAsync>(
schema: TSchema,
action: (value: Output<TSchema>) => never
): NeverSchemaAsync;
export function brand<
TSchema extends NeverSchemaAsync,
TBrandName extends BrandName
>(schema: TSchema, name: TBrandName): NeverSchemaAsync;

export function brand<
TSchema extends NonNullableSchema<any>,
Expand Down Expand Up @@ -449,20 +449,28 @@ export function brand<
): NumberSchemaAsync<Output<TSchema> & Brand<TBrandName>>;

export function brand<
TSchema extends ObjectSchema<any>,
TSchema extends ObjectSchema<any, any>,
TBrandName extends BrandName
>(
schema: TSchema,
name: TBrandName
): ObjectSchema<TSchema['object'], Output<TSchema> & Brand<TBrandName>>;
): ObjectSchema<
TSchema['object']['entries'],
TSchema['object']['rest'],
Output<TSchema> & Brand<TBrandName>
>;

export function brand<
TSchema extends ObjectSchemaAsync<any>,
TSchema extends ObjectSchemaAsync<any, any>,
TBrandName extends BrandName
>(
schema: TSchema,
name: TBrandName
): ObjectSchemaAsync<TSchema['object'], Output<TSchema> & Brand<TBrandName>>;
): ObjectSchemaAsync<
TSchema['object']['entries'],
TSchema['object']['rest'],
Output<TSchema> & Brand<TBrandName>
>;

export function brand<
TSchema extends OptionalSchema<any, any>,
Expand Down
8 changes: 4 additions & 4 deletions library/src/methods/keyof/keyof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ type TupleOrNever<T> = T extends [string, ...string[]] ? T : never;
* @returns A enum schema.
*/
export function keyof<
TSchema extends ObjectSchema<any> | ObjectSchemaAsync<any>
TSchema extends ObjectSchema<any, any> | ObjectSchemaAsync<any, any>
>(
schema: TSchema
): EnumSchema<TupleOrNever<UnionToTuple<keyof TSchema['object']>>> {
): EnumSchema<TupleOrNever<UnionToTuple<keyof TSchema['object']['entries']>>> {
return enumType(
Object.keys(schema.object) as TupleOrNever<
UnionToTuple<keyof TSchema['object']>
Object.keys(schema.object.entries) as TupleOrNever<
UnionToTuple<keyof TSchema['object']['entries']>
>
);
}
2 changes: 1 addition & 1 deletion library/src/methods/merge/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('merge', () => {
object({ key: string() }),
object({ key: number() }),
]);
expect(schema.object.key).toEqual(comparable(number()));
expect(schema.object.entries.key).toEqual(comparable(number()));
const input = { key: 123 };
const output = parse(schema, input);
expect(output).toEqual(input);
Expand Down
Loading

0 comments on commit e1969e3

Please sign in to comment.