Skip to content

Latest commit

 

History

History
1892 lines (1325 loc) · 65.9 KB

api.md

File metadata and controls

1892 lines (1325 loc) · 65.9 KB

Modules

Picobuf

Represents the main class for the Picobuf library.

Picobuf can be instantiated in two ways: using the new keyword or calling Picobuf as a function. Both methods are equivalent. The constructor can receive an optional definitions parameter, which is an object that can include model, enum, and service definitions. Alternatively, these elements can be defined after instantiation, using the relevant methods.

A Picobuf instance is a Proxy object, so it allows destructuring of models, enums, and services directly from the instance.

Classes

Config : Config

Represents the Config class that handles configuration for the application.

Domain : Domain

Represents a Domain.

BaseEncoder

Represents a base encoder.

NoneEncoderBaseEncoder

Represents a NoneEncoder.

MsgPackEncoderBaseEncoder

Represents a MsgPackEncoder.

Enum

Represents an enumeration.

Field

Represents a Field.

BaseField

Represents a base field. This is an abstract base class and cannot be instantiated directly.

StringFieldBaseField

Represents a string field.

BooleanFieldBaseField

Represents a boolean field.

NumberFieldBaseField

Represents a numeric field.

IntegerFieldNumberField

Represents an integer field.

FloatFieldNumberField

Represents a floating-point number field.

EnumFieldBaseField

Represents an enumeration field.

JsonFieldBaseField

Represents a JSON field.

BufferFieldBaseField

Represents a buffer field.

ForeignFieldBaseField

Represents a foreign field.

ModelBuilder

Represents a Model Builder.

Model

Represents a model.

PicobufNodePicobuf

Represents the PicobufNode class, which extends Picobuf.

Method

Represents a Method.

Service

Represents a Service.

Constants

DEFAULT_CONFIG : Object

Default configuration values.

GlobalConfig : Config

The global configuration instance.

DEFAULT_BUFFERS : Array.<string>

Default buffers.

DEFAULT_FIELD_TYPE : string

Default field type.

DEFAULT_OBJECT_MODE : boolean

Default object mode.

DEFAULT_ENCODER : string

Default encoder.

SINGLE_PROP : string

Single property.

DEFAULT_STRICT : boolean

Default strict setting.

MODEL_TYPES : Object

Model types.

GlobalDomain : Domain

The global domain instance.

_

Picobuf utilities. This module provides a custom utility library, combining individual lodash function modules into a single object. It's designed to provide the most frequently used lodash functions, while minimizing the amount of code that's needed. Each function is imported from its own lodash module, which allows for efficient tree-shaking by the bundler. Additionally, the module includes some custom utilities such as isBrowser for checking if the code is running in a browser environment.

Picobuf

Represents the main class for the Picobuf library.

Picobuf can be instantiated in two ways: using the new keyword or calling Picobuf as a function. Both methods are equivalent. The constructor can receive an optional definitions parameter, which is an object that can include model, enum, and service definitions. Alternatively, these elements can be defined after instantiation, using the relevant methods.

A Picobuf instance is a Proxy object, so it allows destructuring of models, enums, and services directly from the instance.

Picobuf~Picobuf

Kind: inner class of Picobuf

new Picobuf([options], config, domain)

Creates a new instance of Picobuf.

Throws:

  • Error If the options are not valid or if the loading from file is attempted outside Node.js environment.
Param Type Description
[options] object Optional options to configure the Picobuf instance.
[options.models] object An object where keys are model names and values are model definitions.
[options.enums] object An object where keys are enum names and values are enum definitions.
[options.services] object An object where keys are service names and values are service definitions.
config Config The configuration options for the Picobuf.
domain Domain The domain for the Picobuf.

picobuf.load(options)

Loads the provided options into the Picobuf.

Kind: instance method of Picobuf

Param Type Description
options Object The options to load.

picobuf.setDomain(domain)

