Skip to content

Commit

Permalink
Revert "Support vite out of the box"
Browse files Browse the repository at this point in the history
This reverts commit 8b95bf9.
  • Loading branch information
decs committed Sep 23, 2023
1 parent 309348f commit 2812493
Show file tree
Hide file tree
Showing 36 changed files with 227 additions and 76 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"jest"
],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/consistent-type-imports": [
"error",
{
Expand Down
33 changes: 15 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,31 @@ jobs:
validate(z.string(), 'hello').then(console.log);
" > src/main.ts
echo "
import {defineConfig} from 'vite';
import {typeschemaPlugin} from '@decs/typeschema/vite';
export default defineConfig({
plugins: [typeschemaPlugin()],
});
" > vite.config.ts
- name: Bundle project
working-directory: ./sample
run: yarn build

check_for_version_upgrade:
name: Check for version upgrade
if: |
github.event_name == 'push' ||
github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
runs-on: ubuntu-latest
needs:
- bundle_with_vite
outputs:
from_version: ${{steps.check.outputs.from_version}}
to_version: ${{steps.check.outputs.to_version}}
is_upgraded_version: ${{steps.check.outputs.is_upgraded_version}}
is_pre_release: ${{steps.check.outputs.is_pre_release}}
from_version: ${{steps.step1.outputs.from_version}}
to_version: ${{steps.step1.outputs.to_version}}
is_upgraded_version: ${{steps.step1.outputs.is_upgraded_version}}
is_pre_release: ${{steps.step1.outputs.is_pre_release}}
steps:
- uses: garronej/[email protected]
id: check
id: step1
with:
action_name: is_package_json_version_upgraded
branch: ${{github.head_ref || github.ref}}
Expand All @@ -92,11 +97,7 @@ jobs:
needs:
- check_for_version_upgrade
if: |
needs.check_for_version_upgrade.outputs.is_upgraded_version == 'true' &&
(
github.event_name == 'push' ||
needs.check_for_version_upgrade.outputs.is_pre_release == 'true'
)
needs.check_for_version_upgrade.outputs.is_upgraded_version == 'true'
steps:
- name: Checkout source code
uses: actions/checkout@v4
Expand Down Expand Up @@ -145,11 +146,7 @@ jobs:
needs:
- check_for_version_upgrade
if: |
needs.check_for_version_upgrade.outputs.is_upgraded_version == 'true' &&
(
github.event_name == 'push' ||
needs.check_for_version_upgrade.outputs.is_pre_release == 'true'
)
needs.check_for_version_upgrade.outputs.is_upgraded_version == 'true'
steps:
- name: Checkout source code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
.next

dist/
vite/
deno_dist/

yarn-debug.log*
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ Install TypeSchema with your package manager of choice:
</tr>
</table>

#### Vite

If using [Vite](https://vitejs.dev/), you'll also need to update your `vite.config.ts` file:

```ts
import {typeschemaPlugin} from '@decs/typeschema/vite';

export default defineConfig({
plugins: [
typeschemaPlugin(), // add this plugin
],
});
```

## API

#### Types
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@decs/typeschema",
"version": "0.11.5",
"version": "0.11.2",
"description": "Universal adapter for schema validation",
"keywords": [
"typescript",
Expand Down Expand Up @@ -32,7 +32,8 @@
"email": "[email protected]"
},
"files": [
"/dist"
"/dist",
"/vite"
],
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand All @@ -47,6 +48,10 @@
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./vite": {
"types": "./vite/index.d.ts",
"default": "./vite/index.js"
}
},
"sideEffects": false,
Expand Down Expand Up @@ -111,6 +116,7 @@
"typescript": "^5.2.2",
"typia": "^5.0.5",
"valibot": "^0.17.0",
"vite": "^4.4.9",
"webpack": "^5.88.2",
"yup": "^1.2.0",
"zod": "^3.22.2"
Expand All @@ -129,6 +135,7 @@
"runtypes": "^6.7.0",
"superstruct": "^1.0.3",
"valibot": "^0.17.0",
"vite": "^4.4.9",
"yup": "^1.2.0",
"zod": "^3.22.2"
},
Expand Down Expand Up @@ -172,6 +179,9 @@
"valibot": {
"optional": true
},
"vite": {
"optional": true
},
"yup": {
"optional": true
},
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ajv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ajv', () => {
required: ['age', 'createdAt', 'email', 'id', 'name', 'updatedAt'],
type: 'object',
};
const module = 'ajv';
const module = '../adapters/modules/ajv';

