@forklaunch/validator 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +7 -3
  2. package/dist/index.d.ts +0 -88
  3. package/dist/index.js +0 -24
  4. package/dist/index.js.map +0 -1
  5. package/dist/interfaces/index.d.ts +0 -1
  6. package/dist/interfaces/index.js +0 -18
  7. package/dist/interfaces/index.js.map +0 -1
  8. package/dist/interfaces/schemaValidator.interfaces.d.ts +0 -108
  9. package/dist/interfaces/schemaValidator.interfaces.js +0 -3
  10. package/dist/interfaces/schemaValidator.interfaces.js.map +0 -1
  11. package/dist/jest.config.d.ts +0 -3
  12. package/dist/jest.config.js +0 -10
  13. package/dist/jest.config.js.map +0 -1
  14. package/dist/tests/mockSchemaValidator.d.ts +0 -21
  15. package/dist/tests/mockSchemaValidator.js +0 -42
  16. package/dist/tests/mockSchemaValidator.js.map +0 -1
  17. package/dist/tests/typebox/equality.test.d.ts +0 -1
  18. package/dist/tests/typebox/equality.test.js +0 -210
  19. package/dist/tests/typebox/equality.test.js.map +0 -1
  20. package/dist/tests/typebox/largeSchema.test.d.ts +0 -1
  21. package/dist/tests/typebox/largeSchema.test.js +0 -141
  22. package/dist/tests/typebox/largeSchema.test.js.map +0 -1
  23. package/dist/tests/zod/equality.test.d.ts +0 -1
  24. package/dist/tests/zod/equality.test.js +0 -214
  25. package/dist/tests/zod/equality.test.js.map +0 -1
  26. package/dist/tests/zod/largeSchema.test.d.ts +0 -1
  27. package/dist/tests/zod/largeSchema.test.js +0 -141
  28. package/dist/tests/zod/largeSchema.test.js.map +0 -1
  29. package/dist/typebox/index.d.ts +0 -148
  30. package/dist/typebox/index.js +0 -198
  31. package/dist/typebox/index.js.map +0 -1
  32. package/dist/typebox/types/typebox.schema.types.d.ts +0 -63
  33. package/dist/typebox/types/typebox.schema.types.js +0 -3
  34. package/dist/typebox/types/typebox.schema.types.js.map +0 -1
  35. package/dist/types/schema.types.d.ts +0 -28
  36. package/dist/types/schema.types.js +0 -3
  37. package/dist/types/schema.types.js.map +0 -1
  38. package/dist/zod/index.d.ts +0 -145
  39. package/dist/zod/index.js +0 -191
  40. package/dist/zod/index.js.map +0 -1
  41. package/dist/zod/types/zod.schema.types.d.ts +0 -65
  42. package/dist/zod/types/zod.schema.types.js +0 -3
  43. package/dist/zod/types/zod.schema.types.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/validator",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Schema validator for ForkLaunch components.",
