Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/actions/environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Setup environment
description: Setup environment with Node.js, Deno and pnpm

runs:
using: composite
steps:
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: pnpm

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Install dependencies
shell: bash
run: pnpm install

- name: Create library build cache
id: library-build-cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/library/dist
key: library-build-cache-${{ hashFiles('library/src/**/*.ts', '!library/src/**/*.test.ts', '!library/src/**/*.test-d.ts') }}

- name: Build library
if: steps.library-build-cache.outputs.cache-hit != 'true'
shell: bash
run: pnpm build
working-directory: library
27 changes: 0 additions & 27 deletions .github/actions/pnpm/action.yml

This file was deleted.

69 changes: 33 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ jobs:
name: Install packages
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment

library_build:
name: Build and publish library
library_preview:
name: Publish library via pkg.pr.new
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Build
run: pnpm build
working-directory: library
- name: Publish
- name: Setup environment
uses: ./.github/actions/environment
- name: Publish library
run: pnpx pkg-pr-new publish --compact --comment=update --pnpm
working-directory: library

Expand All @@ -37,10 +34,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: Prettier check
run: pnpm format.check
working-directory: library
Expand All @@ -50,10 +47,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: ESLint check
run: pnpm lint
working-directory: library
Expand All @@ -63,10 +60,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: Vitest tests
run: pnpm test
working-directory: library
Expand All @@ -76,10 +73,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: Prettier check
run: pnpm format.check
working-directory: packages/to-json-schema
Expand All @@ -89,10 +86,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: ESLint check
run: pnpm lint
working-directory: packages/to-json-schema
Expand All @@ -102,10 +99,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: Vitest tests
run: pnpm test
working-directory: packages/to-json-schema
Expand All @@ -115,10 +112,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: Prettier check
run: pnpm format.check
working-directory: website
Expand All @@ -128,10 +125,10 @@ jobs:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
uses: ./.github/actions/pnpm
- name: Setup environment
uses: ./.github/actions/environment
- name: ESLint check
run: pnpm lint
working-directory: website
45 changes: 21 additions & 24 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
contents: read
id-token: write
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
- name: Setup environment
uses: ./.github/actions/pnpm
- name: Build
- name: Build library
run: pnpm build
working-directory: library
- name: Publish
- name: Publish library
run: pnpm publish --provenance --access public --no-git-checks
working-directory: library
continue-on-error: true
Expand All @@ -40,9 +40,9 @@ jobs:
contents: read
id-token: write
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Publish
- name: Publish library
run: npx jsr publish
working-directory: library

Expand All @@ -54,14 +54,14 @@ jobs:
contents: read
id-token: write
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
- name: Setup environment
uses: ./.github/actions/pnpm
- name: Build
- name: Build i18n
run: pnpm build.npm
working-directory: packages/i18n
- name: Publish
- name: Publish i18n
run: pnpm publish --provenance --access public --no-git-checks
working-directory: packages/i18n
continue-on-error: true
Expand All @@ -76,14 +76,14 @@ jobs:
contents: read
id-token: write
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
- name: Setup environment
uses: ./.github/actions/pnpm
- name: Build
- name: Build i18n
run: pnpm build.jsr
working-directory: packages/i18n
- name: Publish
- name: Publish i18n
run: npx jsr publish --allow-dirty
working-directory: packages/i18n

Expand All @@ -95,14 +95,14 @@ jobs:
contents: read
id-token: write
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
- name: Setup environment
uses: ./.github/actions/pnpm
- name: Build
- name: Build to-json-schema
run: pnpm build
working-directory: packages/to-json-schema
- name: Publish
- name: Publish to-json-schema
run: pnpm publish --provenance --access public --no-git-checks
working-directory: packages/to-json-schema
continue-on-error: true
Expand All @@ -117,13 +117,10 @@ jobs:
contents: read
id-token: write
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup pnpm
- name: Setup environment
uses: ./.github/actions/pnpm
- name: Build
run: pnpm build
working-directory: library
- name: Publish
- name: Publish to-json-schema
run: npx jsr publish
working-directory: packages/to-json-schema
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 `message` method to overwrite local error message configuration of a schema (pull request #1103)
- Add `minProps` and `maxProps` validation action to validate number of object properties (pull request #1100)
- Change implementation of `variant` and `variantAsync` schema to improve performance by aborting validation of discriminators early (pull request #1110)

## v1.0.0 (March 18, 2025)
Expand Down
2 changes: 2 additions & 0 deletions library/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export * from './mapItems/index.ts';
export * from './maxBytes/index.ts';
export * from './maxGraphemes/index.ts';
export * from './maxLength/index.ts';
export * from './maxProps/index.ts';
export * from './maxSize/index.ts';
export * from './maxValue/index.ts';
export * from './maxWords/index.ts';
Expand All @@ -54,6 +55,7 @@ export * from './mimeType/index.ts';
export * from './minBytes/index.ts';
export * from './minGraphemes/index.ts';
export * from './minLength/index.ts';
export * from './minProps/index.ts';
export * from './minSize/index.ts';
export * from './minValue/index.ts';
export * from './minWords/index.ts';
Expand Down
1 change: 1 addition & 0 deletions library/src/actions/maxProps/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './maxProps.ts';
51 changes: 51 additions & 0 deletions library/src/actions/maxProps/maxProps.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { describe, expectTypeOf, test } from 'vitest';
import type { InferInput, InferIssue, InferOutput } from '../../types/index.ts';
import {
maxProps,
type MaxPropsAction,
type MaxPropsIssue,
} from './maxProps.ts';

describe('maxProps', () => {
type Input = Record<string, number>;

describe('should return action object', () => {
test('with undefined message', () => {
type Action = MaxPropsAction<Input, 10, undefined>;
expectTypeOf(maxProps<Input, 10>(10)).toEqualTypeOf<Action>();
expectTypeOf(
maxProps<Input, 10, undefined>(10, undefined)
).toEqualTypeOf<Action>();
});

test('with string message', () => {
expectTypeOf(maxProps<Input, 10, 'message'>(10, 'message')).toEqualTypeOf<
MaxPropsAction<Input, 10, 'message'>
>();
});

test('with function message', () => {
expectTypeOf(
maxProps<Input, 10, () => string>(10, () => 'message')
).toEqualTypeOf<MaxPropsAction<Input, 10, () => string>>();
});
});

describe('should infer correct types', () => {
type Action = MaxPropsAction<Input, 10, undefined>;

test('of input', () => {
expectTypeOf<InferInput<Action>>().toEqualTypeOf<Input>();
});

test('of output', () => {
expectTypeOf<InferOutput<Action>>().toEqualTypeOf<Input>();
});

test('of issue', () => {
expectTypeOf<InferIssue<Action>>().toEqualTypeOf<
MaxPropsIssue<Input, 10>
>();
});
});
});
Loading