@awsless/validate 0.0.5 → 0.0.7

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
@@ -23,9 +23,12 @@ var src_exports = {};
23
23
  __export(src_exports, {
24
24
  bigfloat: () => bigfloat,
25
25
  date: () => date,
26
+ dynamoDbStream: () => dynamoDbStream,
26
27
  json: () => json,
27
28
  positive: () => positive,
28
29
  precision: () => precision,
30
+ snsTopic: () => snsTopic,
31
+ sqsQueue: () => sqsQueue,
29
32
  unique: () => unique,
30
33
  uuid: () => uuid
31
34
  });
@@ -109,46 +112,135 @@ var uuid = () => {
109
112
  return (0, import_valibot4.transform)((0, import_valibot4.string)([(0, import_valibot4.uuid)()]), (v) => v);
110
113
  };
111
114
 
115
+ // src/schema/aws/sqs-queue.ts
116
+ var import_valibot5 = require("valibot");
117
+ var sqsQueue = (body) => {
118
+ const schema = body ?? (0, import_valibot5.unknown)();
119
+ return (0, import_valibot5.union)(
120
+ [
121
+ (0, import_valibot5.transform)(schema, (input) => [input]),
122
+ (0, import_valibot5.array)(schema),
123
+ (0, import_valibot5.transform)(
124
+ (0, import_valibot5.object)({
125
+ Records: (0, import_valibot5.array)(
126
+ (0, import_valibot5.object)({
127
+ body: json(schema)
128
+ })
129
+ )
130
+ }),
131
+ (input) => input.Records.map((record) => {
132
+ return record.body;
133
+ })
134
+ )
135
+ ],
136
+ "Invalid SQS Queue input"
137
+ );
138
+ };
139
+
140
+ // src/schema/aws/sns-topic.ts
141
+ var import_valibot6 = require("valibot");
142
+ var snsTopic = (body) => {
143
+ const schema = body ?? (0, import_valibot6.unknown)();
144
+ return (0, import_valibot6.union)(
145
+ [
146
+ (0, import_valibot6.transform)(schema, (input) => [input]),
147
+ (0, import_valibot6.array)(schema),
148
+ (0, import_valibot6.transform)(
149
+ (0, import_valibot6.object)({
150
+ Records: (0, import_valibot6.array)(
151
+ (0, import_valibot6.object)({
152
+ Sns: (0, import_valibot6.object)({
153
+ Message: json(schema)
154
+ })
155
+ })
156
+ )
157
+ }),
158
+ (input) => input.Records.map((record) => {
159
+ return record.Sns.Message;
160
+ })
161
+ )
162
+ ],
163
+ "Invalid SNS Topic input"
164
+ );
165
+ };
166
+
167
+ // src/schema/aws/dynamodb-stream.ts
168
+ var import_valibot7 = require("valibot");
169
+ var dynamoDbStream = (table) => {
170
+ const marshall = () => (0, import_valibot7.transform)((0, import_valibot7.unknown)(), (value) => table.unmarshall(value));
171
+ return (0, import_valibot7.transform)(
172
+ (0, import_valibot7.object)(
173
+ {
174
+ Records: (0, import_valibot7.array)(
175
+ (0, import_valibot7.object)({
176
+ eventName: (0, import_valibot7.picklist)(["MODIFY", "INSERT", "REMOVE"]),
177
+ dynamodb: (0, import_valibot7.object)({
178
+ Keys: marshall(),
179
+ OldImage: (0, import_valibot7.optional)(marshall()),
180
+ NewImage: (0, import_valibot7.optional)(marshall())
181
+ })
182
+ })
183
+ )
184
+ },
185
+ "Invalid DynamoDB Stream input"
186
+ ),
187
+ (input) => {
188
+ return input.Records.map((record) => {
189
+ const item = record;
190
+ return {
191
+ event: record.eventName.toLowerCase(),
192
+ keys: item.dynamodb.Keys,
193
+ old: item.dynamodb.OldImage,
194
+ new: item.dynamodb.NewImage
195
+ };
196
+ });
197
+ }
198
+ );
199
+ };
200
+
112
201
  // src/validation/positive.ts
113
202
  var import_big_float2 = require("@awsless/big-float");