Sets the domain for the Picobuf.

Kind: instance method of Picobuf

Param Type Description
domain Domain The domain to set.

picobuf.createModel(name, fields, config, [modelClass]) ⇒ Model

Creates a new model in the Picobuf domain.

Kind: instance method of Picobuf
Returns: Model - The created model.

Param Type Default Description
name string The name of the model.
fields Object The fields for the model.
config ConfigOptions The configuration options for the model.
[modelClass] Model Model The class for the model.

picobuf.createModels(models)

Creates multiple models in the Picobuf domain.

Kind: instance method of Picobuf

Param Type Description
models Object An object mapping names to fields for each model.

picobuf.getModel(name) ⇒ Model | undefined

Retrieves a model from the Picobuf domain by its name.

Kind: instance method of Picobuf
Returns: Model | undefined - The retrieved model or undefined if the model does not exist.

Param Type Description
name string The name of the model.

picobuf.createEnum(name, values, config, [enumClass]) ⇒ Enum

Creates a new enum in the Picobuf domain.

Kind: instance method of Picobuf
Returns: Enum - The created enum.

Param Type Default Description
name string The name of the enum.
values Array.<string> The values for the enum.
config ConfigOptions The configuration options for the enum.
[enumClass] Enum Enum The class for the enum.

picobuf.createEnums(enums)

Creates multiple enums in the Picobuf domain.

Kind: instance method of Picobuf

Param Type Description
enums Object An object mapping names to values for each enum.

picobuf.getEnum(name) ⇒ Enum | undefined

Retrieves an enum from the Picobuf domain by its name.

Kind: instance method of Picobuf
Returns: Enum | undefined - The retrieved enum or undefined if the enum does not exist.

Param Type Description
name string The name of the enum.

picobuf.createService(name, definition) ⇒ Service

Creates a new service in the Picobuf domain.

Kind: instance method of Picobuf
Returns: Service - The created service.

Param Type Description
name string The name of the service.
definition Object The definition for the service.

picobuf.createServices(services)

Creates multiple services in the Picobuf domain.

Kind: instance method of Picobuf

Param Type Description
services Object An object mapping names to definitions for each service.

picobuf.getService(name) ⇒ Service | undefined

Retrieves a service from the Picobuf domain by its name.

Kind: instance method of Picobuf
Returns: Service | undefined - The retrieved service or undefined if the service does not exist.

Param Type Description
name string The name of the service.

Picobuf.set(newConfig)

Sets the Config for the Picobuf class.

Kind: static method of Picobuf

Param Type Description
newConfig ConfigOptions The new configuration options for the Picobuf class.

Config : Config

Represents the Config class that handles configuration for the application.

Kind: global class

new Config(initialConfig)

Creates a new Config instance.

Param Type Description
initialConfig Object The initial configuration.

config.defaults : Object

The default configuration.

Kind: instance property of Config

config.setConfig(newConfig)

Updates the current configuration.

Kind: instance method of Config

Param Type Description
newConfig Object The new configuration.

config.setDefault(defaultConfig)

Merges the default configuration into the current configuration.

Kind: instance method of Config

Param Type Description
defaultConfig Object The default configuration.

config.get(key, [defaultValue]) ⇒ any

Gets the value of a key from the configuration.

Kind: instance method of Config
Returns: any - The value.

Param Type Default Description
key string The key.
[defaultValue] any The default value if key is not found.

config.getConfig() ⇒ Object

Gets the current configuration.

Kind: instance method of Config
Returns: Object - The current configuration.

Config.get(config) ⇒ Config

Returns an instance of Config based on the passed config parameter.

Kind: static method of Config
Returns: Config - The instance of Config.

Param Type Description
config Config | Object The config object.

Config.set(newConfig) ⇒ Config

Updates the global configuration.

Kind: static method of Config
Returns: Config - The updated global configuration.

Param Type Description
newConfig Object The new configuration.

