diff --git a/src/lib/aws/firehose/firehose.schema.ts b/src/lib/aws/firehose/firehose.schema.ts new file mode 100644 index 0000000..547036b --- /dev/null +++ b/src/lib/aws/firehose/firehose.schema.ts @@ -0,0 +1,29 @@ +import { $array, $integer, $object, $optional, $ref, $string, $validator } from '@skyleague/therefore' + +export const firehoseRecordMetadata = $object({ + shardId: $string, + partitionKey: $string, + approximateArrivalTimestamp: $integer, + sequenceNumber: $string, + subsequenceNumber: $string, +}) + +export const firehoseTransformationEventRecord = $validator( + $object({ + recordId: $string, + approximateArrivalTimestamp: $integer, + // Base64 encoded + data: $string, + kinesisRecordMetadata: $optional($ref(firehoseRecordMetadata), 'explicit'), + }) +) + +export const firehoseTransformationEvent = $validator( + $object({ + invocationId: $string, + deliveryStreamArn: $string, + sourceKinesisStreamArn: $optional($string, 'explicit'), + region: $string, + records: $array($ref(firehoseTransformationEventRecord)), + }) +) diff --git a/src/lib/aws/firehose/firehose.spec.ts b/src/lib/aws/firehose/firehose.spec.ts new file mode 100644 index 0000000..c319826 --- /dev/null +++ b/src/lib/aws/firehose/firehose.spec.ts @@ -0,0 +1,8 @@ +import type { FirehoseTransformationEvent } from './firehose.type' + +import type { FirehoseTransformationEvent as LambdaFirehoseTransformationEvent } from 'aws-lambda' + +test('type is compatible', () => { + const _test: FirehoseTransformationEvent = {} as unknown as LambdaFirehoseTransformationEvent + const _test2: LambdaFirehoseTransformationEvent = {} as unknown as FirehoseTransformationEvent +}) diff --git a/src/lib/aws/firehose/firehose.type.ts b/src/lib/aws/firehose/firehose.type.ts new file mode 100644 index 0000000..ddf200e --- /dev/null +++ b/src/lib/aws/firehose/firehose.type.ts @@ -0,0 +1,63 @@ +/** + * Generated by @skyleague/therefore@v1.0.0-local + * Do not manually touch this + */ +/* eslint-disable */ +import AjvValidator from 'ajv' +import type { ValidateFunction } from 'ajv' + +export interface FirehoseRecordMetadata { + shardId: string + partitionKey: string + approximateArrivalTimestamp: number + sequenceNumber: string + subsequenceNumber: string +} + +export interface FirehoseTransformationEventRecord { + recordId: string + approximateArrivalTimestamp: number + data: string + kinesisRecordMetadata?: FirehoseRecordMetadata | undefined +} + +export const FirehoseTransformationEventRecord = { + validate: + require('./schemas/firehose-transformation-event-record.schema.js') as ValidateFunction, + get schema() { + return FirehoseTransformationEventRecord.validate.schema + }, + get errors() { + return FirehoseTransformationEventRecord.validate.errors ?? undefined + }, + is: (o: unknown): o is FirehoseTransformationEventRecord => FirehoseTransformationEventRecord.validate(o) === true, + assert: (o: unknown) => { + if (!FirehoseTransformationEventRecord.validate(o)) { + throw new AjvValidator.ValidationError(FirehoseTransformationEventRecord.errors ?? []) + } + }, +} as const + +export interface FirehoseTransformationEvent { + invocationId: string + deliveryStreamArn: string + sourceKinesisStreamArn?: string | undefined + region: string + records: FirehoseTransformationEventRecord[] +} + +export const FirehoseTransformationEvent = { + validate: require('./schemas/firehose-transformation-event.schema.js') as ValidateFunction, + get schema() { + return FirehoseTransformationEvent.validate.schema + }, + get errors() { + return FirehoseTransformationEvent.validate.errors ?? undefined + }, + is: (o: unknown): o is FirehoseTransformationEvent => FirehoseTransformationEvent.validate(o) === true, + assert: (o: unknown) => { + if (!FirehoseTransformationEvent.validate(o)) { + throw new AjvValidator.ValidationError(FirehoseTransformationEvent.errors ?? []) + } + }, +} as const diff --git a/src/lib/aws/firehose/index.ts b/src/lib/aws/firehose/index.ts new file mode 100644 index 0000000..3a34f8e --- /dev/null +++ b/src/lib/aws/firehose/index.ts @@ -0,0 +1 @@ +export * from './firehose.type' diff --git a/src/lib/aws/firehose/schemas/firehose-transformation-event-record.schema.js b/src/lib/aws/firehose/schemas/firehose-transformation-event-record.schema.js new file mode 100644 index 0000000..f538816 --- /dev/null +++ b/src/lib/aws/firehose/schemas/firehose-transformation-event-record.schema.js @@ -0,0 +1,5 @@ +/** + * Generated by @skyleague/therefore + * eslint-disable + */ +"use strict";module.exports = validate10;module.exports.default = validate10;const schema11 = {"$schema":"http://json-schema.org/draft-07/schema#","title":"FirehoseTransformationEventRecord","type":"object","properties":{"recordId":{"type":"string"},"approximateArrivalTimestamp":{"type":"integer"},"data":{"type":"string"},"kinesisRecordMetadata":{"$ref":"#/$defs/FirehoseRecordMetadata"}},"required":["recordId","approximateArrivalTimestamp","data"],"additionalProperties":true,"$defs":{"FirehoseRecordMetadata":{"type":"object","properties":{"shardId":{"type":"string"},"partitionKey":{"type":"string"},"approximateArrivalTimestamp":{"type":"integer"},"sequenceNumber":{"type":"string"},"subsequenceNumber":{"type":"string"}},"required":["shardId","partitionKey","approximateArrivalTimestamp","sequenceNumber","subsequenceNumber"],"additionalProperties":true,"title":"FirehoseRecordMetadata"}}};const schema12 = {"type":"object","properties":{"shardId":{"type":"string"},"partitionKey":{"type":"string"},"approximateArrivalTimestamp":{"type":"integer"},"sequenceNumber":{"type":"string"},"subsequenceNumber":{"type":"string"}},"required":["shardId","partitionKey","approximateArrivalTimestamp","sequenceNumber","subsequenceNumber"],"additionalProperties":true,"title":"FirehoseRecordMetadata"};function validate10(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((((data.recordId === undefined) && (missing0 = "recordId")) || ((data.approximateArrivalTimestamp === undefined) && (missing0 = "approximateArrivalTimestamp"))) || ((data.data === undefined) && (missing0 = "data"))){validate10.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.recordId !== undefined){const _errs2 = errors;if(typeof data.recordId !== "string"){validate10.errors = [{instancePath:instancePath+"/recordId",schemaPath:"#/properties/recordId/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs2 === errors;}else {var valid0 = true;}if(valid0){if(data.approximateArrivalTimestamp !== undefined){let data1 = data.approximateArrivalTimestamp;const _errs4 = errors;if(!(((typeof data1 == "number") && (!(data1 % 1) && !isNaN(data1))) && (isFinite(data1)))){validate10.errors = [{instancePath:instancePath+"/approximateArrivalTimestamp",schemaPath:"#/properties/approximateArrivalTimestamp/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid0 = _errs4 === errors;}else {var valid0 = true;}if(valid0){if(data.data !== undefined){const _errs6 = errors;if(typeof data.data !== "string"){validate10.errors = [{instancePath:instancePath+"/data",schemaPath:"#/properties/data/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs6 === errors;}else {var valid0 = true;}if(valid0){if(data.kinesisRecordMetadata !== undefined){let data3 = data.kinesisRecordMetadata;const _errs8 = errors;const _errs9 = errors;if(errors === _errs9){if(data3 && typeof data3 == "object" && !Array.isArray(data3)){let missing1;let valid2 = true;for( missing1 of schema12.required){valid2 = data3[missing1] !== undefined;if(!valid2){validate10.errors = [{instancePath:instancePath+"/kinesisRecordMetadata",schemaPath:"#/$defs/FirehoseRecordMetadata/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;break;}}if(valid2){if(data3.shardId !== undefined){const _errs12 = errors;if(typeof data3.shardId !== "string"){validate10.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/shardId",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/shardId/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs12 === errors;}else {var valid3 = true;}if(valid3){if(data3.partitionKey !== undefined){const _errs14 = errors;if(typeof data3.partitionKey !== "string"){validate10.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/partitionKey",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/partitionKey/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs14 === errors;}else {var valid3 = true;}if(valid3){if(data3.approximateArrivalTimestamp !== undefined){let data6 = data3.approximateArrivalTimestamp;const _errs16 = errors;if(!(((typeof data6 == "number") && (!(data6 % 1) && !isNaN(data6))) && (isFinite(data6)))){validate10.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/approximateArrivalTimestamp",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/approximateArrivalTimestamp/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid3 = _errs16 === errors;}else {var valid3 = true;}if(valid3){if(data3.sequenceNumber !== undefined){const _errs18 = errors;if(typeof data3.sequenceNumber !== "string"){validate10.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/sequenceNumber",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/sequenceNumber/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs18 === errors;}else {var valid3 = true;}if(valid3){if(data3.subsequenceNumber !== undefined){const _errs20 = errors;if(typeof data3.subsequenceNumber !== "string"){validate10.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/subsequenceNumber",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/subsequenceNumber/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs20 === errors;}else {var valid3 = true;}}}}}}}else {validate10.errors = [{instancePath:instancePath+"/kinesisRecordMetadata",schemaPath:"#/$defs/FirehoseRecordMetadata/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs8 === errors;}else {var valid0 = true;}}}}}}else {validate10.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate10.errors = vErrors;return errors === 0;};validate10.schema=schema11; \ No newline at end of file diff --git a/src/lib/aws/firehose/schemas/firehose-transformation-event.schema.js b/src/lib/aws/firehose/schemas/firehose-transformation-event.schema.js new file mode 100644 index 0000000..9f6266d --- /dev/null +++ b/src/lib/aws/firehose/schemas/firehose-transformation-event.schema.js @@ -0,0 +1,5 @@ +/** + * Generated by @skyleague/therefore + * eslint-disable + */ +"use strict";module.exports = validate10;module.exports.default = validate10;const schema11 = {"$schema":"http://json-schema.org/draft-07/schema#","title":"FirehoseTransformationEvent","type":"object","properties":{"invocationId":{"type":"string"},"deliveryStreamArn":{"type":"string"},"sourceKinesisStreamArn":{"type":"string"},"region":{"type":"string"},"records":{"type":"array","items":{"$ref":"#/$defs/FirehoseTransformationEventRecord"}}},"required":["invocationId","deliveryStreamArn","region","records"],"additionalProperties":true,"$defs":{"FirehoseTransformationEventRecord":{"type":"object","properties":{"recordId":{"type":"string"},"approximateArrivalTimestamp":{"type":"integer"},"data":{"type":"string"},"kinesisRecordMetadata":{"$ref":"#/$defs/FirehoseRecordMetadata"}},"required":["recordId","approximateArrivalTimestamp","data"],"additionalProperties":true,"title":"FirehoseTransformationEventRecord"},"FirehoseRecordMetadata":{"type":"object","properties":{"shardId":{"type":"string"},"partitionKey":{"type":"string"},"approximateArrivalTimestamp":{"type":"integer"},"sequenceNumber":{"type":"string"},"subsequenceNumber":{"type":"string"}},"required":["shardId","partitionKey","approximateArrivalTimestamp","sequenceNumber","subsequenceNumber"],"additionalProperties":true,"title":"FirehoseRecordMetadata"}}};const schema12 = {"type":"object","properties":{"recordId":{"type":"string"},"approximateArrivalTimestamp":{"type":"integer"},"data":{"type":"string"},"kinesisRecordMetadata":{"$ref":"#/$defs/FirehoseRecordMetadata"}},"required":["recordId","approximateArrivalTimestamp","data"],"additionalProperties":true,"title":"FirehoseTransformationEventRecord"};const schema13 = {"type":"object","properties":{"shardId":{"type":"string"},"partitionKey":{"type":"string"},"approximateArrivalTimestamp":{"type":"integer"},"sequenceNumber":{"type":"string"},"subsequenceNumber":{"type":"string"}},"required":["shardId","partitionKey","approximateArrivalTimestamp","sequenceNumber","subsequenceNumber"],"additionalProperties":true,"title":"FirehoseRecordMetadata"};function validate11(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((((data.recordId === undefined) && (missing0 = "recordId")) || ((data.approximateArrivalTimestamp === undefined) && (missing0 = "approximateArrivalTimestamp"))) || ((data.data === undefined) && (missing0 = "data"))){validate11.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.recordId !== undefined){const _errs2 = errors;if(typeof data.recordId !== "string"){validate11.errors = [{instancePath:instancePath+"/recordId",schemaPath:"#/properties/recordId/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs2 === errors;}else {var valid0 = true;}if(valid0){if(data.approximateArrivalTimestamp !== undefined){let data1 = data.approximateArrivalTimestamp;const _errs4 = errors;if(!(((typeof data1 == "number") && (!(data1 % 1) && !isNaN(data1))) && (isFinite(data1)))){validate11.errors = [{instancePath:instancePath+"/approximateArrivalTimestamp",schemaPath:"#/properties/approximateArrivalTimestamp/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid0 = _errs4 === errors;}else {var valid0 = true;}if(valid0){if(data.data !== undefined){const _errs6 = errors;if(typeof data.data !== "string"){validate11.errors = [{instancePath:instancePath+"/data",schemaPath:"#/properties/data/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs6 === errors;}else {var valid0 = true;}if(valid0){if(data.kinesisRecordMetadata !== undefined){let data3 = data.kinesisRecordMetadata;const _errs8 = errors;const _errs9 = errors;if(errors === _errs9){if(data3 && typeof data3 == "object" && !Array.isArray(data3)){let missing1;let valid2 = true;for( missing1 of schema13.required){valid2 = data3[missing1] !== undefined;if(!valid2){validate11.errors = [{instancePath:instancePath+"/kinesisRecordMetadata",schemaPath:"#/$defs/FirehoseRecordMetadata/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;break;}}if(valid2){if(data3.shardId !== undefined){const _errs12 = errors;if(typeof data3.shardId !== "string"){validate11.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/shardId",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/shardId/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs12 === errors;}else {var valid3 = true;}if(valid3){if(data3.partitionKey !== undefined){const _errs14 = errors;if(typeof data3.partitionKey !== "string"){validate11.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/partitionKey",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/partitionKey/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs14 === errors;}else {var valid3 = true;}if(valid3){if(data3.approximateArrivalTimestamp !== undefined){let data6 = data3.approximateArrivalTimestamp;const _errs16 = errors;if(!(((typeof data6 == "number") && (!(data6 % 1) && !isNaN(data6))) && (isFinite(data6)))){validate11.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/approximateArrivalTimestamp",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/approximateArrivalTimestamp/type",keyword:"type",params:{type: "integer"},message:"must be integer"}];return false;}var valid3 = _errs16 === errors;}else {var valid3 = true;}if(valid3){if(data3.sequenceNumber !== undefined){const _errs18 = errors;if(typeof data3.sequenceNumber !== "string"){validate11.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/sequenceNumber",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/sequenceNumber/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs18 === errors;}else {var valid3 = true;}if(valid3){if(data3.subsequenceNumber !== undefined){const _errs20 = errors;if(typeof data3.subsequenceNumber !== "string"){validate11.errors = [{instancePath:instancePath+"/kinesisRecordMetadata/subsequenceNumber",schemaPath:"#/$defs/FirehoseRecordMetadata/properties/subsequenceNumber/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid3 = _errs20 === errors;}else {var valid3 = true;}}}}}}}else {validate11.errors = [{instancePath:instancePath+"/kinesisRecordMetadata",schemaPath:"#/$defs/FirehoseRecordMetadata/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}var valid0 = _errs8 === errors;}else {var valid0 = true;}}}}}}else {validate11.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate11.errors = vErrors;return errors === 0;}function validate10(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((((data.invocationId === undefined) && (missing0 = "invocationId")) || ((data.deliveryStreamArn === undefined) && (missing0 = "deliveryStreamArn"))) || ((data.region === undefined) && (missing0 = "region"))) || ((data.records === undefined) && (missing0 = "records"))){validate10.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.invocationId !== undefined){const _errs2 = errors;if(typeof data.invocationId !== "string"){validate10.errors = [{instancePath:instancePath+"/invocationId",schemaPath:"#/properties/invocationId/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs2 === errors;}else {var valid0 = true;}if(valid0){if(data.deliveryStreamArn !== undefined){const _errs4 = errors;if(typeof data.deliveryStreamArn !== "string"){validate10.errors = [{instancePath:instancePath+"/deliveryStreamArn",schemaPath:"#/properties/deliveryStreamArn/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs4 === errors;}else {var valid0 = true;}if(valid0){if(data.sourceKinesisStreamArn !== undefined){const _errs6 = errors;if(typeof data.sourceKinesisStreamArn !== "string"){validate10.errors = [{instancePath:instancePath+"/sourceKinesisStreamArn",schemaPath:"#/properties/sourceKinesisStreamArn/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs6 === errors;}else {var valid0 = true;}if(valid0){if(data.region !== undefined){const _errs8 = errors;if(typeof data.region !== "string"){validate10.errors = [{instancePath:instancePath+"/region",schemaPath:"#/properties/region/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs8 === errors;}else {var valid0 = true;}if(valid0){if(data.records !== undefined){let data4 = data.records;const _errs10 = errors;if(errors === _errs10){if(Array.isArray(data4)){var valid1 = true;const len0 = data4.length;for(let i0=0; i0