@serum-enterprises/schema 2.0.1-beta.0

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.
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2024", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4
+ "module": "Node16", /* Specify what module code is generated. */
5
+ "lib": ["ES2024"], /* Specify library files to be included in the compilation. */
6
+ "rootDir": "./src", /* Specify the root folder within your source files. */
7
+ "outDir": "./build", /* Specify an output folder for all emitted files. */
8
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
9
+ "declarationDir": "./types", /* Specify the output directory for generated declaration files. */
10
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
11
+ /* Type Checking */
12
+ "strict": true, /* Enable all strict type-checking options. */
13
+ "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
14
+ "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
15
+ "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
16
+ "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
17
+ "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
18
+ "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
19
+ "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
20
+ "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
21
+ "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
22
+ "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
23
+ "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
24
+ "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
25
+ "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
26
+ "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
27
+ "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
28
+ "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
29
+ }
30
+ }
@@ -0,0 +1,99 @@
1
+ import * as JSON from '@serum-enterprises/json';
2
+ import { Result } from '@serum-enterprises/result';
3
+ export declare class SchemaError extends Error {
4
+ }
5
+ export declare class ValidationError extends Error {
6
+ }
7
+ export declare abstract class Schema {
8
+ static get Any(): AnyValidator;
9
+ static get Boolean(): BooleanValidator;
10
+ static get Number(): NumberValidator;
11
+ static get String(): StringValidator;
12
+ static get Array(): ArrayValidator;
13
+ static get Object(): ObjectValidator;
14
+ static get Or(): OrValidator;
15
+ static get And(): AndValidator;
16
+ static get defaultRegistry(): Map<string, typeof Schema>;
17
+ static fromJSON(schema: JSON.JSON, path?: string, registry?: Map<string, typeof Schema>): Result<Schema, SchemaError>;
18
+ abstract validate(data: unknown, path?: string): Result<void, ValidationError>;
19
+ abstract toJSON(): JSON.Object;
20
+ }
21
+ declare class AnyValidator extends Schema {
22
+ static fromJSON(schema: JSON.JSON, path?: string): Result<AnyValidator, SchemaError>;
23
+ constructor();
24
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
25
+ toJSON(): JSON.Object;
26
+ }
27
+ declare class BooleanValidator extends Schema {
28
+ #private;
29
+ static fromJSON(schema: JSON.JSON, path?: string): Result<BooleanValidator, SchemaError>;
30
+ constructor();
31
+ nullable(flag: boolean): this;
32
+ equals(value: boolean): this;
33
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
34
+ toJSON(): JSON.Object;
35
+ }
36
+ declare class NumberValidator extends Schema {
37
+ #private;
38
+ static fromJSON(schema: JSON.JSON, path?: string): Result<NumberValidator, SchemaError>;
39
+ constructor();
40
+ nullable(flag: boolean): this;
41
+ equals(value: number): this;
42
+ integer(flag?: boolean): this;
43
+ min(value: number): this;
44
+ max(value: number): this;
45
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
46
+ toJSON(): JSON.Object;
47
+ }
48
+ declare class StringValidator extends Schema {
49
+ #private;
50
+ static fromJSON(schema: JSON.JSON, path?: string): Result<StringValidator, SchemaError>;
51
+ constructor();
52
+ nullable(flag: boolean): this;
53
+ equals(value: string): this;
54
+ min(value: number): this;
55
+ max(value: number): this;
56
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
57
+ toJSON(): JSON.Object;
58
+ }
59
+ declare class ArrayValidator extends Schema {
60
+ #private;
61
+ static fromJSON(schema: JSON.JSON, path?: string, registry?: Map<string, typeof Schema>): Result<ArrayValidator, SchemaError>;
62
+ constructor();
63
+ nullable(flag?: boolean): this;
64
+ min(value: number): this;
65
+ max(value: number): this;
66
+ every(validator: Schema): this;
67
+ tuple(validators: Schema[]): this;
68
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
69
+ toJSON(): JSON.Object;
70
+ }
71
+ declare class ObjectValidator extends Schema {
72
+ #private;
73
+ static fromJSON(schema: JSON.JSON, path?: string, registry?: Map<string, typeof Schema>): Result<ObjectValidator, SchemaError>;
74
+ constructor();
75
+ nullable(flag?: boolean): this;
76
+ inclusive(flag?: boolean): this;
77
+ schema(value: {
78
+ [key: string]: Schema;
79
+ }, flag?: boolean): this;
80
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
81
+ toJSON(): JSON.Object;
82
+ }
83
+ declare class OrValidator extends Schema {
84
+ #private;
85
+ static fromJSON(schema: JSON.JSON, path?: string, registry?: Map<string, typeof Schema>): Result<OrValidator, SchemaError>;
86
+ constructor();
87
+ oneOf(validators: Schema[]): this;
88
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
89
+ toJSON(): JSON.Object;
90
+ }
91
+ declare class AndValidator extends Schema {
92
+ #private;
93
+ static fromJSON(schema: JSON.JSON, path?: string, registry?: Map<string, typeof Schema>): Result<AndValidator, SchemaError>;
94
+ constructor();
95
+ allOf(validators: Schema[]): this;
96
+ validate(data: unknown, path?: string): Result<void, ValidationError>;
97
+ toJSON(): JSON.Object;
98
+ }
99
+ export {};