@awsless/validate 0.0.3 → 0.0.5
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/dist/index.cjs +101 -175
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +20 -12
- package/dist/index.js +111 -173
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -15,215 +15,141 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
|
|
20
21
|
// src/index.ts
|
|
21
22
|
var src_exports = {};
|
|
22
23
|
__export(src_exports, {
|
|
23
|
-
Struct: () => import_superstruct7.Struct,
|
|
24
|
-
StructError: () => import_superstruct7.StructError,
|
|
25
|
-
any: () => import_superstruct7.any,
|
|
26
|
-
array: () => import_superstruct7.array,
|
|
27
|
-
assert: () => import_superstruct7.assert,
|
|
28
|
-
assign: () => import_superstruct7.assign,
|
|
29
24
|
bigfloat: () => bigfloat,
|
|
30
|
-
bigint: () => import_superstruct7.bigint,
|
|
31
|
-
boolean: () => import_superstruct7.boolean,
|
|
32
|
-
coerce: () => import_superstruct7.coerce,
|
|
33
|
-
create: () => import_superstruct7.create,
|
|
34
25
|
date: () => date,
|
|
35
|
-
defaulted: () => import_superstruct7.defaulted,
|
|
36
|
-
define: () => import_superstruct7.define,
|
|
37
|
-
deprecated: () => import_superstruct7.deprecated,
|
|
38
|
-
dynamic: () => import_superstruct7.dynamic,
|
|
39
|
-
empty: () => import_superstruct7.empty,
|
|
40
|
-
enums: () => import_superstruct7.enums,
|
|
41
|
-
func: () => import_superstruct7.func,
|
|
42
|
-
instance: () => import_superstruct7.instance,
|
|
43
|
-
integer: () => import_superstruct7.integer,
|
|
44
|
-
intersection: () => import_superstruct7.intersection,
|
|
45
|
-
is: () => import_superstruct7.is,
|
|
46
26
|
json: () => json,
|
|
47
|
-
lazy: () => import_superstruct7.lazy,
|
|
48
|
-
literal: () => import_superstruct7.literal,
|
|
49
|
-
lowercase: () => lowercase,
|
|
50
|
-
map: () => import_superstruct7.map,
|
|
51
|
-
mask: () => import_superstruct7.mask,
|
|
52
|
-
max: () => import_superstruct7.max,
|
|
53
|
-
min: () => import_superstruct7.min,
|
|
54
|
-
never: () => import_superstruct7.never,
|
|
55
|
-
nonempty: () => import_superstruct7.nonempty,
|
|
56
|
-
nullable: () => import_superstruct7.nullable,
|
|
57
|
-
number: () => import_superstruct7.number,
|
|
58
|
-
object: () => import_superstruct7.object,
|
|
59
|
-
omit: () => import_superstruct7.omit,
|
|
60
|
-
optional: () => import_superstruct7.optional,
|
|
61
|
-
partial: () => import_superstruct7.partial,
|
|
62
|
-
pattern: () => import_superstruct7.pattern,
|
|
63
|
-
pick: () => import_superstruct7.pick,
|
|
64
27
|
positive: () => positive,
|
|
65
28
|
precision: () => precision,
|
|
66
|
-
record: () => import_superstruct7.record,
|
|
67
|
-
refine: () => import_superstruct7.refine,
|
|
68
|
-
regexp: () => import_superstruct7.regexp,
|
|
69
|
-
set: () => import_superstruct7.set,
|
|
70
|
-
size: () => import_superstruct7.size,
|
|
71
|
-
string: () => import_superstruct7.string,
|
|
72
|
-
struct: () => import_superstruct7.struct,
|
|
73
|
-
trimmed: () => import_superstruct7.trimmed,
|
|
74
|
-
tuple: () => import_superstruct7.tuple,
|
|
75
|
-
type: () => import_superstruct7.type,
|
|
76
|
-
union: () => import_superstruct7.union,
|
|
77
29
|
unique: () => unique,
|
|
78
|
-
unknown: () => import_superstruct7.unknown,
|
|
79
|
-
uppercase: () => uppercase,
|
|
80
30
|
uuid: () => uuid
|
|
81
31
|
});
|
|
82
32
|
module.exports = __toCommonJS(src_exports);
|
|
33
|
+
__reExport(src_exports, require("valibot"), module.exports);
|
|
83
34
|
|
|
84
|
-
// src/
|
|
85
|
-
var
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return new import_big_float.BigFloat(value);
|
|
35
|
+
// src/schema/json.ts
|
|
36
|
+
var import_valibot = require("valibot");
|
|
37
|
+
var json = (schema) => {
|
|
38
|
+
return (0, import_valibot.transform)(
|
|
39
|
+
(0, import_valibot.string)(),
|
|
40
|
+
(value) => {
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(value);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return null;
|
|
95
45
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
var positive = (struct2) => {
|
|
101
|
-
const expected = `Expected a positive ${struct2.type}`;
|
|
102
|
-
const ZERO = new import_big_float.BigFloat(0);
|
|
103
|
-
return (0, import_superstruct.refine)(struct2, "positive", (value) => {
|
|
104
|
-
return (0, import_big_float.gt)(value, ZERO) || `${expected} but received '${value}'`;
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
var precision = (struct2, decimals) => {
|
|
108
|
-
const expected = `Expected a ${struct2.type}`;
|
|
109
|
-
return (0, import_superstruct.refine)(struct2, "precision", (value) => {
|
|
110
|
-
const big = new import_big_float.BigFloat(value);
|
|
111
|
-
return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
|
|
112
|
-
});
|
|
46
|
+
},
|
|
47
|
+
schema
|
|
48
|
+
);
|
|
113
49
|
};
|
|
114
50
|
|
|
115
|
-
// src/
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
51
|
+
// src/schema/bigfloat.ts
|
|
52
|
+
var import_big_float = require("@awsless/big-float");
|
|
53
|
+
var import_valibot2 = require("valibot");
|
|
54
|
+
var make = (value) => new import_big_float.BigFloat(value);
|
|
55
|
+
function bigfloat(arg1, arg2) {
|
|
56
|
+
const [msg, pipe] = (0, import_valibot2.getDefaultArgs)(arg1, arg2);
|
|
57
|
+
const error = msg ?? "Invalid bigfloat";
|
|
58
|
+
return (0, import_valibot2.union)(
|
|
59
|
+
[
|
|
60
|
+
(0, import_valibot2.instance)(import_big_float.BigFloat, pipe),
|
|
61
|
+
(0, import_valibot2.transform)(
|
|
62
|
+
(0, import_valibot2.string)([
|
|
63
|
+
(input) => {
|
|
64
|
+
if (input === "" || isNaN(Number(input))) {
|
|
65
|
+
return (0, import_valibot2.getPipeIssues)("bigfloat", error, input);
|
|
66
|
+
}
|
|
67
|
+
return (0, import_valibot2.getOutput)(input);
|
|
68
|
+
}
|
|
69
|
+
]),
|
|
70
|
+
make,
|
|
71
|
+
pipe
|
|
72
|
+
),
|
|
73
|
+
(0, import_valibot2.transform)((0, import_valibot2.number)(), make, pipe),
|
|
74
|
+
(0, import_valibot2.transform)(
|
|
75
|
+
(0, import_valibot2.object)({
|
|
76
|
+
exponent: (0, import_valibot2.number)(),
|
|
77
|
+
coefficient: (0, import_valibot2.bigint)()
|
|
78
|
+
}),
|
|
79
|
+
make,
|
|
80
|
+
pipe
|
|
81
|
+
)
|
|
82
|
+
],
|
|
83
|
+
error
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/schema/date.ts
|
|
88
|
+
var import_valibot3 = require("valibot");
|
|
89
|
+
function date(arg1, arg2) {
|
|
90
|
+
const [error, pipe] = (0, import_valibot3.getDefaultArgs)(arg1, arg2);
|
|
91
|
+
return (0, import_valibot3.union)(
|
|
92
|
+
[
|
|
93
|
+
(0, import_valibot3.date)(pipe),
|
|
94
|
+
(0, import_valibot3.transform)(
|
|
95
|
+
(0, import_valibot3.string)(),
|
|
96
|
+
(input) => {
|
|
97
|
+
return new Date(input);
|
|
98
|
+
},
|
|
99
|
+
(0, import_valibot3.date)(pipe)
|
|
100
|
+
)
|
|
101
|
+
],
|
|
102
|
+
error ?? "Invalid date"
|
|
103
|
+
);
|
|
104
|
+
}
|
|
122
105
|
|
|
123
|
-
// src/
|
|
124
|
-
var
|
|
106
|
+
// src/schema/uuid.ts
|
|
107
|
+
var import_valibot4 = require("valibot");
|
|
125
108
|
var uuid = () => {
|
|
126
|
-
return (0,
|
|
127
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(value));
|
|
128
|
-
});
|
|
109
|
+
return (0, import_valibot4.transform)((0, import_valibot4.string)([(0, import_valibot4.uuid)()]), (v) => v);
|
|
129
110
|
};
|
|
130
111
|
|
|
131
|
-
// src/
|
|
132
|
-
var
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
};
|
|
112
|
+
// src/validation/positive.ts
|
|
113
|
+
var import_big_float2 = require("@awsless/big-float");
|
|
114
|
+
var import_valibot5 = require("valibot");
|
|
115
|
+
function positive(error) {
|
|
116
|
+
return (input) => {
|
|
117
|
+
return (0, import_big_float2.gt)(input, import_big_float2.ZERO) ? (0, import_valibot5.getOutput)(input) : (0, import_valibot5.getPipeIssues)("positive", error ?? "Invalid positive number", input);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
142
120
|
|
|
143
|
-
// src/
|
|
144
|
-
var
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
};
|
|
121
|
+
// src/validation/precision.ts
|
|
122
|
+
var import_big_float3 = require("@awsless/big-float");
|
|
123
|
+
var import_valibot6 = require("valibot");
|
|
124
|
+
function precision(decimals, error) {
|
|
125
|
+
return (input) => {
|
|
126
|
+
const big = new import_big_float3.BigFloat(input.toString());
|
|
127
|
+
return -big.exponent <= decimals ? (0, import_valibot6.getOutput)(input) : (0, import_valibot6.getPipeIssues)("precision", error ?? `Invalid ${decimals} precision number`, input);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
151
130
|
|
|
152
|
-
// src/
|
|
153
|
-
var
|
|
154
|
-
function unique(
|
|
155
|
-
return (
|
|
156
|
-
for (const x in
|
|
157
|
-
for (const y in
|
|
158
|
-
if (x !== y && compare(
|
|
159
|
-
return
|
|
131
|
+
// src/validation/unique.ts
|
|
132
|
+
var import_valibot7 = require("valibot");
|
|
133
|
+
function unique(compare = (a, b) => a === b, error) {
|
|
134
|
+
return (input) => {
|
|
135
|
+
for (const x in input) {
|
|
136
|
+
for (const y in input) {
|
|
137
|
+
if (x !== y && compare(input[x], input[y])) {
|
|
138
|
+
return (0, import_valibot7.getPipeIssues)("unique", error ?? "None unique array", input);
|
|
160
139
|
}
|
|
161
140
|
}
|
|
162
141
|
}
|
|
163
|
-
return
|
|
164
|
-
}
|
|
142
|
+
return (0, import_valibot7.getOutput)(input);
|
|
143
|
+
};
|
|
165
144
|
}
|
|
166
|
-
|
|
167
|
-
// src/index.ts
|
|
168
|
-
var import_superstruct7 = require("superstruct");
|
|
169
145
|
// Annotate the CommonJS export names for ESM import in node:
|
|
170
146
|
0 && (module.exports = {
|
|
171
|
-
Struct,
|
|
172
|
-
StructError,
|
|
173
|
-
any,
|
|
174
|
-
array,
|
|
175
|
-
assert,
|
|
176
|
-
assign,
|
|
177
147
|
bigfloat,
|
|
178
|
-
bigint,
|
|
179
|
-
boolean,
|
|
180
|
-
coerce,
|
|
181
|
-
create,
|
|
182
148
|
date,
|
|
183
|
-
defaulted,
|
|
184
|
-
define,
|
|
185
|
-
deprecated,
|
|
186
|
-
dynamic,
|
|
187
|
-
empty,
|
|
188
|
-
enums,
|
|
189
|
-
func,
|
|
190
|
-
instance,
|
|
191
|
-
integer,
|
|
192
|
-
intersection,
|
|
193
|
-
is,
|
|
194
149
|
json,
|
|
195
|
-
lazy,
|
|
196
|
-
literal,
|
|
197
|
-
lowercase,
|
|
198
|
-
map,
|
|
199
|
-
mask,
|
|
200
|
-
max,
|
|
201
|
-
min,
|
|
202
|
-
never,
|
|
203
|
-
nonempty,
|
|
204
|
-
nullable,
|
|
205
|
-
number,
|
|
206
|
-
object,
|
|
207
|
-
omit,
|
|
208
|
-
optional,
|
|
209
|
-
partial,
|
|
210
|
-
pattern,
|
|
211
|
-
pick,
|
|
212
150
|
positive,
|
|
213
151
|
precision,
|
|
214
|
-
record,
|
|
215
|
-
refine,
|
|
216
|
-
regexp,
|
|
217
|
-
set,
|
|
218
|
-
size,
|
|
219
|
-
string,
|
|
220
|
-
struct,
|
|
221
|
-
trimmed,
|
|
222
|
-
tuple,
|
|
223
|
-
type,
|
|
224
|
-
union,
|
|
225
152
|
unique,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
uuid
|
|
153
|
+
uuid,
|
|
154
|
+
...require("valibot")
|
|
229
155
|
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, PipeResult } from 'valibot';
|
|
2
|
+
export * from 'valibot';
|
|
3
|
+
import { BigFloat } from '@awsless/big-float';
|
|
4
|
+
import { UUID } from 'crypto';
|
|
5
|
+
|
|
6
|
+
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
7
|
+
declare const json: <T extends BaseSchema<any, any>>(schema: T) => JsonSchema<T>;
|
|
8
|
+
|
|
9
|
+
type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
10
|
+
exponent: number;
|
|
11
|
+
coefficient: bigint;
|
|
12
|
+
}, BigFloat>;
|
|
13
|
+
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
14
|
+
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
15
|
+
|
|
16
|
+
type DateSchema = BaseSchema<string | Date, Date>;
|
|
17
|
+
declare function date(pipe?: Pipe<Date>): DateSchema;
|
|
18
|
+
declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
|
|
19
|
+
|
|
20
|
+
type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
|
|
21
|
+
declare const uuid: () => UuidSchema;
|
|
22
|
+
|
|
23
|
+
declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
24
|
+
|
|
25
|
+
declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
26
|
+
|
|
27
|
+
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
28
|
+
|
|
29
|
+
export { bigfloat, date, json, positive, precision, unique, uuid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, PipeResult } from 'valibot';
|
|
2
|
+
export * from 'valibot';
|
|
3
3
|
import { BigFloat } from '@awsless/big-float';
|
|
4
4
|
import { UUID } from 'crypto';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
declare const
|
|
8
|
-
declare const precision: <T extends number | BigFloat, S extends unknown>(struct: Struct<T, S>, decimals: number) => Struct<T, S>;
|
|
6
|
+
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
7
|
+
declare const json: <T extends BaseSchema<any, any>>(schema: T) => JsonSchema<T>;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
10
|
+
exponent: number;
|
|
11
|
+
coefficient: bigint;
|
|
12
|
+
}, BigFloat>;
|
|
13
|
+
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
14
|
+
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
type DateSchema = BaseSchema<string | Date, Date>;
|
|
17
|
+
declare function date(pipe?: Pipe<Date>): DateSchema;
|
|
18
|
+
declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
|
|
21
|
+
declare const uuid: () => UuidSchema;
|
|
15
22
|
|
|
16
|
-
declare
|
|
17
|
-
declare const uppercase: <T, S>(struct: Struct<T, S>) => Struct<T, S>;
|
|
23
|
+
declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
18
24
|
|
|
19
|
-
declare function
|
|
25
|
+
declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
|
|
28
|
+
|
|
29
|
+
export { bigfloat, date, json, positive, precision, unique, uuid };
|
package/dist/index.js
CHANGED
|
@@ -1,195 +1,133 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "valibot";
|
|
3
|
+
|
|
4
|
+
// src/schema/json.ts
|
|
5
|
+
import { string, transform } from "valibot";
|
|
6
|
+
var json = (schema) => {
|
|
7
|
+
return transform(
|
|
8
|
+
string(),
|
|
9
|
+
(value) => {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(value);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return null;
|
|
12
14
|
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
var positive = (struct2) => {
|
|
18
|
-
const expected = `Expected a positive ${struct2.type}`;
|
|
19
|
-
const ZERO = new BigFloat(0);
|
|
20
|
-
return refine(struct2, "positive", (value) => {
|
|
21
|
-
return gt(value, ZERO) || `${expected} but received '${value}'`;
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var precision = (struct2, decimals) => {
|
|
25
|
-
const expected = `Expected a ${struct2.type}`;
|
|
26
|
-
return refine(struct2, "precision", (value) => {
|
|
27
|
-
const big = new BigFloat(value);
|
|
28
|
-
return -big.exponent <= decimals || `${expected} with ${decimals} decimals`;
|
|
29
|
-
});
|
|
15
|
+
},
|
|
16
|
+
schema
|
|
17
|
+
);
|
|
30
18
|
};
|
|
31
19
|
|
|
32
|
-
// src/
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
// src/schema/bigfloat.ts
|
|
21
|
+
import { BigFloat } from "@awsless/big-float";
|
|
22
|
+
import {
|
|
23
|
+
bigint,
|
|
24
|
+
getDefaultArgs,
|
|
25
|
+
instance,
|
|
26
|
+
number,
|
|
27
|
+
object,
|
|
28
|
+
string as string2,
|
|
29
|
+
transform as transform2,
|
|
30
|
+
union,
|
|
31
|
+
getPipeIssues,
|
|
32
|
+
getOutput
|
|
33
|
+
} from "valibot";
|
|
34
|
+
var make = (value) => new BigFloat(value);
|
|
35
|
+
function bigfloat(arg1, arg2) {
|
|
36
|
+
const [msg, pipe] = getDefaultArgs(arg1, arg2);
|
|
37
|
+
const error = msg ?? "Invalid bigfloat";
|
|
38
|
+
return union(
|
|
39
|
+
[
|
|
40
|
+
instance(BigFloat, pipe),
|
|
41
|
+
transform2(
|
|
42
|
+
string2([
|
|
43
|
+
(input) => {
|
|
44
|
+
if (input === "" || isNaN(Number(input))) {
|
|
45
|
+
return getPipeIssues("bigfloat", error, input);
|
|
46
|
+
}
|
|
47
|
+
return getOutput(input);
|
|
48
|
+
}
|
|
49
|
+
]),
|
|
50
|
+
make,
|
|
51
|
+
pipe
|
|
52
|
+
),
|
|
53
|
+
transform2(number(), make, pipe),
|
|
54
|
+
transform2(
|
|
55
|
+
object({
|
|
56
|
+
exponent: number(),
|
|
57
|
+
coefficient: bigint()
|
|
58
|
+
}),
|
|
59
|
+
make,
|
|
60
|
+
pipe
|
|
61
|
+
)
|
|
62
|
+
],
|
|
63
|
+
error
|
|
64
|
+
);
|
|
65
|
+
}
|
|
39
66
|
|
|
40
|
-
// src/
|
|
41
|
-
import {
|
|
67
|
+
// src/schema/date.ts
|
|
68
|
+
import { getDefaultArgs as getDefaultArgs2, date as base, string as string3, union as union2, transform as transform3 } from "valibot";
|
|
69
|
+
function date(arg1, arg2) {
|
|
70
|
+
const [error, pipe] = getDefaultArgs2(arg1, arg2);
|
|
71
|
+
return union2(
|
|
72
|
+
[
|
|
73
|
+
base(pipe),
|
|
74
|
+
transform3(
|
|
75
|
+
string3(),
|
|
76
|
+
(input) => {
|
|
77
|
+
return new Date(input);
|
|
78
|
+
},
|
|
79
|
+
base(pipe)
|
|
80
|
+
)
|
|
81
|
+
],
|
|
82
|
+
error ?? "Invalid date"
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/schema/uuid.ts
|
|
87
|
+
import { string as string4, uuid as base2, transform as transform4 } from "valibot";
|
|
42
88
|
var uuid = () => {
|
|
43
|
-
return
|
|
44
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(value));
|
|
45
|
-
});
|
|
89
|
+
return transform4(string4([base2()]), (v) => v);
|
|
46
90
|
};
|
|
47
91
|
|
|
48
|
-
// src/
|
|
49
|
-
import {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
};
|
|
92
|
+
// src/validation/positive.ts
|
|
93
|
+
import { ZERO, gt } from "@awsless/big-float";
|
|
94
|
+
import { getOutput as getOutput2, getPipeIssues as getPipeIssues2 } from "valibot";
|
|
95
|
+
function positive(error) {
|
|
96
|
+
return (input) => {
|
|
97
|
+
return gt(input, ZERO) ? getOutput2(input) : getPipeIssues2("positive", error ?? "Invalid positive number", input);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
59
100
|
|
|
60
|
-
// src/
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
101
|
+
// src/validation/precision.ts
|
|
102
|
+
import { BigFloat as BigFloat3 } from "@awsless/big-float";
|
|
103
|
+
import { getOutput as getOutput3, getPipeIssues as getPipeIssues3 } from "valibot";
|
|
104
|
+
function precision(decimals, error) {
|
|
105
|
+
return (input) => {
|
|
106
|
+
const big = new BigFloat3(input.toString());
|
|
107
|
+
return -big.exponent <= decimals ? getOutput3(input) : getPipeIssues3("precision", error ?? `Invalid ${decimals} precision number`, input);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
68
110
|
|
|
69
|
-
// src/
|
|
70
|
-
import {
|
|
71
|
-
function unique(
|
|
72
|
-
return
|
|
73
|
-
for (const x in
|
|
74
|
-
for (const y in
|
|
75
|
-
if (x !== y && compare(
|
|
76
|
-
return
|
|
111
|
+
// src/validation/unique.ts
|
|
112
|
+
import { getOutput as getOutput4, getPipeIssues as getPipeIssues4 } from "valibot";
|
|
113
|
+
function unique(compare = (a, b) => a === b, error) {
|
|
114
|
+
return (input) => {
|
|
115
|
+
for (const x in input) {
|
|
116
|
+
for (const y in input) {
|
|
117
|
+
if (x !== y && compare(input[x], input[y])) {
|
|
118
|
+
return getPipeIssues4("unique", error ?? "None unique array", input);
|
|
77
119
|
}
|
|
78
120
|
}
|
|
79
121
|
}
|
|
80
|
-
return
|
|
81
|
-
}
|
|
122
|
+
return getOutput4(input);
|
|
123
|
+
};
|
|
82
124
|
}
|
|
83
|
-
|
|
84
|
-
// src/index.ts
|
|
85
|
-
import {
|
|
86
|
-
coerce as coerce5,
|
|
87
|
-
defaulted,
|
|
88
|
-
trimmed,
|
|
89
|
-
empty,
|
|
90
|
-
max,
|
|
91
|
-
min,
|
|
92
|
-
nonempty,
|
|
93
|
-
pattern,
|
|
94
|
-
size,
|
|
95
|
-
refine as refine3,
|
|
96
|
-
any,
|
|
97
|
-
array,
|
|
98
|
-
bigint,
|
|
99
|
-
boolean,
|
|
100
|
-
enums,
|
|
101
|
-
func,
|
|
102
|
-
instance,
|
|
103
|
-
integer,
|
|
104
|
-
intersection,
|
|
105
|
-
literal,
|
|
106
|
-
map,
|
|
107
|
-
never,
|
|
108
|
-
nullable,
|
|
109
|
-
number as number2,
|
|
110
|
-
object,
|
|
111
|
-
optional,
|
|
112
|
-
record,
|
|
113
|
-
regexp,
|
|
114
|
-
set,
|
|
115
|
-
string as string5,
|
|
116
|
-
tuple,
|
|
117
|
-
type,
|
|
118
|
-
union as union2,
|
|
119
|
-
unknown,
|
|
120
|
-
assign,
|
|
121
|
-
define as define3,
|
|
122
|
-
deprecated,
|
|
123
|
-
dynamic,
|
|
124
|
-
lazy,
|
|
125
|
-
omit,
|
|
126
|
-
partial,
|
|
127
|
-
pick,
|
|
128
|
-
struct,
|
|
129
|
-
assert,
|
|
130
|
-
create,
|
|
131
|
-
mask,
|
|
132
|
-
is,
|
|
133
|
-
Struct as Struct7,
|
|
134
|
-
StructError
|
|
135
|
-
} from "superstruct";
|
|
136
125
|
export {
|
|
137
|
-
Struct7 as Struct,
|
|
138
|
-
StructError,
|
|
139
|
-
any,
|
|
140
|
-
array,
|
|
141
|
-
assert,
|
|
142
|
-
assign,
|
|
143
126
|
bigfloat,
|
|
144
|
-
bigint,
|
|
145
|
-
boolean,
|
|
146
|
-
coerce5 as coerce,
|
|
147
|
-
create,
|
|
148
127
|
date,
|
|
149
|
-
defaulted,
|
|
150
|
-
define3 as define,
|
|
151
|
-
deprecated,
|
|
152
|
-
dynamic,
|
|
153
|
-
empty,
|
|
154
|
-
enums,
|
|
155
|
-
func,
|
|
156
|
-
instance,
|
|
157
|
-
integer,
|
|
158
|
-
intersection,
|
|
159
|
-
is,
|
|
160
128
|
json,
|
|
161
|
-
lazy,
|
|
162
|
-
literal,
|
|
163
|
-
lowercase,
|
|
164
|
-
map,
|
|
165
|
-
mask,
|
|
166
|
-
max,
|
|
167
|
-
min,
|
|
168
|
-
never,
|
|
169
|
-
nonempty,
|
|
170
|
-
nullable,
|
|
171
|
-
number2 as number,
|
|
172
|
-
object,
|
|
173
|
-
omit,
|
|
174
|
-
optional,
|
|
175
|
-
partial,
|
|
176
|
-
pattern,
|
|
177
|
-
pick,
|
|
178
129
|
positive,
|
|
179
130
|
precision,
|
|
180
|
-
record,
|
|
181
|
-
refine3 as refine,
|
|
182
|
-
regexp,
|
|
183
|
-
set,
|
|
184
|
-
size,
|
|
185
|
-
string5 as string,
|
|
186
|
-
struct,
|
|
187
|
-
trimmed,
|
|
188
|
-
tuple,
|
|
189
|
-
type,
|
|
190
|
-
union2 as union,
|
|
191
131
|
unique,
|
|
192
|
-
unknown,
|
|
193
|
-
uppercase,
|
|
194
132
|
uuid
|
|
195
133
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/validate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@awsless/big-float": "^0.0.
|
|
27
|
+
"@awsless/big-float": "^0.0.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@awsless/big-float": "^0.0.
|
|
30
|
+
"@awsless/big-float": "^0.0.4"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"
|
|
33
|
+
"valibot": "^0.20.1"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "pnpm code test",
|