Config.getConfig(config) ⇒ Object

Returns the configuration object of a Config instance or default config.

Kind: static method of Config
Returns: Object - The configuration object.

Param Type Description
config Config | Object The config object.

Config.setConfig(newConfig)

Merges new configuration with default configuration.

Kind: static method of Config

Param Type Description
newConfig Object The new configuration.

Domain : Domain

Represents a Domain.

Kind: global class

new Domain(config)

Creates a new instance of Domain. This class provides methods to manage models and enums.

Param Type Description
config Config A Config instance.

domain.createModel(name, fields, config, modelClass) ⇒ object

Creates a new Model instance.

Kind: instance method of Domain
Returns: object - The newly created model instance.

Param Type Description
name string The name of the model.
fields object The fields for the model.
config Config A Config instance for the model.
modelClass function The constructor of the model class.

domain.setModel(name, model)

Sets a Model in the Domain.

Kind: instance method of Domain

Param Type Description
name string The name of the model.
model object The model instance to be set.

domain.getModel(name) ⇒ object | null

Gets a Model from the Domain.

Kind: instance method of Domain
Returns: object | null - The requested model, if found. Otherwise, returns null.

Param Type Description
name string The name of the model.

domain.createEnum(name, values, config, enumClass) ⇒ object

Creates a new Enum instance.

Kind: instance method of Domain
Returns: object - The newly created enum instance.

Param Type Description
name string The name of the enum.
values Array.<string> The values for the enum.
config Config A Config instance for the enum.
enumClass function The constructor of the enum class.

domain.getEnum(name) ⇒ object | null

Gets an Enum from the Domain.

Kind: instance method of Domain
Returns: object | null - The requested enum, if found. Otherwise, returns null.

Param Type Description
name string The name of the enum.

domain.setEnum(name, enumInstance)

Sets an Enum in the Domain.

Kind: instance method of Domain

Param Type Description
name string The name of the enum.
enumInstance object The enum instance to be set.

BaseEncoder

Represents a base encoder.

Kind: global class

new BaseEncoder(model)

Creates a new instance of BaseEncoder.

Throws:

  • TypeError - If a new instance of BaseEncoder is attempted to be created directly.
Param Type Description
model Model The model that the encoder will operate on.

baseEncoder.encode(data)

Method stub for encoding data.

Kind: instance method of BaseEncoder
Throws:

  • Error - If the method is not implemented.
Param Type Description
data * The data to encode.

baseEncoder.decode(data)

Method stub for decoding data.

Kind: instance method of BaseEncoder
Throws:

  • Error - If the method is not implemented.
Param Type Description
data * The data to decode.

NoneEncoder ⇐ BaseEncoder

Represents a NoneEncoder.

Kind: global class
Extends: BaseEncoder

noneEncoder.encode(data) ⇒ *

Encodes the data by returning it unchanged.

Kind: instance method of NoneEncoder
Overrides: encode
Returns: * - - The unchanged data.

Param Type Description
data * The data to encode.

noneEncoder.decode(data) ⇒ *

Decodes the data by returning it unchanged.

Kind: instance method of NoneEncoder
Overrides: decode
Returns: * - - The unchanged data.

Param Type Description
data * The data to decode.

MsgPackEncoder ⇐ BaseEncoder

Represents a MsgPackEncoder.

Kind: global class
Extends: BaseEncoder

msgPackEncoder.encode(data) ⇒ *

Encodes the data using msgpack.

Kind: instance method of MsgPackEncoder
Overrides: encode
Returns: * - - The encoded data.

Param Type Description
data * The data to encode.

msgPackEncoder.decode(data) ⇒ *

Decodes the data using msgpack.

Kind: instance method of MsgPackEncoder
Overrides: decode
Returns: * - - The decoded data.

Param Type Description
data * The data to decode.

Enum

Represents an enumeration.

Kind: global class

new Enum(name, values, config, [domain])

