Skip to content

Commit

Permalink
Merge pull request #472 from shimataro/develop
Browse files Browse the repository at this point in the history
version 3.0.0-rc.7
  • Loading branch information
shimataro committed Jun 11, 2020
2 parents e912efb + 580185c commit 94ce449
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 12 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.0.0-rc.7] - 2020-06-11

### Fixed

* TypeScript Generics

## [3.0.0-rc.6] - 2020-06-11

### Fixed
Expand Down Expand Up @@ -471,7 +477,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* First release.

[Unreleased]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.6...HEAD
[Unreleased]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.7...HEAD
[3.0.0-rc.7]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.6...v3.0.0-rc.7
[3.0.0-rc.6]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.5...v3.0.0-rc.6
[3.0.0-rc.5]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.4...v3.0.0-rc.5
[3.0.0-rc.4]: https://github.com/shimataro/value-schema/compare/v3.0.0-rc.3...v3.0.0-rc.4
Expand Down
17 changes: 16 additions & 1 deletion examples/example-deno.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import * as assert from "https://deno.land/std/testing/asserts.ts";
import vs from "../mod.ts";

interface Input {
id: number;
name: string;
age: number;
email: string;
state: string;
classes: number[];
skills: string[];
creditCard: string;
remoteAddr: string;
remoteAddrIpv6: string;
limit: number,
offset: number,
};

const schemaObject: vs.SchemaObject = { // schema for input
id: vs.number({ // number, >=1
minValue: 1,
Expand Down Expand Up @@ -93,7 +108,7 @@ const expected = { // should be converted to this
};

// Let's apply!
const actual = vs.applySchemaObject(schemaObject, input);
const actual = vs.applySchemaObject<Input>(schemaObject, input);

// verification
assert.assertEquals(actual, expected);
Expand Down
17 changes: 16 additions & 1 deletion examples/example.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import assert from "assert";
import vs from "value-schema";

interface Input {
id: number;
name: string;
age: number;
email: string;
state: string;
classes: number[];
skills: string[];
creditCard: string;
remoteAddr: string;
remoteAddrIpv6: string;
limit: number,
offset: number,
};

const schemaObject: vs.SchemaObject = { // schema for input
id: vs.number({ // number, >=1
minValue: 1,
Expand Down Expand Up @@ -93,7 +108,7 @@ const expected = { // should be converted to this
};

// Let's apply!
const actual = vs.applySchemaObject(schemaObject, input);
const actual = vs.applySchemaObject<Input>(schemaObject, input);

// verification
assert.deepStrictEqual(actual, expected);
Expand Down
8 changes: 4 additions & 4 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "value-schema",
"description": "simple, easy-to-use, and declarative schema validator",
"version": "3.0.0-rc.6",
"version": "3.0.0-rc.7",
"author": "shimataro",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/applySchemaObject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {SchemaObject, applySchemaObjectCore} from "./applySchemaObjectCore";
import {ErrorHandler, FinishHandler, onErrorDefault, onFinishedDefault} from "./BaseSchema";

import {AnyObject} from "../libs/types";
import {Empty} from "../libs/types";

export {SchemaObject} from "./applySchemaObjectCore";
export {ErrorHandler} from "./BaseSchema";
Expand All @@ -14,7 +14,7 @@ export {ErrorHandler} from "./BaseSchema";
* @param onFinished finish handler
* @returns applied data
*/
export function applySchemaObject<T extends AnyObject>(schemaObject: SchemaObject, data: unknown, onError: ErrorHandler = onErrorDefault, onFinished: FinishHandler = onFinishedDefault): T
export function applySchemaObject<T extends Empty>(schemaObject: SchemaObject, data: unknown, onError: ErrorHandler = onErrorDefault, onFinished: FinishHandler = onFinishedDefault): T
{
return applySchemaObjectCore(schemaObject, data, onError, onFinished, []);
}
4 changes: 2 additions & 2 deletions src/libs/applySchemaObjectCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AnyObject, Key, isObject} from "./types";
import {AnyObject, Empty, Key, isObject} from "./types";
import {BaseSchema, ErrorHandler, FinishHandler} from "./BaseSchema";
import {CAUSE, ValueSchemaError} from "./ValueSchemaError";

Expand All @@ -13,7 +13,7 @@ export type SchemaObject = Record<string, BaseSchema>
* @param keyStack path to key that caused error
* @returns applied data
*/
export function applySchemaObjectCore<T extends AnyObject>(schemaObject: SchemaObject, data: unknown, onError: ErrorHandler, onFinished: FinishHandler, keyStack: Key[]): T
export function applySchemaObjectCore<T extends Empty>(schemaObject: SchemaObject, data: unknown, onError: ErrorHandler, onFinished: FinishHandler, keyStack: Key[]): T
{
if(!isObject(data))
{
Expand Down
4 changes: 4 additions & 0 deletions src/libs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ type Scalar = boolean | number | string;

export type AnyObject = Record<string, unknown>;

export interface Empty
{
}

export type Key = string | number;

export interface Values<T = unknown>
Expand Down

0 comments on commit 94ce449

Please sign in to comment.