114
- var import_valibot5 = require("valibot");
203
+ var import_valibot8 = require("valibot");
115
204
  function positive(error) {
116
205
  return (input) => {
117
- return (0, import_big_float2.gt)(input, import_big_float2.ZERO) ? (0, import_valibot5.getOutput)(input) : (0, import_valibot5.getPipeIssues)("positive", error ?? "Invalid positive number", input);
206
+ return (0, import_big_float2.gt)(input, import_big_float2.ZERO) ? (0, import_valibot8.getOutput)(input) : (0, import_valibot8.getPipeIssues)("positive", error ?? "Invalid positive number", input);
118
207
  };
119
208
  }
120
209
 
121
210
  // src/validation/precision.ts
122
211
  var import_big_float3 = require("@awsless/big-float");
123
- var import_valibot6 = require("valibot");
212
+ var import_valibot9 = require("valibot");
124
213
  function precision(decimals, error) {
125
214
  return (input) => {
126
215
  const big = new import_big_float3.BigFloat(input.toString());
127
- return -big.exponent <= decimals ? (0, import_valibot6.getOutput)(input) : (0, import_valibot6.getPipeIssues)("precision", error ?? `Invalid ${decimals} precision number`, input);
216
+ return -big.exponent <= decimals ? (0, import_valibot9.getOutput)(input) : (0, import_valibot9.getPipeIssues)("precision", error ?? `Invalid ${decimals} precision number`, input);
128
217
  };
129
218
  }
130
219
 
131
220
  // src/validation/unique.ts
132
- var import_valibot7 = require("valibot");
221
+ var import_valibot10 = require("valibot");
133
222
  function unique(compare = (a, b) => a === b, error) {
134
223
  return (input) => {
135
224
  for (const x in input) {
136
225
  for (const y in input) {
137
226
  if (x !== y && compare(input[x], input[y])) {
138
- return (0, import_valibot7.getPipeIssues)("unique", error ?? "None unique array", input);
227
+ return (0, import_valibot10.getPipeIssues)("unique", error ?? "None unique array", input);
139
228
  }
140
229
  }
141
230
  }
142
- return (0, import_valibot7.getOutput)(input);
231
+ return (0, import_valibot10.getOutput)(input);
143
232
  };
144
233
  }
145
234
  // Annotate the CommonJS export names for ESM import in node:
146
235
  0 && (module.exports = {
147
236
  bigfloat,
148
237
  date,
238
+ dynamoDbStream,
149
239
  json,
150
240
  positive,
151
241
  precision,
242
+ snsTopic,
243
+ sqsQueue,
152
244
  unique,
153
245
  uuid,
154
246
  ...require("valibot")
package/dist/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
- import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, PipeResult } from 'valibot';
1
+ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input, PipeResult } from 'valibot';
2
2
  export * from 'valibot';
3
3
  import { BigFloat } from '@awsless/big-float';
4
4
  import { UUID } from 'crypto';
5
+ import { TableDefinition, PrimaryKey } from '@awsless/dynamodb';
5
6
 
6
7
  type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
7
8
  declare const json: <T extends BaseSchema<any, any>>(schema: T) => JsonSchema<T>;
@@ -20,10 +21,44 @@ declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
20
21
  type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
21
22
  declare const uuid: () => UuidSchema;
22
23
 
24
+ type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
25
+ Records: {
26
+ body: string | Input<S>;
27
+ }[];
28
+ }, Output<S>[]>;
29
+ declare const sqsQueue: <S extends BaseSchema<any, any> = UnknownSchema<unknown>>(body?: S | undefined) => SqsQueueSchema<S>;
30
+
31
+ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
32
+ Records: {
33
+ Sns: {
34
+ Message: string | Input<S>;
35
+ };
36
+ }[];
37
+ }, Output<S>[]>;
38
+ declare const snsTopic: <S extends BaseSchema<any, any> = UnknownSchema<unknown>>(body?: S | undefined) => SnsTopicSchema<S>;
39
+
40
+ type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
41
+ type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseSchema<{
42
+ Records: {
43
+ eventName: EventName;
44
+ dynamodb: {
45
+ Keys: unknown;
46
+ OldImage?: unknown;
47
+ NewImage?: unknown;
48
+ };
49
+ }[];
50
+ }, {
51
+ event: Lowercase<EventName>;
52
+ keys: PrimaryKey<T>;
53
+ old?: T['schema']['OUTPUT'];
54
+ new?: T['schema']['OUTPUT'];
55
+ }[]>;
56
+ declare const dynamoDbStream: <T extends TableDefinition<any, any, any, any>>(table: T) => DynamoDBStreamSchema<T>;
57
+
23
58
  declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
