@awsless/validate 0.0.8 → 0.0.10

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
@@ -119,17 +119,12 @@ var uuid = (error) => {
119
119
  var import_valibot5 = require("valibot");
120
120
  var import_duration = require("@awsless/duration");
121
121
  function duration(arg1, arg2) {
122
- const [error, pipe] = (0, import_valibot5.getDefaultArgs)(arg1, arg2);
123
- return (0, import_valibot5.union)(
124
- [
125
- (0, import_valibot5.transform)(
126
- (0, import_valibot5.string)([(0, import_valibot5.regex)(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/)]),
127
- (value) => (0, import_duration.parse)(value),
128
- pipe
129
- ),
130
- (0, import_valibot5.instance)(import_duration.Duration, pipe)
131
- ],
132
- error ?? "Invalid duration"
122
+ const [msg, pipe] = (0, import_valibot5.getDefaultArgs)(arg1, arg2);
123
+ const error = msg ?? "Invalid duration";
124
+ return (0, import_valibot5.transform)(
125
+ (0, import_valibot5.string)(error, [(0, import_valibot5.regex)(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/, error)]),
126
+ (value) => (0, import_duration.parse)(value),
127
+ pipe
133
128
  );
134
129
  }
135
130
 
@@ -256,14 +251,10 @@ function unique(compare = (a, b) => a === b, error) {
256
251
  // src/validation/duration.ts
257
252
  var import_valibot12 = require("valibot");
258
253
  function minDuration(min, error) {
259
- return (input) => {
260
- return input.value >= min.value ? (0, import_valibot12.getOutput)(input) : (0, import_valibot12.getPipeIssues)("min-duration", error ?? "Invalid duration", input);
261
- };
254
+ return (0, import_valibot12.custom)((input) => input.value >= min.value, error ?? "Invalid duration");
262
255
  }
263
256
  function maxDuration(max, error) {
264
- return (input) => {
265
- return input.value <= max.value ? (0, import_valibot12.getOutput)(input) : (0, import_valibot12.getPipeIssues)("max-duration", error ?? "Invalid duration", input);
266
- };
257
+ return (0, import_valibot12.custom)((input) => input.value <= max.value, error ?? "Invalid duration");
267
258
  }
268
259
  // Annotate the CommonJS export names for ESM import in node:
269
260
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnionSchema, InstanceSchema, UnknownSchema, Input, PipeResult } from 'valibot';
1
+ import * as valibot from 'valibot';
2
+ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input, PipeResult } from 'valibot';
2
3
  export * from 'valibot';
3
4
  import { BigFloat } from '@awsless/big-float';
4
5
  import { UUID } from 'crypto';
@@ -22,10 +23,7 @@ declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
22
23
  type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
23
24
  declare const uuid: (error?: ErrorMessage) => UuidSchema;
24
25
 
25
- type DurationSchema = UnionSchema<[
26
- SchemaWithTransform<StringSchema | BaseSchema<DurationFormat, Duration>, Duration>,
27
- InstanceSchema<typeof Duration>
28
- ], Duration>;
26
+ type DurationSchema = BaseSchema<DurationFormat, Duration>;
29
27
  declare function duration(pipe?: Pipe<Duration>): DurationSchema;
30
28
  declare function duration(error?: ErrorMessage, pipe?: Pipe<Duration>): DurationSchema;
31
29
 
@@ -69,7 +67,7 @@ declare function precision<T extends BigFloat | number>(decimals: number, error?
69
67
 
70
68
  declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
71
69
 
72
- declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): (input: T) => PipeResult<T>;
73
- declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): (input: T) => PipeResult<T>;
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
72
 
75
73
  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,4 +1,5 @@
1
- import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnionSchema, InstanceSchema, UnknownSchema, Input, PipeResult } from 'valibot';
1
+ import * as valibot from 'valibot';
2
+ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input, PipeResult } from 'valibot';
2
3
  export * from 'valibot';
3
4
  import { BigFloat } from '@awsless/big-float';
4
5
  import { UUID } from 'crypto';
@@ -22,10 +23,7 @@ declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
22
23
  type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
23
24
  declare const uuid: (error?: ErrorMessage) => UuidSchema;
24
25
 
25
- type DurationSchema = UnionSchema<[
26
- SchemaWithTransform<StringSchema | BaseSchema<DurationFormat, Duration>, Duration>,
27
- InstanceSchema<typeof Duration>
28
- ], Duration>;
26
+ type DurationSchema = BaseSchema<DurationFormat, Duration>;
29
27
  declare function duration(pipe?: Pipe<Duration>): DurationSchema;
