@awsless/validate 0.0.14 → 0.0.16
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 +72 -49
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +45 -23
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
24
|
bigfloat: () => bigfloat,
|
|
25
|
+
bigint: () => bigint2,
|
|
25
26
|
date: () => date,
|
|
26
27
|
duration: () => duration,
|
|
27
28
|
dynamoDbStream: () => dynamoDbStream,
|
|
@@ -79,19 +80,38 @@ function bigfloat(arg1, arg2) {
|
|
|
79
80
|
);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
// src/schema/
|
|
83
|
+
// src/schema/bigint.ts
|
|
83
84
|
var import_valibot3 = require("valibot");
|
|
84
|
-
function
|
|
85
|
+
function bigint2(arg1, arg2) {
|
|
85
86
|
const [error, pipe] = (0, import_valibot3.defaultArgs)(arg1, arg2);
|
|
86
87
|
return (0, import_valibot3.union)(
|
|
87
88
|
[
|
|
88
|
-
(0, import_valibot3.
|
|
89
|
+
(0, import_valibot3.bigint)(pipe),
|
|
89
90
|
(0, import_valibot3.transform)(
|
|
90
|
-
(0, import_valibot3.string)(),
|
|
91
|
+
(0, import_valibot3.string)([(0, import_valibot3.regex)(/^-?[0-9]+$/)]),
|
|
92
|
+
(input) => {
|
|
93
|
+
return BigInt(input);
|
|
94
|
+
},
|
|
95
|
+
(0, import_valibot3.bigint)(pipe)
|
|
96
|
+
)
|
|
97
|
+
],
|
|
98
|
+
error ?? "Invalid BigInt"
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/schema/date.ts
|
|
103
|
+
var import_valibot4 = require("valibot");
|
|
104
|
+
function date(arg1, arg2) {
|
|
105
|
+
const [error, pipe] = (0, import_valibot4.defaultArgs)(arg1, arg2);
|
|
106
|
+
return (0, import_valibot4.union)(
|
|
107
|
+
[
|
|
108
|
+
(0, import_valibot4.date)(pipe),
|
|
109
|
+
(0, import_valibot4.transform)(
|
|
110
|
+
(0, import_valibot4.string)(),
|
|
91
111
|
(input) => {
|
|
92
112
|
return new Date(input);
|
|
93
113
|
},
|
|
94
|
-
(0,
|
|
114
|
+
(0, import_valibot4.date)(pipe)
|
|
95
115
|
)
|
|
96
116
|
],
|
|
97
117
|
error ?? "Invalid date"
|
|
@@ -99,19 +119,19 @@ function date(arg1, arg2) {
|
|
|
99
119
|
}
|
|
100
120
|
|
|
101
121
|
// src/schema/uuid.ts
|
|
102
|
-
var
|
|
122
|
+
var import_valibot5 = require("valibot");
|
|
103
123
|
var uuid = (error) => {
|
|
104
|
-
return (0,
|
|
124
|
+
return (0, import_valibot5.transform)((0, import_valibot5.string)(error ?? "Invalid UUID", [(0, import_valibot5.uuid)()]), (v) => v);
|
|
105
125
|
};
|
|
106
126
|
|
|
107
127
|
// src/schema/duration.ts
|
|
108
|
-
var
|
|
128
|
+
var import_valibot6 = require("valibot");
|
|
109
129
|
var import_duration = require("@awsless/duration");
|
|
110
130
|
function duration(arg1, arg2) {
|
|
111
|
-
const [msg, pipe] = (0,
|
|
131
|
+
const [msg, pipe] = (0, import_valibot6.defaultArgs)(arg1, arg2);
|
|
112
132
|
const error = msg ?? "Invalid duration";
|
|
113
|
-
return (0,
|
|
114
|
-
(0,
|
|
133
|
+
return (0, import_valibot6.transform)(
|
|
134
|
+
(0, import_valibot6.string)(error, [(0, import_valibot6.regex)(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/, error)]),
|
|
115
135
|
(value) => {
|
|
116
136
|
return (0, import_duration.parse)(value);
|
|
117
137
|
},
|
|
@@ -120,17 +140,17 @@ function duration(arg1, arg2) {
|
|
|
120
140
|
}
|
|
121
141
|
|
|
122
142
|
// src/schema/aws/sqs-queue.ts
|
|
123
|
-
var
|
|
143
|
+
var import_valibot7 = require("valibot");
|
|
124
144
|
var sqsQueue = (body) => {
|
|
125
|
-
const schema = body ?? (0,
|
|
126
|
-
return (0,
|
|
145
|
+
const schema = body ?? (0, import_valibot7.unknown)();
|
|
146
|
+
return (0, import_valibot7.union)(
|
|
127
147
|
[
|
|
128
|
-
(0,
|
|
129
|
-
(0,
|
|
130
|
-
(0,
|
|
131
|
-
(0,
|
|
132
|
-
Records: (0,
|
|
133
|
-
(0,
|
|
148
|
+
(0, import_valibot7.transform)(schema, (input) => [input]),
|
|
149
|
+
(0, import_valibot7.array)(schema),
|
|
150
|
+
(0, import_valibot7.transform)(
|
|
151
|
+
(0, import_valibot7.object)({
|
|
152
|
+
Records: (0, import_valibot7.array)(
|
|
153
|
+
(0, import_valibot7.object)({
|
|
134
154
|
body: json(schema)
|
|
135
155
|
})
|
|
136
156
|
)
|
|
@@ -145,18 +165,18 @@ var sqsQueue = (body) => {
|
|
|
145
165
|
};
|
|
146
166
|
|
|
147
167
|
// src/schema/aws/sns-topic.ts
|
|
148
|
-
var
|
|
168
|
+
var import_valibot8 = require("valibot");
|
|
149
169
|
var snsTopic = (body) => {
|
|
150
|
-
const schema = body ?? (0,
|
|
151
|
-
return (0,
|
|
170
|
+
const schema = body ?? (0, import_valibot8.unknown)();
|
|
171
|
+
return (0, import_valibot8.union)(
|
|
152
172
|
[
|
|
153
|
-
(0,
|
|
154
|
-
(0,
|
|
155
|
-
(0,
|
|
156
|
-
(0,
|
|
157
|
-
Records: (0,
|
|
158
|
-
(0,
|
|
159
|
-
Sns: (0,
|
|
173
|
+
(0, import_valibot8.transform)(schema, (input) => [input]),
|
|
174
|
+
(0, import_valibot8.array)(schema),
|
|
175
|
+
(0, import_valibot8.transform)(
|
|
176
|
+
(0, import_valibot8.object)({
|
|
177
|
+
Records: (0, import_valibot8.array)(
|
|
178
|
+
(0, import_valibot8.object)({
|
|
179
|
+
Sns: (0, import_valibot8.object)({
|
|
160
180
|
Message: json(schema)
|
|
161
181
|
})
|
|
162
182
|
})
|
|
@@ -172,19 +192,21 @@ var snsTopic = (body) => {
|
|
|
172
192
|
};
|
|
173
193
|
|
|
174
194
|
// src/schema/aws/dynamodb-stream.ts
|
|
175
|
-
var
|
|
195
|
+
var import_valibot9 = require("valibot");
|
|
176
196
|
var dynamoDbStream = (table) => {
|
|
177
|
-
const marshall = () => (0,
|
|
178
|
-
return (0,
|
|
179
|
-
(0,
|
|
197
|
+
const marshall = () => (0, import_valibot9.transform)((0, import_valibot9.unknown)(), (value) => table.unmarshall(value));
|
|
198
|
+
return (0, import_valibot9.transform)(
|
|
199
|
+
(0, import_valibot9.object)(
|
|
180
200
|
{
|
|
181
|
-
Records: (0,
|
|
182
|
-
(0,
|
|
183
|
-
|
|
184
|
-
|
|
201
|
+
Records: (0, import_valibot9.array)(
|
|
202
|
+
(0, import_valibot9.object)({
|
|
203
|
+
// For some reason picklist fails to build.
|
|
204
|
+
// eventName: picklist(['MODIFY', 'INSERT', 'REMOVE']),
|
|
205
|
+
eventName: (0, import_valibot9.union)([(0, import_valibot9.literal)("MODIFY"), (0, import_valibot9.literal)("INSERT"), (0, import_valibot9.literal)("REMOVE")]),
|
|
206
|
+
dynamodb: (0, import_valibot9.object)({
|
|
185
207
|
Keys: marshall(),
|
|
186
|
-
OldImage: (0,
|
|
187
|
-
NewImage: (0,
|
|
208
|
+
OldImage: (0, import_valibot9.optional)(marshall()),
|
|
209
|
+
NewImage: (0, import_valibot9.optional)(marshall())
|
|
188
210
|
})
|
|
189
211
|
})
|
|
190
212
|
)
|
|
@@ -207,25 +229,25 @@ var dynamoDbStream = (table) => {
|
|
|
207
229
|
|
|
208
230
|
// src/validation/positive.ts
|
|
209
231
|
var import_big_float2 = require("@awsless/big-float");
|
|
210
|
-
var
|
|
232
|
+
var import_valibot10 = require("valibot");
|
|
211
233
|
function positive(error) {
|
|
212
|
-
return (0,
|
|
234
|
+
return (0, import_valibot10.custom)((input) => (0, import_big_float2.gt)(input, import_big_float2.ZERO), error ?? "Invalid positive number");
|
|
213
235
|
}
|
|
214
236
|
|
|
215
237
|
// src/validation/precision.ts
|
|
216
238
|
var import_big_float3 = require("@awsless/big-float");
|
|
217
|
-
var
|
|
239
|
+
var import_valibot11 = require("valibot");
|
|
218
240
|
function precision(decimals, error) {
|
|
219
|
-
return (0,
|
|
241
|
+
return (0, import_valibot11.custom)((input) => {
|
|
220
242
|
const big = new import_big_float3.BigFloat(input.toString());
|
|
221
243
|
return -big.exponent <= decimals;
|
|
222
244
|
}, error ?? `Invalid ${decimals} precision number`);
|
|
223
245
|
}
|
|
224
246
|
|
|
225
247
|
// src/validation/unique.ts
|
|
226
|
-
var
|
|
248
|
+
var import_valibot12 = require("valibot");
|
|
227
249
|
function unique(compare = (a, b) => a === b, error) {
|
|
228
|
-
return (0,
|
|
250
|
+
return (0, import_valibot12.custom)((input) => {
|
|
229
251
|
for (const x in input) {
|
|
230
252
|
for (const y in input) {
|
|
231
253
|
if (x !== y && compare(input[x], input[y])) {
|
|
@@ -238,16 +260,17 @@ function unique(compare = (a, b) => a === b, error) {
|
|
|
238
260
|
}
|
|
239
261
|
|
|
240
262
|
// src/validation/duration.ts
|
|
241
|
-
var
|
|
263
|
+
var import_valibot13 = require("valibot");
|
|
242
264
|
function minDuration(min, error) {
|
|
243
|
-
return (0,
|
|
265
|
+
return (0, import_valibot13.custom)((input) => input.value >= min.value, error ?? "Invalid duration");
|
|
244
266
|
}
|
|
245
267
|
function maxDuration(max, error) {
|
|
246
|
-
return (0,
|
|
268
|
+
return (0, import_valibot13.custom)((input) => input.value <= max.value, error ?? "Invalid duration");
|
|
247
269
|
}
|
|
248
270
|
// Annotate the CommonJS export names for ESM import in node:
|
|
249
271
|
0 && (module.exports = {
|
|
250
272
|
bigfloat,
|
|
273
|
+
bigint,
|
|
251
274
|
date,
|
|
252
275
|
duration,
|
|
253
276
|
dynamoDbStream,
|
package/dist/index.d.cts
CHANGED
|
@@ -4,10 +4,10 @@ export * from 'valibot';
|
|
|
4
4
|
import { BigFloat } from '@awsless/big-float';
|
|
5
5
|
import { UUID } from 'crypto';
|
|
6
6
|
import { DurationFormat, Duration } from '@awsless/duration';
|
|
7
|
-
import {
|
|
7
|
+
import { AnyTable, PrimaryKey } from '@awsless/dynamodb';
|
|
8
8
|
|
|
9
9
|
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
10
|
-
declare const json: <T extends BaseSchema
|
|
10
|
+
declare const json: <T extends BaseSchema>(schema: T) => JsonSchema<T>;
|
|
11
11
|
|
|
12
12
|
type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
13
13
|
exponent: number;
|
|
@@ -16,6 +16,10 @@ type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
|
16
16
|
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
17
17
|
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
18
18
|
|
|
19
|
+
type BigIntSchema = BaseSchema<string | bigint, bigint>;
|
|
20
|
+
declare function bigint(pipe?: Pipe<bigint>): BigIntSchema;
|
|
21
|
+
declare function bigint(error?: ErrorMessage, pipe?: Pipe<bigint>): BigIntSchema;
|
|
22
|
+
|
|
19
23
|
type DateSchema = BaseSchema<string | Date, Date>;
|
|
20
24
|
declare function date(pipe?: Pipe<Date>): DateSchema;
|
|
21
25
|
declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
|
|
@@ -32,7 +36,7 @@ type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
32
36
|
body: string | Input<S>;
|
|
33
37
|
}[];
|
|
34
38
|
}, Output<S>[]>;
|
|
35
|
-
declare const sqsQueue: <S extends BaseSchema
|
|
39
|
+
declare const sqsQueue: <S extends BaseSchema = UnknownSchema<unknown>>(body?: S) => SqsQueueSchema<S>;
|
|
36
40
|
|
|
37
41
|
type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
|
|
38
42
|
Records: {
|
|
@@ -41,10 +45,10 @@ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
41
45
|
};
|
|
42
46
|
}[];
|
|
43
47
|
}, Output<S>[]>;
|
|
44
|
-
declare const snsTopic: <S extends BaseSchema
|
|
48
|
+
declare const snsTopic: <S extends BaseSchema = UnknownSchema<unknown>>(body?: S) => SnsTopicSchema<S>;
|
|
45
49
|
|
|
46
50
|
type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
|
|
47
|
-
type DynamoDBStreamSchema<T extends
|
|
51
|
+
type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
48
52
|
Records: {
|
|
49
53
|
eventName: EventName;
|
|
50
54
|
dynamodb: {
|
|
@@ -59,7 +63,7 @@ type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseS
|
|
|
59
63
|
old?: T['schema']['OUTPUT'];
|
|
60
64
|
new?: T['schema']['OUTPUT'];
|
|
61
65
|
}[]>;
|
|
62
|
-
declare const dynamoDbStream: <T extends
|
|
66
|
+
declare const dynamoDbStream: <T extends AnyTable>(table: T) => DynamoDBStreamSchema<T>;
|
|
63
67
|
|
|
64
68
|
declare function positive<T extends BigFloat | number>(error?: ErrorMessage): valibot.CustomValidation<T>;
|
|
65
69
|
|
|
@@ -70,4 +74,4 @@ declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number])
|
|
|
70
74
|
declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
|
|
71
75
|
declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
|
|
72
76
|
|
|
73
|
-
export { BigFloatSchema, DateSchema, DurationSchema, DynamoDBStreamSchema, JsonSchema, SnsTopicSchema, SqsQueueSchema, UuidSchema, bigfloat, date, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, snsTopic, sqsQueue, unique, uuid };
|
|
77
|
+
export { type BigFloatSchema, type BigIntSchema, type DateSchema, type DurationSchema, type DynamoDBStreamSchema, type JsonSchema, type SnsTopicSchema, type SqsQueueSchema, type UuidSchema, bigfloat, bigint, date, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, snsTopic, sqsQueue, unique, uuid };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ export * from 'valibot';
|
|
|
4
4
|
import { BigFloat } from '@awsless/big-float';
|
|
5
5
|
import { UUID } from 'crypto';
|
|
6
6
|
import { DurationFormat, Duration } from '@awsless/duration';
|
|
7
|
-
import {
|
|
7
|
+
import { AnyTable, PrimaryKey } from '@awsless/dynamodb';
|
|
8
8
|
|
|
9
9
|
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
10
|
-
declare const json: <T extends BaseSchema
|
|
10
|
+
declare const json: <T extends BaseSchema>(schema: T) => JsonSchema<T>;
|
|
11
11
|
|
|
12
12
|
type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
13
13
|
exponent: number;
|
|
@@ -16,6 +16,10 @@ type BigFloatSchema = BaseSchema<string | number | BigFloat | {
|
|
|
16
16
|
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
17
17
|
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
18
18
|
|
|
19
|
+
type BigIntSchema = BaseSchema<string | bigint, bigint>;
|
|
20
|
+
declare function bigint(pipe?: Pipe<bigint>): BigIntSchema;
|
|
21
|
+
declare function bigint(error?: ErrorMessage, pipe?: Pipe<bigint>): BigIntSchema;
|
|
22
|
+
|
|
19
23
|
type DateSchema = BaseSchema<string | Date, Date>;
|
|
20
24
|
declare function date(pipe?: Pipe<Date>): DateSchema;
|
|
21
25
|
declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
|
|
@@ -32,7 +36,7 @@ type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
32
36
|
body: string | Input<S>;
|
|
33
37
|
}[];
|
|
34
38
|
}, Output<S>[]>;
|
|
35
|
-
declare const sqsQueue: <S extends BaseSchema
|
|
39
|
+
declare const sqsQueue: <S extends BaseSchema = UnknownSchema<unknown>>(body?: S) => SqsQueueSchema<S>;
|
|
36
40
|
|
|
37
41
|
type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
|
|
38
42
|
Records: {
|
|
@@ -41,10 +45,10 @@ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
41
45
|
};
|
|
42
46
|
}[];
|
|
43
47
|
}, Output<S>[]>;
|
|
44
|
-
declare const snsTopic: <S extends BaseSchema
|
|
48
|
+
declare const snsTopic: <S extends BaseSchema = UnknownSchema<unknown>>(body?: S) => SnsTopicSchema<S>;
|
|
45
49
|
|
|
46
50
|
type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
|
|
47
|
-
type DynamoDBStreamSchema<T extends
|
|
51
|
+
type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
48
52
|
Records: {
|
|
49
53
|
eventName: EventName;
|
|
50
54
|
dynamodb: {
|
|
@@ -59,7 +63,7 @@ type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseS
|
|
|
59
63
|
old?: T['schema']['OUTPUT'];
|
|
60
64
|
new?: T['schema']['OUTPUT'];
|
|
61
65
|
}[]>;
|
|
62
|
-
declare const dynamoDbStream: <T extends
|
|
66
|
+
declare const dynamoDbStream: <T extends AnyTable>(table: T) => DynamoDBStreamSchema<T>;
|
|
63
67
|
|
|
64
68
|
declare function positive<T extends BigFloat | number>(error?: ErrorMessage): valibot.CustomValidation<T>;
|
|
65
69
|
|
|
@@ -70,4 +74,4 @@ declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number])
|
|
|
70
74
|
declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
|
|
71
75
|
declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
|
|
72
76
|
|
|
73
|
-
export { BigFloatSchema, DateSchema, DurationSchema, DynamoDBStreamSchema, JsonSchema, SnsTopicSchema, SqsQueueSchema, UuidSchema, bigfloat, date, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, snsTopic, sqsQueue, unique, uuid };
|
|
77
|
+
export { type BigFloatSchema, type BigIntSchema, type DateSchema, type DurationSchema, type DynamoDBStreamSchema, type JsonSchema, type SnsTopicSchema, type SqsQueueSchema, type UuidSchema, bigfloat, bigint, date, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, snsTopic, sqsQueue, unique, uuid };
|
package/dist/index.js
CHANGED
|
@@ -52,39 +52,58 @@ function bigfloat(arg1, arg2) {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// src/schema/
|
|
56
|
-
import {
|
|
57
|
-
function
|
|
55
|
+
// src/schema/bigint.ts
|
|
56
|
+
import { bigint as base, defaultArgs as defaultArgs2, regex, string as string3, transform as transform3, union as union2 } from "valibot";
|
|
57
|
+
function bigint2(arg1, arg2) {
|
|
58
58
|
const [error, pipe] = defaultArgs2(arg1, arg2);
|
|
59
59
|
return union2(
|
|
60
60
|
[
|
|
61
61
|
base(pipe),
|
|
62
62
|
transform3(
|
|
63
|
-
string3(),
|
|
63
|
+
string3([regex(/^-?[0-9]+$/)]),
|
|
64
64
|
(input) => {
|
|
65
|
-
return
|
|
65
|
+
return BigInt(input);
|
|
66
66
|
},
|
|
67
67
|
base(pipe)
|
|
68
68
|
)
|
|
69
69
|
],
|
|
70
|
+
error ?? "Invalid BigInt"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/schema/date.ts
|
|
75
|
+
import { defaultArgs as defaultArgs3, date as base2, string as string4, union as union3, transform as transform4 } from "valibot";
|
|
76
|
+
function date(arg1, arg2) {
|
|
77
|
+
const [error, pipe] = defaultArgs3(arg1, arg2);
|
|
78
|
+
return union3(
|
|
79
|
+
[
|
|
80
|
+
base2(pipe),
|
|
81
|
+
transform4(
|
|
82
|
+
string4(),
|
|
83
|
+
(input) => {
|
|
84
|
+
return new Date(input);
|
|
85
|
+
},
|
|
86
|
+
base2(pipe)
|
|
87
|
+
)
|
|
88
|
+
],
|
|
70
89
|
error ?? "Invalid date"
|
|
71
90
|
);
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
// src/schema/uuid.ts
|
|
75
|
-
import { string as
|
|
94
|
+
import { string as string5, uuid as base3, transform as transform5 } from "valibot";
|
|
76
95
|
var uuid = (error) => {
|
|
77
|
-
return
|
|
96
|
+
return transform5(string5(error ?? "Invalid UUID", [base3()]), (v) => v);
|
|
78
97
|
};
|
|
79
98
|
|
|
80
99
|
// src/schema/duration.ts
|
|
81
|
-
import { defaultArgs as
|
|
100
|
+
import { defaultArgs as defaultArgs4, regex as regex2, string as string6, transform as transform6 } from "valibot";
|
|
82
101
|
import { parse } from "@awsless/duration";
|
|
83
102
|
function duration(arg1, arg2) {
|
|
84
|
-
const [msg, pipe] =
|
|
103
|
+
const [msg, pipe] = defaultArgs4(arg1, arg2);
|
|
85
104
|
const error = msg ?? "Invalid duration";
|
|
86
|
-
return
|
|
87
|
-
|
|
105
|
+
return transform6(
|
|
106
|
+
string6(error, [regex2(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/, error)]),
|
|
88
107
|
(value) => {
|
|
89
108
|
return parse(value);
|
|
90
109
|
},
|
|
@@ -93,14 +112,14 @@ function duration(arg1, arg2) {
|
|
|
93
112
|
}
|
|
94
113
|
|
|
95
114
|
// src/schema/aws/sqs-queue.ts
|
|
96
|
-
import { array, object as object2, transform as
|
|
115
|
+
import { array, object as object2, transform as transform7, union as union4, unknown } from "valibot";
|
|
97
116
|
var sqsQueue = (body) => {
|
|
98
117
|
const schema = body ?? unknown();
|
|
99
|
-
return
|
|
118
|
+
return union4(
|
|
100
119
|
[
|
|
101
|
-
|
|
120
|
+
transform7(schema, (input) => [input]),
|
|
102
121
|
array(schema),
|
|
103
|
-
|
|
122
|
+
transform7(
|
|
104
123
|
object2({
|
|
105
124
|
Records: array(
|
|
106
125
|
object2({
|
|
@@ -118,14 +137,14 @@ var sqsQueue = (body) => {
|
|
|
118
137
|
};
|
|
119
138
|
|
|
120
139
|
// src/schema/aws/sns-topic.ts
|
|
121
|
-
import { array as array2, object as object3, transform as
|
|
140
|
+
import { array as array2, object as object3, transform as transform8, union as union5, unknown as unknown2 } from "valibot";
|
|
122
141
|
var snsTopic = (body) => {
|
|
123
142
|
const schema = body ?? unknown2();
|
|
124
|
-
return
|
|
143
|
+
return union5(
|
|
125
144
|
[
|
|
126
|
-
|
|
145
|
+
transform8(schema, (input) => [input]),
|
|
127
146
|
array2(schema),
|
|
128
|
-
|
|
147
|
+
transform8(
|
|
129
148
|
object3({
|
|
130
149
|
Records: array2(
|
|
131
150
|
object3({
|
|
@@ -145,15 +164,17 @@ var snsTopic = (body) => {
|
|
|
145
164
|
};
|
|
146
165
|
|
|
147
166
|
// src/schema/aws/dynamodb-stream.ts
|
|
148
|
-
import { array as array3, object as object4, optional, transform as
|
|
167
|
+
import { array as array3, literal, object as object4, optional, transform as transform9, union as union6, unknown as unknown3 } from "valibot";
|
|
149
168
|
var dynamoDbStream = (table) => {
|
|
150
|
-
const marshall = () =>
|
|
151
|
-
return
|
|
169
|
+
const marshall = () => transform9(unknown3(), (value) => table.unmarshall(value));
|
|
170
|
+
return transform9(
|
|
152
171
|
object4(
|
|
153
172
|
{
|
|
154
173
|
Records: array3(
|
|
155
174
|
object4({
|
|
156
|
-
|
|
175
|
+
// For some reason picklist fails to build.
|
|
176
|
+
// eventName: picklist(['MODIFY', 'INSERT', 'REMOVE']),
|
|
177
|
+
eventName: union6([literal("MODIFY"), literal("INSERT"), literal("REMOVE")]),
|
|
157
178
|
dynamodb: object4({
|
|
158
179
|
Keys: marshall(),
|
|
159
180
|
OldImage: optional(marshall()),
|
|
@@ -220,6 +241,7 @@ function maxDuration(max, error) {
|
|
|
220
241
|
}
|
|
221
242
|
export {
|
|
222
243
|
bigfloat,
|
|
244
|
+
bigint2 as bigint,
|
|
223
245
|
date,
|
|
224
246
|
duration,
|
|
225
247
|
dynamoDbStream,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/validate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@awsless/big-float": "^0.0.4",
|
|
28
|
-
"@awsless/
|
|
29
|
-
"@awsless/
|
|
28
|
+
"@awsless/dynamodb": "^0.1.1",
|
|
29
|
+
"@awsless/duration": "^0.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@awsless/big-float": "^0.0.4",
|
|
33
|
-
"@awsless/
|
|
34
|
-
"@awsless/
|
|
33
|
+
"@awsless/dynamodb": "^0.1.1",
|
|
34
|
+
"@awsless/duration": "^0.0.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"valibot": "^0.30.0"
|