@awsless/validate 0.0.22 → 0.0.23
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 +106 -143
- package/dist/index.d.cts +60 -61
- package/dist/index.d.ts +60 -61
- package/dist/index.js +117 -141
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -22,8 +22,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
bigfloat: () => bigfloat,
|
|
25
|
-
bigint: () => bigint2,
|
|
26
|
-
date: () => date,
|
|
27
25
|
duration: () => duration,
|
|
28
26
|
dynamoDbStream: () => dynamoDbStream,
|
|
29
27
|
json: () => json,
|
|
@@ -42,16 +40,21 @@ __reExport(index_exports, require("valibot"), module.exports);
|
|
|
42
40
|
// src/schema/json.ts
|
|
43
41
|
var import_json = require("@awsless/json");
|
|
44
42
|
var import_valibot = require("valibot");
|
|
45
|
-
var json = (schema) => {
|
|
46
|
-
return (0, import_valibot.
|
|
47
|
-
(0, import_valibot.string)(),
|
|
48
|
-
(
|
|
43
|
+
var json = (schema, message = "Invalid JSON") => {
|
|
44
|
+
return (0, import_valibot.pipe)(
|
|
45
|
+
(0, import_valibot.string)(message),
|
|
46
|
+
(0, import_valibot.rawTransform)((ctx) => {
|
|
47
|
+
let result;
|
|
49
48
|
try {
|
|
50
|
-
|
|
51
|
-
} catch (
|
|
52
|
-
|
|
49
|
+
result = (0, import_json.parse)(ctx.dataset.value);
|
|
50
|
+
} catch (_error) {
|
|
51
|
+
ctx.addIssue({
|
|
52
|
+
message
|
|
53
|
+
});
|
|
54
|
+
return ctx.NEVER;
|
|
53
55
|
}
|
|
54
|
-
|
|
56
|
+
return result;
|
|
57
|
+
}),
|
|
55
58
|
schema
|
|
56
59
|
);
|
|
57
60
|
};
|
|
@@ -59,160 +62,125 @@ var json = (schema) => {
|
|
|
59
62
|
// src/schema/bigfloat.ts
|
|
60
63
|
var import_big_float = require("@awsless/big-float");
|
|
61
64
|
var import_valibot2 = require("valibot");
|
|
62
|
-
|
|
63
|
-
function bigfloat(arg1, arg2) {
|
|
64
|
-
const [msg, pipe] = (0, import_valibot2.defaultArgs)(arg1, arg2);
|
|
65
|
-
const error = msg ?? "Invalid bigfloat";
|
|
65
|
+
function bigfloat(message = "Invalid bigfloat") {
|
|
66
66
|
return (0, import_valibot2.union)(
|
|
67
67
|
[
|
|
68
|
-
(0, import_valibot2.instance)(import_big_float.BigFloat
|
|
69
|
-
(0, import_valibot2.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(0, import_valibot2.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/schema/bigint.ts
|
|
85
|
-
var import_valibot3 = require("valibot");
|
|
86
|
-
function bigint2(arg1, arg2) {
|
|
87
|
-
const [error, pipe] = (0, import_valibot3.defaultArgs)(arg1, arg2);
|
|
88
|
-
return (0, import_valibot3.union)(
|
|
89
|
-
[
|
|
90
|
-
(0, import_valibot3.bigint)(pipe),
|
|
91
|
-
(0, import_valibot3.transform)(
|
|
92
|
-
(0, import_valibot3.string)([(0, import_valibot3.regex)(/^-?[0-9]+$/)]),
|
|
93
|
-
(input) => {
|
|
94
|
-
return BigInt(input);
|
|
95
|
-
},
|
|
96
|
-
(0, import_valibot3.bigint)(pipe)
|
|
97
|
-
)
|
|
98
|
-
],
|
|
99
|
-
error ?? "Invalid BigInt"
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/schema/date.ts
|
|
104
|
-
var import_valibot4 = require("valibot");
|
|
105
|
-
function date(arg1, arg2) {
|
|
106
|
-
const [error, pipe] = (0, import_valibot4.defaultArgs)(arg1, arg2);
|
|
107
|
-
return (0, import_valibot4.union)(
|
|
108
|
-
[
|
|
109
|
-
(0, import_valibot4.date)(pipe),
|
|
110
|
-
(0, import_valibot4.transform)(
|
|
111
|
-
(0, import_valibot4.string)(),
|
|
112
|
-
(input) => {
|
|
113
|
-
return new Date(input);
|
|
114
|
-
},
|
|
115
|
-
(0, import_valibot4.date)(pipe)
|
|
68
|
+
(0, import_valibot2.instance)(import_big_float.BigFloat),
|
|
69
|
+
(0, import_valibot2.pipe)(
|
|
70
|
+
(0, import_valibot2.string)(),
|
|
71
|
+
(0, import_valibot2.decimal)(),
|
|
72
|
+
(0, import_valibot2.transform)((v) => (0, import_big_float.parse)(v))
|
|
73
|
+
),
|
|
74
|
+
(0, import_valibot2.pipe)(
|
|
75
|
+
(0, import_valibot2.bigint)(),
|
|
76
|
+
(0, import_valibot2.transform)((v) => (0, import_big_float.parse)(v))
|
|
77
|
+
),
|
|
78
|
+
(0, import_valibot2.pipe)(
|
|
79
|
+
(0, import_valibot2.number)(),
|
|
80
|
+
(0, import_valibot2.transform)((v) => (0, import_big_float.parse)(v))
|
|
116
81
|
)
|
|
117
82
|
],
|
|
118
|
-
|
|
83
|
+
message
|
|
119
84
|
);
|
|
120
85
|
}
|
|
121
86
|
|
|
122
87
|
// src/schema/uuid.ts
|
|
123
|
-
var
|
|
124
|
-
var uuid = (
|
|
125
|
-
return (0,
|
|
88
|
+
var import_valibot3 = require("valibot");
|
|
89
|
+
var uuid = (message = "Invalid UUID") => {
|
|
90
|
+
return (0, import_valibot3.pipe)((0, import_valibot3.string)(message), (0, import_valibot3.uuid)(message));
|
|
126
91
|
};
|
|
127
92
|
|
|
128
93
|
// src/schema/duration.ts
|
|
129
94
|
var import_duration = require("@awsless/duration");
|
|
130
|
-
var
|
|
131
|
-
function duration(
|
|
132
|
-
|
|
133
|
-
const error = msg ?? "Invalid duration";
|
|
134
|
-
return (0, import_valibot6.instance)(import_duration.Duration, error, pipe);
|
|
95
|
+
var import_valibot4 = require("valibot");
|
|
96
|
+
function duration(message = "Invalid duration") {
|
|
97
|
+
return (0, import_valibot4.instance)(import_duration.Duration, message);
|
|
135
98
|
}
|
|
136
99
|
|
|
137
100
|
// src/schema/aws/sqs-queue.ts
|
|
138
|
-
var
|
|
139
|
-
var sqsQueue = (
|
|
140
|
-
|
|
141
|
-
return (0, import_valibot7.union)(
|
|
101
|
+
var import_valibot5 = require("valibot");
|
|
102
|
+
var sqsQueue = (schema, message = "Invalid SQS Queue payload") => {
|
|
103
|
+
return (0, import_valibot5.union)(
|
|
142
104
|
[
|
|
143
|
-
|
|
144
|
-
(0,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
(0, import_valibot7.object)({
|
|
105
|
+
// Prioritize the expected payload during production
|
|
106
|
+
(0, import_valibot5.pipe)(
|
|
107
|
+
(0, import_valibot5.object)({
|
|
108
|
+
Records: (0, import_valibot5.array)(
|
|
109
|
+
(0, import_valibot5.object)({
|
|
149
110
|
body: json(schema)
|
|
150
111
|
})
|
|
151
112
|
)
|
|
152
113
|
}),
|
|
153
|
-
(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
)
|
|
114
|
+
(0, import_valibot5.transform)((v) => v.Records.map((r) => r.body))
|
|
115
|
+
),
|
|
116
|
+
// These are allowed during testing
|
|
117
|
+
(0, import_valibot5.pipe)(
|
|
118
|
+
schema,
|
|
119
|
+
(0, import_valibot5.transform)((v) => [v])
|
|
120
|
+
),
|
|
121
|
+
(0, import_valibot5.array)(schema)
|
|
157
122
|
],
|
|
158
|
-
|
|
123
|
+
message
|
|
159
124
|
);
|
|
160
125
|
};
|
|
161
126
|
|
|
162
127
|
// src/schema/aws/sns-topic.ts
|
|
163
|
-
var
|
|
164
|
-
var snsTopic = (
|
|
165
|
-
|
|
166
|
-
return (0, import_valibot8.union)(
|
|
128
|
+
var import_valibot6 = require("valibot");
|
|
129
|
+
var snsTopic = (schema, message = "Invalid SNS Topic payload") => {
|
|
130
|
+
return (0, import_valibot6.union)(
|
|
167
131
|
[
|
|
168
|
-
(0,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
132
|
+
(0, import_valibot6.pipe)(
|
|
133
|
+
schema,
|
|
134
|
+
(0, import_valibot6.transform)((v) => [v])
|
|
135
|
+
),
|
|
136
|
+
(0, import_valibot6.array)(schema),
|
|
137
|
+
(0, import_valibot6.pipe)(
|
|
138
|
+
(0, import_valibot6.object)({
|
|
139
|
+
Records: (0, import_valibot6.array)(
|
|
140
|
+
(0, import_valibot6.object)({
|
|
141
|
+
Sns: (0, import_valibot6.object)({
|
|
175
142
|
Message: json(schema)
|
|
176
143
|
})
|
|
177
144
|
})
|
|
178
145
|
)
|
|
179
146
|
}),
|
|
180
|
-
(
|
|
181
|
-
return record.Sns.Message;
|
|
182
|
-
})
|
|
147
|
+
(0, import_valibot6.transform)((v) => v.Records.map((r) => r.Sns.Message))
|
|
183
148
|
)
|
|
184
149
|
],
|
|
185
|
-
|
|
150
|
+
message
|
|
186
151
|
);
|
|
187
152
|
};
|
|
188
153
|
|
|
189
154
|
// src/schema/aws/dynamodb-stream.ts
|
|
190
|
-
var
|
|
191
|
-
var dynamoDbStream = (table) => {
|
|
192
|
-
const unmarshall = () => (0,
|
|
193
|
-
|
|
194
|
-
(0,
|
|
155
|
+
var import_valibot7 = require("valibot");
|
|
156
|
+
var dynamoDbStream = (table, message = "Invalid DynamoDB Stream payload") => {
|
|
157
|
+
const unmarshall = () => (0, import_valibot7.pipe)(
|
|
158
|
+
(0, import_valibot7.unknown)(),
|
|
159
|
+
(0, import_valibot7.transform)((v) => table.unmarshall(v))
|
|
160
|
+
);
|
|
161
|
+
return (0, import_valibot7.pipe)(
|
|
162
|
+
(0, import_valibot7.object)(
|
|
195
163
|
{
|
|
196
|
-
Records: (0,
|
|
197
|
-
(0,
|
|
198
|
-
(0,
|
|
199
|
-
eventName: (0,
|
|
200
|
-
dynamodb: (0,
|
|
164
|
+
Records: (0, import_valibot7.array)(
|
|
165
|
+
(0, import_valibot7.variant)("eventName", [
|
|
166
|
+
(0, import_valibot7.object)({
|
|
167
|
+
eventName: (0, import_valibot7.literal)("MODIFY"),
|
|
168
|
+
dynamodb: (0, import_valibot7.object)({
|
|
201
169
|
Keys: unmarshall(),
|
|
202
170
|
OldImage: unmarshall(),
|
|
203
171
|
NewImage: unmarshall()
|
|
204
172
|
})
|
|
205
173
|
}),
|
|
206
|
-
(0,
|
|
207
|
-
eventName: (0,
|
|
208
|
-
dynamodb: (0,
|
|
174
|
+
(0, import_valibot7.object)({
|
|
175
|
+
eventName: (0, import_valibot7.literal)("INSERT"),
|
|
176
|
+
dynamodb: (0, import_valibot7.object)({
|
|
209
177
|
Keys: unmarshall(),
|
|
210
178
|
NewImage: unmarshall()
|
|
211
179
|
})
|
|
212
180
|
}),
|
|
213
|
-
(0,
|
|
214
|
-
eventName: (0,
|
|
215
|
-
dynamodb: (0,
|
|
181
|
+
(0, import_valibot7.object)({
|
|
182
|
+
eventName: (0, import_valibot7.literal)("REMOVE"),
|
|
183
|
+
dynamodb: (0, import_valibot7.object)({
|
|
216
184
|
Keys: unmarshall(),
|
|
217
185
|
OldImage: unmarshall()
|
|
218
186
|
})
|
|
@@ -220,9 +188,9 @@ var dynamoDbStream = (table) => {
|
|
|
220
188
|
])
|
|
221
189
|
)
|
|
222
190
|
},
|
|
223
|
-
|
|
191
|
+
message
|
|
224
192
|
),
|
|
225
|
-
(input) => {
|
|
193
|
+
(0, import_valibot7.transform)((input) => {
|
|
226
194
|
return input.Records.map((record) => {
|
|
227
195
|
const item = {
|
|
228
196
|
event: record.eventName.toLowerCase(),
|
|
@@ -236,34 +204,31 @@ var dynamoDbStream = (table) => {
|
|
|
236
204
|
}
|
|
237
205
|
return item;
|
|
238
206
|
});
|
|
239
|
-
}
|
|
207
|
+
})
|
|
240
208
|
);
|
|
241
209
|
};
|
|
242
210
|
|
|
243
211
|
// src/validation/positive.ts
|
|
244
212
|
var import_big_float2 = require("@awsless/big-float");
|
|
245
|
-
var
|
|
246
|
-
function positive(
|
|
247
|
-
return (0,
|
|
213
|
+
var import_valibot8 = require("valibot");
|
|
214
|
+
function positive(message = "Invalid positive number") {
|
|
215
|
+
return (0, import_valibot8.check)((input) => (0, import_big_float2.isPositive)(input), message);
|
|
248
216
|
}
|
|
249
217
|
|
|
250
218
|
// src/validation/precision.ts
|
|
251
219
|
var import_big_float3 = require("@awsless/big-float");
|
|
252
|
-
var
|
|
253
|
-
function precision(decimals,
|
|
254
|
-
return (0,
|
|
255
|
-
(input)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
},
|
|
259
|
-
error ?? `Invalid ${decimals} precision number`
|
|
260
|
-
);
|
|
220
|
+
var import_valibot9 = require("valibot");
|
|
221
|
+
function precision(decimals, message = `Invalid ${decimals} precision number`) {
|
|
222
|
+
return (0, import_valibot9.check)((input) => {
|
|
223
|
+
const big = (0, import_big_float3.parse)(input.toString());
|
|
224
|
+
return -big.exponent <= decimals;
|
|
225
|
+
}, message);
|
|
261
226
|
}
|
|
262
227
|
|
|
263
228
|
// src/validation/unique.ts
|
|
264
|
-
var
|
|
265
|
-
function unique(compare = (a, b) => a === b,
|
|
266
|
-
return (0,
|
|
229
|
+
var import_valibot10 = require("valibot");
|
|
230
|
+
function unique(compare = (a, b) => a === b, message = "None unique array") {
|
|
231
|
+
return (0, import_valibot10.check)((input) => {
|
|
267
232
|
for (const x in input) {
|
|
268
233
|
for (const y in input) {
|
|
269
234
|
if (x !== y && compare(input[x], input[y])) {
|
|
@@ -272,22 +237,20 @@ function unique(compare = (a, b) => a === b, error) {
|
|
|
272
237
|
}
|
|
273
238
|
}
|
|
274
239
|
return true;
|
|
275
|
-
},
|
|
240
|
+
}, message);
|
|
276
241
|
}
|
|
277
242
|
|
|
278
243
|
// src/validation/duration.ts
|
|
279
|
-
var
|
|
280
|
-
function minDuration(min,
|
|
281
|
-
return (0,
|
|
244
|
+
var import_valibot11 = require("valibot");
|
|
245
|
+
function minDuration(min, message = "Invalid duration") {
|
|
246
|
+
return (0, import_valibot11.check)((input) => input.value >= min.value, message);
|
|
282
247
|
}
|
|
283
|
-
function maxDuration(max,
|
|
284
|
-
return (0,
|
|
248
|
+
function maxDuration(max, message = "Invalid duration") {
|
|
249
|
+
return (0, import_valibot11.check)((input) => input.value <= max.value, message);
|
|
285
250
|
}
|
|
286
251
|
// Annotate the CommonJS export names for ESM import in node:
|
|
287
252
|
0 && (module.exports = {
|
|
288
253
|
bigfloat,
|
|
289
|
-
bigint,
|
|
290
|
-
date,
|
|
291
254
|
duration,
|
|
292
255
|
dynamoDbStream,
|
|
293
256
|
json,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,74 +1,69 @@
|
|
|
1
1
|
import * as valibot from 'valibot';
|
|
2
|
-
import { BaseSchema,
|
|
2
|
+
import { BaseSchema, BaseIssue, ErrorMessage, InferOutput, InstanceIssue, InferInput, CheckIssue } from 'valibot';
|
|
3
3
|
export * from 'valibot';
|
|
4
4
|
import { BigFloat } from '@awsless/big-float';
|
|
5
5
|
import { UUID } from 'crypto';
|
|
6
|
-
import { Duration
|
|
6
|
+
import { Duration } from '@awsless/duration';
|
|
7
7
|
import { AnyTable, PrimaryKey, Infer } from '@awsless/dynamodb';
|
|
8
8
|
|
|
9
|
-
type
|
|
10
|
-
|
|
9
|
+
type Schema$2 = BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
10
|
+
type JsonIssue = BaseIssue<unknown>;
|
|
11
|
+
type JsonSchema<T extends Schema$2> = BaseSchema<string, InferOutput<T>, JsonIssue>;
|
|
12
|
+
declare const json: <T extends Schema$2>(schema: T, message?: ErrorMessage<JsonIssue>) => JsonSchema<T>;
|
|
11
13
|
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, BigFloat>;
|
|
16
|
-
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
17
|
-
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
14
|
+
type BigFloatIssue = BaseIssue<unknown>;
|
|
15
|
+
type BigFloatSchema = BaseSchema<BigFloat | string | bigint | number, BigFloat, BigFloatIssue>;
|
|
16
|
+
declare function bigfloat(message?: ErrorMessage<BigFloatIssue>): BigFloatSchema;
|
|
18
17
|
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
declare
|
|
18
|
+
type UuidIssue = BaseIssue<unknown>;
|
|
19
|
+
type UuidSchema = BaseSchema<UUID, UUID, UuidIssue>;
|
|
20
|
+
declare const uuid: (message?: ErrorMessage<UuidIssue>) => UuidSchema;
|
|
22
21
|
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
declare function
|
|
22
|
+
type DurationIssue = InstanceIssue;
|
|
23
|
+
type DurationSchema = BaseSchema<Duration, Duration, DurationIssue>;
|
|
24
|
+
declare function duration(message?: ErrorMessage<DurationIssue>): DurationSchema;
|
|
26
25
|
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type DurationSchema = BaseSchema<DurationFormat | Duration, Duration>;
|
|
31
|
-
declare function duration(pipe?: Pipe<Duration>): DurationSchema;
|
|
32
|
-
declare function duration(error?: ErrorMessage, pipe?: Pipe<Duration>): DurationSchema;
|
|
33
|
-
|
|
34
|
-
type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
|
|
26
|
+
type Schema$1 = BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
27
|
+
type SqsQueueIssue = BaseIssue<unknown>;
|
|
28
|
+
type SqsQueueSchema<S extends Schema$1> = BaseSchema<InferInput<S> | InferInput<S>[] | {
|
|
35
29
|
Records: {
|
|
36
|
-
body: string |
|
|
30
|
+
body: string | InferInput<S>;
|
|
37
31
|
}[];
|
|
38
|
-
},
|
|
39
|
-
declare const sqsQueue: <S extends
|
|
32
|
+
}, InferOutput<S>[], SqsQueueIssue>;
|
|
33
|
+
declare const sqsQueue: <S extends Schema$1>(schema: S, message?: ErrorMessage<SqsQueueIssue>) => SqsQueueSchema<S>;
|
|
40
34
|
|
|
41
|
-
type
|
|
35
|
+
type Schema = BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
36
|
+
type SnsTopicIssue = BaseIssue<unknown>;
|
|
37
|
+
type SnsTopicSchema<S extends Schema> = BaseSchema<InferInput<S> | InferInput<S>[] | {
|
|
42
38
|
Records: {
|
|
43
39
|
Sns: {
|
|
44
|
-
Message: string |
|
|
40
|
+
Message: string | InferInput<S>;
|
|
45
41
|
};
|
|
46
42
|
}[];
|
|
47
|
-
},
|
|
48
|
-
declare const snsTopic: <S extends
|
|
43
|
+
}, InferOutput<S>[], SnsTopicIssue>;
|
|
44
|
+
declare const snsTopic: <S extends Schema>(schema: S, message?: ErrorMessage<SnsTopicIssue>) => SnsTopicSchema<S>;
|
|
49
45
|
|
|
50
|
-
type
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}, Array<{
|
|
46
|
+
type DynamoDBStreamInputRecord = {
|
|
47
|
+
eventName: 'MODIFY';
|
|
48
|
+
dynamodb: {
|
|
49
|
+
Keys: unknown;
|
|
50
|
+
OldImage: unknown;
|
|
51
|
+
NewImage: unknown;
|
|
52
|
+
};
|
|
53
|
+
} | {
|
|
54
|
+
eventName: 'INSERT';
|
|
55
|
+
dynamodb: {
|
|
56
|
+
Keys: unknown;
|
|
57
|
+
NewImage: unknown;
|
|
58
|
+
};
|
|
59
|
+
} | {
|
|
60
|
+
eventName: 'REMOVE';
|
|
61
|
+
dynamodb: {
|
|
62
|
+
Keys: unknown;
|
|
63
|
+
OldImage: unknown;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type DynamoDBStreamOutputRecord<T extends AnyTable> = {
|
|
72
67
|
event: 'modify';
|
|
73
68
|
keys: PrimaryKey<T>;
|
|
74
69
|
old: Infer<T>;
|
|
@@ -81,16 +76,20 @@ type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
|
81
76
|
event: 'remove';
|
|
82
77
|
keys: PrimaryKey<T>;
|
|
83
78
|
old: Infer<T>;
|
|
84
|
-
}
|
|
85
|
-
|
|
79
|
+
};
|
|
80
|
+
type DynamoDBStreamIssue = BaseIssue<unknown>;
|
|
81
|
+
type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
82
|
+
Records: DynamoDBStreamInputRecord[];
|
|
83
|
+
}, DynamoDBStreamOutputRecord<T>[], DynamoDBStreamIssue>;
|
|
84
|
+
declare const dynamoDbStream: <T extends AnyTable>(table: T, message?: ErrorMessage<DynamoDBStreamIssue>) => DynamoDBStreamSchema<T>;
|
|
86
85
|
|
|
87
|
-
declare function positive<T extends BigFloat | number>(
|
|
86
|
+
declare function positive<T extends BigFloat | number>(message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
88
87
|
|
|
89
|
-
declare function precision<T extends BigFloat | number>(decimals: number,
|
|
88
|
+
declare function precision<T extends BigFloat | number>(decimals: number, message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
90
89
|
|
|
91
|
-
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean,
|
|
90
|
+
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
92
91
|
|
|
93
|
-
declare function minDuration
|
|
94
|
-
declare function maxDuration
|
|
92
|
+
declare function minDuration(min: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
93
|
+
declare function maxDuration(max: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
95
94
|
|
|
96
|
-
export { type BigFloatSchema, type
|
|
95
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,74 +1,69 @@
|
|
|
1
1
|
import * as valibot from 'valibot';
|
|
2
|
-
import { BaseSchema,
|
|
2
|
+
import { BaseSchema, BaseIssue, ErrorMessage, InferOutput, InstanceIssue, InferInput, CheckIssue } from 'valibot';
|
|
3
3
|
export * from 'valibot';
|
|
4
4
|
import { BigFloat } from '@awsless/big-float';
|
|
5
5
|
import { UUID } from 'crypto';
|
|
6
|
-
import { Duration
|
|
6
|
+
import { Duration } from '@awsless/duration';
|
|
7
7
|
import { AnyTable, PrimaryKey, Infer } from '@awsless/dynamodb';
|
|
8
8
|
|
|
9
|
-
type
|
|
10
|
-
|
|
9
|
+
type Schema$2 = BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
10
|
+
type JsonIssue = BaseIssue<unknown>;
|
|
11
|
+
type JsonSchema<T extends Schema$2> = BaseSchema<string, InferOutput<T>, JsonIssue>;
|
|
12
|
+
declare const json: <T extends Schema$2>(schema: T, message?: ErrorMessage<JsonIssue>) => JsonSchema<T>;
|
|
11
13
|
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, BigFloat>;
|
|
16
|
-
declare function bigfloat(pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
17
|
-
declare function bigfloat(error?: ErrorMessage, pipe?: Pipe<BigFloat>): BigFloatSchema;
|
|
14
|
+
type BigFloatIssue = BaseIssue<unknown>;
|
|
15
|
+
type BigFloatSchema = BaseSchema<BigFloat | string | bigint | number, BigFloat, BigFloatIssue>;
|
|
16
|
+
declare function bigfloat(message?: ErrorMessage<BigFloatIssue>): BigFloatSchema;
|
|
18
17
|
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
declare
|
|
18
|
+
type UuidIssue = BaseIssue<unknown>;
|
|
19
|
+
type UuidSchema = BaseSchema<UUID, UUID, UuidIssue>;
|
|
20
|
+
declare const uuid: (message?: ErrorMessage<UuidIssue>) => UuidSchema;
|
|
22
21
|
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
declare function
|
|
22
|
+
type DurationIssue = InstanceIssue;
|
|
23
|
+
type DurationSchema = BaseSchema<Duration, Duration, DurationIssue>;
|
|
24
|
+
declare function duration(message?: ErrorMessage<DurationIssue>): DurationSchema;
|
|
26
25
|
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type DurationSchema = BaseSchema<DurationFormat | Duration, Duration>;
|
|
31
|
-
declare function duration(pipe?: Pipe<Duration>): DurationSchema;
|
|
32
|
-
declare function duration(error?: ErrorMessage, pipe?: Pipe<Duration>): DurationSchema;
|
|
33
|
-
|
|
34
|
-
type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
|
|
26
|
+
type Schema$1 = BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
27
|
+
type SqsQueueIssue = BaseIssue<unknown>;
|
|
28
|
+
type SqsQueueSchema<S extends Schema$1> = BaseSchema<InferInput<S> | InferInput<S>[] | {
|
|
35
29
|
Records: {
|
|
36
|
-
body: string |
|
|
30
|
+
body: string | InferInput<S>;
|
|
37
31
|
}[];
|
|
38
|
-
},
|
|
39
|
-
declare const sqsQueue: <S extends
|
|
32
|
+
}, InferOutput<S>[], SqsQueueIssue>;
|
|
33
|
+
declare const sqsQueue: <S extends Schema$1>(schema: S, message?: ErrorMessage<SqsQueueIssue>) => SqsQueueSchema<S>;
|
|
40
34
|
|
|
41
|
-
type
|
|
35
|
+
type Schema = BaseSchema<unknown, unknown, BaseIssue<unknown>>;
|
|
36
|
+
type SnsTopicIssue = BaseIssue<unknown>;
|
|
37
|
+
type SnsTopicSchema<S extends Schema> = BaseSchema<InferInput<S> | InferInput<S>[] | {
|
|
42
38
|
Records: {
|
|
43
39
|
Sns: {
|
|
44
|
-
Message: string |
|
|
40
|
+
Message: string | InferInput<S>;
|
|
45
41
|
};
|
|
46
42
|
}[];
|
|
47
|
-
},
|
|
48
|
-
declare const snsTopic: <S extends
|
|
43
|
+
}, InferOutput<S>[], SnsTopicIssue>;
|
|
44
|
+
declare const snsTopic: <S extends Schema>(schema: S, message?: ErrorMessage<SnsTopicIssue>) => SnsTopicSchema<S>;
|
|
49
45
|
|
|
50
|
-
type
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}, Array<{
|
|
46
|
+
type DynamoDBStreamInputRecord = {
|
|
47
|
+
eventName: 'MODIFY';
|
|
48
|
+
dynamodb: {
|
|
49
|
+
Keys: unknown;
|
|
50
|
+
OldImage: unknown;
|
|
51
|
+
NewImage: unknown;
|
|
52
|
+
};
|
|
53
|
+
} | {
|
|
54
|
+
eventName: 'INSERT';
|
|
55
|
+
dynamodb: {
|
|
56
|
+
Keys: unknown;
|
|
57
|
+
NewImage: unknown;
|
|
58
|
+
};
|
|
59
|
+
} | {
|
|
60
|
+
eventName: 'REMOVE';
|
|
61
|
+
dynamodb: {
|
|
62
|
+
Keys: unknown;
|
|
63
|
+
OldImage: unknown;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type DynamoDBStreamOutputRecord<T extends AnyTable> = {
|
|
72
67
|
event: 'modify';
|
|
73
68
|
keys: PrimaryKey<T>;
|
|
74
69
|
old: Infer<T>;
|
|
@@ -81,16 +76,20 @@ type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
|
81
76
|
event: 'remove';
|
|
82
77
|
keys: PrimaryKey<T>;
|
|
83
78
|
old: Infer<T>;
|
|
84
|
-
}
|
|
85
|
-
|
|
79
|
+
};
|
|
80
|
+
type DynamoDBStreamIssue = BaseIssue<unknown>;
|
|
81
|
+
type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
82
|
+
Records: DynamoDBStreamInputRecord[];
|
|
83
|
+
}, DynamoDBStreamOutputRecord<T>[], DynamoDBStreamIssue>;
|
|
84
|
+
declare const dynamoDbStream: <T extends AnyTable>(table: T, message?: ErrorMessage<DynamoDBStreamIssue>) => DynamoDBStreamSchema<T>;
|
|
86
85
|
|
|
87
|
-
declare function positive<T extends BigFloat | number>(
|
|
86
|
+
declare function positive<T extends BigFloat | number>(message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
88
87
|
|
|
89
|
-
declare function precision<T extends BigFloat | number>(decimals: number,
|
|
88
|
+
declare function precision<T extends BigFloat | number>(decimals: number, message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
90
89
|
|
|
91
|
-
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean,
|
|
90
|
+
declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, message?: ErrorMessage<CheckIssue<T>>): valibot.CheckAction<T, ErrorMessage<CheckIssue<T>>>;
|
|
92
91
|
|
|
93
|
-
declare function minDuration
|
|
94
|
-
declare function maxDuration
|
|
92
|
+
declare function minDuration(min: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
93
|
+
declare function maxDuration(max: Duration, message?: ErrorMessage<CheckIssue<Duration>>): valibot.CheckAction<Duration, ErrorMessage<CheckIssue<Duration>>>;
|
|
95
94
|
|
|
96
|
-
export { type BigFloatSchema, type
|
|
95
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -3,188 +3,169 @@ export * from "valibot";
|
|
|
3
3
|
|
|
4
4
|
// src/schema/json.ts
|
|
5
5
|
import { parse } from "@awsless/json";
|
|
6
|
-
import {
|
|
7
|
-
var json = (schema) => {
|
|
8
|
-
return
|
|
9
|
-
string(),
|
|
10
|
-
(
|
|
6
|
+
import { pipe, rawTransform, string } from "valibot";
|
|
7
|
+
var json = (schema, message = "Invalid JSON") => {
|
|
8
|
+
return pipe(
|
|
9
|
+
string(message),
|
|
10
|
+
rawTransform((ctx) => {
|
|
11
|
+
let result;
|
|
11
12
|
try {
|
|
12
|
-
|
|
13
|
-
} catch (
|
|
14
|
-
|
|
13
|
+
result = parse(ctx.dataset.value);
|
|
14
|
+
} catch (_error) {
|
|
15
|
+
ctx.addIssue({
|
|
16
|
+
message
|
|
17
|
+
});
|
|
18
|
+
return ctx.NEVER;
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
return result;
|
|
21
|
+
}),
|
|
17
22
|
schema
|
|
18
23
|
);
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
// src/schema/bigfloat.ts
|
|
22
|
-
import { BigFloat } from "@awsless/big-float";
|
|
27
|
+
import { BigFloat, parse as parse2 } from "@awsless/big-float";
|
|
23
28
|
import {
|
|
24
29
|
bigint,
|
|
25
|
-
|
|
26
|
-
defaultArgs,
|
|
30
|
+
decimal,
|
|
27
31
|
instance,
|
|
28
32
|
number,
|
|
29
|
-
|
|
33
|
+
pipe as pipe2,
|
|
30
34
|
string as string2,
|
|
31
|
-
transform
|
|
35
|
+
transform,
|
|
32
36
|
union
|
|
33
37
|
} from "valibot";
|
|
34
|
-
|
|
35
|
-
function bigfloat(arg1, arg2) {
|
|
36
|
-
const [msg, pipe] = defaultArgs(arg1, arg2);
|
|
37
|
-
const error = msg ?? "Invalid bigfloat";
|
|
38
|
+
function bigfloat(message = "Invalid bigfloat") {
|
|
38
39
|
return union(
|
|
39
40
|
[
|
|
40
|
-
instance(BigFloat
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// src/schema/bigint.ts
|
|
57
|
-
import { bigint as base, defaultArgs as defaultArgs2, regex, string as string3, transform as transform3, union as union2 } from "valibot";
|
|
58
|
-
function bigint2(arg1, arg2) {
|
|
59
|
-
const [error, pipe] = defaultArgs2(arg1, arg2);
|
|
60
|
-
return union2(
|
|
61
|
-
[
|
|
62
|
-
base(pipe),
|
|
63
|
-
transform3(
|
|
64
|
-
string3([regex(/^-?[0-9]+$/)]),
|
|
65
|
-
(input) => {
|
|
66
|
-
return BigInt(input);
|
|
67
|
-
},
|
|
68
|
-
base(pipe)
|
|
69
|
-
)
|
|
70
|
-
],
|
|
71
|
-
error ?? "Invalid BigInt"
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// src/schema/date.ts
|
|
76
|
-
import { date as base2, defaultArgs as defaultArgs3, string as string4, transform as transform4, union as union3 } from "valibot";
|
|
77
|
-
function date(arg1, arg2) {
|
|
78
|
-
const [error, pipe] = defaultArgs3(arg1, arg2);
|
|
79
|
-
return union3(
|
|
80
|
-
[
|
|
81
|
-
base2(pipe),
|
|
82
|
-
transform4(
|
|
83
|
-
string4(),
|
|
84
|
-
(input) => {
|
|
85
|
-
return new Date(input);
|
|
86
|
-
},
|
|
87
|
-
base2(pipe)
|
|
41
|
+
instance(BigFloat),
|
|
42
|
+
pipe2(
|
|
43
|
+
string2(),
|
|
44
|
+
decimal(),
|
|
45
|
+
transform((v) => parse2(v))
|
|
46
|
+
),
|
|
47
|
+
pipe2(
|
|
48
|
+
bigint(),
|
|
49
|
+
transform((v) => parse2(v))
|
|
50
|
+
),
|
|
51
|
+
pipe2(
|
|
52
|
+
number(),
|
|
53
|
+
transform((v) => parse2(v))
|
|
88
54
|
)
|
|
89
55
|
],
|
|
90
|
-
|
|
56
|
+
message
|
|
91
57
|
);
|
|
92
58
|
}
|
|
93
59
|
|
|
94
60
|
// src/schema/uuid.ts
|
|
95
|
-
import { uuid as
|
|
96
|
-
var uuid = (
|
|
97
|
-
return
|
|
61
|
+
import { uuid as base, pipe as pipe3, string as string3 } from "valibot";
|
|
62
|
+
var uuid = (message = "Invalid UUID") => {
|
|
63
|
+
return pipe3(string3(message), base(message));
|
|
98
64
|
};
|
|
99
65
|
|
|
100
66
|
// src/schema/duration.ts
|
|
101
67
|
import { Duration } from "@awsless/duration";
|
|
102
|
-
import {
|
|
103
|
-
function duration(
|
|
104
|
-
|
|
105
|
-
const error = msg ?? "Invalid duration";
|
|
106
|
-
return instance2(Duration, error, pipe);
|
|
68
|
+
import { instance as instance2 } from "valibot";
|
|
69
|
+
function duration(message = "Invalid duration") {
|
|
70
|
+
return instance2(Duration, message);
|
|
107
71
|
}
|
|
108
72
|
|
|
109
73
|
// src/schema/aws/sqs-queue.ts
|
|
110
|
-
import {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
74
|
+
import {
|
|
75
|
+
array,
|
|
76
|
+
object,
|
|
77
|
+
pipe as pipe4,
|
|
78
|
+
transform as transform2,
|
|
79
|
+
union as union2
|
|
80
|
+
} from "valibot";
|
|
81
|
+
var sqsQueue = (schema, message = "Invalid SQS Queue payload") => {
|
|
82
|
+
return union2(
|
|
114
83
|
[
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
object2({
|
|
84
|
+
// Prioritize the expected payload during production
|
|
85
|
+
pipe4(
|
|
86
|
+
object({
|
|
119
87
|
Records: array(
|
|
120
|
-
|
|
88
|
+
object({
|
|
121
89
|
body: json(schema)
|
|
122
90
|
})
|
|
123
91
|
)
|
|
124
92
|
}),
|
|
125
|
-
(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
93
|
+
transform2((v) => v.Records.map((r) => r.body))
|
|
94
|
+
),
|
|
95
|
+
// These are allowed during testing
|
|
96
|
+
pipe4(
|
|
97
|
+
schema,
|
|
98
|
+
transform2((v) => [v])
|
|
99
|
+
),
|
|
100
|
+
array(schema)
|
|
129
101
|
],
|
|
130
|
-
|
|
102
|
+
message
|
|
131
103
|
);
|
|
132
104
|
};
|
|
133
105
|
|
|
134
106
|
// src/schema/aws/sns-topic.ts
|
|
135
|
-
import {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
107
|
+
import {
|
|
108
|
+
array as array2,
|
|
109
|
+
object as object2,
|
|
110
|
+
pipe as pipe5,
|
|
111
|
+
transform as transform3,
|
|
112
|
+
union as union3
|
|
113
|
+
} from "valibot";
|
|
114
|
+
var snsTopic = (schema, message = "Invalid SNS Topic payload") => {
|
|
115
|
+
return union3(
|
|
139
116
|
[
|
|
140
|
-
|
|
117
|
+
pipe5(
|
|
118
|
+
schema,
|
|
119
|
+
transform3((v) => [v])
|
|
120
|
+
),
|
|
141
121
|
array2(schema),
|
|
142
|
-
|
|
143
|
-
|
|
122
|
+
pipe5(
|
|
123
|
+
object2({
|
|
144
124
|
Records: array2(
|
|
145
|
-
|
|
146
|
-
Sns:
|
|
125
|
+
object2({
|
|
126
|
+
Sns: object2({
|
|
147
127
|
Message: json(schema)
|
|
148
128
|
})
|
|
149
129
|
})
|
|
150
130
|
)
|
|
151
131
|
}),
|
|
152
|
-
(
|
|
153
|
-
return record.Sns.Message;
|
|
154
|
-
})
|
|
132
|
+
transform3((v) => v.Records.map((r) => r.Sns.Message))
|
|
155
133
|
)
|
|
156
134
|
],
|
|
157
|
-
|
|
135
|
+
message
|
|
158
136
|
);
|
|
159
137
|
};
|
|
160
138
|
|
|
161
139
|
// src/schema/aws/dynamodb-stream.ts
|
|
162
|
-
import { array as array3, literal, object as
|
|
163
|
-
var dynamoDbStream = (table) => {
|
|
164
|
-
const unmarshall = () =>
|
|
165
|
-
|
|
166
|
-
|
|
140
|
+
import { array as array3, literal, object as object3, pipe as pipe6, transform as transform4, unknown, variant } from "valibot";
|
|
141
|
+
var dynamoDbStream = (table, message = "Invalid DynamoDB Stream payload") => {
|
|
142
|
+
const unmarshall = () => pipe6(
|
|
143
|
+
unknown(),
|
|
144
|
+
transform4((v) => table.unmarshall(v))
|
|
145
|
+
);
|
|
146
|
+
return pipe6(
|
|
147
|
+
object3(
|
|
167
148
|
{
|
|
168
149
|
Records: array3(
|
|
169
150
|
variant("eventName", [
|
|
170
|
-
|
|
151
|
+
object3({
|
|
171
152
|
eventName: literal("MODIFY"),
|
|
172
|
-
dynamodb:
|
|
153
|
+
dynamodb: object3({
|
|
173
154
|
Keys: unmarshall(),
|
|
174
155
|
OldImage: unmarshall(),
|
|
175
156
|
NewImage: unmarshall()
|
|
176
157
|
})
|
|
177
158
|
}),
|
|
178
|
-
|
|
159
|
+
object3({
|
|
179
160
|
eventName: literal("INSERT"),
|
|
180
|
-
dynamodb:
|
|
161
|
+
dynamodb: object3({
|
|
181
162
|
Keys: unmarshall(),
|
|
182
163
|
NewImage: unmarshall()
|
|
183
164
|
})
|
|
184
165
|
}),
|
|
185
|
-
|
|
166
|
+
object3({
|
|
186
167
|
eventName: literal("REMOVE"),
|
|
187
|
-
dynamodb:
|
|
168
|
+
dynamodb: object3({
|
|
188
169
|
Keys: unmarshall(),
|
|
189
170
|
OldImage: unmarshall()
|
|
190
171
|
})
|
|
@@ -192,9 +173,9 @@ var dynamoDbStream = (table) => {
|
|
|
192
173
|
])
|
|
193
174
|
)
|
|
194
175
|
},
|
|
195
|
-
|
|
176
|
+
message
|
|
196
177
|
),
|
|
197
|
-
(input) => {
|
|
178
|
+
transform4((input) => {
|
|
198
179
|
return input.Records.map((record) => {
|
|
199
180
|
const item = {
|
|
200
181
|
event: record.eventName.toLowerCase(),
|
|
@@ -208,34 +189,31 @@ var dynamoDbStream = (table) => {
|
|
|
208
189
|
}
|
|
209
190
|
return item;
|
|
210
191
|
});
|
|
211
|
-
}
|
|
192
|
+
})
|
|
212
193
|
);
|
|
213
194
|
};
|
|
214
195
|
|
|
215
196
|
// src/validation/positive.ts
|
|
216
|
-
import {
|
|
217
|
-
import {
|
|
218
|
-
function positive(
|
|
219
|
-
return
|
|
197
|
+
import { isPositive } from "@awsless/big-float";
|
|
198
|
+
import { check } from "valibot";
|
|
199
|
+
function positive(message = "Invalid positive number") {
|
|
200
|
+
return check((input) => isPositive(input), message);
|
|
220
201
|
}
|
|
221
202
|
|
|
222
203
|
// src/validation/precision.ts
|
|
223
|
-
import { parse as
|
|
224
|
-
import {
|
|
225
|
-
function precision(decimals,
|
|
226
|
-
return
|
|
227
|
-
(input)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
},
|
|
231
|
-
error ?? `Invalid ${decimals} precision number`
|
|
232
|
-
);
|
|
204
|
+
import { parse as parse3 } from "@awsless/big-float";
|
|
205
|
+
import { check as check2 } from "valibot";
|
|
206
|
+
function precision(decimals, message = `Invalid ${decimals} precision number`) {
|
|
207
|
+
return check2((input) => {
|
|
208
|
+
const big = parse3(input.toString());
|
|
209
|
+
return -big.exponent <= decimals;
|
|
210
|
+
}, message);
|
|
233
211
|
}
|
|
234
212
|
|
|
235
213
|
// src/validation/unique.ts
|
|
236
|
-
import {
|
|
237
|
-
function unique(compare = (a, b) => a === b,
|
|
238
|
-
return
|
|
214
|
+
import { check as check3 } from "valibot";
|
|
215
|
+
function unique(compare = (a, b) => a === b, message = "None unique array") {
|
|
216
|
+
return check3((input) => {
|
|
239
217
|
for (const x in input) {
|
|
240
218
|
for (const y in input) {
|
|
241
219
|
if (x !== y && compare(input[x], input[y])) {
|
|
@@ -244,21 +222,19 @@ function unique(compare = (a, b) => a === b, error) {
|
|
|
244
222
|
}
|
|
245
223
|
}
|
|
246
224
|
return true;
|
|
247
|
-
},
|
|
225
|
+
}, message);
|
|
248
226
|
}
|
|
249
227
|
|
|
250
228
|
// src/validation/duration.ts
|
|
251
|
-
import {
|
|
252
|
-
function minDuration(min,
|
|
253
|
-
return
|
|
229
|
+
import { check as check4 } from "valibot";
|
|
230
|
+
function minDuration(min, message = "Invalid duration") {
|
|
231
|
+
return check4((input) => input.value >= min.value, message);
|
|
254
232
|
}
|
|
255
|
-
function maxDuration(max,
|
|
256
|
-
return
|
|
233
|
+
function maxDuration(max, message = "Invalid duration") {
|
|
234
|
+
return check4((input) => input.value <= max.value, message);
|
|
257
235
|
}
|
|
258
236
|
export {
|
|
259
237
|
bigfloat,
|
|
260
|
-
bigint2 as bigint,
|
|
261
|
-
date,
|
|
262
238
|
duration,
|
|
263
239
|
dynamoDbStream,
|
|
264
240
|
json,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/validate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@awsless/big-float": "^0.1.5",
|
|
28
|
-
"@awsless/dynamodb": "^0.2.14",
|
|
29
28
|
"@awsless/duration": "^0.0.4",
|
|
29
|
+
"@awsless/dynamodb": "^0.3.2",
|
|
30
30
|
"@awsless/json": "^0.0.10"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@awsless/big-float": "^0.1.5",
|
|
34
|
-
"@awsless/
|
|
35
|
-
"@awsless/
|
|
36
|
-
"@awsless/
|
|
34
|
+
"@awsless/duration": "^0.0.4",
|
|
35
|
+
"@awsless/dynamodb": "^0.3.2",
|
|
36
|
+
"@awsless/json": "^0.0.10"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"valibot": "^
|
|
39
|
+
"valibot": "^1.2.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"test": "pnpm code test",
|