30
28
  declare function duration(error?: ErrorMessage, pipe?: Pipe<Duration>): DurationSchema;
31
29
 
@@ -69,7 +67,7 @@ declare function precision<T extends BigFloat | number>(decimals: number, error?
69
67
 
70
68
  declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
71
69
 
72
- declare function minDuration<T extends Duration>(min: Duration, error?: ErrorMessage): (input: T) => PipeResult<T>;
73
- declare function maxDuration<T extends Duration>(max: Duration, error?: ErrorMessage): (input: T) => PipeResult<T>;
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
72
 
75
73
  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
@@ -94,35 +94,23 @@ var uuid = (error) => {
94
94
  };
95
95
 
96
96
  // src/schema/duration.ts
97
- import {
98
- getDefaultArgs as getDefaultArgs3,
99
- instance as instance2,
100
- regex,
101
- string as string5,
102
- transform as transform5,
103
- union as union3
104
- } from "valibot";
105
- import { Duration, parse } from "@awsless/duration";
97
+ import { getDefaultArgs as getDefaultArgs3, regex, string as string5, transform as transform5 } from "valibot";
98
+ import { parse } from "@awsless/duration";
106
99
  function duration(arg1, arg2) {
107
- const [error, pipe] = getDefaultArgs3(arg1, arg2);
108
- return union3(
109
- [
110
- transform5(
111
- string5([regex(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/)]),
112
- (value) => parse(value),
113
- pipe
114
- ),
115
- instance2(Duration, pipe)
116
- ],
117
- error ?? "Invalid duration"
100
+ const [msg, pipe] = getDefaultArgs3(arg1, arg2);
101
+ const error = msg ?? "Invalid duration";
102
+ return transform5(
103
+ string5(error, [regex(/^[0-9]+ (milliseconds?|seconds?|minutes?|hours?|days?)/, error)]),
104
+ (value) => parse(value),
105
+ pipe
118
106
  );
119
107
  }
120
108
 
121
109
  // src/schema/aws/sqs-queue.ts
122
- import { array, object as object2, transform as transform6, union as union4, unknown } from "valibot";
110
+ import { array, object as object2, transform as transform6, union as union3, unknown } from "valibot";
123
111
  var sqsQueue = (body) => {
124
112
  const schema = body ?? unknown();
125
- return union4(
113
+ return union3(
126
114
  [
127
115
  transform6(schema, (input) => [input]),
128
116
  array(schema),
@@ -144,10 +132,10 @@ var sqsQueue = (body) => {
144
132
  };
145
133
 
146
134
  // src/schema/aws/sns-topic.ts
147
- import { array as array2, object as object3, transform as transform7, union as union5, unknown as unknown2 } from "valibot";
135
+ import { array as array2, object as object3, transform as transform7, union as union4, unknown as unknown2 } from "valibot";
148
136
  var snsTopic = (body) => {
149
137
  const schema = body ?? unknown2();
150
- return union5(
138
+ return union4(
151
139
  [
152
140
  transform7(schema, (input) => [input]),
153
141
  array2(schema),
@@ -239,16 +227,12 @@ function unique(compare = (a, b) => a === b, error) {
239
227
  }
240
228
 
241
229
  // src/validation/duration.ts
242
- import { getOutput as getOutput5, getPipeIssues as getPipeIssues5 } from "valibot";
230
+ import { custom } from "valibot";
243
231
  function minDuration(min, error) {
244
- return (input) => {
245
- return input.value >= min.value ? getOutput5(input) : getPipeIssues5("min-duration", error ?? "Invalid duration", input);
246
- };
232
+ return custom((input) => input.value >= min.value, error ?? "Invalid duration");
247
233
  }
248
234
  function maxDuration(max, error) {
249
- return (input) => {
250
- return input.value <= max.value ? getOutput5(input) : getPipeIssues5("max-duration", error ?? "Invalid duration", input);
251
- };
235
+ return custom((input) => input.value <= max.value, error ?? "Invalid duration");
252
236
  }
253
237
  export {
254
238
  bigfloat,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/validate",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@awsless/big-float": "^0.0.4",
33
- "@awsless/duration": "^0.0.1",
34
- "@awsless/dynamodb": "^0.0.40"
33
+ "@awsless/dynamodb": "^0.0.40",
34
+ "@awsless/duration": "^0.0.1"
35
35
  },
36
36
  "dependencies": {
37
37
  "valibot": "^0.20.1"