unischema 1.1.0 → 1.2.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/README.md +151 -2
- package/dist/adapters/backend/index.d.mts +2 -2
- package/dist/adapters/backend/index.d.ts +2 -2
- package/dist/adapters/backend/index.js +11 -11
- package/dist/adapters/backend/index.mjs +8 -8
- package/dist/adapters/frontend/index.d.mts +2 -2
- package/dist/adapters/frontend/index.d.ts +2 -2
- package/dist/adapters/frontend/index.js +10 -10
- package/dist/adapters/frontend/index.mjs +8 -8
- package/dist/{chunk-XGTUU27F.mjs → chunk-5A4ITJVD.mjs} +1 -1
- package/dist/{chunk-ASKTY6EG.js → chunk-66RFUBVU.js} +20 -20
- package/dist/{chunk-KHHJD6QK.mjs → chunk-75YSYC4K.mjs} +1 -1
- package/dist/{chunk-BNIB23NQ.js → chunk-76BBWQDH.js} +13 -13
- package/dist/{chunk-ELL7U7IC.mjs → chunk-7XES4A3M.mjs} +1 -1
- package/dist/{chunk-FRBZHN4K.mjs → chunk-COMVAVFU.mjs} +1 -1
- package/dist/chunk-DT2TQZU7.js +796 -0
- package/dist/{chunk-2JYFKT3R.js → chunk-FPCCH55A.js} +14 -14
- package/dist/{chunk-3FANCMEF.js → chunk-IUXRLMET.js} +34 -34
- package/dist/{chunk-CQYXR2LZ.js → chunk-JEW6U6CB.js} +65 -65
- package/dist/{chunk-XC4DKEXP.mjs → chunk-KZCV5IW4.mjs} +1 -1
- package/dist/{chunk-FKDWSZIV.mjs → chunk-KZZ7NVU3.mjs} +4 -2
- package/dist/{chunk-3TS35CVJ.mjs → chunk-MFEBMQAU.mjs} +341 -40
- package/dist/{chunk-NUW55QTO.js → chunk-OIYG5D2I.js} +4 -2
- package/dist/{chunk-VWP24NYS.mjs → chunk-RW6HDA5H.mjs} +1 -1
- package/dist/{chunk-FZ7K2PC7.js → chunk-TXT36BCE.js} +35 -35
- package/dist/index-C17xs-fU.d.mts +140 -0
- package/dist/index-C17xs-fU.d.ts +140 -0
- package/dist/index.d.mts +26 -8
- package/dist/index.d.ts +26 -8
- package/dist/index.js +262 -25
- package/dist/index.mjs +228 -14
- package/dist/{schema-DYU1zGVm.d.mts → schema-DYE8Wz8X.d.mts} +84 -2
- package/dist/{schema-CpAjXgEF.d.ts → schema-Dtp-joeT.d.ts} +84 -2
- package/dist/validators/array.d.mts +1 -1
- package/dist/validators/array.d.ts +1 -1
- package/dist/validators/array.js +8 -8
- package/dist/validators/array.mjs +2 -2
- package/dist/validators/common.d.mts +1 -1
- package/dist/validators/common.d.ts +1 -1
- package/dist/validators/common.js +7 -7
- package/dist/validators/common.mjs +2 -2
- package/dist/validators/date.d.mts +1 -1
- package/dist/validators/date.d.ts +1 -1
- package/dist/validators/date.js +12 -12
- package/dist/validators/date.mjs +2 -2
- package/dist/validators/index.d.mts +2 -2
- package/dist/validators/index.d.ts +2 -2
- package/dist/validators/index.js +68 -68
- package/dist/validators/index.mjs +7 -7
- package/dist/validators/number.d.mts +1 -1
- package/dist/validators/number.d.ts +1 -1
- package/dist/validators/number.js +13 -13
- package/dist/validators/number.mjs +2 -2
- package/dist/validators/object.d.mts +1 -1
- package/dist/validators/object.d.ts +1 -1
- package/dist/validators/object.js +6 -6
- package/dist/validators/object.mjs +2 -2
- package/dist/validators/string.d.mts +1 -1
- package/dist/validators/string.d.ts +1 -1
- package/dist/validators/string.js +19 -19
- package/dist/validators/string.mjs +2 -2
- package/package.json +47 -5
- package/dist/chunk-BJLVOIAP.js +0 -491
- package/dist/index-BQR7OrY7.d.mts +0 -80
- package/dist/index-BQR7OrY7.d.ts +0 -80
package/README.md
CHANGED
|
@@ -98,15 +98,144 @@ const emailProps = form.getFieldProps('email');
|
|
|
98
98
|
|
|
99
99
|
## 🎯 Features
|
|
100
100
|
|
|
101
|
-
- ✅ **
|
|
101
|
+
- ✅ **53+ Built-in Validators** - Email, URL, IPv4/IPv6, phone, coordinates, and more
|
|
102
|
+
- ✅ **Async Validation** - Database checks, API validation with debouncing
|
|
103
|
+
- ✅ **Data Transformation** - Transform & coerce values before validation
|
|
104
|
+
- ✅ **Advanced Schema Composition** - deepPartial, passthrough, strict, catchall
|
|
102
105
|
- ✅ **Isomorphic** - Same code runs in browser and Node.js
|
|
103
106
|
- ✅ **TypeScript First** - Automatic type inference
|
|
104
107
|
- ✅ **Hard & Soft Validation** - Errors vs warnings for enterprise apps
|
|
108
|
+
- ✅ **Nullable/Nullish Support** - Proper null/undefined handling
|
|
105
109
|
- ✅ **Tree-Shakeable** - Only bundle what you use (~2KB min+gzip)
|
|
106
110
|
- ✅ **Framework Agnostic** - Works with React, Vue, Svelte, Angular, etc.
|
|
107
111
|
- ✅ **Zero Dependencies** - Lightweight and fast
|
|
108
112
|
|
|
109
|
-
##
|
|
113
|
+
## 🆕 What's New in v1.2.0 - Production Ready!
|
|
114
|
+
|
|
115
|
+
Phase 1 is complete! Unischema now includes powerful features for production applications:
|
|
116
|
+
|
|
117
|
+
### Async Validation
|
|
118
|
+
|
|
119
|
+
Validate against external APIs, databases, or async operations with built-in debouncing:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const UserSchema = schema({
|
|
123
|
+
email: field.string()
|
|
124
|
+
.email()
|
|
125
|
+
.refineAsync(async (email) => {
|
|
126
|
+
const exists = await checkEmailExists(email);
|
|
127
|
+
return !exists || { message: 'Email already registered' };
|
|
128
|
+
}, { debounce: 500, timeout: 5000 }),
|
|
129
|
+
|
|
130
|
+
username: field.string()
|
|
131
|
+
.refineAsync(async (name) => {
|
|
132
|
+
const available = await api.checkUsername(name);
|
|
133
|
+
return available;
|
|
134
|
+
}, { debounce: 300, message: 'Username taken' })
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Use async validation
|
|
138
|
+
const result = await validateAsync(UserSchema.definition, data);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Data Transformation & Coercion
|
|
142
|
+
|
|
143
|
+
Transform and coerce values before validation:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// Transform strings
|
|
147
|
+
const LoginSchema = schema({
|
|
148
|
+
email: field.string()
|
|
149
|
+
.transform(s => s.trim())
|
|
150
|
+
.transform(s => s.toLowerCase())
|
|
151
|
+
.email(),
|
|
152
|
+
|
|
153
|
+
name: field.string()
|
|
154
|
+
.transform(s => s.trim())
|
|
155
|
+
.transform(s => s.replace(/\s+/g, ' ')) // Normalize whitespace
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Type coercion from form inputs
|
|
159
|
+
const FormSchema = schema({
|
|
160
|
+
age: coerce.number().min(18), // "25" → 25
|
|
161
|
+
active: coerce.boolean(), // "true" → true
|
|
162
|
+
startDate: coerce.date(), // "2024-01-01" → Date
|
|
163
|
+
tags: coerce.array(field.string()), // "javascript" → ["javascript"]
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Preprocessing for nullable values
|
|
167
|
+
const ProfileSchema = schema({
|
|
168
|
+
bio: field.string()
|
|
169
|
+
.preprocess(s => s?.trim()) // Handle null/undefined safely
|
|
170
|
+
.nullable()
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Advanced Schema Composition
|
|
175
|
+
|
|
176
|
+
More flexible schema manipulation:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const BaseSchema = schema({
|
|
180
|
+
id: field.string(),
|
|
181
|
+
name: field.string().required(),
|
|
182
|
+
email: field.string().email().required(),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Deep partial - make all fields optional recursively
|
|
186
|
+
const PartialSchema = deepPartial(BaseSchema);
|
|
187
|
+
|
|
188
|
+
// Passthrough - allow unknown keys
|
|
189
|
+
const FlexibleSchema = passthrough(BaseSchema);
|
|
190
|
+
|
|
191
|
+
// Strict mode - reject unknown keys
|
|
192
|
+
const StrictSchema = strict(BaseSchema);
|
|
193
|
+
|
|
194
|
+
// Catchall - handle unknown keys with validation
|
|
195
|
+
const CatchAllSchema = catchall(BaseSchema, field.string());
|
|
196
|
+
|
|
197
|
+
// Make specific fields required/optional
|
|
198
|
+
const RequiredFields = required(BaseSchema, ['name', 'email']);
|
|
199
|
+
const OptionalFields = optional(BaseSchema, ['email']);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Nullable & Nullish Handling
|
|
203
|
+
|
|
204
|
+
Better null/undefined value handling:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const UserSchema = schema({
|
|
208
|
+
// Allow null
|
|
209
|
+
middleName: field.string().nullable(), // string | null
|
|
210
|
+
|
|
211
|
+
// Allow null or undefined
|
|
212
|
+
bio: field.string().nullish(), // string | null | undefined
|
|
213
|
+
|
|
214
|
+
// Required but nullable
|
|
215
|
+
avatar: field.string().nullable().required(),
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Enhanced Error Context
|
|
220
|
+
|
|
221
|
+
Get detailed error information:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const result = validate(schema({ age: field.number().min(18) }), { age: 15 });
|
|
225
|
+
|
|
226
|
+
result.hardErrors[0];
|
|
227
|
+
// {
|
|
228
|
+
// field: "age",
|
|
229
|
+
// code: "MIN_VALUE",
|
|
230
|
+
// message: "Value must be at least 18",
|
|
231
|
+
// severity: "hard",
|
|
232
|
+
// received: 15, // ✨ The actual value
|
|
233
|
+
// expected: { min: 18 } // ✨ The constraint that failed
|
|
234
|
+
// path: ["age"] // ✨ Path as array
|
|
235
|
+
// }
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 📚 All Validators (v1.2.0)
|
|
110
239
|
|
|
111
240
|
### String Validators (17)
|
|
112
241
|
|
|
@@ -714,17 +843,37 @@ Import only what you use for minimal bundle size.
|
|
|
714
843
|
|
|
715
844
|
```typescript
|
|
716
845
|
import {
|
|
846
|
+
// Schema creation
|
|
717
847
|
schema, // Create schema
|
|
718
848
|
field, // Field builders
|
|
849
|
+
coerce, // Type coercion builders
|
|
850
|
+
|
|
851
|
+
// Sync validation
|
|
719
852
|
validate, // Validate data
|
|
720
853
|
validateSchema, // Validate with schema
|
|
721
854
|
isValid, // Boolean validation
|
|
722
855
|
assertValid, // Throws if invalid
|
|
856
|
+
|
|
857
|
+
// Async validation (v1.2.0)
|
|
858
|
+
validateAsync, // Async validate data
|
|
859
|
+
validateSchemaAsync, // Async validate with schema
|
|
860
|
+
isValidAsync, // Async boolean validation
|
|
861
|
+
assertValidAsync, // Async throws if invalid
|
|
862
|
+
|
|
863
|
+
// Schema composition
|
|
723
864
|
extend, // Extend schema
|
|
724
865
|
pick, // Pick fields
|
|
725
866
|
omit, // Omit fields
|
|
726
867
|
merge, // Merge schemas
|
|
727
868
|
partial, // Make all optional
|
|
869
|
+
deepPartial, // Make all optional recursively (v1.2.0)
|
|
870
|
+
passthrough, // Allow unknown keys (v1.2.0)
|
|
871
|
+
strict, // Reject unknown keys (v1.2.0)
|
|
872
|
+
catchall, // Validate unknown keys (v1.2.0)
|
|
873
|
+
required, // Make specific fields required (v1.2.0)
|
|
874
|
+
optional, // Make specific fields optional (v1.2.0)
|
|
875
|
+
|
|
876
|
+
// Type inference
|
|
728
877
|
type InferInput, // Input type
|
|
729
878
|
type InferOutput // Output type
|
|
730
879
|
} from 'unischema';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Request, Response, RequestHandler, NextFunction } from 'express';
|
|
2
|
-
import { S as SchemaBuilder, I as InferInput } from '../../schema-
|
|
3
|
-
import { b as ValidationResult, E as EnterpriseValidationResponse } from '../../index-
|
|
2
|
+
import { S as SchemaBuilder, I as InferInput } from '../../schema-DYE8Wz8X.mjs';
|
|
3
|
+
import { b as ValidationResult, E as EnterpriseValidationResponse } from '../../index-C17xs-fU.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Express.js middleware adapter for FormSchema validation
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Request, Response, RequestHandler, NextFunction } from 'express';
|
|
2
|
-
import { S as SchemaBuilder, I as InferInput } from '../../schema-
|
|
3
|
-
import { b as ValidationResult, E as EnterpriseValidationResponse } from '../../index-
|
|
2
|
+
import { S as SchemaBuilder, I as InferInput } from '../../schema-Dtp-joeT.js';
|
|
3
|
+
import { b as ValidationResult, E as EnterpriseValidationResponse } from '../../index-C17xs-fU.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Express.js middleware adapter for FormSchema validation
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkBVRXGZLS_js = require('../../chunk-BVRXGZLS.js');
|
|
4
|
-
var
|
|
5
|
-
require('../../chunk-
|
|
6
|
-
require('../../chunk-
|
|
7
|
-
require('../../chunk-
|
|
8
|
-
require('../../chunk-
|
|
9
|
-
require('../../chunk-
|
|
10
|
-
require('../../chunk-
|
|
11
|
-
require('../../chunk-
|
|
4
|
+
var chunkDT2TQZU7_js = require('../../chunk-DT2TQZU7.js');
|
|
5
|
+
require('../../chunk-76BBWQDH.js');
|
|
6
|
+
require('../../chunk-FPCCH55A.js');
|
|
7
|
+
require('../../chunk-JEW6U6CB.js');
|
|
8
|
+
require('../../chunk-IUXRLMET.js');
|
|
9
|
+
require('../../chunk-TXT36BCE.js');
|
|
10
|
+
require('../../chunk-66RFUBVU.js');
|
|
11
|
+
require('../../chunk-OIYG5D2I.js');
|
|
12
12
|
|
|
13
13
|
// src/adapters/backend/express.ts
|
|
14
14
|
function defaultErrorHandler(result, _req, res) {
|
|
@@ -38,7 +38,7 @@ function validateRequest(schema, options = {}) {
|
|
|
38
38
|
if (transform) {
|
|
39
39
|
data = transform(data);
|
|
40
40
|
}
|
|
41
|
-
const result =
|
|
41
|
+
const result = chunkDT2TQZU7_js.validate(schema.definition, data);
|
|
42
42
|
req.validationResult = result;
|
|
43
43
|
if (!result.valid) {
|
|
44
44
|
onError(result, req, res);
|
|
@@ -120,7 +120,7 @@ function createHandler(schema, handler, options = {}) {
|
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
const validation =
|
|
123
|
+
const validation = chunkDT2TQZU7_js.validate(schema.definition, data);
|
|
124
124
|
if (!validation.valid) {
|
|
125
125
|
return {
|
|
126
126
|
statusCode: 400,
|
|
@@ -176,7 +176,7 @@ function createHandler(schema, handler, options = {}) {
|
|
|
176
176
|
}
|
|
177
177
|
function validateInput(schema, input) {
|
|
178
178
|
const data = typeof input === "string" ? JSON.parse(input) : input;
|
|
179
|
-
const result =
|
|
179
|
+
const result = chunkDT2TQZU7_js.validate(schema.definition, data);
|
|
180
180
|
return {
|
|
181
181
|
valid: result.valid,
|
|
182
182
|
data: result.valid ? data : null,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { toEnterpriseResponse } from '../../chunk-TTK77YBI.mjs';
|
|
2
|
-
import { validate } from '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
5
|
-
import '../../chunk-
|
|
6
|
-
import '../../chunk-
|
|
7
|
-
import '../../chunk-
|
|
8
|
-
import '../../chunk-
|
|
9
|
-
import '../../chunk-
|
|
2
|
+
import { validate } from '../../chunk-MFEBMQAU.mjs';
|
|
3
|
+
import '../../chunk-75YSYC4K.mjs';
|
|
4
|
+
import '../../chunk-KZCV5IW4.mjs';
|
|
5
|
+
import '../../chunk-COMVAVFU.mjs';
|
|
6
|
+
import '../../chunk-RW6HDA5H.mjs';
|
|
7
|
+
import '../../chunk-7XES4A3M.mjs';
|
|
8
|
+
import '../../chunk-5A4ITJVD.mjs';
|
|
9
|
+
import '../../chunk-KZZ7NVU3.mjs';
|
|
10
10
|
|
|
11
11
|
// src/adapters/backend/express.ts
|
|
12
12
|
function defaultErrorHandler(result, _req, res) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SchemaBuilder, I as InferInput } from '../../schema-
|
|
2
|
-
import { a as ValidationError, b as ValidationResult } from '../../index-
|
|
1
|
+
import { S as SchemaBuilder, I as InferInput } from '../../schema-DYE8Wz8X.mjs';
|
|
2
|
+
import { a as ValidationError, b as ValidationResult } from '../../index-C17xs-fU.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Headless form utilities for frontend frameworks
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SchemaBuilder, I as InferInput } from '../../schema-
|
|
2
|
-
import { a as ValidationError, b as ValidationResult } from '../../index-
|
|
1
|
+
import { S as SchemaBuilder, I as InferInput } from '../../schema-Dtp-joeT.js';
|
|
2
|
+
import { a as ValidationError, b as ValidationResult } from '../../index-C17xs-fU.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Headless form utilities for frontend frameworks
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
5
|
-
require('../../chunk-
|
|
6
|
-
require('../../chunk-
|
|
7
|
-
require('../../chunk-
|
|
8
|
-
require('../../chunk-
|
|
9
|
-
require('../../chunk-
|
|
10
|
-
require('../../chunk-
|
|
3
|
+
var chunkDT2TQZU7_js = require('../../chunk-DT2TQZU7.js');
|
|
4
|
+
require('../../chunk-76BBWQDH.js');
|
|
5
|
+
require('../../chunk-FPCCH55A.js');
|
|
6
|
+
require('../../chunk-JEW6U6CB.js');
|
|
7
|
+
require('../../chunk-IUXRLMET.js');
|
|
8
|
+
require('../../chunk-TXT36BCE.js');
|
|
9
|
+
require('../../chunk-66RFUBVU.js');
|
|
10
|
+
require('../../chunk-OIYG5D2I.js');
|
|
11
11
|
|
|
12
12
|
// src/adapters/frontend/form.ts
|
|
13
13
|
function createForm(schema, options = {}) {
|
|
@@ -137,7 +137,7 @@ var FormController = class {
|
|
|
137
137
|
* Validate a single field
|
|
138
138
|
*/
|
|
139
139
|
validateField(field) {
|
|
140
|
-
const result =
|
|
140
|
+
const result = chunkDT2TQZU7_js.validate(this.schema.definition, this.state.values);
|
|
141
141
|
const fieldHardErrors = result.hardErrors.filter((e) => e.field === field);
|
|
142
142
|
const fieldSoftErrors = result.softErrors.filter((e) => e.field === field);
|
|
143
143
|
this.state.errors[field] = fieldHardErrors;
|
|
@@ -154,7 +154,7 @@ var FormController = class {
|
|
|
154
154
|
* Validate entire form
|
|
155
155
|
*/
|
|
156
156
|
validate() {
|
|
157
|
-
const result =
|
|
157
|
+
const result = chunkDT2TQZU7_js.validate(this.schema.definition, this.state.values);
|
|
158
158
|
const errors = {};
|
|
159
159
|
const warnings = {};
|
|
160
160
|
for (const error of result.hardErrors) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { validate } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
5
|
-
import '../../chunk-
|
|
6
|
-
import '../../chunk-
|
|
7
|
-
import '../../chunk-
|
|
8
|
-
import '../../chunk-
|
|
1
|
+
import { validate } from '../../chunk-MFEBMQAU.mjs';
|
|
2
|
+
import '../../chunk-75YSYC4K.mjs';
|
|
3
|
+
import '../../chunk-KZCV5IW4.mjs';
|
|
4
|
+
import '../../chunk-COMVAVFU.mjs';
|
|
5
|
+
import '../../chunk-RW6HDA5H.mjs';
|
|
6
|
+
import '../../chunk-7XES4A3M.mjs';
|
|
7
|
+
import '../../chunk-5A4ITJVD.mjs';
|
|
8
|
+
import '../../chunk-KZZ7NVU3.mjs';
|
|
9
9
|
|
|
10
10
|
// src/adapters/frontend/form.ts
|
|
11
11
|
function createForm(schema, options = {}) {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
|
|
4
4
|
|
|
5
5
|
// src/validators/array/includes.ts
|
|
6
6
|
var includesValidator = (value, params, context) => {
|
|
7
|
-
if (
|
|
7
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
8
8
|
const item = params?.item;
|
|
9
9
|
const soft = params?.soft;
|
|
10
10
|
const message = params?.message;
|
|
11
|
-
if (!
|
|
11
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
12
12
|
if (!value.includes(item)) {
|
|
13
|
-
return
|
|
13
|
+
return chunkOIYG5D2I_js.createError(
|
|
14
14
|
context,
|
|
15
15
|
"INVALID_INCLUDES",
|
|
16
16
|
message || `Array must include ${JSON.stringify(item)}`,
|
|
@@ -22,13 +22,13 @@ var includesValidator = (value, params, context) => {
|
|
|
22
22
|
|
|
23
23
|
// src/validators/array/excludes.ts
|
|
24
24
|
var excludesValidator = (value, params, context) => {
|
|
25
|
-
if (
|
|
25
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
26
26
|
const item = params?.item;
|
|
27
27
|
const soft = params?.soft;
|
|
28
28
|
const message = params?.message;
|
|
29
|
-
if (!
|
|
29
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
30
30
|
if (value.includes(item)) {
|
|
31
|
-
return
|
|
31
|
+
return chunkOIYG5D2I_js.createError(
|
|
32
32
|
context,
|
|
33
33
|
"INVALID_EXCLUDES",
|
|
34
34
|
message || `Array must not include ${JSON.stringify(item)}`,
|
|
@@ -40,12 +40,12 @@ var excludesValidator = (value, params, context) => {
|
|
|
40
40
|
|
|
41
41
|
// src/validators/array/empty.ts
|
|
42
42
|
var emptyValidator = (value, params, context) => {
|
|
43
|
-
if (
|
|
43
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
44
44
|
const soft = params?.soft;
|
|
45
45
|
const message = params?.message;
|
|
46
|
-
if (!
|
|
46
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
47
47
|
if (value.length > 0) {
|
|
48
|
-
return
|
|
48
|
+
return chunkOIYG5D2I_js.createError(
|
|
49
49
|
context,
|
|
50
50
|
"INVALID_EMPTY",
|
|
51
51
|
message || "Array must be empty",
|
|
@@ -57,12 +57,12 @@ var emptyValidator = (value, params, context) => {
|
|
|
57
57
|
|
|
58
58
|
// src/validators/array/notEmpty.ts
|
|
59
59
|
var notEmptyValidator = (value, params, context) => {
|
|
60
|
-
if (
|
|
60
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
61
61
|
const soft = params?.soft;
|
|
62
62
|
const message = params?.message;
|
|
63
|
-
if (!
|
|
63
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
64
64
|
if (value.length === 0) {
|
|
65
|
-
return
|
|
65
|
+
return chunkOIYG5D2I_js.createError(
|
|
66
66
|
context,
|
|
67
67
|
"INVALID_NOT_EMPTY",
|
|
68
68
|
message || "Array must not be empty",
|
|
@@ -74,17 +74,17 @@ var notEmptyValidator = (value, params, context) => {
|
|
|
74
74
|
|
|
75
75
|
// src/validators/array/sorted.ts
|
|
76
76
|
var sortedValidator = (value, params, context) => {
|
|
77
|
-
if (
|
|
77
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
78
78
|
const order = params?.order || "asc";
|
|
79
79
|
const soft = params?.soft;
|
|
80
80
|
const message = params?.message;
|
|
81
|
-
if (!
|
|
81
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
82
82
|
for (let i = 1; i < value.length; i++) {
|
|
83
83
|
const prev = value[i - 1];
|
|
84
84
|
const curr = value[i];
|
|
85
85
|
if (order === "asc") {
|
|
86
86
|
if (prev > curr) {
|
|
87
|
-
return
|
|
87
|
+
return chunkOIYG5D2I_js.createError(
|
|
88
88
|
context,
|
|
89
89
|
"INVALID_SORTED",
|
|
90
90
|
message || "Array must be sorted in ascending order",
|
|
@@ -93,7 +93,7 @@ var sortedValidator = (value, params, context) => {
|
|
|
93
93
|
}
|
|
94
94
|
} else {
|
|
95
95
|
if (prev < curr) {
|
|
96
|
-
return
|
|
96
|
+
return chunkOIYG5D2I_js.createError(
|
|
97
97
|
context,
|
|
98
98
|
"INVALID_SORTED",
|
|
99
99
|
message || "Array must be sorted in descending order",
|
|
@@ -107,13 +107,13 @@ var sortedValidator = (value, params, context) => {
|
|
|
107
107
|
|
|
108
108
|
// src/validators/array/compact.ts
|
|
109
109
|
var compactValidator = (value, params, context) => {
|
|
110
|
-
if (
|
|
110
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
111
111
|
const soft = params?.soft;
|
|
112
112
|
const message = params?.message;
|
|
113
|
-
if (!
|
|
113
|
+
if (!chunkOIYG5D2I_js.isArray(value)) return null;
|
|
114
114
|
const hasFalsy = value.some((item) => !item);
|
|
115
115
|
if (hasFalsy) {
|
|
116
|
-
return
|
|
116
|
+
return chunkOIYG5D2I_js.createError(
|
|
117
117
|
context,
|
|
118
118
|
"INVALID_COMPACT",
|
|
119
119
|
message || "Array must not contain falsy values",
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
|
|
4
4
|
|
|
5
5
|
// src/validators/object/keys.ts
|
|
6
6
|
var keysValidator = (value, params, context) => {
|
|
7
|
-
if (
|
|
7
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
8
8
|
const pattern = params?.pattern;
|
|
9
9
|
const soft = params?.soft;
|
|
10
10
|
const message = params?.message;
|
|
11
|
-
if (!
|
|
11
|
+
if (!chunkOIYG5D2I_js.isObject(value)) return null;
|
|
12
12
|
if (pattern) {
|
|
13
13
|
const keys = Object.keys(value);
|
|
14
14
|
const invalidKeys = keys.filter((key) => !pattern.test(key));
|
|
15
15
|
if (invalidKeys.length > 0) {
|
|
16
|
-
return
|
|
16
|
+
return chunkOIYG5D2I_js.createError(
|
|
17
17
|
context,
|
|
18
18
|
"INVALID_KEYS",
|
|
19
19
|
message || `Invalid keys: ${invalidKeys.join(", ")}`,
|
|
@@ -26,15 +26,15 @@ var keysValidator = (value, params, context) => {
|
|
|
26
26
|
|
|
27
27
|
// src/validators/object/pick.ts
|
|
28
28
|
var pickValidator = (value, params, context) => {
|
|
29
|
-
if (
|
|
29
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
30
30
|
const allowedKeys = params?.keys;
|
|
31
31
|
const soft = params?.soft;
|
|
32
32
|
const message = params?.message;
|
|
33
|
-
if (!
|
|
33
|
+
if (!chunkOIYG5D2I_js.isObject(value) || !allowedKeys) return null;
|
|
34
34
|
const keys = Object.keys(value);
|
|
35
35
|
const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
|
|
36
36
|
if (extraKeys.length > 0) {
|
|
37
|
-
return
|
|
37
|
+
return chunkOIYG5D2I_js.createError(
|
|
38
38
|
context,
|
|
39
39
|
"INVALID_PICK",
|
|
40
40
|
message || `Unexpected keys: ${extraKeys.join(", ")}`,
|
|
@@ -46,15 +46,15 @@ var pickValidator = (value, params, context) => {
|
|
|
46
46
|
|
|
47
47
|
// src/validators/object/omit.ts
|
|
48
48
|
var omitValidator = (value, params, context) => {
|
|
49
|
-
if (
|
|
49
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
50
50
|
const forbiddenKeys = params?.keys;
|
|
51
51
|
const soft = params?.soft;
|
|
52
52
|
const message = params?.message;
|
|
53
|
-
if (!
|
|
53
|
+
if (!chunkOIYG5D2I_js.isObject(value) || !forbiddenKeys) return null;
|
|
54
54
|
const keys = Object.keys(value);
|
|
55
55
|
const foundForbidden = keys.filter((key) => forbiddenKeys.includes(key));
|
|
56
56
|
if (foundForbidden.length > 0) {
|
|
57
|
-
return
|
|
57
|
+
return chunkOIYG5D2I_js.createError(
|
|
58
58
|
context,
|
|
59
59
|
"INVALID_OMIT",
|
|
60
60
|
message || `Forbidden keys found: ${foundForbidden.join(", ")}`,
|
|
@@ -66,15 +66,15 @@ var omitValidator = (value, params, context) => {
|
|
|
66
66
|
|
|
67
67
|
// src/validators/object/strict.ts
|
|
68
68
|
var strictValidator = (value, params, context) => {
|
|
69
|
-
if (
|
|
69
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
70
70
|
const allowedKeys = params?.allowedKeys;
|
|
71
71
|
const soft = params?.soft;
|
|
72
72
|
const message = params?.message;
|
|
73
|
-
if (!
|
|
73
|
+
if (!chunkOIYG5D2I_js.isObject(value) || !allowedKeys) return null;
|
|
74
74
|
const keys = Object.keys(value);
|
|
75
75
|
const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
|
|
76
76
|
if (extraKeys.length > 0) {
|
|
77
|
-
return
|
|
77
|
+
return chunkOIYG5D2I_js.createError(
|
|
78
78
|
context,
|
|
79
79
|
"INVALID_STRICT",
|
|
80
80
|
message || `Unknown keys not allowed: ${extraKeys.join(", ")}`,
|