@awsless/validate 0.0.10 → 0.0.11

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 CHANGED
@@ -59,23 +59,12 @@ var import_big_float = require("@awsless/big-float");
59
59
  var import_valibot2 = require("valibot");
60
60
  var make = (value) => new import_big_float.BigFloat(value);
61
61
  function bigfloat(arg1, arg2) {
62
- const [msg, pipe] = (0, import_valibot2.getDefaultArgs)(arg1, arg2);
62
+ const [msg, pipe] = (0, import_valibot2.defaultArgs)(arg1, arg2);
63
63
  const error = msg ?? "Invalid bigfloat";
64
64
  return (0, import_valibot2.union)(
65
65
  [
66
66
  (0, import_valibot2.instance)(import_big_float.BigFloat, pipe),
67
- (0, import_valibot2.transform)(
68
- (0, import_valibot2.string)([
69
- (input) => {
70
- if (input === "" || isNaN(Number(input))) {
71
- return (0, import_valibot2.getPipeIssues)("bigfloat", error, input);
72
- }
73
- return (0, import_valibot2.getOutput)(input);
74
- }
75
- ]),
76
- make,
77
- pipe
78
- ),
67
+ (0, import_valibot2.transform)((0, import_valibot2.string)([(0, import_valibot2.custom)((input) => input !== "" && !isNaN(Number(input)), error)]), make, pipe),
79
68
  (0, import_valibot2.transform)((0, import_valibot2.number)(), make, pipe),
80
69
  (0, import_valibot2.transform)(
81
70
  (0, import_valibot2.object)({
@@ -93,7 +82,7 @@ function bigfloat(arg1, arg2) {
93
82
  // src/schema/date.ts
94
83
  var import_valibot3 = require("valibot");
95
84
  function date(arg1, arg2) {
96
- const [error, pipe] = (0, import_valibot3.getDefaultArgs)(arg1, arg2);
85
+ const [error, pipe] = (0, import_valibot3.defaultArgs)(arg1, arg2);
97
86
  return (0, import_valibot3.union)(
98
87
  [
99
88
  (0, import_valibot3.date)(pipe),
@@ -119,11 +108,15 @@ var uuid = (error) => {
119
108
  var import_valibot5 = require("valibot");
120
109
  var import_duration = require("@awsless/duration");
121
110
  function duration(arg1, arg2) {
122
- const [msg, pipe] = (0, import_valibot5.getDefaultArgs)(arg1, arg2);
111
+ const [msg, pipe] = (0, import_valibot5.defaultArgs)(arg1, arg2);
123
112
  const error = msg ?? "Invalid duration";
124
113
  return (0, import_valibot5.transform)(
125
114
  (0, import_valibot5.string)(error, [(0, import_valibot5.regex)(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/, error)]),
126
- (value) => (0, import_duration.parse)(value),
115
+ (value, { issues }) => {
116
+ if (issues)
117
+ return;
118
+ return (0, import_duration.parse)(value);
119
+ },
127
120
  pipe
128
121
  );
129
122
  }
@@ -182,6 +175,12 @@ var snsTopic = (body) => {
182
175
 
183
176
  // src/schema/aws/dynamodb-stream.ts
184
177
  var import_valibot8 = require("valibot");
178
+ var EventName = /* @__PURE__ */ ((EventName2) => {
179
+ EventName2["modify"] = "MODIFY";
180
+ EventName2["insert"] = "INSERT";
181
+ EventName2["remove"] = "REMOVE";
182
+ return EventName2;
183
+ })(EventName || {});
185
184
  var dynamoDbStream = (table) => {
186
185
  const marshall = () => (0, import_valibot8.transform)((0, import_valibot8.unknown)(), (value) => table.unmarshall(value));
187
186
  return (0, import_valibot8.transform)(
@@ -189,7 +188,8 @@ var dynamoDbStream = (table) => {
189
188
  {
190
189
  Records: (0, import_valibot8.array)(
191
190
  (0, import_valibot8.object)({
192
- eventName: (0, import_valibot8.picklist)(["MODIFY", "INSERT", "REMOVE"]),
191
+ eventName: (0, import_valibot8.enum_)(EventName),
192
+ // eventName: picklist(['MODIFY', 'INSERT', 'REMOVE']),
193
193
  dynamodb: (0, import_valibot8.object)({
194
194
  Keys: marshall(),
195
195
  OldImage: (0, import_valibot8.optional)(marshall()),
@@ -218,34 +218,32 @@ var dynamoDbStream = (table) => {
218
218
  var import_big_float2 = require("@awsless/big-float");
219
219
  var import_valibot9 = require("valibot");
220
220
  function positive(error) {
221
- return (input) => {
222
- return (0, import_big_float2.gt)(input, import_big_float2.ZERO) ? (0, import_valibot9.getOutput)(input) : (0, import_valibot9.getPipeIssues)("positive", error ?? "Invalid positive number", input);
223
- };
221
+ return (0, import_valibot9.custom)((input) => (0, import_big_float2.gt)(input, import_big_float2.ZERO), error ?? "Invalid positive number");
224
222
  }
225
223
 
226
224
  // src/validation/precision.ts
227
225
  var import_big_float3 = require("@awsless/big-float");
228
226
  var import_valibot10 = require("valibot");
229
227
  function precision(decimals, error) {
230
- return (input) => {
228
+ return (0, import_valibot10.custom)((input) => {
231
229
  const big = new import_big_float3.BigFloat(input.toString());
232
- return -big.exponent <= decimals ? (0, import_valibot10.getOutput)(input) : (0, import_valibot10.getPipeIssues)("precision", error ?? `Invalid ${decimals} precision number`, input);
233
- };
230
+ return -big.exponent <= decimals;
231
+ }, error ?? `Invalid ${decimals} precision number`);
234
232
  }
235
233
 
236
234
  // src/validation/unique.ts
237
235
  var import_valibot11 = require("valibot");
238
236
  function unique(compare = (a, b) => a === b, error) {
239
- return (input) => {
237
+ return (0, import_valibot11.custom)((input) => {
240
238
  for (const x in input) {
241
239
  for (const y in input) {
242
240
  if (x !== y && compare(input[x], input[y])) {
243
- return (0, import_valibot11.getPipeIssues)("unique", error ?? "None unique array", input);
241
+ return false;
244
242
  }
245
243
  }
246
244
  }
247
- return (0, import_valibot11.getOutput)(input);
248
- };
245
+ return true;
246
+ }, error ?? "None unique array");
249
247
  }
250
248
 
251
249
  // src/validation/duration.ts
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as valibot from 'valibot';
2
- import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input, PipeResult } from 'valibot';
2
+ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input } from 'valibot';
3
3
  export * from 'valibot';
4
4
  import { BigFloat } from '@awsless/big-float';
5
5
  import { UUID } from 'crypto';
@@ -20,7 +20,7 @@ type DateSchema = BaseSchema<string | Date, Date>;
20
20
  declare function date(pipe?: Pipe<Date>): DateSchema;
21
21
  declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
22
22
 
23
- type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
23
+ type UuidSchema = SchemaWithTransform<StringSchema, UUID>;
24
24
  declare const uuid: (error?: ErrorMessage) => UuidSchema;
25
25
 
26
26
  type DurationSchema = BaseSchema<DurationFormat, Duration>;
@@ -43,7 +43,11 @@ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
43
43
  }, Output<S>[]>;
44
44
  declare const snsTopic: <S extends BaseSchema<any, any> = UnknownSchema<unknown>>(body?: S | undefined) => SnsTopicSchema<S>;
45
45
 
46
- type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
46
+ declare enum EventName {
47
+ modify = "MODIFY",
48
+ insert = "INSERT",
49
+ remove = "REMOVE"
50
+ }
47
51
  type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseSchema<{
48
52
  Records: {
49
53
  eventName: EventName;
@@ -61,13 +65,13 @@ type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseS
61
65
  }[]>;
62
66
  declare const dynamoDbStream: <T extends TableDefinition<any, any, any, any>>(table: T) => DynamoDBStreamSchema<T>;
63
67
 
64
- declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
68
+ declare function positive<T extends BigFloat | number>(error?: ErrorMessage): valibot.CustomValidation<T>;
65
69
 
66
- declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
70
+ declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): valibot.CustomValidation<T>;
67
71
 
68
- declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
72
+ declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): valibot.CustomValidation<T>;
69
73
 
70
- declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): (input: T) => valibot.PipeResult<T>;
71
- declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): (input: T) => valibot.PipeResult<T>;
74
+ declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
75
+ declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
72
76
 
73
77
  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,5 +1,5 @@
1
1
  import * as valibot from 'valibot';
2
- import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input, PipeResult } from 'valibot';
2
+ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input } from 'valibot';
3
3
  export * from 'valibot';
4
4
  import { BigFloat } from '@awsless/big-float';
5
5
  import { UUID } from 'crypto';
@@ -20,7 +20,7 @@ type DateSchema = BaseSchema<string | Date, Date>;
20
20
  declare function date(pipe?: Pipe<Date>): DateSchema;
21
21
  declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
22
22
 
23
- type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
23
+ type UuidSchema = SchemaWithTransform<StringSchema, UUID>;
24
24
  declare const uuid: (error?: ErrorMessage) => UuidSchema;
25
25
 
26
26
  type DurationSchema = BaseSchema<DurationFormat, Duration>;
@@ -43,7 +43,11 @@ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S>
43
43
  }, Output<S>[]>;
44
44
  declare const snsTopic: <S extends BaseSchema<any, any> = UnknownSchema<unknown>>(body?: S | undefined) => SnsTopicSchema<S>;
45
45
 
46
- type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
46
+ declare enum EventName {
47
+ modify = "MODIFY",
48
+ insert = "INSERT",
49
+ remove = "REMOVE"
50
+ }
47
51
  type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseSchema<{
48
52
  Records: {
49
53
  eventName: EventName;
@@ -61,13 +65,13 @@ type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseS
61
65
  }[]>;
62
66
  declare const dynamoDbStream: <T extends TableDefinition<any, any, any, any>>(table: T) => DynamoDBStreamSchema<T>;
63
67
 
64
- declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
68
+ declare function positive<T extends BigFloat | number>(error?: ErrorMessage): valibot.CustomValidation<T>;
65
69
 
66
- declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
70
+ declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): valibot.CustomValidation<T>;
67
71
 
68
- declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
72
+ declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): valibot.CustomValidation<T>;
69
73
 
70
- declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): (input: T) => valibot.PipeResult<T>;
71
- declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): (input: T) => valibot.PipeResult<T>;
74
+ declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
75
+ declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): valibot.CustomValidation<T>;
72
76
 
73
77
  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
@@ -21,35 +21,23 @@ var json = (schema) => {
21
21
  import { BigFloat } from "@awsless/big-float";
22
22
  import {
23
23
  bigint,
24
- getDefaultArgs,
24
+ defaultArgs,
25
25
  instance,
26
26
  number,
27
27
  object,
28
28
  string as string2,
29
29
  transform as transform2,
30
30
  union,
31
- getPipeIssues,
32
- getOutput
31
+ custom
33
32
  } from "valibot";
34
33
  var make = (value) => new BigFloat(value);
35
34
  function bigfloat(arg1, arg2) {
36
- const [msg, pipe] = getDefaultArgs(arg1, arg2);
35
+ const [msg, pipe] = defaultArgs(arg1, arg2);
37
36
  const error = msg ?? "Invalid bigfloat";
38
37
  return union(
39
38
  [
40
39
  instance(BigFloat, pipe),
41
- transform2(
42
- string2([
43
- (input) => {
44
- if (input === "" || isNaN(Number(input))) {
45
- return getPipeIssues("bigfloat", error, input);
46
- }
47
- return getOutput(input);
48
- }
49
- ]),
50
- make,
51
- pipe
52
- ),
40
+ transform2(string2([custom((input) => input !== "" && !isNaN(Number(input)), error)]), make, pipe),
53
41
  transform2(number(), make, pipe),
54
42
  transform2(
55
43
  object({
@@ -65,9 +53,9 @@ function bigfloat(arg1, arg2) {
65
53
  }
66
54
 
67
55
  // src/schema/date.ts
68
- import { getDefaultArgs as getDefaultArgs2, date as base, string as string3, union as union2, transform as transform3 } from "valibot";
56
+ import { defaultArgs as defaultArgs2, date as base, string as string3, union as union2, transform as transform3 } from "valibot";
69
57
  function date(arg1, arg2) {
70
- const [error, pipe] = getDefaultArgs2(arg1, arg2);
58
+ const [error, pipe] = defaultArgs2(arg1, arg2);
71
59
  return union2(
72
60
  [
73
61
  base(pipe),
@@ -84,24 +72,24 @@ function date(arg1, arg2) {
84
72
  }
85
73
 
86
74
  // src/schema/uuid.ts
87
- import {
88
- string as string4,
89
- uuid as base2,
90
- transform as transform4
91
- } from "valibot";
75
+ import { string as string4, uuid as base2, transform as transform4 } from "valibot";
92
76
  var uuid = (error) => {
93
77
  return transform4(string4(error ?? "Invalid UUID", [base2()]), (v) => v);
94
78
  };
95
79
 
96
80
  // src/schema/duration.ts
97
- import { getDefaultArgs as getDefaultArgs3, regex, string as string5, transform as transform5 } from "valibot";
81
+ import { defaultArgs as defaultArgs3, regex, string as string5, transform as transform5 } from "valibot";
98
82
  import { parse } from "@awsless/duration";
99
83
  function duration(arg1, arg2) {
100
- const [msg, pipe] = getDefaultArgs3(arg1, arg2);
84
+ const [msg, pipe] = defaultArgs3(arg1, arg2);
101
85
  const error = msg ?? "Invalid duration";
102
86
  return transform5(
103
87
  string5(error, [regex(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/, error)]),
104
- (value) => parse(value),
88
+ (value, { issues }) => {
89
+ if (issues)
90
+ return;
91
+ return parse(value);
92
+ },
105
93
  pipe
106
94
  );
107
95
  }
@@ -159,7 +147,13 @@ var snsTopic = (body) => {
159
147
  };
160
148
 
161
149
  // src/schema/aws/dynamodb-stream.ts
162
- import { array as array3, object as object4, optional, picklist, transform as transform8, unknown as unknown3 } from "valibot";
150
+ import { array as array3, object as object4, optional, enum_, transform as transform8, unknown as unknown3 } from "valibot";
151
+ var EventName = /* @__PURE__ */ ((EventName2) => {
152
+ EventName2["modify"] = "MODIFY";
153
+ EventName2["insert"] = "INSERT";
154
+ EventName2["remove"] = "REMOVE";
155
+ return EventName2;
156
+ })(EventName || {});
163
157
  var dynamoDbStream = (table) => {
164
158
  const marshall = () => transform8(unknown3(), (value) => table.unmarshall(value));
165
159
  return transform8(
@@ -167,7 +161,8 @@ var dynamoDbStream = (table) => {
167
161
  {
168
162
  Records: array3(
169
163
  object4({
170
- eventName: picklist(["MODIFY", "INSERT", "REMOVE"]),
164
+ eventName: enum_(EventName),
165
+ // eventName: picklist(['MODIFY', 'INSERT', 'REMOVE']),
171
166
  dynamodb: object4({
172
167
  Keys: marshall(),
173
168
  OldImage: optional(marshall()),
@@ -194,45 +189,43 @@ var dynamoDbStream = (table) => {
194
189
 
195
190
  // src/validation/positive.ts
196
191
  import { ZERO, gt } from "@awsless/big-float";
197
- import { getOutput as getOutput2, getPipeIssues as getPipeIssues2 } from "valibot";
192
+ import { custom as custom2 } from "valibot";
198
193
  function positive(error) {
199
- return (input) => {
200
- return gt(input, ZERO) ? getOutput2(input) : getPipeIssues2("positive", error ?? "Invalid positive number", input);
201
- };
194
+ return custom2((input) => gt(input, ZERO), error ?? "Invalid positive number");
202
195
  }
203
196
 
204
197
  // src/validation/precision.ts
205
198
  import { BigFloat as BigFloat3 } from "@awsless/big-float";
206
- import { getOutput as getOutput3, getPipeIssues as getPipeIssues3 } from "valibot";
199
+ import { custom as custom3 } from "valibot";
207
200
  function precision(decimals, error) {
208
- return (input) => {
201
+ return custom3((input) => {
209
202
  const big = new BigFloat3(input.toString());
210
- return -big.exponent <= decimals ? getOutput3(input) : getPipeIssues3("precision", error ?? `Invalid ${decimals} precision number`, input);
211
- };
203
+ return -big.exponent <= decimals;
204
+ }, error ?? `Invalid ${decimals} precision number`);
212
205
  }
213
206
 
214
207
  // src/validation/unique.ts
215
- import { getOutput as getOutput4, getPipeIssues as getPipeIssues4 } from "valibot";
208
+ import { custom as custom4 } from "valibot";
216
209
  function unique(compare = (a, b) => a === b, error) {
217
- return (input) => {
210
+ return custom4((input) => {
218
211
  for (const x in input) {
219
212
  for (const y in input) {
220
213
  if (x !== y && compare(input[x], input[y])) {
221
- return getPipeIssues4("unique", error ?? "None unique array", input);
214
+ return false;
222
215
  }
223
216
  }
224
217
  }
225
- return getOutput4(input);
226
- };
218
+ return true;
219
+ }, error ?? "None unique array");
227
220
  }
228
221
 
229
222
  // src/validation/duration.ts
230
- import { custom } from "valibot";
223
+ import { custom as custom5 } from "valibot";
231
224
  function minDuration(min, error) {
232
- return custom((input) => input.value >= min.value, error ?? "Invalid duration");
225
+ return custom5((input) => input.value >= min.value, error ?? "Invalid duration");
233
226
  }
234
227
  function maxDuration(max, error) {
235
- return custom((input) => input.value <= max.value, error ?? "Invalid duration");
228
+ return custom5((input) => input.value <= max.value, error ?? "Invalid duration");
236
229
  }
237
230
  export {
238
231
  bigfloat,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/validate",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -25,16 +25,16 @@
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@awsless/big-float": "^0.0.4",
28
- "@awsless/dynamodb": "^0.0.40",
29
- "@awsless/duration": "^0.0.1"
28
+ "@awsless/duration": "^0.0.1",
29
+ "@awsless/dynamodb": "^0.0.42"
30
30
  },
31
31
  "devDependencies": {
32
+ "@awsless/duration": "^0.0.1",
32
33
  "@awsless/big-float": "^0.0.4",
33
- "@awsless/dynamodb": "^0.0.40",
34
- "@awsless/duration": "^0.0.1"
34
+ "@awsless/dynamodb": "^0.0.42"
35
35
  },
36
36
  "dependencies": {
37
- "valibot": "^0.20.1"
37
+ "valibot": "^0.28.1"
38
38
  },
39
39
  "scripts": {
40
40
  "test": "pnpm code test",