Creates a new instance of Enum.

Param Type Default Description
name string The name of the enum.
values Array.<string> The values of the enum.
config ConfigOptions The configuration options for the enum.
[domain] Domain GlobalDomain The domain for the enum, defaults to GlobalDomain if none provided.

enum.hasValue(value) ⇒ boolean

Checks if a value exists in the enumeration.

Kind: instance method of Enum
Returns: boolean - True if the value exists, false otherwise.

Param Type Description
value * The value to check.

enum.getIndex(value) ⇒ number

Retrieves the index of a value in the enumeration.

Kind: instance method of Enum
Returns: number - The index of the value, or undefined if the value does not exist.

Param Type Description
value * The value to get the index for.

enum.getValue(index) ⇒ *

Retrieves the value at a specific index in the enumeration.

Kind: instance method of Enum
Returns: * - The value at the specified index, or undefined if no value exists at that index.

Param Type Description
index number The index to get the value for.

enum.addValue(value) ⇒ void

Adds a new value to the enum.

Kind: instance method of Enum
Throws:

  • Error If the value already exists in the enum.
Param Type Description
value * The value to be added to the enum.

Field

Represents a Field.

Kind: global class

new Field(name, field, config, domain)

Creates a new instance of Field.

Param Type Description
name string The name of the field.
field FieldOption The field option for the field.
config ConfigOptions The configuration options for the field.
domain Domain The domain for the field.

BaseField

Represents a base field. This is an abstract base class and cannot be instantiated directly.

Kind: global class

new BaseField(name, field, config, domain)

Creates a new instance of BaseField.

Throws:

  • TypeError If attempted to be instantiated directly.
Param Type Description
name string The name of the field.
field Object An object representing the field. This object should include 'type', 'required', 'default', and 'list' properties.
config ConfigOptions The configuration options for the field.
domain Domain The domain for the field.

baseField.validate(value)

Validates the provided value against the field.

Kind: instance method of BaseField
Throws:

  • Error If the value is of an incorrect type for the field.
Param Type Description
value * The value to validate.

baseField.serialize(data) ⇒ *

Serializes the provided data.

Kind: instance method of BaseField
Returns: * - The serialized data.

Param Type Description
data * The data to serialize.

baseField.deserialize(data) ⇒ *

Deserializes the provided data.

Kind: instance method of BaseField
Returns: * - The deserialized data.

Param Type Description
data * The data to deserialize.

StringField ⇐ BaseField

Represents a string field.

Kind: global class
Extends: BaseField

stringField.validate(value)

Validates the provided value against the field.

Kind: instance method of StringField
Throws:

  • Error If the value is of an incorrect type for the field.
Param Type Description
value * The value to validate.

stringField.serialize(data) ⇒ *

Serializes the provided data.

Kind: instance method of StringField
Returns: * - The serialized data.

Param Type Description
data * The data to serialize.

stringField.deserialize(data) ⇒ *

Deserializes the provided data.

Kind: instance method of StringField
Returns: * - The deserialized data.

Param Type Description
data * The data to deserialize.

BooleanField ⇐ BaseField

Represents a boolean field.

Kind: global class
Extends: BaseField

booleanField.validate(value)

Validates the provided boolean value.

Kind: instance method of BooleanField
Overrides: validate
Throws:

  • Error If the value is not a boolean.
Param Type Description
value * The value to validate.

booleanField.serialize(value) ⇒ number

Serializes the provided boolean value to 1 (for true) or 0 (for false).

Kind: instance method of BooleanField
Overrides: serialize
Returns: number - The serialized value.

Param Type Description
value * The boolean value to serialize.

booleanField.deserialize(value) ⇒ boolean

Deserializes the provided value to a boolean. 1 is deserialized to true, and anything else to false.

Kind: instance method of BooleanField
Overrides: deserialize
Returns: boolean - The deserialized value.

Param Type Description
value * The value to deserialize.