5
5
  "files": [
6
6
  "dist"
@@ -12,8 +12,10 @@
12
12
  "scripts": {
13
13
  "test": "jest",
14
14
  "build": "tsc",
15
+ "docs": "typedoc --out docs *",
15
16
  "lint": "eslint . -c eslint.config.mjs",
16
- "lint:fix": "eslint . -c eslint.config.mjs --fix"
17
+ "lint:fix": "eslint . -c eslint.config.mjs --fix",
18
+ "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.ts' --write"
17
19
  },
18
20
  "repository": {
19
21
  "type": "git",
@@ -34,6 +36,8 @@
34
36
  "devDependencies": {
35
37
  "@eslint/js": "^9.6.0",
36
38
  "@types/jest": "^29.5.12",
39
+ "eslint-config-prettier": "^9.1.0",
40
+ "eslint-plugin-prettier": "^5.1.3",
37
41
  "globals": "^15.7.0",
38
42
  "openapi3-ts": "^4.3.3",
39
43
  "ts-jest": "^29.1.5",
@@ -74,4 +78,4 @@
74
78
  "default": "./dist/tests/mockSchemaValidator.js"
75
79
  }
76
80
  }
77
- }
81
+ }
package/dist/index.d.ts DELETED
@@ -1,88 +0,0 @@
1
- /**
2
- * This module provides type definitions and utilities for working with schemas using Zod and TypeBox.
3
- * It includes type mappings and transformations for schema objects, arrays, and resolutions.
4
- *
5
- * @module SchemaTypes
6
- */
7
- import { Prettify } from "@forklaunch/common";
8
- import { SchemaValidator } from "./interfaces/schemaValidator.interfaces";
9
- import { TypeboxSchemaValidator } from "./typebox";
10
- import { TCatchall, TObject, TObjectShape, TOuterArray, TResolve, TSchemaTranslate } from "./typebox/types/typebox.schema.types";
11
- import { IdiomaticSchema } from "./types/schema.types";
12
- import { ZodSchemaValidator } from "./zod";
13
- import { ZodCatchall, ZodObject, ZodObjectShape, ZodOuterArray, ZodResolve, ZodSchemaTranslate } from "./zod/types/zod.schema.types";
14
- /**
15
- * Interface representing unknown schema validator.
16
- * Extends the SchemaValidator interface with unknown schema types.
17
- */
18
- export type AnySchemaValidator = SchemaValidator<unknown, unknown, unknown, unknown, unknown, unknown, unknown>;
19
- /**
20
- * Type alias for a schema object shape.
21
- * Resolves to ZodObjectShape for Zod schemas and TObjectShape for TypeBox schemas.
22
- *
23
- * @template SV - SchemaValidator type.
24
- */
25
- type SchemaObjectShape<SV extends AnySchemaValidator> = (SV extends ZodSchemaValidator ? ZodObjectShape : SV extends TypeboxSchemaValidator ? TObjectShape : never);
26
- /**
27
- * Type alias for a schema object.
28
- * Resolves to ZodObject for Zod schemas and TObject for TypeBox schemas.
29
- *
30
- * @template T - Schema object shape.
31
- * @template SV - SchemaValidator type.
32
- */
33
- type SchemaObject<T extends SchemaObjectShape<SV>, SV extends AnySchemaValidator> = (SV extends ZodSchemaValidator ? ZodObject<T> : SV extends TypeboxSchemaValidator ? TObject<T> : never);
34
- /**
35
- * Type alias for a schema outer array.
36
- * Resolves to ZodOuterArray for Zod schemas and TOuterArray for TypeBox schemas.
37
- *
38
- * @template T - Schema object.
39
- * @template SV - SchemaValidator type.
40
- */
41
- type SchemaOuterArray<T extends SchemaObject<SchemaObjectShape<SV>, SV>, SV extends AnySchemaValidator> = (SV extends ZodSchemaValidator ? ZodOuterArray<T> : SV extends TypeboxSchemaValidator ? TOuterArray<T> : never);
42
- /**
43
- * Type alias for resolving a schema.
44
- * Resolves to ZodResolve for Zod schemas and TResolve for TypeBox schemas.
45
- *
46
- * @template T - Schema type.
47
- * @template SV - SchemaValidator type.
48
- */
49
- type SchemaResolve<T, SV extends AnySchemaValidator> = (SV extends ZodSchemaValidator ? ZodResolve<T> : SV extends TypeboxSchemaValidator ? TResolve<T> : never);
50
- /**
51
- * Type alias for translating a schema.
52
- * Resolves to ZodSchemaTranslate for Zod schemas and TSchemaTranslate for TypeBox schemas.
53
- *
54
- * @template T - Schema type.
55
- * @template SV - SchemaValidator type.
56
- */
57
- type SchemaTranslate<T, SV extends AnySchemaValidator> = (SV extends ZodSchemaValidator ? ZodSchemaTranslate<T> : SV extends TypeboxSchemaValidator ? TSchemaTranslate<T> : never);
58
- /**
59
- * Type alias for prettifying a schema translation.
60
- * Uses the Prettify utility from @forklaunch/common.
61
- *
62
- * @template T - Schema type.
63
- * @template SV - SchemaValidator type.
64
- */
65
- type SchemaPrettify<T, SV extends AnySchemaValidator> = Prettify<SchemaTranslate<T, SV>>;
66
- /**
67
- * Type alias for a schema catchall type.
68
- * Resolves to ZodCatchall for Zod schemas and TCatchall for TypeBox schemas.
69
- *
70
- * @template SV - SchemaValidator type.
71
- */
72
- export type SchemaCatchall<SV extends AnySchemaValidator> = (SV extends ZodSchemaValidator ? ZodCatchall : SV extends TypeboxSchemaValidator ? TCatchall : never);
73
- /**
74
- * Type alias for a valid schema object.
75
- * Can be a schema object or a schema outer array.
76
- *
77
- * @template SV - SchemaValidator type.
78
- */
79
- export type ValidSchemaObject<SV extends AnySchemaValidator> = SchemaObject<SchemaObjectShape<SV>, SV> | SchemaOuterArray<SchemaObject<SchemaObjectShape<SV>, SV>, SV>;
80
- /**
81
- * Type alias for a schema.
82
- * Applies prettification to the resolved schema.
83
- *
84
- * @template T - Valid schema object or idiomatic schema.
85
- * @template SV - SchemaValidator type.
86
- */
87
- export type Schema<T extends ValidSchemaObject<SV> | IdiomaticSchema<SchemaCatchall<SV>>, SV extends AnySchemaValidator> = SchemaPrettify<SchemaResolve<T, SV>, SV>;
88
- export * from "./interfaces";
package/dist/index.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /**
3
- * This module provides type definitions and utilities for working with schemas using Zod and TypeBox.
4
- * It includes type mappings and transformations for schema objects, arrays, and resolutions.
5
- *
6
- * @module SchemaTypes
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./interfaces"), exports);
24
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAsHH,+CAA6B"}
@@ -1 +0,0 @@
1
- export * from './schemaValidator.interfaces';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./schemaValidator.interfaces"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C"}
@@ -1,108 +0,0 @@
1
- import { SchemaObject } from "openapi3-ts/oas31";
2
- import { LiteralSchema } from "../types/schema.types";
3
- /**
4
- * Interface representing a schema validator.
5
- *
6
- * @template UnionContainer - The type for union schemas.
7
- * @template IdiomaticSchema<unknown> - The type for idiomatic schemas.
8
- * @template Catchall - The catch-all type for all schemas.
9
- */
10
- export interface SchemaValidator<SchematicFunction = <T>(schema: T) => unknown, OptionalFunction = <T>(schema: T) => unknown, ArrayFunction = <T>(schema: T) => unknown, UnionFunction = <T>(schemas: T[]) => unknown, LiteralFunction = <T extends LiteralSchema>(schema: T) => unknown, ValidationFunction = <T>(schema: T, value: unknown) => boolean, OpenAPIFunction = <T>(schema: T) => SchemaObject> {
11
- /**
12
- * Validator for string type.
13
- */
14
- string: unknown;
15
- /**
16
- * Validator for number type.
17
- */
18
- number: unknown;
19
- /**
20
- * Validator for bigint type.
21
- */
22
- bigint: unknown;
23
- /**
24
- * Validator for boolean type.
25
- */
26
- boolean: unknown;
27
- /**
28
- * Validator for date type.
29
- */
30
- date: unknown;
31
- /**
32
- * Validator for symbol type.
33
- */
34
- symbol: unknown;
35
- /**
36
- * Validator for empty type.
37
- */
38
- empty: unknown;
39
- /**
40
- * Validator for any type.
41
- */
42
- any: unknown;
43
- /**
44
- * Validator for unknown type.
45
- */
46
- unknown: unknown;
47
- /**
48
- * Validator for never type.
49
- */
50
- never: unknown;
51
- /**
52
- * Converts a valid schema input into a schemified form.
53
- *
54
- * @template T - The type of the idiomatic schema.
55
- * @param {T} schema - The schema to schemify.
56
- * @returns {unknown} - The schemified form of the schema.
57
- */
58
- schemify: SchematicFunction;
59
- /**
60
- * Converts a schema into an optional schema.
61
- *
62
- * @template T - The type of the idiomatic schema.
63
- * @param {T} schema - The schema to make optional.
64
- * @returns {unknown} - The optional form of the schema.
65
- */
66
- optional: OptionalFunction;
67
- /**
68
- * Converts a schema into an array schema.
69
- *
70
- * @template T - The type of the idiomatic schema.
71
- * @param {T} schema - The schema to convert into an array.
72
- * @returns {unknown} - The array form of the schema.
73
- */
74
- array: ArrayFunction;
75
- /**
76
- * Converts multiple schemas into a union schema.
77
- *
78
- * @template T - The type of the union container.
79
- * @param {T} schemas - The schemas to unionize.
80
- * @returns {unknown} - The union form of the schemas.
81
- */
82
- union: UnionFunction;
83
- /**
84
- * Creates a literal schema from a value.
85
- *
86
- * @template T - The type of the literal value.
87
- * @param {T} value - The literal value.
88
- * @returns {unknown} - The literal schema.
89
- */
90
- literal: LiteralFunction;
91
- /**
92
- * Validates a value against a schema.
93
- *
94
- * @template T - The type of the catch-all schema.
95
- * @param {T} schema - The schema to validate against.
96
- * @param {unknown} value - The value to validate.
97
- * @returns {boolean} - Whether the value is valid according to the schema.
98
- */
99
- validate: ValidationFunction;
100
- /**
101
- * Converts a schema into an OpenAPI schema object.
102
- *
103
- * @template T - The type of the idiomatic schema.
104
- * @param {T} schema - The schema to convert.
105
- * @returns {SchemaObject} - The OpenAPI schema object.
106
- */
107
- openapi: OpenAPIFunction;
108
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=schemaValidator.interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemaValidator.interfaces.js","sourceRoot":"","sources":["../../interfaces/schemaValidator.interfaces.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- import type { Config } from 'jest';
2
- declare const config: Config;
3
- export default config;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const config = {
4
- verbose: true,
5
- preset: 'ts-jest',
6
- testEnvironment: 'node',
7
- testPathIgnorePatterns: ['dist/', 'node_modules/']
8
- };
9
- exports.default = config;
10
- //# sourceMappingURL=jest.config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";;AAEA,MAAM,MAAM,GAAW;IACrB,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,MAAM;IACvB,sBAAsB,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC;CACnD,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -1,21 +0,0 @@
1
- import { SchemaValidator } from "../index";
2
- import { LiteralSchema } from "../types/schema.types";
3
- export declare class MockSchemaValidator implements SchemaValidator {
4
- string: string;
5
- number: string;
6
- bigint: string;
7
- boolean: string;
8
- date: string;
9
- symbol: string;
10
- empty: string;
11
- any: string;
12
- unknown: string;
13
- never: string;
14
- schemify<T>(schema: T): T;
15
- optional<T>(schema: T): string;
16
- array<T>(schema: T): string;
17
- union<T>(schemas: T[]): string;
18
- literal<T extends LiteralSchema>(schema: T): string;
19
- validate<T>(schema: T): boolean;
20
- openapi<T>(schema: T): {};
21
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MockSchemaValidator = void 0;
4
- class MockSchemaValidator {
5
- string = 'string';
6
- number = 'number';
7
- bigint = 'bigint';
8
- boolean = 'boolean';
9
- date = 'date';
10
- symbol = 'symbol';
11
- empty = 'empty';
12
- any = 'any';
13
- unknown = 'unknown';
14
- never = 'never';
15
- schemify(schema) {
16
- return schema;
17
- }
18
- ;
19
- optional(schema) {
20
- return 'optional ' + schema;
21
- }
22
- ;
23
- array(schema) {
24
- return 'array ' + schema;
25
- }
26
- union(schemas) {
27
- return schemas.join(' | ');
28
- }
29
- literal(schema) {
30
- return 'literal ' + schema;
31
- }
32
- ;
33
- validate(schema) {
34
- return true;
35
- }
36
- ;
37
- openapi(schema) {
38
- return {};
39
- }
40
- }
41
- exports.MockSchemaValidator = MockSchemaValidator;
42
- //# sourceMappingURL=mockSchemaValidator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockSchemaValidator.js","sourceRoot":"","sources":["../../tests/mockSchemaValidator.ts"],"names":[],"mappings":";;;AAIA,MAAa,mBAAmB;IAC5B,MAAM,GAAG,QAAQ,CAAC;IAClB,MAAM,GAAG,QAAQ,CAAC;IAClB,MAAM,GAAG,QAAQ,CAAC;IAClB,OAAO,GAAG,SAAS,CAAC;IACpB,IAAI,GAAG,MAAM,CAAC;IACd,MAAM,GAAG,QAAQ,CAAC;IAClB,KAAK,GAAG,OAAO,CAAC;IAChB,GAAG,GAAG,KAAK,CAAC;IACZ,OAAO,GAAG,SAAS,CAAC;IACpB,KAAK,GAAG,OAAO,CAAC;IAEhB,QAAQ,CAAI,MAAS;QACjB,OAAO,MAAM,CAAC;IAClB,CAAC;IAAA,CAAC;IACF,QAAQ,CAAI,MAAS;QACjB,OAAO,WAAW,GAAG,MAAM,CAAC;IAChC,CAAC;IAAA,CAAC;IACF,KAAK,CAAI,MAAS;QACd,OAAO,QAAQ,GAAG,MAAM,CAAC;IAC7B,CAAC;IACD,KAAK,CAAI,OAAY;QACjB,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,CAA0B,MAAS;QACtC,OAAO,UAAU,GAAG,MAAM,CAAC;IAC/B,CAAC;IAAA,CAAC;IACF,QAAQ,CAAI,MAAS;QACjB,OAAO,IAAI,CAAC;IAChB,CAAC;IAAA,CAAC;IACF,OAAO,CAAI,MAAS;QAChB,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAjCD,kDAiCC"}
@@ -1 +0,0 @@
1
- export declare function assert<T extends never>(): void;
@@ -1,210 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assert = assert;
4
- const typebox_1 = require("@sinclair/typebox");
5
- const index_1 = require("../../typebox/index");
6
- const one = (0, index_1.array)({
7
- name: {
8
- j: (0, index_1.union)([index_1.string, index_1.number, index_1.date, index_1.boolean, index_1.bigint, index_1.empty, index_1.symbol, index_1.never]),
9
- t: (0, index_1.optional)((0, index_1.union)([(0, index_1.array)({
10
- y: (0, index_1.array)(index_1.number)
11
- }), index_1.string])),
12
- m: {
13
- a: (0, index_1.optional)(index_1.string),
14
- b: index_1.number,
15
- c: {
16
- d: index_1.string,
17
- e: index_1.number
18
- }
19
- }
20
- },
21
- 200: {
22
- j: index_1.string
23
- },
24
- m: {
25
- a: true
26
- }
27
- });
28
- const two = (0, index_1.array)({
29
- name: {
30
- j: (0, index_1.union)([index_1.string, index_1.number, index_1.date, index_1.boolean, index_1.bigint, index_1.empty, index_1.symbol, index_1.never]),
31
- t: (0, index_1.optional)((0, index_1.union)([(0, index_1.array)({
32
- y: (0, index_1.array)(index_1.number)
33
- }), index_1.string])),
34
- m: (0, index_1.schemify)({
35
- a: (0, index_1.optional)(index_1.string),
36
- b: index_1.number,
37
- c: {
38
- d: index_1.string,
39
- e: index_1.number
40
- }
41
- })
42
- },
43
- 200: {
44
- j: index_1.string
45
- },
46
- m: {
47
- a: true
48
- }
49
- });
50
- const three = (0, index_1.schemify)((0, index_1.array)((0, index_1.schemify)({
51
- name: (0, index_1.schemify)({
52
- j: (0, index_1.union)([index_1.string, index_1.number, index_1.date, index_1.boolean, index_1.bigint, index_1.empty, index_1.symbol, index_1.never]),
53
- t: (0, index_1.optional)((0, index_1.union)([(0, index_1.array)({
54
- y: (0, index_1.array)(index_1.number)
55
- }), index_1.string])),
56
- m: (0, index_1.schemify)({
57
- a: (0, index_1.optional)(index_1.string),
58
- b: index_1.number,
59
- c: {
60
- d: index_1.string,
61
- e: index_1.number
62
- }
63
- })
64
- }),
65
- 200: (0, index_1.schemify)({
66
- j: index_1.string
67
- }),
68
- m: (0, index_1.schemify)({
69
- a: true
70
- })
71
- })));
72
- function assert() { }
73
- assert();
74
- assert();
75
- assert();
76
- assert();
77
- const shortOne = {
78
- s: index_1.string,
79
- non: index_1.number
80
- };
81
- const shortTwo = (0, index_1.schemify)({
82
- s: index_1.string,
83
- non: index_1.number
84
- });
85
- assert();
86
- assert();
87
- describe('Typebox Equality Tests', () => {
88
- let schema;
89
- let schemified;
90
- let expectedSchema;
91
- beforeAll(() => {
92
- schema = {
93
- hello: {
94
- world: index_1.string
95
- },
96
- foo: {
97
- bar: index_1.number
98
- }
99
- };
100
- schemified = (0, index_1.schemify)(schema);
101
- expectedSchema = typebox_1.Type.Object({
102
- hello: typebox_1.Type.Object({
103
- world: typebox_1.Type.String()
104
- }),
105
- foo: typebox_1.Type.Object({
106
- bar: typebox_1.Type.Number()
107
- })
108
- });
109
- });
110
- test('Schema Equality', async () => {
111
- expect(schemified).toEqual(expectedSchema);
112
- expect(schemified).toEqual((0, index_1.schemify)({
113
- hello: {
114
- world: index_1.string
115
- },
116
- foo: {
117
- bar: index_1.number
118
- }
119
- }));
120
- expect(schemified).toEqual((0, index_1.schemify)({
121
- hello: (0, index_1.schemify)({
122
- world: index_1.string
123
- }),
124
- foo: {
125
- bar: index_1.number
126
- }
127
- }));
128
- expect(schemified).toEqual((0, index_1.schemify)({
129
- hello: {
130
- world: index_1.string
131
- },
132
- foo: (0, index_1.schemify)({
133
- bar: index_1.number
134
- })
135
- }));
136
- expect(schemified).toEqual((0, index_1.schemify)({
137
- hello: (0, index_1.schemify)({
138
- world: index_1.string
139
- }),
140
- foo: (0, index_1.schemify)({
141
- bar: index_1.number
142
- })
143
- }));
144
- });
145
- test('Optional Schema Equality', async () => {
146
- const unboxSchemified = (0, index_1.optional)(schema);
147
- const boxSchemified = (0, index_1.optional)(schemified);
148
- const schemifiedExpected = typebox_1.Type.Optional(expectedSchema);
149
- expect(unboxSchemified).toEqual(schemifiedExpected);
150
- expect(boxSchemified).toEqual(schemifiedExpected);
151
- });
152
- test('Array Schema Equality', async () => {
153
- const unboxSchemified = (0, index_1.array)(schema);
154
- const boxSchemified = (0, index_1.array)(schemified);
155
- const schemifiedExpected = typebox_1.Type.Array(expectedSchema);
156
- expect(unboxSchemified).toEqual(schemifiedExpected);
157
- expect(boxSchemified).toEqual(schemifiedExpected);
158
- });
159
- test('Union Schema Equality', async () => {
160
- const unboxSchemified = (0, index_1.union)([schema, {
161
- test: index_1.string
162
- }]);
163
- const unboxSchemified2 = (0, index_1.union)([schema, (0, index_1.schemify)({
164
- test: index_1.string
165
- })]);
166
- const boxSchemified1 = (0, index_1.union)([schemified, (0, index_1.schemify)({
167
- test: index_1.string
168
- })]);
169
- const boxSchemified2 = (0, index_1.union)([schemified, {
170
- test: index_1.string
171
- }]);
172
- const schemifiedExpected = typebox_1.Type.Union([expectedSchema, typebox_1.Type.Object({
173
- test: typebox_1.Type.String()
174
- })]);
175
- expect(unboxSchemified).toEqual(schemifiedExpected);
176
- expect(unboxSchemified2).toEqual(schemifiedExpected);
177
- });
178
- test('Literal Schema Equality', async () => {
179
- const schemified = (0, index_1.schemify)({
180
- hello: 'world'
181
- });
182
- expect(schemified).toEqual(typebox_1.Type.Object({
183
- hello: typebox_1.Type.Literal('world')
184
- }));
185
- });
186
- test('Validate Schema', async () => {
187
- expect((0, index_1.validate)(schemified, {
188
- hello: {
189
- world: 'world'
190
- },
191
- foo: {
192
- bar: 42
193
- }
194
- })).toBe(true);
195
- expect((0, index_1.validate)(schemified, {
196
- hello: {
197
- world: 55
198
- },
199
- foo: {
200
- bar: 42
201
- }
202
- })).toBe(false);
203
- });
204
- test('OpenAPI Conversion', async () => {
205
- const schemified = (0, index_1.schemify)(schema);
206
- const openApi = (0, index_1.openapi)(schemified);
207
- expect(openApi).toEqual(schemified);
208
- });
209
- });
210
- //# sourceMappingURL=equality.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"equality.test.js","sourceRoot":"","sources":["../../../tests/typebox/equality.test.ts"],"names":[],"mappings":";;AAwEA,wBAA4C;AAxE5C,+CAAiD;AAEjD,+CAA8K;AAG9K,MAAM,GAAG,GAAG,IAAA,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