24
59
 
25
60
  declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
26
61
 
27
62
  declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
28
63
 
29
- export { bigfloat, date, json, positive, precision, unique, uuid };
64
+ export { BigFloatSchema, DateSchema, DynamoDBStreamSchema, JsonSchema, SnsTopicSchema, SqsQueueSchema, UuidSchema, bigfloat, date, dynamoDbStream, json, positive, precision, snsTopic, sqsQueue, unique, uuid };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, PipeResult } from 'valibot';
1
+ import { BaseSchema, SchemaWithTransform, StringSchema, Output, Pipe, ErrorMessage, UnknownSchema, Input, PipeResult } from 'valibot';
2
2
  export * from 'valibot';
3
3
  import { BigFloat } from '@awsless/big-float';
4
4
  import { UUID } from 'crypto';
5
+ import { TableDefinition, PrimaryKey } from '@awsless/dynamodb';
5
6
 
6
7
  type JsonSchema<T extends BaseSchema> = SchemaWithTransform<StringSchema, Output<T>>;
7
8
  declare const json: <T extends BaseSchema<any, any>>(schema: T) => JsonSchema<T>;
@@ -20,10 +21,44 @@ declare function date(error?: ErrorMessage, pipe?: Pipe<Date>): DateSchema;
20
21
  type UuidSchema = SchemaWithTransform<StringSchema | BaseSchema<UUID>, UUID>;
21
22
  declare const uuid: () => UuidSchema;
22
23
 
24
+ type SqsQueueSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
25
+ Records: {
26
+ body: string | Input<S>;
27
+ }[];
28
+ }, Output<S>[]>;
29
+ declare const sqsQueue: <S extends BaseSchema<any, any> = UnknownSchema<unknown>>(body?: S | undefined) => SqsQueueSchema<S>;
30
+
31
+ type SnsTopicSchema<S extends BaseSchema = UnknownSchema> = BaseSchema<Input<S> | Input<S>[] | {
32
+ Records: {
33
+ Sns: {
34
+ Message: string | Input<S>;
35
+ };
36
+ }[];
37
+ }, Output<S>[]>;
38
+ declare const snsTopic: <S extends BaseSchema<any, any> = UnknownSchema<unknown>>(body?: S | undefined) => SnsTopicSchema<S>;
39
+
40
+ type EventName = 'MODIFY' | 'INSERT' | 'REMOVE';
41
+ type DynamoDBStreamSchema<T extends TableDefinition<any, any, any, any>> = BaseSchema<{
42
+ Records: {
43
+ eventName: EventName;
44
+ dynamodb: {
45
+ Keys: unknown;
46
+ OldImage?: unknown;
47
+ NewImage?: unknown;
48
+ };
49
+ }[];
50
+ }, {
51
+ event: Lowercase<EventName>;
52
+ keys: PrimaryKey<T>;
53
+ old?: T['schema']['OUTPUT'];
54
+ new?: T['schema']['OUTPUT'];
55
+ }[]>;
56
+ declare const dynamoDbStream: <T extends TableDefinition<any, any, any, any>>(table: T) => DynamoDBStreamSchema<T>;
57
+
23
58
  declare function positive<T extends BigFloat | number>(error?: ErrorMessage): (input: T) => PipeResult<T>;
24
59
 
25
60
  declare function precision<T extends BigFloat | number>(decimals: number, error?: ErrorMessage): (input: T) => PipeResult<T>;
26
61
 
27
62
  declare function unique<T extends any[]>(compare?: (a: T[number], b: T[number]) => boolean, error?: ErrorMessage): (input: T) => PipeResult<T>;
28
63
 