NumberField ⇐ BaseField

Represents a numeric field.

Kind: global class
Extends: BaseField

numberField.validate(value)

Validates the provided numeric value.

Kind: instance method of NumberField
Overrides: validate
Throws:

  • Error If the value is not a number or is NaN.
Param Type Description
value * The value to validate.

numberField.serialize(data) ⇒ *

Serializes the provided data.

Kind: instance method of NumberField
Returns: * - The serialized data.

Param Type Description
data * The data to serialize.

numberField.deserialize(data) ⇒ *

Deserializes the provided data.

Kind: instance method of NumberField
Returns: * - The deserialized data.

Param Type Description
data * The data to deserialize.

IntegerField ⇐ NumberField

Represents an integer field.

Kind: global class
Extends: NumberField

integerField.validate(value)

Validates the provided integer value.

Kind: instance method of IntegerField
Overrides: validate
Throws:

  • Error If the value is not an integer.
Param Type Description
value * The value to validate.

integerField.serialize(data) ⇒ *

Serializes the provided data.

Kind: instance method of IntegerField
Returns: * - The serialized data.

Param Type Description
data * The data to serialize.

integerField.deserialize(data) ⇒ *

Deserializes the provided data.

Kind: instance method of IntegerField
Returns: * - The deserialized data.

Param Type Description
data * The data to deserialize.

FloatField ⇐ NumberField

Represents a floating-point number field.

Kind: global class
Extends: NumberField

floatField.serialize(data) ⇒ string

Serializes the provided floating-point number.

Kind: instance method of FloatField
Overrides: serialize
Returns: string - The serialized data.

Param Type Description
data * The data to serialize.

floatField.deserialize(data) ⇒ number

Deserializes the provided string to a floating-point number.

Kind: instance method of FloatField
Overrides: deserialize
Returns: number - The deserialized data.

Param Type Description
data * The data to deserialize.

floatField.validate(value)

Validates the provided numeric value.

Kind: instance method of FloatField
Throws:

  • Error If the value is not a number or is NaN.
Param Type Description
value * The value to validate.

EnumField ⇐ BaseField

Represents an enumeration field.

Kind: global class
Extends: BaseField

new EnumField(name, field, config)

Creates a new instance of EnumField.

Param Type Description
name string The name of the enum field.
field object The field object.
config ConfigOptions The configuration options for the enum field.

enumField.validate(value)

Validates the provided enum value.

Kind: instance method of EnumField
Overrides: validate
Throws:

  • Error If the value is not a string or if it's not a valid enum value.
Param Type Description
value * The value to validate.

enumField.serialize(value) ⇒ number

Serializes the provided enum value.

Kind: instance method of EnumField
Overrides: serialize
Returns: number - The serialized value.

Param Type Description
value * The enum value to serialize.

enumField.deserialize(value) ⇒ string

Deserializes the provided value to an enum value.

Kind: instance method of EnumField
Overrides: deserialize
Returns: string - The deserialized value.

Param Type Description
value * The value to deserialize.

JsonField ⇐ BaseField

Represents a JSON field.

Kind: global class
Extends: BaseField

jsonField.validate(value)

Validates the provided JSON value.

Kind: instance method of JsonField
Overrides: validate
Throws:

  • Error If the value is not an object.
Param Type Description
value * The value to validate.

jsonField.serialize(data) ⇒ *

Serializes the provided data.

Kind: instance method of JsonField
Returns: * - The serialized data.

Param Type Description
data * The data to serialize.

jsonField.deserialize(data) ⇒ *

Deserializes the provided data.

Kind: instance method of JsonField
Returns: * - The deserialized data.

Param Type Description
data * The data to deserialize.

BufferField ⇐ BaseField

Represents a buffer field.

Kind: global class
Extends: BaseField

bufferField.validate(value)

Validates the provided buffer value.

Kind: instance method of BufferField
Overrides: validate
Throws:

  • Error If the value is not a buffer.
