@forklaunch/validator 0.2.6 → 0.2.8

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.
@@ -1,5 +1,13 @@
1
1
  import { SchemaValidator } from '../index';
2
2
  import { LiteralSchema } from '../types/schema.types';
3
+ declare module '../types/schema.types' {
4
+ interface SchemaResolve<T> {
5
+ Mock: T;
6
+ }
7
+ interface SchemaTranslate<T> {
8
+ Mock: T;
9
+ }
10
+ }
3
11
  export declare class MockSchemaValidator implements SchemaValidator {
4
12
  _Type: 'Mock';
5
13
  _SchemaCatchall: string;
@@ -18,7 +26,25 @@ export declare class MockSchemaValidator implements SchemaValidator {
18
26
  optional<T>(schema: T): string;
19
27
  array<T>(schema: T): string;
20
28
  union<T>(schemas: T[]): string;
21
- literal<T extends LiteralSchema>(schema: T): string;
29
+ literal<T extends LiteralSchema>(schema: T): `literal ${T}`;
22
30
  validate<T>(schema: T): boolean;
23
31
  openapi<T>(schema: T): {};
24
32
  }
33
+ export declare const mockSchemaValidator: MockSchemaValidator;
34
+ export declare const string: string;
35
+ export declare const number: string;
36
+ export declare const bigint: string;
37
+ export declare const boolean: string;
38
+ export declare const date: string;
39
+ export declare const symbol: string;
40
+ export declare const empty: string;
41
+ export declare const any: string;
42
+ export declare const unknown: string;
43
+ export declare const never: string;
44
+ export declare const schemify: <T>(schema: T) => T;
45
+ export declare const optional: <T>(schema: T) => string;
46
+ export declare const array: <T>(schema: T) => string;
47
+ export declare const union: <T>(schemas: T[]) => string;
48
+ export declare const literal: <T extends LiteralSchema>(schema: T) => `literal ${T}`;
49
+ export declare const validate: <T>(schema: T) => boolean;
50
+ export declare const openapi: <T>(schema: T) => {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MockSchemaValidator = void 0;
3
+ exports.openapi = exports.validate = exports.literal = exports.union = exports.array = exports.optional = exports.schemify = exports.never = exports.unknown = exports.any = exports.empty = exports.symbol = exports.date = exports.boolean = exports.bigint = exports.number = exports.string = exports.mockSchemaValidator = exports.MockSchemaValidator = void 0;
4
4
  class MockSchemaValidator {
5
5
  _Type;
6
6
  _SchemaCatchall;
@@ -28,7 +28,7 @@ class MockSchemaValidator {
28
28
  return schemas.join(' | ');
29
29
  }
30
30
  literal(schema) {
31
- return 'literal ' + schema;
31
+ return `literal ${schema}`;
32
32
  }
33
33
  validate(schema) {
34
34
  return true;
@@ -38,4 +38,22 @@ class MockSchemaValidator {
38
38
  }
39
39
  }
40
40
  exports.MockSchemaValidator = MockSchemaValidator;
41
+ exports.mockSchemaValidator = new MockSchemaValidator();
42
+ exports.string = exports.mockSchemaValidator.string;
43
+ exports.number = exports.mockSchemaValidator.number;
44
+ exports.bigint = exports.mockSchemaValidator.bigint;
45
+ exports.boolean = exports.mockSchemaValidator.boolean;
46
+ exports.date = exports.mockSchemaValidator.date;
47
+ exports.symbol = exports.mockSchemaValidator.symbol;
48
+ exports.empty = exports.mockSchemaValidator.empty;
49
+ exports.any = exports.mockSchemaValidator.any;
50
+ exports.unknown = exports.mockSchemaValidator.unknown;
51
+ exports.never = exports.mockSchemaValidator.never;
52
+ exports.schemify = exports.mockSchemaValidator.schemify.bind(exports.mockSchemaValidator);
53
+ exports.optional = exports.mockSchemaValidator.optional.bind(exports.mockSchemaValidator);
54
+ exports.array = exports.mockSchemaValidator.array.bind(exports.mockSchemaValidator);
55
+ exports.union = exports.mockSchemaValidator.union.bind(exports.mockSchemaValidator);
56
+ exports.literal = exports.mockSchemaValidator.literal.bind(exports.mockSchemaValidator);
57
+ exports.validate = exports.mockSchemaValidator.validate.bind(exports.mockSchemaValidator);
58
+ exports.openapi = exports.mockSchemaValidator.openapi.bind(exports.mockSchemaValidator);
41
59
  //# sourceMappingURL=mockSchemaValidator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockSchemaValidator.js","sourceRoot":"","sources":["../../tests/mockSchemaValidator.ts"],"names":[],"mappings":";;;AAGA,MAAa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AQ,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAClE,QAAA,QAAQ,GAAG,2BAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAClE,QAAA,KAAK,GAAG,2BAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAC5D,QAAA,KAAK,GAAG,2BAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAC5D,QAAA,OAAO,GAAG,2BAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAChE,QAAA,QAAQ,GAAG,2BAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAClE,QAAA,OAAO,GAAG,2BAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC"}
@@ -112,16 +112,20 @@ export interface SchemaValidator<SchematicFunction = <T>(schema: T) => unknown,
112
112
  openapi: OpenAPIFunction;
113
113
  }
114
114
  export type AnySchemaValidator = SchemaValidator<unknown, unknown, unknown, unknown, unknown, unknown, unknown>;
115
- interface SchemaResolve<T> {
115
+ export interface SchemaResolve<T> {
116
116
  Zod: ZodResolve<T>;
117
117
  TypeBox: TResolve<T>;
118
118
  }
119
- interface SchemaTranslate<T> {
119
+ export interface SchemaTranslate<T> {
120
120
  Zod: ZodSchemaTranslate<T>;
121
121
  TypeBox: TSchemaTranslate<T>;
122
122
  }
123
- type SchemaPrettify<T, SV extends AnySchemaValidator> = SV['_Type'] extends keyof SchemaTranslate<T> ? Prettify<SchemaTranslate<T>[SV['_Type']]> : never;
124
- export type Schema<T extends SV['_ValidSchemaObject'] | IdiomaticSchema<SV>, SV extends AnySchemaValidator> = SV['_Type'] extends keyof SchemaResolve<T> ? SchemaPrettify<SchemaResolve<T>[SV['_Type']], SV> : never;
123
+ type SchemaPrettify<T, SV extends {
124
+ _Type: keyof SchemaResolve<T>;
125
+ } & AnySchemaValidator> = Prettify<SchemaTranslate<T>[SV['_Type']]>;
126
+ export type Schema<T extends SV['_ValidSchemaObject'] | IdiomaticSchema<SV>, SV extends {
127
+ _Type: keyof SchemaResolve<T>;
128
+ } & AnySchemaValidator> = SchemaPrettify<SchemaResolve<T>[SV['_Type']], SV>;
125
129
  /**
126
130
  * Represents a schema for an unboxed object where each key can have an idiomatic schema.
127
131
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/validator",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Schema validator for ForkLaunch components.",
5
5
  "files": [
6
6
  "dist"
@@ -12,6 +12,7 @@
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
17
  "lint:fix": "eslint . -c eslint.config.mjs --fix",
17
18
  "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.ts' --write"