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