@forklaunch/validator 0.4.11 → 0.5.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.
@@ -1,5 +1,5 @@
1
1
  import { SchemaObject } from 'openapi3-ts/oas31';
2
- import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-BA3PeCI5.mjs';
2
+ import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-BL6n8u4w.mjs';
3
3
  import '@forklaunch/common';
4
4
  import '@sinclair/typebox';
5
5
  import '@sinclair/typebox/compiler';
@@ -13,11 +13,26 @@ declare module '@forklaunch/validator' {
13
13
  Mock: T;
14
14
  }
15
15
  }
16
+ /**
17
+ * Creates a union type string from an array of string literals.
18
+ *
19
+ * @template T - Array of string literals
20
+ * @example
21
+ * type Result = RecursiveUnion<['a', 'b', 'c']>; // 'a | b | c'
22
+ */
16
23
  type RecursiveUnion<T extends readonly string[]> = T extends readonly [
17
24
  infer F extends string,
18
25
  ...infer R extends readonly string[]
19
26
  ] ? R extends [] ? F : `${F} | ${RecursiveUnion<R>}` : '';
20
- declare class MockSchemaValidator implements SchemaValidator<(<T extends string>(schema: T) => T), <T extends string>(schema: T) => T, <T extends string>(schema: T) => `optional ${T}`, <T extends string>(schema: T) => `array ${T}`, <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>, <T extends LiteralSchema>(schema: T) => `literal ${T}`, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => `enum ${T}`, (value: unknown) => value is string, <T extends string>(schema: T, value: string) => boolean, <T extends string>(schema: T, value: string) => ParseResult<T>, <T extends string>(schema: T) => SchemaObject> {
27
+ type SerializeStringArray<T extends string[]> = T extends [
28
+ infer F extends string,
29
+ ...infer R extends string[]
30
+ ] ? R extends [] ? F : `${F}, ${SerializeStringArray<R>}` : '';
31
+ /**
32
+ * A mock implementation of SchemaValidator for testing purposes.
33
+ * This validator represents schemas as strings and provides simple string-based operations.
34
+ */
35
+ declare class MockSchemaValidator implements SchemaValidator<(<T extends string>(schema: T) => T), <T extends string>(schema: T) => T, <T extends string>(schema: T) => `optional ${T}`, <T extends string>(schema: T) => `array ${T}`, <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>, <T extends LiteralSchema>(schema: T) => `literal ${T}`, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => `enum ${T}`, <Args extends string[], ReturnType extends string>(args: Args, returnType: ReturnType) => `function(${SerializeStringArray<Args>}) => ${ReturnType}`, <Key extends string, Value extends string>(key: Key, value: Value) => `{${Key}: ${Value}}`, <T extends string>(schema: T) => `Promise<${T}>`, (value: unknown) => value is string, <T extends string>(schema: T, value: string) => boolean, <T extends string>(schema: T, value: string) => ParseResult<T>, <T extends string>(schema: T) => SchemaObject> {
21
36
  _Type: "Mock";
22
37
  _SchemaCatchall: string;
23
38
  _ValidSchemaObject: string;
@@ -34,16 +49,106 @@ declare class MockSchemaValidator implements SchemaValidator<(<T extends string>
34
49
  any: string;
35
50
  unknown: string;
36
51
  never: string;
52
+ /**
53
+ * Compiles a schema string.
54
+ *
55
+ * @param {T} schema - The schema string to compile
56
+ * @returns {T} The same schema string
57
+ */
37
58
  compile<T extends string>(schema: T): T;
59
+ /**
60
+ * Converts a schema string to its schemified form.
61
+ *
62
+ * @param {T} schema - The schema string to schemify
63
+ * @returns {T} The same schema string
64
+ */
38
65
  schemify<T extends string>(schema: T): T;
66
+ /**
67
+ * Makes a schema string optional.
68
+ *
69
+ * @param {T} schema - The schema string to make optional
70
+ * @returns {`optional ${T}`} The schema string prefixed with 'optional'
71
+ */
39
72
  optional<T extends string>(schema: T): `optional ${T}`;
73
+ /**
74
+ * Creates an array schema string.
75
+ *
76
+ * @param {T} schema - The schema string to convert to an array
77
+ * @returns {`array ${T}`} The schema string prefixed with 'array'
78
+ */
40
79
  array<T extends string>(schema: T): `array ${T}`;
80
+ /**
81
+ * Creates a union schema string from multiple schema strings.
82
+ *
83
+ * @param {T} schemas - Array of schema strings to union
84
+ * @returns {RecursiveUnion<T>} The schema strings joined with ' | '
85
+ */
41
86
  union<T extends readonly string[]>(schemas: T): RecursiveUnion<T>;
87
+ /**
88
+ * Creates a literal schema string.
89
+ *
90
+ * @param {T} schema - The literal value
91
+ * @returns {`literal ${T}`} The schema string prefixed with 'literal'
92
+ */
42
93
  literal<T extends LiteralSchema>(schema: T): `literal ${T}`;
94
+ /**
95
+ * Creates an enum schema string.
96
+ *
97
+ * @param {Record<string, T>} schemaEnum - The enum values
98
+ * @returns {`enum ${T}`} The schema string prefixed with 'enum'
99
+ */
43
100
  enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): `enum ${T}`;
101
+ /**
102
+ * Creates a function schema string.
103
+ *
104
+ * @param {Args} args - The arguments of the function
105
+ * @param {ReturnType} returnType - The return type of the function
106
+ * @returns {`function(${SerializeStringArray<Args>}) => ${ReturnType}`} The schema string prefixed with 'function'
107
+ */
108
+ function_<Args extends string[], ReturnType extends string>(args: Args, returnType: ReturnType): `function(${SerializeStringArray<Args>}) => ${ReturnType}`;
109
+ /**
110
+ * Creates a record schema string.
111
+ *
112
+ * @param {Key} key - The key schema string
113
+ * @param {Value} value - The value schema string
114
+ * @returns {`{${Key}: ${Value}}`} The schema string prefixed with 'record'
115
+ */
116
+ record<Key extends string, Value extends string>(key: Key, value: Value): `{${Key}: ${Value}}`;
117
+ /**
118
+ * Creates a promise schema string.
119
+ *
120
+ * @param {T} schema - The schema string to convert to a promise
121
+ * @returns {`Promise<${T}>`} The schema string prefixed with 'Promise'
122
+ */
123
+ promise<T extends string>(schema: T): `Promise<${T}>`;
124
+ /**
125
+ * Checks if a value is a schema string.
126
+ *
127
+ * @param {unknown} value - The value to check
128
+ * @returns {boolean} True if the value is a string
129
+ */
44
130
  isSchema(value: unknown): value is string;
131
+ /**
132
+ * Validates a value against a schema string.
133
+ *
134
+ * @param {T} schema - The schema string to validate against
135
+ * @param {string} value - The value to validate
136
+ * @returns {boolean} True if the schema and value strings match
137
+ */
45
138
  validate<T extends string>(schema: T, value: string): boolean;
139
+ /**
140
+ * Parses a value against a schema string.
141
+ *
142
+ * @param {T} schema - The schema string to parse against
143
+ * @param {string} value - The value to parse
144
+ * @returns {ParseResult<T>} Success if the schema and value strings match, error otherwise
145
+ */
46
146
  parse<T extends string>(schema: T, value: string): ParseResult<T>;
147
+ /**
148
+ * Generates a mock OpenAPI schema object.
149
+ *
150
+ * @returns {SchemaObject} A simple string type schema object
151
+ */
47
152
  openapi(): SchemaObject;
48
153
  }
49
154
  declare const mockSchemaValidator: MockSchemaValidator;
@@ -63,7 +168,10 @@ declare const array: <T extends string>(schema: T) => `array ${T}`;
63
168
  declare const union: <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>;
64
169
  declare const literal: <T extends LiteralSchema>(schema: T) => `literal ${T}`;
65
170
  declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => `enum ${T}`;
171
+ declare const function_: <Args extends string[], ReturnType extends string>(args: Args, returnType: ReturnType) => `function(${SerializeStringArray<Args>}) => ${ReturnType}`;
172
+ declare const record: <Key extends string, Value extends string>(key: Key, value: Value) => `{${Key}: ${Value}}`;
173
+ declare const promise: <T extends string>(schema: T) => `Promise<${T}>`;
66
174
  declare const validate: <T extends string>(schema: T, value: string) => boolean;
67
175
  declare const openapi: () => SchemaObject;
68
176
 
69
- export { MockSchemaValidator, any, array, bigint, boolean, date, enum_, literal, mockSchemaValidator, never, nullish, number, openapi, optional, schemify, string, symbol, union, unknown, validate };
177
+ export { MockSchemaValidator, any, array, bigint, boolean, date, enum_, function_, literal, mockSchemaValidator, never, nullish, number, openapi, optional, promise, record, schemify, string, symbol, union, unknown, validate };
@@ -1,5 +1,5 @@
1
1
  import { SchemaObject } from 'openapi3-ts/oas31';
2
- import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-BA3PeCI5.js';
2
+ import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-BL6n8u4w.js';
3
3
  import '@forklaunch/common';
4
4
  import '@sinclair/typebox';
5
5
  import '@sinclair/typebox/compiler';
@@ -13,11 +13,26 @@ declare module '@forklaunch/validator' {
13
13
  Mock: T;
14
14
  }
15
15
  }
