repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessorBuilder.withDifferenceHashing | public withDifferenceHashing(differenceHashing: boolean): HashingImageProcessorBuilder {
this.providerProps.differenceHashing = differenceHashing;
return (this);
} | /**
* Sets whether to compute the difference hash of images.
* @default true
* @param differenceHashing whether to compute the difference hash of images.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L92-L95 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessorBuilder.withWaveletHashing | public withWaveletHashing(waveletHashing: boolean): HashingImageProcessorBuilder {
this.providerProps.waveletHashing = waveletHashing;
return (this);
} | /**
* Sets whether to compute the wavelet hash of images.
* @default true
* @param waveletHashing whether to compute the wavelet hash of images.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L103-L106 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessorBuilder.withColorHashing | public withColorHashing(colorHashing: boolean): HashingImageProcessorBuilder {
this.providerProps.colorHashing = colorHashing;
return (this);
} | /**
* Sets whether to compute the color hash of images.
* @default true
* @param colorHashing whether to compute the color hash of images.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L114-L117 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessorBuilder.build | public build(): HashingImageProcessor {
return (new HashingImageProcessor(
this.scope,
this.identifier, {
...this.providerProps as HashingImageProcessorProps,
...this.props
}
));
} | /**
* @returns a new instance of the `HashingImageProcessor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L123-L131 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessor.constructor | constructor(scope: Construct, id: string, private props: HashingImageProcessorProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
3 * PROCESSING_TIMEOUT.toSeconds()
)
});
// Validating the properties.
this.props = this.parse(HashingImageProcessorPropsSchema, props);
///////////////////////////////////////////
/////// Processing Function ///////
///////////////////////////////////////////
this.eventProcessor = new lambda.DockerImageFunction(this, 'Compute', {
description: 'Computes the hashes of images using different algorithms.',
code: lambda.DockerImageCode.fromImageAsset(
path.resolve(__dirname, 'lambdas', 'processor')
),
vpc: this.props.vpc,
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
architecture: lambda.Architecture.X86_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
LAKECHAIN_CACHE_STORAGE: this.props.cacheStorage.id(),
AVERAGE_HASHING: this.props.averageHashing ? 'true' : 'false',
PERCEPTUAL_HASHING: this.props.perceptualHashing ? 'true' : 'false',
DIFFERENCE_HASHING: this.props.differenceHashing ? 'true' : 'false',
WAVELET_HASHING: this.props.waveletHashing ? 'true' : 'false',
COLOR_HASHING: this.props.colorHashing ? 'true' : 'false'
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.eventProcessor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.eventProcessor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: this.props.batchSize ?? 1,
reportBatchItemFailures: true
}));
// Function permissions.
this.eventBus.grantPublish(this.eventProcessor);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L153-L211 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
// Since this middleware simply passes through the data
// from the previous middleware, we grant any subsequent
// middlewares in the pipeline read access to the
// data of all source middlewares.
for (const source of this.sources) {
source.grantReadProcessedDocuments(grantee);
}
return ({} as iam.Grant);
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L217-L226 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'image/jpeg',
'image/png',
'image/bmp',
'image/webp'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L232-L239 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessor.supportedOutputTypes | supportedOutputTypes(): string[] {
return (this.supportedInputTypes());
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L245-L247 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L253-L257 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | HashingImageProcessor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/hashing-image-processor/src/index.ts#L266-L271 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessorBuilder.withLayers | public withLayers(...layers: LayerOperation[]) {
this.providerProps.layers = layers;
return (this);
} | /**
* Specifies the layer operation to apply on
* the image.
* @param layers the layer operation to apply.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L71-L74 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessorBuilder.build | public build(): ImageLayerProcessor {
return (new ImageLayerProcessor(
this.scope,
this.identifier, {
...this.providerProps as ImageLayerProcessorProps,
...this.props
}
));
} | /**
* @returns a new instance of the `ImageLayerProcessor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L80-L88 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessor.constructor | constructor(scope: Construct, id: string, private props: ImageLayerProcessorProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
6 * PROCESSING_TIMEOUT.toSeconds()
)
});
// Validating the properties.
this.props = this.parse(ImageLayerProcessorPropsSchema, props);
///////////////////////////////////////////
//////// Processing Storage ///////
///////////////////////////////////////////
this.storage = new CacheStorage(this, 'Storage', {
encryptionKey: this.props.kmsKey
});
///////////////////////////////////////////
/////// Processing Function ///////
///////////////////////////////////////////
this.eventProcessor = new lambda.DockerImageFunction(this, 'Compute', {
description: 'Highlights faces and objects on images.',
code: lambda.DockerImageCode.fromImageAsset(
path.resolve(__dirname, 'lambdas', 'filter-processor')
),
vpc: this.props.vpc,
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
architecture: lambda.Architecture.X86_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
LAKECHAIN_CACHE_STORAGE: this.props.cacheStorage.id(),
PROCESSED_FILES_BUCKET: this.storage.id(),
FILTERS: JSON.stringify(this.props.layers)
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.eventProcessor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.eventProcessor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: this.props.batchSize ?? 10,
reportBatchItemFailures: true
}));
// Function permissions.
this.eventBus.grantPublish(this.eventProcessor);
this.storage.grantWrite(this.eventProcessor);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L115-L179 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
return (this.storage.grantRead(grantee));
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L185-L187 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'image/jpeg',
'image/png',
'image/tiff',
'image/webp'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L193-L200 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessor.supportedOutputTypes | supportedOutputTypes(): string[] {
return ([
'image/jpeg',
'image/png',
'image/bmp',
'image/gif'
]);
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L206-L213 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L219-L223 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageLayerProcessor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-layer-processor/src/index.ts#L232-L237 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageMetadataExtractorBuilder.build | public build(): ImageMetadataExtractor {
return (new ImageMetadataExtractor(
this.scope,
this.identifier, {
...this.props
}
));
} | /**
* @returns a new instance of the `ImageMetadataExtractor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/index.ts#L74-L81 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageMetadataExtractor.constructor | constructor(scope: Construct, id: string, private props: MiddlewareProps) {
super(scope, id, description, props);
///////////////////////////////////////////
/////// Processing Function ///////
///////////////////////////////////////////
this.eventProcessor = new node.NodejsFunction(this, 'Compute', {
description: 'A function extracting metadata from images.',
entry: path.resolve(__dirname, 'lambdas', 'metadata-extractor', 'index.js'),
vpc: this.props.vpc,
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn
},
layers: [
SharpLayer.arm64(this, 'SharpLayer')
],
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-s3',
'@aws-sdk/client-sns',
'sharp'
]
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.eventProcessor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.eventProcessor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: props.batchSize ?? 5,
reportBatchItemFailures: true
}));
// Function permissions.
this.eventBus.grantPublish(this.eventProcessor);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/index.ts#L103-L157 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageMetadataExtractor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
// Since this middleware simply passes through the data
// from the previous middleware, we grant any subsequent
// middlewares in the pipeline read access to the
// data of all source middlewares.
for (const source of this.sources) {
source.grantReadProcessedDocuments(grantee);
}
return ({} as iam.Grant);
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/index.ts#L163-L172 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageMetadataExtractor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'image/jpeg',
'image/png',
'image/tiff',
'image/webp',
'image/gif',
'image/avif'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/index.ts#L178-L187 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageMetadataExtractor.supportedOutputTypes | supportedOutputTypes(): string[] {
return (this.supportedInputTypes());
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/index.ts#L193-L195 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageMetadataExtractor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/index.ts#L201-L205 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ImageMetadataExtractor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/index.ts#L214-L219 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getAuthors | const getAuthors = (exif: any): string[] => {
if (exif) {
if (typeof exif.creator === 'string') {
return ([exif.creator.trim()]);
}
if (typeof exif.Artist === 'string') {
return ([exif.Artist.trim()]);
}
}
return ([]);
}; | /**
* @param exif the EXIF data to extract the authors from.
* @returns the authors of the image if found in
* the EXIF data, an empty array otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L41-L52 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getKeywords | const getKeywords = (exif: any): string[] => {
if (exif && Array.isArray(exif.subject)) {
return (exif.subject.map((keyword: string) => keyword.trim()));
}
return ([]);
}; | /**
* @param exif the EXIF data to extract the keywords from.
* @returns the keywords of the image if found in
* the EXIF data, an empty array otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L59-L64 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getCreatedAt | const getCreatedAt = (exif: any): Date | null => {
try {
if (exif && typeof exif.CreateDate === 'string') {
return (new Date(exif.CreateDate));
}
return (null);
} catch (err) {
return (null);
}
}; | /**
* @param exif the EXIF data to extract the creation date from.
* @returns the creation date of the image if found in
* the EXIF data, null otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L71-L80 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getUpdatedAt | const getUpdatedAt = (exif: any): Date | null => {
try {
if (exif && typeof exif.ModifyDate === 'string') {
return (new Date(exif.ModifyDate));
}
return (null);
} catch (err) {
return (null);
}
}; | /**
* @param exif the EXIF data to extract the update date from.
* @returns the latest update date of the image if found in
* the EXIF data, null otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L87-L96 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getTitle | const getTitle = (exif: any): string | null => {
if (exif && typeof exif.Title === 'object' && typeof exif.Title.value === 'string') {
return (exif.Title.value.trim());
}
return (null);
}; | /**
* Attempts to infer the title of the document by looking
* at its metadata.
* @param exif the EXIF data to extract the title from.
* @returns the title of the image if found in
* the EXIF data, null otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L105-L110 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getDescription | const getDescription = (exif: any): string | null => {
if (exif) {
if (typeof exif.ImageDescription === 'string') {
return (exif.ImageDescription.trim());
}
if (typeof exif.Headline === 'string') {
return (exif.Headline.trim());
}
if (typeof exif.description === 'object' && typeof exif.description.value === 'string') {
return (exif.description.value.trim());
}
}
return (null);
}; | /**
* @param exif the EXIF data to extract the description from.
* @returns the textual description of the image if found in
* the EXIF data, null otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L117-L132 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getGeolocation | const getGeolocation = (exif: any): Geolocation | null => {
if (exif?.latitude && exif?.longitude) {
return ({
latitude: exif.latitude,
longitude: exif.longitude
});
}
return (null);
}; | /**
* @param exif the EXIF data to extract the geolocation from.
* @returns the geolocation of the image if found in
* the EXIF data, null otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L139-L147 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getExifTags | const getExifTags = (exif: any): any => {
if (exif) {
return (Object.fromEntries(
Object
.entries(exif)
.filter(([key]) => exifTags.includes(key))
));
}
return ({});
}; | /**
* @param exif the EXIF data to extract the EXIF tags from.
* @returns the EXIF tags of the image if found in
* the EXIF data, an empty object otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L154-L163 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getVibrantColor | const getVibrantColor = async (image: Buffer): Promise<Color | undefined> => {
try {
const { value } = await getAverageColor(image);
return ({
red: value[0],
green: value[1],
blue: value[2]
});
} catch (err) {
return (undefined);
}
}; | /**
* @param image the buffer containing the image
* to extract the vibrant colors from.
* @returns the vibrant colors of the image if found in
* the EXIF data, an undefined value otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L171-L182 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SQSEvent, _: Context): Promise<SQSBatchResponse> {
return (await processPartialResponse(
event,
(record: SQSRecord) => this.processEvent(
CloudEvent.from(JSON.parse(record.body))
),
processor
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/image-metadata-extractor/src/lambdas/metadata-extractor/index.ts#L72-L80 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessorBuilder.withDepth | public withDepth(depth: Depth): LaplacianImageProcessorBuilder {
this.providerProps.depth = depth;
return (this);
} | /**
* Sets the depth level to apply when computing
* the Laplacian variance.
* @param depth the depth level.
* @default Depth.CV_64F
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L72-L75 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessorBuilder.withKernelSize | public withKernelSize(kernelSize: number): LaplacianImageProcessorBuilder {
this.providerProps.kernelSize = kernelSize;
return (this);
} | /**
* Sets the kernel size to apply when computing
* the Laplacian variance.
* @param kernelSize the kernel size.
* @default 3
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L84-L87 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessorBuilder.build | public build(): LaplacianImageProcessor {
return (new LaplacianImageProcessor(
this.scope,
this.identifier, {
...this.providerProps as LaplacianImageProcessorProps,
...this.props
}
));
} | /**
* @returns a new instance of the `LaplacianImageProcessor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L93-L101 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessor.constructor | constructor(scope: Construct, id: string, private props: LaplacianImageProcessorProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
3 * PROCESSING_TIMEOUT.toSeconds()
)
});
// Validating the properties.
this.props = this.parse(LaplacianImageProcessorPropsSchema, props);
///////////////////////////////////////////
/////// Processing Function ///////
///////////////////////////////////////////
this.eventProcessor = new lambda.DockerImageFunction(this, 'Compute', {
description: 'Computes the Laplacian variance of images',
code: lambda.DockerImageCode.fromImageAsset(
path.resolve(__dirname, 'lambdas', 'processor')
),
vpc: this.props.vpc,
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
architecture: lambda.Architecture.X86_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
LAKECHAIN_CACHE_STORAGE: this.props.cacheStorage.id(),
DEPTH: `${this.props.depth}`,
KERNEL_SIZE: `${this.props.kernelSize}`
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.eventProcessor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.eventProcessor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: this.props.batchSize ?? 2,
reportBatchItemFailures: true
}));
// Function permissions.
this.eventBus.grantPublish(this.eventProcessor);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L123-L178 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
// Since this middleware simply passes through the data
// from the previous middleware, we grant any subsequent
// middlewares in the pipeline read access to the
// data of all source middlewares.
for (const source of this.sources) {
source.grantReadProcessedDocuments(grantee);
}
return ({} as iam.Grant);
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L184-L193 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'image/jpeg',
'image/png',
'image/bmp',
'image/webp'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L199-L206 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessor.supportedOutputTypes | supportedOutputTypes(): string[] {
return (this.supportedInputTypes());
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L212-L214 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L220-L224 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LaplacianImageProcessor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/laplacian-image-processor/src/index.ts#L233-L238 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessorBuilder.withIntent | public withIntent(intent: Intent) {
this.providerProps.intent = intent;
return (this);
} | /**
* @param intent the detection intent to apply.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L74-L77 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessorBuilder.build | public build(): RekognitionImageProcessor {
return (new RekognitionImageProcessor(
this.scope,
this.identifier, {
...this.providerProps as RekognitionImageProcessorProps,
...this.props
}
));
} | /**
* @returns a new instance of the `RekognitionImageProcessor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L83-L91 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessor.constructor | constructor(scope: Construct, id: string, private props: RekognitionImageProcessorProps) {
super(scope, id, description, props);
// Validating the properties.
this.props = this.parse(RekognitionImageProcessorSchema, props);
///////////////////////////////////////////
/////// Processing Function ///////
///////////////////////////////////////////
this.eventProcessor = new node.NodejsFunction(this, 'Compute', {
description: 'Analyzes images using Amazon Rekognition.',
entry: path.resolve(__dirname, 'lambdas', 'rekognition', 'index.js'),
vpc: this.props.vpc,
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
LAKECHAIN_CACHE_STORAGE: this.props.cacheStorage.id(),
INTENT: this.props.intent.compile()
},
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-s3',
'@aws-sdk/client-sns'
]
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.eventProcessor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.eventProcessor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: this.props.batchSize ?? 2,
maxConcurrency: 20,
reportBatchItemFailures: true
}));
// Allowing the function to call Amazon Rekognition.
this.eventProcessor.addToRolePolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'rekognition:DetectLabels',
'rekognition:DetectFaces',
'rekognition:DetectText',
'rekognition:DetectModerationLabels',
'rekognition:DetectProtectiveEquipment'
],
resources: ['*']
}));
// Function permissions.
this.eventBus.grantPublish(this.eventProcessor);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L118-L187 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
// Since this middleware simply passes through the data
// from the previous middleware, we grant any subsequent
// middlewares in the pipeline to have read access to the
// data of all source middlewares.
for (const source of this.sources) {
source.grantReadProcessedDocuments(grantee);
}
return ({} as iam.Grant);
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L193-L202 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'image/jpeg',
'image/png'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L208-L213 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessor.supportedOutputTypes | supportedOutputTypes(): string[] {
return (this.supportedInputTypes());
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L219-L221 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L227-L231 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RekognitionImageProcessor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/index.ts#L240-L245 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | DetectionOperations.faces | faces(...args: Array<MinConfidence
| Limit
| Emotions
| Attributes<AgeRange | Gender | SmileFilter>
>): this {
const opts = {};
args.forEach((arg: any) => Object.assign(opts, arg));
this.ops.set('faces', { args: [opts] });
return (this);
} | /**
* Specifies that face detection should be performed.
* You can pass additional parameters to set the minimum
* confidence level and filter the features to be detected
* on faces.
* @param args a set of optional filters you can pass to customize
* the face recognition process.
* @returns the current instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/definitions/index.ts#L188-L197 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | DetectionOperations.labels | labels(...args: Array<MinConfidence
| Label<string>
| Limit
| Categories<string>
| Moderation
>): this {
const opts = {};
args.forEach((arg: any) => Object.assign(opts, arg));
this.ops.set('labels', { args: [opts] });
return (this);
} | /**
* Specifies that label detection should be performed.
* You can pass additional parameters to set the minimum
* confidence level and specify filters to be applied
* during the detection process.
* @param args a set of optional filters you can pass to customize
* the object detection process.
* @returns the current instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/definitions/index.ts#L208-L218 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | DetectionOperations.text | text(...args: Array<MinConfidence
| Limit
>): this {
const opts = {};
args.forEach((arg: any) => Object.assign(opts, arg));
this.ops.set('text', { args: [opts] });
return (this);
} | /**
* Specifies that text detection should be performed.
* You can pass additional parameters to set the minimum
* confidence level to filter out detections.
* @param args a set of optional filters you can pass to customize
* the text detection process.
* @returns the current instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/definitions/index.ts#L228-L235 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | DetectionOperations.ppe | ppe(confidence: MinConfidence, equipment: EquipmentFilter): this {
const opts = {
minConfidence: confidence.minConfidence,
requiredEquipment: equipment.equipment
};
this.ops.set('ppe', { args: [opts] });
return (this);
} | /**
* Specifies that personal protective equipment detection should
* be performed.
* @param args a set of optional filters you can pass to customize
* the personal protective equipment detection process.
* @returns the current instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/definitions/index.ts#L244-L251 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | DetectionOperations.compile | compile(): string {
// Verify whether the operations are valid.
if (!this.ops.size) {
throw new Error('At least one operation must be specified on the intent');
}
// Convert the map to an array.
const array = Array.from(this.ops, (entry) => {
return { op: entry[0], args: entry[1].args };
});
// Sort by priority.
return (JSON.stringify(array));
} | /**
* Compiles the intent into a string
* representation.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/definitions/index.ts#L257-L270 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SQSEvent, _: Context) {
return (await processPartialResponse(
event,
(record: SQSRecord) => this.processEvent(
CloudEvent.from(JSON.parse(record.body))
),
processor
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/lambdas/rekognition/index.ts#L77-L85 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | filterAttributes | const filterAttributes = (attributes: Attributes) => (face: FaceDetail) => {
// Age attribute filtering.
if (attributes?.age) {
const age = face.AgeRange!;
if (attributes.age.range.lhs > age.Low! || attributes.age.range.rhs < age.High!) {
return (false);
}
}
// Gender attribute filtering.
if (attributes?.gender) {
if (face.Gender!.Value !== attributes.gender) {
return (false);
}
}
// Smile attribute filtering.
if (attributes?.smile) {
if (face.Smile!.Value !== attributes.smile) {
return (false);
}
}
return (true);
}; | /**
* A filter function to filter out faces that do not match
* the given attributes.
* @param attributes a set of attributes to filter faces.
* @returns a boolean value indicating whether the face
* matches the given attributes.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/lambdas/rekognition/detection/faces/index.ts#L41-L65 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | asBoundingBox | const asBoundingBox = (boundingBox: RekognitionBoundingBox): BoundingBox => ({
left: boundingBox.Left!,
top: boundingBox.Top!,
width: boundingBox.Width!,
height: boundingBox.Height!
}); | /**
* Converts a Rekognition bounding box to a bounding box
* normalized schema.
* @param boundingBox the bounding box to convert.
* @returns the converted bounding box.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/lambdas/rekognition/detection/ppe/index.ts#L55-L60 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | asDetection | const asDetection = (detection: EquipmentDetection): Detection => ({
type: detection.Type!,
boundingBox: asBoundingBox(detection.BoundingBox!)
}); | /**
* Converts a Rekognition detection to a detection
* normalized schema.
* @param detection the detection to convert.
* @returns the converted detection.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/lambdas/rekognition/detection/ppe/index.ts#L68-L71 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | asBodyPart | const asBodyPart = (bodyPart: ProtectiveEquipmentBodyPart): BodyPart => ({
name: bodyPart.Name!,
confidence: bodyPart.Confidence!,
detections: (bodyPart.EquipmentDetections ?? []).map(asDetection)
}); | /**
* Converts a Rekognition body part to a body part
* normalized schema.
* @param bodyPart the body part to convert.
* @returns the converted body part.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rekognition-image-processor/src/lambdas/rekognition/detection/ppe/index.ts#L79-L83 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessorBuilder.withMaxInstances | public withMaxInstances(maxInstances: number) {
this.middlewareProps.maxInstances = maxInstances;
return (this);
} | /**
* The maximum amount of instances the
* cluster can have. Keep this number to
* a reasonable value to avoid over-provisioning
* the cluster.
* @param maxInstances the maximum amount of instances.
* @default 5
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L95-L98 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessorBuilder.withAlphaMatting | public withAlphaMatting(alphaMatting: boolean) {
this.middlewareProps.alphaMatting = alphaMatting;
return (this);
} | /**
* Whether to enable alpha matting.
* @param alphaMatting a boolean indicating whether
* to enable alpha matting.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L106-L109 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessorBuilder.withAlphaMattingForegroundThreshold | public withAlphaMattingForegroundThreshold(threshold: number) {
this.middlewareProps.alphaMattingForegroundThreshold = threshold;
return (this);
} | /**
* Foreground threshold for alpha matting.
* @param threshold the foreground threshold.
* @default 240
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L117-L120 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessorBuilder.withAlphaMattingBackgroundThreshold | public withAlphaMattingBackgroundThreshold(threshold: number) {
this.middlewareProps.alphaMattingBackgroundThreshold = threshold;
return (this);
} | /**
* Background threshold for alpha matting.
* @param threshold the background threshold.
* @default 10
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L128-L131 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessorBuilder.withAlphaMattingErosionSize | public withAlphaMattingErosionSize(size: number) {
this.middlewareProps.alphaMattingErosionSize = size;
return (this);
} | /**
* Erosion size for alpha matting.
* @param size the erosion size.
* @default 10
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L139-L142 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessorBuilder.withMaskPostProcessing | public withMaskPostProcessing(maskPostProcessing: boolean) {
this.middlewareProps.maskPostProcessing = maskPostProcessing;
return (this);
} | /**
* Whether to enable mask post-processing.
* @param maskPostProcessing a boolean indicating whether
* to enable mask post-processing.
* @default false
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L151-L154 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessorBuilder.build | public build(): RembgImageProcessor {
const props = RembgImageProcessorPropsSchema.parse({
...this.middlewareProps,
...this.props
});
return (new RembgImageProcessor(
this.scope,
this.identifier, {
...this.middlewareProps as RembgImageProcessorProps,
...props
}
));
} | /**
* @returns a new instance of the `RembgImageProcessor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L160-L173 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.constructor | constructor(scope: Construct, id: string, private props: RembgImageProcessorProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
3 * PROCESSING_TIMEOUT.toSeconds()
)
});
// Validate the properties.
this.props = this.parse(RembgImageProcessorPropsSchema, props);
///////////////////////////////////////////
///////// Processing Storage //////
///////////////////////////////////////////
this.storage = new CacheStorage(this, 'Storage', {
encryptionKey: props.kmsKey
});
///////////////////////////////////////////
/////// Parameter Validation //////
///////////////////////////////////////////
if (this.props.alphaMatting === true) {
// If the user is using alpha matting with a CPU compute, and the
// `maxMemorySize` is not set or is less than 10240 MB, we throw an error
// to prevent the user from running the service with insufficient memory.
if ((!this.props.maxMemorySize || this.props.maxMemorySize < 10240)
&& (!this.props.computeType || this.props.computeType === ComputeType.CPU)) {
throw new Error(`
The minimum memory size for alpha matting is 10240 MB of memory.
Please increase the memory size using the 'withMaxMemorySize' method.
`);
}
}
///////////////////////////////////////////
////// Middleware Event Handler ////
///////////////////////////////////////////
if (this.props.computeType === ComputeType.GPU) {
this.createGpuImpl();
} else {
this.createCpuImpl();
}
// Grant the compute type permissions to
// write to the post-processing bucket.
this.storage.grantWrite(this.grantPrincipal);
// Grant the compute type permissions to
// publish to the SNS topic.
this.eventBus.grantPublish(this.grantPrincipal);
super.bind();
} | /**
* Construct constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L201-L256 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.createCpuImpl | private createCpuImpl() {
const fileSystem = new efs.FileSystem(this, 'Filesystem', {
removalPolicy: cdk.RemovalPolicy.DESTROY,
vpc: this.props.vpc,
throughputMode: efs.ThroughputMode.ELASTIC,
vpcSubnets: {
subnetType: ec2.SubnetType.PRIVATE_ISOLATED
},
lifecyclePolicy: efs.LifecyclePolicy.AFTER_7_DAYS,
encrypted: true,
kmsKey: this.props.kmsKey
});
// Allow services in the VPC to access the EFS.
fileSystem.connections.allowFrom(
ec2.Peer.ipv4(this.props.vpc.vpcCidrBlock),
ec2.Port.tcp(2049),
'Provides access to the EFS from the VPC.'
);
// Create an EFS access point to allow the lambda
// function to access the EFS.
const accessPoint = new efs.AccessPoint(this, 'AccessPoint', {
fileSystem,
path: '/cache',
createAcl: {
ownerGid: '1001',
ownerUid: '1001',
permissions: '750'
},
posixUser: {
uid: '1001',
gid: '1001'
}
});
// The processing function.
this.processor = new lambda.DockerImageFunction(this, 'Compute', {
description: 'A function removing the background from images.',
code: lambda.DockerImageCode.fromImageAsset(
path.resolve(__dirname, 'lambdas', 'processor')
),
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE_CPU,
vpc: this.props.vpc,
timeout: PROCESSING_TIMEOUT,
architecture: lambda.Architecture.X86_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/efs'),
insightsVersion: this.props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
PROCESSED_FILES_BUCKET: this.storage.id(),
ALPHA_MATTING: this.props.alphaMatting ? 'true' : 'false',
ALPHA_MATTING_FG_THRESHOLD: this.props.alphaMattingForegroundThreshold?.toString(),
ALPHA_MATTING_BG_THRESHOLD: this.props.alphaMattingBackgroundThreshold?.toString(),
ALPHA_MATTING_EROSION_SIZE: this.props.alphaMattingErosionSize?.toString(),
MASK_POST_PROCESSING: this.props.maskPostProcessing ? 'true' : 'false',
U2NET_HOME: '/mnt/efs/models',
NUMBA_CACHE_DIR: '/mnt/efs/cache'
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.processor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.processor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: this.props.batchSize ?? 1,
reportBatchItemFailures: true
}));
} | /**
* Creates the CPU infrastructure for running RunBg on images
* from the input queue.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L262-L340 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.createGpuImpl | private createGpuImpl() {
// The container image to provision the ECS tasks with.
const image = ecs.ContainerImage.fromDockerImageAsset(
new assets.DockerImageAsset(this, 'Container', {
directory: path.resolve(__dirname, 'container'),
platform: assets.Platform.LINUX_AMD64
})
);
// Use the ECS container middleware pattern to create an
// auto-scaled ECS cluster, an EFS mounted on the cluster's tasks
// and all the components required to manage the cluster.
const cluster = new EcsCluster(this, 'Cluster', {
vpc: this.props.vpc,
eventQueue: this.eventQueue,
eventBus: this.eventBus,
kmsKey: this.props.kmsKey,
logGroup: this.logGroup,
containerProps: {
image,
containerName: 'rembg-image-processor',
cpuLimit: 4096,
memoryLimitMiB: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE_GPU,
gpuCount: 1,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
PROCESSED_FILES_BUCKET: this.storage.id(),
ALPHA_MATTING: this.props.alphaMatting ? 'true' : 'false',
ALPHA_MATTING_FG_THRESHOLD: this.props.alphaMattingForegroundThreshold?.toString(),
ALPHA_MATTING_BG_THRESHOLD: this.props.alphaMattingBackgroundThreshold?.toString(),
ALPHA_MATTING_EROSION_SIZE: this.props.alphaMattingErosionSize?.toString(),
MASK_POST_PROCESSING: this.props.maskPostProcessing ? 'true' : 'false',
U2NET_HOME: '/cache/models',
NUMBA_CACHE_DIR: '/cache/numba'
}
},
autoScaling: {
minInstanceCapacity: 0,
maxInstanceCapacity: this.props.maxInstances,
maxTaskCapacity: this.props.maxInstances,
maxMessagesPerTask: 5
},
launchTemplateProps: {
instanceType: DEFAULT_INSTANCE_TYPE,
machineImage: ecs.EcsOptimizedImage.amazonLinux2(
ecs.AmiHardwareType.GPU
),
userData: ec2.UserData.forLinux()
},
fileSystem: {
throughputMode: efs.ThroughputMode.ELASTIC,
readonly: false,
containerPath: '/cache',
accessPoint: {
uid: 1000,
gid: 1000,
permission: 750
}
},
containerInsights: this.props.cloudWatchInsights
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = cluster.taskRole.grantPrincipal;
return (cluster);
} | /**
* Creates the GPU infrastructure for running RunBg on images
* from the input queue.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L346-L415 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
return (this.storage.grantRead(grantee));
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L421-L423 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'image/png',
'image/jpeg'
]);
} | /**
* @returns an array of mime-types supported as input
* type by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L429-L434 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.supportedOutputTypes | supportedOutputTypes(): string[] {
return ([
'image/png'
]);
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L440-L444 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU,
ComputeType.GPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L450-L455 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | RembgImageProcessor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/rembg-image-processor/src/index.ts#L464-L469 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransformBuilder.withSharpTransforms | public withSharpTransforms(sharpTransforms: SharpOperations | IntentExpression) {
this.providerProps.sharpTransforms = sharpTransforms;
return (this);
} | /**
* @param sharpTransforms the sharp transforms to apply.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L84-L87 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransformBuilder.build | public build(): SharpImageTransform {
return (new SharpImageTransform(
this.scope,
this.identifier, {
...this.providerProps as SharpImageTransformProps,
...this.props
}
));
} | /**
* @returns a new instance of the `SharpImageTransform`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L93-L101 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransform.constructor | constructor(scope: Construct, id: string, private props: SharpImageTransformProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
6 * PROCESSING_TIMEOUT.toSeconds()
)
});
// Validate the properties.
this.props = this.parse(SharpImageTransformSchema, props);
///////////////////////////////////////////
/////// Transform Expression //////
///////////////////////////////////////////
let type = 'expression';
let expression = null;
if (this.props.sharpTransforms instanceof SharpOperations) {
// Verify whether the transforms are valid.
const ops = this.props.sharpTransforms.getOps();
if (!ops.length) {
throw new Error('At least one Sharp transform must be specified.');
}
expression = JSON.stringify(ops);
} else {
expression = this.serializeFn(this.props.sharpTransforms);
type = 'funclet';
}
///////////////////////////////////////////
//////// Processing Storage ///////
///////////////////////////////////////////
this.storage = new CacheStorage(this, 'Storage', {
encryptionKey: this.props.kmsKey
});
///////////////////////////////////////////
/////// Processing Function ///////
///////////////////////////////////////////
this.eventProcessor = new node.NodejsFunction(this, 'Compute', {
description: 'Transforms images using the Sharp library.',
entry: path.resolve(__dirname, 'lambdas', 'sharp', 'index.js'),
vpc: this.props.vpc,
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
PROCESSED_FILES_BUCKET: this.storage.id(),
OPS_TYPE: type,
INTENT: expression,
INTENT_SYMBOL
},
layers: [
SharpLayer.arm64(this, 'SharpLayer')
],
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-s3',
'@aws-sdk/client-sns',
'sharp'
]
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.eventProcessor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.eventProcessor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: props.batchSize ?? 5,
reportBatchItemFailures: true
}));
// Function permissions.
this.eventBus.grantPublish(this.eventProcessor);
this.storage.grantWrite(this.eventProcessor);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L128-L222 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransform.serializeFn | private serializeFn(fn: IntentExpression, opts?: esbuild.TransformOptions): string {
const res = esbuild.transformSync(`const ${INTENT_SYMBOL} = ${serialize(fn)}\n`, {
minify: true,
...opts
});
return (res.code);
} | /**
* A helper used to serialize the user-provided intent into a string.
* This function also uses `esbuild` to validate the syntax of the
* provided function and minify it.
* @param fn the function to serialize.
* @param opts the esbuild transform options.
* @returns the serialized function.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L232-L238 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransform.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
return (this.storage.grantRead(grantee));
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L244-L246 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransform.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'image/jpeg',
'image/png',
'image/tiff',
'image/webp',
'image/avif',
'image/gif',
'image/heic',
'image/heif'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L252-L263 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransform.supportedOutputTypes | supportedOutputTypes(): string[] {
return (this.supportedInputTypes());
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L269-L271 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransform.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L277-L281 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpImageTransform.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/index.ts#L290-L295 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | def | const def = (v: any) => typeof v !== 'undefined'; | /**
* @param v the value to check.
* @returns true if the value is defined.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/definitions/index.ts#L81-L81 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | isObject | const isObject = (value: any) => value !== null && typeof value === 'object'; | /**
* @param value the value to check.
* @returns true if the value is an object, false otherwise.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/lambdas/sharp/expression.ts#L25-L25 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | reviver | const reviver = (event: CloudEvent) => (key: string, value: any) => {
if (value?.type === 'Buffer') {
// Buffer de-serialization.
return (Buffer.from(value.data));
} else if (value?.subject?.type) {
// Reference resolution.
return (event.resolve(value));
}
return (value);
}; | /**
* A custom reviver function to use with `JSON.parse`
* in order to properly deserialize `Buffer` objects
* and references from the event data.
* @param key the current key being processed.
* @param value the value associated with the key.
* @returns the value to use for the key.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/lambdas/sharp/expression.ts#L35-L44 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | deepResolve | const deepResolve = async (value: any): Promise<any> => {
if (value instanceof Promise) {
// If it's a promise, await it
return value;
} else if (Array.isArray(value)) {
// If it's an array, recursively resolve each element
return Promise.all(value.map(deepResolve));
} else if (isObject(value)) {
// If it's an object, recursively resolve each property
const entries: any = await Promise.all(
Object.entries(value).map(async ([key, val]) => [key, await deepResolve(val)])
);
return (Object.fromEntries(entries));
}
return (value);
}; | /**
* A helper function to recursively resolve any promises,
* deeply nested within an object or array.
* @param value the value to resolve.
* @returns the resolved value.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/lambdas/sharp/expression.ts#L52-L67 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.processEvent | async processEvent(event: CloudEvent): Promise<CloudEvent> {
const results = process.env.OPS_TYPE === 'expression' ?
processExpression(event) :
processFunclet(event);
// For each yielded image, we create a new document.
for await (const result of results) {
const key = `${event.data().chainId()}/${randomUUID()}.${result.ext}`;
// Create a new document with the processed image.
event.data().props.document = await Document.create({
url: new URL(`s3://${PROCESSED_FILES_BUCKET}/${key}`),
data: result.buffer,
type: result.type
});
// We set the image metadata as the document metadata.
merge(event.data().props.metadata, result.metadata);
// Forward the event to the next middlewares.
await nextAsync(event);
}
return (event);
} | /**
* @param event the event to process.
* @note the next decorator will automatically forward the
* returned cloud event to the next middlewares
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/lambdas/sharp/index.ts#L57-L81 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SQSEvent, _: Context): Promise<SQSBatchResponse> {
return (await processPartialResponse(
event,
(record: SQSRecord) => this.processEvent(
CloudEvent.from(JSON.parse(record.body))
),
processor
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/image-processors/sharp-image-transform/src/lambdas/sharp/index.ts#L91-L99 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnectorBuilder.withDestinationStream | public withDestinationStream(destinationStream: firehose.CfnDeliveryStream) {
this.providerProps.destinationStream = destinationStream;
return (this);
} | /**
* Sets the destination Firehose delivery stream to forward
* processing results to.
* @param destinationStream the destination Firehose delivery stream.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L55-L58 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnectorBuilder.build | public build(): FirehoseStorageConnector {
return (new FirehoseStorageConnector(
this.scope,
this.identifier, {
...this.providerProps as FirehoseStorageConnectorProps,
...this.props
}
));
} | /**
* @returns a new instance of the `FirehoseStorageConnector`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L64-L72 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnector.constructor | constructor(scope: Construct, id: string, private props: FirehoseStorageConnectorProps) {
super(scope, id, description, props);
// Validate the properties.
this.props = this.parse(FirehoseStorageConnectorPropsSchema, props);
super.bind();
} | /**
* Construct constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L89-L96 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnector.getInput | public getInput() {
return (this.props.destinationStream);
} | /**
* We override the `getInput` method to return the user-provided
* delivery stream. This way this middleware only acts as a passthrough between
* the previous middleware's SNS topics and the user-provided delivery stream.
* @returns the user-provided delivery stream.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L104-L106 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnector.grantReadProcessedDocuments | grantReadProcessedDocuments(_: iam.IGrantable): iam.Grant {
return ({} as iam.Grant);
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L112-L114 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnector.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'*/*'
]);
} | /**
* @returns an array of mime-types supported as input
* type by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L120-L124 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnector.supportedOutputTypes | supportedOutputTypes(): string[] {
return ([]);
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L130-L132 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | FirehoseStorageConnector.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/storage-connectors/firehose-storage-connector/src/index.ts#L138-L142 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.