@awsless/validate 0.0.19 → 0.0.21
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 +12 -18
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +24 -30
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -19,8 +19,8 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
|
|
21
21
|
// src/index.ts
|
|
22
|
-
var
|
|
23
|
-
__export(
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
24
|
bigfloat: () => bigfloat,
|
|
25
25
|
bigint: () => bigint2,
|
|
26
26
|
date: () => date,
|
|
@@ -36,8 +36,8 @@ __export(src_exports, {
|
|
|
36
36
|
unique: () => unique,
|
|
37
37
|
uuid: () => uuid
|
|
38
38
|
});
|
|
39
|
-
module.exports = __toCommonJS(
|
|
40
|
-
__reExport(
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
__reExport(index_exports, require("valibot"), module.exports);
|
|
41
41
|
|
|
42
42
|
// src/schema/json.ts
|
|
43
43
|
var import_json = require("@awsless/json");
|
|
@@ -131,16 +131,7 @@ var import_valibot6 = require("valibot");
|
|
|
131
131
|
function duration(arg1, arg2) {
|
|
132
132
|
const [msg, pipe] = (0, import_valibot6.defaultArgs)(arg1, arg2);
|
|
133
133
|
const error = msg ?? "Invalid duration";
|
|
134
|
-
return (0, import_valibot6.
|
|
135
|
-
(0, import_valibot6.instance)(import_duration.Duration, pipe),
|
|
136
|
-
(0, import_valibot6.transform)(
|
|
137
|
-
(0, import_valibot6.string)(error, [(0, import_valibot6.regex)(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?|weeks?)/, error)]),
|
|
138
|
-
(value) => {
|
|
139
|
-
return (0, import_duration.parse)(value);
|
|
140
|
-
},
|
|
141
|
-
pipe
|
|
142
|
-
)
|
|
143
|
-
]);
|
|
134
|
+
return (0, import_valibot6.instance)(import_duration.Duration, error, pipe);
|
|
144
135
|
}
|
|
145
136
|
|
|
146
137
|
// src/schema/aws/sqs-queue.ts
|
|
@@ -242,10 +233,13 @@ function positive(error) {
|
|
|
242
233
|
var import_big_float3 = require("@awsless/big-float");
|
|
243
234
|
var import_valibot11 = require("valibot");
|
|
244
235
|
function precision(decimals, error) {
|
|
245
|
-
return (0, import_valibot11.custom)(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
236
|
+
return (0, import_valibot11.custom)(
|
|
237
|
+
(input) => {
|
|
238
|
+
const big = (0, import_big_float3.parse)(input.toString());
|
|
239
|
+
return -big.exponent <= decimals;
|
|
240
|
+
},
|
|
241
|
+
error ?? `Invalid ${decimals} precision number`
|
|
242
|
+
);
|
|
249
243
|
}
|
|
250
244
|
|
|
251
245
|
// src/validation/unique.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessa
|
|
|
3
3
|
export * from 'valibot';
|
|
4
4
|
import { BigFloat } from '@awsless/big-float';
|
|
5
5
|
import { UUID } from 'crypto';
|
|
6
|
-
import {
|
|
7
|
-
import { AnyTable, PrimaryKey } from '@awsless/dynamodb';
|
|
6
|
+
import { Duration, DurationFormat } from '@awsless/duration';
|
|
7
|
+
import { AnyTable, PrimaryKey, Infer } from '@awsless/dynamodb';
|
|
8
8
|
|
|
9
9
|
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
10
10
|
declare const json: <T extends BaseSchema>(schema: T) => JsonSchema<T>;
|
|
@@ -36,7 +36,7 @@ type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
36
36
|
body: string | Input<S>;
|
|
37
37
|
}[];
|
|
38
38
|
}, Output<S>[]>;
|
|
39
|
-
declare const sqsQueue: <S extends BaseSchema = UnknownSchema
|
|
39
|
+
declare const sqsQueue: <S extends BaseSchema = UnknownSchema>(body?: S) => SqsQueueSchema<S>;
|
|
40
40
|
|
|
41
41
|
type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
|
|
42
42
|
Records: {
|
|
@@ -45,7 +45,7 @@ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
45
45
|
};
|
|
46
46
|
}[];
|
|
47
47
|
}, Output<S>[]>;
|
|
48
|
-
declare const snsTopic: <S extends BaseSchema = UnknownSchema
|
|
48
|
+
declare const snsTopic: <S extends BaseSchema = UnknownSchema>(body?: S) => SnsTopicSchema<S>;
|
|
49
49
|
|
|
50
50
|
type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
|
|
51
51
|
type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
@@ -60,8 +60,8 @@ type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
|
60
60
|
}, {
|
|
61
61
|
event: Lowercase<EventName>;
|
|
62
62
|
keys: PrimaryKey<T>;
|
|
63
|
-
old?: T
|
|
64
|
-
new?: T
|
|
63
|
+
old?: Infer<T>;
|
|
64
|
+
new?: Infer<T>;
|
|
65
65
|
}[]>;
|
|
66
66
|
declare const dynamoDbStream: <T extends AnyTable>(table: T) => DynamoDBStreamSchema<T>;
|
|
67
67
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessa
|
|
|
3
3
|
export * from 'valibot';
|
|
4
4
|
import { BigFloat } from '@awsless/big-float';
|
|
5
5
|
import { UUID } from 'crypto';
|
|
6
|
-
import {
|
|
7
|
-
import { AnyTable, PrimaryKey } from '@awsless/dynamodb';
|
|
6
|
+
import { Duration, DurationFormat } from '@awsless/duration';
|
|
7
|
+
import { AnyTable, PrimaryKey, Infer } from '@awsless/dynamodb';
|
|
8
8
|
|
|
9
9
|
type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
|
|
10
10
|
declare const json: <T extends BaseSchema>(schema: T) => JsonSchema<T>;
|
|
@@ -36,7 +36,7 @@ type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
36
36
|
body: string | Input<S>;
|
|
37
37
|
}[];
|
|
38
38
|
}, Output<S>[]>;
|
|
39
|
-
declare const sqsQueue: <S extends BaseSchema = UnknownSchema
|
|
39
|
+
declare const sqsQueue: <S extends BaseSchema = UnknownSchema>(body?: S) => SqsQueueSchema<S>;
|
|
40
40
|
|
|
41
41
|
type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
|
|
42
42
|
Records: {
|
|
@@ -45,7 +45,7 @@ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
|
|
|
45
45
|
};
|
|
46
46
|
}[];
|
|
47
47
|
}, Output<S>[]>;
|
|
48
|
-
declare const snsTopic: <S extends BaseSchema = UnknownSchema
|
|
48
|
+
declare const snsTopic: <S extends BaseSchema = UnknownSchema>(body?: S) => SnsTopicSchema<S>;
|
|
49
49
|
|
|
50
50
|
type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
|
|
51
51
|
type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
@@ -60,8 +60,8 @@ type DynamoDBStreamSchema<T extends AnyTable> = BaseSchema<{
|
|
|
60
60
|
}, {
|
|
61
61
|
event: Lowercase<EventName>;
|
|
62
62
|
keys: PrimaryKey<T>;
|
|
63
|
-
old?: T
|
|
64
|
-
new?: T
|
|
63
|
+
old?: Infer<T>;
|
|
64
|
+
new?: Infer<T>;
|
|
65
65
|
}[]>;
|
|
66
66
|
declare const dynamoDbStream: <T extends AnyTable>(table: T) => DynamoDBStreamSchema<T>;
|
|
67
67
|
|
package/dist/index.js
CHANGED
|
@@ -73,7 +73,7 @@ function bigint2(arg1, arg2) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// src/schema/date.ts
|
|
76
|
-
import {
|
|
76
|
+
import { date as base2, defaultArgs as defaultArgs3, string as string4, transform as transform4, union as union3 } from "valibot";
|
|
77
77
|
function date(arg1, arg2) {
|
|
78
78
|
const [error, pipe] = defaultArgs3(arg1, arg2);
|
|
79
79
|
return union3(
|
|
@@ -98,32 +98,23 @@ var uuid = (error) => {
|
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
// src/schema/duration.ts
|
|
101
|
-
import { Duration
|
|
102
|
-
import { defaultArgs as defaultArgs4, instance as instance2
|
|
101
|
+
import { Duration } from "@awsless/duration";
|
|
102
|
+
import { defaultArgs as defaultArgs4, instance as instance2 } from "valibot";
|
|
103
103
|
function duration(arg1, arg2) {
|
|
104
104
|
const [msg, pipe] = defaultArgs4(arg1, arg2);
|
|
105
105
|
const error = msg ?? "Invalid duration";
|
|
106
|
-
return
|
|
107
|
-
instance2(Duration, pipe),
|
|
108
|
-
transform5(
|
|
109
|
-
string6(error, [regex2(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?|weeks?)/, error)]),
|
|
110
|
-
(value) => {
|
|
111
|
-
return parse2(value);
|
|
112
|
-
},
|
|
113
|
-
pipe
|
|
114
|
-
)
|
|
115
|
-
]);
|
|
106
|
+
return instance2(Duration, error, pipe);
|
|
116
107
|
}
|
|
117
108
|
|
|
118
109
|
// src/schema/aws/sqs-queue.ts
|
|
119
|
-
import { array, object as object2, transform as
|
|
110
|
+
import { array, object as object2, transform as transform5, union as union4, unknown } from "valibot";
|
|
120
111
|
var sqsQueue = (body) => {
|
|
121
112
|
const schema = body ?? unknown();
|
|
122
|
-
return
|
|
113
|
+
return union4(
|
|
123
114
|
[
|
|
124
|
-
|
|
115
|
+
transform5(schema, (input) => [input]),
|
|
125
116
|
array(schema),
|
|
126
|
-
|
|
117
|
+
transform5(
|
|
127
118
|
object2({
|
|
128
119
|
Records: array(
|
|
129
120
|
object2({
|
|
@@ -141,14 +132,14 @@ var sqsQueue = (body) => {
|
|
|
141
132
|
};
|
|
142
133
|
|
|
143
134
|
// src/schema/aws/sns-topic.ts
|
|
144
|
-
import { array as array2, object as object3, transform as
|
|
135
|
+
import { array as array2, object as object3, transform as transform6, union as union5, unknown as unknown2 } from "valibot";
|
|
145
136
|
var snsTopic = (body) => {
|
|
146
137
|
const schema = body ?? unknown2();
|
|
147
|
-
return
|
|
138
|
+
return union5(
|
|
148
139
|
[
|
|
149
|
-
|
|
140
|
+
transform6(schema, (input) => [input]),
|
|
150
141
|
array2(schema),
|
|
151
|
-
|
|
142
|
+
transform6(
|
|
152
143
|
object3({
|
|
153
144
|
Records: array2(
|
|
154
145
|
object3({
|
|
@@ -168,17 +159,17 @@ var snsTopic = (body) => {
|
|
|
168
159
|
};
|
|
169
160
|
|
|
170
161
|
// src/schema/aws/dynamodb-stream.ts
|
|
171
|
-
import { array as array3, literal, object as object4, optional, transform as
|
|
162
|
+
import { array as array3, literal, object as object4, optional, transform as transform7, union as union6, unknown as unknown3 } from "valibot";
|
|
172
163
|
var dynamoDbStream = (table) => {
|
|
173
|
-
const marshall = () =>
|
|
174
|
-
return
|
|
164
|
+
const marshall = () => transform7(unknown3(), (value) => table.unmarshall(value));
|
|
165
|
+
return transform7(
|
|
175
166
|
object4(
|
|
176
167
|
{
|
|
177
168
|
Records: array3(
|
|
178
169
|
object4({
|
|
179
170
|
// For some reason picklist fails to build.
|
|
180
171
|
// eventName: picklist(['MODIFY', 'INSERT', 'REMOVE']),
|
|
181
|
-
eventName:
|
|
172
|
+
eventName: union6([literal("MODIFY"), literal("INSERT"), literal("REMOVE")]),
|
|
182
173
|
dynamodb: object4({
|
|
183
174
|
Keys: marshall(),
|
|
184
175
|
OldImage: optional(marshall()),
|
|
@@ -211,13 +202,16 @@ function positive(error) {
|
|
|
211
202
|
}
|
|
212
203
|
|
|
213
204
|
// src/validation/precision.ts
|
|
214
|
-
import {
|
|
205
|
+
import { parse as parse2 } from "@awsless/big-float";
|
|
215
206
|
import { custom as custom3 } from "valibot";
|
|
216
207
|
function precision(decimals, error) {
|
|
217
|
-
return custom3(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
208
|
+
return custom3(
|
|
209
|
+
(input) => {
|
|
210
|
+
const big = parse2(input.toString());
|
|
211
|
+
return -big.exponent <= decimals;
|
|
212
|
+
},
|
|
213
|
+
error ?? `Invalid ${decimals} precision number`
|
|
214
|
+
);
|
|
221
215
|
}
|
|
222
216
|
|
|
223
217
|
// src/validation/unique.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/validate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@awsless/big-float": "^0.
|
|
28
|
-
"@awsless/dynamodb": "^0.
|
|
29
|
-
"@awsless/
|
|
30
|
-
"@awsless/
|
|
27
|
+
"@awsless/big-float": "^0.1.5",
|
|
28
|
+
"@awsless/dynamodb": "^0.2.12",
|
|
29
|
+
"@awsless/duration": "^0.0.3",
|
|
30
|
+
"@awsless/json": "^0.0.10"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@awsless/big-float": "^0.
|
|
34
|
-
"@awsless/
|
|
35
|
-
"@awsless/
|
|
36
|
-
"@awsless/json": "^0.0.
|
|
33
|
+
"@awsless/big-float": "^0.1.5",
|
|
34
|
+
"@awsless/duration": "^0.0.3",
|
|
35
|
+
"@awsless/dynamodb": "^0.2.12",
|
|
36
|
+
"@awsless/json": "^0.0.10"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"valibot": "^0.30.0"
|