29
- export { bigfloat, date, json, positive, precision, unique, uuid };
64
+ export { BigFloatSchema, DateSchema, DynamoDBStreamSchema, JsonSchema, SnsTopicSchema, SqsQueueSchema, UuidSchema, bigfloat, date, dynamoDbStream, json, positive, precision, snsTopic, sqsQueue, unique, uuid };
package/dist/index.js CHANGED
@@ -89,6 +89,92 @@ var uuid = () => {
89
89
  return transform4(string4([base2()]), (v) => v);
90
90
  };
91
91
 
92
+ // src/schema/aws/sqs-queue.ts
93
+ import { array, object as object2, transform as transform5, union as union3, unknown } from "valibot";
94
+ var sqsQueue = (body) => {
95
+ const schema = body ?? unknown();
96
+ return union3(
97
+ [
98
+ transform5(schema, (input) => [input]),
99
+ array(schema),
100
+ transform5(
101
+ object2({
102
+ Records: array(
103
+ object2({
104
+ body: json(schema)
105
+ })
106
+ )
107
+ }),
108
+ (input) => input.Records.map((record) => {
109
+ return record.body;
110
+ })
111
+ )
112
+ ],
113
+ "Invalid SQS Queue input"
114
+ );
115
+ };
116
+
117
+ // src/schema/aws/sns-topic.ts
118
+ import { array as array2, object as object3, transform as transform6, union as union4, unknown as unknown2 } from "valibot";
119
+ var snsTopic = (body) => {
120
+ const schema = body ?? unknown2();
121
+ return union4(
122
+ [
123
+ transform6(schema, (input) => [input]),
124
+ array2(schema),
125
+ transform6(
126
+ object3({
127
+ Records: array2(
128
+ object3({
129
+ Sns: object3({
130
+ Message: json(schema)
131
+ })
132
+ })
133
+ )
134
+ }),
135
+ (input) => input.Records.map((record) => {
136
+ return record.Sns.Message;
137
+ })
138
+ )
139
+ ],
140
+ "Invalid SNS Topic input"
141
+ );
142
+ };
143
+
144
+ // src/schema/aws/dynamodb-stream.ts
145
+ import { array as array3, object as object4, optional, picklist, transform as transform7, unknown as unknown3 } from "valibot";
146
+ var dynamoDbStream = (table) => {
147
+ const marshall = () => transform7(unknown3(), (value) => table.unmarshall(value));
148
+ return transform7(
149
+ object4(
150
+ {
151
+ Records: array3(
152
+ object4({
153
+ eventName: picklist(["MODIFY", "INSERT", "REMOVE"]),
154
+ dynamodb: object4({
155
+ Keys: marshall(),
156
+ OldImage: optional(marshall()),
157
+ NewImage: optional(marshall())
158
+ })
159
+ })
160
+ )
161
+ },
162
+ "Invalid DynamoDB Stream input"
163
+ ),
164
+ (input) => {
165
+ return input.Records.map((record) => {
166
+ const item = record;
167
+ return {
168
+ event: record.eventName.toLowerCase(),
169
+ keys: item.dynamodb.Keys,
170
+ old: item.dynamodb.OldImage,
171
+ new: item.dynamodb.NewImage
172
+ };
173
+ });
174
+ }
175
+ );
176
+ };
177
+
92
178
  // src/validation/positive.ts
93
179
  import { ZERO, gt } from "@awsless/big-float";
94
180
  import { getOutput as getOutput2, getPipeIssues as getPipeIssues2 } from "valibot";
@@ -125,9 +211,12 @@ function unique(compare = (a, b) => a === b, error) {
125
211
  export {
126
212
  bigfloat,
127
213
  date,
214
+ dynamoDbStream,
128
215
  json,
129
216
  positive,
130
217
  precision,
218
+ snsTopic,
219
+ sqsQueue,
131
220
  unique,
132
221
  uuid
133
222
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/validate",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -24,10 +24,12 @@
24
24
  }
25
25
  },
26
26
  "peerDependencies": {
27
- "@awsless/big-float": "^0.0.4"
27
+ "@awsless/big-float": "^0.0.4",
28
+ "@awsless/dynamodb": "^0.0.40"
28
29
  },
29
30
  "devDependencies": {
30
- "@awsless/big-float": "^0.0.4"
31
+ "@awsless/big-float": "^0.0.4",
32
+ "@awsless/dynamodb": "^0.0.40"
31
33
  },
32
34
  "dependencies": {
33
35
  "valibot": "^0.20.1"