Param Type Description
value * The value to validate.

bufferField.serialize(data) ⇒ *

Serializes the provided data.

Kind: instance method of BufferField
Returns: * - The serialized data.

Param Type Description
data * The data to serialize.

bufferField.deserialize(data) ⇒ *

Deserializes the provided data.

Kind: instance method of BufferField
Returns: * - The deserialized data.

Param Type Description
data * The data to deserialize.

ForeignField ⇐ BaseField

Represents a foreign field.

Kind: global class
Extends: BaseField

new ForeignField(name, field, config, domain)

Creates a new instance of ForeignField.

Throws:

  • Error If the model for the foreign field could not be found.
Param Type Description
name string The name of the foreign field.
field object The field object.
config ConfigOptions The configuration options for the foreign field.
domain Domain The domain for the foreign field.

foreignField.validate(value)

Validates the provided value using the model of the foreign field.

Kind: instance method of ForeignField
Overrides: validate

Param Type Description
value * The value to validate.

foreignField.serialize(value) ⇒ *

Serializes the provided value using the model of the foreign field.

Kind: instance method of ForeignField
Overrides: serialize
Returns: * - The serialized value.

Param Type Description
value * The value to serialize.

foreignField.deserialize(value) ⇒ *

Deserializes the provided value to a model instance of the foreign field.

Kind: instance method of ForeignField
Overrides: deserialize
Returns: * - The deserialized value.

Param Type Description
value * The value to deserialize.

ModelBuilder

Represents a Model Builder.

Kind: global class

new ModelBuilder(model, fields, config, domain)

Creates a new instance of ModelBuilder.

Param Type Description
model Model The model to be built.
fields object The fields of the model.
config ConfigOptions The configuration options for the model.
domain Domain The domain for the model.

modelBuilder.getFields() ⇒ Array

Fetches the fields for the model.

Kind: instance method of ModelBuilder
Returns: Array - An array of fields for the model.

modelBuilder.getInitialType() ⇒ string

Determines the initial type of the model.

Kind: instance method of ModelBuilder
Returns: string - The initial type of the model.

modelBuilder.getFieldsArray(arr) ⇒ Array

Converts the model fields into an array.

Kind: instance method of ModelBuilder
Returns: Array - The converted model fields.

Param Type Description
arr Array The model fields to convert.

modelBuilder.getFieldsSingle(input) ⇒ object

Fetches a single field from the model.

Kind: instance method of ModelBuilder
Returns: object - The fetched field.

Param Type Description
input string The name of the field to fetch.

modelBuilder.getFieldsObject(input) ⇒ Array.<Field>

Transforms an object of fields into an array of Field instances. This method takes into account several field configurations such as type, required, default, repeated, enum and creates a Field instance for each field definition.

Kind: instance method of ModelBuilder
Returns: Array.<Field> - An array of Field instances, each representing a field in the input.

Here's what happens in detail:

  • If the field definition is a string, it's assumed to be the type of the field. An object is then created with the type set to the string.
  • If the type of the field isn't explicitly set, it's defaulted to the defaultFieldType from the configuration.
  • If the required property isn't explicitly set to a boolean, it's set based on the strict mode from the configuration. If strict mode is enabled, the field is considered required.
  • If a default value is provided and strict mode is enabled, the field is marked as not required.
  • If both a default value is provided and the field is marked as required, an error is thrown because this is an inconsistent state.
  • If the field is marked as repeated, the list property is set to true and repeated is deleted.
  • If the type of the field is an array, the actual type is set to the first element of the array and list is set to true.
  • If the type starts with '', the required property is set to true and the '' is removed from the type.
  • If enum or values properties are provided, the type is set to 'enum'.
  • If the type is 'enum', depending on the enum property value:
    • If it's a string, it's assumed to be the name of an Enum instance which is fetched from the domain. The values from the Enum instance are also fetched.
    • If it's an Enum instance, its values are fetched.
    • If it's an array, it's used as the values for the Enum.
  • Finally, an Enum instance is created if enum is not already an Enum instance.
  • For each field, a Field instance is created with the name and the final configuration, and pushed to the array to be returned.
