Skip to content

Commit

Permalink
feat(utils) create createJSONSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
adwher committed Sep 24, 2024
1 parent c628972 commit 3932c32
Show file tree
Hide file tree
Showing 61 changed files with 592 additions and 71 deletions.
7 changes: 0 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"deno.enable": true,
"deno.lint": true,
"deno.enablePaths": [
"./pipes",
"./schemas",
"./utils",
"*.ts"
],
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
Expand Down
6 changes: 3 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adwher/typecheck",
"version": "0.3.0",
"version": "0.4.0",
"tasks": {
"ok:format": "deno fmt --check",
"ok:types": "deno check **/*.ts",
Expand All @@ -10,8 +10,8 @@
"ok": "deno task ok:format && deno task ok:types && deno task ok:lint && deno task ok:unit && deno task ok:publish"
},
"imports": {
"assert/": "https://deno.land/std@0.204.0/assert/",
"testing/": "https://deno.land/std@0.204.0/testing/"
"@std/assert": "jsr:@std/assert@^1.0.6",
"@std/testing": "jsr:@std/testing@^1.0.3"
},
"exports": {
".": "./mod.ts",
Expand Down
49 changes: 49 additions & 0 deletions deno.lock

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

1 change: 0 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ export * from "./context.ts";
export * from "./errors.ts";
export * from "./pipes.ts";
export * from "./schemas.ts";
export * from "./utils.ts";
2 changes: 1 addition & 1 deletion pipes/endsWith.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { endsWith } from "./endsWith.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isDate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { isDate } from "./isDate.ts";
import { pipe, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isDateTime.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { isDateTime } from "./isDateTime.ts";
import { pipe, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isEmail.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { isEmail } from "./isEmail.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isInteger.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number, pipe } from "../schemas.ts";
import { isInteger } from "./isInteger.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isMatch.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { isMatch } from "./isMatch.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isNegative.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number, pipe } from "../schemas.ts";
import { isNegative } from "./isNegative.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isPositive.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number, pipe } from "../schemas.ts";
import { isPositive } from "./isPositive.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isTime.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { isTime } from "./isTime.ts";
import { safeParse } from "../utils.ts";
import { pipe, string } from "../schemas.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/isURL.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { isURL } from "./isURL.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/length.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { array, number, pipe, string } from "../schemas.ts";
import { length } from "./length.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/maxLength.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { array, number, pipe, string } from "../schemas.ts";
import { maxLength } from "./maxLength.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/maxValue.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { date, number, pipe } from "../schemas.ts";
import { maxValue } from "./maxValue.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/minLength.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { array, number, pipe, string } from "../schemas.ts";
import { minLength } from "./minLength.ts";
import { safeParse } from "../utils.ts";
Expand Down
7 changes: 4 additions & 3 deletions pipes/minValue.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { assertObjectMatch } from "assert/mod.ts";
import { number, pipe } from "../schemas.ts";
import { assertObjectMatch } from "@std/assert";

import { date, number, pipe } from "../schemas.ts";
import { minValue } from "./minValue.ts";
import { date, safeParse } from "../mod.ts";
import { safeParse } from "../utils.ts";

Deno.test("restrict the allowed numbers", () => {
const schema = pipe(number(), minValue(2));
Expand Down
2 changes: 1 addition & 1 deletion pipes/nonEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { array, number, pipe, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";
import { nonEmpty } from "./nonEmpty.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/startsWith.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { startsWith } from "./startsWith.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/toCapitalize.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { toCapitalize } from "./toCapitalize.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/toLowerCase.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { toLowerCase } from "./toLowerCase.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/toTrimmed.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { toTrimmed } from "./toTrimmed.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion pipes/toUpperCase.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { toUpperCase } from "./toUpperCase.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion schemas/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { array, number } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/boolean.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { boolean } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
5 changes: 3 additions & 2 deletions schemas/custom.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";

import { isStr } from "../types.ts";
import { custom } from "../schemas.ts";
import { safeParse } from "../mod.ts";
import { failure } from "../schema.ts";
import { safeParse } from "../utils.ts";

Deno.test("assert with the given validation", () => {
type Distance = `${string}${"cm" | "m" | "km"}`;
Expand Down
2 changes: 1 addition & 1 deletion schemas/custom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context } from "../context.ts";
import { type Check, type Failure, failure, type Schema } from "../schema.ts";
import { isFailure } from "../utils.ts";
import { isFailure } from "../utils/isFailure.ts";

/** Function that validates the satisfaction of the given `value` as the given schema. */
export type SchemaValidation = (
Expand Down
5 changes: 3 additions & 2 deletions schemas/date.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertObjectMatch } from "assert/mod.ts";
import { safeParse } from "../mod.ts";
import { assertObjectMatch } from "@std/assert";

import { safeParse } from "../utils.ts";
import { date } from "./date.ts";

Deno.test("return on success", () => {
Expand Down
2 changes: 1 addition & 1 deletion schemas/either.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { boolean, either, number, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/enumerated.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { enumerated } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/lazy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { type Describe, failure } from "../schema.ts";
import { array, lazy, object } from "../schemas.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion schemas/lazy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context } from "../context.ts";
import type { CheckFrom, Failure, Schema, SchemaFrom } from "../schema.ts";
import { isFailure } from "../utils.ts";
import { isFailure } from "../utils/isFailure.ts";

export const SCHEMA_LAZY_NAME = "SCHEMA_LAZY";

Expand Down
2 changes: 1 addition & 1 deletion schemas/literal.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { literal } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/merge.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { merge, number, object, string } from "../schemas.ts";

Deno.test("merge object schemas", () => {
Expand Down
2 changes: 1 addition & 1 deletion schemas/never.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { never } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/nullable.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { boolean, nullable, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/number.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number, object, strict, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/omit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { object, omit, string } from "../schemas.ts";

Deno.test("omit the given fields on the shape", () => {
Expand Down
2 changes: 1 addition & 1 deletion schemas/optional.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { boolean, optional, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/override.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number, object, override, string } from "../schemas.ts";

Deno.test("override with the same key", () => {
Expand Down
2 changes: 1 addition & 1 deletion schemas/partial.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { object, partial, string } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/pick.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number, object, pick, string } from "../schemas.ts";

Deno.test("pick the given fields on the shape", () => {
Expand Down
4 changes: 2 additions & 2 deletions schemas/pipe.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertSpyCall, spy } from "testing/mock.ts";
import { assertObjectMatch } from "assert/mod.ts";
import { assertSpyCall, spy } from "@std/testing/mock";
import { assertObjectMatch } from "@std/assert";
import { pipe, string } from "../schemas.ts";
import { failure } from "../schema.ts";
import { safeParse } from "../utils.ts";
Expand Down
2 changes: 1 addition & 1 deletion schemas/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type SchemaFrom,
success,
} from "../schema.ts";
import { isFailure } from "../utils.ts";
import { isFailure } from "../utils/isFailure.ts";

/**
* Allow to transform the initial `value` and add extra validations with more details to the schemas.
Expand Down
2 changes: 1 addition & 1 deletion schemas/record.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { number, record } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemas/string.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertObjectMatch } from "assert/mod.ts";
import { assertObjectMatch } from "@std/assert";
import { string } from "../schemas.ts";
import { safeParse } from "../utils.ts";

Expand Down
Loading

0 comments on commit 3932c32

Please sign in to comment.