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