@awsless/validate 0.0.21 → 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 +128 -147
- package/dist/index.d.cts +71 -53
- package/dist/index.d.ts +71 -53
- package/dist/index.js +143 -149
- 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,193 +62,173 @@ 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
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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)({
|
|
169
|
+
Keys: unmarshall(),
|
|
170
|
+
OldImage: unmarshall(),
|
|
171
|
+
NewImage: unmarshall()
|
|
172
|
+
})
|
|
173
|
+
}),
|
|
174
|
+
(0, import_valibot7.object)({
|
|
175
|
+
eventName: (0, import_valibot7.literal)("INSERT"),
|
|
176
|
+
dynamodb: (0, import_valibot7.object)({
|
|
177
|
+
Keys: unmarshall(),
|
|
178
|
+
NewImage: unmarshall()
|
|
179
|
+
})
|
|
180
|
+
}),
|
|
181
|
+
(0, import_valibot7.object)({
|
|
182
|
+
eventName: (0, import_valibot7.literal)("REMOVE"),
|
|
183
|
+
dynamodb: (0, import_valibot7.object)({
|
|
184
|
+
Keys: unmarshall(),
|
|
185
|
+
OldImage: unmarshall()
|
|
186
|
+
})
|
|
205
187
|
})
|
|
206
|
-
|
|
188
|
+
])
|
|
207
189
|
)
|
|
208
190
|
},
|
|
209
|
-
|
|
191
|
+
message
|
|
210
192
|
),
|
|
211
|
-
(input) => {
|
|
193
|
+
(0, import_valibot7.transform)((input) => {
|
|
212
194
|
return input.Records.map((record) => {
|
|
213
|
-
const item =
|
|
214
|
-
return {
|
|
195
|
+
const item = {
|
|
215
196
|
event: record.eventName.toLowerCase(),
|
|
216
|
-
keys:
|
|
217
|
-
old: item.dynamodb.OldImage,
|
|
218
|
-
new: item.dynamodb.NewImage
|
|
197
|
+
keys: record.dynamodb.Keys
|
|
219
198
|
};
|
|
199
|
+
if ("OldImage" in record.dynamodb) {
|
|
200
|
+
item.old = record.dynamodb.OldImage;
|
|
201
|
+
}
|
|
202
|
+
if ("NewImage" in record.dynamodb) {
|
|
203
|
+
item.new = record.dynamodb.NewImage;
|
|
204
|
+
}
|
|
205
|
+
return item;
|
|
220
206
|
});
|
|
221
|
-
}
|
|
207
|
+
})
|
|
222
208
|
);
|
|
223
209
|
};
|
|
224
210
|
|
|
225
211
|
// src/validation/positive.ts
|
|
226
212
|
var import_big_float2 = require("@awsless/big-float");
|
|
227
|
-
var
|
|
228
|
-
function positive(
|
|
229
|
-
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);
|
|
230
216
|
}
|
|
231
217
|
|
|
232
218
|
// src/validation/precision.ts
|
|
233
219
|
var import_big_float3 = require("@awsless/big-float");
|
|
234
|
-
var
|
|
235
|
-
function precision(decimals,
|
|
236
|
-
return (0,
|
|
237
|
-
(input)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
},
|
|
241
|
-
error ?? `Invalid ${decimals} precision number`
|
|
242
|
-
);
|
|
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);
|
|
243
226
|
}
|
|
244
227
|
|
|
245
228
|
// src/validation/unique.ts
|
|
246
|
-
var
|
|
247
|
-
function unique(compare = (a, b) => a === b,
|
|
248
|
-
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) => {
|
|
249
232
|
for (const x in input) {
|
|
250
233
|
for (const y in input) {
|
|
251
234
|
if (x !== y && compare(input[x], input[y])) {
|
|
@@ -254,22 +237,20 @@ function unique(compare = (a, b) => a === b, error) {
|
|
|
254
237
|
}
|
|
255
238
|
}
|
|
256
239
|
return true;
|
|
257
|
-
},
|
|
240
|
+
}, message);
|
|
258
241
|
}
|
|
259
242
|
|
|
260
243
|
// src/validation/duration.ts
|
|
261
|
-
var
|
|
262
|
-
function minDuration(min,
|
|
263
|
-
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);
|
|
264
247
|
}
|
|
265
|
-
function maxDuration(max,
|
|
266
|
-
return (0,
|
|
248
|
+
function maxDuration(max, message = "Invalid duration") {
|
|
249
|
+
return (0, import_valibot11.check)((input) => input.value <= max.value, message);
|
|
267
250
|
}
|
|
268
251
|
// Annotate the CommonJS export names for ESM import in node:
|
|
269
252
|
0 && (module.exports = {
|
|
270
253
|
bigfloat,
|
|
271
|
-
bigint,
|
|
272
|
-
date,
|
|
273
254
|
duration,
|
|
274
255
|
dynamoDbStream,
|
|
275
256
|
json,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,77 +1,95 @@
|
|
|
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
|
-
|
|
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> = {
|
|
67
|
+
event: 'modify';
|
|
68
|
+
keys: PrimaryKey<T>;
|
|
69
|
+
old: Infer<T>;
|
|
70
|
+
new: Infer<T>;
|
|
71
|
+
} | {
|
|
72
|
+
event: 'insert';
|
|
62
73
|
keys: PrimaryKey<T>;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
new: Infer<T>;
|
|
75
|
+
} | {
|
|
76
|
+
event: 'remove';
|
|
77
|
+
keys: PrimaryKey<T>;
|
|
78
|
+
old: Infer<T>;
|
|
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>;
|
|
67
85
|
|
|
68
|
-
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>>>;
|
|
69
87
|
|
|
70
|
-
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>>>;
|
|
71
89
|
|
|
72
|
-
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>>>;
|
|
73
91
|
|
|
74
|
-
declare function minDuration
|
|
75
|
-
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>>>;
|
|
76
94
|
|
|
77
|
-
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,77 +1,95 @@
|
|
|
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
|
-
|
|
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> = {
|
|
67
|
+
event: 'modify';
|
|
68
|
+
keys: PrimaryKey<T>;
|
|
69
|
+
old: Infer<T>;
|
|
70
|
+
new: Infer<T>;
|
|
71
|
+
} | {
|
|
72
|
+
event: 'insert';
|
|
62
73
|
keys: PrimaryKey<T>;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
new: Infer<T>;
|
|
75
|
+
} | {
|
|
76
|
+
event: 'remove';
|
|
77
|
+
keys: PrimaryKey<T>;
|
|
78
|
+
old: Infer<T>;
|
|
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>;
|
|
67
85
|
|
|
68
|
-
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>>>;
|
|
69
87
|
|
|
70
|
-
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>>>;
|
|
71
89
|
|
|
72
|
-
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>>>;
|
|
73
91
|
|
|
74
|
-
declare function minDuration
|
|
75
|
-
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>>>;
|
|
76
94
|
|
|
77
|
-
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,221 +3,217 @@ 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)
|
|
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))
|
|
69
54
|
)
|
|
70
55
|
],
|
|
71
|
-
|
|
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)
|
|
88
|
-
)
|
|
89
|
-
],
|
|
90
|
-
error ?? "Invalid date"
|
|
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
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
150
|
+
variant("eventName", [
|
|
151
|
+
object3({
|
|
152
|
+
eventName: literal("MODIFY"),
|
|
153
|
+
dynamodb: object3({
|
|
154
|
+
Keys: unmarshall(),
|
|
155
|
+
OldImage: unmarshall(),
|
|
156
|
+
NewImage: unmarshall()
|
|
157
|
+
})
|
|
158
|
+
}),
|
|
159
|
+
object3({
|
|
160
|
+
eventName: literal("INSERT"),
|
|
161
|
+
dynamodb: object3({
|
|
162
|
+
Keys: unmarshall(),
|
|
163
|
+
NewImage: unmarshall()
|
|
164
|
+
})
|
|
165
|
+
}),
|
|
166
|
+
object3({
|
|
167
|
+
eventName: literal("REMOVE"),
|
|
168
|
+
dynamodb: object3({
|
|
169
|
+
Keys: unmarshall(),
|
|
170
|
+
OldImage: unmarshall()
|
|
171
|
+
})
|
|
177
172
|
})
|
|
178
|
-
|
|
173
|
+
])
|
|
179
174
|
)
|
|
180
175
|
},
|
|
181
|
-
|
|
176
|
+
message
|
|
182
177
|
),
|
|
183
|
-
(input) => {
|
|
178
|
+
transform4((input) => {
|
|
184
179
|
return input.Records.map((record) => {
|
|
185
|
-
const item =
|
|
186
|
-
return {
|
|
180
|
+
const item = {
|
|
187
181
|
event: record.eventName.toLowerCase(),
|
|
188
|
-
keys:
|
|
189
|
-
old: item.dynamodb.OldImage,
|
|
190
|
-
new: item.dynamodb.NewImage
|
|
182
|
+
keys: record.dynamodb.Keys
|
|
191
183
|
};
|
|
184
|
+
if ("OldImage" in record.dynamodb) {
|
|
185
|
+
item.old = record.dynamodb.OldImage;
|
|
186
|
+
}
|
|
187
|
+
if ("NewImage" in record.dynamodb) {
|
|
188
|
+
item.new = record.dynamodb.NewImage;
|
|
189
|
+
}
|
|
190
|
+
return item;
|
|
192
191
|
});
|
|
193
|
-
}
|
|
192
|
+
})
|
|
194
193
|
);
|
|
195
194
|
};
|
|
196
195
|
|
|
197
196
|
// src/validation/positive.ts
|
|
198
|
-
import {
|
|
199
|
-
import {
|
|
200
|
-
function positive(
|
|
201
|
-
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);
|
|
202
201
|
}
|
|
203
202
|
|
|
204
203
|
// src/validation/precision.ts
|
|
205
|
-
import { parse as
|
|
206
|
-
import {
|
|
207
|
-
function precision(decimals,
|
|
208
|
-
return
|
|
209
|
-
(input)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
},
|
|
213
|
-
error ?? `Invalid ${decimals} precision number`
|
|
214
|
-
);
|
|
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);
|
|
215
211
|
}
|
|
216
212
|
|
|
217
213
|
// src/validation/unique.ts
|
|
218
|
-
import {
|
|
219
|
-
function unique(compare = (a, b) => a === b,
|
|
220
|
-
return
|
|
214
|
+
import { check as check3 } from "valibot";
|
|
215
|
+
function unique(compare = (a, b) => a === b, message = "None unique array") {
|
|
216
|
+
return check3((input) => {
|
|
221
217
|
for (const x in input) {
|
|
222
218
|
for (const y in input) {
|
|
223
219
|
if (x !== y && compare(input[x], input[y])) {
|
|
@@ -226,21 +222,19 @@ function unique(compare = (a, b) => a === b, error) {
|
|
|
226
222
|
}
|
|
227
223
|
}
|
|
228
224
|
return true;
|
|
229
|
-
},
|
|
225
|
+
}, message);
|
|
230
226
|
}
|
|
231
227
|
|
|
232
228
|
// src/validation/duration.ts
|
|
233
|
-
import {
|
|
234
|
-
function minDuration(min,
|
|
235
|
-
return
|
|
229
|
+
import { check as check4 } from "valibot";
|
|
230
|
+
function minDuration(min, message = "Invalid duration") {
|
|
231
|
+
return check4((input) => input.value >= min.value, message);
|
|
236
232
|
}
|
|
237
|
-
function maxDuration(max,
|
|
238
|
-
return
|
|
233
|
+
function maxDuration(max, message = "Invalid duration") {
|
|
234
|
+
return check4((input) => input.value <= max.value, message);
|
|
239
235
|
}
|
|
240
236
|
export {
|
|
241
237
|
bigfloat,
|
|
242
|
-
bigint2 as bigint,
|
|
243
|
-
date,
|
|
244
238
|
duration,
|
|
245
239
|
dynamoDbStream,
|
|
246
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/
|
|
29
|
-
"@awsless/
|
|
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/duration": "^0.0.
|
|
35
|
-
"@awsless/dynamodb": "^0.2
|
|
34
|
+
"@awsless/duration": "^0.0.4",
|
|
35
|
+
"@awsless/dynamodb": "^0.3.2",
|
|
36
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",
|