@awsless/validate 0.1.1 → 0.1.2
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 +74 -15
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +64 -6
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ __export(index_exports, {
|
|
|
29
29
|
minDuration: () => minDuration,
|
|
30
30
|
positive: () => positive,
|
|
31
31
|
precision: () => precision,
|
|
32
|
+
s3Event: () => s3Event,
|
|
32
33
|
snsTopic: () => snsTopic,
|
|
33
34
|
sqsQueue: () => sqsQueue,
|
|
34
35
|
unique: () => unique,
|
|
@@ -129,11 +130,7 @@ var import_valibot6 = require("valibot");
|
|
|
129
130
|
var snsTopic = (schema, message = "Invalid SNS Topic payload") => {
|
|
130
131
|
return (0, import_valibot6.union)(
|
|
131
132
|
[
|
|
132
|
-
|
|
133
|
-
schema,
|
|
134
|
-
(0, import_valibot6.transform)((v) => [v])
|
|
135
|
-
),
|
|
136
|
-
(0, import_valibot6.array)(schema),
|
|
133
|
+
// Prioritize the expected payload during production
|
|
137
134
|
(0, import_valibot6.pipe)(
|
|
138
135
|
(0, import_valibot6.object)({
|
|
139
136
|
Records: (0, import_valibot6.array)(
|
|
@@ -145,7 +142,13 @@ var snsTopic = (schema, message = "Invalid SNS Topic payload") => {
|
|
|
145
142
|
)
|
|
146
143
|
}),
|
|
147
144
|
(0, import_valibot6.transform)((v) => v.Records.map((r) => r.Sns.Message))
|
|
148
|
-
)
|
|
145
|
+
),
|
|
146
|
+
// These are allowed during testing
|
|
147
|
+
(0, import_valibot6.pipe)(
|
|
148
|
+
schema,
|
|
149
|
+
(0, import_valibot6.transform)((v) => [v])
|
|
150
|
+
),
|
|
151
|
+
(0, import_valibot6.array)(schema)
|
|
149
152
|
],
|
|
150
153
|
message
|
|
151
154
|
);
|
|
@@ -208,27 +211,82 @@ var dynamoDbStream = (table, message = "Invalid DynamoDB Stream payload") => {
|
|
|
208
211
|
);
|
|
209
212
|
};
|
|
210
213
|
|
|
214
|
+
// src/schema/aws/s3-event.ts
|
|
215
|
+
var import_valibot8 = require("valibot");
|
|
216
|
+
var s3Event = () => {
|
|
217
|
+
const schema = (0, import_valibot8.object)({
|
|
218
|
+
event: (0, import_valibot8.string)(),
|
|
219
|
+
bucket: (0, import_valibot8.string)(),
|
|
220
|
+
key: (0, import_valibot8.string)(),
|
|
221
|
+
size: (0, import_valibot8.number)(),
|
|
222
|
+
eTag: (0, import_valibot8.string)(),
|
|
223
|
+
time: (0, import_valibot8.date)()
|
|
224
|
+
});
|
|
225
|
+
return (0, import_valibot8.union)(
|
|
226
|
+
[
|
|
227
|
+
// Prioritize the expected payload during production
|
|
228
|
+
(0, import_valibot8.pipe)(
|
|
229
|
+
(0, import_valibot8.object)({
|
|
230
|
+
Records: (0, import_valibot8.array)(
|
|
231
|
+
(0, import_valibot8.object)({
|
|
232
|
+
eventTime: (0, import_valibot8.pipe)((0, import_valibot8.string)(), (0, import_valibot8.toDate)()),
|
|
233
|
+
eventName: (0, import_valibot8.string)(),
|
|
234
|
+
s3: (0, import_valibot8.object)({
|
|
235
|
+
bucket: (0, import_valibot8.object)({
|
|
236
|
+
name: (0, import_valibot8.string)()
|
|
237
|
+
}),
|
|
238
|
+
object: (0, import_valibot8.object)({
|
|
239
|
+
key: (0, import_valibot8.string)(),
|
|
240
|
+
size: (0, import_valibot8.number)(),
|
|
241
|
+
eTag: (0, import_valibot8.string)()
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
)
|
|
246
|
+
}),
|
|
247
|
+
(0, import_valibot8.transform)((input) => {
|
|
248
|
+
return input.Records.map((record) => ({
|
|
249
|
+
event: record.eventName,
|
|
250
|
+
time: record.eventTime,
|
|
251
|
+
bucket: record.s3.bucket.name,
|
|
252
|
+
key: record.s3.object.key,
|
|
253
|
+
size: record.s3.object.size,
|
|
254
|
+
eTag: record.s3.object.eTag
|
|
255
|
+
}));
|
|
256
|
+
})
|
|
257
|
+
),
|
|
258
|
+
// These are allowed during testing
|
|
259
|
+
(0, import_valibot8.pipe)(
|
|
260
|
+
schema,
|
|
261
|
+
(0, import_valibot8.transform)((v) => [v])
|
|
262
|
+
),
|
|
263
|
+
(0, import_valibot8.array)(schema)
|
|
264
|
+
],
|
|
265
|
+
"Invalid S3 Event payload"
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
|
|
211
269
|
// src/validation/positive.ts
|
|
212
270
|
var import_big_float2 = require("@awsless/big-float");
|
|
213
|
-
var
|
|
271
|
+
var import_valibot9 = require("valibot");
|
|
214
272
|
function positive(message = "Invalid positive number") {
|
|
215
|
-
return (0,
|
|
273
|
+
return (0, import_valibot9.check)((input) => (0, import_big_float2.isPositive)(input), message);
|
|
216
274
|
}
|
|
217
275
|
|
|
218
276
|
// src/validation/precision.ts
|
|
219
277
|
var import_big_float3 = require("@awsless/big-float");
|
|
220
|
-
var
|
|
278
|
+
var import_valibot10 = require("valibot");
|
|
221
279
|
function precision(decimals, message = `Invalid ${decimals} precision number`) {
|
|
222
|
-
return (0,
|
|
280
|
+
return (0, import_valibot10.check)((input) => {
|
|
223
281
|
const big = (0, import_big_float3.parse)(input.toString());
|
|
224
282
|
return -big.exponent <= decimals;
|
|
225
283
|
}, message);
|
|
226
284
|
}
|
|
227
285
|
|
|
228
286
|
// src/validation/unique.ts
|
|
229
|
-
var
|
|
287
|
+
var import_valibot11 = require("valibot");
|
|
230
288
|
function unique(compare = (a, b) => a === b, message = "None unique array") {
|
|
231
|
-
return (0,
|
|
289
|
+
return (0, import_valibot11.check)((input) => {
|
|
232
290
|
for (const x in input) {
|
|
233
291
|
for (const y in input) {
|
|
234
292
|
if (x !== y && compare(input[x], input[y])) {
|
|
@@ -241,12 +299,12 @@ function unique(compare = (a, b) => a === b, message = "None unique array") {
|
|
|
241
299
|
}
|
|
242
300
|
|
|
243
301
|
// src/validation/duration.ts
|
|
244
|
-
var
|
|
302
|
+
var import_valibot12 = require("valibot");
|
|
245
303
|
function minDuration(min, message = "Invalid duration") {
|
|
246
|
-
return (0,
|
|
304
|
+
return (0, import_valibot12.check)((input) => input.value >= min.value, message);
|
|
247
305
|
}
|
|
248
306
|
function maxDuration(max, message = "Invalid duration") {
|
|
249
|
-
return (0,
|
|
307
|
+
return (0, import_valibot12.check)((input) => input.value <= max.value, message);
|
|
250
308
|
}
|
|
251
309
|
// Annotate the CommonJS export names for ESM import in node:
|
|
252
310
|
0 && (module.exports = {
|
|
@@ -258,6 +316,7 @@ function maxDuration(max, message = "Invalid duration") {
|
|
|
258
316
|
minDuration,
|
|
259
317
|
positive,
|
|
260
318
|
precision,
|
|
319
|
+
s3Event,
|
|
261
320
|
snsTopic,
|
|
262
321
|
sqsQueue,
|
|
263
322
|
unique,
|
package/dist/index.d.cts
CHANGED
|
@@ -73,6 +73,21 @@ type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
|
73
73
|
}, DynamoDBStreamOutputRecord<T>[], GenericIssue>;
|
|
74
74
|
declare const dynamoDbStream: <T extends AnyTable>(table: T, message?: ErrorMessage<GenericIssue>) => DynamoDBStreamSchema<T>;
|
|
75
75
|
|
|
76
|
+
type S3EventOutput = {
|
|
77
|
+
event: string;
|
|
78
|
+
time: Date;
|
|
79
|
+
bucket: string;
|
|
80
|
+
key: string;
|
|
81
|
+
size: number;
|
|
82
|
+
eTag: string;
|
|
83
|
+
};
|
|
84
|
+
type S3EventSchema = BaseSchema<S3EventOutput | S3EventOutput[] | {
|
|
85
|
+
Records: {
|
|
86
|
+
eventTime: string;
|
|
87
|
+
}[];
|
|
88
|
+
}, S3EventOutput[], GenericIssue>;
|
|
89
|
+
declare const s3Event: () => S3EventSchema;
|
|
90
|
+
|
|
76
91
|
declare function positive<T extends BigFloat | number>(message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
77
92
|
|
|
78
93
|
declare function precision<T extends BigFloat | number>(decimals: number, message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
@@ -82,4 +97,4 @@ declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number])
|
|
|
82
97
|
declare function minDuration(min: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
83
98
|
declare function maxDuration(max: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
84
99
|
|
|
85
|
-
export { type BigFloatSchema, type DurationSchema, type DynamoDBStreamSchema, type JsonSchema, type SnsTopicSchema, type SqsQueueSchema, type UuidSchema, bigfloat, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, snsTopic, sqsQueue, unique, uuid };
|
|
100
|
+
export { type BigFloatSchema, type DurationSchema, type DynamoDBStreamSchema, type JsonSchema, type S3EventSchema, type SnsTopicSchema, type SqsQueueSchema, type UuidSchema, bigfloat, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, s3Event, snsTopic, sqsQueue, unique, uuid };
|
package/dist/index.d.ts
CHANGED
|
@@ -73,6 +73,21 @@ type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
|
73
73
|
}, DynamoDBStreamOutputRecord<T>[], GenericIssue>;
|
|
74
74
|
declare const dynamoDbStream: <T extends AnyTable>(table: T, message?: ErrorMessage<GenericIssue>) => DynamoDBStreamSchema<T>;
|
|
75
75
|
|
|
76
|
+
type S3EventOutput = {
|
|
77
|
+
event: string;
|
|
78
|
+
time: Date;
|
|
79
|
+
bucket: string;
|
|
80
|
+
key: string;
|
|
81
|
+
size: number;
|
|
82
|
+
eTag: string;
|
|
83
|
+
};
|
|
84
|
+
type S3EventSchema = BaseSchema<S3EventOutput | S3EventOutput[] | {
|
|
85
|
+
Records: {
|
|
86
|
+
eventTime: string;
|
|
87
|
+
}[];
|
|
88
|
+
}, S3EventOutput[], GenericIssue>;
|
|
89
|
+
declare const s3Event: () => S3EventSchema;
|
|
90
|
+
|
|
76
91
|
declare function positive<T extends BigFloat | number>(message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
77
92
|
|
|
78
93
|
declare function precision<T extends BigFloat | number>(decimals: number, message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
@@ -82,4 +97,4 @@ declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number])
|
|
|
82
97
|
declare function minDuration(min: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
83
98
|
declare function maxDuration(max: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
84
99
|
|
|
85
|
-
export { type BigFloatSchema, type DurationSchema, type DynamoDBStreamSchema, type JsonSchema, type SnsTopicSchema, type SqsQueueSchema, type UuidSchema, bigfloat, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, snsTopic, sqsQueue, unique, uuid };
|
|
100
|
+
export { type BigFloatSchema, type DurationSchema, type DynamoDBStreamSchema, type JsonSchema, type S3EventSchema, type SnsTopicSchema, type SqsQueueSchema, type UuidSchema, bigfloat, duration, dynamoDbStream, json, maxDuration, minDuration, positive, precision, s3Event, snsTopic, sqsQueue, unique, uuid };
|
package/dist/index.js
CHANGED
|
@@ -114,11 +114,7 @@ import {
|
|
|
114
114
|
var snsTopic = (schema, message = "Invalid SNS Topic payload") => {
|
|
115
115
|
return union3(
|
|
116
116
|
[
|
|
117
|
-
|
|
118
|
-
schema,
|
|
119
|
-
transform3((v) => [v])
|
|
120
|
-
),
|
|
121
|
-
array2(schema),
|
|
117
|
+
// Prioritize the expected payload during production
|
|
122
118
|
pipe5(
|
|
123
119
|
object2({
|
|
124
120
|
Records: array2(
|
|
@@ -130,7 +126,13 @@ var snsTopic = (schema, message = "Invalid SNS Topic payload") => {
|
|
|
130
126
|
)
|
|
131
127
|
}),
|
|
132
128
|
transform3((v) => v.Records.map((r) => r.Sns.Message))
|
|
133
|
-
)
|
|
129
|
+
),
|
|
130
|
+
// These are allowed during testing
|
|
131
|
+
pipe5(
|
|
132
|
+
schema,
|
|
133
|
+
transform3((v) => [v])
|
|
134
|
+
),
|
|
135
|
+
array2(schema)
|
|
134
136
|
],
|
|
135
137
|
message
|
|
136
138
|
);
|
|
@@ -201,6 +203,61 @@ var dynamoDbStream = (table, message = "Invalid DynamoDB Stream payload") => {
|
|
|
201
203
|
);
|
|
202
204
|
};
|
|
203
205
|
|
|
206
|
+
// src/schema/aws/s3-event.ts
|
|
207
|
+
import { array as array4, date, number as number2, object as object4, pipe as pipe7, string as string4, toDate, transform as transform5, union as union4 } from "valibot";
|
|
208
|
+
var s3Event = () => {
|
|
209
|
+
const schema = object4({
|
|
210
|
+
event: string4(),
|
|
211
|
+
bucket: string4(),
|
|
212
|
+
key: string4(),
|
|
213
|
+
size: number2(),
|
|
214
|
+
eTag: string4(),
|
|
215
|
+
time: date()
|
|
216
|
+
});
|
|
217
|
+
return union4(
|
|
218
|
+
[
|
|
219
|
+
// Prioritize the expected payload during production
|
|
220
|
+
pipe7(
|
|
221
|
+
object4({
|
|
222
|
+
Records: array4(
|
|
223
|
+
object4({
|
|
224
|
+
eventTime: pipe7(string4(), toDate()),
|
|
225
|
+
eventName: string4(),
|
|
226
|
+
s3: object4({
|
|
227
|
+
bucket: object4({
|
|
228
|
+
name: string4()
|
|
229
|
+
}),
|
|
230
|
+
object: object4({
|
|
231
|
+
key: string4(),
|
|
232
|
+
size: number2(),
|
|
233
|
+
eTag: string4()
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
)
|
|
238
|
+
}),
|
|
239
|
+
transform5((input) => {
|
|
240
|
+
return input.Records.map((record) => ({
|
|
241
|
+
event: record.eventName,
|
|
242
|
+
time: record.eventTime,
|
|
243
|
+
bucket: record.s3.bucket.name,
|
|
244
|
+
key: record.s3.object.key,
|
|
245
|
+
size: record.s3.object.size,
|
|
246
|
+
eTag: record.s3.object.eTag
|
|
247
|
+
}));
|
|
248
|
+
})
|
|
249
|
+
),
|
|
250
|
+
// These are allowed during testing
|
|
251
|
+
pipe7(
|
|
252
|
+
schema,
|
|
253
|
+
transform5((v) => [v])
|
|
254
|
+
),
|
|
255
|
+
array4(schema)
|
|
256
|
+
],
|
|
257
|
+
"Invalid S3 Event payload"
|
|
258
|
+
);
|
|
259
|
+
};
|
|
260
|
+
|
|
204
261
|
// src/validation/positive.ts
|
|
205
262
|
import { isPositive } from "@awsless/big-float";
|
|
206
263
|
import { check } from "valibot";
|
|
@@ -250,6 +307,7 @@ export {
|
|
|
250
307
|
minDuration,
|
|
251
308
|
positive,
|
|
252
309
|
precision,
|
|
310
|
+
s3Event,
|
|
253
311
|
snsTopic,
|
|
254
312
|
sqsQueue,
|
|
255
313
|
unique,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/validate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@awsless/dynamodb": "^0.3.2",
|
|
28
27
|
"@awsless/big-float": "^0.1.5",
|
|
28
|
+
"@awsless/duration": "^0.0.4",
|
|
29
29
|
"@awsless/json": "^0.0.10",
|
|
30
|
-
"@awsless/
|
|
30
|
+
"@awsless/dynamodb": "^0.3.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@awsless/
|
|
33
|
+
"@awsless/duration": "^0.0.4",
|
|
34
34
|
"@awsless/dynamodb": "^0.3.2",
|
|
35
|
-
"@awsless/
|
|
36
|
-
"@awsless/
|
|
35
|
+
"@awsless/big-float": "^0.1.5",
|
|
36
|
+
"@awsless/json": "^0.0.10"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"valibot": "^1.2.0"
|