/* * Copyright 2021 Lightbend Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import * as protobuf from 'protobufjs'; import * as grpc from '@grpc/grpc-js'; /** *

The AkkaServerless module.

*/ declare module "@lightbend/akkaserverless-javascript-sdk" { namespace Action { /** *

Context for an action command.

* @property cancelled -

Whether the client is still connected.

* @property metadata -

The metadata associated with the command.

*/ interface ActionCommandContext extends CommandContext { /** *

Write a message.

* @param message -

The protobuf message to write.

* @param [metadata] -

The metadata associated with the message.

*/ write(message: any, metadata?: Metadata): void; /** *

Register an event handler.

* @param eventType -

The type of the event.

* @param callback -

The callback to handle the event.

*/ on(eventType: string, callback: (...params: any[]) => any): void; } /** *

Context for a unary action command.

*/ interface UnaryCommandContext extends Action.ActionCommandContext { } /** *

Context for a streamed in action command.

*/ interface StreamedInCommandContext extends Action.StreamedInContext, Action.ActionCommandContext { metadata: Metadata; } /** *

Context for a streamed out action command.

*/ interface StreamedOutCommandContext extends Action.StreamedOutContext { } /** *

Context for a streamed action command.

*/ interface StreamedCommandContext extends Action.StreamedInContext, Action.StreamedOutContext { metadata: Metadata; } /** *

Context for an action command that returns a streamed message out.

*/ interface StreamedOutContext extends Action.ActionCommandContext { /** *

Send a reply

* @param reply -

The reply to send

*/ reply(reply: replies.Reply): void; /** *

Terminate the outgoing stream of messages.

*/ end(): void; } /** *

Context for an action command that handles streamed messages in.

*/ interface StreamedInContext extends Action.ActionCommandContext { /** *

Cancel the incoming stream of messages.

*/ cancel(): void; } /** *

Options for an action.

*/ type options = { /** *

The directories to include when looking up imported protobuf files.

* @defaultValue ["."] */ includeDirs?: string[]; /** *

request headers to be forwarded as metadata to the action

* @defaultValue [] */ forwardHeaders?: string[]; }; /** *

A unary action command handler.

* @param command -

The command message, this will be of the type of the gRPC service call input type.

* @param context -

The command context.

*/ type unaryCommandHandler = (command: any, context: Action.UnaryCommandContext) => undefined | any | Promise | replies.Reply; /** *

A streamed in action command handler.

* @param context -

The command context.

*/ type streamedInCommandHandler = (context: Action.StreamedInCommandContext) => undefined | any | Promise; /** *

A streamed out command handler.

* @param command -

The command message, this will be of the type of the gRPC service call input type.

* @param context -

The command context.

*/ type streamedOutCommandHandler = (command: any, context: Action.StreamedOutCommandContext) => void; /** *

A streamed command handler.

* @param context -

The command context.

*/ type streamedCommandHandler = (context: Action.StreamedCommandContext) => void; /** *

An action command handler.

*/ type ActionCommandHandler = Action.unaryCommandHandler | Action.streamedInCommandHandler | Action.streamedOutCommandHandler | Action.streamedCommandHandler; } interface Action extends Component { } /** *

Create a new action.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this interface.

* @param [options] -

The options for this action

*/ class Action implements Component { /** *

Create a new action.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this interface.

* @param [options] -

The options for this action

*/ constructor(desc: string | string[], serviceName: string, options?: Action.options); options: Action.options; serviceName: string; service: protobuf.Service; /** *

Access to gRPC clients (with promisified unary methods).

*/ clients: GrpcClientLookup; /** *

The command handlers.

*

The names of the properties must match the names of the service calls specified in the gRPC descriptor

*/ commandHandlers: { [key: string]: Action.ActionCommandHandler; }; /** * @returns

action component type.

*/ componentType(): string; /** *

Lookup a protobuf message type.

*

This is provided as a convenience to lookup protobuf message types for use with events and snapshots.

* @param messageType -

The fully qualified name of the type to lookup.

* @returns

The protobuf message type.

*/ lookupType(messageType: string): protobuf.Type; /** *

Set the command handlers for this action.

* @param handlers -

The command handlers.

* @returns

This action.

*/ setCommandHandlers(handlers: { [key: string]: Action.ActionCommandHandler; }): Action; } /** *

Akka Serverless Component.

*/ interface Component { } /** *

Akka Serverless Entity.

*/ interface Entity extends Component { } /** *

Akka Serverless service.

* @param [options] -

The options for starting the service.

*/ class AkkaServerless { constructor(options?: AkkaServerlessOptions); /** *

Add one or more components to this AkkaServerless service.

* @param components -

The components to add.

* @returns

this AkkaServerless service.

*/ addComponent(...components: Component[]): AkkaServerless; /** *

Start the Akka Serverless service.

* @param [binding] -

optional address/port binding to start the service on.

* @returns

A Promise of the bound port for this service.

*/ start(binding?: ServiceBinding): Promise; /** *

Shut down the Akka Serverless service.

*/ shutdown(): void; /** *

Shut down the Akka Serverless service.

* @param callback -

shutdown callback, accepting possible error

*/ tryShutdown(callback: AkkaServerless.shutdownCallback): void; } /** * @property [serviceName] -

The name of this service (defaults to name from package.json).

* @property [serviceVersion] -

The version of this service (defaults to version from package.json).

* @property [descriptorSetPath = "user-function.desc"] -

Path to a Protobuf FileDescriptor * set, as output by protoc --descriptor_set_out=somefile.desc. This file must contain all of the component services * that this Akka Serverless service serves. See the compile-descriptor command for creating this file.

*/ interface AkkaServerlessOptions { } /** *

Service binding with address and port.

* @property [address] -

The address to bind the Akka Serverless service to.

* @property [port] -

The port to bind the Akka Serverless service to.

*/ interface ServiceBinding { } namespace AkkaServerless { /** *

Callback for tryShutdown, accepting possible error.

* @param [error] -

Error on shutting down the service.

*/ type shutdownCallback = (error?: Error) => void; } /** *

Replicated write consistency setting for replicated entities.

*/ enum ReplicatedWriteConsistency { LOCAL, MAJORITY, ALL } /** *

The GRPC status codes.

*/ enum GrpcStatus { Ok = 0, Cancelled = 1, Unknown = 2, InvalidArgument = 3, DeadlineExceeded = 4, NotFound = 5, AlreadyExists = 6, PermissionDenied = 7, ResourceExhausted = 8, FailedPrecondition = 9, Aborted = 10, OutOfRange = 11, Unimplemented = 12, Internal = 13, Unavailable = 14, DataLoss = 15, Unauthenticated = 16 } /** *

CloudEvent data.

*

This exposes CloudEvent data from metadata. Changes made to the Cloudevent are reflected in the backing metadata, * as are changes to the backing metadata reflected in this CloudEvent.

* @param metadata -

The metadata backing this CloudEvent.

*/ class Cloudevent { constructor(metadata: Metadata); /** *

The metadata backing this CloudEvent.

*/ readonly metadata: Metadata; /** *

The spec version

*/ readonly specversion: string | undefined; /** *

The id

*/ id: string | undefined; /** *

The source

*/ source: string | undefined; /** *

The type

*/ type: string | undefined; /** *

The datacontenttype

*/ datacontenttype: string | undefined; /** *

The dataschema

*/ dataschema: string | undefined; /** *

The subject

*/ subject: string | undefined; /** *

The time

*/ time: Date | undefined; } /** *

Context for an entity.

* @property entityId -

The id of the entity that the command is for.

* @property commandId -

The id of the command.

* @property replyMetadata -

The metadata to send with a reply.

*/ interface EntityContext { entityId: string; commandId: Long; replyMetadata: Metadata; } /** *

Effect context.

* @property metadata -

The metadata associated with the command.

*/ interface EffectContext { metadata: Metadata; /** *

DEPRECATED. Emit an effect after processing this command.

* @param method -

The entity service method to invoke.

* @param message -

The message to send to that service.

* @param [synchronous] -

Whether the effect should be execute synchronously or not.

* @param [metadata] -

Metadata to send with the effect.

* @param [internalCall] -

For internal calls to this deprecated function.

*/ effect(method: any, message: any, synchronous?: boolean, metadata?: Metadata, internalCall?: boolean): void; /** *

Fail handling this command.

*

An alternative to using this is to return a failed Reply created with 'ReplyFactory.failed'.

* @param msg -

The failure message.

* @param [grpcStatus] -

The grpcStatus.

*/ fail(msg: string, grpcStatus?: number): void; } /** *

Context for a command.

*/ interface CommandContext extends EffectContext { /** *

DEPRECATED. Forward this command to another service component call.

* @param method -

The service component method to invoke.

* @param message -

The message to send to that service component.

* @param metadata -

Metadata to send with the forward.

*/ thenForward(method: any, message: any, metadata: Metadata): void; /** *

DEPRECATED. Forward this command to another service component call, use 'ReplyFactory.forward' instead.

* @param method -

The service component method to invoke.

* @param message -

The message to send to that service component.

* @param [metadata] -

Metadata to send with the forward.

* @param [internalCall] -

For internal calls to this deprecated function.

*/ forward(method: any, message: any, metadata?: Metadata, internalCall?: boolean): void; } namespace EventSourcedEntity { /** *

Context for an event sourced command.

*/ interface EventSourcedEntityCommandContext extends CommandContext, EntityContext { /** *

Persist an event.

*

The event won't be persisted until the reply is sent to the proxy. Then, the event will be persisted * before the reply is sent back to the client.

* @param event -

The event to emit.

*/ emit(event: Serializable): void; } /** *

An event sourced entity command handler.

* @param command -

The command message, this will be of the type of the gRPC service call input type.

* @param state -

The entity state.

* @param context -

The command context.

*/ type commandHandler = (command: any, state: Serializable, context: EventSourcedEntity.EventSourcedEntityCommandContext) => undefined | any | replies.Reply; /** *

An event sourced entity event handler.

* @param event -

The event.

* @param state -

The entity state.

*/ type eventHandler = (event: Serializable, state: Serializable) => Serializable; /** *

An event sourced entity behavior.

*/ type behavior = { /** *

The command handlers.

The names of the properties must match the names of the service calls specified in the gRPC descriptor for this event sourced entities service.

*/ commandHandlers: { [key: string]: EventSourcedEntity.commandHandler; }; /** *

The event handlers.

The names of the properties must match the short names of the events.

*/ eventHandlers: { [key: string]: EventSourcedEntity.eventHandler; }; }; /** *

An event sourced entity behavior callback.

*

This callback takes the current entity state, and returns a set of handlers to handle commands and events for it.

* @param state -

The entity state.

*/ type behaviorCallback = (state: Serializable) => EventSourcedEntity.behavior; /** *

Initial state callback.

*

This is invoked if the entity is started with no snapshot.

* @param entityId -

The entity id.

*/ type initialCallback = (entityId: string) => Serializable; /** *

Options for an event sourced entity.

*/ type options = { /** *

A snapshot will be persisted every time this many events are emitted. It is strongly recommended to not disable snapshotting unless it is known that event sourced entities will never have more than 100 events (in which case the default will anyway not trigger any snapshots)

* @defaultValue 100 */ snapshotEvery?: number; /** *

The directories to include when looking up imported protobuf files.

* @defaultValue ["."] */ includeDirs?: string[]; /** *

Whether serialization of primitives should be supported when serializing events and snapshots.

*/ serializeAllowPrimitives?: boolean; /** *

Whether serialization should fallback to using JSON if an event or snapshot can't be serialized as a protobuf.

*/ serializeFallbackToJson?: boolean; /** *

request headers to be forwarded as metadata to the event sourced entity

* @defaultValue [] */ forwardHeaders?: string[]; /** *

Entity passivation strategy to use.

*/ entityPassivationStrategy?: EventSourcedEntity.entityPassivationStrategy; }; /** *

Entity passivation strategy for an event sourced entity.

*/ type entityPassivationStrategy = { /** *

Passivation timeout (in milliseconds).

*/ timeout?: number; }; } interface EventSourcedEntity extends Entity { } /** *

Create a new event sourced entity.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this entities interface.

* @param entityType -

The entity type name for all event source entities of this type. This will be prefixed * onto the entityId when storing the events for this entity. Be aware that the * chosen name must be stable through the entity lifecycle. Never change it after deploying * a service that stored data of this type

* @param [options] -

The options for this event sourced entity

*/ class EventSourcedEntity implements Entity { /** *

Create a new event sourced entity.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this entities interface.

* @param entityType -

The entity type name for all event source entities of this type. This will be prefixed * onto the entityId when storing the events for this entity. Be aware that the * chosen name must be stable through the entity lifecycle. Never change it after deploying * a service that stored data of this type

* @param [options] -

The options for this event sourced entity

*/ constructor(desc: string | string[], serviceName: string, entityType: string, options?: EventSourcedEntity.options); options: EventSourcedEntity.options; serviceName: string; service: protobuf.Service; /** *

Access to gRPC clients (with promisified unary methods).

*/ clients: GrpcClientLookup; /** * @returns

event sourced entity component type.

*/ componentType(): string; /** *

Lookup a protobuf message type.

*

This is provided as a convenience to lookup protobuf message types for use with events and snapshots.

* @param messageType -

The fully qualified name of the type to lookup.

* @returns

The protobuf message type.

*/ lookupType(messageType: string): protobuf.Type; /** *

The initial state callback.

*/ initial: EventSourcedEntity.initialCallback; /** *

Set the initial state callback.

* @param callback -

The initial state callback.

* @returns

This entity.

*/ setInitial(callback: EventSourcedEntity.initialCallback): EventSourcedEntity; /** *

The behavior callback.

*/ behavior: EventSourcedEntity.behaviorCallback; /** *

Set the behavior callback.

* @param callback -

The behavior callback.

* @returns

This entity.

*/ setBehavior(callback: EventSourcedEntity.behaviorCallback): EventSourcedEntity; } /** *

gRPC client.

*/ interface GrpcClient extends grpc.Client { } /** *

gRPC client creator for a service.

*/ interface GrpcClientCreator { /** *

Create a new client for service.

* @param address -

the address for the service

* @param [credentials] -

the credentials for the connection

* @returns

a new gRPC client for the service

*/ createClient(address: string, credentials?: grpc.ChannelCredentials): GrpcClient; } /** *

gRPC client lookup, using fully qualified name for service.

*/ type GrpcClientLookup = { [key: string]: GrpcClientLookup|GrpcClientCreator; }; /** *

Integration Testkit.

* @param [options] -

Options for the testkit and Akka Serverless service.

*/ class IntegrationTestkit { constructor(options?: any); /** *

Add the given component to this testkit.

* @param component -

The component to add.

* @returns

This testkit.

*/ addComponent(component: Component): IntegrationTestkit; /** *

Start the testkit, with the registered components.

* @param callback -

Start callback, accepting possible error.

*/ start(callback: IntegrationTestkit.startCallback): void; /** *

Shut down the testkit.

* @param callback -

Shutdown callback, accepting possible error.

*/ shutdown(callback: IntegrationTestkit.shutdownCallback): void; } namespace IntegrationTestkit { /** *

Callback for start, accepting possible error.

* @param [error] -

Error on starting the testkit.

*/ type startCallback = (error?: Error) => void; /** *

Callback for shutdown, accepting possible error.

* @param [error] -

Error on shutting down the testkit.

*/ type shutdownCallback = (error?: Error) => void; } /** *

JWT claims.

*

This exposes an JWT claims that were extracted from the bearer token.

* @param metadata -

The metadata that the JWT claims com efrom.

*/ class JwtClaims { constructor(metadata: Metadata); /** *

The metadata backing this JWT claims object.

*/ readonly metadata: Metadata; /** *

The issuer

*/ readonly issuer: string | undefined; /** *

The subject

*/ readonly subject: string | undefined; /** *

The audience

*/ readonly audience: string | undefined; /** *

The expiration time

*/ readonly expirationTime: Date | undefined; /** *

The not before

*/ readonly notBefore: Date | undefined; /** *

The issued at

*/ readonly issuedAt: Date | undefined; /** *

The jwt id

*/ readonly jwtId: string | undefined; /** *

Get the string claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getString(name: string): string | undefined; /** *

Get the numeric claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getNumber(name: string): number | undefined; /** *

Get the numeric date claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getNumericDate(name: string): Date | undefined; /** *

Get the boolean claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getBoolean(name: string): boolean | undefined; /** *

Get the object claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getObject(name: string): any | undefined; /** *

Get the string array claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getStringArray(name: string): string[] | undefined; /** *

Get the numeric array claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getNumberArray(name: string): number[] | undefined; /** *

Get the boolean array claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getBooleanArray(name: string): boolean[] | undefined; /** *

Get the object array claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getObjectArray(name: string): object[] | undefined; /** *

Get the numeric date array claim with the given name.

* @param name -

The name of the claim.

* @returns

the claim, or undefined if it doesn't exist or is not of the right type.

*/ getNumericDateArray(name: string): Date[] | undefined; } /** *

A metadata value. Can either be a string or a buffer.

*/ type MetadataValue = string | Buffer; /** * @property key -

The key for this metadata entry.

* @property bytesValue -

The entry value as bytes.

* @property stringValue -

The entry value as a string.

*/ interface MetadataEntry { } /** *

Akka Serverless metadata.

*

Metadata is treated as case insensitive on lookup, and case sensitive on set. Multiple values per key are supported, * setting a value will add it to the current values for that key. You should delete first if you wish to replace a * value.

*

Values can either be strings or byte buffers. If a non string or byte buffer value is set, it will be converted to * a string using toString.

* @param [entries = []] -

The list of entries

*/ class Metadata { constructor(entries?: MetadataEntry[]); /** *

The entries as a map of keys to single values.

*

This allows working with the metadata as if it's just a map with single values for each key.

*

Modifications to the object will be reflected by replacing all values for a given key with a single value for the
* key.

*

Keys are also treated case insensitively.

*/ readonly asMap: { [key: string]: string | Buffer | undefined; }; /** *

The CloudEvent information extracted from the metadata.

*/ readonly cloudevent: Cloudevent; /** *

The JWT claims information extracted from the metadata.

*/ readonly jwtClaims: JwtClaims; /** * @returns

CloudEvent subject value.

*/ getSubject(): MetadataValue | undefined; /** *

Set the HTTP status code for the response when sending a successful response using HTTP transcoding.

*

This will only apply to responses that are being transcoded to plain HTTP from gRPC using the protobuf HTTP * annotations. When gRPC is being used, calling this has no effect.

* @param code -

The HTTP status code.

*/ setHttpStatusCode(code: number): void; /** *

Get all the values for the given key.

*

The key is case insensitive.

* @param key -

The key to get.

* @returns

All the values, or an empty array if no values exist for the key.

*/ get(key: string): MetadataValue[]; /** *

Set a given key value.

*

This will append the key value to the metadata, it won't replace any existing values for existing keys.

* @param key -

The key to set.

* @param value -

The value to set.

* @returns

This updated metadata.

*/ set(key: string, value: any): Metadata; /** *

Delete all values with the given key.

*

The key is case insensitive.

* @param key -

The key to delete.

* @returns

This updated metadata.

*/ delete(key: string): Metadata; /** *

Whether there exists a metadata value for the given key.

*

The key is case insensitive.

* @param key -

The key to check.

* @returns

Whether values exist for the given key.

*/ has(key: string): boolean; /** *

Clear the metadata.

* @returns

This updated metadata.

*/ clear(): Metadata; } /** *

This is any type that has been returned by the protobufjs Message.create method.

*

It should have a encode() method on it.

*/ type SerializableProtobufMessage = any; /** *

Any type that has a type property on it can be serialized as JSON, with the value of the type property describing * the type of the value.

*/ type TypedJson = { /** *

The type of the object.

*/ type: string; }; /** *

A type that is serializable.

*/ type Serializable = SerializableProtobufMessage | TypedJson | any | string | number | boolean | Long | Buffer; /** *

All Replicated Data types and Replicated Data type support classes.

*/ namespace replicatedentity { interface ReplicatedCounterMap extends replicatedentity.ReplicatedData { } /** *

A replicated map of counters.

*/ class ReplicatedCounterMap implements replicatedentity.ReplicatedData { /** *

Get the value at the given key.

* @param key -

The key to get.

* @returns

The counter value, or undefined if no value is defined at that key.

*/ get(key: Serializable): number | undefined; /** *

Get the value as a long at the given key.

* @param key -

The key to get.

* @returns

The counter value as a long, or undefined if no value is defined at that key.

*/ getLong(key: Serializable): Long | undefined; /** *

Increment the counter at the given key by the given number.

* @param key -

The key for the counter to increment.

* @param increment -

The amount to increment the counter by. If negative, it will be decremented instead.

* @returns

This counter map.

*/ increment(key: Serializable, increment: Long | number): replicatedentity.ReplicatedCounterMap; /** *

Decrement the counter at the given key by the given number.

* @param key -

The key for the counter to decrement.

* @param decrement -

The amount to decrement the counter by. If negative, it will be incremented instead.

* @returns

This counter map.

*/ decrement(key: Serializable, decrement: Long | number): replicatedentity.ReplicatedCounterMap; /** *

Check whether this map contains a value of the given key.

* @param key -

The key to check.

* @returns

True if this counter map contains a value for the given key.

*/ has(key: Serializable): boolean; /** *

The number of elements in this map.

*/ readonly size: number; /** *

Return an iterator of the keys of this counter map.

*/ keys(): IterableIterator; /** *

Delete the counter at the given key.

* @param key -

The key to delete.

* @returns

This counter map.

*/ delete(key: Serializable): replicatedentity.ReplicatedCounterMap; /** *

Clear all counters from this counter map.

* @returns

This counter map.

*/ clear(): replicatedentity.ReplicatedCounterMap; } interface ReplicatedCounter extends replicatedentity.ReplicatedData { } /** *

A Replicated Counter data type.

*

A counter that can be incremented and decremented.

*

The value is stored as a 64-bit signed long, hence values over 2^63 - 1 and less than 2^63 can't be represented.

*/ class ReplicatedCounter implements replicatedentity.ReplicatedData { /** *

The value as a long.

*/ readonly longValue: Long; /** *

The value as a number. Note that once the value exceeds 2^53, this will not be an accurate * representation of the value. If you expect it to exceed 2^53, {@link replicatedentity.ReplicatedCounter#longValue} * should be used instead.

*/ readonly value: number; /** *

Increment the counter by the given number.

* @param increment -

The amount to increment the counter by. If negative, it will be decremented instead.

* @returns

This counter.

*/ increment(increment: Long | number): replicatedentity.ReplicatedCounter; /** *

Decrement the counter by the given number.

* @param decrement -

The amount to decrement the counter by. If negative, it will be incremented instead.

* @returns

This counter.

*/ decrement(decrement: Long | number): replicatedentity.ReplicatedCounter; } /** *

A Replicated Data type.

*/ interface ReplicatedData { } /** *

A clock that may be used by {@link replicatedentity.ReplicatedRegister}.

*/ type Clock = number; /** *

An enum of all clocks that can be used by {@link replicatedentity.ReplicatedRegister}.

*/ enum Clocks { DEFAULT, REVERSE, CUSTOM, CUSTOM_AUTO_INCREMENT } interface ReplicatedMap extends replicatedentity.ReplicatedData, Iterable> { } /** *

A Replicated Map data type.

*

ReplicatedMaps are a mapping of keys (which can be any {@link Serializable}) to * Replicated Data types. Values of the map are merged together. Elements can be added and removed, however, when an * element is removed and then added again, it's possible that the old value will be merged with the new, depending on * whether the remove was replicated to all nodes before the add was.

*

Note that while the map may contain different types of Replicated Data for different keys, a given key may not change * its type, and doing so will likely result in the Replicated Data entering a non mergable state, from which it can't * recover.

*/ class ReplicatedMap implements replicatedentity.ReplicatedData, Iterable> { /** *

Generator for default values.

*

This is invoked by get when the current map has no Replicated Data defined for the key.

*

If this returns a Replicated Data object, it will be added to the map.

*

Care should be taken when using this, since it means that the get method can trigger elements to be created. If * using default values, the get method should not be used in queries where an empty value for the Replicated Data * means the value is not present.

*/ defaultValue: replicatedentity.ReplicatedMap.defaultValueCallback; /** *

Check whether this map contains a value of the given key.

* @param key -

The key to check.

* @returns

True if this map contains a value of the given key.

*/ has(key: Serializable): boolean; /** *

The number of elements in this map.

*/ readonly size: number; /** *

Execute the given callback for each element.

* @param callback -

The callback to handle each element.

*/ forEach(callback: replicatedentity.ReplicatedMap.forEachCallback): void; /** *

Return an iterator of the entries of this map.

*/ entries(): Iterator; /** *

Return an iterator of the entries of this map.

*/ iterator(): Iterator; /** *

Return an iterator of the values of this map.

*/ values(): Iterator; /** *

Return an iterator of the keys of this map.

*/ keys(): Iterator; /** *

Get the value at the given key.

* @param key -

The key to get.

* @returns

The Replicated Data value, or undefined if no value is defined at that key.

*/ get(key: Serializable): undefined | replicatedentity.ReplicatedData; /** *

A representation of this map as an object.

*

All entries whose keys are strings will be properties of this object, and setting any property of the object will * insert that property as a key into the map.

*/ asObject: { [key: string]: replicatedentity.ReplicatedData; }; /** *

Set the given value for the given key.

* @param key -

The key to set.

* @param value -

The value to set.

* @returns

This map.

*/ set(key: Serializable, value: replicatedentity.ReplicatedData): replicatedentity.ReplicatedMap; /** *

Delete the value at the given key.

* @param key -

The key to delete.

* @returns

This map.

*/ delete(key: Serializable): replicatedentity.ReplicatedMap; /** *

Clear all entries from this map.

* @returns

This map.

*/ clear(): replicatedentity.ReplicatedMap; } interface ReplicatedMultiMap extends replicatedentity.ReplicatedData { } /** *

A replicated multimap (map of sets).

*

A replicated map that maps keys to values, where each key may be associated with multiple values.

*/ class ReplicatedMultiMap implements replicatedentity.ReplicatedData { /** *

Get the values for the given key.

* @param key -

The key of the entry.

* @returns

The current values at the given key, or an empty Set.

*/ get(key: Serializable): Set; /** *

Store a key-value pair.

* @param key -

The key of the entry.

* @param value -

The value to add to the entry.

* @returns

This multimap.

*/ put(key: Serializable, value: Serializable): replicatedentity.ReplicatedMultiMap; /** *

Store multiple values for a key.

* @param key -

The key of the entry.

* @param values -

The values to add to the entry.

* @returns

This multimap.

*/ putAll(key: Serializable, values: Iterator): replicatedentity.ReplicatedMultiMap; /** *

Delete a single key-value pair for the given key and value.

* @param key -

The key of the entry.

* @param value -

The value to remove from the entry.

* @returns

This multimap.

*/ delete(key: Serializable, value: Serializable): replicatedentity.ReplicatedMultiMap; /** *

Delete all values associated with the given key.

* @param key -

The key of the entry.

* @returns

This multimap.

*/ deleteAll(key: Serializable): replicatedentity.ReplicatedMultiMap; /** *

Check whether this multimap contains at least one value for the given key.

* @param key -

The key to check.

* @returns

True if this multimap contains any values for the given key.

*/ has(key: Serializable): boolean; /** *

Check whether this multimap contains the given value associated with the given key.

* @param key -

The key to check.

* @param value -

The value to check.

* @returns

True if the key-value pair is in this multimap.

*/ hasValue(key: Serializable, value: Serializable): boolean; /** *

The total number of values stored in the multimap.

*/ readonly size: number; /** *

The number of keys with values stored in the multimap.

*/ readonly keysSize: number; /** *

Return an iterator of the keys of this multimap.

*/ keys(): IterableIterator; /** *

Clear all entries from this multimap.

* @returns

This multimap.

*/ clear(): replicatedentity.ReplicatedMultiMap; } interface ReplicatedRegisterMap extends replicatedentity.ReplicatedData { } /** *

A replicated map of registers.

*/ class ReplicatedRegisterMap implements replicatedentity.ReplicatedData { /** *

Get the value at the given key.

* @param key -

The key to get.

* @returns

The register value, or undefined if no value is defined at that key.

*/ get(key: Serializable): number | undefined; /** *

Set the register at the given key to the given value.

* @param key -

The key for the register.

* @param value -

The new value for the register.

* @param [clock = Clocks.DEFAULT] -

The register clock.

* @param [customClockValue = 0] -

Clock value when using custom clock, otherwise ignored.

* @returns

This register map.

*/ set(key: Serializable, value: Serializable, clock?: replicatedentity.Clock, customClockValue?: number): replicatedentity.ReplicatedRegisterMap; /** *

Check whether this map contains a value of the given key.

* @param key -

The key to check.

* @returns

True if this register map contains a value for the given key.

*/ has(key: Serializable): boolean; /** *

The number of elements in this map.

*/ readonly size: number; /** *

Return an iterator of the keys of this register map.

*/ keys(): IterableIterator; /** *

Delete the register at the given key.

* @param key -

The key to delete.

* @returns

This register map.

*/ delete(key: Serializable): replicatedentity.ReplicatedRegisterMap; /** *

Clear all registers from this register map.

* @returns

This register map.

*/ clear(): replicatedentity.ReplicatedRegisterMap; } interface ReplicatedRegister extends replicatedentity.ReplicatedData { } /** *

A Replicated Register data type.

*

A ReplicatedRegister uses a clock to determine which of two concurrent updates should win. The * last write wins. The clock is represented as a number. The default clock uses the proxies system * time, custom clocks can supply a custom number to be used. If two clock values are equal, the * write from the node with the lowest address wins.

* @param value -

A value to hold in the register.

* @param [clock = Clocks.DEFAULT] -

The clock to use.

* @param [customClockValue = 0] -

The custom clock value, if using a custom clock.

*/ class ReplicatedRegister implements replicatedentity.ReplicatedData { constructor(value: Serializable, clock?: replicatedentity.Clock, customClockValue?: number); /** *

The value of this register.

*

Setting it will cause it to be set with the default clock.

*/ value: Serializable; /** *

Set the value using a custom clock.

* @param value -

The value to set.

* @param [clock = Clocks.DEFAULT] -

The clock.

* @param [customClockValue = 0] -

Ignored if a custom clock isn't specified.

*/ setWithClock(value: Serializable, clock?: replicatedentity.Clock, customClockValue?: number): void; } interface ReplicatedSet extends replicatedentity.ReplicatedData, Iterable { } /** *

A Replicated Set data type.

*

A ReplicatedSet is a set of {@link Serializable} values. Elements can be added and removed.

*/ class ReplicatedSet implements replicatedentity.ReplicatedData, Iterable { /** *

Does this set contain the given element?

* @param element -

The element to check.

* @returns

True if the set contains the element.

*/ has(element: Serializable): boolean; /** *

The number of elements in this set.

*/ readonly size: number; /** *

Execute the given callback for each element.

* @param callback -

The callback to handle each element.

*/ forEach(callback: replicatedentity.ReplicatedSet.forEachCallback): void; /** *

Create an iterator for this set.

*/ iterator(): Iterator; /** *

Get a copy of the current elements as a Set.

*/ elements(): Set; /** *

Add an element to this set.

* @param element -

The element to add.

* @returns

This set.

*/ add(element: Serializable): replicatedentity.ReplicatedSet; /** *

Add multiple elements to this set.

* @param elements -

The elements to add.

* @returns

This set.

*/ addAll(elements: Iterator): replicatedentity.ReplicatedSet; /** *

Remove an element from this set.

* @param element -

The element to delete.

* @returns

This set.

*/ delete(element: Serializable): replicatedentity.ReplicatedSet; /** *

Remove all elements from this set.

* @returns

This set.

*/ clear(): replicatedentity.ReplicatedSet; } interface Vote extends replicatedentity.ReplicatedData { } /** *

A Vote Replicated Data type.

*

A Vote Replicated Data type allows all nodes an a cluster to vote on a condition, such as whether a user is online.

*/ class Vote implements replicatedentity.ReplicatedData { /** *

The number of nodes that have voted for this condition.

*/ readonly votesFor: number; /** *

The total number of nodes that have voted.

*/ readonly totalVoters: number; /** *

Whether at least one node has voted for this condition.

*/ readonly atLeastOne: boolean; /** *

Whether a majority of nodes have voted for this condition.

*/ readonly majority: boolean; /** *

Whether all of nodes have voted for this condition.

*/ readonly all: boolean; /** *

The current nodes vote.

*

Setting this will update the current nodes vote accordingly.

*/ vote: boolean; } /** *

Context for a Replicated Entity command handler.

*/ interface ReplicatedEntityCommandContext extends replicatedentity.StateManagementContext, CommandContext, EntityContext { } /** *

Context that allows managing a Replicated Entity's state.

*/ interface StateManagementContext { /** *

Delete this Replicated Entity.

*/ delete(): void; /** *

The Replicated Data state for a Replicated Entity. * It may only be set once, if it's already set, an error will be thrown.

*/ state: replicatedentity.ReplicatedData; } namespace ReplicatedEntity { /** *

Options for creating a Replicated Entity.

*/ type options = { /** *

The directories to include when looking up imported protobuf files.

* @defaultValue ["."] */ includeDirs?: string[]; /** *

Entity passivation strategy to use.

*/ entityPassivationStrategy?: replicatedentity.ReplicatedEntity.entityPassivationStrategy; /** *

Write consistency to use for this replicated entity.

*/ replicatedWriteConsistency?: ReplicatedWriteConsistency; }; /** *

Entity passivation strategy for a replicated entity.

*/ type entityPassivationStrategy = { /** *

Passivation timeout (in milliseconds).

*/ timeout?: number; }; /** *

A command handler callback.

* @param command -

The command message, this will be of the type of the gRPC service call input type.

* @param context -

The command context.

*/ type commandHandler = (command: any, context: replicatedentity.ReplicatedEntityCommandContext) => undefined | any; /** *

A state set handler callback.

*

This is invoked whenever a new state is set on the Replicated Entity, to allow the state to be enriched with domain * specific properties and methods. This may be due to the state being set explicitly from a command handler on the * command context, or implicitly as the default value, or implicitly when a new state is received from the proxy.

* @param state -

The Replicated Data state that was set.

* @param entityId -

The id of the entity.

*/ type onStateSetCallback = (state: replicatedentity.ReplicatedData, entityId: string) => void; /** *

A callback that is invoked to create a default value if the Akka Serverless proxy doesn't send an existing one.

* @param entityId -

The id of the entity.

*/ type defaultValueCallback = (entityId: string) => any; } namespace ReplicatedMap { /** *

Generator for default values.

*

This is invoked by get when the current map has no Replicated Data defined for the key.

*

If this returns a Replicated Data object, it will be added to the map.

*

Care should be taken when using this, since it means that the get method can trigger elements to be created. If * using default values, the get method should not be used in queries where an empty value for the Replicated Data * means the value is not present.

* @param key -

The key the default value is being generated for.

*/ type defaultValueCallback = (key: Serializable) => undefined | replicatedentity.ReplicatedData; /** *

Callback for handling elements iterated through by {@link replicatedentity.ReplicatedMap#forEach}.

* @param value -

The Replicated Data value.

* @param key -

The key.

* @param This -

map.

*/ type forEachCallback = (value: replicatedentity.ReplicatedData, key: Serializable, This: ReplicatedMap) => void; } namespace ReplicatedSet { /** *

Callback for handling elements iterated through by {@link replicatedentity.ReplicatedSet#forEach}.

* @param element -

The element.

*/ type forEachCallback = (element: Serializable) => void; } interface ReplicatedEntity extends Entity { } /** *

Create a Replicated Entity.

* @param desc -

The file name of a protobuf descriptor or set of descriptors containing the * Replicated Entity service.

* @param serviceName -

The fully qualified name of the gRPC service that this Replicated Entity implements.

* @param entityType -

The entity type name, used to namespace entities of different Replicated Data * types in the same service.

* @param [options] -

The options for this entity.

*/ class ReplicatedEntity implements Entity { /** *

Create a Replicated Entity.

* @param desc -

The file name of a protobuf descriptor or set of descriptors containing the * Replicated Entity service.

* @param serviceName -

The fully qualified name of the gRPC service that this Replicated Entity implements.

* @param entityType -

The entity type name, used to namespace entities of different Replicated Data * types in the same service.

* @param [options] -

The options for this entity.

*/ constructor(desc: string | string[], serviceName: string, entityType: string, options?: replicatedentity.ReplicatedEntity.options); options: replicatedentity.ReplicatedEntity.options; serviceName: string; service: protobuf.Service; /** *

Access to gRPC clients (with promisified unary methods).

*/ clients: GrpcClientLookup; /** *

The command handlers.

*

The names of the properties must match the names of the service calls specified in the gRPC descriptor for this * Replicated Entity service.

*/ commandHandlers: { [key: string]: replicatedentity.ReplicatedEntity.commandHandler; }; /** *

A callback that is invoked whenever the Replicated Data state is set for this Replicated Entity.

*

This is invoked whenever a new Replicated Data state is set on the Replicated Entity, to allow the state to be * enriched with domain specific properties and methods. This may be due to the state being set explicitly from a * command handler on the command context, or implicitly as the default value, or implicitly when a new state is * received from the proxy.

*/ onStateSet: replicatedentity.ReplicatedEntity.onStateSetCallback; /** *

A callback that is invoked to create a default value if the Akka Serverless proxy doesn't send an existing one.

*/ defaultValue: replicatedentity.ReplicatedEntity.defaultValueCallback; /** * @returns

replicated entity component type.

*/ componentType(): string; /** *

Lookup a Protobuf message type.

*

This is provided as a convenience to lookup protobuf message types for use, for example, as values in sets and * maps.

* @param messageType -

The fully qualified name of the type to lookup.

* @returns

The protobuf message type.

*/ lookupType(messageType: string): protobuf.Type; } } /** *

Creating replies.

*/ namespace replies { /** *

Side effect for a reply.

* @param method -

The entity service method to invoke.

* @param message -

The message to send to that service.

* @param [synchronous = false] -

Whether the effect should be execute synchronously or not, default is false

* @param [metadata] -

Metadata to send with the effect.

*/ class Effect { constructor(method: protobuf.Method, message: any, synchronous?: boolean, metadata?: Metadata); } /** *

A return type to allow returning forwards or failures, and attaching effects to messages.

*/ class Reply { /** * @returns

The protobuf method for a forwarding reply.

*/ getMethod(): protobuf.Method | undefined; /** *

Set the protobuf method for a forwarding reply.

* @param method -

The protobuf method.

* @returns

The updated reply.

*/ setMethod(method: protobuf.Method): replies.Reply; /** * @returns

the reply message

*/ getMessage(): any; /** *

Set the message for this reply.

* @param message -

The reply message.

* @returns

The updated reply.

*/ setMessage(message: any): replies.Reply; /** * @returns

The metadata attached to the reply.

*/ getMetadata(): Metadata; /** *

Attach metadata to this reply.

* @param metadata -

Metadata to send with the reply.

* @returns

The updated reply.

*/ setMetadata(metadata: Metadata | undefined): replies.Reply; /** * @returns

The forwarding reply.

*/ getForward(): replies.Reply | undefined; /** *

Make this a forwarding reply.

* @param forward -

The forward reply.

* @returns

The updated reply.

*/ setForward(forward: replies.Reply): replies.Reply; getFailure(): replies.Failure | undefined; /** *

Make this a failure reply.

* @param failure -

The failure description.

* @param [status] -

the status code to fail with, defaults to Unknown.

* @returns

The updated reply.

*/ setFailure(failure: string, status?: GrpcStatus): replies.Reply; /** * @returns

The side effects for this reply.

*/ getEffects(): replies.Effect[]; /** *

Attach the given effect to this reply.

* @param method -

The entity service method to invoke.

* @param message -

The message to send to that service.

* @param [synchronous = false] -

Whether the effect should be execute synchronously or not, default is false.

* @param [metadata] -

Metadata to send with the effect.

* @returns

This reply after adding the effect.

*/ addEffect(method: protobuf.Method, message: any, synchronous?: boolean, metadata?: Metadata): replies.Reply; /** *

Attach the given effects to this reply.

* @param effects -

One or more service calls to execute as side effects.

* @returns

This reply after adding the effects.

*/ addEffects(effects: Effect[]): replies.Reply; /** *

Whether this reply is empty: does not have a message, forward, or failure.

* @returns

Whether the reply is empty.

*/ isEmpty(): boolean; } /** *

Create a message reply.

* @param message -

The message to reply with.

* @param [metadata] -

Optional metadata to pass with the reply.

* @returns

A message reply.

*/ function message(message: any, metadata?: Metadata): replies.Reply; /** *

Create a forward reply.

* @param method -

The service call representing the forward.

* @param message -

The message to forward.

* @param [metadata] -

Optional metadata to pass with the forwarded message.

* @returns

A forward reply.

*/ function forward(method: protobuf.Method, message: any, metadata?: Metadata): replies.Reply; /** *

Create a failure reply.

* @param description -

A description of the failure.

* @param [status] -

the GRPC status, defaults to Unknown

* @returns

A failure reply.

*/ function failure(description: string, status?: GrpcStatus): replies.Reply; /** *

Create a reply that contains neither a message nor a forward nor a failure.

*

This may be useful for emitting effects without sending a message.

* @returns

An empty reply.

*/ function noReply(): replies.Reply; class Failure { getDescription(): string; getStatus(): GrpcStatus | undefined; } } namespace ValueEntity { /** *

Context for an value entity command.

*/ interface ValueEntityCommandContext extends CommandContext, EntityContext { /** *

Persist the updated state.

*

The state won't be persisted until the reply is sent to the proxy. Then, the state will be persisted * before the reply is sent back to the client.

* @param newState -

The state to store.

*/ updateState(newState: Serializable): void; /** *

Delete this entity.

*/ deleteState(): void; } /** *

Value entity command handlers * The names of the properties must match the names of the service calls specified in the gRPC descriptor for this value entities service.

*/ type commandHandlers = { [key: string]: ValueEntity.commandHandler; }; /** *

A command handler for one service call to the value entity

* @param command -

The command message, this will be of the type of the gRPC service call input type.

* @param state -

The entity state.

* @param context -

The command context.

*/ type commandHandler = (command: any, state: Serializable, context: ValueEntity.ValueEntityCommandContext) => undefined | any | replies.Reply; /** *

Initial state callback.

*

This is invoked if the entity is started with no snapshot.

* @param entityId -

The entity id.

*/ type initialCallback = (entityId: string) => Serializable; /** *

Options for a value entity.

*/ type options = { /** *

The directories to include when looking up imported protobuf files.

* @defaultValue ["."] */ includeDirs?: string[]; /** *

Whether serialization of primitives should be supported when serializing the state.

*/ serializeAllowPrimitives?: boolean; /** *

Whether serialization should fallback to using JSON if the state can't be serialized as a protobuf.

*/ serializeFallbackToJson?: boolean; /** *

request headers to be forwarded as metadata to the value entity

* @defaultValue [] */ forwardHeaders?: string[]; /** *

Entity passivation strategy to use.

*/ entityPassivationStrategy?: ValueEntity.entityPassivationStrategy; }; /** *

Entity passivation strategy for a value entity.

*/ type entityPassivationStrategy = { /** *

Passivation timeout (in milliseconds).

*/ timeout?: number; }; } interface ValueEntity extends Entity { } /** *

Create a new value entity.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this entities interface.

* @param entityType -

The entity type name for all value entities of this type. Never change it after deploying * a service that stored data of this type

* @param [options] -

The options for this entity

*/ class ValueEntity implements Entity { /** *

Create a new value entity.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this entities interface.

* @param entityType -

The entity type name for all value entities of this type. Never change it after deploying * a service that stored data of this type

* @param [options] -

The options for this entity

*/ constructor(desc: string | string[], serviceName: string, entityType: string, options?: ValueEntity.options); options: ValueEntity.options; serviceName: string; service: protobuf.Service; /** *

Access to gRPC clients (with promisified unary methods).

*/ clients: GrpcClientLookup; /** * @returns

value entity component type.

*/ componentType(): string; /** *

Lookup a protobuf message type.

*

This is provided as a convenience to lookup protobuf message types for use with state.

* @param messageType -

The fully qualified name of the type to lookup.

* @returns

The protobuf message type.

*/ lookupType(messageType: string): protobuf.Type; /** *

The initial state callback.

*/ initial: ValueEntity.initialCallback; /** *

Set the initial state callback.

* @param callback -

The initial state callback.

* @returns

This entity.

*/ setInitial(callback: ValueEntity.initialCallback): ValueEntity; /** *

The command handlers.

*/ commandHandlers: ValueEntity.commandHandlers; /** *

Set the command handlers of the entity.

* @param handlers -

The command handler callbacks.

* @returns

This entity.

*/ setCommandHandlers(handlers: ValueEntity.commandHandlers): ValueEntity; } namespace View { /** *

Context for a view update event.

* @property metadata -

for the event

*/ interface UpdateHandlerContext { } /** *

Options for a view.

*/ type options = { /** *

The id for the view, used for persisting the view.

* @defaultValue serviceName */ viewId?: string; /** *

The directories to include when looking up imported protobuf files.

* @defaultValue ["."] */ includeDirs?: string[]; }; /** *

View handlers * The names of the properties must match the names of all the view methods specified in the gRPC * descriptor.

*/ type handlers = { [key: string]: View.handler; }; /** *

A handler for transforming an incoming event and the previous view state into a new state

* @param event -

The event, this will be of the type of the gRPC event handler input type.

* @param state -

The previous view state or 'undefined' if no previous state was stored.

* @param context -

The view handler context.

*/ type handler = (event: any, state: undefined | Serializable, context: View.UpdateHandlerContext) => undefined | Serializable; } interface View extends Component { } /** *

Create a new view.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this interface.

* @param [options] -

The options for this view

*/ class View implements Component { /** *

Create a new view.

* @param desc -

A descriptor or list of descriptors to parse, containing the service to serve.

* @param serviceName -

The fully qualified name of the service that provides this interface.

* @param [options] -

The options for this view

*/ constructor(desc: string | string[], serviceName: string, options?: View.options); options: View.options; serviceName: string; service: protobuf.Service; /** * @returns

view component type.

*/ componentType(): string; /** *

Lookup a protobuf message type.

*

This is provided as a convenience to lookup protobuf message types.

* @param messageType -

The fully qualified name of the type to lookup.

* @returns

The protobuf message type.

*/ lookupType(messageType: string): protobuf.Type; /** *

Set the update handlers of the view. Only used for updates where event transformation is enabled through * "transform_updates: true" in the grpc descriptor.

* @param handlers -

The handler callbacks.

* @returns

This view.

*/ setUpdateHandlers(handlers: View.handlers): View; } namespace settings { const frameworkVersion: string; interface ProtocolVersion { major: string; minor: string; } function protocolVersion(): settings.ProtocolVersion; function baseVersion(): string; } }