@@ -4,7 +4,7 @@ import type { KinesisEnvelope } from '../envelopes/kinesis.js';
44import type { DynamoDBMarshalled } from '../helpers/dynamodb.js' ;
55import type { DynamoDBStreamEvent } from '../types/schema.js' ;
66
7- const DynamoDBStreamChangeRecordBase = z . object ( {
7+ const DynamoDBStreamChangeRecordBaseSchema = z . object ( {
88 ApproximateCreationDateTime : z . number ( ) . optional ( ) ,
99 Keys : z . record ( z . string ( ) , z . record ( z . string ( ) , z . any ( ) ) ) ,
1010 NewImage : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
@@ -19,17 +19,16 @@ const DynamoDBStreamChangeRecordBase = z.object({
1919 ] ) ,
2020} ) ;
2121
22- const DynamoDBStreamToKinesisChangeRecord = DynamoDBStreamChangeRecordBase . omit (
23- {
22+ const DynamoDBStreamToKinesisChangeRecordSchema =
23+ DynamoDBStreamChangeRecordBaseSchema . omit ( {
2424 SequenceNumber : true ,
2525 StreamViewType : true ,
26- }
27- ) ;
26+ } ) ;
2827
2928const unmarshallDynamoDBTransform = (
3029 object :
31- | z . infer < typeof DynamoDBStreamChangeRecordBase >
32- | z . infer < typeof DynamoDBStreamToKinesisChangeRecord > ,
30+ | z . infer < typeof DynamoDBStreamChangeRecordBaseSchema >
31+ | z . infer < typeof DynamoDBStreamToKinesisChangeRecordSchema > ,
3332 ctx : z . RefinementCtx
3433) => {
3534 const result = { ...object } ;
@@ -73,24 +72,23 @@ const unmarshallDynamoDBTransform = (
7372 return result ;
7473} ;
7574
76- const DynamoDBStreamChangeRecord = DynamoDBStreamChangeRecordBase . transform (
77- unmarshallDynamoDBTransform
78- ) ;
75+ const DynamoDBStreamChangeRecordSchema =
76+ DynamoDBStreamChangeRecordBaseSchema . transform ( unmarshallDynamoDBTransform ) ;
7977
80- const UserIdentity = z . object ( {
78+ const UserIdentitySchema = z . object ( {
8179 type : z . enum ( [ 'Service' ] ) ,
8280 principalId : z . literal ( 'dynamodb.amazonaws.com' ) ,
8381} ) ;
8482
85- const DynamoDBStreamRecord = z . object ( {
83+ const DynamoDBStreamRecordSchema = z . object ( {
8684 eventID : z . string ( ) ,
8785 eventName : z . enum ( [ 'INSERT' , 'MODIFY' , 'REMOVE' ] ) ,
8886 eventVersion : z . string ( ) ,
8987 eventSource : z . literal ( 'aws:dynamodb' ) ,
9088 awsRegion : z . string ( ) ,
9189 eventSourceARN : z . string ( ) ,
92- dynamodb : DynamoDBStreamChangeRecord ,
93- userIdentity : UserIdentity . optional ( ) ,
90+ dynamodb : DynamoDBStreamChangeRecordSchema ,
91+ userIdentity : UserIdentitySchema . optional ( ) ,
9492} ) ;
9593
9694/**
@@ -135,11 +133,11 @@ const DynamoDBStreamRecord = z.object({
135133 * type CustomEvent = z.infer<typeof CustomSchema>;
136134 * ```
137135 */
138- const DynamoDBStreamToKinesisRecord = DynamoDBStreamRecord . extend ( {
136+ const DynamoDBStreamToKinesisRecordSchema = DynamoDBStreamRecordSchema . extend ( {
139137 recordFormat : z . literal ( 'application/json' ) ,
140138 tableName : z . string ( ) ,
141- userIdentity : UserIdentity . nullish ( ) ,
142- dynamodb : DynamoDBStreamToKinesisChangeRecord . transform (
139+ userIdentity : UserIdentitySchema . nullish ( ) ,
140+ dynamodb : DynamoDBStreamToKinesisChangeRecordSchema . transform (
143141 unmarshallDynamoDBTransform
144142 ) ,
145143} ) . omit ( {
@@ -256,8 +254,8 @@ const DynamoDBStreamToKinesisRecord = DynamoDBStreamRecord.extend({
256254 * @see {@link DynamoDBStreamEvent | DynamoDBStreamEvent }
257255 * @see {@link https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html }
258256 */
259- const DynamoDBStreamSchema = z . object ( {
260- Records : z . array ( DynamoDBStreamRecord ) . nonempty ( ) ,
257+ const DynamoDBStreamSchemaSchema = z . object ( {
258+ Records : z . array ( DynamoDBStreamRecordSchema ) . nonempty ( ) ,
261259 window : z
262260 . object ( {
263261 start : z . iso . datetime ( ) ,
@@ -272,11 +270,11 @@ const DynamoDBStreamSchema = z.object({
272270} ) ;
273271
274272export {
275- DynamoDBStreamToKinesisRecord ,
276- DynamoDBStreamToKinesisChangeRecord ,
277- DynamoDBStreamSchema ,
278- DynamoDBStreamRecord ,
279- DynamoDBStreamChangeRecord ,
280- DynamoDBStreamChangeRecordBase ,
281- UserIdentity ,
273+ DynamoDBStreamToKinesisRecordSchema as DynamoDBStreamToKinesisRecord ,
274+ DynamoDBStreamToKinesisChangeRecordSchema as DynamoDBStreamToKinesisChangeRecord ,
275+ DynamoDBStreamSchemaSchema as DynamoDBStreamSchema ,
276+ DynamoDBStreamRecordSchema as DynamoDBStreamRecord ,
277+ DynamoDBStreamChangeRecordSchema as DynamoDBStreamChangeRecord ,
278+ DynamoDBStreamChangeRecordBaseSchema as DynamoDBStreamChangeRecordBase ,
279+ UserIdentitySchema as UserIdentity ,
282280} ;
0 commit comments