Param Type Description
input Object An object whose properties represent field definitions. Each property value could be a string (representing a type), or an object with detailed configuration.

modelBuilder.getEncoder() ⇒ Encoder

Fetches the encoder for the model.

Kind: instance method of ModelBuilder
Returns: Encoder - The encoder for the model.

modelBuilder.getEncoderClass(encoder, encoders) ⇒ function | undefined

Fetches the encoder class based on a string.

Kind: instance method of ModelBuilder
Returns: function | undefined - The fetched encoder class.

Param Type Description
encoder string The name of the encoder to fetch.
encoders object The object containing the encoder classes keyed by class name.

modelBuilder.build() ⇒ Model

Builds the model.

Kind: instance method of ModelBuilder
Returns: Model - The built model.

Model

Represents a model.

Kind: global class

new Model(name, fields, config, [domain])

Creates a new instance of Model.

Param Type Default Description
name string The name of the model.
fields Array.<Field> The fields of the model.
config ConfigOptions The configuration options for the model.
[domain] Domain GlobalDomain The domain for the model, defaults to GlobalDomain if none provided.

model.create(data, ...args) ⇒ *

Creates a new instance of the model with the provided data.

Kind: instance method of Model
Returns: * - The created model instance.

Param Type Description
data Object The data for the new model instance.
...args * Additional arguments.

model.validate(data) ⇒ boolean

Validates the provided data against the model.

Kind: instance method of Model
Returns: boolean - True if the data is valid, false otherwise.

Param Type Description
data Object The data to validate.

model.encode(data) ⇒ string

Encodes the provided data.

Kind: instance method of Model
Returns: string - The encoded data.

Param Type Description
data Object The data to encode.

model.decode(input) ⇒ Object

Decodes the provided input.

Kind: instance method of Model
Returns: Object - The decoded data.

Param Type Description
input string The input to decode.

PicobufNode ⇐ Picobuf

Represents the PicobufNode class, which extends Picobuf.

Kind: global class
Extends: Picobuf

new PicobufNode(options, config, domain)

Creates a new instance of PicobufNode.

Param Type Description
options object The options for the PicobufNode.
config ConfigOptions The configuration options for the PicobufNode.
domain Domain The domain for the PicobufNode.

picobufNode.Picobuf : function

Provides a Proxy for instantiating new PicobufNode objects.

Kind: instance property of PicobufNode

picobufNode.load(options, [loader]) ⇒ PicobufNode

Loads configuration data for the PicobufNode.

Kind: instance method of PicobufNode
Returns: PicobufNode - The PicobufNode instance.
Throws:

  • Error Throws an error if an invalid loader is provided or if the options cannot be parsed.
Param Type Description
options object | string The options to load. If a string is passed, it is treated as a file path to load configuration from.
[loader] function | string The loader to use for loading the configuration. If a string is passed, it is used to find a default loader function. If not provided, the loader will be determined based on the file extension.

Method

Represents a Method.

Kind: global class

new Method(name, requestModel, responseModel)

Creates a new instance of Method.

Param Type Description
name string The name of the method.
requestModel Model The request model for the method.
responseModel Model The response model for the method.

Service

Represents a Service.

Kind: global class

new Service(name, definition, [domain])

Creates a new instance of Service.

Param Type Default Description
name string The name of the service.
definition Object The definition of the service.
[domain] Domain GlobalDomain The domain of the service.

service.createMethod(name, requestModel, responseModel, [domain]) ⇒ Method

Creates a new method within the Service.

Kind: instance method of Service
Returns: Method - The created method.