16
+ /**
17
+ * Creates a union type string from an array of string literals.
18
+ *
19
+ * @template T - Array of string literals
20
+ * @example
21
+ * type Result = RecursiveUnion<['a', 'b', 'c']>; // 'a | b | c'
22
+ */
16
23
  type RecursiveUnion<T extends readonly string[]> = T extends readonly [
17
24
  infer F extends string,
18
25
  ...infer R extends readonly string[]
19
26
  ] ? R extends [] ? F : `${F} | ${RecursiveUnion<R>}` : '';
20
- declare class MockSchemaValidator implements SchemaValidator<(<T extends string>(schema: T) => T), <T extends string>(schema: T) => T, <T extends string>(schema: T) => `optional ${T}`, <T extends string>(schema: T) => `array ${T}`, <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>, <T extends LiteralSchema>(schema: T) => `literal ${T}`, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => `enum ${T}`, (value: unknown) => value is string, <T extends string>(schema: T, value: string) => boolean, <T extends string>(schema: T, value: string) => ParseResult<T>, <T extends string>(schema: T) => SchemaObject> {
27
+ type SerializeStringArray<T extends string[]> = T extends [
28
+ infer F extends string,
29
+ ...infer R extends string[]
30
+ ] ? R extends [] ? F : `${F}, ${SerializeStringArray<R>}` : '';
31
+ /**
32
+ * A mock implementation of SchemaValidator for testing purposes.
33
+ * This validator represents schemas as strings and provides simple string-based operations.
34
+ */
35
+ declare class MockSchemaValidator implements SchemaValidator<(<T extends string>(schema: T) => T), <T extends string>(schema: T) => T, <T extends string>(schema: T) => `optional ${T}`, <T extends string>(schema: T) => `array ${T}`, <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>, <T extends LiteralSchema>(schema: T) => `literal ${T}`, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => `enum ${T}`, <Args extends string[], ReturnType extends string>(args: Args, returnType: ReturnType) => `function(${SerializeStringArray<Args>}) => ${ReturnType}`, <Key extends string, Value extends string>(key: Key, value: Value) => `{${Key}: ${Value}}`, <T extends string>(schema: T) => `Promise<${T}>`, (value: unknown) => value is string, <T extends string>(schema: T, value: string) => boolean, <T extends string>(schema: T, value: string) => ParseResult<T>, <T extends string>(schema: T) => SchemaObject> {
21
36
  _Type: "Mock";
22
37
  _SchemaCatchall: string;
23
38
  _ValidSchemaObject: string;
@@ -34,16 +49,106 @@ declare class MockSchemaValidator implements SchemaValidator<(<T extends string>
34
49
  any: string;
35
50
  unknown: string;
36
51
  never: string;
52
+ /**
53
+ * Compiles a schema string.
54
+ *
55
+ * @param {T} schema - The schema string to compile
56
+ * @returns {T} The same schema string
57
+ */
37
58
  compile<T extends string>(schema: T): T;
59
+ /**
60
+ * Converts a schema string to its schemified form.
61
+ *
62
+ * @param {T} schema - The schema string to schemify
63
+ * @returns {T} The same schema string
64
+ */
38
65
  schemify<T extends string>(schema: T): T;
66
+ /**
67
+ * Makes a schema string optional.
68
+ *
69
+ * @param {T} schema - The schema string to make optional
70
+ * @returns {`optional ${T}`} The schema string prefixed with 'optional'
71
+ */
39
72
  optional<T extends string>(schema: T): `optional ${T}`;
73
+ /**
74
+ * Creates an array schema string.
75
+ *
76
+ * @param {T} schema - The schema string to convert to an array
77
+ * @returns {`array ${T}`} The schema string prefixed with 'array'
78
+ */
40
79
  array<T extends string>(schema: T): `array ${T}`;
80
+ /**
81
+ * Creates a union schema string from multiple schema strings.
82
+ *
83
+ * @param {T} schemas - Array of schema strings to union
84
+ * @returns {RecursiveUnion<T>} The schema strings joined with ' | '
85
+ */
41
86
  union<T extends readonly string[]>(schemas: T): RecursiveUnion<T>;
87
+ /**
88
+ * Creates a literal schema string.
89
+ *
90
+ * @param {T} schema - The literal value
91
+ * @returns {`literal ${T}`} The schema string prefixed with 'literal'
92
+ */
42
93
  literal<T extends LiteralSchema>(schema: T): `literal ${T}`;
94
+ /**
95
+ * Creates an enum schema string.
96
+ *
97
+ * @param {Record<string, T>} schemaEnum - The enum values
98
+ * @returns {`enum ${T}`} The schema string prefixed with 'enum'
99
+ */
43
100
  enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): `enum ${T}`;
101
+ /**
102
+ * Creates a function schema string.
103
+ *
104
+ * @param {Args} args - The arguments of the function
105
+ * @param {ReturnType} returnType - The return type of the function
106
+ * @returns {`function(${SerializeStringArray<Args>}) => ${ReturnType}`} The schema string prefixed with 'function'
107
+ */
108
+ function_<Args extends string[], ReturnType extends string>(args: Args, returnType: ReturnType): `function(${SerializeStringArray<Args>}) => ${ReturnType}`;
109
+ /**
110
+ * Creates a record schema string.
111
+ *
112
+ * @param {Key} key - The key schema string
113
+ * @param {Value} value - The value schema string
114
+ * @returns {`{${Key}: ${Value}}`} The schema string prefixed with 'record'
115
+ */
116
+ record<Key extends string, Value extends string>(key: Key, value: Value): `{${Key}: ${Value}}`;
117
+ /**
118
+ * Creates a promise schema string.
119
+ *
120
+ * @param {T} schema - The schema string to convert to a promise
121
+ * @returns {`Promise<${T}>`} The schema string prefixed with 'Promise'
122
+ */
123
+ promise<T extends string>(schema: T): `Promise<${T}>`;
124
+ /**
125
+ * Checks if a value is a schema string.
126
+ *
127
+ * @param {unknown} value - The value to check
128
+ * @returns {boolean} True if the value is a string
129
+ */
44
130
  isSchema(value: unknown): value is string;
131
+ /**
132
+ * Validates a value against a schema string.
133
+ *
134
+ * @param {T} schema - The schema string to validate against
135
+ * @param {string} value - The value to validate
136
+ * @returns {boolean} True if the schema and value strings match
137
+ */
45
138
  validate<T extends string>(schema: T, value: string): boolean;
139
+ /**
140
+ * Parses a value against a schema string.
141
+ *
142
+ * @param {T} schema - The schema string to parse against
143
+ * @param {string} value - The value to parse
144
+ * @returns {ParseResult<T>} Success if the schema and value strings match, error otherwise
145
+ */
46
146
  parse<T extends string>(schema: T, value: string): ParseResult<T>;
147
+ /**
148
+ * Generates a mock OpenAPI schema object.
149
+ *
150
+ * @returns {SchemaObject} A simple string type schema object
151
+ */
47
152
  openapi(): SchemaObject;
48
153
  }
49
154
  declare const mockSchemaValidator: MockSchemaValidator;
@@ -63,7 +168,10 @@ declare const array: <T extends string>(schema: T) => `array ${T}`;
63
168
  declare const union: <T extends readonly string[]>(schemas: T) => RecursiveUnion<T>;
64
169
  declare const literal: <T extends LiteralSchema>(schema: T) => `literal ${T}`;
65
170
  declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => `enum ${T}`;
171
+ declare const function_: <Args extends string[], ReturnType extends string>(args: Args, returnType: ReturnType) => `function(${SerializeStringArray<Args>}) => ${ReturnType}`;
172
+ declare const record: <Key extends string, Value extends string>(key: Key, value: Value) => `{${Key}: ${Value}}`;
173
+ declare const promise: <T extends string>(schema: T) => `Promise<${T}>`;
66
174
  declare const validate: <T extends string>(schema: T, value: string) => boolean;
67
175
  declare const openapi: () => SchemaObject;
68
176
 
69
- export { MockSchemaValidator, any, array, bigint, boolean, date, enum_, literal, mockSchemaValidator, never, nullish, number, openapi, optional, schemify, string, symbol, union, unknown, validate };
177
+ export { MockSchemaValidator, any, array, bigint, boolean, date, enum_, function_, literal, mockSchemaValidator, never, nullish, number, openapi, optional, promise, record, schemify, string, symbol, union, unknown, validate };
@@ -27,6 +27,7 @@ __export(mockSchemaValidator_exports, {
27
27
  boolean: () => boolean,
28
28
  date: () => date,
29
29
  enum_: () => enum_,
30
+ function_: () => function_,
30
31
  literal: () => literal,
31
32
  mockSchemaValidator: () => mockSchemaValidator,
32
33
  never: () => never,
@@ -34,6 +35,8 @@ __export(mockSchemaValidator_exports, {
34
35
  number: () => number,
35
36
  openapi: () => openapi,
36
37
  optional: () => optional,
38
+ promise: () => promise,
39
+ record: () => record,
37
40
  schemify: () => schemify,
38
41
  string: () => string,
39
42
  symbol: () => symbol,
@@ -59,33 +62,124 @@ var MockSchemaValidator = class {
59
62
  any = "any";
60
63
  unknown = "unknown";
61
64
  never = "never";
65
+ /**
66
+ * Compiles a schema string.
67
+ *
68
+ * @param {T} schema - The schema string to compile
69
+ * @returns {T} The same schema string
70
+ */
62
71
  compile(schema) {
63
72
  return schema;
64
73
  }
74
+ /**
75
+ * Converts a schema string to its schemified form.
76
+ *
77
+ * @param {T} schema - The schema string to schemify
78
+ * @returns {T} The same schema string
79
+ */
65
80
  schemify(schema) {
66
81
  return schema;
67
82
  }
83
+ /**
84
+ * Makes a schema string optional.
85
+ *
86
+ * @param {T} schema - The schema string to make optional
87
+ * @returns {`optional ${T}`} The schema string prefixed with 'optional'
88
+ */
68
89
  optional(schema) {
69
90
  return `optional ${schema}`;
70
91
  }
92
+ /**
93
+ * Creates an array schema string.
94
+ *
95
+ * @param {T} schema - The schema string to convert to an array
96
+ * @returns {`array ${T}`} The schema string prefixed with 'array'
97
+ */
71
98
  array(schema) {
72
99
  return `array ${schema}`;
73
100
  }
101
+ /**
102
+ * Creates a union schema string from multiple schema strings.
103
+ *
104
+ * @param {T} schemas - Array of schema strings to union
105
+ * @returns {RecursiveUnion<T>} The schema strings joined with ' | '
106
+ */
74
107
  union(schemas) {
75
108
  return schemas.join(" | ");
76
109
  }
110
+ /**
111
+ * Creates a literal schema string.
112
+ *
113
+ * @param {T} schema - The literal value
114
+ * @returns {`literal ${T}`} The schema string prefixed with 'literal'
115
+ */
77
116
  literal(schema) {
78
117
  return `literal ${schema}`;
79
118
  }
119
+ /**
120
+ * Creates an enum schema string.
121
+ *
122
+ * @param {Record<string, T>} schemaEnum - The enum values
123
+ * @returns {`enum ${T}`} The schema string prefixed with 'enum'
124
+ */
80
125
  enum_(schemaEnum) {
81
126
  return `enum ${Object.values(schemaEnum).join(" | ")}`;
82
127
  }
128
+ /**
129
+ * Creates a function schema string.
130
+ *
131
+ * @param {Args} args - The arguments of the function
132
+ * @param {ReturnType} returnType - The return type of the function
133
+ * @returns {`function(${SerializeStringArray<Args>}) => ${ReturnType}`} The schema string prefixed with 'function'
134
+ */
135
+ function_(args, returnType) {
136
+ return `function(${args.join(", ")}) => ${returnType}`;
137
+ }
138
+ /**
139
+ * Creates a record schema string.
140
+ *
141
+ * @param {Key} key - The key schema string
142
+ * @param {Value} value - The value schema string
143
+ * @returns {`{${Key}: ${Value}}`} The schema string prefixed with 'record'
144
+ */
145
+ record(key, value) {
146
+ return `{${key}: ${value}}`;
147
+ }
148
+ /**
149
+ * Creates a promise schema string.
150
+ *
151
+ * @param {T} schema - The schema string to convert to a promise
152
+ * @returns {`Promise<${T}>`} The schema string prefixed with 'Promise'
153
+ */
154
+ promise(schema) {
155
+ return `Promise<${schema}>`;
156
+ }
157
+ /**
158
+ * Checks if a value is a schema string.
159
+ *
160
+ * @param {unknown} value - The value to check
161
+ * @returns {boolean} True if the value is a string
162
+ */
83
163
  isSchema(value) {
84
164
  return typeof value === "string";
85
165
  }
166
+ /**
167
+ * Validates a value against a schema string.
168
+ *
169
+ * @param {T} schema - The schema string to validate against
170
+ * @param {string} value - The value to validate
171
+ * @returns {boolean} True if the schema and value strings match
172
+ */
86
173
  validate(schema, value) {
87
174
  return schema === value;
88
175
  }
176
+ /**
177
+ * Parses a value against a schema string.
178
+ *
179
+ * @param {T} schema - The schema string to parse against
180
+ * @param {string} value - The value to parse
181
+ * @returns {ParseResult<T>} Success if the schema and value strings match, error otherwise
182
+ */
89
183
  parse(schema, value) {
90
184
  return JSON.stringify(schema) === JSON.stringify(value) ? {
91
185
  ok: true,
@@ -95,6 +189,11 @@ var MockSchemaValidator = class {
95
189
  errors: [{ path: [], message: "Some error" }]
96
190
  };
97
191
  }
192
+ /**
193
+ * Generates a mock OpenAPI schema object.
194
+ *
195
+ * @returns {SchemaObject} A simple string type schema object
196
+ */
98
197
  openapi() {
99
198
  return {
100
199
  type: "string"
@@ -118,6 +217,9 @@ var array = mockSchemaValidator.array.bind(mockSchemaValidator);
118
217
  var union = mockSchemaValidator.union.bind(mockSchemaValidator);
119
218
  var literal = mockSchemaValidator.literal.bind(mockSchemaValidator);
120
219
  var enum_ = mockSchemaValidator.enum_.bind(mockSchemaValidator);
220
+ var function_ = mockSchemaValidator.function_.bind(mockSchemaValidator);
221
+ var record = mockSchemaValidator.record.bind(mockSchemaValidator);
222
+ var promise = mockSchemaValidator.promise.bind(mockSchemaValidator);
121
223
  var validate = mockSchemaValidator.validate.bind(mockSchemaValidator);
122
224
  var openapi = mockSchemaValidator.openapi.bind(mockSchemaValidator);
123
225
  // Annotate the CommonJS export names for ESM import in node:
@@ -129,6 +231,7 @@ var openapi = mockSchemaValidator.openapi.bind(mockSchemaValidator);
129
231
  boolean,
130
232
  date,
131
233
  enum_,
234
+ function_,
132
235
  literal,
133
236
  mockSchemaValidator,
134
237
  never,
@@ -136,6 +239,8 @@ var openapi = mockSchemaValidator.openapi.bind(mockSchemaValidator);
136
239
  number,
137
240
  openapi,
138
241
  optional,
242
+ promise,
243
+ record,
139
244
  schemify,
140
245
  string,
141
246
  symbol,
@@ -16,33 +16,124 @@ var MockSchemaValidator = class {
16
16
  any = "any";
17
17
  unknown = "unknown";
18
18
  never = "never";
19
+ /**
20
+ * Compiles a schema string.
21
+ *
22
+ * @param {T} schema - The schema string to compile
23
+ * @returns {T} The same schema string
24
+ */
19
25
  compile(schema) {
20
26
  return schema;
21
27
  }
28
+ /**
29
+ * Converts a schema string to its schemified form.
30
+ *
31
+ * @param {T} schema - The schema string to schemify
32
+ * @returns {T} The same schema string
33
+ */
22
34
  schemify(schema) {
23
35
  return schema;
24
36
  }
37
+ /**
38
+ * Makes a schema string optional.
39
+ *
40
+ * @param {T} schema - The schema string to make optional
41
+ * @returns {`optional ${T}`} The schema string prefixed with 'optional'
42
+ */
25
43
  optional(schema) {
26
44
  return `optional ${schema}`;
27
45
  }
46
+ /**
47
+ * Creates an array schema string.
48
+ *
49
+ * @param {T} schema - The schema string to convert to an array
50
+ * @returns {`array ${T}`} The schema string prefixed with 'array'
51
+ */
28
52
  array(schema) {
29
53
  return `array ${schema}`;
30
54
  }
55
+ /**
56
+ * Creates a union schema string from multiple schema strings.
57
+ *
58
+ * @param {T} schemas - Array of schema strings to union
59
+ * @returns {RecursiveUnion<T>} The schema strings joined with ' | '
60
+ */
31
61
  union(schemas) {
32
62
  return schemas.join(" | ");
33
63
  }
64
+ /**
65
+ * Creates a literal schema string.
66
+ *
67
+ * @param {T} schema - The literal value
68
+ * @returns {`literal ${T}`} The schema string prefixed with 'literal'
69
+ */
34
70
  literal(schema) {
35
71
  return `literal ${schema}`;
36
72
  }
73
+ /**
74
+ * Creates an enum schema string.
75
+ *
76
+ * @param {Record<string, T>} schemaEnum - The enum values
77
+ * @returns {`enum ${T}`} The schema string prefixed with 'enum'
78
+ */
37
79
  enum_(schemaEnum) {
38
80
  return `enum ${Object.values(schemaEnum).join(" | ")}`;
39
81
  }
82
+ /**
83
+ * Creates a function schema string.
84
+ *
85
+ * @param {Args} args - The arguments of the function
86
+ * @param {ReturnType} returnType - The return type of the function
87
+ * @returns {`function(${SerializeStringArray<Args>}) => ${ReturnType}`} The schema string prefixed with 'function'
88
+ */
89
+ function_(args, returnType) {
90
+ return `function(${args.join(", ")}) => ${returnType}`;
91
+ }
92
+ /**
93
+ * Creates a record schema string.
94
+ *
95
+ * @param {Key} key - The key schema string
96
+ * @param {Value} value - The value schema string
97
+ * @returns {`{${Key}: ${Value}}`} The schema string prefixed with 'record'
98
+ */
99
+ record(key, value) {
100
+ return `{${key}: ${value}}`;
101
+ }
102
+ /**
103
+ * Creates a promise schema string.
104
+ *
105
+ * @param {T} schema - The schema string to convert to a promise
106
+ * @returns {`Promise<${T}>`} The schema string prefixed with 'Promise'
107
+ */
108
+ promise(schema) {
109
+ return `Promise<${schema}>`;
110
+ }
111
+ /**
112
+ * Checks if a value is a schema string.
113
+ *
114
+ * @param {unknown} value - The value to check
115
+ * @returns {boolean} True if the value is a string
116
+ */
40
117
  isSchema(value) {
41
118
  return typeof value === "string";
42
119
  }
120
+ /**
121
+ * Validates a value against a schema string.
122
+ *
123
+ * @param {T} schema - The schema string to validate against
124
+ * @param {string} value - The value to validate
125
+ * @returns {boolean} True if the schema and value strings match
126
+ */
43
127
  validate(schema, value) {
44
128
  return schema === value;
45
129
  }
130
+ /**
131
+ * Parses a value against a schema string.
132
+ *
133
+ * @param {T} schema - The schema string to parse against
134
+ * @param {string} value - The value to parse
135
+ * @returns {ParseResult<T>} Success if the schema and value strings match, error otherwise
136
+ */
46
137
  parse(schema, value) {
47
138
  return JSON.stringify(schema) === JSON.stringify(value) ? {
48
139
  ok: true,
@@ -52,6 +143,11 @@ var MockSchemaValidator = class {
52
143
  errors: [{ path: [], message: "Some error" }]
53
144
  };
54
145
  }
146
+ /**
147
+ * Generates a mock OpenAPI schema object.
148
+ *
149
+ * @returns {SchemaObject} A simple string type schema object
150
+ */
55
151
  openapi() {
56
152
  return {
57
153
  type: "string"
@@ -75,6 +171,9 @@ var array = mockSchemaValidator.array.bind(mockSchemaValidator);
75
171
  var union = mockSchemaValidator.union.bind(mockSchemaValidator);
76
172
  var literal = mockSchemaValidator.literal.bind(mockSchemaValidator);
77
173
  var enum_ = mockSchemaValidator.enum_.bind(mockSchemaValidator);
174
+ var function_ = mockSchemaValidator.function_.bind(mockSchemaValidator);
175
+ var record = mockSchemaValidator.record.bind(mockSchemaValidator);
176
+ var promise = mockSchemaValidator.promise.bind(mockSchemaValidator);
78
177
  var validate = mockSchemaValidator.validate.bind(mockSchemaValidator);
79
178
  var openapi = mockSchemaValidator.openapi.bind(mockSchemaValidator);
80
179
  export {
@@ -85,6 +184,7 @@ export {
85
184
  boolean,
86
185
  date,
87
186
  enum_,
187
+ function_,
88
188
  literal,
89
189
  mockSchemaValidator,
90
190
  never,
@@ -92,6 +192,8 @@ export {
92
192
  number,
93
193
  openapi,
94
194
  optional,
195
+ promise,
196
+ record,
95
197
  schemify,
96
198
  string,
97
199
  symbol,
package/lib/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as ParseError } from './schema.types-BA3PeCI5.mjs';
2
- export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-BA3PeCI5.mjs';
1
+ import { P as ParseError } from './schema.types-BL6n8u4w.mjs';
2
+ export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-BL6n8u4w.mjs';
3
3
  import '@forklaunch/common';
4
4
  import 'openapi3-ts/oas31';
5
5
  import '@sinclair/typebox';
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as ParseError } from './schema.types-BA3PeCI5.js';
2
- export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-BA3PeCI5.js';
1
+ import { P as ParseError } from './schema.types-BL6n8u4w.js';
2
+ export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-BL6n8u4w.js';
3
3
  import '@forklaunch/common';
4
4
  import 'openapi3-ts/oas31';
5
5
  import '@sinclair/typebox';