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
OllamaEmbeddingProcessor.supportedInputTypes
supportedInputTypes(): string[] { return (this.props.model.definition.inputs); }
/** * @returns an array of mime-types supported as input * type by this middleware. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/index.ts#L224-L226
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
OllamaEmbeddingProcessor.supportedOutputTypes
supportedOutputTypes(): string[] { return (this.props.model.definition.outputs); }
/** * @returns an array of mime-types supported as output * type by the data producer. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/index.ts#L232-L234
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
OllamaEmbeddingProcessor.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/embedding-processors/ollama-embedding-processor/src/index.ts#L240-L245
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
OllamaEmbeddingProcessor.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/embedding-processors/ollama-embedding-processor/src/index.ts#L254-L259
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
getPlatform
const getPlatform = (instanceType: ec2.InstanceType) => { if (instanceType.architecture === ec2.InstanceArchitecture.ARM_64) { return assets.Platform.LINUX_ARM64; } else { return assets.Platform.LINUX_AMD64; } };
/** * A helper function returning the platform (AMD64 or ARM64) * to use given an instance type. * @param instanceType the instance type to evaluate. * @returns the platform to use. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/ecs-configuration.ts#L28-L34
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinitionBuilder.withInstanceType
public withInstanceType(instanceType: ec2.InstanceType) { this.props.instanceType = instanceType; return (this); }
/** * Sets the instance type to use. * @param instanceType the instance type to use. * @returns the builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L43-L46
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinitionBuilder.withMaxMemory
public withMaxMemory(maxMemory: number) { this.props.maxMemory = maxMemory; return (this); }
/** * Sets the maximum memory to use. * @param maxMemory the maximum memory to use. * @returns the builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L53-L56
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinitionBuilder.withGpus
public withGpus(gpus: number) { this.props.gpus = gpus; return (this); }
/** * Sets the number of GPUs to use. * @param gpus the number of GPUs to use. * @returns the builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L63-L66
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinitionBuilder.build
public build(): InfrastructureDefinition { return (InfrastructureDefinition.from(this.props)); }
/** * Builds the infrastructure definition. * @returns the infrastructure definition. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L72-L74
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinition.constructor
constructor(public props: InfrastructureDefinitionProps) {}
/** * Creates a new instance of the `InfrastructureDefinition` class. * @param props the infrastructure definition properties. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L92-L92
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinition.instanceType
public instanceType() { return (this.props.instanceType); }
/** * @returns the instance type to use. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L97-L99
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinition.maxMemory
public maxMemory() { return (this.props.maxMemory); }
/** * @returns the maximum memory to use. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L104-L106
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinition.gpus
public gpus() { return (this.props.gpus); }
/** * @returns the number of GPUs to use. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L111-L113
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinition.from
public static from(props: any) { return (new InfrastructureDefinition(InfrastructureDefinitionPropsSchema.parse(props))); }
/** * Creates a new instance of the `InfrastructureDefinition` class. * @param props the infrastructure definition properties. * @returns a new instance of the `InfrastructureDefinition` class. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L120-L122
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
InfrastructureDefinition.toJSON
public toJSON() { return (this.props); }
/** * @returns the JSON representation of the * infrastructure definition. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/infrastructure.ts#L128-L130
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
OllamaEmbeddingModel.of
public static of( name: string, opts: { tag: string } ) { return (new OllamaEmbeddingModel(name, { tag: opts.tag, inputs: BASE_TEXT_INPUTS, outputs: BASE_TEXT_INPUTS })); }
/** * Create a new instance of the `OllamaEmbeddingModel` * by name. * @param name the name of the model. * @returns a new instance of the `OllamaEmbeddingModel`. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/model.ts#L126-L135
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
OllamaEmbeddingModel.constructor
constructor( public name: string, public definition: OllamaEmbeddingModelDefinition ) {}
/** * Creates a new instance of the `OllamaEmbeddingModel` class. * @param name the name of the model. * @param definition the model definition. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/model.ts#L142-L145
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
OllamaEmbeddingModel.tag
public tag(tag: string) { this.definition.tag = tag; return (this); }
/** * Sets the tag of the model. * @param tag the tag of the model. * @returns the model instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/ollama-embedding-processor/src/definitions/model.ts#L152-L155
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessorBuilder.withMaxInstances
public withMaxInstances(maxInstances: number) { this.providerProps.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 */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/panns-embedding-processor/src/index.ts#L65-L68
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessorBuilder.build
public build(): PannsEmbeddingProcessor { return (new PannsEmbeddingProcessor( this.scope, this.identifier, { ...this.providerProps as PannsEmbeddingProcessorProps, ...this.props } )); }
/** * @returns a new instance of the `PannsEmbeddingProcessor` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/panns-embedding-processor/src/index.ts#L74-L82
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessor.constructor
constructor(scope: Construct, id: string, private props: PannsEmbeddingProcessorProps) { super(scope, id, description, props); // Validate the properties. this.props = this.parse(PannsEmbeddingProcessorPropsSchema, props); /////////////////////////////////////////// ///////// ECS Container ///////// /////////////////////////////////////////// const image = ecs.ContainerImage.fromDockerImageAsset( new assets.DockerImageAsset(this, 'PannsImage', { 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: 'panns-embedding-processor', cpuLimit: 4096, memoryLimitMiB: 8192, gpuCount: 1, environment: { POWERTOOLS_SERVICE_NAME: description.name, LAKECHAIN_CACHE_STORAGE: this.props.cacheStorage.id(), CACHE_DIR: '/cache' } }, 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 ), ebsOptimized: true, blockDevices: [{ deviceName: '/dev/xvda', volume: ec2.BlockDeviceVolume.ebs(80) }], 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; super.bind(); }
/** * Provider constructor. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/panns-embedding-processor/src/index.ts#L101-L176
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessor.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/embedding-processors/panns-embedding-processor/src/index.ts#L182-L191
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessor.supportedInputTypes
supportedInputTypes(): string[] { return ([ 'audio/mpeg', 'audio/mp4', 'audio/wav', 'audio/x-wav', 'audio/x-m4a', 'audio/ogg', 'audio/x-flac', 'audio/flac', 'audio/x-aiff', 'audio/aiff', 'audio/x-ms-wma', 'audio/x-matroska', 'audio/webm', 'audio/aac' ]); }
/** * @returns an array of mime-types supported as input * type by this middleware. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/panns-embedding-processor/src/index.ts#L197-L214
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessor.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/embedding-processors/panns-embedding-processor/src/index.ts#L220-L222
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessor.supportedComputeTypes
supportedComputeTypes(): ComputeType[] { return ([ ComputeType.GPU ]); }
/** * @returns the supported compute types by a given * middleware. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/panns-embedding-processor/src/index.ts#L228-L232
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PannsEmbeddingProcessor.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/embedding-processors/panns-embedding-processor/src/index.ts#L241-L246
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformersBuilder.withModel
public withModel(model: SentenceTransformersModel) { this.providerProps.model = model; return (this); }
/** * Sets the embedding model to use. * @param model the embedding model to use. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/sentence-transformers/src/index.ts#L75-L78
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformersBuilder.withMaxInstances
public withMaxInstances(maxInstances: number) { this.providerProps.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 */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/sentence-transformers/src/index.ts#L88-L91
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformersBuilder.build
public build(): SentenceTransformers { return (new SentenceTransformers( this.scope, this.identifier, { ...this.providerProps as SentenceTransformersProps, ...this.props } )); }
/** * @returns a new instance of the `SentenceTransformers` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/sentence-transformers/src/index.ts#L97-L105
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformers.constructor
constructor(scope: Construct, id: string, private props: SentenceTransformersProps) { super(scope, id, description, { ...props, queueVisibilityTimeout: cdk.Duration.seconds( 6 * PROCESSING_TIMEOUT.toSeconds() ) }); // Validate the properties. this.props = this.parse(SentenceTransformersPropsSchema, props); /////////////////////////////////////////// ////// Middleware Event Handler //// /////////////////////////////////////////// // 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: 'sentence-transformers', cpuLimit: 2048, memoryLimitMiB: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE, gpuCount: 1, environment: { POWERTOOLS_SERVICE_NAME: description.name, LAKECHAIN_CACHE_STORAGE: this.props.cacheStorage.id(), EMBEDDING_MODEL: this.props.model.name, CACHE_DIR: '/cache', HF_HOME: '/cache' } }, autoScaling: { minInstanceCapacity: 0, maxInstanceCapacity: this.props.maxInstances, maxTaskCapacity: this.props.maxInstances, maxMessagesPerTask: 10 }, 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; // 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/embedding-processors/sentence-transformers/src/index.ts#L127-L209
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformers.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/embedding-processors/sentence-transformers/src/index.ts#L215-L224
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformers.supportedInputTypes
supportedInputTypes(): string[] { return ([ 'text/plain', 'text/markdown' ]); }
/** * @returns an array of mime-types supported as input * type by this middleware. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/sentence-transformers/src/index.ts#L230-L235
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformers.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/embedding-processors/sentence-transformers/src/index.ts#L241-L243
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformers.supportedComputeTypes
supportedComputeTypes(): ComputeType[] { return ([ ComputeType.GPU ]); }
/** * @returns the supported compute types by a given * middleware. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/sentence-transformers/src/index.ts#L249-L253
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformers.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/embedding-processors/sentence-transformers/src/index.ts#L262-L267
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
SentenceTransformersModel.of
public static of(name: string) { return (new SentenceTransformersModel(name)); }
/** * Create a new instance of the `SentenceTransformersModel` * by name. * @param name the path of the model on sentence-transformers. * @returns a new instance of the `SentenceTransformersModel`. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/embedding-processors/sentence-transformers/src/definitions/model.ts#L85-L87
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionBuilder.withConditional
public withConditional(conditional: ConditionalExpression | lambda.IFunction) { this.providerProps.conditional = conditional; return (this); }
/** * Sets the conditional expression to evaluate. * @param conditional a conditional expression or a reference * to a lambda function. * @returns the builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/index.ts#L88-L91
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionBuilder.build
public build(): Condition { return (new Condition( this.scope, this.identifier, { ...this.providerProps as ConditionProps, ...this.props } )); }
/** * @returns a new instance of the `Condition` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/index.ts#L97-L105
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.constructor
constructor(scope: Construct, id: string, props: ConditionProps) { super(scope, id, description, { ...props, queueVisibilityTimeout: cdk.Duration.seconds( 3 * PROCESSING_TIMEOUT.toSeconds() ) }); // Validating the properties. props = this.parse(ConditionPropsSchema, props); /////////////////////////////////////////// ////// Conditional Expression ///// /////////////////////////////////////////// let conditional: string; // If the conditional expression is a Lambda function, // we give it the permission to read the processed // documents generated by the previous middlewares. if (props.conditional instanceof lambda.Function) { conditional = props.conditional.functionArn; this.grantReadProcessedDocuments(props.conditional); // If it is a function expression, we serialize it for the // processing function to evaluate it. } else if (typeof props.conditional === 'function') { conditional = this.serializeFn(props.conditional); // Otherwise, we throw an error. } else { throw new Error(` Invalid or missing conditional expression in condition middleware. `); } /////////////////////////////////////////// /////// Processing Function /////// /////////////////////////////////////////// this.eventProcessor = new node.NodejsFunction(this, 'Compute', { description: 'A function evaluating a conditional expression.', entry: path.resolve(__dirname, 'lambdas', 'condition-evaluation', 'index.js'), vpc: props.vpc, memorySize: props.maxMemorySize ?? DEFAULT_MEMORY_SIZE, timeout: PROCESSING_TIMEOUT, runtime: EXECUTION_RUNTIME, architecture: lambda.Architecture.ARM_64, tracing: lambda.Tracing.ACTIVE, environmentEncryption: 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, CONDITIONAL_TYPE: props.conditional instanceof lambda.Function ? 'lambda' : 'expression', CONDITIONAL: conditional, CONDITIONAL_SYMBOL }, 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; // If the conditional is a lambda function, grant // the processing lambda the permission to invoke it. if (props.conditional instanceof lambda.Function) { props.conditional.grantInvoke(this.eventProcessor); } // Allow the function to publish to the SNS topic. this.eventBus.grantPublish(this.eventProcessor); // Plug the SQS queue into the lambda function. this.eventProcessor.addEventSource(new sources.SqsEventSource(this.eventQueue, { batchSize: props.batchSize ?? 10, maxBatchingWindow: props.batchingWindow, reportBatchItemFailures: true })); super.bind(); }
/** * Provider constructor. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/index.ts#L126-L221
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.serializeFn
private serializeFn(fn: ConditionalExpression, opts?: esbuild.TransformOptions): string { const res = esbuild.transformSync(`const ${CONDITIONAL_SYMBOL} = ${serialize(fn)}\n`, { minify: true, ...opts }); return (res.code); }
/** * A helper used to serialize the different types of JavaScript * functions that the user can provide (e.g functions, arrow functions, * async functions, etc.) 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/flow-control/condition/src/index.ts#L233-L239
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.onMatch
public onMatch(consumer: Middleware): Middleware { return (this.pipe(consumer, consumer.conditional() .and( when('data.metadata.custom.__condition_result').equals('true') ))); }
/** * Defines the next middleware to execute when the * condition is matched. * @param consumer the next middleware to execute. * @returns a reference to this middleware. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/index.ts#L247-L252
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.onMismatch
public onMismatch(consumer: Middleware): Middleware { return (this.pipe(consumer, consumer.conditional() .and( when('data.metadata.custom.__condition_result').equals('false') ))); }
/** * Defines the next middleware to execute when the * condition is not matched. * @param consumer the next middleware to execute. * @returns a reference to this middleware. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/index.ts#L260-L265
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.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/flow-control/condition/src/index.ts#L271-L280
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.supportedInputTypes
supportedInputTypes(): string[] { return ([ '*/*' ]); }
/** * @returns an array of mime-types supported as input * type by the data producer. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/index.ts#L286-L290
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.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/flow-control/condition/src/index.ts#L296-L300
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Condition.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/flow-control/condition/src/index.ts#L306-L310
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
evaluateLambda
const evaluateLambda = async (event: CloudEvent): Promise<boolean> => { const res = await lambda.send(new InvokeCommand({ FunctionName: CONDITIONAL, Payload: JSON.stringify(event.toJSON()) })); // If the function failed to execute, we throw an error. if (res.FunctionError) { throw new Error(res.FunctionError); } // Parse the result of the lambda function into a boolean value. const payload = JSON.parse( new TextDecoder().decode(res.Payload as Uint8Array) ); return (payload === true); };
/** * Synchronously invokes the conditional lambda function and * returns its boolean result. * @param event the event to process. * @returns a promise to the boolean result of the conditional. * @throws an error if the conditional function failed to execute. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/lambdas/condition-evaluation/evaluate.ts#L33-L50
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
evaluateExpression
const evaluateExpression = async (event: CloudEvent, opts?: RunningCodeOptions): Promise<boolean> => { const context = createContext({ console, require, setTimeout, setInterval, setImmediate, event }); // Run the expression within a VM. const res = runInContext(`${CONDITIONAL}\n${CONDITIONAL_SYMBOL}(event);`, context, { timeout: 10_000, ...opts }); // If the expression did not return a promise, we throw an error. if (!res.then) { throw new Error(` Invalid conditional expression return type, a promise is expected. `); } return ((await res) === true); };
/** * Evaluates the given conditional expression and returns * its boolean result. * @param event the event to process. * @param opts execution options. * @returns a promise to the boolean result of the conditional. * @throws an error if the conditional expression is invalid. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/condition/src/lambdas/condition-evaluation/evaluate.ts#L60-L84
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/flow-control/condition/src/lambdas/condition-evaluation/index.ts#L78-L86
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
DelayBuilder.withTime
public withTime(time: cdk.Duration | Date) { this.providerProps.time = time; return (this); }
/** * The time or delay duration at which the pipeline * should resume. * @param time the time or delay duration. * @returns the builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/delay/src/index.ts#L76-L79
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
DelayBuilder.build
public build(): Delay { return (new Delay( this.scope, this.identifier, { ...this.providerProps as DelayProps, ...this.props } )); }
/** * @returns a new instance of the `Delay` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/delay/src/index.ts#L85-L93
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Delay.constructor
constructor(scope: Construct, id: string, props: DelayProps) { super(scope, id, description, { ...props, queueVisibilityTimeout: cdk.Duration.seconds( 6 * PROCESSING_TIMEOUT.toSeconds() ) }); // Validating the properties. props = this.parse(DelayPropsSchema, props); /////////////////////////////////////////// ////////// State Machine ////////// /////////////////////////////////////////// // The delay step associated with the user delay. const delayStep = new sfn.Wait(this, 'DelayStep', { time: props.time instanceof cdk.Duration ? sfn.WaitTime.duration(props.time) : sfn.WaitTime.timestamp(props.time.toISOString()) }); // Forward the event to the output SNS topic. const publishStep = new tasks.SnsPublish(this, 'PublishStep', { topic: this.eventBus, message: sfn.TaskInput.fromJsonPathAt('$.data') }); // The state machine definition. const definition = delayStep.next(publishStep); // The state machine orchestrating the delay step. const stateMachine = new sfn.StateMachine(this, 'StateMachine', { definitionBody: sfn.DefinitionBody.fromChainable(definition), tracingEnabled: true, comment: 'A state machine orchestrating a delay.', stateMachineType: sfn.StateMachineType.STANDARD }); /////////////////////////////////////////// /////// Processing Function /////// /////////////////////////////////////////// this.eventProcessor = new node.NodejsFunction(this, 'Compute', { description: 'A function starting a step-function to delay the processing.', entry: path.resolve(__dirname, 'lambdas', 'delay', 'index.js'), vpc: props.vpc, memorySize: props.maxMemorySize ?? DEFAULT_MEMORY_SIZE, timeout: PROCESSING_TIMEOUT, runtime: EXECUTION_RUNTIME, architecture: lambda.Architecture.ARM_64, tracing: lambda.Tracing.ACTIVE, environmentEncryption: props.kmsKey, logGroup: this.logGroup, insightsVersion: props.cloudWatchInsights ? LAMBDA_INSIGHTS_VERSION : undefined, environment: { POWERTOOLS_SERVICE_NAME: description.name, POWERTOOLS_METRICS_NAMESPACE: NAMESPACE, STATE_MACHINE_ARN: stateMachine.stateMachineArn }, bundling: { minify: true, externalModules: [ '@aws-sdk/client-sfn' ] } }); // 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 ?? 10, maxBatchingWindow: props.batchingWindow, reportBatchItemFailures: true })); // Function permissions. stateMachine.grantStartExecution(this.eventProcessor); super.bind(); }
/** * Provider constructor. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/delay/src/index.ts#L114-L200
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Delay.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/flow-control/delay/src/index.ts#L206-L215
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Delay.supportedInputTypes
supportedInputTypes(): string[] { return ([ '*/*' ]); }
/** * @returns an array of mime-types supported as input * type by the data producer. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/delay/src/index.ts#L221-L225
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Delay.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/flow-control/delay/src/index.ts#L231-L235
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Delay.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/flow-control/delay/src/index.ts#L241-L245
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Lambda.processEvent
async processEvent(event: CloudEvent): Promise<any> { return (sfn.send(new StartExecutionCommand({ stateMachineArn: process.env.STATE_MACHINE_ARN as string, input: JSON.stringify({ data: event.toJSON() }) }))); }
/** * Start a new execution of the state machine. * @param event the event to process. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/delay/src/lambdas/delay/index.ts#L59-L66
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/flow-control/delay/src/lambdas/delay/index.ts#L76-L84
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Lambda.handler
async handler(event: any, _: Context): Promise<any> { return (CloudEvent.from(event)); }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/delay/src/lambdas/handler/index.ts#L40-L42
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PassthroughBuilder.withResolveMetadata
public withResolveMetadata(resolveMetadata: boolean) { this.providerProps.resolveMetadata = resolveMetadata; return (this); }
/** * Whether to dump the metadata of the document and * resolve pointers into their actual values. * @param resolveMetadata whether to resolve the metadata. * @returns the builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/passthrough/src/index.ts#L74-L77
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
PassthroughBuilder.build
public build(): Passthrough { return (new Passthrough( this.scope, this.identifier, { ...this.providerProps as PassthroughProps, ...this.props } )); }
/** * @returns a new instance of the `Passthrough` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/passthrough/src/index.ts#L83-L91
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Passthrough.constructor
constructor(scope: Construct, id: string, props: PassthroughProps) { super(scope, id, description, { ...props, queueVisibilityTimeout: cdk.Duration.seconds( 6 * PROCESSING_TIMEOUT.toSeconds() ) }); // Validating the properties. props = this.parse(PassthroughPropsSchema, props); /////////////////////////////////////////// /////// Processing Function /////// /////////////////////////////////////////// this.eventProcessor = new node.NodejsFunction(this, 'Compute', { description: 'A function acting as a passthrough for logging events.', entry: path.resolve(__dirname, 'lambdas', 'passthrough', 'index.js'), vpc: props.vpc, memorySize: props.maxMemorySize ?? DEFAULT_MEMORY_SIZE, timeout: PROCESSING_TIMEOUT, runtime: EXECUTION_RUNTIME, architecture: lambda.Architecture.ARM_64, tracing: lambda.Tracing.ACTIVE, environmentEncryption: 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: props.cacheStorage.id(), RESOLVE_METADATA: props.resolveMetadata ? 'true' : 'false' }, 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: props.batchSize ?? 10, maxBatchingWindow: props.batchingWindow, reportBatchItemFailures: true })); // Function permissions. this.eventBus.grantPublish(this.eventProcessor); super.bind(); }
/** * Provider constructor. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/passthrough/src/index.ts#L112-L173
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Passthrough.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/flow-control/passthrough/src/index.ts#L179-L188
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Passthrough.supportedInputTypes
supportedInputTypes(): string[] { return ([ '*/*' ]); }
/** * @returns an array of mime-types supported as input * type by the data producer. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/passthrough/src/index.ts#L194-L198
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Passthrough.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/flow-control/passthrough/src/index.ts#L204-L208
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Passthrough.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/flow-control/passthrough/src/index.ts#L214-L218
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/flow-control/passthrough/src/lambdas/passthrough/index.ts#L75-L83
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
walk
const walk = async (obj: any) => { for (const key in obj) { copy[key] = obj[key]; if (obj[key] instanceof Pointer) { copy[key] = await obj[key].resolve(); } else if (typeof obj[key] === 'object') { copy = copy[key]; await walk(obj[key]); } } };
// Recursively walk the metadata to resolve pointers
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/passthrough/src/lambdas/passthrough/resolve.ts#L23-L33
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ReducerBuilder.withReducerStrategy
public withReducerStrategy(strategy: ReducerStrategy) { this.providerProps.strategy = strategy; return (this); }
/** * Specifies a reducer strategy to be used to aggregate * events. * @param strategy the strategy instance to use. * @returns the builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/index.ts#L67-L70
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ReducerBuilder.build
public build(): Reducer { return (new Reducer( this.scope, this.identifier, { ...this.providerProps as ReducerProps, ...this.props } )); }
/** * @returns a new instance of the `Reducer` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/index.ts#L76-L84
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Reducer.constructor
constructor(scope: Construct, id: string, props: ReducerProps) { super(scope, id, description, { ...props, queueVisibilityTimeout: cdk.Duration.seconds( 3 * PROCESSING_TIMEOUT.toSeconds() ) }); // Validating the properties. props = this.parse(ReducerPropsSchema, props); /////////////////////////////////////////// /////// Processing Storage //////// /////////////////////////////////////////// this.storage = new CacheStorage(this, 'Storage', { encryptionKey: props.kmsKey }); /////////////////////////////////////////// ///////// Reducer Strategy //////// /////////////////////////////////////////// if (props.strategy.name() === 'TIME_WINDOW') { new TimeWindowStrategyConstruct(this, 'TimeWindowStrategy', this, props); } else if (props.strategy.name() === 'STATIC_COUNTER') { new StaticCounterStrategyConstruct(this, 'StaticCounterStrategy', this, props); } else if (props.strategy.name() === 'CONDITIONAL') { new ConditionalStrategyConstruct(this, 'ConditionalStrategy', this, props); } else { throw new Error(`Unsupported reducer strategy: ${props.strategy.name()}`); } super.bind(); }
/** * Provider constructor. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/index.ts#L105-L139
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Reducer.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); } this.storage.grantRead(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/flow-control/reducer/src/index.ts#L145-L155
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Reducer.supportedInputTypes
supportedInputTypes(): string[] { return ([ '*/*' ]); }
/** * @returns an array of mime-types supported as input * type by the data producer. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/index.ts#L161-L165
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Reducer.supportedOutputTypes
supportedOutputTypes(): string[] { return ([ 'application/cloudevents+json' ]); }
/** * @returns an array of mime-types supported as output * type by the data producer. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/index.ts#L171-L175
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Reducer.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/flow-control/reducer/src/index.ts#L181-L185
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
Reducer.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/flow-control/reducer/src/index.ts#L194-L199
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategyBuilder.withConditional
public withConditional(conditional: ConditionalExpression | lambda.IFunction) { if (conditional instanceof lambda.Function) { this.props.conditionalType = 'lambda'; this.props.expression = conditional.functionArn; } else if (typeof conditional === 'function') { this.props.conditionalType = 'expression'; this.props.expression = this.serializeFn(conditional); } this.props.conditional = conditional; return (this); }
/** * Sets the conditional expression to evaluate. * @param conditional a conditional expression or a reference * to a lambda function. * @returns the current builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L98-L108
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategyBuilder.serializeFn
private serializeFn(fn: ConditionalExpression, opts?: esbuild.TransformOptions): string { const res = esbuild.transformSync(`const ${CONDITIONAL_SYMBOL} = ${serialize(fn)}\n`, { minify: true, ...opts }); return (res.code); }
/** * A helper used to serialize the different types of JavaScript * functions that the user can provide (e.g functions, arrow functions, * async functions, etc.) 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/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L120-L126
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategyBuilder.build
public build(): ConditionalStrategy { return (ConditionalStrategy.from(this.props)); }
/** * @returns a new instance of the `ConditionalStrategy` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L132-L134
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.constructor
constructor(public props: ConditionalStrategyProps) {}
/** * Creates a new instance of the `ConditionalStrategy` class. * @param props the task properties. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L151-L151
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.conditional
public conditional() { return (this.props.conditional); }
/** * @returns the conditional expression. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L156-L158
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.expression
public expression() { return (this.props.expression); }
/** * @returns the serialized conditional expression. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L163-L165
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.type
public type() { return (this.props.conditionalType); }
/** * @returns the conditional expression type. * @note can be either 'lambda' or 'expression'. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L171-L173
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.name
public name() { return (this.props.reduceType); }
/** * @returns the strategy name. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L178-L180
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.compile
public compile() { return (this.toJSON()); }
/** * @returns an object describing the strategy. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L185-L187
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.from
public static from(props: any) { return (new ConditionalStrategy(ConditionalStrategyPropsSchema.parse(props))); }
/** * Creates a new instance of the `ConditionalStrategy` class. * @param props the task properties. * @returns a new instance of the `ConditionalStrategy` class. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L194-L196
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
ConditionalStrategy.toJSON
public toJSON() { return ({ reduceType: this.props.reduceType, expression: this.props.expression, symbol: CONDITIONAL_SYMBOL, type: this.props.conditionalType }); }
/** * @returns the JSON representation of the task. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/conditional-strategy/index.ts#L201-L208
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategyBuilder.withEventCount
public withEventCount(eventCount: number) { this.props.eventCount = eventCount; return (this); }
/** * @param eventCount the number of events to wait for before * the reducer is triggered. * @returns the current builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L61-L64
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategyBuilder.build
public build(): StaticCounterStrategy { return (StaticCounterStrategy.from(this.props)); }
/** * @returns a new instance of the `StaticCounterStrategy` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L70-L72
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategy.constructor
constructor(public props: StaticCounterStrategyProps) {}
/** * Creates a new instance of the `StaticCounterStrategy` class. * @param props the task properties. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L89-L89
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategy.eventCount
public eventCount() { return (this.props.eventCount); }
/** * @returns the event count to wait for before the reducer * is triggered. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L95-L97
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategy.name
public name() { return (this.props.reduceType); }
/** * @returns the strategy name. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L102-L104
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategy.compile
public compile() { return (this.toJSON()); }
/** * @returns an object describing the strategy. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L109-L111
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategy.from
public static from(props: any) { return (new StaticCounterStrategy(StaticCounterStrategyPropsSchema.parse(props))); }
/** * Creates a new instance of the `StaticCounterStrategy` class. * @param props the task properties. * @returns a new instance of the `StaticCounterStrategy` class. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L118-L120
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
StaticCounterStrategy.toJSON
public toJSON() { return ({ reduceType: this.props.reduceType, eventCount: this.props.eventCount }); }
/** * @returns the JSON representation of the task. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/static-counter-strategy/index.ts#L125-L130
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
TimeWindowStrategyBuilder.withTimeWindow
public withTimeWindow(timeWindow: cdk.Duration) { this.props.timeWindow = timeWindow; return (this); }
/** * @param timeWindow the duration during which the reducer * will aggregate events belonging to the same execution * identifier. * @returns the current builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/time-window-strategy/index.ts#L78-L81
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
TimeWindowStrategyBuilder.withJitter
public withJitter(jitter: cdk.Duration) { this.props.jitter = jitter; return (this); }
/** * @param jitter the jitter value to apply to the time window * in order to smoothen the scheduling of the reducer. * @returns the current builder instance. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/time-window-strategy/index.ts#L88-L91
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
TimeWindowStrategyBuilder.build
public build(): TimeWindowStrategy { return (TimeWindowStrategy.from(this.props)); }
/** * @returns a new instance of the `TimeWindowStrategy` * service constructed with the given parameters. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/time-window-strategy/index.ts#L97-L99
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
TimeWindowStrategy.constructor
constructor(public props: TimeWindowStrategyProps) {}
/** * Creates a new instance of the `TimeWindowStrategy` class. * @param props the task properties. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/time-window-strategy/index.ts#L116-L116
4285173e80584eedfc1a8424d3d1b6c1a7038088
project-lakechain
github_2023
awslabs
typescript
TimeWindowStrategy.timeWindow
public timeWindow() { return (this.props.timeWindow); }
/** * @returns the time window duration. */
https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/flow-control/reducer/src/definitions/strategies/time-window-strategy/index.ts#L121-L123
4285173e80584eedfc1a8424d3d1b6c1a7038088