Param Type Default Description
name string The name of the method.
requestModel Model | string | object The request model for the method. Can be a Model instance, model name string or model definition object.
responseModel Model | string | object The response model for the method. Can be a Model instance, model name string or model definition object.
[domain] Domain this.domain The domain for the method. Defaults to the Service's domain.

service.getMethod(name) ⇒ Method | null

Retrieves a method from the Service by its name.

Kind: instance method of Service
Returns: Method | null - The retrieved method or null if not found.

Param Type Description
name string The name of the method.

DEFAULT_CONFIG : Object

Default configuration values.

Kind: global constant
Properties

Name Type Description
objectMode boolean Default object mode. Defaults to CONSTANTS.DEFAULT_OBJECT_MODE.
strict boolean Whether to use strict mode. Defaults to CONSTANTS.DEFAULT_STRICT.
defaultFieldType string The default field type. Defaults to CONSTANTS.DEFAULT_FIELD_TYPE.
defaultEncoder string The default encoder. Defaults to CONSTANTS.DEFAULT_ENCODER.
singleProp boolean Whether to use single property mode. Defaults to CONSTANTS.SINGLE_PROP.
fieldClasses Object The field classes.
encoderClasses Object The encoder classes.

GlobalConfig : Config

The global configuration instance.

Kind: global constant

DEFAULT_BUFFERS : Array.<string>

Default buffers.

Kind: global constant

DEFAULT_FIELD_TYPE : string

Default field type.

Kind: global constant

DEFAULT_OBJECT_MODE : boolean

Default object mode.

Kind: global constant

DEFAULT_ENCODER : string

Default encoder.

Kind: global constant

SINGLE_PROP : string

Single property.

Kind: global constant

DEFAULT_STRICT : boolean

Default strict setting.

Kind: global constant

MODEL_TYPES : Object

Model types.

Kind: global constant

GlobalDomain : Domain

The global domain instance.

Kind: global constant

_

Picobuf utilities. This module provides a custom utility library, combining individual lodash function modules into a single object. It's designed to provide the most frequently used lodash functions, while minimizing the amount of code that's needed. Each function is imported from its own lodash module, which allows for efficient tree-shaking by the bundler. Additionally, the module includes some custom utilities such as isBrowser for checking if the code is running in a browser environment.

Kind: global constant
See: Lodash Documentation

_.isBrowser : boolean

Checks if the current execution environment is a web browser. It returns true if the global window object is defined, false otherwise.

Kind: static property of _

_.log(...args)

Log a message to the console.

Kind: static method of _

Param Type Description
...args * The message or messages to log.

_.print(...args)

Alias for _.log.

Kind: static method of _

Param Type Description
...args * The message or messages to log.

_.objProp(obj, key, value, opts)

Define a property on an object with given options.

Kind: static method of _

Param Type Description
obj Object The object to define a property on.
key string The name of the property.
value * The value of the property.
opts Object The property descriptor.

_.proxyGet(obj, callback) ⇒ Proxy

Create a Proxy with a custom getter.

Kind: static method of _
Returns: Proxy - The Proxy object.

Param Type Description
obj Object The object to wrap.
callback function The callback to run when getting properties.

_.proxyNew(obj) ⇒ Proxy

Create a Proxy that can be used to instantiate the target as if it were a class.

Kind: static method of _
Returns: Proxy - The Proxy object.

Param Type Description
obj function The function to wrap.

_.isBinary(value) ⇒ boolean

Check if a value is binary.

Kind: static method of _
Returns: boolean - Whether the value is binary or not.

Param Type Description
value * The value to check.

_.toBuffer(data, [encoding]) ⇒ Buffer | Uint8Array

Converts data to a buffer (or Uint8Array in a browser context).

Kind: static method of _
Returns: Buffer | Uint8Array - The data as a Buffer or Uint8Array.
Throws:

  • Error If the data type is unsupported.
Param Type Description
data * The data to convert.
[encoding] string The encoding to use.