const data = {
age: 123,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/deepkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('deepkit', () => {
name: string;
updatedAt: string;
}>();
const module = '@deepkit/type';
const module = '../adapters/modules/deepkit';

const data = {
age: 123,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/effect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('effect', () => {
name: S.string,
updatedAt: S.dateFromString(S.string),
});
const module = '@effect/schema/Schema';
const module = '../adapters/modules/effect';

const data = readonly({
age: 123,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/io-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('io-ts', () => {
name: t.string,
updatedAt: DateFromISOString,
});
const module = 'fp-ts/Either';
const module = '../adapters/modules/io-ts';

const data = {
age: 123,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('ow', () => {
name: ow.string,
updatedAt: ow.string,
});
const module = 'ow';
const module = '../adapters/modules/ow';

const data = {
age: 123,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/typebox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('typebox', () => {
name: Type.String(),
updatedAt: Type.String(),
});
const module = '@sinclair/typebox/compiler';
const module = '../adapters/modules/typebox';

const data = {
age: 123,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/valibot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('valibot', () => {
name: string(),
updatedAt: transform(string(), value => new Date(value)),
});
const module = 'valibot';
const module = '../adapters/modules/valibot';

const data = {
age: 123,
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/yup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('yup', () => {
name: string().required(),
updatedAt: date().required(),
});
const module = 'yup';
const module = '../adapters/modules/yup';

const data = {
age: 123,
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ export interface AjvResolver extends Resolver {
base: SchemaObject;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const Ajv = require('ajv').default as typeof import('ajv').default;
return {ajv: new Ajv()};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/ajv'),
);

const coerce: Coerce<'ajv'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema =>
isJSONSchema(schema) ? fn(schema) : undefined;
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/deepkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ export interface DeepkitResolver extends Resolver {
base: Type;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {validate} = require('@deepkit/type') as typeof import('@deepkit/type');
return {validate};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/deepkit'),
);

const coerce: Coerce<'deepkit'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema =>
'kind' in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema)
Expand Down
12 changes: 3 additions & 9 deletions src/adapters/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ export interface EffectResolver extends Resolver {
: never;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {isRight} =
require('@effect/data/Either') as typeof import('@effect/data/Either');
const {isSchema, parseEither} =
require('@effect/schema/Schema') as typeof import('@effect/schema/Schema');
const {formatErrors} =
require('@effect/schema/TreeFormatter') as typeof import('@effect/schema/TreeFormatter');
return {formatErrors, isRight, isSchema, parseEither};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/effect'),
);

const coerce: Coerce<'effect'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema => {
return 'ast' in schema && !isJSONSchema(schema) && !isTypeBoxSchema(schema)
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/io-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ export interface IoTsResolver extends Resolver {
output: this['schema'] extends Any ? TypeOf<this['schema']> : never;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {isRight} = require('fp-ts/Either') as typeof import('fp-ts/Either');
return {isRight};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/io-ts'),
);

const coerce: Coerce<'io-ts'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema =>
'encode' in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema)
Expand Down
3 changes: 3 additions & 0 deletions src/adapters/modules/ajv.deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Ajv from 'npm:[email protected]';

export const ajv = new Ajv.default();
3 changes: 3 additions & 0 deletions src/adapters/modules/ajv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Ajv from 'ajv';

export const ajv = new Ajv();
1 change: 1 addition & 0 deletions src/adapters/modules/deepkit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {validate} from '@deepkit/type';
3 changes: 3 additions & 0 deletions src/adapters/modules/effect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {isRight} from '@effect/data/Either';
export {isSchema, parseEither} from '@effect/schema/Schema';
export {formatErrors} from '@effect/schema/TreeFormatter';
1 change: 1 addition & 0 deletions src/adapters/modules/io-ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {isRight} from 'fp-ts/Either';
6 changes: 6 additions & 0 deletions src/adapters/modules/ow.deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {Ow} from 'npm:[email protected]';

import owImport from 'npm:[email protected]';

export {ArgumentError} from 'npm:[email protected]';
export const ow: Ow = owImport.default;
6 changes: 6 additions & 0 deletions src/adapters/modules/ow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {Ow} from 'ow';

import owImport from 'ow';

export {ArgumentError} from 'ow';
export const ow: Ow = owImport;
1 change: 1 addition & 0 deletions src/adapters/modules/typebox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {TypeCompiler} from '@sinclair/typebox/compiler';
1 change: 1 addition & 0 deletions src/adapters/modules/valibot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {safeParseAsync} from 'valibot';
1 change: 1 addition & 0 deletions src/adapters/modules/yup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {ValidationError} from 'yup';
8 changes: 3 additions & 5 deletions src/adapters/ow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ export interface OwResolver extends Resolver {
output: this['schema'] extends Predicate ? Infer<this['schema']> : never;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const ow = require('ow').default as typeof import('ow').default;
const {ArgumentError} = require('ow') as typeof import('ow');
return {ArgumentError, ow};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/ow'),
);

const coerce: Coerce<'ow'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema =>
'context' in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema)
Expand Down
8 changes: 3 additions & 5 deletions src/adapters/typebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ export interface TypeBoxResolver extends Resolver {
output: this['schema'] extends TSchema ? Static<this['schema']> : never;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {TypeCompiler} =
require('@sinclair/typebox/compiler') as typeof import('@sinclair/typebox/compiler');
return {TypeCompiler};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/typebox'),
);

const coerce: Coerce<'typebox'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema =>
isTypeBoxSchema(schema) ? fn(schema) : undefined;
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ export interface ValibotResolver extends Resolver {
: never;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {safeParseAsync} = require('valibot') as typeof import('valibot');
return {safeParseAsync};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/valibot'),
);

const coerce: Coerce<'valibot'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema =>
'async' in schema && !isTypeBoxSchema(schema) && !isJSONSchema(schema)
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/yup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ export interface YupResolver extends Resolver {
output: this['schema'] extends Schema ? InferType<this['schema']> : never;
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {ValidationError} = require('yup') as typeof import('yup');
return {ValidationError};
});
export const fetchModule = /* @__PURE__ */ memoize(
() => import('./modules/yup'),
);

const coerce: Coerce<'yup'> = /* @__NO_SIDE_EFFECTS__ */ fn => schema =>
'__isYupSchema__' in schema &&
Expand Down
Loading

0 comments on commit 2812493

Please sign in to comment.